Merge "Move DB errors to Rdbms namespace"
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index 0e07fac..c1b8a0f 100644 (file)
@@ -404,7 +404,11 @@ class LoadBalancer implements ILoadBalancer {
                        # Replica DB connection successful.
                        # Wait for the session master pos for a short time.
                        if ( $this->mWaitForPos && $i > 0 ) {
-                               $this->doWait( $i );
+                               # When LoadBalancer::waitFor() set mWaitForPos, the wait will happen here.
+                               # Be sure to update laggedReplicaMode accordingly for consistency.
+                               if ( !$this->doWait( $i ) ) {
+                                       $laggedReplicaMode = true;
+                               }
                        }
                        if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $group === false ) {
                                $this->mReadIndex = $i;
@@ -433,7 +437,7 @@ class LoadBalancer implements ILoadBalancer {
                                }
                        }
                } finally {
-                       // Restore the older position if it was higher
+                       // Restore the older position if it was higher since this is used for lag-protection
                        $this->setWaitForPositionIfHigher( $oldPos );
                }
        }
@@ -458,8 +462,8 @@ class LoadBalancer implements ILoadBalancer {
                                $ok = true; // no applicable loads
                        }
                } finally {
-                       // Restore the older position if it was higher
-                       $this->setWaitForPositionIfHigher( $oldPos );
+                       # Restore the old position, as this is not used for lag-protection but for throttling
+                       $this->mWaitForPos = $oldPos;
                }
 
                return $ok;
@@ -478,8 +482,8 @@ class LoadBalancer implements ILoadBalancer {
                                }
                        }
                } finally {
-                       // Restore the older position if it was higher
-                       $this->setWaitForPositionIfHigher( $oldPos );
+                       # Restore the old position, as this is not used for lag-protection but for throttling
+                       $this->mWaitForPos = $oldPos;
                }
 
                return $ok;