Added wfLogDBError() call to LoadBalancer::doWait()
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 6 Oct 2014 17:42:58 +0000 (10:42 -0700)
committerOri.livneh <ori@wikimedia.org>
Thu, 13 Nov 2014 21:34:54 +0000 (21:34 +0000)
Change-Id: Ida0970754a2a7287c129bb5ad633765dab97133a

includes/GlobalFunctions.php
includes/db/LoadBalancer.php

index eab8031..81f767d 100644 (file)
@@ -1789,52 +1789,37 @@ function wfDebugBacktrace( $limit = 0 ) {
 /**
  * Get a debug backtrace as a string
  *
+ * @param bool|null $raw If true, the return value is plain text. If false, HTML.
+ *   Defaults to $wgCommandLineMode if unset.
  * @return string
+ * @since 1.25 Supports $raw parameter.
  */
-function wfBacktrace() {
+function wfBacktrace( $raw = null ) {
        global $wgCommandLineMode;
 
-       if ( $wgCommandLineMode ) {
-               $msg = '';
-       } else {
-               $msg = "<ul>\n";
+       if ( $raw === null ) {
+               $raw = $wgCommandLineMode;
        }
-       $backtrace = wfDebugBacktrace();
-       foreach ( $backtrace as $call ) {
-               if ( isset( $call['file'] ) ) {
-                       $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
-                       $file = $f[count( $f ) - 1];
-               } else {
-                       $file = '-';
-               }
-               if ( isset( $call['line'] ) ) {
-                       $line = $call['line'];
-               } else {
-                       $line = '-';
-               }
-               if ( $wgCommandLineMode ) {
-                       $msg .= "$file line $line calls ";
-               } else {
-                       $msg .= '<li>' . $file . ' line ' . $line . ' calls ';
-               }
-               if ( !empty( $call['class'] ) ) {
-                       $msg .= $call['class'] . $call['type'];
-               }
-               $msg .= $call['function'] . '()';
 
-               if ( $wgCommandLineMode ) {
-                       $msg .= "\n";
-               } else {
-                       $msg .= "</li>\n";
-               }
-       }
-       if ( $wgCommandLineMode ) {
-               $msg .= "\n";
+       if ( $raw ) {
+               $frameFormat = "%s line %s calls %s()\n";
+               $traceFormat = "%s";
        } else {
-               $msg .= "</ul>\n";
+               $frameFormat = "<li>%s line %s calls %s()</li>\n";
+               $traceFormat = "<ul>\n%s</ul>\n";
        }
 
-       return $msg;
+       $frames = array_map( function ( $frame ) use ( $frameFormat ) {
+               $file = !empty( $frame['file'] ) ? basename( $frame['file'] ) : '-';
+               $line = $frame['line'] ?: '-';
+               $call = $frame['function'];
+               if ( !empty( $frame['class'] ) ) {
+                       $call = $frame['class'] . $frame['type'] . $call;
+               }
+               return sprintf( $frameFormat, $file, $line, $call );
+       }, wfDebugBacktrace() );
+
+       return sprintf( $traceFormat, implode( '', $frames ) );
 }
 
 /**
index eeb2fec..0fb2d09 100644 (file)
@@ -410,7 +410,10 @@ class LoadBalancer {
 
                if ( $result == -1 || is_null( $result ) ) {
                        # Timed out waiting for slave, use master instead
-                       wfDebug( __METHOD__ . ": Timed out waiting for slave #$index pos {$this->mWaitForPos}\n" );
+                       $server = $this->mServers[$index];
+                       $msg = __METHOD__ . ": Timed out waiting on $server pos {$this->mWaitForPos}";
+                       wfDebug( "$msg\n" );
+                       wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) );
                        $ok = false;
                } else {
                        wfDebug( __METHOD__ . ": Done\n" );