Give informative connection errors more often
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 28 Oct 2005 01:08:49 +0000 (01:08 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 28 Oct 2005 01:08:49 +0000 (01:08 +0000)
includes/Database.php
includes/LoadBalancer.php

index 5aef1bb..3d2f5c0 100644 (file)
@@ -221,6 +221,8 @@ class Database {
         * If the failFunction is set to a non-zero integer, returns success
         */
        function open( $server, $user, $password, $dbName ) {
+               global $wguname;
+               
                # Test for missing mysql.so
                # First try to load it
                if (!@extension_loaded('mysql')) {
@@ -258,7 +260,9 @@ class Database {
                        if ( $this->mConn !== false ) {
                                $success = @/**/mysql_select_db( $dbName, $this->mConn );
                                if ( !$success ) {
-                                       wfDebug( "Error selecting database \"$dbName\": " . $this->lastError() . "\n" );
+                                       $error = "Error selecting database $dbname on server {$this->mServer} " .
+                                               "from client host {$wguname['nodename']}\n";
+                                       wfDebug( $error );
                                }
                        } else {
                                wfDebug( "DB connection error\n" );
@@ -308,16 +312,21 @@ class Database {
 
        /**
         * @access private
-        * @param string $msg error message ?
+        * @param string $error fallback error message, used if none is given by MySQL
         */
-       function reportConnectionError() {
+       function reportConnectionError( $error = 'Unknown error' ) {
+               $myError = $this->lastError();
+               if ( $myError ) {
+                       $error = $myError;
+               }
+               
                if ( $this->mFailFunction ) {
                        if ( !is_int( $this->mFailFunction ) ) {
                                $ff = $this->mFailFunction;
-                               $ff( $this, $this->lastError() );
+                               $ff( $this, $error );
                        }
                } else {
-                       wfEmergencyAbort( $this, $this->lastError() );
+                       wfEmergencyAbort( $this, $error );
                }
        }
 
@@ -1764,6 +1773,12 @@ border=\"0\" ALT=\"Google\"></A>
        if ( is_object( $wgMessageCache ) ) {
                $wgMessageCache->disable();
        }
+
+       if ( trim( $error ) == '' ) {
+               $error = $this->mServer;
+       }
+
+       wfLogDBError( "Connection error: $error\n" );
        
        $msg = wfGetSiteNotice();
        if($msg == '') {
index 89860d7..aaa4d83 100644 (file)
@@ -226,6 +226,7 @@ class LoadBalancer {
                                } while ( count( $loads ) && !$done && $totalElapsed / 1e6 < $wgDBClusterTimeout );
 
                                if ( $totalElapsed / 1e6 >= $wgDBClusterTimeout ) {
+                                       $this->mErrorConnection = false;
                                        $this->mLastError = 'All servers busy';
                                }
                                
@@ -454,7 +455,7 @@ class LoadBalancer {
                                $conn = new Database;
                                if ( $this->mFailFunction ) {
                                        $conn->failFunction( $this->mFailFunction );
-                                       $conn->reportConnectionError();
+                                       $conn->reportConnectionError( $this->mLastError );
                                } else {
                                        // If all servers were busy, mLastError will contain something sensible
                                        wfEmergencyAbort( $conn, $this->mLastError );
@@ -465,7 +466,7 @@ class LoadBalancer {
                                } else {
                                        $conn->failFunction( false );
                                }
-                               $conn->reportConnectionError();
+                               $conn->reportConnectionError( "{$this->mLastError} ({$conn->mServer})" );
                        }
                        $reporting = false;
                }