Avoid certain useless dbperformance log entries
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 13 Mar 2015 01:50:05 +0000 (18:50 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 13 Mar 2015 01:50:05 +0000 (18:50 -0700)
* If DB_SLAVE was used but a master was picked due to having
  non-zero load, that should not issue a warning.

Change-Id: I79f3c477b4160b15ffb7f7679d7e15cabc236b82

includes/db/LoadBalancer.php

index dd95844..4e0a5b9 100644 (file)
@@ -471,6 +471,9 @@ class LoadBalancer {
                        ? array( false ) // check one "group": the generic pool
                        : (array)$groups;
 
+               $masterOnly = ( $i == DB_MASTER || $i == $this->getWriterIndex() );
+               $oldConnsOpened = $this->connsOpened; // connections open now
+
                if ( $i == DB_MASTER ) {
                        $i = $this->getWriterIndex();
                } else {
@@ -506,6 +509,14 @@ class LoadBalancer {
                        return $this->reportConnectionError();
                }
 
+               # Profile any new connections that happen
+               if ( $this->connsOpened > $oldConnsOpened ) {
+                       $host = $conn->getServer();
+                       $dbname = $conn->getDBname();
+                       $trxProf = Profiler::instance()->getTransactionProfiler();
+                       $trxProf->recordConnection( $host, $dbname, $masterOnly );
+               }
+
                return $conn;
        }
 
@@ -756,10 +767,6 @@ class LoadBalancer {
                        $db = $e->db;
                }
 
-               $isMaster = !empty( $server['master'] );
-               $trxProf = Profiler::instance()->getTransactionProfiler();
-               $trxProf->recordConnection( $server['host'], $server['dbname'], $isMaster );
-
                $db->setLBInfo( $server );
                if ( isset( $server['fakeSlaveLag'] ) ) {
                        $db->setFakeSlaveLag( $server['fakeSlaveLag'] );