jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/338499 )
Change subject: Move remaining LoadBalancer classes to Rdbms ...................................................................... Move remaining LoadBalancer classes to Rdbms The old names are left as aliases. Change-Id: I52a327f2463a2ba7437324047b5b00d28cd1d758 --- M autoload.php M includes/GlobalFunctions.php M includes/MediaWikiServices.php M includes/WatchedItemQueryService.php M includes/WatchedItemStore.php M includes/dao/DBAccessBase.php M includes/deferred/DeferredUpdates.php M includes/externalstore/ExternalStoreDB.php M includes/libs/rdbms/connectionmanager/ConnectionManager.php M includes/libs/rdbms/lbfactory/ILBFactory.php M includes/libs/rdbms/lbfactory/LBFactory.php M includes/libs/rdbms/lbfactory/LBFactoryMulti.php M includes/libs/rdbms/lbfactory/LBFactorySimple.php M includes/libs/rdbms/lbfactory/LBFactorySingle.php M includes/libs/rdbms/loadbalancer/ILoadBalancer.php M includes/libs/rdbms/loadbalancer/LoadBalancer.php M includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php M includes/objectcache/SqlBagOStuff.php M includes/site/DBSiteStore.php M maintenance/backup.inc M maintenance/dumpTextPass.php M tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php M tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php 23 files changed, 76 insertions(+), 51 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/autoload.php b/autoload.php index b21310e..e5be333 100644 --- a/autoload.php +++ b/autoload.php @@ -1590,6 +1590,8 @@ 'Wikimedia\\Rdbms\\LBFactorySimple' => __DIR__ . '/includes/libs/rdbms/lbfactory/LBFactorySimple.php', 'Wikimedia\\Rdbms\\LBFactorySingle' => __DIR__ . '/includes/libs/rdbms/lbfactory/LBFactorySingle.php', 'Wikimedia\\Rdbms\\LikeMatch' => __DIR__ . '/includes/libs/rdbms/encasing/LikeMatch.php', + 'Wikimedia\\Rdbms\\LoadBalancer' => __DIR__ . '/includes/libs/rdbms/loadbalancer/LoadBalancer.php', + 'Wikimedia\\Rdbms\\LoadBalancerSingle' => __DIR__ . '/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php', 'Wikimedia\\Rdbms\\LoadMonitor' => __DIR__ . '/includes/libs/rdbms/loadmonitor/LoadMonitor.php', 'Wikimedia\\Rdbms\\LoadMonitorMySQL' => __DIR__ . '/includes/libs/rdbms/loadmonitor/LoadMonitorMySQL.php', 'Wikimedia\\Rdbms\\LoadMonitorNull' => __DIR__ . '/includes/libs/rdbms/loadmonitor/LoadMonitorNull.php', diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 46def53..3c3cdb8 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -28,7 +28,6 @@ use MediaWiki\Logger\LoggerFactory; use MediaWiki\Session\SessionManager; use Wikimedia\ScopedCallback; -use Wikimedia\Rdbms\LBFactory; // Hide compatibility functions from Doxygen /// @cond @@ -3085,7 +3084,7 @@ * or MediaWikiServices::getDBLoadBalancerFactory() instead. * * @param string|bool $wiki Wiki ID, or false for the current wiki - * @return LoadBalancer + * @return \Wikimedia\Rdbms\LoadBalancer */ function wfGetLB( $wiki = false ) { if ( $wiki === false ) { @@ -3101,7 +3100,7 @@ * * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancerFactory() instead. * - * @return LBFactory + * @return \Wikimedia\Rdbms\LBFactory */ function wfGetLBFactory() { return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index ac151e2..e44fefe 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -12,7 +12,7 @@ use Wikimedia\Rdbms\LBFactory; use LinkCache; use Liuggio\StatsdClient\Factory\StatsdDataFactory; -use LoadBalancer; +use Wikimedia\Rdbms\LoadBalancer; use MediaHandlerFactory; use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkRendererFactory; diff --git a/includes/WatchedItemQueryService.php b/includes/WatchedItemQueryService.php index c80e4a5..dd23310 100644 --- a/includes/WatchedItemQueryService.php +++ b/includes/WatchedItemQueryService.php @@ -2,6 +2,7 @@ use MediaWiki\Linker\LinkTarget; use Wikimedia\Assert\Assert; +use Wikimedia\Rdbms\LoadBalancer; /** * Class performing complex database queries related to WatchedItems. diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 858d87b..9af5310 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -5,6 +5,7 @@ use MediaWiki\MediaWikiServices; use Wikimedia\Assert\Assert; use Wikimedia\ScopedCallback; +use Wikimedia\Rdbms\LoadBalancer; /** * Storage layer class for WatchedItems. diff --git a/includes/dao/DBAccessBase.php b/includes/dao/DBAccessBase.php index 6a1bbd6..da660bd 100644 --- a/includes/dao/DBAccessBase.php +++ b/includes/dao/DBAccessBase.php @@ -1,5 +1,7 @@ <?php +use Wikimedia\Rdbms\LoadBalancer; + /** * Base class for objects that allow access to other wiki's databases using * the foreign database access mechanism implemented by LBFactoryMulti. diff --git a/includes/deferred/DeferredUpdates.php b/includes/deferred/DeferredUpdates.php index 05256ae..000b526 100644 --- a/includes/deferred/DeferredUpdates.php +++ b/includes/deferred/DeferredUpdates.php @@ -21,6 +21,7 @@ */ use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\LBFactory; +use Wikimedia\Rdbms\LoadBalancer; /** * Class for managing the deferred updates diff --git a/includes/externalstore/ExternalStoreDB.php b/includes/externalstore/ExternalStoreDB.php index 52c1a4c..d907c30 100644 --- a/includes/externalstore/ExternalStoreDB.php +++ b/includes/externalstore/ExternalStoreDB.php @@ -20,6 +20,8 @@ * @file */ +use Wikimedia\Rdbms\LoadBalancer; + /** * DB accessable external objects. * @@ -106,9 +108,7 @@ * @return LoadBalancer */ private function getLoadBalancer( $cluster ) { - $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false; - - return wfGetLBFactory()->getExternalLB( $cluster, $wiki ); + return wfGetLBFactory()->getExternalLB( $cluster ); } /** diff --git a/includes/libs/rdbms/connectionmanager/ConnectionManager.php b/includes/libs/rdbms/connectionmanager/ConnectionManager.php index 4f72f77..fc00965 100644 --- a/includes/libs/rdbms/connectionmanager/ConnectionManager.php +++ b/includes/libs/rdbms/connectionmanager/ConnectionManager.php @@ -6,7 +6,6 @@ use DBConnRef; use IDatabase; use InvalidArgumentException; -use LoadBalancer; /** * Database connection manager. diff --git a/includes/libs/rdbms/lbfactory/ILBFactory.php b/includes/libs/rdbms/lbfactory/ILBFactory.php index 7b9b1cf..faf7fb1 100644 --- a/includes/libs/rdbms/lbfactory/ILBFactory.php +++ b/includes/libs/rdbms/lbfactory/ILBFactory.php @@ -24,7 +24,6 @@ namespace Wikimedia\Rdbms; use InvalidArgumentException; -use LoadBalancer; use DBTransactionError; use DBReplicationWaitError; diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index b2bd7ca..c4229bc 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -31,7 +31,6 @@ use Exception; use RuntimeException; use IDatabase; -use LoadBalancer; use DBTransactionError; use DBReplicationWaitError; diff --git a/includes/libs/rdbms/lbfactory/LBFactoryMulti.php b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php index bb6e445..447b96f 100644 --- a/includes/libs/rdbms/lbfactory/LBFactoryMulti.php +++ b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php @@ -23,7 +23,6 @@ namespace Wikimedia\Rdbms; -use LoadBalancer; use IDatabase; use InvalidArgumentException; diff --git a/includes/libs/rdbms/lbfactory/LBFactorySimple.php b/includes/libs/rdbms/lbfactory/LBFactorySimple.php index 1f5f93f..15cd508 100644 --- a/includes/libs/rdbms/lbfactory/LBFactorySimple.php +++ b/includes/libs/rdbms/lbfactory/LBFactorySimple.php @@ -23,7 +23,6 @@ namespace Wikimedia\Rdbms; -use LoadBalancer; use InvalidArgumentException; /** diff --git a/includes/libs/rdbms/lbfactory/LBFactorySingle.php b/includes/libs/rdbms/lbfactory/LBFactorySingle.php index f992643..5931d80 100644 --- a/includes/libs/rdbms/lbfactory/LBFactorySingle.php +++ b/includes/libs/rdbms/lbfactory/LBFactorySingle.php @@ -23,7 +23,6 @@ namespace Wikimedia\Rdbms; -use LoadBalancerSingle; use IDatabase; use InvalidArgumentException; use BadMethodCallException; diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php index 4e6f6b0..4c277ff 100644 --- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php @@ -240,9 +240,6 @@ * Index must be an actual index into the array. * If the server is already open, returns it. * - * On error, returns false, and the connection which caused the - * error will be available via $this->mErrorConnection. - * * @note If disable() was called on this LoadBalancer, this method will throw a DBAccessError. * * @param int $i Server index or DB_MASTER/DB_REPLICA diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index b1c0cc8..6878712 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -20,14 +20,29 @@ * @file * @ingroup Database */ +namespace Wikimedia\Rdbms; + use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Wikimedia\ScopedCallback; -use Wikimedia\Rdbms\TransactionProfiler; -use Wikimedia\Rdbms\ILoadMonitor; -use Wikimedia\Rdbms\DatabaseDomain; -use Wikimedia\Rdbms\ILoadBalancer; -use Wikimedia\Rdbms\DBMasterPos; +use IDatabase; +use Database; +use DBConnRef; +use MaintainableDBConnRef; +use BagOStuff; +use EmptyBagOStuff; +use WANObjectCache; +use ArrayUtils; +use DBError; +use DBAccessError; +use DBExpectedError; +use DBUnexpectedError; +use DBTransactionError; +use DBTransactionSizeError; +use DBConnectionError; +use InvalidArgumentException; +use RuntimeException; +use Exception; /** * Database connection, tracking, load balancing, and transaction manager for a cluster @@ -37,7 +52,7 @@ class LoadBalancer implements ILoadBalancer { /** @var array[] Map of (server index => server config array) */ private $mServers; - /** @var IDatabase[][][] Map of local/foreignUsed/foreignFree => server index => IDatabase array */ + /** @var \Database[][][] Map of local/foreignUsed/foreignFree => server index => IDatabase array */ private $mConns; /** @var float[] Map of (server index => weight) */ private $mLoads; @@ -73,8 +88,8 @@ /** @var LoggerInterface */ protected $perfLogger; - /** @var bool|IDatabase Database connection that caused a problem */ - private $mErrorConnection; + /** @var \Database Database connection that caused a problem */ + private $errorConnection; /** @var integer The generic (not query grouped) replica DB index (of $mServers) */ private $mReadIndex; /** @var bool|DBMasterPos False if not set */ @@ -146,7 +161,6 @@ ]; $this->mLoads = []; $this->mWaitForPos = false; - $this->mErrorConnection = false; $this->mAllowLagged = false; if ( isset( $params['readOnlyReason'] ) && is_string( $params['readOnlyReason'] ) ) { @@ -218,9 +232,9 @@ private function getLoadMonitor() { if ( !isset( $this->loadMonitor ) ) { $compat = [ - 'LoadMonitor' => Wikimedia\Rdbms\LoadMonitor::class, - 'LoadMonitorNull' => Wikimedia\Rdbms\LoadMonitorNull::class, - 'LoadMonitorMySQL' => Wikimedia\Rdbms\LoadMonitorMySQL::class, + 'LoadMonitor' => LoadMonitor::class, + 'LoadMonitorNull' => LoadMonitorNull::class, + 'LoadMonitorMySQL' => LoadMonitorMySQL::class, ]; $class = $this->loadMonitorConfig['class']; @@ -722,17 +736,17 @@ $this->mConns['local'][$i][0] = $conn; } else { $this->connLogger->warning( "Failed to connect to database $i at '$serverName'." ); - $this->mErrorConnection = $conn; + $this->errorConnection = $conn; $conn = false; } } - if ( $conn && !$conn->isOpen() ) { + if ( $conn instanceof IDatabase && !$conn->isOpen() ) { // Connection was made but later unrecoverably lost for some reason. // Do not return a handle that will just throw exceptions on use, // but let the calling code (e.g. getReaderIndex) try another server. // See DatabaseMyslBase::ping() for how this can happen. - $this->mErrorConnection = $conn; + $this->errorConnection = $conn; $conn = false; } @@ -751,7 +765,7 @@ * it has been freed first with reuseConnection(). * * On error, returns false, and the connection which caused the - * error will be available via $this->mErrorConnection. + * error will be available via $this->errorConnection. * * @note If disable() was called on this LoadBalancer, this method will throw a DBAccessError. * @@ -783,7 +797,7 @@ if ( strlen( $dbName ) && !$conn->selectDB( $dbName ) ) { $this->mLastError = "Error selecting database '$dbName' on server " . $conn->getServer() . " from client host {$this->host}"; - $this->mErrorConnection = $conn; + $this->errorConnection = $conn; $conn = false; } else { $conn->tablePrefix( $prefix ); @@ -804,7 +818,7 @@ $conn = $this->reallyOpenConnection( $server, $dbName ); if ( !$conn->isOpen() ) { $this->connLogger->warning( __METHOD__ . ": connection error for $i/$domain" ); - $this->mErrorConnection = $conn; + $this->errorConnection = $conn; $conn = false; } else { $conn->tablePrefix( $prefix ); @@ -814,7 +828,7 @@ } // Increment reference count - if ( $conn ) { + if ( $conn instanceof IDatabase ) { $refCount = $conn->getLBInfo( 'foreignPoolRefCount' ); $conn->setLBInfo( 'foreignPoolRefCount', $refCount + 1 ); } @@ -912,22 +926,13 @@ * @throws DBConnectionError */ private function reportConnectionError() { - $conn = $this->mErrorConnection; // the connection which caused the error + $conn = $this->errorConnection; // the connection which caused the error $context = [ 'method' => __METHOD__, 'last_error' => $this->mLastError, ]; - if ( !is_object( $conn ) ) { - // No last connection, probably due to all servers being too busy - $this->connLogger->error( - "LB failure with no last connection. Connection error: {last_error}", - $context - ); - - // If all servers were busy, mLastError will contain something sensible - throw new DBConnectionError( null, $this->mLastError ); - } else { + if ( $conn instanceof IDatabase ) { $context['db_server'] = $conn->getServer(); $this->connLogger->warning( "Connection error: {last_error} ({db_server})", @@ -936,6 +941,15 @@ // throws DBConnectionError $conn->reportConnectionError( "{$this->mLastError} ({$context['db_server']})" ); + } else { + // No last connection, probably due to all servers being too busy + $this->connLogger->error( + "LB failure with no last connection. Connection error: {last_error}", + $context + ); + + // If all servers were busy, mLastError will contain something sensible + throw new DBConnectionError( null, $this->mLastError ); } } @@ -1355,7 +1369,7 @@ /** * @param string $domain Domain ID, or false for the current domain - * @param IDatabase|null DB master connectionl used to avoid loops [optional] + * @param IDatabase|null $conn DB master connectionl used to avoid loops [optional] * @return bool */ private function masterRunningReadOnly( $domain, IDatabase $conn = null ) { @@ -1591,3 +1605,5 @@ $this->disable(); } } + +class_alias( LoadBalancer::class, 'LoadBalancer' ); diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php b/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php index 0a05202..b9fefda 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php @@ -21,6 +21,11 @@ * @ingroup Database */ +namespace Wikimedia\Rdbms; + +use IDatabase; +use InvalidArgumentException; + /** * Trivial LoadBalancer that always returns an injected connection handle */ @@ -72,3 +77,5 @@ return $this->db; } } + +class_alias( 'Wikimedia\Rdbms\LoadBalancerSingle', 'LoadBalancerSingle' ); diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 5fd3348..7e8c2ba 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -24,6 +24,7 @@ use \MediaWiki\MediaWikiServices; use \Wikimedia\WaitConditionLoop; use \Wikimedia\Rdbms\TransactionProfiler; +use Wikimedia\Rdbms\LoadBalancer; /** * Class to store objects in the database diff --git a/includes/site/DBSiteStore.php b/includes/site/DBSiteStore.php index e5247f2..e106f37 100644 --- a/includes/site/DBSiteStore.php +++ b/includes/site/DBSiteStore.php @@ -1,5 +1,7 @@ <?php +use Wikimedia\Rdbms\LoadBalancer; + /** * Represents the site configuration of a wiki. * Holds a list of sites (ie SiteList), stored in the database. diff --git a/maintenance/backup.inc b/maintenance/backup.inc index befafc1..286fb58 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -27,6 +27,8 @@ require_once __DIR__ . '/Maintenance.php'; require_once __DIR__ . '/../includes/export/DumpFilter.php'; +use Wikimedia\Rdbms\LoadBalancer; + /** * @ingroup Dump Maintenance */ diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index d8661c1..5d92eec 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -27,6 +27,8 @@ require_once __DIR__ . '/backup.inc'; require_once __DIR__ . '/../includes/export/WikiExporter.php'; +use Wikimedia\Rdbms\LoadBalancer; + /** * @ingroup Maintenance */ @@ -212,7 +214,6 @@ // We do /not/ retry upon failure, but delegate to encapsulating logic, to avoid // individually retrying at different layers of code. - // 1. The LoadBalancer. try { $this->lb = wfGetLBFactory()->newMainLB(); } catch ( Exception $e ) { @@ -220,7 +221,6 @@ . " rotating DB failed to obtain new load balancer (" . $e->getMessage() . ")" ); } - // 2. The Connection, through the load balancer. try { $this->db = $this->lb->getConnection( DB_REPLICA, 'dump' ); } catch ( Exception $e ) { diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php index 1677851..cd350e5 100644 --- a/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php +++ b/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php @@ -3,7 +3,7 @@ namespace Wikimedia\Tests\Rdbms; use IDatabase; -use LoadBalancer; +use Wikimedia\Rdbms\LoadBalancer; use PHPUnit_Framework_MockObject_MockObject; use Wikimedia\Rdbms\ConnectionManager; diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php index 0d54659..3b26d6f 100644 --- a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php +++ b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php @@ -3,7 +3,7 @@ namespace Wikimedia\Tests\Rdbms; use IDatabase; -use LoadBalancer; +use Wikimedia\Rdbms\LoadBalancer; use PHPUnit_Framework_MockObject_MockObject; use Wikimedia\Rdbms\SessionConsistentConnectionManager; -- To view, visit https://gerrit.wikimedia.org/r/338499 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I52a327f2463a2ba7437324047b5b00d28cd1d758 Gerrit-PatchSet: 9 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits