r44639 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44638‎ | r44639 | r44640 >
Date:23:37, 15 December 2008
Author:brion
Status:ok (Comments)
Tags:
Comment:
* (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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/FiveUpgrade.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/FiveUpgrade.inc
@@ -20,8 +20,9 @@
2121 function FiveUpgrade() {
2222 $this->conversionTables = $this->prepareWindows1252();
2323
24 - $this->dbw =& $this->newConnection();
25 - $this->dbr =& $this->streamConnection();
 24+ $this->loadBalancers = array();
 25+ $this->dbw = wfGetDB( DB_MASTER );
 26+ $this->dbr = $this->streamConnection();
2627
2728 $this->cleanupSwaps = array();
2829 $this->emailAuth = false; # don't preauthenticate emails
@@ -67,13 +68,24 @@
6869 * @return Database
6970 * @access private
7071 */
71 - function &newConnection() {
72 - global $wgDBadminuser, $wgDBadminpassword, $wgDBtype;
73 - global $wgDBserver, $wgDBname;
74 - $dbclass = 'Database' . ucfirst( $wgDBtype ) ;
75 - $db = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 72+ function newConnection() {
 73+ $lb = wfGetLBFactory()->newMainLB();
 74+ $db = $lb->getConnection( DB_MASTER );
 75+
 76+ $this->loadBalancers[] = $lb;
7677 return $db;
7778 }
 79+
 80+ /**
 81+ * Close out the connections when we're done...
 82+ * Is this needed?
 83+ */
 84+ function close() {
 85+ foreach( $this->loadBalancers as $lb ) {
 86+ $lb->commitMasterChanges();
 87+ $lb->closeAll();
 88+ }
 89+ }
7890
7991 /**
8092 * Open a second connection to the master server, with buffering off.
@@ -82,7 +94,7 @@
8395 * @return Database
8496 * @access private
8597 */
86 - function &streamConnection() {
 98+ function streamConnection() {
8799 global $wgDBtype;
88100
89101 $timeout = 3600 * 24;
Index: trunk/phase3/RELEASE-NOTES
@@ -420,6 +420,8 @@
421421 move a title to an interwiki target
422422 * (bug 16638) 8-bit URL fallback encoding now set on additional languages using
423423 Arabic script (Persian, Urdu, Sindhi, Punjabi)
 424+* (bug 16656) cleanupTitles and friends should now work in load-balanced
 425+ DB environments when $wgDBserver isn't set.
424426
425427 === API changes in 1.14 ===
426428

Comments

#Comment by Aaron Schulz (talk | contribs)   23:54, 15 December 2008

Looks nice :)

Status & tagging log