Skip to content

vfs: check if equal before uploading to remote - #5576

Closed
wloot wants to merge 1 commit into
rclone:masterfrom
wloot:patch-1
Closed

wloot wants to merge 1 commit into
rclone:masterfrom
wloot:patch-1

Conversation

@wloot

@wloot wloot commented Sep 6, 2021

Copy link
Copy Markdown

What is the purpose of this change?

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 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 patch looks like a sensible idea - thank you :-)

I'm slightly concerned about changing the behaviour when using backends which don't support modtimes or checksums.

I'd like a bit more background if possible.

How did you notice that this was a problem?

Can you give me a recipe for making a duplicate upload? So I can try it here.

If so then we could make a test for it too.

Thank you

@wloot

wloot commented Sep 6, 2021 •

Copy link
Copy Markdown
Author

I'm slightly concerned about changing the behaviour when using backends which don't support modtimes or checksums.

The Equal() is already being used elsewhere(iirc such as rclone copy), so it shouldn't be a problem.

I'd like a bit more background if possible.

How did you notice that this was a problem?

I use rclone mount with a google drive backend. When I write the same content to a file as itself, a new revision of the file will be generated on drive.google.com if without the patch.

# mount fs
rclone mount gd:/ /gd
# create a new file
echo "content" > /gd/test
# without the patch, a new revision of /gd/test generated
# with the patch, only modtime is updated
echo "content" > /gd/test

@ncw

ncw commented Sep 6, 2021

Copy link
Copy Markdown
Member

I'm slightly concerned about changing the behaviour when using backends which don't support modtimes or checksums.

The Equal() is already being used elsewhere(iirc such as rclone copy), so it shouldn't be a problem.

Can you try this test with your patch?

Run

mkdir /tmp/ftp-files
rclone serve ftp /tmp/ftp-files --user test --pass test

and

rclone mount --vfs-cache-mode full -vv  ":ftp,host=localhost,port=2121,user=test,pass=6V5Bl1rGjBXdBzAbnHP2FBMOH08:" /mnt/data/

And then try overwriting a file on the FTP server with a file that is the same size

$ echo one > /mnt/data/file.txt
$ sleep 6
$ cat /tmp/ftp-files/file.txt 
one
$ echo two > /mnt/data/file.txt
$ sleep 6
$ cat /tmp/ftp-files/file.txt 
two
$ 

If you do this with your patch the file won't get uploaded. This is because FTP remotes don't support modification times.

I use rclone mount with a google drive backend. When I write the same content to a file as itself, a new revision of the file will be generated on drive.google.com if without the patch.

# mount fs
rclone mount gd:/ /gd
# create a new file
echo "content" > /gd/test
# without the patch, a new revision of /gd/test generated
# with the patch, only modtime is updated
echo "content" > /gd/test

I see.

So what is happening is that Equal is saying that the modtimes are different, then doing remote and local checksums and seeing they are identical and not uploading.

Perhaps what we should be doing is calling

func CheckHashes(ctx context.Context, src fs.ObjectInfo, dst fs.Object) (equal bool, ht hash.Type, err error) {

And if equal && ht != hash.None then skip the transfer and set the ModTime of the destination instead.

This is slightly annoying duplication of the logic in Equal - however Equal is designed for syncing which is less demanding than mounting in a lot of ways.

Whatever logic we decide on it needs a test :-)

Another thought crosses my mind - how common is it to alter a file and leave it the same? This patch makes us checksum every file we are about to update which potentially slows everything down.

@wloot

wloot commented Sep 6, 2021 •

Copy link
Copy Markdown
Author

Perhaps what we should be doing is calling

func CheckHashes(ctx context.Context, src fs.ObjectInfo, dst fs.Object) (equal bool, ht hash.Type, err error) {

And if equal && ht != hash.None then skip the transfer and set the ModTime of the destination instead.

if ht == hash.None && !ci.RefreshTimes {
// if couldn't check hash, return that they differ
return false
}

It seems the case that remote does not support checksum is catched in equal().

This is slightly annoying duplication of the logic in Equal - however Equal is designed for syncing which is less demanding than mounting in a lot of ways.

Whatever logic we decide on it needs a test :-)

Another thought crosses my mind - how common is it to alter a file and leave it the same? This patch makes us checksum every file we are about to update which potentially slows everything down.

Perhaps check modtime & size is enough and only do hash check when --checksum is set. And users who do not like this can set --ignore-times so that we skip all check.

edit: I was just realized that modtime is always different as a vfs sync only happens when files change, so what do you think about this wloot@0476432

@wloot

wloot commented Sep 6, 2021

Copy link
Copy Markdown
Author

Another thought crosses my mind - how common is it to alter a file and leave it the same? This patch makes us checksum every file we are about to update which potentially slows everything down.

This is actually common in my use case, emby writes same content to metadata file within almost every check cycle, in the meantime there are thousands of metadata files.

@ivandeex

ivandeex commented Nov 17, 2021 •

Copy link
Copy Markdown
Member

This patch fixes a corner case and has potential to break stuff for a lot of existing cases/
I think we'd better reject this proposal for safety sake and postpone solution to

cc @ncw

@ivandeex

ivandeex commented Nov 18, 2021 •

Copy link
Copy Markdown
Member

If this ever gets accepted,
this must use a dedicated vfs flag like --vfs-no-upload-if-same-data
and have a clear explanation of a warranting user case in the vfs docs

@ivandeex

Copy link
Copy Markdown
Member

Captured the requested behavior as a new user case in #4810 (comment)

@ivandeex

ivandeex commented Nov 19, 2021 •

Copy link
Copy Markdown
Member

In its current form, this PR cannot be accepted.
I wrote the requirements above.

P.S. Generally, the change detection logic in rclone has come to the verge of unsupportable - every new optimization brings more and more risk to break something. It requires deeper overall discussion rather than the stream of small per-user-case optimizations.

@wloot wloot closed this Nov 19, 2021
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.

3 participants