Skip to content

Cache in filecache#28166

Closed
butonic wants to merge 1 commit into
masterfrom
cache-in-filecache
Closed

Cache in filecache#28166
butonic wants to merge 1 commit into
masterfrom
cache-in-filecache

Conversation

@butonic

@butonic butonic commented Jun 20, 2017

Copy link
Copy Markdown
Contributor

alternative approach to #28165


/**
* @var CappedMemoryCache
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why static?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing revealed that we instantiate more than one instance of this class which works against the caching effect.

Comment thread lib/private/Files/Cache/Cache.php Outdated
if (!$data and is_string($file)) {
if (isset($this->partial[$file])) {
$data = $this->partial[$file];
return $this->partial[$file]; // return here, no need cache partial entries

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure this is not necessary?

/**
* @var CappedMemoryCache
*/
private static $metaDataCache = null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

um leftover code from the previous attempt.

@PVince81

Copy link
Copy Markdown
Contributor

@mrow4a would be good if you could also check this out. I remember you looked into wasteful DB queries related to file cache. Maybe you have more insights. Didn't you have a PR adressing this or some piece of this differently ?

@mrow4a

mrow4a commented Jun 22, 2017

Copy link
Copy Markdown
Contributor

Will have a look also later, looks really promising, it is something I wanted to have. There is one disavantage -> if someone forgets to use CacheIndex somewhere and uses filecache directly to write (read is ok) -> 💥

@mrow4a

mrow4a commented Jun 27, 2017

Copy link
Copy Markdown
Contributor

Any new comments? I would really see sth like that be merged. Would small "filecache code" refactor and protection be needed here?

@PVince81

Copy link
Copy Markdown
Contributor

I'm not sure. It feels like a workaround on top of a sub-par architecture.

On the other hand, caching stuff locally is what we've been doing everywhere with other things to prevent talking to the DB repeatedly.

@felixboehm

Copy link
Copy Markdown
Contributor

moved to triage, assuming this will not be ready for 10.0.3

@tomneedham tomneedham force-pushed the cache-in-filecache branch from e0e3d27 to d4dc116 Compare July 24, 2017 11:16
@tomneedham

Copy link
Copy Markdown
Contributor

Rebased

@butonic

butonic commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

encryption also needs changes: owncloud/encryption#13

@tomneedham tomneedham modified the milestones: development, triage Sep 6, 2017
@tomneedham tomneedham changed the title [WIP] Cache in filecache Cache in filecache Sep 6, 2017
@tomneedham

Copy link
Copy Markdown
Contributor

8.2 -> 10.0.3beta2 upgrade succeeded with this - which will have helped speed up the upgrade process for large amounts of reshares when coming from 8.2.

@PVince81

PVince81 commented Sep 6, 2017

Copy link
Copy Markdown
Contributor

metaDataCache should rather be an instance variable of our default Cache implementation.

Custom cache implementations would not benefit from this and might not even extend from our Cache implementations.

The only advantage of having it static here is the ability to quickly clear it from various locations, while normally you should go to the storage and do a $storage->getCache() which is usually more expensive.

@PVince81

PVince81 commented Sep 6, 2017

Copy link
Copy Markdown
Contributor

Also I wonder if this should/could be implemented as a CacheWrapper instead. We might lose the ability to clear it from outside unless we keep the staticness.

}

private function fixTypes(array &$data) {
$data['fileid'] = 0 + $data['fileid'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this here for caching ? I expect to see potential additional issues

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I see this was moved from another place

@tomneedham

Copy link
Copy Markdown
Contributor

Happy to postpone this.

@butonic

butonic commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

@PVince81 The initial implementation was a cache wrapper: https://github.com/owncloud/core/pull/28165/files

Nice and clean approach ... isn't it? Unfortunately, we

  1. Instantiate multiple instances for the same share storages, defeating the cache effect.
  2. Tests, encryption and other technical debt directly manipulate the filecache in the db by executing their own SQL.

I added the necessary things we need to do: https://github.com/owncloud/core/pull/28166/files#diff-b4012cb6106f634acc5ff12ef395021fR85-R87

so ... no this cannot be an instance variable ... because ... still too much crappy code in other places.

@PVince81

PVince81 commented Sep 7, 2017

Copy link
Copy Markdown
Contributor

so ... no this cannot be an instance variable ... because ... still too much crappy code in other places.

Argh, you're right

@mrow4a

mrow4a commented May 1, 2018

Copy link
Copy Markdown
Contributor

I can see one disadvantage - if new code is written which writes to filecache, dev needs to be aware that cache needs to be cleaned with that static function. Apart from that - if no fragment of the code which writes to filecache has not been forgoten - looks good.

*
* FIXME first, refactor this class as an entity and add any necessary methods to its mapper
* FIXME then, get rid of all the places that directly touch the tables
* FIXME finally, make this private non-static

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan it to have as separate PR? Do you expect it to be large change later?

@mrow4a mrow4a left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@butonic please see the comments

$result = $this->connection->executeQuery($sql, $params);
$data = $result->fetch();

//FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not sure if you removed the hack, so FIXME still needs to stay

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole logic is not changed, and under function fixTypes

protected $connection;

/**
* caches 2048 filecache rows

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 2048? This PR usecase is I guess a repetitive calls during GET and PUT. Not sure if we need more then 32 rows in cache. What do you think? Won't it impact PROPFIND memory usage too much?

') AND `fileid` = ? ';
$this->connection->executeQuery($sql, $params);

self::$metaDataCache->clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this shouldnt be as first line. There is small chance your filecache will be out of sync for very small time (not sure if this is that important)

if ($entry['mimetype'] === 'httpd/unix-directory') {
$this->removeChildren($entry);
}
self::$metaDataCache->clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here

} else {
$this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath);
}
self::$metaDataCache->clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@PVince81

Copy link
Copy Markdown
Contributor
  • please rebase for more recent CI
  • please run smashbox tests against this to confirm

@butonic

butonic commented May 15, 2018

Copy link
Copy Markdown
Contributor Author
  • move more sql to the filecache class
  • always clear filecache in memory cache after every repair step
  • always clear filecache in memory cache after every background job
  • always clear filecache in memory cache after every test class

@mrow4a

mrow4a commented May 19, 2018

Copy link
Copy Markdown
Contributor

Safer, alternative approach to this PR by fixing the app logic - #31486

@DeepDiver1975

Copy link
Copy Markdown
Member

@butonic would you agree on pushing #31486 instead of this one? THX

'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'),
'path_hash' => $query->createNamedParameter(\md5('apps/files/tests/deleteorphanedtagsjobtest.php')),
])->execute();
if (Cache::$metaDataCache !== null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear metadata cache before executing the query.

);
$output->write("deleting files for storage $numericId ... ");
$count = $queryBuilder->execute();
if (Cache::$metaDataCache !== null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear before executing the query

$filesQuery->setParameter(2, \md5('file' . $i));
$filesQuery->execute();
}
if (Cache::$metaDataCache !== null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same (clear)

'', '4', '3', '163', '1499256550', '1499256550',
'0', '0', '595cd6e63f375', '27', 'NULL')";
$this->connection->executeQuery($query);
if (Cache::$metaDataCache !== null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same (clear)

}

$builder->execute();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same (clear)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also in other places

@butonic

butonic commented Feb 18, 2019

Copy link
Copy Markdown
Contributor Author

Closing in favor of OCIS.

@butonic butonic closed this Feb 18, 2019
@butonic butonic deleted the cache-in-filecache branch February 18, 2019 09:58
@lock lock Bot locked as resolved and limited conversation to collaborators Feb 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants