jenkins-bot has submitted this change and it was merged. Change subject: Use SessionConsistentConnectionManager from core everywhere ......................................................................
Use SessionConsistentConnectionManager from core everywhere Change-Id: I4341a1b4ff6a67e4c1770faae38e9b126f1bf0bf --- M client/includes/RecentChanges/RecentChangesDuplicateDetector.php M client/includes/Store/Sql/BulkSubscriptionUpdater.php M client/includes/Store/Sql/DirectSqlStore.php M client/includes/Usage/Sql/SqlSubscriptionManager.php M client/includes/Usage/Sql/SqlUsageTracker.php M client/maintenance/updateSubscriptions.php M client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php M client/tests/phpunit/includes/Store/Sql/BulkSubscriptionUpdaterTest.php M client/tests/phpunit/includes/Usage/Sql/SqlSubscriptionManagerTest.php M client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php 10 files changed, 68 insertions(+), 60 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/RecentChanges/RecentChangesDuplicateDetector.php b/client/includes/RecentChanges/RecentChangesDuplicateDetector.php index f85b7cc..2b1c910 100644 --- a/client/includes/RecentChanges/RecentChangesDuplicateDetector.php +++ b/client/includes/RecentChanges/RecentChangesDuplicateDetector.php @@ -4,7 +4,7 @@ use MWException; use RecentChange; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; /** * @since 0.5 @@ -16,11 +16,11 @@ class RecentChangesDuplicateDetector { /** - * @var ConsistentReadConnectionManager + * @var SessionConsistentConnectionManager */ private $connectionManager; - public function __construct( ConsistentReadConnectionManager $connectionManager ) { + public function __construct( SessionConsistentConnectionManager $connectionManager ) { $this->connectionManager = $connectionManager; } @@ -38,7 +38,7 @@ $attribs = $change->getAttributes(); //XXX: need to check master? - $db = $this->connectionManager->getReadConnection(); + $db = $this->connectionManager->getReadConnectionRef(); $res = $db->select( 'recentchanges', @@ -73,7 +73,6 @@ } } - $this->connectionManager->releaseConnection( $db ); return false; } diff --git a/client/includes/Store/Sql/BulkSubscriptionUpdater.php b/client/includes/Store/Sql/BulkSubscriptionUpdater.php index a7d7eba..8b5fe7a 100644 --- a/client/includes/Store/Sql/BulkSubscriptionUpdater.php +++ b/client/includes/Store/Sql/BulkSubscriptionUpdater.php @@ -10,6 +10,7 @@ use Wikibase\Lib\Reporting\LogWarningExceptionHandler; use Wikibase\Lib\Reporting\MessageReporter; use Wikibase\Lib\Reporting\NullMessageReporter; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; /** * Implements bulk updates for the repo's wb_changes_subscription table, @@ -22,12 +23,12 @@ class BulkSubscriptionUpdater { /** - * @var ConsistentReadConnectionManager + * @var SessionConsistentConnectionManager */ private $localConnectionManager; /** - * @var ConsistentReadConnectionManager + * @var SessionConsistentConnectionManager */ private $repoConnectionManager; @@ -59,9 +60,9 @@ private $progressReporter; /** - * @param ConsistentReadConnectionManager $localConnectionManager Connection manager for DB + * @param SessionConsistentConnectionManager $localConnectionManager Connection manager for DB * connections to the local wiki. - * @param ConsistentReadConnectionManager $repoConnectionManager Connection manager for DB + * @param SessionConsistentConnectionManager $repoConnectionManager Connection manager for DB * connections to the repo. * @param string $subscriberWikiId The local wiki's global ID, to be used as the subscriber ID * in the repo's subscription table. @@ -73,8 +74,8 @@ * @throws InvalidArgumentException */ public function __construct( - ConsistentReadConnectionManager $localConnectionManager, - ConsistentReadConnectionManager $repoConnectionManager, + SessionConsistentConnectionManager $localConnectionManager, + SessionConsistentConnectionManager $repoConnectionManager, $subscriberWikiId, $repoWiki, $batchSize = 1000 @@ -122,7 +123,7 @@ * @param EntityId|null $startEntity The entity to start with. */ public function updateSubscriptions( EntityId $startEntity = null ) { - $this->repoConnectionManager->forceMaster(); + $this->repoConnectionManager->prepareForUpdates(); $continuation = $startEntity === null ? null : array( $startEntity->getSerialization() ); @@ -162,7 +163,8 @@ * @return int The number of rows inserted. */ private function insertUpdateBatch( array $entities ) { - $dbw = $this->repoConnectionManager->beginAtomicSection( __METHOD__ ); + $dbw = $this->repoConnectionManager->getWriteConnectionRef(); + $dbw->startAtomic( __METHOD__ ); $rows = $this->makeSubscriptionRows( $entities ); @@ -176,7 +178,7 @@ ); $count = $dbw->affectedRows(); - $this->repoConnectionManager->commitAtomicSection( $dbw, __METHOD__ ); + $dbw->endAtomic( __METHOD__ ); return $count; } @@ -265,7 +267,7 @@ public function purgeSubscriptions( EntityId $startEntity = null ) { $continuation = $startEntity === null ? null : array( $startEntity->getSerialization() ); - $this->repoConnectionManager->forceMaster(); + $this->repoConnectionManager->prepareForUpdates(); while ( true ) { wfWaitForSlaves( null, $this->repoWiki ); @@ -363,7 +365,8 @@ * @param string $maxId Entity id string indicating the last element in the deletion range */ private function deleteSubscriptionRange( $minId, $maxId ) { - $dbw = $this->repoConnectionManager->beginAtomicSection( __METHOD__ ); + $dbw = $this->repoConnectionManager->getWriteConnectionRef(); + $dbw->startAtomic( __METHOD__ ); $conditions = array( 'cs_subscriber_id' => $this->subscriberWikiId, @@ -377,7 +380,7 @@ __METHOD__ ); - $this->repoConnectionManager->commitAtomicSection( $dbw, __METHOD__ ); + $dbw->endAtomic( __METHOD__ ); } } diff --git a/client/includes/Store/Sql/DirectSqlStore.php b/client/includes/Store/Sql/DirectSqlStore.php index 922e232..4f4e8a1 100644 --- a/client/includes/Store/Sql/DirectSqlStore.php +++ b/client/includes/Store/Sql/DirectSqlStore.php @@ -5,8 +5,8 @@ use HashBagOStuff; use ObjectCache; use Wikibase\Client\RecentChanges\RecentChangesDuplicateDetector; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; use Wikibase\Client\Store\Sql\PagePropsEntityIdLookup; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\Store\UsageUpdater; use Wikibase\Client\Usage\Sql\SqlSubscriptionManager; use Wikibase\Client\Usage\Sql\SqlUsageTracker; @@ -72,12 +72,12 @@ private $repoWiki; /** - * @var ConsistentReadConnectionManager|null + * @var SessionConsistentConnectionManager|null */ private $repoConnectionManager = null; /** - * @var ConsistentReadConnectionManager|null + * @var SessionConsistentConnectionManager|null */ private $localConnectionManager = null; @@ -214,11 +214,14 @@ * Returns a LoadBalancer that acts as a factory for connections to the repo wiki's * database. * - * @return ConsistentReadConnectionManager + * @return SessionConsistentConnectionManager */ private function getRepoConnectionManager() { if ( $this->repoConnectionManager === null ) { - $this->repoConnectionManager = new ConsistentReadConnectionManager( wfGetLB( $this->repoWiki ), $this->repoWiki ); + $this->repoConnectionManager = new SessionConsistentConnectionManager( + wfGetLB( $this->repoWiki ), + $this->repoWiki + ); } return $this->repoConnectionManager; @@ -228,11 +231,11 @@ * Returns a LoadBalancer that acts as a factory for connections to the local (client) wiki's * database. * - * @return ConsistentReadConnectionManager + * @return SessionConsistentConnectionManager */ private function getLocalConnectionManager() { if ( $this->localConnectionManager === null ) { - $this->localConnectionManager = new ConsistentReadConnectionManager( wfGetLB() ); + $this->localConnectionManager = new SessionConsistentConnectionManager( wfGetLB() ); } return $this->localConnectionManager; diff --git a/client/includes/Usage/Sql/SqlSubscriptionManager.php b/client/includes/Usage/Sql/SqlSubscriptionManager.php index 0f97f4a..5c12ceb 100644 --- a/client/includes/Usage/Sql/SqlSubscriptionManager.php +++ b/client/includes/Usage/Sql/SqlSubscriptionManager.php @@ -5,8 +5,9 @@ use Database; use DBError; use Exception; +use IDatabase; use InvalidArgumentException; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\Usage\SubscriptionManager; use Wikibase\Client\Usage\UsageTrackerException; use Wikibase\DataModel\Entity\EntityId; @@ -22,14 +23,14 @@ class SqlSubscriptionManager implements SubscriptionManager { /** - * @var ConsistentReadConnectionManager + * @var SessionConsistentConnectionManager */ private $connectionManager; /** - * @param ConsistentReadConnectionManager $connectionManager + * @param SessionConsistentConnectionManager $connectionManager */ - public function __construct( ConsistentReadConnectionManager $connectionManager ) { + public function __construct( SessionConsistentConnectionManager $connectionManager ) { $this->connectionManager = $connectionManager; } @@ -60,16 +61,17 @@ } $subscriptions = $this->idsToString( $entityIds ); - $db = $this->connectionManager->beginAtomicSection( __METHOD__ ); + $dbw = $this->connectionManager->getWriteConnectionRef(); + $dbw->startAtomic( __METHOD__ ); try { - $oldSubscriptions = $this->querySubscriptions( $db, $subscriber, $subscriptions ); + $oldSubscriptions = $this->querySubscriptions( $dbw, $subscriber, $subscriptions ); $newSubscriptions = array_diff( $subscriptions, $oldSubscriptions ); - $this->insertSubscriptions( $db, $subscriber, $newSubscriptions ); + $this->insertSubscriptions( $dbw, $subscriber, $newSubscriptions ); - $this->connectionManager->commitAtomicSection( $db, __METHOD__ ); + $dbw->endAtomic( __METHOD__ ); } catch ( Exception $ex ) { - $this->connectionManager->rollbackAtomicSection( $db, __METHOD__ ); + $dbw->rollback( __METHOD__ ); if ( $ex instanceof DBError ) { throw new UsageTrackerException( $ex->getMessage(), $ex->getCode(), $ex ); @@ -95,16 +97,17 @@ } $unsubscriptions = $this->idsToString( $entityIds ); - $db = $this->connectionManager->beginAtomicSection( __METHOD__ ); + $dbw = $this->connectionManager->getWriteConnectionRef(); + $dbw->startAtomic( __METHOD__ ); try { - $oldSubscriptions = $this->querySubscriptions( $db, $subscriber, $unsubscriptions ); + $oldSubscriptions = $this->querySubscriptions( $dbw, $subscriber, $unsubscriptions ); $obsoleteSubscriptions = array_intersect( $unsubscriptions, $oldSubscriptions ); - $this->deleteSubscriptions( $db, $subscriber, $obsoleteSubscriptions ); + $this->deleteSubscriptions( $dbw, $subscriber, $obsoleteSubscriptions ); - $this->connectionManager->commitAtomicSection( $db, __METHOD__ ); + $dbw->endAtomic( __METHOD__ ); } catch ( Exception $ex ) { - $this->connectionManager->rollbackAtomicSection( $db, __METHOD__ ); + $dbw->rollback( __METHOD__ ); if ( $ex instanceof DBError ) { throw new UsageTrackerException( $ex->getMessage(), $ex->getCode(), $ex ); @@ -117,13 +120,13 @@ /** * For a set of potential subscriptions, returns the existing subscriptions. * - * @param Database $db + * @param IDatabase $db * @param string $subscriber * @param string[] $subscriptions * * @return string[] Entity ID strings from $subscriptions which $subscriber is already subscribed to. */ - private function querySubscriptions( Database $db, $subscriber, array $subscriptions ) { + private function querySubscriptions( IDatabase $db, $subscriber, array $subscriptions ) { if ( $subscriptions ) { $subscriptions = $db->selectFieldValues( 'wb_changes_subscription', @@ -142,11 +145,11 @@ /** * Inserts a set of subscriptions. * - * @param Database $db + * @param IDatabase $db * @param string $subscriber * @param string[] $subscriptions */ - private function insertSubscriptions( Database $db, $subscriber, array $subscriptions ) { + private function insertSubscriptions( IDatabase $db, $subscriber, array $subscriptions ) { $rows = $this->makeSubscriptionRows( $subscriber, $subscriptions ); $db->insert( @@ -160,11 +163,11 @@ /** * Inserts a set of subscriptions. * - * @param Database $db + * @param IDatabase $db * @param string $subscriber * @param string[] $subscriptions */ - private function deleteSubscriptions( Database $db, $subscriber, array $subscriptions ) { + private function deleteSubscriptions( IDatabase $db, $subscriber, array $subscriptions ) { if ( $subscriptions ) { $db->delete( 'wb_changes_subscription', diff --git a/client/includes/Usage/Sql/SqlUsageTracker.php b/client/includes/Usage/Sql/SqlUsageTracker.php index 0dd9521..425fdc8 100644 --- a/client/includes/Usage/Sql/SqlUsageTracker.php +++ b/client/includes/Usage/Sql/SqlUsageTracker.php @@ -8,7 +8,7 @@ use Exception; use InvalidArgumentException; use Traversable; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\UsageLookup; use Wikibase\Client\Usage\UsageTracker; @@ -30,7 +30,7 @@ private $idParser; /** - * @var ConsistentReadConnectionManager + * @var SessionConsistentConnectionManager */ private $connectionManager; @@ -41,9 +41,9 @@ /** * @param EntityIdParser $idParser - * @param ConsistentReadConnectionManager $connectionManager + * @param SessionConsistentConnectionManager $connectionManager */ - public function __construct( EntityIdParser $idParser, ConsistentReadConnectionManager $connectionManager ) { + public function __construct( EntityIdParser $idParser, SessionConsistentConnectionManager $connectionManager ) { $this->idParser = $idParser; $this->connectionManager = $connectionManager; } diff --git a/client/maintenance/updateSubscriptions.php b/client/maintenance/updateSubscriptions.php index c5ae1eb..5ae88e0 100644 --- a/client/maintenance/updateSubscriptions.php +++ b/client/maintenance/updateSubscriptions.php @@ -4,7 +4,7 @@ use Maintenance; use Wikibase\Client\Store\Sql\BulkSubscriptionUpdater; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\WikibaseClient; use Wikibase\DataModel\Entity\EntityIdParsingException; use Wikibase\Lib\Reporting\ObservableMessageReporter; @@ -72,8 +72,8 @@ ); $updater = new BulkSubscriptionUpdater( - new ConsistentReadConnectionManager( wfGetLB() ), - new ConsistentReadConnectionManager( wfGetLB( $repoDB ), $repoDB ), + new SessionConsistentConnectionManager( wfGetLB() ), + new SessionConsistentConnectionManager( wfGetLB( $repoDB ), $repoDB ), $clientId, $repoDB, $this->mBatchSize diff --git a/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php b/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php index aa6964c..053e50c 100644 --- a/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php +++ b/client/tests/phpunit/includes/RecentChanges/RecentChangesDuplicateDetectorTest.php @@ -5,7 +5,7 @@ use RecentChange; use Wikibase\Client\RecentChanges\RecentChangeFactory; use Wikibase\Client\RecentChanges\RecentChangesDuplicateDetector; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; /** * @covers Wikibase\Client\RecentChanges\RecentChangesDuplicateDetector @@ -129,7 +129,7 @@ * @dataProvider provideChangeExists */ public function testChangeExists( $expected, array $changeData ) { - $connectionManager = new ConsistentReadConnectionManager( wfGetLB() ); + $connectionManager = new SessionConsistentConnectionManager( wfGetLB() ); $detector = new RecentChangesDuplicateDetector( $connectionManager ); $this->initRecentChanges(); diff --git a/client/tests/phpunit/includes/Store/Sql/BulkSubscriptionUpdaterTest.php b/client/tests/phpunit/includes/Store/Sql/BulkSubscriptionUpdaterTest.php index 9a12ba2..d0f3b1d 100644 --- a/client/tests/phpunit/includes/Store/Sql/BulkSubscriptionUpdaterTest.php +++ b/client/tests/phpunit/includes/Store/Sql/BulkSubscriptionUpdaterTest.php @@ -4,7 +4,7 @@ use PHPUnit_Framework_MockObject_Matcher_Invocation; use Wikibase\Client\Store\Sql\BulkSubscriptionUpdater; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\Usage\Sql\EntityUsageTable; use Wikibase\DataModel\Entity\ItemId; use Wikibase\Lib\Reporting\ExceptionHandler; @@ -43,8 +43,8 @@ $loadBalancer = wfGetLB(); return new BulkSubscriptionUpdater( - new ConsistentReadConnectionManager( $loadBalancer, false ), - new ConsistentReadConnectionManager( $loadBalancer, false ), + new SessionConsistentConnectionManager( $loadBalancer, false ), + new SessionConsistentConnectionManager( $loadBalancer, false ), 'testwiki', false, $batchSize diff --git a/client/tests/phpunit/includes/Usage/Sql/SqlSubscriptionManagerTest.php b/client/tests/phpunit/includes/Usage/Sql/SqlSubscriptionManagerTest.php index 5ed3fcd..5cd9471 100644 --- a/client/tests/phpunit/includes/Usage/Sql/SqlSubscriptionManagerTest.php +++ b/client/tests/phpunit/includes/Usage/Sql/SqlSubscriptionManagerTest.php @@ -2,7 +2,7 @@ namespace Wikibase\Client\Tests\Usage\Sql; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\Usage\Sql\SqlSubscriptionManager; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\PropertyId; @@ -36,7 +36,7 @@ */ private function getSubscriptionManager() { return new SqlSubscriptionManager( - new ConsistentReadConnectionManager( wfGetLB() ) + new SessionConsistentConnectionManager( wfGetLB() ) ); } diff --git a/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php b/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php index 7ac9511..8d4a08f 100644 --- a/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php +++ b/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php @@ -2,7 +2,7 @@ namespace Wikibase\Client\Tests\Usage\Sql; -use Wikibase\Client\Store\Sql\ConsistentReadConnectionManager; +use Wikimedia\Rdbms\SessionConsistentConnectionManager; use Wikibase\Client\Tests\Usage\UsageLookupContractTester; use Wikibase\Client\Tests\Usage\UsageTrackerContractTester; use Wikibase\Client\Usage\Sql\EntityUsageTable; @@ -45,7 +45,7 @@ $this->sqlUsageTracker = new SqlUsageTracker( new BasicEntityIdParser(), - new ConsistentReadConnectionManager( wfGetLB() ) + new SessionConsistentConnectionManager( wfGetLB() ) ); $this->trackerTester = new UsageTrackerContractTester( $this->sqlUsageTracker, array( $this, 'getUsages' ) ); -- To view, visit https://gerrit.wikimedia.org/r/322681 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4341a1b4ff6a67e4c1770faae38e9b126f1bf0bf Gerrit-PatchSet: 11 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits