-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Cache in filecache #28166
Cache in filecache #28166
Conversation
lib/private/Files/Cache/Cache.php
Outdated
@@ -79,6 +80,11 @@ class Cache implements ICache { | |||
protected $connection; | |||
|
|||
/** | |||
* @var CappedMemoryCache | |||
*/ | |||
public static $metaDataCache = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why static?
There was a problem hiding this comment.
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.
lib/private/Files/Cache/Cache.php
Outdated
@@ -137,9 +155,10 @@ public function get($file) { | |||
//merge partial data | |||
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static ?
There was a problem hiding this comment.
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.
@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 ? |
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) -> 💥 |
Any new comments? I would really see sth like that be merged. Would small "filecache code" refactor and protection be needed here? |
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. |
moved to triage, assuming this will not be ready for 10.0.3 |
e0e3d27
to
d4dc116
Compare
Rebased |
d4dc116
to
3783534
Compare
encryption also needs changes: owncloud/encryption#13 |
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. |
Custom cache implementations would not benefit from this and might not even extend from our 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 |
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. |
lib/private/Files/Cache/Cache.php
Outdated
}, $files); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
private function fixTypes(array &$data) { | ||
$data['fileid'] = 0 + $data['fileid']; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Happy to postpone this. |
@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
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. |
Argh, you're right |
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@@ -128,45 +154,21 @@ public function get($file) { | |||
$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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -78,6 +79,18 @@ class Cache implements ICache { | |||
*/ | |||
protected $connection; | |||
|
|||
/** | |||
* caches 2048 filecache rows |
There was a problem hiding this comment.
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?
@@ -316,6 +346,7 @@ public function update($id, array $data) { | |||
') AND `fileid` = ? '; | |||
$this->connection->executeQuery($sql, $params); | |||
|
|||
self::$metaDataCache->clear(); |
There was a problem hiding this comment.
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)
@@ -441,6 +482,7 @@ public function remove($file) { | |||
if ($entry['mimetype'] === 'httpd/unix-directory') { | |||
$this->removeChildren($entry); | |||
} | |||
self::$metaDataCache->clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same here
@@ -544,12 +587,14 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { | |||
} else { | |||
$this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); | |||
} | |||
self::$metaDataCache->clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
|
|
Safer, alternative approach to this PR by fixing the app logic - #31486 |
@@ -220,6 +229,9 @@ public function testClearCommentReadMarks() { | |||
'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'), | |||
'path_hash' => $query->createNamedParameter(\md5('apps/files/tests/deleteorphanedtagsjobtest.php')), | |||
])->execute(); | |||
if (Cache::$metaDataCache !== null) { |
There was a problem hiding this comment.
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.
@@ -129,6 +130,9 @@ public function deleteFiles ($numericId, OutputInterface $output) { | |||
); | |||
$output->write("deleting files for storage $numericId ... "); | |||
$count = $queryBuilder->execute(); | |||
if (Cache::$metaDataCache !== null) { |
There was a problem hiding this comment.
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
@@ -101,6 +102,9 @@ protected function setup() { | |||
$filesQuery->setParameter(2, \md5('file' . $i)); | |||
$filesQuery->execute(); | |||
} | |||
if (Cache::$metaDataCache !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same (clear)
@@ -53,6 +54,9 @@ public function increaseFileIDsBeyondMax32bits(){ | |||
'', '4', '3', '163', '1499256550', '1499256550', | |||
'0', '0', '595cd6e63f375', '27', 'NULL')"; | |||
$this->connection->executeQuery($query); | |||
if (Cache::$metaDataCache !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same (clear)
@@ -96,6 +96,10 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) { | |||
} | |||
|
|||
$builder->execute(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same (clear)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also in other places
Closing in favor of OCIS. |
alternative approach to #28165