http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90644

Revision: 90644
Author:   tstarling
Date:     2011-06-23 03:19:10 +0000 (Thu, 23 Jun 2011)
Log Message:
-----------
Merged the DatabaseMysql::getLag() patch from trunk r90643 for immediate 
deployment, since this bug just hit dewiki pretty badly, locking the database 
for 10 minutes due to a brief lag spike.

Modified Paths:
--------------
    branches/wmf/1.17wmf1/includes/db/DatabaseMysql.php

Modified: branches/wmf/1.17wmf1/includes/db/DatabaseMysql.php
===================================================================
--- branches/wmf/1.17wmf1/includes/db/DatabaseMysql.php 2011-06-23 03:14:11 UTC 
(rev 90643)
+++ branches/wmf/1.17wmf1/includes/db/DatabaseMysql.php 2011-06-23 03:19:10 UTC 
(rev 90644)
@@ -344,7 +344,11 @@
 
        /**
         * Returns slave lag.
-        * At the moment, this will only work if the DB user has the PROCESS 
privilege
+        *
+        * On MySQL 4.1.9 and later, this will do a SHOW SLAVE STATUS. On 
earlier
+        * versions of MySQL, it uses SHOW PROCESSLIST, which requires the 
PROCESS
+        * privilege.
+        *
         * @result int
         */
        function getLag() {
@@ -352,6 +356,31 @@
                        wfDebug( "getLag: fake slave lagged 
{$this->mFakeSlaveLag} seconds\n" );
                        return $this->mFakeSlaveLag;
                }
+
+               if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' 
) ) {
+                       return $this->getLagFromSlaveStatus();
+               } else {
+                       return $this->getLagFromProcesslist();
+               }
+       }
+
+       function getLagFromSlaveStatus() {
+               $res = $this->query( 'SHOW SLAVE STATUS', __METHOD__ );
+               if ( !$res ) {
+                       return false;
+               }
+               $row = $res->fetchObject();
+               if ( !$row ) {
+                       return false;
+               }
+               if ( strval( $row->Seconds_Behind_Master ) === '' ) {
+                       return false;
+               } else {
+                       return intval( $row->Seconds_Behind_Master );
+               }
+       }
+
+       function getLagFromProcesslist() {
                $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ );
                if( !$res ) {
                        return false;


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to