debug output, and proper handling of NULL return from masterPosWait(), which occurs...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 23 Jul 2004 12:37:55 +0000 (12:37 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 23 Jul 2004 12:37:55 +0000 (12:37 +0000)
includes/LoadBalancer.php

index 00d2c1d..b52cabb 100644 (file)
@@ -130,6 +130,7 @@ class LoadBalancer {
        # If a DB_SLAVE connection has been opened already, waits
        # Otherwise sets a variable telling it to wait if such a connection is opened
        function waitFor( $file, $pos ) {
+               wfDebug( "User master pos: $file $pos\n" );
                $this->mWaitForFile = false;
                $this->mWaitForPos = false;
 
@@ -160,14 +161,19 @@ class LoadBalancer {
                }
 
                $conn =& $this->getConnection( $index );
+               wfDebug( "Waiting for slave #$index to catch up...\n" );
                $result = $conn->masterPosWait( $this->mWaitForFile, $this->mWaitForPos, MASTER_WAIT_TIMEOUT );
-               if ( $result == -1 ) {
+
+               if ( $result == -1 || is_null( $result ) ) {
                        # Timed out waiting for slave, use master instead
                        # This is not the ideal solution. If there are a large number of slaves, a slow
                        # replicated write query will cause the master to be swamped with reads. However
                        # that's a relatively graceful failure mode, so it will do for now.
+                       wfDebug( "Timed out waiting for slave #$index pos {$this->mWaitForFile} {$this->mWaitForPos}\n" );
                        $this->mReadIndex = 0;
-               } 
+               } else {
+                       wfDebug( "Done\n" );
+               }
        }               
 
        function &getConnection( $i, $fail = false )
@@ -275,9 +281,11 @@ class LoadBalancer {
                        if ( empty( $this->mConnections[0] ) ) {
                                $conn =& $this->getConnection( DB_SLAVE );
                                list( $file, $pos ) = $conn->getSlavePos();
+                               wfDebug( "Saving master pos fetched from slave: $file $pos\n" );
                        } else {
                                $conn =& $this->getConnection( 0 );
                                list( $file, $pos ) = $conn->getMasterPos();
+                               wfDebug( "Saving master pos: $file $pos\n" );
                        }
                        if ( $file !== false ) {
                                $_SESSION['master_log_file'] = $file;