From e9dcfbcfb7f31134888a5c41f11ee24367c6788e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 29 Aug 2024 19:12:44 +0200 Subject: [PATCH 1/4] fix(DB): set sharding parameters only when intended Signed-off-by: Arthur Schiwon --- lib/private/DB/ConnectionFactory.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index d8764f07753a2..03a7a4f84449b 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -225,11 +225,16 @@ public function createConnectionParams(string $configPrefix = '', array $additio } $connectionParams['sharding'] = $this->config->getValue('dbsharding', []); - $connectionParams['shard_connection_manager'] = $this->shardConnectionManager; - $connectionParams['auto_increment_handler'] = new AutoIncrementHandler( - $this->cacheFactory, - $this->shardConnectionManager, - ); + if (!empty($connectionParams['sharding'])) { + $connectionParams['shard_connection_manager'] = $this->shardConnectionManager; + $connectionParams['auto_increment_handler'] = new AutoIncrementHandler( + $this->cacheFactory, + $this->shardConnectionManager, + ); + } else { + // just in case only the presence could lead to funny behaviour + unset($connectionParams['sharding']); + } $connectionParams = array_merge($connectionParams, $additionalConnectionParams); From 1b893237033c759732e402434b8700d8eff38365 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 29 Aug 2024 19:43:11 +0200 Subject: [PATCH 2/4] fix(DB): do not assume sharding is always enabled Signed-off-by: Arthur Schiwon --- lib/private/DB/Connection.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 1b724179f0687..adcae868bd3bf 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -91,6 +91,7 @@ class Connection extends PrimaryReadReplicaConnection { protected array $shards = []; protected ShardConnectionManager $shardConnectionManager; protected AutoIncrementHandler $autoIncrementHandler; + protected bool $isShardingEnabled; public const SHARD_PRESETS = [ 'filecache' => [ @@ -130,14 +131,17 @@ public function __construct( parent::__construct($params, $driver, $config, $eventManager); $this->adapter = new $params['adapter']($this); $this->tablePrefix = $params['tablePrefix']; - - /** @psalm-suppress InvalidArrayOffset */ - $this->shardConnectionManager = $this->params['shard_connection_manager'] ?? Server::get(ShardConnectionManager::class); - /** @psalm-suppress InvalidArrayOffset */ - $this->autoIncrementHandler = $this->params['auto_increment_handler'] ?? new AutoIncrementHandler( - Server::get(ICacheFactory::class), - $this->shardConnectionManager, - ); + $this->isShardingEnabled = isset($this->params['sharding']) && !empty($this->params['sharding']); + + if ($this->isShardingEnabled) { + /** @psalm-suppress InvalidArrayOffset */ + $this->shardConnectionManager = $this->params['shard_connection_manager'] ?? Server::get(ShardConnectionManager::class); + /** @psalm-suppress InvalidArrayOffset */ + $this->autoIncrementHandler = $this->params['auto_increment_handler'] ?? new AutoIncrementHandler( + Server::get(ICacheFactory::class), + $this->shardConnectionManager, + ); + } $this->systemConfig = \OC::$server->getSystemConfig(); $this->clock = Server::get(ClockInterface::class); $this->logger = Server::get(LoggerInterface::class); @@ -192,10 +196,12 @@ public function __construct( */ public function getShardConnections(): array { $connections = []; - foreach ($this->shards as $shardDefinition) { - foreach ($shardDefinition->getAllShards() as $shard) { - /** @var ConnectionAdapter $connection */ - $connections[] = $this->shardConnectionManager->getConnection($shardDefinition, $shard); + if ($this->isShardingEnabled) { + foreach ($this->shards as $shardDefinition) { + foreach ($shardDefinition->getAllShards() as $shard) { + /** @var ConnectionAdapter $connection */ + $connections[] = $this->shardConnectionManager->getConnection($shardDefinition, $shard); + } } } return $connections; @@ -255,7 +261,7 @@ public function getQueryBuilder(): IQueryBuilder { $this->systemConfig, $this->logger ); - if (count($this->partitions) > 0) { + if ($this->isShardingEnabled && count($this->partitions) > 0) { $builder = new PartitionedQueryBuilder( $builder, $this->shards, From cb31a40d99bbc20c3e718152824b6b0ee5d28851 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 29 Aug 2024 20:08:03 +0200 Subject: [PATCH 3/4] build: bump version to force 32bit test Signed-off-by: Arthur Schiwon --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index b0aee7c7ee0fc..0d26e5bbbefd1 100644 --- a/version.php +++ b/version.php @@ -9,7 +9,7 @@ // between betas, final and RCs. This is _not_ the public version number. Reset minor/patch level // when updating major/minor version number. -$OC_Version = [30, 0, 0, 10]; +$OC_Version = [30, 0, 0, 11]; // The human-readable string $OC_VersionString = '30.0.0 RC2'; From 656412daa422533ddc09e7b97bbb00ca3a3042e3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 29 Aug 2024 20:18:35 +0200 Subject: [PATCH 4/4] test(phpunit): skip sharding tests on 32bit Signed-off-by: Arthur Schiwon --- .../QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php | 3 +++ tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php b/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php index 0397ce687767b..12ba74fe89fe0 100644 --- a/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php @@ -26,6 +26,9 @@ class PartitionedQueryBuilderTest extends TestCase { private AutoIncrementHandler $autoIncrementHandler; protected function setUp(): void { + if (PHP_INT_SIZE < 8) { + $this->markTestSkipped('Test requires 64bit'); + } $this->connection = Server::get(IDBConnection::class); $this->shardConnectionManager = Server::get(ShardConnectionManager::class); $this->autoIncrementHandler = Server::get(AutoIncrementHandler::class); diff --git a/tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php b/tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php index 7af93bbbe590a..8f95c1b626352 100644 --- a/tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php @@ -27,6 +27,9 @@ class SharedQueryBuilderTest extends TestCase { private AutoIncrementHandler $autoIncrementHandler; protected function setUp(): void { + if (PHP_INT_SIZE < 8) { + $this->markTestSkipped('Test requires 64bit'); + } $this->connection = Server::get(IDBConnection::class); $this->autoIncrementHandler = Server::get(AutoIncrementHandler::class); }