From 05ab20fcc6a65357102246a7517e18eb9ada9a62 Mon Sep 17 00:00:00 2001 From: addshore Date: Thu, 1 Dec 2016 00:13:16 +0000 Subject: [PATCH] Remove Atomic methods from ConnectionManagers Change-Id: I697f63f45975b13af52bc22fced6e4d07e35115f Depends-On: I4341a1b4ff6a67e4c1770faae38e9b126f1bf0bf --- .../connectionmanager/ConnectionManager.php | 39 ------------- .../SessionConsistentConnectionManager.php | 21 ------- ...SessionConsistentConnectionManagerTest.php | 56 ------------------- 3 files changed, 116 deletions(-) diff --git a/includes/libs/rdbms/connectionmanager/ConnectionManager.php b/includes/libs/rdbms/connectionmanager/ConnectionManager.php index 6d5d8ababc..4f72f77afd 100644 --- a/includes/libs/rdbms/connectionmanager/ConnectionManager.php +++ b/includes/libs/rdbms/connectionmanager/ConnectionManager.php @@ -138,43 +138,4 @@ class ConnectionManager { return $this->getConnectionRef( DB_REPLICA, $groups ); } - /** - * Begins an atomic section and returns a database connection to the master DB, for updating. - * - * @since 1.29 - * - * @param string $fname - * - * @return Database - */ - public function beginAtomicSection( $fname ) { - $db = $this->getWriteConnection(); - $db->startAtomic( $fname ); - - return $db; - } - - /** - * @since 1.29 - * - * @param IDatabase $db - * @param string $fname - */ - public function commitAtomicSection( IDatabase $db, $fname ) { - $db->endAtomic( $fname ); - $this->releaseConnection( $db ); - } - - /** - * @since 1.29 - * - * @param IDatabase $db - * @param string $fname - */ - public function rollbackAtomicSection( IDatabase $db, $fname ) { - // FIXME: there does not seem to be a clean way to roll back an atomic section?! - $db->rollback( $fname, 'flush' ); - $this->releaseConnection( $db ); - } - } diff --git a/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManager.php b/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManager.php index 02972e5dc7..e183823244 100644 --- a/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManager.php +++ b/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManager.php @@ -37,7 +37,6 @@ class SessionConsistentConnectionManager extends ConnectionManager { /** * Forces all future calls to getReadConnection() to return a write connection. * Use this before performing read operations that are critical for a future update. - * Calling beginAtomicSection() implies a call to prepareForUpdates(). * * @since 1.29 */ @@ -95,24 +94,4 @@ class SessionConsistentConnectionManager extends ConnectionManager { return parent::getWriteConnectionRef(); } - /** - * Begins an atomic section and returns a database connection to the master DB, for updating. - * - * @since 1.29 - * - * @note: This causes all future calls to getReadConnection() to return a connection - * to the master DB, even after commitAtomicSection() or rollbackAtomicSection() have - * been called. - * - * @param string $fname - * - * @return Database - */ - public function beginAtomicSection( $fname ) { - // Once we have written to master, do not read from replica. - $this->prepareForUpdates(); - - return parent::beginAtomicSection( $fname ); - } - } diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php index 4dcab82df8..0d54659b5e 100644 --- a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php +++ b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php @@ -105,60 +105,4 @@ class SessionConsistentConnectionManagerTest extends \PHPUnit_Framework_TestCase $manager = new SessionConsistentConnectionManager( $lb ); $manager->releaseConnection( $database ); } - - public function testBeginAtomicSection() { - $database = $this->getIDatabaseMock(); - $lb = $this->getLoadBalancerMock(); - - $lb->expects( $this->exactly( 2 ) ) - ->method( 'getConnection' ) - ->with( DB_MASTER ) - ->will( $this->returnValue( $database ) ); - - $database->expects( $this->once() ) - ->method( 'startAtomic' ) - ->will( $this->returnValue( null ) ); - - $manager = new SessionConsistentConnectionManager( $lb ); - $manager->beginAtomicSection( 'TEST' ); - - // Should also ask for a DB_MASTER connection. - // This is asserted by the $lb mock. - $manager->getReadConnection(); - } - - public function testCommitAtomicSection() { - $database = $this->getIDatabaseMock(); - $lb = $this->getLoadBalancerMock(); - - $lb->expects( $this->once() ) - ->method( 'reuseConnection' ) - ->with( $database ) - ->will( $this->returnValue( null ) ); - - $database->expects( $this->once() ) - ->method( 'endAtomic' ) - ->will( $this->returnValue( null ) ); - - $manager = new SessionConsistentConnectionManager( $lb ); - $manager->commitAtomicSection( $database, 'TEST' ); - } - - public function testRollbackAtomicSection() { - $database = $this->getIDatabaseMock(); - $lb = $this->getLoadBalancerMock(); - - $lb->expects( $this->once() ) - ->method( 'reuseConnection' ) - ->with( $database ) - ->will( $this->returnValue( null ) ); - - $database->expects( $this->once() ) - ->method( 'rollback' ) - ->will( $this->returnValue( null ) ); - - $manager = new SessionConsistentConnectionManager( $lb ); - $manager->rollbackAtomicSection( $database, 'TEST' ); - } - } -- 2.20.1