diff options
author | Amir Sarabadani <ladsgroup@gmail.com> | 2025-02-14 19:31:56 +0100 |
---|---|---|
committer | Amir Sarabadani <ladsgroup@gmail.com> | 2025-03-11 20:44:26 +0100 |
commit | ec2d0953101fa98a8290feb1dac5f15d9c8179df (patch) | |
tree | b521db7c639b3ea0f7d17d66150e08d8b916fa1a /tests/phpunit/unit | |
parent | f47c3624275b73afde9571e9ae4a1d1e2e05577a (diff) | |
download | mediawikicore-ec2d0953101fa98a8290feb1dac5f15d9c8179df.tar.gz mediawikicore-ec2d0953101fa98a8290feb1dac5f15d9c8179df.zip |
objectcache: Introduce dataRedundancy to SqlBagOStuff
This forces SqlBagOStuff to instead of sharding keys, write to n out of
m servers instead. It also reads from those servers as well and in case of
incosistency, picks the value with the highest exptime.
This is mostly for mainstash and allows us to provide stronger
consistency guarantees while allowing for a section to be depooled and
put to maintenance. It basically implements the logic already used by
NoSQL database systems such as Cassandra (There are two types to solve
conflict, quorum or timestamp, Cassandra is using quorum while we are
using timestamp).
There will be some edge cases that it might still pick the wrong value:
- if TTL is set to INDEF
- if the TTL gets shortened for various reasons.
- If we go with two clusters, value is set, one gets depooled, a new
value is set, the depooled one gets pooled and the other depooled and
then read happens.
But all of these are extremely rare edge cases and we should be fine.
This also means if data redundancy is set, locking means all sections
will be locked and removal means all sections must allow the unblock.
Otherwise, the lock will be kept.
Bug: T383327
Change-Id: I80da12396858ee4fc58ae257f6c154b3050df696
Diffstat (limited to 'tests/phpunit/unit')
-rw-r--r-- | tests/phpunit/unit/includes/objectcache/SqlBagOStuffTest.php | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/phpunit/unit/includes/objectcache/SqlBagOStuffTest.php b/tests/phpunit/unit/includes/objectcache/SqlBagOStuffTest.php index 15bc7ff6881e..cb203522f3d5 100644 --- a/tests/phpunit/unit/includes/objectcache/SqlBagOStuffTest.php +++ b/tests/phpunit/unit/includes/objectcache/SqlBagOStuffTest.php @@ -47,22 +47,32 @@ class SqlBagOStuffTest extends MediaWikiUnitTestCase { ] ); $cacheObj = \Wikimedia\TestingAccessWrapper::newFromObject( $cache ); - [ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( 'Test123' ); - [ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( 'Test133' ); + $indexFirstKey = $cacheObj->getShardIndexesForKey( 'Test123' ); + $tableNameFirstKey = $cacheObj->getTableNameForKey( 'Test123' ); + + $indexSecondKey = $cacheObj->getShardIndexesForKey( 'Test133' ); + $tableNameSecondKey = $cacheObj->getTableNameForKey( 'Test133' ); + $this->assertNotEquals( $indexFirstKey, $indexSecondKey ); $this->assertNotEquals( $tableNameFirstKey, $tableNameSecondKey ); - [ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( 'Test123|#|12345' ); - [ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( 'Test123|#|54321' ); + $indexFirstKey = $cacheObj->getShardIndexesForKey( 'Test123|#|12345' ); + $tableNameFirstKey = $cacheObj->getTableNameForKey( 'Test123|#|12345' ); + + $indexSecondKey = $cacheObj->getShardIndexesForKey( 'Test123|#|54321' ); + $tableNameSecondKey = $cacheObj->getTableNameForKey( 'Test123|#|54321' ); + $this->assertSame( $indexFirstKey, $indexSecondKey ); $this->assertSame( $tableNameFirstKey, $tableNameSecondKey ); - [ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( - $cache->makeKey( 'Test123', '|#|', '12345' ) - ); - [ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( - $cache->makeKey( 'Test123', '|#|', '54321' ) - ); + $firstKey = $cache->makeKey( 'Test123', '|#|', '12345' ); + $indexFirstKey = $cacheObj->getShardIndexesForKey( $firstKey ); + $tableNameFirstKey = $cacheObj->getTableNameForKey( $firstKey ); + + $secondKey = $cache->makeKey( 'Test123', '|#|', '54321' ); + $indexSecondKey = $cacheObj->getShardIndexesForKey( $secondKey ); + $tableNameSecondKey = $cacheObj->getTableNameForKey( $secondKey ); + $this->assertSame( $indexFirstKey, $indexSecondKey ); $this->assertSame( $tableNameFirstKey, $tableNameSecondKey ); } |