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

[12] fix moving folders out of a cache jail #5655

Merged
merged 6 commits into from
Jul 13, 2017

Conversation

icewind1991
Copy link
Member

Backport of #5424

@icewind1991 icewind1991 added the 3. to review Waiting for reviews label Jul 8, 2017
@icewind1991 icewind1991 added this to the Nextcloud 12.0.1 milestone Jul 8, 2017
@mention-bot
Copy link

@icewind1991, thanks for your PR! By analyzing the history of the files in this pull request, we identified @rullzer, @nickvergessen and @LukasReschke to be potential reviewers.

@codecov
Copy link

codecov bot commented Jul 8, 2017

Codecov Report

Merging #5655 into stable12 will increase coverage by 0.02%.
The diff coverage is 87.5%.

@@              Coverage Diff               @@
##             stable12    #5655      +/-   ##
==============================================
+ Coverage       54.09%   54.12%   +0.02%     
- Complexity      22408    22422      +14     
==============================================
  Files            1379     1380       +1     
  Lines           85706    85767      +61     
  Branches         1329     1329              
==============================================
+ Hits            46365    46422      +57     
- Misses          39341    39345       +4
Impacted Files Coverage Δ Complexity Δ
version.php 0% <0%> (ø) 0 <0> (ø) ⬇️
lib/private/Repair.php 27.84% <0%> (-0.36%) 19 <0> (ø)
lib/private/Files/Cache/Wrapper/CacheJail.php 88.09% <100%> (+0.29%) 38 <1> (+1) ⬆️
lib/private/Repair/NC13/RepairInvalidPaths.php 93.1% <93.1%> (ø) 13 <13> (?)
lib/private/Files/Cache/Propagator.php 94.93% <0%> (-1.27%) 16% <0%> (ø)
lib/private/Security/CertificateManager.php 90.81% <0%> (-1.03%) 39% <0%> (ø)
lib/private/Server.php 93.45% <0%> (+0.14%) 120% <0%> (ø) ⬇️
apps/comments/lib/EventHandler.php 87.5% <0%> (+8.33%) 7% <0%> (ø) ⬇️

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

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

Works 👍

@MorrisJobke MorrisJobke requested a review from rullzer July 10, 2017 07:08
@LukasReschke
Copy link
Member

Do we have some idea about the performance here if you have like 20 million files in the file cache? What is the execution time here?

If this would take ages we may need to have a repair step if someone enters a folder or so.

@rullzer
Copy link
Member

rullzer commented Jul 12, 2017

@LukasReschke well it should only happen on files that got corrupted. And if you have 20k corrupted files then we still should fix them all...

From my POV a PR that fixes it properly on update is way better than all kinds of dark magic when entering a folder... because that will basically require extra queries on each access...

))
->where($builder->expr()->neq('f.path', $computedPath));

return $query->execute()->fetchAll();
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be way to huge if you have some big corrupted shares for example?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, it should be chunked somehow... Otherwise the MySQL server will go away

Copy link
Member Author

Choose a reason for hiding this comment

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

switched to a generator that fetches rows seperate

private function update($fileid, $newPath) {
$builder = $this->connection->getQueryBuilder();

$query = $builder->update('filecache')
Copy link
Member

Choose a reason for hiding this comment

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

Please create this only once and just set the parameters afterwards

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

private function getId($storage, $path) {
$builder = $this->connection->getQueryBuilder();

$query = $builder->select('fileid')
Copy link
Member

Choose a reason for hiding this comment

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

Please create this only once and just set the parameters afterwards

Copy link
Member Author

Choose a reason for hiding this comment

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

While I agree that that would be the best thing to do in theory, it adds to much code complexity for the expected gain in this case.

Copy link
Member

Choose a reason for hiding this comment

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

How I see it is that we execute this like 100.000 times on our instance. Not sure if that is "negligible"?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

private function reparent($from, $to) {
$builder = $this->connection->getQueryBuilder();

$query = $builder->update('filecache')
Copy link
Member

Choose a reason for hiding this comment

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

Please create this only once and just set the parameters afterwards

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

private function delete($fileid) {
$builder = $this->connection->getQueryBuilder();

$query = $builder->delete('filecache')
Copy link
Member

Choose a reason for hiding this comment

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

Please create this only once and just set the parameters afterwards

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

->where($builder->expr()->neq('f.path', $computedPath));

$result = $query->execute();
while ($row = $result->fetch()) {
Copy link
Member

Choose a reason for hiding this comment

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

this still selects potentially 100k entries or more in one query and kills the database server.

It's not php having the problem. Please just use a limit and loop this method until the result set is empty....

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@codecov-io
Copy link

codecov-io commented Jul 12, 2017

Codecov Report

Merging #5655 into stable12 will increase coverage by 0.03%.
The diff coverage is 89.53%.

@@              Coverage Diff               @@
##             stable12    #5655      +/-   ##
==============================================
+ Coverage       54.09%   54.13%   +0.03%     
- Complexity      22413    22433      +20     
==============================================
  Files            1379     1380       +1     
  Lines           85719    85802      +83     
  Branches         1329     1329              
==============================================
+ Hits            46368    46445      +77     
- Misses          39351    39357       +6
Impacted Files Coverage Δ Complexity Δ
version.php 0% <0%> (ø) 0 <0> (ø) ⬇️
lib/private/Repair.php 27.84% <0%> (-0.36%) 19 <0> (ø)
lib/private/Files/Cache/Wrapper/CacheJail.php 88.09% <100%> (+0.29%) 38 <1> (+1) ⬆️
lib/private/Repair/NC13/RepairInvalidPaths.php 93.75% <93.75%> (ø) 19 <19> (?)

@MorrisJobke
Copy link
Member

@icewind1991 Please rebase to fix the autoloader failure.

icewind1991 and others added 6 commits July 13, 2017 13:08
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991
Copy link
Member Author

@icewind1991 Please rebase to fix the autoloader failure.

Done

Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

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

Looks good to me. Lets do this!

@MorrisJobke MorrisJobke merged commit 9097204 into stable12 Jul 13, 2017
@MorrisJobke MorrisJobke deleted the moveFromCache-from-shared-12 branch July 13, 2017 14:36
@MorrisJobke MorrisJobke mentioned this pull request Jul 13, 2017
@MorrisJobke
Copy link
Member

Ported the added fixes to master: #5715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants