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

[wip] Filecache chunking #43576

Closed
wants to merge 7 commits into from
Closed

[wip] Filecache chunking #43576

wants to merge 7 commits into from

Conversation

icewind1991
Copy link
Member

@icewind1991 icewind1991 commented Feb 14, 2024

  • block queries to filecache tables that don't go through the sharding logic
  • allow getting a query builder for the filecache tables when provided a storage id to select a shard
    • probably not going to expose this to apps and leave it internal for the cache handling
  • provide methods for querying by fileid without known storage

github-advanced-security[bot]

This comment was marked as resolved.

@@ -693,6 +717,7 @@
* @return $this This QueryBuilder instance.
*/
public function from($from, $alias = null) {
$this->checkTableAccess($from);

Check failure

Code scanning / Psalm

ImplicitToStringCast Error

Argument 1 of OC\DB\QueryBuilder\QueryBuilder::checkTableAccess expects string, but OCP\DB\QueryBuilder\IQueryFunction|string provided with a __toString method
}

/**
* @param List<int> $storages

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OC\Files\Cache\List does not exist
}

/**
* @param List<int> $storages

Check failure

Code scanning / Psalm

MismatchingDocblockParamType Error

Parameter $storages has wrong type 'OC\Files\Cache\List', should be 'array<array-key, mixed>'

/**
* @param List<int> $storages
* @return array<int, List<int>>

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OC\Files\Cache\List does not exist
* The results from the callback will be combined and returned
*
* @template T
* @param List<int> $storages

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OC\Files\Cache\List does not exist
if (in_array('owner', $requestedFields) || in_array('share_with', $requestedFields) || in_array('share_type', $requestedFields)) {
$this->equipQueryForShares($query);
}
$rawEntries = $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $builder, $storages) use ($requestedFields, $searchQuery, $cachesByStorage) {

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OC\Files\Cache\CacheDatabase::queryStorages expects OC\Files\Cache\List, but array<T:fn-oc\files\cache\querysearchhelper::searchincaches as array-key, int> provided
$this->equipQueryForShares($query);
}
$rawEntries = $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $builder, $storages) use ($requestedFields, $searchQuery, $cachesByStorage) {
$cachesForShard = array_map(fn (int $storage) => $cachesByStorage[$storage], $storages);

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 2 of array_map expects array<array-key, mixed>, but OC\Files\Cache\List provided
lib/private/Files/Config/UserMountCache.php Fixed Show fixed Hide fixed

return $list;
return $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $qb, array $storages) use ($fileIdsByStorage) {

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OC\Files\Cache\CacheDatabase::queryStorages expects OC\Files\Cache\List, but array<array-key, mixed> provided
Comment on lines 128 to 149
return $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $qb, array $storages) use ($fileIdsByStorage) {
$fileIds = [];
foreach ($storages as $storage) {
$fileIds += $fileIdsByStorage[$storage];
}

$qb->select('file_id', 'json', 'sync_token')->from(self::TABLE_METADATA);
$qb->where(
$qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
);

$list = [];
$result = $qb->executeQuery();
while ($data = $result->fetch()) {
$fileId = (int) $data['file_id'];
$metadata = new FilesMetadata($fileId);
try {
$metadata->importFromDatabase($data);
} catch (FilesMetadataNotFoundException) {
continue;
}
$list[$fileId] = $metadata;
}
return $list;
});

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 2 of OC\Files\Cache\CacheDatabase::queryStorages expects callable(OC\Files\Cache\CacheQueryBuilder, OC\Files\Cache\List):array<array-key, OC\FilesMetadata\Model\FilesMetadata>, but impure-Closure(OC\Files\Cache\CacheQueryBuilder, array<array-key, mixed>):array<int, OC\FilesMetadata\Model\FilesMetadata> provided
@icewind1991 icewind1991 force-pushed the filecache-chunking branch 7 times, most recently from f06b5b8 to 6d4e9c0 Compare March 6, 2024 13:54
@@ -53,7 +56,8 @@
* @throws Exception
*/
public function store(IFilesMetadata $filesMetadata): void {
$qb = $this->dbConnection->getQueryBuilder();
$file = $this->cacheDatabase->getByFileId($filesMetadata->getFileId());

Check failure

Code scanning / Psalm

UndefinedMethod Error

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
@@ -72,7 +76,12 @@
*/
public function getMetadataFromFileId(int $fileId): IFilesMetadata {
try {
$qb = $this->dbConnection->getQueryBuilder();
$file = $this->cacheDatabase->getByFileId($fileId);

Check failure

Code scanning / Psalm

UndefinedMethod Error

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
$list[$fileId] = $metadata;
public function getMetadataFromFileIds(array $fileIds, array $storageIds = []): array {
if (!$storageIds) {
$files = $this->cacheDatabase->getByFileIds($fileIds);

Check failure

Code scanning / Psalm

UndefinedMethod Error

Method OC\Files\Cache\CacheDatabase::getByFileIds does not exist
$qb->delete(self::TABLE_METADATA)
->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$qb->executeStatement();
$file = $this->cacheDatabase->getByFileId($fileId);

Check failure

Code scanning / Psalm

UndefinedMethod Error

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
@@ -155,7 +183,8 @@
* @throws Exception
*/
public function updateMetadata(IFilesMetadata $filesMetadata): int {
$qb = $this->dbConnection->getQueryBuilder();
$file = $this->cacheDatabase->getByFileId($filesMetadata->getFileId());

Check failure

Code scanning / Psalm

UndefinedMethod Error

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
apps/files_sharing/lib/Updater.php Fixed Show fixed Hide fixed
apps/files_sharing/lib/Updater.php Fixed Show fixed Hide fixed
lib/private/Files/Config/UserMountCache.php Fixed Show fixed Hide fixed
lib/private/Files/Cache/CacheAccess.php Fixed Show fixed Hide fixed
@icewind1991 icewind1991 force-pushed the filecache-chunking branch 2 times, most recently from 8aa41af to adc3d9c Compare May 22, 2024 15:11
Signed-off-by: Robin Appelman <[email protected]>
not as performant but compatible with sharding

Signed-off-by: Robin Appelman <[email protected]>
@@ -723,26 +718,26 @@
$retryLimit = 4;
for ($i = 1; $i <= $retryLimit; $i++) {
try {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments Error

Too few arguments for OC\Files\Cache\CacheDatabase::beginTransaction - expecting storageId to be passed
@@ -723,26 +718,26 @@
$retryLimit = 4;
for ($i = 1; $i <= $retryLimit; $i++) {
try {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments Error

Too few arguments for method OC\Files\Cache\CacheDatabase::begintransaction saw 0
throw $e;
} catch (RetryableException $e) {
// Simply throw if we already retried 4 times.
if ($i === $retryLimit) {
throw $e;
}

$this->connection->rollBack();
$this->cacheDb->rollBack();

Check failure

Code scanning / Psalm

TooFewArguments Error

Too few arguments for OC\Files\Cache\CacheDatabase::rollBack - expecting storageId to be passed
throw $e;
} catch (RetryableException $e) {
// Simply throw if we already retried 4 times.
if ($i === $retryLimit) {
throw $e;
}

$this->connection->rollBack();
$this->cacheDb->rollBack();

Check failure

Code scanning / Psalm

TooFewArguments Error

Too few arguments for method OC\Files\Cache\CacheDatabase::rollback saw 0

// Sleep a bit to give some time to the other transaction to finish.
usleep(100 * 1000 * $i);
}
}
} else {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments Error

Too few arguments for OC\Files\Cache\CacheDatabase::beginTransaction - expecting storageId to be passed

// Sleep a bit to give some time to the other transaction to finish.
usleep(100 * 1000 * $i);
}
}
} else {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments Error

Too few arguments for method OC\Files\Cache\CacheDatabase::begintransaction saw 0
foreach ($shares as $share) {
if (isset($files[$share->getNodeId()])) {
$cacheItem = $files[$share->getNodeId()];
if ($this->isAccessibleResult($cacheItem->getData())) {

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod Error

Method OCP\Files\Cache\ICacheEntry::getData does not exist
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
@AndyScherzinger AndyScherzinger removed this from the Nextcloud 31 milestone Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants