* (bug 16656) cleanupTitles and friends should now work in load-balanced DB environme...
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 15 Dec 2008 23:37:36 +0000 (23:37 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 15 Dec 2008 23:37:36 +0000 (23:37 +0000)
Lots of cleanup scripts are based on the FiveUpgrade class created for the 1.5 schema upgrade -- this provides a utility class designed around pulling data from a second, unbuffered connection, processing it, and stuffing it into a master connection.
Originally, both connections were created by manually instantiating the Database class. This worked as long as $wgDBserver was set, but at some point we apparently stopped setting it in our fancy-ass load-balanced environment where we're exclusively using the $wgDBservers array.
As a result, the connections used the default $wgDBserver of 'localhost' which inconveniently fails on Wikimedia's servers. ;)
Now uses the Tim-approved method of getting a new database connection -- creates a new LoadBalancer via wfGetLBFactory()->newMainLB(), then asks it for a fresh connection.

RELEASE-NOTES
maintenance/FiveUpgrade.inc

index c4795a2..467ab57 100644 (file)
@@ -420,6 +420,8 @@ The following extensions are migrated into MediaWiki 1.14:
   move a title to an interwiki target
 * (bug 16638) 8-bit URL fallback encoding now set on additional languages using
   Arabic script (Persian, Urdu, Sindhi, Punjabi)
+* (bug 16656) cleanupTitles and friends should now work in load-balanced
+  DB environments when $wgDBserver isn't set.
 
 === API changes in 1.14 ===
 
index 32c200f..9f994d2 100644 (file)
@@ -20,8 +20,9 @@ class FiveUpgrade {
        function FiveUpgrade() {
                $this->conversionTables = $this->prepareWindows1252();
 
-               $this->dbw =& $this->newConnection();
-               $this->dbr =& $this->streamConnection();
+               $this->loadBalancers = array();
+               $this->dbw = wfGetDB( DB_MASTER );
+               $this->dbr = $this->streamConnection();
 
                $this->cleanupSwaps = array();
                $this->emailAuth = false; # don't preauthenticate emails
@@ -67,13 +68,24 @@ class FiveUpgrade {
         * @return Database
         * @access private
         */
-       function &newConnection() {
-               global $wgDBadminuser, $wgDBadminpassword, $wgDBtype;
-               global $wgDBserver, $wgDBname;
-               $dbclass = 'Database' . ucfirst( $wgDBtype ) ;
-               $db = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+       function newConnection() {
+               $lb = wfGetLBFactory()->newMainLB();
+               $db = $lb->getConnection( DB_MASTER );
+               
+               $this->loadBalancers[] = $lb;
                return $db;
        }
+       
+       /**
+        * Close out the connections when we're done...
+        * Is this needed?
+        */
+       function close() {
+               foreach( $this->loadBalancers as $lb ) {
+                       $lb->commitMasterChanges();
+                       $lb->closeAll();
+               }
+       }
 
        /**
         * Open a second connection to the master server, with buffering off.
@@ -82,7 +94,7 @@ class FiveUpgrade {
         * @return Database
         * @access private
         */
-       function &streamConnection() {
+       function streamConnection() {
                global $wgDBtype;
 
                $timeout = 3600 * 24;