Skip to content

chunker: allow for no-rename checkpoints on backends with slow rename - #4675

Merged
ivandeex merged 1 commit into
rclone:masterfrom
mcalman:chunker-avoid-renames
Feb 28, 2021
Merged

ivandeex merged 1 commit into
rclone:masterfrom
mcalman:chunker-avoid-renames

Conversation

@mcalman

@mcalman mcalman commented Oct 12, 2020 •

Copy link
Copy Markdown

What is the purpose of this change?

Some storage providers, such as S3 (edit) or IBM COS, don't have an efficient rename operation. When chunker finishes an upload, the server-side copy and delete operations that are done to rename temporary chunks to their final chunk names takes a very long time (in some cases nearly as long as the upload took).

This change replaces temporary chunk names with a "status" control chunk that is uploaded at the beginning of a chunked upload. All operations that require ignoring temporary chunks will check for the existence of this "status" control chunk. When an upload succeeds, the "status" control chunk is removed to signify that it is a complete upload and the chunks are no longer temporary. This removes the need for temporary chunk names entirely, and therefore avoids the rename operation that is normally done at the end of a chunked upload.

EDIT
This PR extends metadata with a random "transaction identifier" striving to remove the need for the rename operation on such backends.

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

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 :-)

@ncw

ncw commented Oct 13, 2020

Copy link
Copy Markdown
Member

@ivandeex have you got time to review this?

@ivandeex

ivandeex commented Oct 13, 2020 •

Copy link
Copy Markdown
Member

Thanks for contribution. I have a few comments.

I keep in mind that any remote filesystem can be accessed from several rclone instances, possibly modifying the same file in parallel, possibly from different rclone versions, and rclone must prevent data corruption in all known cases.

  1. Every change that introduces or removes metadata fields or introduces new control chunks or changes their semantics/behavior, must increase metadata version number. As soon a file is modified by a recent rclone (chunker), any attempt to work on it from an older rclone can corrupt data and should be rejected due to version mismatch. Currently the error message explicitly asks user to upgrade rclone (in case they upgraded one installation and forgot another). Also, chunker documentation must explicitly state what previous rclone versions are affected.

  2. With your patch, when user uploads a new version of existing file, it disappears from directory listing until upload finishes. This looks slightly unnatural. If second instance of rclone tried to work with the same file in parallel, what would give? What if another instance had opened a file while it was visible, then stalled due to external event, then proceeded to its actions?

  3. Did you consider making parallel operations wait on files marked by status instead of hiding them?

  4. Looking at line https://github.com/rclone/rclone/pull/4675/files#diff-0cc14ded5dbad90b4cd5673dc7716447fde13995a5d4fa504cb9c33701f5d7e2R964 I suspect that removal of old chunks would remove just uploaded chunks with same chunk numbers since they don't have temporary suffix anymore. I may be wrong. Did you test such scenario?

  5. I admit that chunker test suite lacks testing of parallel operations, e.g. start a few long multichunk Update()s or Update()+Move(), then cancel one of them, etc. Before we have those (I will submit an issue and start working on PR later), could you try something like that manually with your patch? I suspect there be dragons.

  6. AFAIK most supported rclone backends have fast/atomic server-side move or fast/atomic server-side copy (at least AWS S3 behaves as if it had copy-on-write and consequently fast copy). If we decide to go on with your approach to backends that don't have it, I think we'd better have a fs.Feature flag like SlowServerSideMove and activate your codepath conditionally, so we could keep on using parallel safe operations on existing backends.

  7. Instead of removing transaction ID suffix from chunk names, we could go the other way and instead of renaming chunks just update the ID in the metadata upon operation completion. This approach avoids renaming but changes notion of what temporary chunk is (permanent if suffix is registered with metadata, temporary or garbage otherwise). Also it has to accept data chunks without transaction ID from older rclone versions and migrate transparently. This idea needs more thinking, though.

UPD. Besides go test unit test rclone has integration test suite (https://github.com/rclone/rclone/blob/master/CONTRIBUTING.md#testing) that can help investigate many corner cases (though it does not test parallel access thoroughly).

@ivandeex
ivandeex self-requested a review October 13, 2020 18:24
@ivandeex

Copy link
Copy Markdown
Member

@mcalman

mcalman commented Oct 30, 2020

Copy link
Copy Markdown
Author

@ivandeex I just pushed a new commit trying out your last suggestion of permanently keeping the transaction ID suffix in chunk names. It seems like this should address most of your other concerns as well, but let me know what you think.

@leoluan1

Copy link
Copy Markdown
Contributor

@ivandeex @ncw The impact of the performance penalty and server-side overhead of using the copy-and-delete rename operation is a problem broader than IBM COS. I tried Amazon S3 backend it also incurs copy and delete and it takes a few seconds for each one GB chunk object. So we should use the “Remote: S3” label instead of "IBM COS"? Chunker is a great feature for large files, but the S3 server-side copy for large files (e.g., terabytes) can add hours of delay before a Rclone copy operation completes. Is it possible to allow this PR to be merged for 1.54? I had a discussion with Max on addressing backward compatibility by adding a simple extension to his fix to allow the new Rclone to read the files created by existing Rclone versions without the fix. We will also test the current Rclone version's behavior when seeing files created by the new version. Max said that the code already passes the integration tests. Please let us know what else we might be able to do now to ready the PR for merging. Thanks!

Comment thread backend/chunker/chunker.go Resolved
Comment thread backend/chunker/chunker.go Resolved
Comment thread backend/chunker/chunker.go Resolved
Comment thread backend/chunker/chunker.go Resolved
Comment thread backend/chunker/chunker.go Resolved
@ivandeex

ivandeex commented Nov 16, 2020 •

Copy link
Copy Markdown
Member

@mcalman @leoluan1

rclone supports some 30+ storage backends:

  • [DUMBCOPY] some with slow server-side copy (because they are dumb and copy data when told to)
  • [REFCOPY] some with instant server-side copy (because they just bind same data to another path like Ceph in filesystem mode ie with file metadata, or due to hash-based deduplication under the hood like Mailru)
  • [FASTMOVE] some with instant server-side moves (well, almost, up to the network roundtrip for the api request)
  • [MOVEISCOPY] some with slow server-side moves (because they select disk based on full name hash, e.g. Ceph in S3 mode)
  • [APIMOVE] some with Move (slow or fast) directly in the API
  • [NOAPIMOVE] some without Move in API, so rclone will replace it with Copy (slow or fast) + Delete (slow or fast)
  • [FASTDELETE] most cloud providers: actually deleting a large blob takes long, especially when it's spread over replication groups, but most providers just mark it instantly as removed and postpone actual deletion to a background job
  • [DUMBDELETE] eg. Hubic because its ancient Swift storage doesn't postpone actual deletion for the nightly scrub
  • more exotic cases. since you work with bigdata you migh make up some.

Let's make sure we all (including you, me and @ncw) know what we are doing for backends labeled in this issue.

Please run a simple test: create a 10G local file, upload to your storage and compare rclone move vs rclone copy time for uploaded and copied file.

dd if=/dev/zero of=./test1 bs=1m count=10240
rclone copy ./test1 remote:
time rclone copy remote:test1 remote:test2
time rclone move remote:test1 remote:test3
time rclone move remote:test2 remote:test4

Please compare results for IBM COS vs S3 as remote and post here. Increase test file size to your taste if needed. For better accuracy you might repeat the test 3-5 times and take an average. It's gonna be very quick as you have access already.

Upd 1. In another comment we can discuss how to avoid affecting others.
Upd 2. Added backend [legends].

@ivandeex

ivandeex commented Nov 16, 2020 •

Copy link
Copy Markdown
Member

By the way, this PR does not do what the title says: avoid renames completely. Currently it only deals with put (uploads) but leaves move as is. With measurements requested above we can decide what to do about it.

Comment thread backend/chunker/chunker.go Resolved
Comment thread backend/chunker/chunker.go Resolved
@ivandeex

ivandeex commented Nov 16, 2020 •

Copy link
Copy Markdown
Member

Is it possible to allow this PR to be merged for 1.54?

@ncw has not yet attached a term to that milestone so it depends. Fairly possible as we have three pair of eyes reviewing this stuff now (with Nick to join later). We can publish a beta and use it before a release. I used to install betas from my own fork to start eating own dogfood before it hit the release. Your patch helps improve chunker performance on more storage systems. If an important patch misses 1.5x there always is 1.5x.1 to land. Missing a release is not good but introducing regressions or breaking peoples data is much worse.

@leoluan1

Copy link
Copy Markdown
Contributor

@ivandeex Good idea to get some performance numbers recorded here as a reference! #4675 (comment)
Here are some quick measurements that I got.
Using an Amazon S3 bucket, I got the following numbers.

Leos-MacBook-Pro:tmp leoluan$ dd if=/dev/zero of=./test1 bs=1m count=10240
10240+0 records in
10240+0 records out
10737418240 bytes transferred in 9.070568 secs (1183764693 bytes/sec)
bash-3.2# rclone copy ./test1 aws:/firebird-leo/

bash-3.2# time rclone copy aws:/firebird-leo/test1 aws:/firebird-leo/test2

real	3m55.478s
user	0m0.129s
sys	0m0.075s
bash-3.2# time rclone move aws:/firebird-leo/test1 aws:/firebird-leo/test3

real	3m15.304s
user	0m0.134s
sys	0m0.066s

bash-3.2# time rclone move aws:/firebird-leo/test2 aws:/firebird-leo/test4

real	1m56.005s
user	0m0.113s
sys	0m0.054s
bash-3.2# 

Using an IBM COS bucket, I got the following numbers.

root@tapsrv01:/tmp# dd if=/dev/zero of=./test1 bs=1M count=10240
10240+0 records in
10240+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 8.05723 s, 1.3 GB/s
root@tapsrv01:/tmp# rclone --no-check-certificate copy ./test1 tucson:leo/
root@tapsrv01:/tmp# time rclone --no-check-certificate copy tucson:leo/test1 tucson:leo/test2

real    1m31.070s
user    0m0.608s
sys     0m0.164s
root@tapsrv01:/tmp# time rclone --no-check-certificate move tucson:leo/test1 tucson:leo/test3

real    1m31.824s
user    0m0.597s
sys     0m0.132s
root@tapsrv01:/tmp# time rclone --no-check-certificate move tucson:leo/test2 tucson:leo/test4

real    1m32.685s
user    0m0.651s
sys     0m0.084s

The AWS S3 move operation had a large fluctuation between the first and second moves. But it's consistent that they all took significant amount of time to complete.

@ivandeex

ivandeex commented Nov 16, 2020 •

Copy link
Copy Markdown
Member

Looks like both S3 and IBM COS are [NOAPIMOVE] [MOVEISCOPY] [DUMBCOPY] [FASTDELETE]
(see legend in updated #4675 (comment)).
Time variations can be attributed to the provider ops scheduler selecting different disk groups for each other operation (but I'm not sure).

Conclusions:

  1. Move is as slow as Copy, on average.
  2. You are right, chunker should avoid move completely.
  3. Current implementation of Move in chunker is transaction-unsafe on such providers (see copyOrMove). Moving chunks is on average as slow as copy and by the time it "commits" (ie moves metadata) a concurrent operation can hit the composite in an inconsistent state with a good probability. The solution is to
    rewrite the sequence move chunks, move metaobject
    as get new xactID, copy chunks, commit metaobject, delete old chunks.
    For "normal" providers (slow copy, quasi-instant move) the former sequence can stay as is (quasi-safe, but ~100 chunks with ~70ms latency will give 7 inconsistent seconds, but reasonably fast on average) until someone comes up with a better idea (low level retries? parallelize chunk moves?).
  4. I'm not sure though if that change belongs with this PR or can be postponed to another one. Do you want to have a go? Or let @ncw decide.

Upd. [1 hour later] Cleaned up the text.

@mcalman

mcalman commented Dec 5, 2020

Copy link
Copy Markdown
Author

@ivandeex The latest commit should address most of the points you brought up. Mainly, I made changes to ensure that chunker is backwards compatible, to the extent possible, and made it so the new codepath is only used conditionally (to avoid the inefficiencies you pointed out with reading the metadata file for backends that won’t benefit from the changes).

From my testing, the new version of chunker can correctly identify and deal with files that were written using the original version of chunker. The only scenario I see any problems is when the original version of chunker is interacting with version 2 files (files that were written by the new version of chunker using the new style). In this scenario, the permanent chunks are ignored and the metadata file gets treated like a small, unchunked file.

Currently, I am just checking if the wrapped file system has a Move operation in order to decide whether or not to use the new codepath. I wanted to hear your input on what the most robust solution might be. I know you mentioned previously the idea of adding an fs.Feature flag for SlowServerSideMove. If we are worried about older versions of rclone incorrectly handling new chunked files, then another thought would be to create a new backend flag and only use the new codepath when it is set.

@ivandeex

ivandeex commented Dec 7, 2020 •

Copy link
Copy Markdown
Member

I made changes to ensure that chunker is backwards compatible, to the extent possible, and made it so the new codepath is only used conditionally

Great. We are getting there.

From my testing, the new version of chunker can correctly identify and deal with files that were written using the original version of chunker.

I can't find a unit test for that in your patch. I prefer extensive unit tests activated on every merge as they guarantee against regressions and make changes less fragile.

The only scenario I see any problems is when the original version of chunker is interacting with version 2 files

That's expected

In this scenario, the permanent chunks are ignored

Before this PR rclone always treated them as temporary or garbage chunks, that's fine.

and the metadata file gets treated like a small, unchunked file.

Hmm. I would expect that "List" will list it (as it doesn't read metadata details for performance sake) but any operation that needs NewObject, like cat, hash, copy, move or anything that modifies data must fail with "please upgrade rclone". I'd start to worry if it doesn't fail. Please correct me. If I'm wrong I will develop a bugfix and backport it to 1.53 and 1.52.

Currently, I am just checking if the wrapped file system has a Move operation in order to decide whether or not to use the new codepath.

I don't see a better way a.t.m.

I know you mentioned previously the idea of adding an fs.Feature flag for SlowServerSideMove.

@ncw has a big picture of backends. Before we merge we'll ask him about a better way to check it than Features.Move != nil

another thought would be to create a new backend flag and only use the new codepath when it is set

Much appreciated. A "level of indirection" will help here, I think. Let's add a parameter transactions (CLI option --chunker-transactions), or maybe name it commit_method or checkpointing. It will have three possible values: rename (old-style checkpoints), norename (avoid renames), auto (Apple-style "do me good" option). Such a multi-select string option f.opt.Transactions will allow for more flexibility in future.

However the internal code logic is currently binary: either use rename or avoid it, thus internally we'd better use something like f.PreferRenames bool flag (or UseRename etc). The auto value will set it to true/false depending on baseFs.Features().Move like this code. Non-auto values let advanced users opt out.

The new flag can also be used to write an internal test like what I suggest above: set flag to true, upload object, set to false, read object, and vice versa.

I'm not sure what would be the better default. auto is more bold, rename is more backwards compatible. I'd prefer rename for 1.54 and let beta-test volunteers set it to auto/norename to enjoy faster uploads. Then in 1.55 after we beta-test norename uploads and implement norename checkpoints for Move, we can safely change default to auto

What do you think?

@ivandeex
ivandeex self-requested a review February 15, 2021 05:47
@ivandeex ivandeex changed the title chunker: avoid rename for temporary chunks chunker: allow for no-rename checkpoints on backends with slow rename Feb 15, 2021
@ivandeex
ivandeex marked this pull request as draft February 17, 2021 01:02
@mcalman
mcalman force-pushed the chunker-avoid-renames branch from 259ca4b to 8708d3e Compare February 19, 2021 20:45
@mcalman
mcalman marked this pull request as ready for review February 19, 2021 21:47
Comment thread backend/chunker/chunker.go Resolved

@ivandeex ivandeex 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.

All inline comments addressed

@ivandeex

ivandeex commented Feb 20, 2021 •

Copy link
Copy Markdown
Member

All commits are squashed in preparation for next review.
The original chain of commits is saved at ivandeex/rclone@save-chunker-avoid-renames-20210221

@ivandeex

ivandeex commented Feb 20, 2021 •

Copy link
Copy Markdown
Member

@ncw
Please review this change.
I can confirm that integration suite passes for all tested flavors of chunker now.
Below are a few comments for your consideration.

1. Currently fs.Features does not have a flag like SlowServerSideMove.
This PR detects such backends using the Features.Move == nil guess (see chunker.CanQuickRename).
Can you propose a better method?

2. A note about directory listings:
After this PR the metadata for every composite object in a directory will be read during the listing operation (by the readXactID function, once per object). Additionlly, it will be re-read again by readMetadata when a concrete operation is requested (Open, Move, Hash, etc). Probably, this can be partially optimized during implementation of #3972 (comment).

UPD: Just noticed that UpdateNotify will also reread metadata for every change.

3. Summary of features yet unimplemented by this PR:

  • Avoid server-side moves in chunker.Move for the new "norename" transactions
  • Use transaction identifiers in chunker.Copy for the new "norename" transactions
  • Enable "rename"-style transactions to recognize norename-style chunks
  • Switch default transactions value to auto . This is postponed until the above bullets are finished and sufficient beta-testing of the new feature is done (i.e. while it's released but the default is set to rename)

If @ncw decides to merge this PR as is, these requirements should be captured in feature request(s).

4. Note about integration tests:
rclone.conf on the integration test box will need a new test remote after this PR:

[TestChunkerChunk3bNoRenameLocal]
type = chunker
remote = /tmp
chunk_size = 3b
transactions = norename

Some storage providers e.g. S3 don't have an efficient rename operation.
Before this change, when chunker finished an upload, the server-side copy
and delete operations that renamed temporary chunks to their final names
could take a significant amount of time.
This PR records transaction identifier (versioning) in the metadata of
chunker composite objects striving to remove the need for rename
operations on such backends.
This approach will be triggered be the new "transactions" configuration
option, which can be "rename" (the default) or "norename".
We implement the new approach for uploads (Put operations).
The chunker Move operation still uses the rename operation of
underlying backend. Filling this gap is left for a later PR.

Co-authored-by: Ivan Andreev <[email protected]>
@ivandeex
ivandeex force-pushed the chunker-avoid-renames branch from 6066f71 to bede6ee Compare February 23, 2021 23:47

@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.

Please review this change.

Sorry for the delay in the review.

I can confirm that integration suite passes for all tested flavors of chunker now.

:-)

1. Currently fs.Features does not have a flag like SlowServerSideMove.
This PR detects such backends using the Features.Move == nil guess (see chunker.CanQuickRename).
Can you propose a better method?

Normally we'd use operations.CanServerSideMove() but if you are trying to specifically avoid that Copy+Delete then Features.Move == nil is pretty close.

2. A note about directory listings:
After this PR the metadata for every composite object in a directory will be read during the listing operation (by the readXactID function, once per object). Additionlly, it will be re-read again by readMetadata when a concrete operation is requested (Open, Move, Hash, etc). Probably, this can be partially optimized during implementation of #3972 (comment).

Composite objects are usually large so there hopefully won't be too many of them in a directory so this seems like an acceptable tradeoff.

UPD: Just noticed that UpdateNotify will also reread metadata for every change.

3. Summary of features yet unimplemented by this PR:

  • Avoid server-side moves in chunker.Move for the new "norename" transactions
  • Use transaction identifiers in chunker.Copy for the new "norename" transactions
  • Enable "rename"-style transactions to recognize norename-style chunks
  • Switch default transactions value to auto . This is postponed until the above bullets are finished and sufficient beta-testing of the new feature is done (i.e. while it's released but the default is set to rename)

If @ncw decides to merge this PR as is, these requirements should be captured in feature request(s).

OK

4. Note about integration tests:
rclone.conf on the integration test box will need a new test remote after this PR:

[TestChunkerChunk3bNoRenameLocal]
type = chunker
remote = /tmp
chunk_size = 3b
transactions = norename

I've put that in in preparation.

What is the backwards compatibility story with this commit?

I've had a look through the code and I'm happy for you to merge this if you are :-)

Thank you

@ivandeex

ivandeex commented Feb 27, 2021 •

Copy link
Copy Markdown
Member

@ncw
Thank you for review.
Before it I was in doubt whether this can be merged as is.

What is the backwards compatibility story with this commit?

After this patch chunker in "rename mode" will not be able to detect "metadata in norename mode" as a chunker object. That's partially why I requested to enable new mode manually only. Nor do I have time now to fix open items left after author.

Generally the more chunker features we merge -> the more format flavors we have -> the more combinations we test.
I have an idea to merge chunker changes on a dedicated branch and flush on master with metaformat versions "squashed" to tangle the complexity.
See #4547 (comment)

@mcalman
I was in doubt whether this can be merged as is.

I will merge it as soon as you submit tickets for open items.

@ivandeex ivandeex assigned ivandeex and unassigned ncw Feb 27, 2021
@ivandeex
ivandeex merged commit 9cc8ff4 into rclone:master Feb 28, 2021
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
Some storage providers e.g. S3 don't have an efficient rename operation.
Before this change, when chunker finished an upload, the server-side copy
and delete operations that renamed temporary chunks to their final names
could take a significant amount of time.
This PR records transaction identifier (versioning) in the metadata of
chunker composite objects striving to remove the need for rename
operations on such backends.
This approach will be triggered be the new "transactions" configuration
option, which can be "rename" (the default) or "norename".
We implement the new approach for uploads (Put operations).
The chunker Move operation still uses the rename operation of
underlying backend. Filling this gap is left for a later PR.

Co-authored-by: Ivan Andreev <[email protected]>
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.

4 participants