Skip to content

local: skip files removed concurrently with List - #5297

Merged
ivandeex merged 1 commit into
rclone:masterfrom
ivandeex:pr-localdir
Jul 7, 2021
Merged

ivandeex merged 1 commit into
rclone:masterfrom
ivandeex:pr-localdir

Conversation

@ivandeex

@ivandeex ivandeex commented May 2, 2021 •

Copy link
Copy Markdown
Member

What is the purpose of this change?

UPDATED on 2021-06-12

This change fixes the bug described below:
if a file is removed while the local backend List() runs, the call will flag an accounting error.
The bug manifests itself if local backend is the Sync target due to intrinsic concurrency.
The odds to hit this bug depend on --checkers and --transfers.
Chunker over local backend is affected even more because updating a composite object
with a smaller size content translates into removing chunks on the underlying file system
and involves a number of List() calls.

This patch will make List skip the file.

Unit test:

go test ./fs/sync -remote TestChunkerChunk3bLocal: -run TestSyncConcurrent

or run the full rclone integration test with -backends local,chunker.

Was the change discussed in an issue or in the forum before?

No

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@ivandeex ivandeex self-assigned this May 2, 2021
@ivandeex
ivandeex marked this pull request as draft May 2, 2021 15:36
@ivandeex ivandeex mentioned this pull request May 2, 2021
38 tasks done

@ncw ncw left a comment

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.

The window for this to happen is quite small isn't it?

Do we need to recheck? Maybe just checking for os.IsNotExist on the os.Lstat is enough for us to skip the file. The listing said the file was there - the stat says its missing which means

  1. the file got deleted, or
  2. the filesystem is broken

The first is the likely case, the second is very unlikely - I've never seen it. So I'd propose just a log, skip the file and carry on.

Effectivelly your code stats the missing files twice doesn't it? So if you feel uneasy about that you could stat the file twice, but I'm not sure it is necessary.

@ivandeex ivandeex changed the title local: re-read directory list for missing items local: skip files removed concurrently with List May 2, 2021
@ivandeex

ivandeex commented May 2, 2021 •

Copy link
Copy Markdown
Member Author

I'm easy about it. The digging wasn't quite as easy. :)

tl;dr Chunker fell victim of its heavy use of List. By fixing localFs I'm rescuing the victim.

[gory-details]
I started from the bisync torture test, which gave me unexpectedly high failure rate if one of sides would be chunker. Failed mostly when a chunked file would be overwritten by a smaller contents. All returned errors in the call chain happen to be nil, but the sync (bisync calls Sync in a couple places) will abort due to the lstat error flagged by someone in the context structure shared by a number of goroutines and further bubbling up in a random sibling thread.
[/gory-details]

The window for this to happen is quite small

The interval is large enough for 4+ checkers and 4+ remover gorutines to step on each others toes within a single Sync call. Context switches happen due to IO kernel calls, and go densely because SSD+cache works fast.

@ncw

ncw commented May 3, 2021

Copy link
Copy Markdown
Member

I'm easy about it.

Simpler fix until we need to make it more complicated seems good to me.

The digging wasn't quite as easy. :)

No-ones favorite sort of bug - concurrency problems!

tl;dr Chunker fell victim of its heavy use of List. By fixing localFs I'm rescuing the victim.

:-)

The window for this to happen is quite small

The interval is large enough for 4+ checkers and 4+ remover gorutines to step on each others toes within a single Sync call. Context switches happen due to IO kernel calls, and go densely because SSD+cache works fast.

Ah yes. The interval is small in terms of code, but there is IO in there and syscalls which likely the go runtime is scheduling on so what should never happen happens all the time!

@ivandeex
ivandeex force-pushed the pr-localdir branch 4 times, most recently from e9bae51 to 32bc588 Compare May 3, 2021 16:00
@ivandeex
ivandeex force-pushed the pr-localdir branch 2 times, most recently from 403fb39 to 84c8e80 Compare May 14, 2021 14:17

@ncw ncw left a comment

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.

This looks OK to me if you want to merge it?

(It is still set to draft)

@ivandeex

Copy link
Copy Markdown
Member Author

This looks OK to me if you want to merge it?

(It is still set to draft)

It's missing unit tests:

  1. Add N "even" files to local path A, N "even" + N "odd" to B, run sync A -> B with 4+ transfers, 4+ checkers. sync runners will delete and check (list) in parallel. Failure probability is >0 without, =0 with patch.

  2. Similar but with TestChunkerChunk3bLocal: remote from the integration suite. Mix of 9-byte (3 chunks + metadata) and 0-byte (only metadata) chunked files on side A, only 9-byte guys on B, then sync A -> B. Internally reduces to removing underlying files and a lot of listings.

@ncw

ncw commented May 18, 2021

Copy link
Copy Markdown
Member

This is going to be very hard to make a test which fails reliably I think, though I'd be delighted to be proved wrong :-)

@ivandeex

ivandeex commented May 18, 2021 •

Copy link
Copy Markdown
Member Author

This is going to be very hard to make a test which fails reliably I think, though I'd be delighted to be proved wrong :-)

Flaky test is "better" (as in "gives you food for thought") than no test.
A note in PR to run the test manually as go test ./backend/bbb/... -remote rrr -count 1000
will make fail "reliably" :)
I'd prefer to have it tested for confidence. Who knows what we'll code in future. Let it save our users... :)

This change fixes the bug described below:
if a file is removed while the local backend List() runs,
the call will flag an accounting error.
The bug manifests itself if local backend is the Sync target
due to intrinsic concurrency.
The odds to hit this bug depend on --checkers and --transfers.
Chunker over local backend is affected even more because
updating a composite object with a smaller size content
translates into removing chunks on the underlying file system
and involves a number of List() calls.
@ivandeex

ivandeex commented Jun 12, 2021 •

Copy link
Copy Markdown
Member Author

@ncw

I have added the unit test which is very short and fails with ~99% probability :)
Check it out - comment out the single continue statement added by this patch and run

go test ./fs/sync -remote TestChunkerChunk3bLocal: -run TestSyncConcurrent

The TestChunkerChunk3bLocal remote is part of our standard integration tests.
The test is added as a generic fs/sync test because all backends and remotes must confirm to this consistency check.

Description updated. Ready to merge. PTAL 🙏

P.S. This block in sync.go

if _, ok := s.srcEmptyDirs[parentDir]; ok {
    delete(s.srcEmptyDirs, parentDir)
}

caused vscode warning unnecessary guard around call to delete (S1033)go-staticcheck

@ivandeex
ivandeex requested a review from ncw June 12, 2021 12:46
@ivandeex
ivandeex marked this pull request as ready for review June 12, 2021 12:46
@ivandeex

ivandeex commented Jul 7, 2021

Copy link
Copy Markdown
Member Author

@ncw ready for 1.56

@ivandeex
ivandeex merged commit 4680c07 into rclone:master Jul 7, 2021
@ivandeex
ivandeex deleted the pr-localdir branch July 7, 2021 13:50
@ivandeex ivandeex mentioned this pull request Jul 7, 2021
5 tasks done
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
…5297)

This change fixes the bug described below:
if a file is removed while the local backend List() runs,
the call will flag an accounting error.
The bug manifests itself if local backend is the Sync target
due to intrinsic concurrency.
The odds to hit this bug depend on --checkers and --transfers.
Chunker over local backend is affected even more because
updating a composite object with a smaller size content
translates into removing chunks on the underlying file system
and involves a number of List() calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants