Cleanup live hack from wmf-deployment r53208 a bit: DB selection using load balancer.
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 14 Sep 2009 22:32:30 +0000 (22:32 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 14 Sep 2009 22:32:30 +0000 (22:32 +0000)
Should fix a couple regressions or possible regressions:
* Hack was pulling the main LB's DB_SLAVE connection although we were deliberately opening a new connection. Could have caused problems when we were fetching other things from the local database in the middle of an export.
* We no longer lose the connection timeout override.

However we still have a regression:
* --server option is ignored (but we're now pulling from the 'backup' group, so we at least have some kind of consistency :)

maintenance/backup.inc

index e546df4..30bd0d8 100644 (file)
@@ -232,21 +232,13 @@ class BackupDumper {
                $this->startTime = wfTime();
        }
 
+       /**
+        * @fixme the --server parameter is currently not respected, as it doesn't seem
+        * terribly easy to ask the load balancer for a particular connection by name.
+        */
        function backupDb() {
-               global $wgDBadminuser, $wgDBadminpassword;
-               global $wgDBuser, $wgDBpassword;
-               global $wgDBname, $wgDebugDumpSql, $wgDBtype;
-               $flags = ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT; // god-damn hack
-               
-               if ( !$wgDBadminuser ) {
-                       $wgDBadminuser = $wgDBuser;
-               }
-               if ( !$wgDBadminpassword ) {
-                       $wgDBadminpassword = $wgDBpassword;
-               }
-
-               $class = 'Database' . ucfirst($wgDBtype);
-               $db = new $class( $this->backupServer(), $wgDBadminuser, $wgDBadminpassword, $wgDBname, false, $flags );
+               $this->lb = wfGetLBFactory()->newMainLB();
+               $db = $this->lb->getConnection( DB_SLAVE, 'backup' );
                
                // Discourage the server from disconnecting us if it takes a long time
                // to read out the big ol' batch query.
@@ -254,6 +246,12 @@ class BackupDumper {
                
                return $db;
        }
+       
+       function __destruct() {
+               if( isset( $this->lb ) ) {
+                       $this->lb->closeAll();
+               }
+       }
 
        function backupServer() {
                global $wgDBserver;