rdbms: Group disconnect/reconnect errors by DB server name
authorChad Horohoe <chadh@wikimedia.org>
Thu, 26 Oct 2017 20:43:49 +0000 (13:43 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 27 Oct 2017 20:09:45 +0000 (20:09 +0000)
Still allow varying on stacktrace, as those are interesting

Change-Id: I62bc3f68fcbe43532dce849d515a5e0620fba6f2

includes/libs/rdbms/database/Database.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php

index c04e167..a9dd074 100644 (file)
@@ -945,10 +945,12 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        # Update state tracking to reflect transaction loss due to disconnection
                        $this->handleSessionLoss();
                        if ( $this->reconnect() ) {
-                               $msg = __METHOD__ . ": lost connection to {$this->getServer()}; reconnected";
-                               $this->connLogger->warning( $msg );
+                               $msg = __METHOD__ . ': lost connection to {dbserver}; reconnected';
+                               $params = [ 'dbserver' => $this->getServer() ];
+                               $this->connLogger->warning( $msg, $params );
                                $this->queryLogger->warning(
-                                       "$msg:\n" . ( new RuntimeException() )->getTraceAsString() );
+                                       "$msg:\n" . ( new RuntimeException() )->getTraceAsString(),
+                                       $params );
 
                                if ( !$recoverable ) {
                                        # Callers may catch the exception and continue to use the DB
@@ -958,8 +960,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                        $ret = $this->doProfiledQuery( $sql, $commentedSql, $isNonTempWrite, $fname );
                                }
                        } else {
-                               $msg = __METHOD__ . ": lost connection to {$this->getServer()} permanently";
-                               $this->connLogger->error( $msg );
+                               $msg = __METHOD__ . ': lost connection to {dbserver} permanently';
+                               $this->connLogger->error( $msg, [ 'dbserver' => $this->getServer() ] );
                        }
                }
 
index 8393e2b..1be8926 100644 (file)
@@ -568,7 +568,8 @@ class LoadBalancer implements ILoadBalancer {
                        $knownReachedPos->hasReached( $this->mWaitForPos )
                ) {
                        $this->replLogger->debug( __METHOD__ .
-                               ": replica DB $server known to be caught up (pos >= $knownReachedPos)." );
+                               ': replica DB {dbserver} known to be caught up (pos >= $knownReachedPos).',
+                               [ 'dbserver' => $server ] );
                        return true;
                }
 
@@ -576,13 +577,15 @@ class LoadBalancer implements ILoadBalancer {
                $conn = $this->getAnyOpenConnection( $index );
                if ( !$conn ) {
                        if ( !$open ) {
-                               $this->replLogger->debug( __METHOD__ . ": no connection open for $server" );
+                               $this->replLogger->debug( __METHOD__ . ': no connection open for {dbserver}',
+                                       [ 'dbserver' => $server ] );
 
                                return false;
                        } else {
                                $conn = $this->openConnection( $index, self::DOMAIN_ANY );
                                if ( !$conn ) {
-                                       $this->replLogger->warning( __METHOD__ . ": failed to connect to $server" );
+                                       $this->replLogger->warning( __METHOD__ . ': failed to connect to {dbserver}',
+                                               [ 'dbserver' => $server ] );
 
                                        return false;
                                }
@@ -592,7 +595,8 @@ class LoadBalancer implements ILoadBalancer {
                        }
                }
 
-               $this->replLogger->info( __METHOD__ . ": Waiting for replica DB $server to catch up..." );
+               $this->replLogger->info( __METHOD__ . ': Waiting for replica DB {dbserver} to catch up...',
+                       [ 'dbserver' => $server ] );
                $timeout = $timeout ?: $this->mWaitTimeout;
                $result = $conn->masterPosWait( $this->mWaitForPos, $timeout );