[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make database classes handle hyphens in $wgDBname
jenkins-bot has submitted this change and it was merged. Change subject: Make database classes handle hyphens in $wgDBname .. Make database classes handle hyphens in $wgDBname * Add DatabaseDomain class to handle passing domains around. It also can be cast to and from strings, which are of the same format as wfWikiId() except with hyphens escaped. * Make IDatabase::getDomainID() use these IDs so they can be passed into LoadBalancer::getConnection() and friends without breaking on sites with a hyphen in the DB name. * Add more LBFactory unit tests for domains. Bug: T145840 Change-Id: Icfed62b251af8cef706a899197c3ccdb730ef4d1 --- M autoload.php M includes/db/loadbalancer/LBFactoryMW.php M includes/libs/rdbms/database/DBConnRef.php M includes/libs/rdbms/database/Database.php A includes/libs/rdbms/database/DatabaseDomain.php M includes/libs/rdbms/lbfactory/LBFactory.php M includes/libs/rdbms/loadbalancer/LoadBalancer.php M tests/phpunit/includes/db/LBFactoryTest.php A tests/phpunit/includes/libs/rdbms/database/DatabaseDomainTest.php 9 files changed, 469 insertions(+), 24 deletions(-) Approvals: Aaron Schulz: Looks good to me, but someone else must approve Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/autoload.php b/autoload.php index 716e56d..035c152 100644 --- a/autoload.php +++ b/autoload.php @@ -318,6 +318,7 @@ 'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php', 'Database' => __DIR__ . '/includes/libs/rdbms/database/Database.php', 'DatabaseBase' => __DIR__ . '/includes/libs/rdbms/database/DatabaseBase.php', + 'DatabaseDomain' => __DIR__ . '/includes/libs/rdbms/database/DatabaseDomain.php', 'DatabaseInstaller' => __DIR__ . '/includes/installer/DatabaseInstaller.php', 'DatabaseLag' => __DIR__ . '/maintenance/lag.php', 'DatabaseLogEntry' => __DIR__ . '/includes/logging/LogEntry.php', diff --git a/includes/db/loadbalancer/LBFactoryMW.php b/includes/db/loadbalancer/LBFactoryMW.php index 49d0624..16faeb7 100644 --- a/includes/db/loadbalancer/LBFactoryMW.php +++ b/includes/db/loadbalancer/LBFactoryMW.php @@ -37,10 +37,10 @@ * @TODO: inject objects via dependency framework */ public function __construct( array $conf ) { - global $wgCommandLineMode, $wgSQLMode, $wgDBmysql5; + global $wgCommandLineMode, $wgSQLMode, $wgDBmysql5, $wgDBname, $wgDBprefix; $defaults = [ - 'localDomain' => wfWikiID(), + 'localDomain' => new DatabaseDomain( $wgDBname, null, $wgDBprefix ), 'hostname' => wfHostname(), 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), 'replLogger' => LoggerFactory::getInstance( 'DBReplication' ), diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index 876ee30..0d9b692 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -14,22 +14,22 @@ /** @var IDatabase|null Live connection handle */ private $conn; - /** @var array|null */ + /** @var array|null N-tuple of (server index, group, DatabaseDomain|string) */ private $params; const FLD_INDEX = 0; const FLD_GROUP = 1; - const FLD_WIKI = 2; + const FLD_DOMAIN = 2; /** * @param ILoadBalancer $lb -* @param IDatabase|array $conn Connection or (server index, group, wiki ID) +* @param IDatabase|array $conn Connection or (server index, group, DatabaseDomain|string) */ public function __construct( ILoadBalancer $lb, $conn ) { $this->lb = $lb; if ( $conn instanceof IDatabase ) { $this->conn = $conn; // live handle - } elseif ( count( $conn ) >= 3 && $conn[self::FLD_WIKI] !== false ) { + } elseif ( count( $conn ) >= 3 && $conn[self::FLD_DOMAIN] !== false ) { $this->params = $conn; } else { throw new InvalidArgumentException( "Missing lazy connection arguments." ); @@ -147,8 +147,9 @@ public function getDomainID() { if ( $this->conn === null ) { - // Avoid triggering a connection - return $this->params[self::FLD_WIKI]; + $domain = $this->params[self::FLD_DOMAIN]; + // Avoid triggering a database connection + return $domain instanceof DatabaseDomain ? $domain->getId() : $domain; } return $this->__call( __FUNCTION__, func_get_args() ); diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 9a63b7f..4cab119
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make database classes handle hyphens in $wgDBname
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/311222 Change subject: Make database classes handle hyphens in $wgDBname .. Make database classes handle hyphens in $wgDBname * Add DatabaseDomain class to handle passing domains around. It also can be cast to and from strings, which are of the same format as wfWikiId() except with hyphens escaped. * Make IDatabase::getDomainID() use these IDs so they can be passed into LoadBalancer::getConnection() and friends without breaking on sites with a hyphen in the DB name. * Add more LBFactory unit tests for domains. Bug: T145840 Change-Id: Icfed62b251af8cef706a899197c3ccdb730ef4d1 --- M autoload.php M includes/db/loadbalancer/LBFactoryMW.php M includes/libs/rdbms/database/DBConnRef.php M includes/libs/rdbms/database/Database.php A includes/libs/rdbms/database/DatabaseDomain.php M includes/libs/rdbms/lbfactory/LBFactory.php M includes/libs/rdbms/loadbalancer/LoadBalancer.php M tests/phpunit/includes/db/LBFactoryTest.php 8 files changed, 381 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/22/311222/1 diff --git a/autoload.php b/autoload.php index 716e56d..035c152 100644 --- a/autoload.php +++ b/autoload.php @@ -318,6 +318,7 @@ 'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php', 'Database' => __DIR__ . '/includes/libs/rdbms/database/Database.php', 'DatabaseBase' => __DIR__ . '/includes/libs/rdbms/database/DatabaseBase.php', + 'DatabaseDomain' => __DIR__ . '/includes/libs/rdbms/database/DatabaseDomain.php', 'DatabaseInstaller' => __DIR__ . '/includes/installer/DatabaseInstaller.php', 'DatabaseLag' => __DIR__ . '/maintenance/lag.php', 'DatabaseLogEntry' => __DIR__ . '/includes/logging/LogEntry.php', diff --git a/includes/db/loadbalancer/LBFactoryMW.php b/includes/db/loadbalancer/LBFactoryMW.php index 49d0624..16faeb7 100644 --- a/includes/db/loadbalancer/LBFactoryMW.php +++ b/includes/db/loadbalancer/LBFactoryMW.php @@ -37,10 +37,10 @@ * @TODO: inject objects via dependency framework */ public function __construct( array $conf ) { - global $wgCommandLineMode, $wgSQLMode, $wgDBmysql5; + global $wgCommandLineMode, $wgSQLMode, $wgDBmysql5, $wgDBname, $wgDBprefix; $defaults = [ - 'localDomain' => wfWikiID(), + 'localDomain' => new DatabaseDomain( $wgDBname, null, $wgDBprefix ), 'hostname' => wfHostname(), 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), 'replLogger' => LoggerFactory::getInstance( 'DBReplication' ), diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index 876ee30..f111fdf 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -14,22 +14,22 @@ /** @var IDatabase|null Live connection handle */ private $conn; - /** @var array|null */ + /** @var array|null N-tuple of (server index, group, DatabaseDomain|string) */ private $params; const FLD_INDEX = 0; const FLD_GROUP = 1; - const FLD_WIKI = 2; + const FLD_DOMAIN = 2; /** * @param ILoadBalancer $lb -* @param IDatabase|array $conn Connection or (server index, group, wiki ID) +* @param IDatabase|array $conn Connection or (server index, group, DatabaseDomain|string) */ public function __construct( ILoadBalancer $lb, $conn ) { $this->lb = $lb; if ( $conn instanceof IDatabase ) { $this->conn = $conn; // live handle - } elseif ( count( $conn ) >= 3 && $conn[self::FLD_WIKI] !== false ) { + } elseif ( count( $conn ) >= 3 && $conn[self::FLD_DOMAIN] !== false ) { $this->params = $conn; } else { throw new InvalidArgumentException( "Missing lazy connection arguments." ); @@ -146,9 +146,10 @@ } public function getDomainID() { - if ( $this->conn === null ) { - // Avoid triggering a connection - return $this->params[self::FLD_WIKI]; + if ( !$this->conn ) { + $domain = $this->params[self::FLD_DOMAIN]; + // Avoid triggering a database connection + return $domain instanceof DatabaseDomain ? $domain->getId() : $domain; } return $this->__call( __FUNCTION__, func_get_args() ); diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 9a63b7f..f13db72 100644 ---