diff options
author | Aaron Schulz <aschulz@wikimedia.org> | 2024-09-23 15:33:35 -0700 |
---|---|---|
committer | Aaron Schulz <aschulz@wikimedia.org> | 2024-10-09 20:34:25 +0000 |
commit | b69c1839d4ede374747eca8f32137b6c6fca9df6 (patch) | |
tree | 732aa10d56174f3c521821929d0f16c0738a1cba /tests | |
parent | 6c56577575b3e79e38eaaac38c6f114cfe2ca58e (diff) | |
download | mediawikicore-b69c1839d4ede374747eca8f32137b6c6fca9df6.tar.gz mediawikicore-b69c1839d4ede374747eca8f32137b6c6fca9df6.zip |
rdbms: clear replica snapshots in (begin|commit|rollback)PrimaryChanges()
Automatically perform the empty-transaction commit logic in methods
like beginPrimaryChanges() and commitPrimaryChanges(). This avoids
the proliferation of callers having to call the same set of methods
one after another for non-obvious reasons. It also discourages code
from making brittle assumptions that might fail for setups where
there is only a primary or the primary has non-zero read load.
Deprecate flushReplicaSnapshots() and remove callers.
Clarify the related method documentation.
Bug: T315664
Change-Id: I255afd22ffcaeac0fad2d4e4a2a0c55c99be7905
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/includes/db/LBFactoryTest.php | 23 | ||||
-rw-r--r-- | tests/phpunit/includes/deferred/DeferredUpdatesTest.php | 1 | ||||
-rw-r--r-- | tests/phpunit/integration/includes/db/DatabaseMysqlTest.php | 2 |
3 files changed, 24 insertions, 2 deletions
diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php index f3390aada00d..a437a8408bfd 100644 --- a/tests/phpunit/includes/db/LBFactoryTest.php +++ b/tests/phpunit/includes/db/LBFactoryTest.php @@ -191,6 +191,29 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $factory->closeAll( __METHOD__ ); } + public function testLBFactoryMultiRoundTransactionSnapshots() { + $factory = $this->newLBFactoryMultiLBs(); + $dbr = $factory->getMainLB()->getConnection( DB_REPLICA ); + $dbw = $factory->getMainLB()->getConnection( DB_PRIMARY ); + + $dbr->begin( __METHOD__, $dbr::TRANSACTION_INTERNAL ); + $this->assertSame( 1, $dbr->trxLevel() ); + $this->assertSame( 0, $dbw->trxLevel() ); + + $factory->beginPrimaryChanges( __METHOD__ ); + $this->assertSame( 0, $dbr->trxLevel() ); + $this->assertSame( 0, $dbw->trxLevel() ); + + $dbr->begin( __METHOD__, $dbr::TRANSACTION_INTERNAL ); + $dbw->begin( __METHOD__, $dbw::TRANSACTION_INTERNAL ); + $this->assertSame( 1, $dbr->trxLevel() ); + $this->assertSame( 1, $dbw->trxLevel() ); + + $factory->commitPrimaryChanges( __METHOD__ ); + $this->assertSame( 0, $dbr->trxLevel() ); + $this->assertSame( 0, $dbw->trxLevel() ); + } + private function newLBFactoryMultiLBs() { global $wgDBserver, $wgDBport, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype; global $wgSQLiteDataDir; diff --git a/tests/phpunit/includes/deferred/DeferredUpdatesTest.php b/tests/phpunit/includes/deferred/DeferredUpdatesTest.php index 47d2533099dc..6faedf679a89 100644 --- a/tests/phpunit/includes/deferred/DeferredUpdatesTest.php +++ b/tests/phpunit/includes/deferred/DeferredUpdatesTest.php @@ -354,7 +354,6 @@ class DeferredUpdatesTest extends MediaWikiIntegrationTestCase { DeferredUpdates::attemptUpdate( new MWCallableUpdate( static function () use ( $lbFactory, $fname, &$called ) { - $lbFactory->flushReplicaSnapshots( $fname ); $lbFactory->commitPrimaryChanges( $fname ); $called = true; }, diff --git a/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php b/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php index 39a8fdb05610..d1a400e27521 100644 --- a/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php +++ b/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php @@ -197,7 +197,7 @@ class DatabaseMysqlTest extends \MediaWikiIntegrationTestCase { // Get a lock outside of any transaction $unlocker = $this->conn->getScopedLockAndFlush( 'testing-key', __METHOD__, 0 ); - // Start transaction *after* getting the lock + // Start transaction after getting the lock $this->conn->begin( __METHOD__, IDatabase::TRANSACTION_INTERNAL ); $row = $this->conn->query( 'SELECT connection_id() AS id', __METHOD__ )->fetchObject(); |