Fixed getReaderIndex() handling of $group
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 15 Jan 2014 18:20:52 +0000 (10:20 -0800)
committerTim Starling <tstarling@wikimedia.org>
Thu, 30 Jan 2014 22:36:26 +0000 (22:36 +0000)
* Connections for a group should not override the generic connection handle.
  That can cause special DBs to be reused for general queries more so than
  optimal.
* Also made the code use ProfileSection to clean it up a bit.

Change-Id: Ia8973133a93410bd906d8ad52a711a7d810df2f6

includes/db/LoadBalancer.php

index 7d0fe34..c622afe 100644 (file)
@@ -203,7 +203,7 @@ class LoadBalancer {
                        return $this->mReadIndex;
                }
 
-               wfProfileIn( __METHOD__ );
+               $section = new ProfileSection( __METHOD__ );
 
                # Find the relevant load array
                if ( $group !== false ) {
@@ -212,7 +212,6 @@ class LoadBalancer {
                        } else {
                                # No loads for this group, return false and the caller can use some other group
                                wfDebug( __METHOD__ . ": no loads for group $group\n" );
-                               wfProfileOut( __METHOD__ );
 
                                return false;
                        }
@@ -221,7 +220,6 @@ class LoadBalancer {
                }
 
                if ( !count( $nonErrorLoads ) ) {
-                       wfProfileOut( __METHOD__ );
                        throw new MWException( "Empty server array given to LoadBalancer" );
                }
 
@@ -255,7 +253,6 @@ class LoadBalancer {
                                # This is permanent and means the configuration or the load monitor
                                # wants us to return false.
                                wfDebugLog( 'connect', __METHOD__ . ": pickRandom() returned false\n" );
-                               wfProfileOut( __METHOD__ );
 
                                return false;
                        }
@@ -294,11 +291,10 @@ class LoadBalancer {
                                        $this->mServers[$i]['slave pos'] = $conn->getSlavePos();
                                }
                        }
-                       if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $i !== false ) {
+                       if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $group !== false ) {
                                $this->mReadIndex = $i;
                        }
                }
-               wfProfileOut( __METHOD__ );
 
                return $i;
        }