* If a DB_REPLICA connection has been opened already, then wait immediately.
* Otherwise sets a variable telling it to wait if such a connection is opened.
*
+ * This only applies to connections to the generic replica DB for this request.
+ * If a timeout happens when waiting, then getLaggedReplicaMode()/laggedReplicaUsed()
+ * will return true.
+ *
* @param DBMasterPos|bool $pos Master position or false
*/
public function waitFor( $pos );
# 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;
}
}
} 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 );
}
}
$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;
}
}
} 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;