$this->asOfTime = microtime( true );
}
+ function asOfTime() {
+ return $this->asOfTime;
+ }
+
+ function hasReached( DBMasterPos $pos ) {
+ if ( !( $pos instanceof self ) ) {
+ throw new InvalidArgumentException( "Position not an instance of " . __CLASS__ );
+ }
+
+ $thisPos = $this->getCoordinates();
+ $thatPos = $pos->getCoordinates();
+
+ return ( $thisPos && $thatPos && $thisPos >= $thatPos );
+ }
+
function __toString() {
// e.g db1034-bin.000976/843431247
return "{$this->file}/{$this->pos}";
return false;
}
-
- function hasReached( MySQLMasterPos $pos ) {
- $thisPos = $this->getCoordinates();
- $thatPos = $pos->getCoordinates();
-
- return ( $thisPos && $thatPos && $thisPos >= $thatPos );
- }
-
- function asOfTime() {
- return $this->asOfTime;
- }
}
private $mLoadMonitorClass;
/** @var LoadMonitor */
private $mLoadMonitor;
+ /** @var BagOStuff */
+ private $srvCache;
/** @var bool|DatabaseBase Database connection that caused a problem */
private $mErrorConnection;
}
}
}
+
+ $this->srvCache = ObjectCache::getLocalServerInstance();
}
/**
protected function doWait( $index, $open = false, $timeout = null ) {
$close = false; // close the connection afterwards
- # Find a connection to wait on, creating one if needed and allowed
+ // Check if we already know that the DB has reached this point
+ $server = $this->getServerName( $index );
+ $key = $this->srvCache->makeGlobalKey( __CLASS__, 'last-known-pos', $server );
+ /** @var DBMasterPos $knownReachedPos */
+ $knownReachedPos = $this->srvCache->get( $key );
+ if ( $knownReachedPos && $knownReachedPos->hasReached( $this->mWaitForPos ) ) {
+ wfDebugLog( 'replication', __METHOD__ . ": Slave $server known to be caught up.\n" );
+ return true;
+ }
+
+ // Find a connection to wait on, creating one if needed and allowed
$conn = $this->getAnyOpenConnection( $index );
if ( !$conn ) {
if ( !$open ) {
- wfDebug( __METHOD__ . ": no connection open\n" );
+ wfDebugLog( 'replication', __METHOD__ . ": no connection open for $server\n" );
return false;
} else {
$conn = $this->openConnection( $index, '' );
if ( !$conn ) {
- wfDebug( __METHOD__ . ": failed to open connection\n" );
+ wfDebugLog( 'replication', __METHOD__ . ": failed to open connection to $server\n" );
return false;
}
}
}
- wfDebug( __METHOD__ . ": Waiting for slave #$index to catch up...\n" );
+ wfDebugLog( 'replication', __METHOD__ . ": Waiting for slave $server to catch up...\n" );
$timeout = $timeout ?: $this->mWaitTimeout;
$result = $conn->masterPosWait( $this->mWaitForPos, $timeout );
if ( $result == -1 || is_null( $result ) ) {
- # Timed out waiting for slave, use master instead
- $server = $server = $this->getServerName( $index );
+ // Timed out waiting for slave, use master instead
$msg = __METHOD__ . ": Timed out waiting on $server pos {$this->mWaitForPos}";
- wfDebug( "$msg\n" );
+ wfDebugLog( 'replication', "$msg\n" );
wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) );
$ok = false;
} else {
- wfDebug( __METHOD__ . ": Done\n" );
+ wfDebugLog( 'replication', __METHOD__ . ": Done\n" );
$ok = true;
+ // Remember that the DB reached this point
+ $this->srvCache->set( $key, $this->mWaitForPos, BagOStuff::TTL_DAY );
}
if ( $close ) {