Make NameTableStore use LoadBalancer::getConnectionRef()
authorAaron Schulz <aschulz@wikimedia.org>
Sun, 4 Aug 2019 03:38:54 +0000 (23:38 -0400)
committerAaron Schulz <aschulz@wikimedia.org>
Sun, 25 Aug 2019 01:24:16 +0000 (01:24 +0000)
This method handles reuseConnection() calls, disallows writes to
DB_REPLICA role handles, is more consistent with wfGetDB(), and
is more efficient with I540b08920997c5.

Change-Id: I8edaef0ea4718414e2004fad04afca8ec5797669

includes/Storage/NameTableStore.php
tests/phpunit/includes/Storage/NameTableStoreTest.php

index 5ef0304..f8a1f5c 100644 (file)
@@ -111,7 +111,7 @@ class NameTableStore {
         * @return IDatabase
         */
        private function getDBConnection( $index, $flags = 0 ) {
-               return $this->loadBalancer->getConnection( $index, [], $this->domain, $flags );
+               return $this->loadBalancer->getConnectionRef( $index, [], $this->domain, $flags );
        }
 
        /**
index 47d3b92..7a4ea2d 100644 (file)
@@ -12,6 +12,7 @@ use Psr\Log\NullLogger;
 use WANObjectCache;
 use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\MaintainableDBConnRef;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -51,8 +52,10 @@ class NameTableStoreTest extends MediaWikiTestCase {
                        ->disableOriginalConstructor()
                        ->getMock();
                $mock->expects( $this->any() )
-                       ->method( 'getConnection' )
-                       ->willReturn( $db );
+                       ->method( 'getConnectionRef' )
+                       ->willReturnCallback( function ( $i ) use ( $mock, $db ) {
+                               return new MaintainableDBConnRef( $mock, $db, $i );
+                       } );
                return $mock;
        }