aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2024-08-29 19:43:11 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2024-08-29 20:06:33 +0200
commit1b893237033c759732e402434b8700d8eff38365 (patch)
tree7b0914d5db2a9bc43fd56c60e748df7a63fe3e7f /lib/private
parente9dcfbcfb7f31134888a5c41f11ee24367c6788e (diff)
downloadnextcloud-server-1b893237033c759732e402434b8700d8eff38365.tar.gz
nextcloud-server-1b893237033c759732e402434b8700d8eff38365.zip
fix(DB): do not assume sharding is always enabled
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/DB/Connection.php32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 1b724179f06..adcae868bd3 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 @@ class Connection extends PrimaryReadReplicaConnection {
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 @@ class Connection extends PrimaryReadReplicaConnection {
*/
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 @@ class Connection extends PrimaryReadReplicaConnection {
$this->systemConfig,
$this->logger
);
- if (count($this->partitions) > 0) {
+ if ($this->isShardingEnabled && count($this->partitions) > 0) {
$builder = new PartitionedQueryBuilder(
$builder,
$this->shards,