r75343 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75342‎ | r75343 | r75344 >
Date:21:27, 24 October 2010
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
(bug 24853) Kill failFunction - Fixed! :D
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseIbm_db2.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMssql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -185,10 +185,10 @@
186186 var $mFieldInfoCache = array();
187187
188188 function __construct( $server = false, $user = false, $password = false, $dbName = false,
189 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
 189+ $flags = 0, $tablePrefix = 'get from global' )
190190 {
191191 $tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper( $tablePrefix );
192 - parent::__construct( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
 192+ parent::__construct( $server, $user, $password, $dbName, $flags, $tablePrefix );
193193 wfRunHooks( 'DatabaseOraclePostInit', array( &$this ) );
194194 }
195195
@@ -218,14 +218,12 @@
219219 return true;
220220 }
221221
222 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0, $tablePrefix )
223 - {
224 - return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
 222+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0, $tablePrefix ) {
 223+ return new DatabaseOracle( $server, $user, $password, $dbName, $flags, $tablePrefix );
225224 }
226225
227226 /**
228227 * Usually aborts on failure
229 - * If the failFunction is set to a non-zero integer, returns success
230228 */
231229 function open( $server, $user, $password, $dbName ) {
232230 if ( !function_exists( 'oci_connect' ) ) {
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -101,7 +101,7 @@
102102 var $mAffectedRows = null;
103103
104104 function __construct( $server = false, $user = false, $password = false, $dbName = false,
105 - $failFunction = false, $flags = 0 )
 105+ $flags = 0 )
106106 {
107107 $this->mFlags = $flags;
108108 $this->open( $server, $user, $password, $dbName );
@@ -144,13 +144,12 @@
145145 return $this->numRows( $res );
146146 }
147147
148 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
149 - return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
 148+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
 149+ return new DatabasePostgres( $server, $user, $password, $dbName, $flags );
150150 }
151151
152152 /**
153153 * Usually aborts on failure
154 - * If the failFunction is set to a non-zero integer, returns success
155154 */
156155 function open( $server, $user, $password, $dbName ) {
157156 # Test for Postgres support, to avoid suppressed fatal error
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -116,7 +116,6 @@
117117 protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
118118 protected $mOut, $mOpened = false;
119119
120 - protected $mFailFunction;
121120 protected $mTablePrefix;
122121 protected $mFlags;
123122 protected $mTrxLevel = 0;
@@ -257,13 +256,12 @@
258257 * @param $user String: username
259258 * @param $password String: password
260259 * @param $dbName String: database name on the server
261 - * @param $failFunction Callback (optional)
262260 * @param $flags Integer: database behaviour flags (optional, unused)
263261 * @param $schema String
264262 */
265263 public function DatabaseIbm_db2( $server = false, $user = false,
266264 $password = false,
267 - $dbName = false, $failFunction = false, $flags = 0,
 265+ $dbName = false, $flags = 0,
268266 $schema = self::USE_GLOBAL )
269267 {
270268
@@ -437,15 +435,14 @@
438436 * @param $user String: username
439437 * @param $password String
440438 * @param $dbName String: database name on the server
441 - * @param $failFunction Callback (optional)
442439 * @param $flags Integer: database behaviour flags (optional, unused)
443440 * @return DatabaseIbm_db2 object
444441 */
445442 static function newFromParams( $server, $user, $password, $dbName,
446 - $failFunction = false, $flags = 0 )
 443+ $flags = 0 )
447444 {
448445 return new DatabaseIbm_db2( $server, $user, $password, $dbName,
449 - $failFunction, $flags );
 446+ $flags );
450447 }
451448
452449 /**
Index: trunk/phase3/includes/db/Database.php
@@ -32,7 +32,6 @@
3333
3434 /**
3535 * Open a connection to the database. Usually aborts on failure
36 - * If the failFunction is set to a non-zero integer, returns success
3736 *
3837 * @param $server String: database server host
3938 * @param $user String: database user name
@@ -210,7 +209,6 @@
211210 protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
212211 protected $mOpened = false;
213212
214 - protected $mFailFunction;
215213 protected $mTablePrefix;
216214 protected $mFlags;
217215 protected $mTrxLevel = 0;
@@ -479,12 +477,11 @@
480478 * @param $user String: database user name
481479 * @param $password String: database user password
482480 * @param $dbName String: database name
483 - * @param $failFunction
484481 * @param $flags
485482 * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
486483 */
487484 function __construct( $server = false, $user = false, $password = false, $dbName = false,
488 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global'
 485+ $flags = 0, $tablePrefix = 'get from global'
489486 ) {
490487 global $wgOut, $wgDBprefix, $wgCommandLineMode;
491488
@@ -527,12 +524,11 @@
528525 * @param $user String: database user name
529526 * @param $password String: database user password
530527 * @param $dbName String: database name
531 - * @param failFunction
532528 * @param $flags
533529 */
534 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
 530+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
535531 wfDeprecated( __METHOD__ );
536 - return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags );
 532+ return new DatabaseMysql( $server, $user, $password, $dbName, $flags );
537533 }
538534
539535 protected function installErrorHandler() {
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -18,7 +18,7 @@
1919 var $mAffectedRows = NULL;
2020
2121 function __construct( $server = false, $user = false, $password = false, $dbName = false,
22 - $failFunction = false, $flags = 0 )
 22+ $flags = 0 )
2323 {
2424 $this->mFlags = $flags;
2525 $this->open( $server, $user, $password, $dbName );
@@ -49,14 +49,12 @@
5050 return false;
5151 }
5252
53 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
54 - {
55 - return new DatabaseMssql( $server, $user, $password, $dbName, $failFunction, $flags );
 53+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
 54+ return new DatabaseMssql( $server, $user, $password, $dbName, $flags );
5655 }
5756
5857 /**
5958 * Usually aborts on failure
60 - * If the failFunction is set to a non-zero integer, returns success
6159 */
6260 function open( $server, $user, $password, $dbName ) {
6361 # Test for driver support, to avoid suppressed fatal error
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -23,7 +23,7 @@
2424 * Constructor.
2525 * Parameters $server, $user and $password are not used.
2626 */
27 - function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) {
 27+ function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) {
2828 global $wgSharedDB;
2929 $this->mFlags = $flags;
3030 $this->mName = $dbName;
@@ -42,8 +42,8 @@
4343 */
4444 function implicitGroupby() { return false; }
4545
46 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
47 - return new DatabaseSqlite( $server, $user, $password, $dbName, $failFunction, $flags );
 46+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
 47+ return new DatabaseSqlite( $server, $user, $password, $dbName, $flags );
4848 }
4949
5050 /** Open an SQLite database and return a resource handle to it
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -14,7 +14,7 @@
1515 */
1616 class LoadBalancer {
1717 /* private */ var $mServers, $mConns, $mLoads, $mGroupLoads;
18 - /* private */ var $mFailFunction, $mErrorConnection;
 18+ /* private */ var $mErrorConnection;
1919 /* private */ var $mReadIndex, $mAllowLagged;
2020 /* private */ var $mWaitForPos, $mWaitTimeout;
2121 /* private */ var $mLaggedSlaveMode, $mLastError = 'Unknown error';
@@ -24,7 +24,6 @@
2525 /**
2626 * @param $params Array with keys:
2727 * servers Required. Array of server info structures.
28 - * failFunction Deprecated, use exceptions instead.
2928 * masterWaitTimeout Replication lag wait timeout
3029 * loadMonitor Name of a class used to fetch server lag and load.
3130 */
@@ -68,9 +67,8 @@
6968 }
7069 }
7170
72 - static function newFromParams( $servers, $failFunction = false, $waitTimeout = 10 )
73 - {
74 - return new LoadBalancer( $servers, $failFunction, $waitTimeout );
 71+ static function newFromParams( $servers, $waitTimeout = 10 ) {
 72+ return new LoadBalancer( $servers, $waitTimeout );
7573 }
7674
7775 /**
@@ -643,7 +641,7 @@
644642
645643 # Create object
646644 wfDebug( "Connecting to $host $dbname...\n" );
647 - $db = new $class( $host, $user, $password, $dbname, 1, $flags );
 645+ $db = new $class( $host, $user, $password, $dbname, $flags );
648646 if ( $db->isOpen() ) {
649647 wfDebug( "Connected to $host $dbname.\n" );
650648 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r75350* fixed accidental revert of r75343freakolowsky12:06, 25 October 2010
r75444Followup r75431, bug 24853. Add to RELEASE-NOTESreedy17:12, 26 October 2010
r79591Simplest possible fix for *(bug 26552) ForeignDBRepo broken?...reedy19:33, 4 January 2011
r79593Remove another setting of failFunction in phase3 in a database constructorreedy19:54, 4 January 2011
r79595Kill some FailFunction remenantsreedy20:04, 4 January 2011
r90266* (bug 29233) Temporary fix which roughly restores the 1.16 behaviour of open...tstarling12:59, 17 June 2011
r96517Merge r90266 to trunk...reedy23:21, 7 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75341Start of bug 24853, killing off 'functional' parts of failfunction code. Seem...reedy20:48, 24 October 2010

Comments

#Comment by Reedy (talk | contribs)   21:31, 24 October 2010

Finally killed after being deprecated in r14625

#Comment by Bryan (talk | contribs)   21:43, 3 January 2011

This breaks ForeignDBRepo. More importantly it breaks all extensions and core code that constructs a Database object. I suggest leaving the $failFunction parameter in the constructor forever, instead of dealing with the unknown side-effects that changing the constructor function signature. (This is why long lists of unnamed parameters sucks)

#Comment by Reedy (talk | contribs)   21:57, 3 January 2011

I was wondering why you'd assigned that bug to me...

#Comment by Bryan (talk | contribs)   21:59, 3 January 2011

Forgot to cross reference :) bug 26552

#Comment by Tim Starling (talk | contribs)   07:09, 17 June 2011

This broke failover in LoadBalancer and caused 15 minutes of downtime on the English Wikipedia (bug 29233).

#Comment by Reedy (talk | contribs)   09:19, 17 June 2011

Surely it's more likely to have actually been r75341?

-			if ( $this->mFailFunction ) {
-				$conn->failFunction( $this->mFailFunction );
-				$conn->reportConnectionError( $this->mLastError );
-			} else {
-				// If all servers were busy, mLastError will contain something sensible
-				throw new DBConnectionError( $conn, $this->mLastError );
-			}
+			// If all servers were busy, mLastError will contain something sensible
+			throw new DBConnectionError( $conn, $this->mLastError );


And unless I'm missing something, it seems rare/I'm struggling to see where it wasn't set to false, and hence, would have actually have been called somewhere...

#Comment by Tim Starling (talk | contribs)   10:31, 17 June 2011

I guess so, I'll mark that one fixme as well. The one place where it wasn't false was the place where almost all database objects are constructed:

-		$db = new $class( $host, $user, $password, $dbname, 1, $flags );
+		$db = new $class( $host, $user, $password, $dbname, $flags );
#Comment by Brion VIBBER (talk | contribs)   23:38, 20 July 2011

Is there anything in this revision that still needs to be fixed, or does the r90266 solution just need to be improved? (My recommendation there: refactor the Database* constructor to not open the connection automatically, and finish cleaning up all the things that call Database* constructors manually when they should probably not be.)

#Comment by 😂 (talk | contribs)   23:28, 7 September 2011

Per the discussion, nothing with this rev is really the problem anymore. r90266 could use improvement, but will suffice for REL1_18. A proper fix in trunk would be ideal.

Marking RESOLVED.

Status & tagging log