Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: misc code fixes around db sharding #47852

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/private/DB/QueryBuilder/ExtendedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ public function executeStatement(?IDBConnection $connection = null): int {
return $this->builder->executeStatement($connection);
}

public function hintShardKey(string $column, mixed $value, bool $overwrite = false) {
public function hintShardKey(string $column, mixed $value, bool $overwrite = false): self {
$this->builder->hintShardKey($column, $value, $overwrite);
return $this;
}

public function runAcrossAllShards() {
public function runAcrossAllShards(): self {
$this->builder->runAcrossAllShards();
return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/private/DB/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public function addSelect(...$selects) {
return $this;
}

private function addOutputColumns(array $columns) {
private function addOutputColumns(array $columns): void {
foreach ($columns as $column) {
if (is_array($column)) {
$this->addOutputColumns($column);
Expand Down Expand Up @@ -1370,11 +1370,11 @@ public function escapeLikeParameter(string $parameter): string {
return $this->connection->escapeLikeParameter($parameter);
}

public function hintShardKey(string $column, mixed $value, bool $overwrite = false) {
public function hintShardKey(string $column, mixed $value, bool $overwrite = false): self {
return $this;
}

public function runAcrossAllShards() {
public function runAcrossAllShards(): self {
// noop
return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private function registerOrder(string $column, string $order): void {
];
}

public function hintShardKey(string $column, mixed $value, bool $overwrite = false) {
public function hintShardKey(string $column, mixed $value, bool $overwrite = false): self {
if ($overwrite) {
$this->primaryKeys = [];
$this->shardKeys = [];
Expand All @@ -310,7 +310,7 @@ public function hintShardKey(string $column, mixed $value, bool $overwrite = fal
return $this;
}

public function runAcrossAllShards() {
public function runAcrossAllShards(): self {
$this->allShards = true;
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEnt
}
}

private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath) {
private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath): void {
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
$fileIds = $this->getChildIds($sourceCache->getNumericStorageId(), $sourceEntry->getPath());
} else {
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Memcache/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace OC\Memcache;

use Closure;
use OCP\Cache\CappedMemoryCache;
use OCP\ICache;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -40,15 +41,15 @@ class Factory implements ICacheFactory {
private IProfiler $profiler;

/**
* @param callable $globalPrefixClosure
* @param Closure $globalPrefixClosure
* @param LoggerInterface $logger
* @param ?class-string<ICache> $localCacheClass
* @param ?class-string<ICache> $distributedCacheClass
* @param ?class-string<IMemcache> $lockingCacheClass
* @param string $logFile
*/
public function __construct(
private $globalPrefixClosure,
private Closure $globalPrefixClosure,
LoggerInterface $logger,
IProfiler $profiler,
?string $localCacheClass = null,
Expand Down
1 change: 0 additions & 1 deletion lib/private/Preview/BackgroundCleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IDBConnection;
use function Symfony\Component\Translation\t;

class BackgroundCleanupJob extends TimedJob {
/** @var IDBConnection */
Expand Down
4 changes: 2 additions & 2 deletions lib/public/DB/QueryBuilder/IQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,15 +1036,15 @@ public function getColumnName($column, $tableAlias = '');
* @return $this
* @since 30.0.0
*/
public function hintShardKey(string $column, mixed $value, bool $overwrite = false);
public function hintShardKey(string $column, mixed $value, bool $overwrite = false): self;

/**
* Set the query to run across all shards if sharding is enabled.
*
* @return $this
* @since 30.0.0
*/
public function runAcrossAllShards();
public function runAcrossAllShards(): self;

/**
* Get a list of column names that are expected in the query output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function getQueryBuilder(): PartitionedQueryBuilder {
}
}

private function setupFileCache() {
private function setupFileCache(): void {
$this->cleanupDb();
$query = $this->getQueryBuilder();
$query->insert('storages')
Expand Down Expand Up @@ -92,7 +92,7 @@ private function setupFileCache() {
$query->executeStatement();
}

private function cleanupDb() {
private function cleanupDb(): void {
$query = $this->getQueryBuilder();
$query->delete('storages')
->where($query->expr()->gt('numeric_id', $query->createNamedParameter(1000000, IQueryBuilder::PARAM_INT)));
Expand All @@ -115,7 +115,7 @@ private function cleanupDb() {
$query->executeStatement();
}

public function testSimpleOnlyPartitionQuery() {
public function testSimpleOnlyPartitionQuery(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

Expand All @@ -129,7 +129,7 @@ public function testSimpleOnlyPartitionQuery() {
$this->assertEquals($results[0]['path'], 'file1');
}

public function testSimplePartitionedQuery() {
public function testSimplePartitionedQuery(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

Expand All @@ -151,7 +151,7 @@ public function testSimplePartitionedQuery() {
$this->assertEquals($results[0]['path'], 'file1');
}

public function testMultiTablePartitionedQuery() {
public function testMultiTablePartitionedQuery(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache', 'filecache_extended']));

Expand All @@ -174,7 +174,7 @@ public function testMultiTablePartitionedQuery() {
$this->assertEquals($results[0]['upload_time'], 1234);
}

public function testPartitionedQueryFromSplit() {
public function testPartitionedQueryFromSplit(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

Expand All @@ -195,7 +195,7 @@ public function testPartitionedQueryFromSplit() {
$this->assertEquals($results[0]['path'], 'file1');
}

public function testMultiJoinPartitionedQuery() {
public function testMultiJoinPartitionedQuery(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

Expand Down
14 changes: 7 additions & 7 deletions tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function getQueryBuilder(string $table, string $shardColumn, string $pri
);
}

public function testGetShardKeySingleParam() {
public function testGetShardKeySingleParam(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('fileid', 'path')
->from('filecache')
Expand All @@ -56,7 +56,7 @@ public function testGetShardKeySingleParam() {
$this->assertEquals([10], $query->getShardKeys());
}

public function testGetPrimaryKeyParam() {
public function testGetPrimaryKeyParam(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('fileid', 'path')
->from('filecache')
Expand All @@ -66,7 +66,7 @@ public function testGetPrimaryKeyParam() {
$this->assertEquals([], $query->getShardKeys());
}

public function testValidateWithShardKey() {
public function testValidateWithShardKey(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('fileid', 'path')
->from('filecache')
Expand All @@ -76,7 +76,7 @@ public function testValidateWithShardKey() {
$this->assertTrue(true);
}

public function testValidateWithPrimaryKey() {
public function testValidateWithPrimaryKey(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('fileid', 'path')
->from('filecache')
Expand All @@ -86,7 +86,7 @@ public function testValidateWithPrimaryKey() {
$this->assertTrue(true);
}

public function testValidateWithNoKey() {
public function testValidateWithNoKey(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('fileid', 'path')
->from('filecache')
Expand All @@ -97,7 +97,7 @@ public function testValidateWithNoKey() {
$this->fail('exception expected');
}

public function testValidateNonSharedTable() {
public function testValidateNonSharedTable(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('configvalue')
->from('appconfig')
Expand All @@ -107,7 +107,7 @@ public function testValidateNonSharedTable() {
$this->assertTrue(true);
}

public function testGetShardKeyMultipleSingleParam() {
public function testGetShardKeyMultipleSingleParam(): void {
$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
$query->select('fileid', 'path')
->from('filecache')
Expand Down
Loading