rdbms: make $i in LoadBalancer::getConnection override $groups
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 12 Apr 2018 20:15:34 +0000 (13:15 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 12 Apr 2018 20:48:04 +0000 (20:48 +0000)
Previously, passing a specific server index (even the master index)
would result in a connection to some server in $groups or the generic
read group being selected.

Change-Id: Ifb497f5f4bb61f16b310d4d30fb8315e3bcdce8e

includes/libs/rdbms/loadbalancer/ILoadBalancer.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php

index 715f4e4..ce042f0 100644 (file)
@@ -181,7 +181,7 @@ interface ILoadBalancer {
         * call ILoadBalancer::reuseConnection() on the handle when finished using it.
         * In all other cases, this is not necessary, though not harmful either.
         *
         * call ILoadBalancer::reuseConnection() on the handle when finished using it.
         * In all other cases, this is not necessary, though not harmful either.
         *
-        * @param int $i Server index or DB_MASTER/DB_REPLICA
+        * @param int $i Server index (overrides $groups) or DB_MASTER/DB_REPLICA
         * @param array|string|bool $groups Query group(s), or false for the generic reader
         * @param string|bool $domain Domain ID, or false for the current domain
         * @param int $flags Bitfield of CONN_* class constants
         * @param array|string|bool $groups Query group(s), or false for the generic reader
         * @param string|bool $domain Domain ID, or false for the current domain
         * @param int $flags Bitfield of CONN_* class constants
index 94acc1e..0ed3f80 100644 (file)
@@ -714,7 +714,7 @@ class LoadBalancer implements ILoadBalancer {
 
                if ( $i == self::DB_MASTER ) {
                        $i = $this->getWriterIndex();
 
                if ( $i == self::DB_MASTER ) {
                        $i = $this->getWriterIndex();
-               } else {
+               } elseif ( $i == self::DB_REPLICA ) {
                        # Try to find an available server in any the query groups (in order)
                        foreach ( $groups as $group ) {
                                $groupIndex = $this->getReaderIndex( $group, $domain );
                        # Try to find an available server in any the query groups (in order)
                        foreach ( $groups as $group ) {
                                $groupIndex = $this->getReaderIndex( $group, $domain );