From: Aaron Schulz Date: Wed, 22 Apr 2015 06:12:59 +0000 (-0700) Subject: Added LoadBalancer::waitForOne method X-Git-Tag: 1.31.0-rc.0~11618 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22config_fonctions%22%2C%20%22image_process=%24process%22%29%20.%20%22?a=commitdiff_plain;h=5f163008d10a57be0e502488975006f5523b1f6f;p=lhc%2Fweb%2Fwiklou.git Added LoadBalancer::waitForOne method * This waits on the generic reader (or a random slave) Change-Id: I4d4a96806d55b119fa535556e11abd55736e9077 --- diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index bc17911f9a..624f46bc3b 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -358,6 +358,37 @@ class LoadBalancer { } } + /** + * Set the master wait position and wait for a "generic" slave to catch up to it + * + * This can be used a faster proxy for waitForAll() + * + * @param DBMasterPos $pos + * @param int $timeout Max seconds to wait; default is mWaitTimeout + * @return bool Success (able to connect and no timeouts reached) + * @since 1.26 + */ + public function waitForOne( $pos, $timeout = null ) { + $this->mWaitForPos = $pos; + + $i = $this->mReadIndex; + if ( $i <= 0 ) { + // Pick a generic slave if there isn't one yet + $readLoads = $this->mLoads; + unset( $readLoads[$this->getWriterIndex()] ); // slaves only + $readLoads = array_filter( $readLoads ); // with non-zero load + $i = ArrayUtils::pickRandom( $readLoads ); + } + + if ( $i > 0 ) { + $ok = $this->doWait( $i, true, $timeout ); + } else { + $ok = true; // no applicable loads + } + + return $ok; + } + /** * Set the master wait position and wait for ALL slaves to catch up to it * @param DBMasterPos $pos