Merge "Remove PHP detection from entry points other than index.php"
[lhc/web/wiklou.git] / includes / db / DatabaseMysqlBase.php
index d2ccbf4..4f93419 100644 (file)
  * @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;
 
@@ -55,8 +52,6 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                $this->lagDetectionMethod = isset( $params['lagDetectionMethod'] )
                        ? $params['lagDetectionMethod']
                        : 'Seconds_Behind_Master';
-
-               $this->srvCache = ObjectCache::newAccelerator( 'hash' );
        }
 
        /**
@@ -684,6 +679,24 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                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
@@ -1341,6 +1354,21 @@ class MySQLMasterPos implements DBMasterPos {
                $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}";
@@ -1357,15 +1385,4 @@ class MySQLMasterPos implements DBMasterPos {
 
                return false;
        }
-
-       function hasReached( MySQLMasterPos $pos ) {
-               $thisPos = $this->getCoordinates();
-               $thatPos = $pos->getCoordinates();
-
-               return ( $thisPos && $thatPos && $thisPos >= $thatPos );
-       }
-
-       function asOfTime() {
-               return $this->asOfTime;
-       }
 }