From 199d238b548e8cc4f0b215d85146c73f306597f6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 15 Dec 2008 23:37:36 +0000 Subject: [PATCH] * (bug 16656) cleanupTitles and friends should now work in load-balanced DB environments when $wgDBserver isn't set. 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 | 2 ++ maintenance/FiveUpgrade.inc | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c4795a20a7..467ab57ae9 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/maintenance/FiveUpgrade.inc b/maintenance/FiveUpgrade.inc index 32c200f2c6..9f994d29e3 100644 --- a/maintenance/FiveUpgrade.inc +++ b/maintenance/FiveUpgrade.inc @@ -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; -- 2.20.1