[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add LoadBalancer::getMaintenanceConnectionRef() method
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/323883 ) Change subject: Add LoadBalancer::getMaintenanceConnectionRef() method .. Add LoadBalancer::getMaintenanceConnectionRef() method This is useful when IMaintainableDatabase methods are needed for foreign wiki connections to things like external store. Also: * Set visibility for ExternalStoreDB methods. * Cleaned up various type hints and comments. Change-Id: Ie35b1ff21032cc4e78912dc499486da23aeba041 --- M autoload.php M includes/db/CloneDatabase.php M includes/externalstore/ExternalStoreDB.php M includes/libs/rdbms/database/DBConnRef.php M includes/libs/rdbms/database/Database.php M includes/libs/rdbms/database/IMaintainableDatabase.php A includes/libs/rdbms/database/MaintainableDBConnRef.php M includes/libs/rdbms/loadbalancer/ILoadBalancer.php M includes/libs/rdbms/loadbalancer/LoadBalancer.php M tests/phpunit/MediaWikiTestCase.php 10 files changed, 161 insertions(+), 67 deletions(-) Approvals: Krinkle: Looks good to me, approved Addshore: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/autoload.php b/autoload.php index e079686..66a9e9b 100644 --- a/autoload.php +++ b/autoload.php @@ -803,6 +803,7 @@ 'MagicWordArray' => __DIR__ . '/includes/MagicWordArray.php', 'MailAddress' => __DIR__ . '/includes/mail/MailAddress.php', 'MainConfigDependency' => __DIR__ . '/includes/cache/CacheDependency.php', + 'MaintainableDBConnRef' => __DIR__ . '/includes/libs/rdbms/database/MaintainableDBConnRef.php', 'Maintenance' => __DIR__ . '/maintenance/Maintenance.php', 'MaintenanceFormatInstallDoc' => __DIR__ . '/maintenance/formatInstallDoc.php', 'MakeTestEdits' => __DIR__ . '/maintenance/makeTestEdits.php', diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index f1ccd2a..2b394b6 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -41,19 +41,19 @@ /** @var bool Whether to use temporary tables or not */ private $useTemporaryTables = true; - /** @var Database */ + /** @var IMaintainableDatabase */ private $db; /** * Constructor * -* @param Database $db A database subclass +* @param IMaintainableDatabase $db A database subclass * @param array $tablesToClone An array of tables to clone, unprefixed * @param string $newTablePrefix Prefix to assign to the tables * @param string $oldTablePrefix Prefix on current tables, if not $wgDBprefix * @param bool $dropCurrentTables */ - public function __construct( Database $db, array $tablesToClone, + public function __construct( IMaintainableDatabase $db, array $tablesToClone, $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true ) { $this->db = $db; @@ -107,7 +107,8 @@ # Create new table wfDebug( __METHOD__ . " duplicating $oldTableName to $newTableName\n" ); - $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables ); + $this->db->duplicateTableStructure( + $oldTableName, $newTableName, $this->useTemporaryTables ); } } diff --git a/includes/externalstore/ExternalStoreDB.php b/includes/externalstore/ExternalStoreDB.php index 7e93299..52c1a4c 100644 --- a/includes/externalstore/ExternalStoreDB.php +++ b/includes/externalstore/ExternalStoreDB.php @@ -105,7 +105,7 @@ * @param string $cluster Cluster name * @return LoadBalancer */ - function getLoadBalancer( $cluster ) { + private function getLoadBalancer( $cluster ) { $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false; return wfGetLBFactory()->getExternalLB( $cluster, $wiki ); @@ -115,9 +115,9 @@ * Get a replica DB connection for the specified cluster * * @param string $cluster Cluster name -* @return IDatabase +* @return DBConnRef */ - function getSlave( $cluster ) { + public function getSlave( $cluster ) { global $wgDefaultExternalStore; $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false; @@ -140,13 +140,13 @@ * Get a master database connection for the specified cluster * * @param string $cluster Cluster name -* @return IDatabase +* @return MaintainableDBConnRef */ - function getMaster( $cluster ) { + public function getMaster( $cluster ) { $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false; $lb =
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add LoadBalancer::getMaintenanceConnectionRef() method
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/323883 Change subject: Add LoadBalancer::getMaintenanceConnectionRef() method .. Add LoadBalancer::getMaintenanceConnectionRef() method This is useful when IMaintainableDatabase methods are needed for foreign wiki connections to things like external store. Change-Id: Ie35b1ff21032cc4e78912dc499486da23aeba041 --- M includes/externalstore/ExternalStoreDB.php M includes/libs/rdbms/database/DBConnRef.php A includes/libs/rdbms/database/MaintainableDBConnRef.php M includes/libs/rdbms/loadbalancer/ILoadBalancer.php M includes/libs/rdbms/loadbalancer/LoadBalancer.php 5 files changed, 114 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/83/323883/1 diff --git a/includes/externalstore/ExternalStoreDB.php b/includes/externalstore/ExternalStoreDB.php index 7e93299..dc7d194 100644 --- a/includes/externalstore/ExternalStoreDB.php +++ b/includes/externalstore/ExternalStoreDB.php @@ -115,7 +115,7 @@ * Get a replica DB connection for the specified cluster * * @param string $cluster Cluster name -* @return IDatabase +* @return DBConnRef */ function getSlave( $cluster ) { global $wgDefaultExternalStore; @@ -140,7 +140,7 @@ * Get a master database connection for the specified cluster * * @param string $cluster Cluster name -* @return IDatabase +* @return DBConnRef */ function getMaster( $cluster ) { $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false; diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index 20198bf..b268b9f 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -10,10 +10,8 @@ class DBConnRef implements IDatabase { /** @var ILoadBalancer */ private $lb; - - /** @var IDatabase|null Live connection handle */ + /** @var Database|null Live connection handle */ private $conn; - /** @var array|null N-tuple of (server index, group, DatabaseDomain|string) */ private $params; @@ -22,12 +20,12 @@ const FLD_DOMAIN = 2; /** -* @param ILoadBalancer $lb -* @param IDatabase|array $conn Connection or (server index, group, DatabaseDomain|string) +* @param ILoadBalancer $lb Connection manager for $conn +* @param Database|array $conn New connection handle or (server index, query groups, domain) */ public function __construct( ILoadBalancer $lb, $conn ) { $this->lb = $lb; - if ( $conn instanceof IDatabase ) { + if ( $conn instanceof Database ) { $this->conn = $conn; // live handle } elseif ( count( $conn ) >= 3 && $conn[self::FLD_DOMAIN] !== false ) { $this->params = $conn; @@ -595,7 +593,7 @@ * Clean up the connection when out of scope */ function __destruct() { - if ( $this->conn !== null ) { + if ( $this->conn ) { $this->lb->reuseConnection( $this->conn ); } } diff --git a/includes/libs/rdbms/database/MaintainableDBConnRef.php b/includes/libs/rdbms/database/MaintainableDBConnRef.php new file mode 100644 index 000..ad54ad8 --- /dev/null +++ b/includes/libs/rdbms/database/MaintainableDBConnRef.php @@ -0,0 +1,62 @@ +__call( __FUNCTION__, func_get_args() ); + } + + public function tableNames() { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function tableNamesN() { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function sourceFile( + $filename, + callable $lineCallback = null, + callable $resultCallback = null, + $fname = false, + callable $inputCallback = null + ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function sourceStream( + $fp, + callable $lineCallback = null, + callable $resultCallback = null, + $fname = __METHOD__, + callable $inputCallback = null + ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function dropTable( $tableName, $fName = __METHOD__ ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function deadlockLoop() { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function listViews( $prefix = null, $fname = __METHOD__ ) { +