diff --git a/RELEASE-NOTES-1.35 b/RELEASE-NOTES-1.35 index 280e6de04c0..1de7d58963a 100644 --- a/RELEASE-NOTES-1.35 +++ b/RELEASE-NOTES-1.35 @@ -644,6 +644,9 @@ because of Phabricator reports. - AuthenticationProvider - ResourceLoaderModule - SearchEngine +* The parameters to ChronologyProtector::getTouched() and + ILBFactory::getChronologyProtectorTouched() were changed without backwards + compatibility. * … === Deprecations in 1.35 === diff --git a/includes/libs/rdbms/ChronologyProtector.php b/includes/libs/rdbms/ChronologyProtector.php index 35c12ea61ba..d85804c6e15 100644 --- a/includes/libs/rdbms/ChronologyProtector.php +++ b/includes/libs/rdbms/ChronologyProtector.php @@ -35,6 +35,8 @@ use Wikimedia\WaitConditionLoop; * This helps to ensure a consistent ordering of events as seen by an client * * Kind of like Hawking's [[Chronology Protection Agency]]. + * + * @internal */ class ChronologyProtector implements LoggerAwareInterface { /** @var BagOStuff */ @@ -269,21 +271,23 @@ class ChronologyProtector implements LoggerAwareInterface { } /** - * @param string $dbName DB master name (e.g. "db1052") + * @param ILoadBalancer $lb The load balancer. Prior to 1.35, the first parameter was the + * master name. * @return float|bool UNIX timestamp when client last touched the DB; false if not on record - * @since 1.28 + * @since 1.35 */ - public function getTouched( $dbName ) { - return $this->store->get( $this->getTouchedKey( $this->store, $dbName ) ); + public function getTouched( ILoadBalancer $lb ) { + $masterName = $lb->getServerName( $lb->getWriterIndex() ); + return $this->store->get( $this->getTouchedKey( $this->store, $masterName ) ); } /** * @param BagOStuff $store - * @param string $dbName + * @param string $masterName * @return string */ - private function getTouchedKey( BagOStuff $store, $dbName ) { - return $store->makeGlobalKey( __CLASS__, 'mtime', $this->clientId, $dbName ); + private function getTouchedKey( BagOStuff $store, $masterName ) { + return $store->makeGlobalKey( __CLASS__, 'mtime', $this->clientId, $masterName ); } /** diff --git a/includes/libs/rdbms/lbfactory/ILBFactory.php b/includes/libs/rdbms/lbfactory/ILBFactory.php index 47d1540f846..92af3d6a078 100644 --- a/includes/libs/rdbms/lbfactory/ILBFactory.php +++ b/includes/libs/rdbms/lbfactory/ILBFactory.php @@ -330,10 +330,10 @@ interface ILBFactory { public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] ); /** - * @param string $dbName DB master name (e.g. "db1052") + * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain * @return float|bool UNIX timestamp when client last touched the DB or false if not recent */ - public function getChronologyProtectorTouched( $dbName ); + public function getChronologyProtectorTouched( $domain = false ); /** * Disable the ChronologyProtector for all load balancers diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index a4f252220d5..ff9542c5aea 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -530,8 +530,8 @@ abstract class LBFactory implements ILBFactory { return $waitSucceeded; } - public function getChronologyProtectorTouched( $dbName ) { - return $this->getChronologyProtector()->getTouched( $dbName ); + public function getChronologyProtectorTouched( $domain = false ) { + return $this->getChronologyProtector()->getTouched( $this->getMainLB( $domain ) ); } public function disableChronologyProtection() { diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php index 17034102f85..b15318c8fb4 100644 --- a/tests/phpunit/includes/db/LBFactoryTest.php +++ b/tests/phpunit/includes/db/LBFactoryTest.php @@ -799,4 +799,21 @@ class LBFactoryTest extends MediaWikiTestCase { $this->assertEquals( 'realdb', $lb->resolveDomainID( 'alias-db' ) ); $this->assertEquals( "realdb-realprefix_", $lb->resolveDomainID( "alias-db-prefix_" ) ); } + + /** + * @covers \Wikimedia\Rdbms\ChronologyProtector + * @covers \Wikimedia\Rdbms\LBFactory + */ + public function testGetChronologyProtectorTouched() { + $store = new HashBagOStuff; + $lbFactory = $this->newLBFactoryMulti( [ + 'memStash' => $store + ] ); + $lbFactory->setRequestInfo( [ 'ChronologyClientId' => 'ii' ] ); + $key = $store->makeGlobalKey( ChronologyProtector::class, + 'mtime', 'ii', 'test-db1' ); + $store->set( $key, 2 ); + $touched = $lbFactory->getChronologyProtectorTouched(); + $this->assertEquals( 2, $touched ); + } }