r41329 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41328‎ | r41329 | r41330 >
Date:01:42, 28 September 2008
Author:tstarling
Status:old
Tags:
Comment:
* Revert revert r41234 of ES-related changes. The site_stats complaint should be fixed by the transaction added in r41287.
* Fix broken recursion guard in LoadBalancer::reportConnectionError(), which was causing getConnection() to return false on the second and subsequent errors, instead of throwing an exception. Revert incorrect fix r41229/r41230.
Modified paths:
  • /trunk/phase3/includes/ExternalStoreDB.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDeletedContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -343,13 +343,17 @@
344344
345345 wfProfileIn("dbconnect-$server");
346346
347 - # Try to connect up to three times
348347 # The kernel's default SYN retransmission period is far too slow for us,
349 - # so we use a short timeout plus a manual retry.
 348+ # so we use a short timeout plus a manual retry. Retrying means that a small
 349+ # but finite rate of SYN packet loss won't cause user-visible errors.
350350 $this->mConn = false;
351 - $max = 3;
 351+ if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
 352+ $numAttempts = 2;
 353+ } else {
 354+ $numAttempts = 1;
 355+ }
352356 $this->installErrorHandler();
353 - for ( $i = 0; $i < $max && !$this->mConn; $i++ ) {
 357+ for ( $i = 0; $i < $numAttempts && !$this->mConn; $i++ ) {
354358 if ( $i > 1 ) {
355359 usleep( 1000 );
356360 }
@@ -365,30 +369,28 @@
366370 }
367371 }
368372 $phpError = $this->restoreErrorHandler();
 373+ # Always log connection errors
369374 if ( !$this->mConn ) {
370375 $error = $this->lastError();
371376 if ( !$error ) {
372377 $error = $phpError;
373378 }
374379 wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
 380+ wfDebug( "DB connection error\n" );
 381+ wfDebug( "Server: $server, User: $user, Password: " .
 382+ substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" );
 383+ $success = false;
375384 }
376385
377386 wfProfileOut("dbconnect-$server");
378387
379 - if ( $dbName != '' ) {
380 - if ( $this->mConn !== false ) {
381 - $success = @/**/mysql_select_db( $dbName, $this->mConn );
382 - if ( !$success ) {
383 - $error = "Error selecting database $dbName on server {$this->mServer} " .
384 - "from client host {$wguname['nodename']}\n";
385 - wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n");
386 - wfDebug( $error );
387 - }
388 - } else {
389 - wfDebug( "DB connection error\n" );
390 - wfDebug( "Server: $server, User: $user, Password: " .
391 - substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" );
392 - $success = false;
 388+ if ( $dbName != '' && $this->mConn !== false ) {
 389+ $success = @/**/mysql_select_db( $dbName, $this->mConn );
 390+ if ( !$success ) {
 391+ $error = "Error selecting database $dbName on server {$this->mServer} " .
 392+ "from client host {$wguname['nodename']}\n";
 393+ wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n");
 394+ wfDebug( $error );
393395 }
394396 } else {
395397 # Delay USE query
@@ -2505,6 +2507,13 @@
25062508
25072509 $text = str_replace( '$1', $this->error, $noconnect );
25082510
 2511+ /*
 2512+ if ( $GLOBALS['wgShowExceptionDetails'] ) {
 2513+ $text .= '</p><p>Backtrace:</p><p>' .
 2514+ nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
 2515+ "</p>\n";
 2516+ }*/
 2517+
25092518 if($wgUseFileCache) {
25102519 if($wgTitle) {
25112520 $t =& $wgTitle;
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -398,11 +398,20 @@
399399 /**
400400 * Get a connection by index
401401 * This is the main entry point for this class.
 402+ * @param int $i Database
 403+ * @param array $groups Query groups
 404+ * @param string $wiki Wiki ID
402405 */
403406 public function &getConnection( $i, $groups = array(), $wiki = false ) {
404407 global $wgDBtype;
405408 wfProfileIn( __METHOD__ );
406409
 410+ if ( $i == DB_LAST ) {
 411+ throw new MWException( 'Attempt to call ' . __METHOD__ . ' with deprecated server index DB_LAST' );
 412+ } elseif ( $i === null || $i === false ) {
 413+ throw new MWException( 'Attempt to call ' . __METHOD__ . ' with invalid server index' );
 414+ }
 415+
407416 if ( $wiki === wfWikiID() ) {
408417 $wiki = false;
409418 }
@@ -432,13 +441,13 @@
433442 # Operation-based index
434443 if ( $i == DB_SLAVE ) {
435444 $i = $this->getReaderIndex( false, $wiki );
436 - } elseif ( $i == DB_LAST ) {
437 - throw new MWException( 'Attempt to call ' . __METHOD__ . ' with deprecated server index DB_LAST' );
 445+ # Couldn't find a working server in getReaderIndex()?
 446+ if ( $i === false ) {
 447+ $this->mLastError = 'No working slave server: ' . $this->mLastError;
 448+ $this->reportConnectionError( $this->mErrorConnection );
 449+ return false;
 450+ }
438451 }
439 - # Couldn't find a working server in getReaderIndex()?
440 - if ( $i === false ) {
441 - $this->reportConnectionError( $this->mErrorConnection );
442 - }
443452
444453 # Now we have an explicit index into the servers array
445454 $conn = $this->openConnection( $i, $wiki );
@@ -518,7 +527,7 @@
519528 } else {
520529 $server = $this->mServers[$i];
521530 $server['serverIndex'] = $i;
522 - $conn = $this->reallyOpenConnection( $server );
 531+ $conn = $this->reallyOpenConnection( $server, false );
523532 if ( $conn->isOpen() ) {
524533 $this->mConns['local'][$i][0] = $conn;
525534 } else {
@@ -653,31 +662,27 @@
654663
655664 function reportConnectionError( &$conn ) {
656665 wfProfileIn( __METHOD__ );
657 - # Prevent infinite recursion
658666
659 - static $reporting = false;
660 - if ( !$reporting ) {
661 - $reporting = true;
662 - if ( !is_object( $conn ) ) {
663 - // No last connection, probably due to all servers being too busy
664 - $conn = new Database;
665 - if ( $this->mFailFunction ) {
666 - $conn->failFunction( $this->mFailFunction );
667 - $conn->reportConnectionError( $this->mLastError );
668 - } else {
669 - // If all servers were busy, mLastError will contain something sensible
670 - throw new DBConnectionError( $conn, $this->mLastError );
671 - }
 667+ if ( !is_object( $conn ) ) {
 668+ // No last connection, probably due to all servers being too busy
 669+ wfLogDBError( "LB failure with no last connection\n" );
 670+ $conn = new Database;
 671+ if ( $this->mFailFunction ) {
 672+ $conn->failFunction( $this->mFailFunction );
 673+ $conn->reportConnectionError( $this->mLastError );
672674 } else {
673 - if ( $this->mFailFunction ) {
674 - $conn->failFunction( $this->mFailFunction );
675 - } else {
676 - $conn->failFunction( false );
677 - }
678 - $server = $conn->getProperty( 'mServer' );
679 - $conn->reportConnectionError( "{$this->mLastError} ({$server})" );
 675+ // If all servers were busy, mLastError will contain something sensible
 676+ throw new DBConnectionError( $conn, $this->mLastError );
680677 }
681 - $reporting = false;
 678+ } else {
 679+ if ( $this->mFailFunction ) {
 680+ $conn->failFunction( $this->mFailFunction );
 681+ } else {
 682+ $conn->failFunction( false );
 683+ }
 684+ $server = $conn->getProperty( 'mServer' );
 685+ wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
 686+ $conn->reportConnectionError( "{$this->mLastError} ({$server})" );
682687 }
683688 wfProfileOut( __METHOD__ );
684689 }
Index: trunk/phase3/includes/Revision.php
@@ -769,10 +769,13 @@
770770 $flags = Revision::compressRevisionText( $data );
771771
772772 # Write to external storage if required
773 - if ( $wgDefaultExternalStore ) {
 773+ if( $wgDefaultExternalStore ) {
774774 // Store and get the URL
775775 $data = ExternalStore::insertToDefault( $data );
776 - if ( $flags ) {
 776+ if( !$data ) {
 777+ throw new MWException( "Unable to store text to external storage" );
 778+ }
 779+ if( $flags ) {
777780 $flags .= ',';
778781 }
779782 $flags .= 'external';
Index: trunk/phase3/includes/ExternalStoreDB.php
@@ -123,9 +123,6 @@
124124 */
125125 function store( $cluster, $data ) {
126126 $dbw = $this->getMaster( $cluster );
127 - if( !$dbw ) {
128 - return false;
129 - }
130127 $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' );
131128 $dbw->insert( $this->getTable( $dbw ),
132129 array( 'blob_id' => $id, 'blob_text' => $data ),
Property changes on: trunk/phase3/includes/specials/SpecialDeletedContributions.php
___________________________________________________________________
Deleted: svn:mergeinfo

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41229Revert untested code change from r41086. Don't call methods on non-objects, t...aaron16:09, 24 September 2008
r41230Uncomment out needed code, PN2 not wanting to save :/aaron16:13, 24 September 2008
r41234Revert some recent ES-related changes -- they made behavior much worse when w...brion18:09, 24 September 2008
r41287* Use a separate transaction for the site_stats update...tstarling15:35, 26 September 2008

Status & tagging log