}
}
- /**
- * Set lag time in seconds for a fake slave
- *
- * @param mixed $lag Valid values for this parameter are determined by the
- * subclass, but should be a PHP scalar or array that would be sensible
- * as part of $wgLBFactoryConf.
- */
- public function setFakeSlaveLag( $lag ) {
- }
-
- /**
- * Make this connection a fake master
- *
- * @param bool $enabled
- */
- public function setFakeMaster( $enabled = true ) {
- }
-
/**
* @return TransactionProfiler
*/
/** @var MysqlMasterPos */
protected $lastKnownSlavePos;
- /** @var null|int */
- protected $mFakeSlaveLag = null;
-
- protected $mFakeMaster = false;
-
/** @var string|null */
private $serverVersion = null;
*/
abstract protected function mysqlPing();
- /**
- * Set lag time in seconds for a fake slave
- *
- * @param int $lag
- */
- public function setFakeSlaveLag( $lag ) {
- $this->mFakeSlaveLag = $lag;
- }
-
- /**
- * Make this connection a fake master
- *
- * @param bool $enabled
- */
- public function setFakeMaster( $enabled = true ) {
- $this->mFakeMaster = $enabled;
- }
-
/**
* Returns slave lag.
*
* @return int
*/
function getLag() {
- if ( !is_null( $this->mFakeSlaveLag ) ) {
- wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" );
-
- return $this->mFakeSlaveLag;
- }
-
return $this->getLagFromSlaveStatus();
}
# Commit any open transactions
$this->commit( __METHOD__, 'flush' );
- if ( !is_null( $this->mFakeSlaveLag ) ) {
- $wait = intval( ( $pos->pos - microtime( true ) + $this->mFakeSlaveLag ) * 1e6 );
-
- if ( $wait > $timeout * 1e6 ) {
- wfDebug( "Fake slave timed out waiting for $pos ($wait us)\n" );
-
- return -1;
- } elseif ( $wait > 0 ) {
- wfDebug( "Fake slave waiting $wait us\n" );
- usleep( $wait );
-
- return 1;
- } else {
- wfDebug( "Fake slave up to date ($wait us)\n" );
-
- return 0;
- }
- }
-
# Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set
$encFile = $this->addQuotes( $pos->file );
$encPos = intval( $pos->pos );
* @return MySQLMasterPos|bool
*/
function getSlavePos() {
- if ( !is_null( $this->mFakeSlaveLag ) ) {
- $pos = new MySQLMasterPos( 'fake', microtime( true ) - $this->mFakeSlaveLag );
- wfDebug( __METHOD__ . ": fake slave pos = $pos\n" );
-
- return $pos;
- }
-
$res = $this->query( 'SHOW SLAVE STATUS', 'DatabaseBase::getSlavePos' );
$row = $this->fetchObject( $res );
* @return MySQLMasterPos|bool
*/
function getMasterPos() {
- if ( $this->mFakeMaster ) {
- return new MySQLMasterPos( 'fake', microtime( true ) );
- }
-
$res = $this->query( 'SHOW MASTER STATUS', 'DatabaseBase::getMasterPos' );
$row = $this->fetchObject( $res );