protected $mForeign;
protected $mErrorCount = 0;
protected $mLBInfo = array();
- protected $mFakeSlaveLag = null, $mFakeMaster = false;
protected $mDefaultBigSelects = null;
protected $mSchemaVars = false;
/**
* Set lag time in seconds for a fake slave
*
- * @param int $lag
+ * @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 ) {
- $this->mFakeSlaveLag = $lag;
}
/**
* @param bool $enabled
*/
public function setFakeMaster( $enabled = true ) {
- $this->mFakeMaster = $enabled;
}
/**
* zero if we timed out.
*/
public function masterPosWait( DBMasterPos $pos, $timeout ) {
- wfProfileIn( __METHOD__ );
-
- 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" );
- wfProfileOut( __METHOD__ );
-
- return -1;
- } elseif ( $wait > 0 ) {
- wfDebug( "Fake slave waiting $wait us\n" );
- usleep( $wait );
- wfProfileOut( __METHOD__ );
-
- return 1;
- } else {
- wfDebug( "Fake slave up to date ($wait us)\n" );
- wfProfileOut( __METHOD__ );
-
- return 0;
- }
- }
-
- wfProfileOut( __METHOD__ );
-
# Real waits are implemented in the subclass.
return 0;
}
* @return DBMasterPos|bool False if this is not a slave.
*/
public function getSlavePos() {
- if ( !is_null( $this->mFakeSlaveLag ) ) {
- $pos = new MySQLMasterPos( 'fake', microtime( true ) - $this->mFakeSlaveLag );
- wfDebug( __METHOD__ . ": fake slave pos = $pos\n" );
-
- return $pos;
- } else {
- # Stub
- return false;
- }
+ # Stub
+ return false;
}
/**
* @return DBMasterPos|bool False if this is not a master
*/
public function getMasterPos() {
- if ( $this->mFakeMaster ) {
- return new MySQLMasterPos( 'fake', microtime( true ) );
- } else {
- return false;
- }
+ # Stub
+ return false;
}
/**
* @return int Database replication lag in seconds
*/
public function getLag() {
- return intval( $this->mFakeSlaveLag );
+ return 0;
}
/**
/** @var MysqlMasterPos */
protected $lastKnownSlavePos;
+ /** @var null|int */
+ protected $mFakeSlaveLag = null;
+
+ protected $mFakeMaster = false;
+
/**
* @return string
*/
*/
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.
*
*
* @param DBMasterPos|MySQLMasterPos $pos
* @param int $timeout The maximum number of seconds to wait for synchronisation
- * @return bool|string
+ * @return int Zero if the slave was past that position already,
+ * greater than zero if we waited for some period of time, less than
+ * zero if we timed out.
*/
function masterPosWait( DBMasterPos $pos, $timeout ) {
if ( $this->lastKnownSlavePos && $this->lastKnownSlavePos->hasReached( $pos ) ) {
$this->commit( __METHOD__, 'flush' );
if ( !is_null( $this->mFakeSlaveLag ) ) {
- $status = parent::masterPosWait( $pos, $timeout );
- wfProfileOut( __METHOD__ );
+ $wait = intval( ( $pos->pos - microtime( true ) + $this->mFakeSlaveLag ) * 1e6 );
- return $status;
+ if ( $wait > $timeout * 1e6 ) {
+ wfDebug( "Fake slave timed out waiting for $pos ($wait us)\n" );
+ wfProfileOut( __METHOD__ );
+
+ return -1;
+ } elseif ( $wait > 0 ) {
+ wfDebug( "Fake slave waiting $wait us\n" );
+ usleep( $wait );
+ wfProfileOut( __METHOD__ );
+
+ return 1;
+ } else {
+ wfDebug( "Fake slave up to date ($wait us)\n" );
+ wfProfileOut( __METHOD__ );
+
+ return 0;
+ }
}
# Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set
$encFile = $this->addQuotes( $pos->file );
- $encPos = intval( $pos->getMasterPos() );
+ $encPos = intval( $pos->pos );
$sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)";
$res = $this->doQuery( $sql );
*/
function getSlavePos() {
if ( !is_null( $this->mFakeSlaveLag ) ) {
- return parent::getSlavePos();
+ $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' );
*/
function getMasterPos() {
if ( $this->mFakeMaster ) {
- return parent::getMasterPos();
+ return new MySQLMasterPos( 'fake', microtime( true ) );
}
$res = $this->query( 'SHOW MASTER STATUS', 'DatabaseBase::getMasterPos' );
/** @var string */
public $file;
- /** @var int */
- private $pos;
+ /** @var int timestamp */
+ public $pos;
function __construct( $file, $pos ) {
$this->file = $file;
return ( $thisPos && $thatPos && $thisPos >= $thatPos );
}
-
- /**
- * @return int
- */
- public function getMasterPos() {
- return $this->pos;
- }
}