mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
Merge pull request #47611 from nextcloud/fix/noid/no-sharding-32
fix(DB): set sharding parameters only when intended
This commit is contained in:
commit
4accba8016
5 changed files with 35 additions and 18 deletions
|
|
@ -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'];
|
||||
$this->isShardingEnabled = isset($this->params['sharding']) && !empty($this->params['sharding']);
|
||||
|
||||
/** @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,
|
||||
);
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -225,11 +225,16 @@ class ConnectionFactory {
|
|||
}
|
||||
|
||||
$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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = [31, 0, 0, 1];
|
||||
$OC_Version = [31, 0, 0, 2];
|
||||
|
||||
// The human-readable string
|
||||
$OC_VersionString = '31.0.0 dev';
|
||||
|
|
|
|||
Loading…
Reference in a new issue