fix(sharing): Avoid (dead)locking during orphan deletion#43252
Merged
fix(sharing): Avoid (dead)locking during orphan deletion#43252
Conversation
Member
Author
|
The old test still passes. This is good to go. |
Member
Author
|
/backport to stable28 |
Member
Author
|
/backport to stable27 |
Member
Author
|
/backport to stable26 |
solracsf
reviewed
Feb 1, 2024
come-nc
reviewed
Feb 1, 2024
Contributor
come-nc
left a comment
There was a problem hiding this comment.
Is it not cleaner to select everything and chunk the deletes with array_chunk? It avoids the premature stop I think.
Member
Author
|
Avoids the stop but could exhaust memory if there are lots of orphans |
Member
Agree, same as #41272 |
come-nc
approved these changes
Feb 1, 2024
Contributor
come-nc
left a comment
There was a problem hiding this comment.
Hum ok but that would mean like a LOT of orphans. Other things will break first :-P
Anyway, fine with either approach.
juliusknorr
approved these changes
Feb 8, 2024
5 tasks
Member
|
I've also created #43605 to reduce the interval from every 15m to daily |
Member
Author
|
This is done |
Member
|
Conflicting due to #43605 |
f0743d5 to
5073fdb
Compare
Member
|
rebased |
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
5073fdb to
5c20f5b
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Concurrent modifications of shared entries in oc_filecache makes the share orphan background job lock. This is fine. If the row is UPDATED, we don't care. If the row is DELETEd, the next background job will catch it.
This replaces widely locking DELETE with SELECT+DELETE. See code comments.
How to test
The real world (dead)lock is hard to reproduce in a lab setup. You have to simulate concurrent modifications of filecache.
SELECT id FROM oc_jobs WHERE class = 'OCA\\Files_Sharing\\DeleteOrphanedSharesJob'. Note down the job id.SELECT file_target, file_source FROM oc_share ORDER BY id DESC LIMIT 2;. These are your f1 and f2 shares. Note down the file_source of f1.SELECT storage, path_hash FROM oc_filecache WHERE fileid=<file_source>;. Note down storage and path_hash values.START TRANSACTION;UPDATE `oc_filecache` SET `mtime` = GREATEST(`mtime`, 1706777193), `etag` = '659cf751000cd' WHERE (`storage` = <storage>) AND (`path_hash` IN (<path_hash>));php occ background-job:execute <id> --force-executemaster: job will stall. Run
ROLLBACK;in the datbase shell to unlock the occ command.here: job will finish and clean up the oc_share entry of f2 despite the lock on f1's filecache entry. Run
ROLLBACK;to unlock your dev env for other operations ;-)Checklist