Aaron Schulz has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/404056 )
Change subject: rdbms: specify DB name and table prefix even for the local
domain
......................................................................
rdbms: specify DB name and table prefix even for the local domain
When LoadBalancer opens new local domain connections, it currently
assumes that the domain specified by the server info array is the
same. For sanity, make sure that the handle is set to the local
domain.
The main LBFactory/LoadBalancer use $wgDBname/$wgDBprefix as the
local domain, corresponding with wfWikiId(). This relation is set
automatically in MWLBFactory. If $wgLBFactoryConf/$wgDBservers is
manually configured in a way breaking this correspondance, then it
is misconfigured.
Change-Id: I56f8b32fe957f984b8c9753e6db3b20abe96b038
---
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
M includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php
2 files changed, 12 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/56/404056/1
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index a75dc4d..9977442 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -810,9 +810,10 @@
$server = $this->mServers[$i];
$server['serverIndex'] = $i;
$server['autoCommitOnly'] = $autoCommit;
- $conn = $this->reallyOpenConnection( $server,
false );
+ $conn = $this->reallyOpenConnection( $server,
$this->localDomain->getDatabase() );
$host = $this->getServerName( $i );
if ( $conn->isOpen() ) {
+ $conn->tablePrefix(
$this->localDomain->getTablePrefix() ); // local domain
$this->connLogger->debug( "Connected to
database $i at '$host'." );
$this->mConns[$connKey][$i][0] = $conn;
} else {
@@ -888,8 +889,9 @@
// Reuse a free connection from another domain
$conn = reset( $this->mConns[$connFreeKey][$i] );
$oldDomain = key( $this->mConns[$connFreeKey][$i] );
- // The empty string as a DB name means "don't care".
- // DatabaseMysqlBase::open() already handle this on
connection.
+ // Change the domain of the handle to that of $domain.
If $domain uses an empty
+ // string to specify the DB name, that means that the
caller doesn't care what
+ // database is selected for use (e.g. leave it as is).
if ( strlen( $dbName ) && !$conn->selectDB( $dbName ) )
{
$this->mLastError = "Error selecting database
'$dbName' on server " .
$conn->getServer() . " from client host
{$this->host}";
@@ -918,7 +920,7 @@
$this->errorConnection = $conn;
$conn = false;
} else {
- $conn->tablePrefix( $prefix );
+ $conn->tablePrefix( $prefix ); // as specified
$this->mConns[$connInUseKey][$i][$domain] =
$conn;
$this->connLogger->debug( __METHOD__ . ":
opened new connection for $i/$domain" );
}
@@ -949,24 +951,22 @@
}
/**
- * Really opens a connection. Uncached.
+ * Open a new network connection to a server (uncached)
+ *
* Returns a Database object whether or not the connection was
successful.
- * @access private
*
* @param array $server
- * @param string|bool $dbNameOverride Use "" to not select any database
+ * @param string $dbNameOverride Use "" to not select any database
* @return Database
* @throws DBAccessError
* @throws InvalidArgumentException
*/
- protected function reallyOpenConnection( array $server, $dbNameOverride
= false ) {
+ protected function reallyOpenConnection( array $server, $dbNameOverride
) {
if ( $this->disabled ) {
throw new DBAccessError();
}
- if ( $dbNameOverride !== false ) {
- $server['dbname'] = $dbNameOverride;
- }
+ $server['dbname'] = $dbNameOverride;
// Let the handle know what the cluster master is (e.g.
"db1052")
$masterName = $this->getServerName( $this->getWriterIndex() );
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php
b/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php
index 79d250f..c737563 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php
@@ -72,7 +72,7 @@
return new static( [ 'connection' => $db ] + $params );
}
- protected function reallyOpenConnection( array $server, $dbNameOverride
= false ) {
+ protected function reallyOpenConnection( array $server, $dbNameOverride
) {
return $this->db;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/404056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I56f8b32fe957f984b8c9753e6db3b20abe96b038
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits