Skip to content

Use transactions when renaming directory contents #13948

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

Merged
merged 1 commit into from
Feb 8, 2015

Conversation

icewind1991
Copy link
Contributor

Or "how to save 99% execution time with 2 simple lines" 😄

From 33s to ~600ms when moving ~5000 files (comparison)

For #13391

cc @PVince81 @DeepDiver1975

@PVince81
Copy link
Contributor

PVince81 commented Feb 6, 2015

Wow, okay

@PVince81
Copy link
Contributor

PVince81 commented Feb 6, 2015

While this might speed up database update, the time window where the filesystem contents and cache do not match will still exist (and any file operation happening in-between will trigger a scanner process that will try and update it). So that ticket will probably need additional fixes.

@PVince81
Copy link
Contributor

PVince81 commented Feb 6, 2015

  • needs to be tested on SQLite too

Do we have a unit test that tests this part of code ? (I suppose we do)

@MorrisJobke
Copy link
Contributor

Wow o.O We should check our code more often for such stuff.

@icewind1991
Copy link
Contributor Author

So that ticket will probably need additional fixes.

Agree, this should solve the majority of the issues though

@MorrisJobke
Copy link
Contributor

@icewind1991 So this is for a rename of a folder, right?

@icewind1991
Copy link
Contributor Author

@icewind1991 So this is for a rename of a folder, right?

Yes, for my test I created a folder with 5k small files in it

@icewind1991
Copy link
Contributor Author

Do we have a unit test that tests this part of code ? (I suppose we do)

Yes

@scrutinizer-notifier
Copy link

The inspection completed: 4 new issues

@ghost
Copy link

ghost commented Feb 6, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/8913/
Test PASSed.

@MorrisJobke
Copy link
Contributor

Same here. Tested with SQLite and 10.000 files from 32s to 0.9s - compare

Works and code looks good 👍

@MorrisJobke
Copy link
Contributor

Let me test with mysql and postgres again.

@MorrisJobke
Copy link
Contributor

Works with Postgres 9.4 and Mysql 5.6 too.

@MorrisJobke
Copy link
Contributor

I guess this reduces my problem with the data loss while renaming such a folder a lot.

@DeepDiver1975 @karlitschek I would propose this for backporting at least to stable8 (for 8.0.1 maybe)

@karlitschek
Copy link
Contributor

Sorry. We only backport serious bugfixes. The risk for something is too high.

@DeepDiver1975 DeepDiver1975 added this to the 8.1-next milestone Feb 6, 2015
@icewind1991
Copy link
Contributor Author

We can do even better: #13956 uses some dark sql rituals to bring the whole thing down to a single query.

@DeepDiver1975
Copy link
Member

uses some dark sql rituals

like this ....

black-magic

@LukasReschke
Copy link
Member

Black magic has been verified by me: 👍

LukasReschke added a commit that referenced this pull request Feb 8, 2015
Use transactions when renaming directory contents
@LukasReschke LukasReschke merged commit 0e604aa into master Feb 8, 2015
@LukasReschke LukasReschke deleted the cache-move-transaction branch February 8, 2015 18:08
@PVince81
Copy link
Contributor

@karlitscheck so... data loss on folder renames isn't a serious bug ?

@MorrisJobke
Copy link
Contributor

@karlitschek ^

@d10r
Copy link

d10r commented Mar 4, 2015

If you care about a users opinion (using it at our company, ~25 users): I consider this issue to be critical, not just serious. We started to plan migrating to another sync solution because of occasional data loss with OC.
The additional Apps OC offers are nice, but if the core feature isn't reliable, that's a killer for us.

@christianrj
Copy link

@bcg-didi Same for us (~31 users). I reported various bugs related to file operations, none of them was fixed so far, and some of them was closed for no reason. If these bugs are not resolved soon, we will migrate to another sync solution too (which we are already testing).

@MorrisJobke
Copy link
Contributor

@karlitschek Should I prepare a backport PR?

@DeepDiver1975
Copy link
Member

Should I prepare a backport PR?

yes please - thx

@MorrisJobke
Copy link
Contributor

Backport: #14752

@Helios07
Copy link

Hey guys,
I do not want to play the bad cop here, but as far as I understand this function, there is a serious risk for errors because of the transaction.
The "commit" of the transaction will be executed either the executeAudited()-function succeeds or not. I cannot see any error handling here and no rollback. I would expect a "try" and a "catch" routine here like it is written here: http://php.net/manual/de/pdo.transactions.php
Please do not underestimate the risk of failing database actions. We run a huge owncloud (20k users at the moment and rising daily) with a clustered database. In a database cluster it is quite normal that you have deadlocks when two application servers write to different database nodes. Without transactions this is not a critical problem because you can make Galera (the cluster solution) retry the commands. But as far as I know, with transactions, such a retry is not possible.

So to conclude this, please prove me wrong, but I can see no error handling here which could corrupt the data!

@MorrisJobke
Copy link
Contributor

@icewind1991 @PVince81 Please have a look at the comment. Is there an error handling in place? I don't think so. What can we do in this case? Retry for ourself? or rollback this somehow?

@PVince81
Copy link
Contributor

Not sure. It seems we have autocommit enabled here https://github.com/owncloud/core/blob/master/lib/private/db/connectionfactory.php#L109.
So if I understand well, if an exception occurs the instruction pointer will jump to the next "catch" block which is likely to be far away, and does NOT contain any rollback code.

We probably need to find all locations in the code that have transactions and add a catch block that rolls back, as advised here: http://doctrine-dbal.readthedocs.org/en/latest/reference/transactions.html#transactions

@MorrisJobke
Copy link
Contributor

@Helios07 @icewind1991 @PVince81 to not forget about this I opened a technical debt ticket: #16445

@Helios07
Copy link

Thank you very much.

@danimo
Copy link
Contributor

danimo commented May 25, 2015

Ping? We just got owncloud/client#3275, and I think it's really serious to resolve this properly. /cc @DeepDiver1975

@hoho508
Copy link

hoho508 commented May 26, 2015

#16558

@PVince81
Copy link
Contributor

@danimo this PR was already merged a while ago

@PVince81
Copy link
Contributor

@icewind1991 any reason why the update of the actual parent folder isn't inside the transaction ? https://github.com/owncloud/core/pull/13948/files#diff-fb4e3a03c02988e8dde2af0b55f7b96fR421

@lock lock bot locked as resolved and limited conversation to collaborators Aug 12, 2019
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.