Repository navigation
Description
I think a nice feature would be the ability to generate a cache of checksums for local files, which could be used to accelerate subsequent calls to rclone. This would make the following sequence of operations much faster, by avoiding redundant checksum computations on the local side:
rclone check --checksum cloud:/path /local/path
[user thinks about why the files might be different, and decides what to do]
rclone copy some files
[repeat as necessary]
rclone check --checksum cloud:/path /local/path
[see where we stand now]
I'm thinking that this might be accomplished with a single command-line argument..something like --local-file-checksum-cache=path/to/database/file. If the file is missing, it's created, and in either case is written out when rclone terminates. The checksum DB would cache the file's size and mod-time along with the checksum, and when the checksum is needed for a local file, the cached one is used if the size and mod-time match.
Note that the cache file would potentially need to cache both MD5 and SHA1 checksums, and there should also be a way to disable reading the cache (e.g., if I believe my filesystem may have been damaged, and want to re-download pristine versions of any corrupted files, then I don't want to trust the local checksum cache).
See also related issues #725, #626 and #157.
How to use GitHub
- Please use the 👍 reaction to show that you are affected by the same issue.
- Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
- Subscribe to receive notifications on status change and new comments.
Activity
monroe-74 commentedon Dec 13, 2016
This is a great idea, thank you for bringing this up.
I would think that it would be sufficient for the user to refrain from using the command you suggested ("local-file-checksum-cache"). If the user refrains from using that command, then rclone will behave as it does currently. That is, it will recalculate all checksums, which is the same thing as "disable reading the cache," right?
In any situation where the user feels this way, then aside from not using the command, they are also free to trash the checksum file. Then use the command again, and the local checksum cache will be recreated.
Your basic design for how this works makes perfect sense, and it's probably all that's needed. Unless there's something I misunderstand about this part of your comment.
jediry commentedon Dec 13, 2016
Yes, you're correct...so long as the cache file is opt-in, no extra option is needed to disable it. I only mention this scenario in case the person who implements this chooses to instead make this an on-by-default, opt-out thing. The point is, there are cases where one doesn't want the cache.
monroe-74 commentedon Dec 13, 2016
OK, thanks for explaining, I see what you mean. But even in that case, any user who is worried about a corrupted cache file is always free to trash it, and that would always force rclone to recreate it, right? Then again, if for some reason a user worries that the local file is always subject to corruption for some reason, then remembering to delete it every time would be a major nuisance.
Anyway, I like your original suggestion of making this feature happen only when explicitly invoked. In my opinion, it should not be on-by-default. People upgrading to a new rclone version should not suddenly see a new cache file they might not expect or need.
jediry commentedon Dec 13, 2016
I agree that my original opt-in design seems best, as it avoids surprising users.
ncw commentedon Dec 14, 2016
I'd propose implementing it like this.
Use a simple Key/Value database - bolt looks like the leading contender here. Using an actual DB rather than a text file will mean we don't have to load the entire database into memory and we can update it as we go along.
Use the absolute value of the paths as a key - this will mean that you can use the cache for any local file accesses, not just ones from a specific directory.
As the values we need to store
I'd serialize these into JSON probably.
We'd use this DB
Potential issues
monroe-74 commentedon Dec 14, 2016
Hi Nick, thank you for the work you are putting into this.
A suggestion: at least for now, just let the user worry about this. As a user, I'm well-aware of the existence of this file, because you won't create it unless I explicitly ask you to do so. It's easy enough for the user to pay attention to where it is, and how big/old/stale it's getting. Periodically, I should trash that file and let a new one be built, but the optimum schedule for that is very dependent on the specifics of my situation. For example, I might know my data well enough to be sure that it's rare for files to be moved or deleted.
Later on, if eventually there are many people using this feature, then you will be in a position to notice the presence (or absence) of many people reporting problems that are a result of garbage accumulating in the file. Then enhancements can be made, and the nature of the problems that are reported (if any) will be a helpful framework for designing those enhancements. Like you said, it might not be a big problem, ever, so no point worrying about it right now.
For now, how about you just put a statement like this in the documentation for this new command: "If you have many files that are moved or deleted, this checksum file will eventually contain obsolete information, so it could be a good idea to periodically throw this file away. Then you can let rclone build a new one which will contain only current information."
rclone currently allows me to create multiple log files with unique names. Then I can run multiple jobs concurrently, and each log file will reflect only the specific job which owns that file. Could checksum files work the same way? Then as a user it's up to me to decide how many of these files should exist, and what they should be called, and where they should live.
The documentation could say something like this: "You can run multiple rclone instances concurrently, but if you are using checksum files, then each instance must have its own."
When a job starts, if I ask you to use a checksum file, you check and see if the file I specified is currently in use. If it's in use, you stop the job with an error. A helpful message would be something like this: "The checksum file you specified is currently in use."
My understanding is that "Bolt currently works on Windows, Mac OS X, and Linux." (https://godoc.org/github.com/boltdb/bolt) That should cover most rclone users, right? If you are on some other platform, then maybe you just have to live without this feature, at least for now?
jediry commentedon Dec 14, 2016
Yes, thanks for taking this on. Excited to see the improvement!
I agree that the user-visibility of this file makes it less of a problem. Still, I could imagine a user with many terabytes of data being unhappy with the "just delete your cache" solution.
If it does become a problem, two possible solutions:
So long as rclone detects this situation and aborts (rather than continuing and corrupting the DB), I think this is fine. I agree with Monroe-74 that this won't be a huge problem in practice...if I'm routinely processing different directories in parallel, I'll have separate cache DBs for those tasks. The only users likely to be significantly hampered by this are people trying to sync the same local directory into multiple cloud locations...and they can work around this by doing an "rclone check" to bring the DB (mostly) up-to-date, and then making copies of the DB for each "rclone sync" instance they plan to spawn.
Is it fairly cheap to simultaneously compute the SHA1 and MD5 (vs. computing just one)? If it's a significant extra expense to compute both, you might consider making them "optional", and only compute them on-demand. In my case, I'm using OneDrive exclusively, so computing the MD5 sum doesn't matter. I imagine other people's usage is similar. But if it's cheap to do both simultaneously, then probably best to do that, to avoid reading the same file twice to generate two different checksums.
Depending on what you mean by "absolute value", I probably agree. Specifically, in addition to being a non-relative path, I think the path needs to be canonicalized to remove this-directory (./) and parent-directory (../) sequences, superfluous '/' sequences (e.g., /mnt///path -> /mnt/path), and also should resolve symbolic links.
monroe-74 commentedon Dec 14, 2016
Hi jediry, I just want to chime in and say that everything you said makes a lot of sense to me. One minor comment:
If I were doing backups to multiple cloud locations, I think I would probably do them on some kind of rolling or alternating schedule, instead of making them simultaneous. I assume a rolling schedule would be a common practice, because then I have more options if I want to rollback to a previous state of my data? So I'm inclined to guess that the exact case you described would be rare. Anyway, you suggested a good way for the user to handle that situation.
jediry commentedon Dec 14, 2016
Yeah, I would do that too. The difficulty is that it's hard to know when a backup task will finish, so unless you're certain that the duration of one backup will always be "short" compared to the gap between launching them, then you have to account for the possibility that the previous backup could still be running when the next scheduled "start" rolls around. Of course, it's possible to code around this, but it's more complicated.
monroe-74 commentedon Dec 14, 2016
Good point, I see what you mean. I was assuming no overlap, but you're right that this is not a safe assumption.
The new feature we're discussing might radically improve the speed of certain backups, so that might minimize the overlap issue you described. But it will still happen in some situations, so it's good that this problem is getting some thought ahead of time, and I like your suggestions.
ncw commentedon Dec 16, 2016
@jediry @monroe-74 thanks for thinking about this.
I think the garbage collection would be solved for the time being with some extra docs. If necessary rclone could grow an extra command to help deal with it. The compact on shutdown is a reasonable idea, but even scanning a huge directory tree can take some time. We'll have to see how big the DBs become, but pessimistically 1k per file. So for 1M files the DB becomes 1GB. So if there are 100k stale files that is not going to be much of a problem.
As for concurrent access, rclone could wait until the db was available rather than stop with an error. It could print a message every 60s while it was waiting. This would mean that backups would proceed in an orderly fashion. boltdb takes a lot of care to not allow concurrent access so you wont get corruption.
I could solve the concurrent access to the db problem like this if necessary
Using multiple DB's is a good idea. You could fill it up from one run then copy it and use it in another.
The main cost is IO so it is pretty much free computing the SHA1 if you are already computing the MD5. That is what rclone does at the moment anyway.
Absolutely (pun intended ;-)
ncw commentedon Dec 16, 2016
rclone ignores symbolic links at the moment - that needs a little bit of extra thought...
monroe-74 commentedon Dec 16, 2016
Sounds good to me.
Good point. I suggested you just stop, but waiting instead would be much friendlier. In my situation it wouldn't matter, but I could picture another user being annoyed if you stop instead of waiting.
Deferring writes this way is a clever solution. However, speaking for myself, this is not needed, and I imagine this could be a noticeable chunk of extra work for you. So I suppose this could be a later enhancement, if many users adopt the new feature and express a need for this enhancement.
Speaking again strictly for myself, you ignoring symbolic links does not cause any trouble for me.
52 remaining items
borkd commentedon May 26, 2021
What are the chances for being able to feed/populate the hash cache out of band, instead of having rclone recalculate it periodically?
Also, while this could require backend-specific code, storing and persisting hashes in a Merkle tree could drastically cut down on remote api calls when syncing larger directory trees.
ivandeex commentedon May 28, 2021
Answered above.
None of currently supported hashes (md5, sha1, quickxor, etc) support merkle tree. As soon as we have such, e.g. blake3, we'll use merkle tree to build hash from partial range reads.
tb582 commentedon Jun 24, 2021
ivandeex commentedon Jun 24, 2021
How to use GitHub
ivandeex commentedon Sep 9, 2021
Experimental
hasherbeta is published as latestivarelease at https://github.com/ivandeex/rclone/releases, preliminary documentation is at #5587