Merge "rdbms: make DOMAIN_ANY ignore bogus MySQL DB names in config"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 9 Feb 2018 13:47:40 +0000 (13:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 9 Feb 2018 13:47:40 +0000 (13:47 +0000)
includes/libs/rdbms/database/DatabaseMysqlBase.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
tests/phpunit/includes/db/LBFactoryTest.php

index 208f506..fcedf56 100644 (file)
@@ -159,7 +159,7 @@ abstract class DatabaseMysqlBase extends Database {
                        $this->reportConnectionError( $error );
                }
 
-               if ( $dbName != '' ) {
+               if ( strlen( $dbName ) ) {
                        MediaWiki\suppressWarnings();
                        $success = $this->selectDB( $dbName );
                        MediaWiki\restoreWarnings();
index f410882..d070c1e 100644 (file)
@@ -1006,7 +1006,17 @@ class LoadBalancer implements ILoadBalancer {
                        throw new DBAccessError();
                }
 
-               if ( $domainOverride->getDatabase() !== null ) {
+               // Handle $domainOverride being a specified or an unspecified domain
+               if ( $domainOverride->getDatabase() === null ) {
+                       // Normally, an RDBMS requires a DB name specified on connection and the $server
+                       // configuration array is assumed to already specify an appropriate DB name.
+                       if ( $server['type'] === 'mysql' ) {
+                               // For MySQL, DATABASE and SCHEMA are synonyms, connections need not specify a DB,
+                               // and the DB name in $server might not exist due to legacy reasons (the default
+                               // domain used to ignore the local LB domain, even when mismatched).
+                               $server['dbname'] = null;
+                       }
+               } else {
                        $server['dbname'] = $domainOverride->getDatabase();
                        $server['schema'] = $domainOverride->getSchema();
                }
index fa1cfc9..356ebe5 100644 (file)
@@ -376,14 +376,14 @@ class LBFactoryTest extends MediaWikiTestCase {
                $db = $lb->getConnection( DB_MASTER, [], '' );
 
                $this->assertEquals(
-                       $wgDBname,
+                       '',
                        $db->getDomainId(),
-                       'Main domain ID handle used; same DB name'
+                       'Null domain ID handle used'
                );
                $this->assertEquals(
-                       $wgDBname,
+                       '',
                        $db->getDBname(),
-                       'Main domain ID handle used; same DB name'
+                       'Null domain ID handle used'
                );
                $this->assertEquals(
                        '',
@@ -446,16 +446,16 @@ class LBFactoryTest extends MediaWikiTestCase {
                $dbname = 'unittest-domain'; // explodes if DB is selected
                $factory = $this->newLBFactoryMulti(
                        [ 'localDomain' => ( new DatabaseDomain( $dbname, null, '' ) )->getId() ],
-                       [ 'dbFilePath' => $dbPath ]
+                       [
+                               'dbFilePath' => $dbPath,
+                               'dbName' => 'do_not_select_me' // explodes if DB is selected
+                       ]
                );
                $lb = $factory->getMainLB();
                /** @var Database $db */
                $db = $lb->getConnection( DB_MASTER, [], '' );
 
-               $this->assertEquals(
-                       $wgDBname,
-                       $db->getDomainID()
-               );
+               $this->assertEquals( '', $db->getDomainID(), "Null domain used" );
 
                $this->assertEquals(
                        $this->quoteTable( $db, 'page' ),