* @since 1.22
* @see Database
*/
-abstract class DatabaseMysqlBase extends DatabaseBase {
+abstract class DatabaseMysqlBase extends Database {
/** @var MysqlMasterPos */
protected $lastKnownSlavePos;
/** @var string Method to detect slave lag */
protected $lagDetectionMethod;
- /** @var BagOStuff APC cache */
- protected $srvCache;
-
/** @var string|null */
private $serverVersion = null;
$this->lagDetectionMethod = isset( $params['lagDetectionMethod'] )
? $params['lagDetectionMethod']
: 'Seconds_Behind_Master';
-
- $this->srvCache = ObjectCache::newAccelerator( 'hash' );
}
/**
return false;
}
+ public function getApproximateLagStatus() {
+ if ( $this->lagDetectionMethod === 'pt-heartbeat' ) {
+ // Disable caching since this is fast enough and we don't wan't
+ // to be *too* pessimistic by having both the cache TTL and the
+ // pt-heartbeat interval count as lag in getSessionLagStatus()
+ return parent::getApproximateLagStatus();
+ }
+
+ $key = wfGlobalCacheKey( 'mysql-lag', $this->getServer() );
+ $approxLag = $this->srvCache->get( $key );
+ if ( !$approxLag ) {
+ $approxLag = parent::getApproximateLagStatus();
+ $this->srvCache->set( $key, $approxLag, 1 );
+ }
+
+ return $approxLag;
+ }
+
/**
* Wait for the slave to catch up to a given master position.
* @todo Return values for this and base class are rubbish
$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;
- }
}