From 75d41fe3b6b0e516fda840cc8b810204c93ffcbb Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 2 Jul 2010 13:17:28 +0000 Subject: [PATCH] Refactored Database*::getLag(): moved the default implementation to MySQL, replaced it with a proper dummy, deleted stub implementations from other classes. This adds fake lag support to all databases. --- includes/db/Database.php | 36 +++------------------------- includes/db/DatabaseIbm_db2.php | 10 -------- includes/db/DatabaseMysql.php | 40 ++++++++++++++++++++++++++++++++ includes/db/DatabaseOracle.php | 11 --------- includes/db/DatabasePostgres.php | 10 -------- includes/db/DatabaseSqlite.php | 7 ------ 6 files changed, 43 insertions(+), 71 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index d38b6c3dc7..c3ef663d83 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2098,41 +2098,11 @@ abstract class DatabaseBase { /** * Get slave lag. - * At the moment, this will only work if the DB user has the PROCESS privilege + * Currently supported only by MySQL + * @return Database replication lag in seconds */ function getLag() { - if ( !is_null( $this->mFakeSlaveLag ) ) { - wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" ); - return $this->mFakeSlaveLag; - } - $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ ); - # Find slave SQL thread - while ( $row = $this->fetchObject( $res ) ) { - /* This should work for most situations - when default db - * for thread is not specified, it had no events executed, - * and therefore it doesn't know yet how lagged it is. - * - * Relay log I/O thread does not select databases. - */ - if ( $row->User == 'system user' && - $row->State != 'Waiting for master to send event' && - $row->State != 'Connecting to master' && - $row->State != 'Queueing master event to the relay log' && - $row->State != 'Waiting for master update' && - $row->State != 'Requesting binlog dump' && - $row->State != 'Waiting to reconnect after a failed master event read' && - $row->State != 'Reconnecting after a failed master event read' && - $row->State != 'Registering slave on master' - ) { - # This is it, return the time (except -ve) - if ( $row->Time > 0x7fffffff ) { - return false; - } else { - return $row->Time; - } - } - } - return false; + return $this->mFakeSlaveLag; } /** diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index 4a10bd6fc4..024990ce1e 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -1501,16 +1501,6 @@ EOF; * @deprecated */ public function getStatus( $which="%" ) { $this->installPrint('Not implemented for DB2: getStatus()'); return ''; } - /** - * Not implemented - * TODO - * @return bool true - */ - /** - * Not implemented - * @deprecated - */ - public function setFakeSlaveLag( $lag ) { $this->installPrint('Not implemented for DB2: setFakeSlaveLag()'); } /** * Not implemented * @deprecated diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 58809f1f97..dcdfa2d58d 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -304,6 +304,46 @@ class DatabaseMysql extends DatabaseBase { return true; } + /** + * Returns slave lag. + * At the moment, this will only work if the DB user has the PROCESS privilege + * @result int + */ + function getLag() { + if ( !is_null( $this->mFakeSlaveLag ) ) { + wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" ); + return $this->mFakeSlaveLag; + } + $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ ); + # Find slave SQL thread + while ( $row = $this->fetchObject( $res ) ) { + /* This should work for most situations - when default db + * for thread is not specified, it had no events executed, + * and therefore it doesn't know yet how lagged it is. + * + * Relay log I/O thread does not select databases. + */ + if ( $row->User == 'system user' && + $row->State != 'Waiting for master to send event' && + $row->State != 'Connecting to master' && + $row->State != 'Queueing master event to the relay log' && + $row->State != 'Waiting for master update' && + $row->State != 'Requesting binlog dump' && + $row->State != 'Waiting to reconnect after a failed master event read' && + $row->State != 'Reconnecting after a failed master event read' && + $row->State != 'Registering slave on master' + ) { + # This is it, return the time (except -ve) + if ( $row->Time > 0x7fffffff ) { + return false; + } else { + return $row->Time; + } + } + } + return false; + } + function getServerVersion() { return mysql_get_server_info( $this->mConn ); } diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 9bb947f36a..9eb9e79ad8 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -1148,17 +1148,6 @@ class DatabaseOracle extends DatabaseBase { return 'BITOR(' . $fieldLeft . ', ' . $fieldRight . ')'; } - /** - * How lagged is this slave? - * - * @return int - */ - public function getLag() { - # Not implemented for Oracle - return 0; - } - - function setFakeSlaveLag( $lag ) { } function setFakeMaster( $enabled = true ) { } function getDBname() { diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 784845d2fb..578f12f996 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -1451,16 +1451,6 @@ SQL; return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail ); } - /** - * How lagged is this slave? - * - */ - public function getLag() { - # Not implemented for PostgreSQL - return false; - } - - function setFakeSlaveLag( $lag ) {} function setFakeMaster( $enabled = true ) {} function getDBname() { diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 418dcd0663..535b5c4a53 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -508,13 +508,6 @@ class DatabaseSqlite extends DatabaseBase { return parent::buildLike( $params ) . "ESCAPE '\' "; } - /** - * How lagged is this slave? - */ - public function getLag() { - return 0; - } - /** * Called by the installer script (when modified according to the MediaWikiLite installation instructions) * - this is the same way PostgreSQL works, MySQL reads in tables.sql and interwiki.sql using dbsource (which calls db->sourceFile) -- 2.20.1