-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[WIP] remote: locally index list of checksums available on cloud remotes #3600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
073d4de
remote: locally index list of checksums available on cloud remotes
pmrowla c8be39a
fix review issues
pmrowla 6a8c57e
Use .dir checksums to (in)validate local remote index
pmrowla 7c0c271
Add --drop-index CLI option for push/pull/status
pmrowla ca5e554
fix tests
pmrowla f85020b
fix py3.5 issues
pmrowla 50c9743
push: only upload .dir file after full file contents has been uploaded
pmrowla 20e8510
gc: always remove .dir checksums first
pmrowla a08f6b7
fix review issues
pmrowla 8e4eed5
only save index once per command
pmrowla 38a80e3
write checksums to a flat file instead of using pickle
pmrowla a16fb14
no need to try to compress md5 hashes
pmrowla a6f5877
add helper functions update_all/replace_all
pmrowla 199cdba
review docstring fixes
pmrowla 56e511c
treat gc -c as full re-indexing
pmrowla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,67 +48,110 @@ def get_remote(self, remote=None, command="<command>"): | |
| def _init_remote(self, remote): | ||
| return Remote(self.repo, name=remote) | ||
|
|
||
| def push(self, cache, jobs=None, remote=None, show_checksums=False): | ||
| def push( | ||
| self, | ||
| caches, | ||
| jobs=None, | ||
| remote=None, | ||
| show_checksums=False, | ||
| drop_index=False, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
| ): | ||
| """Push data items in a cloud-agnostic way. | ||
|
|
||
| Args: | ||
| cache (NamedCache): named checksums to push to the cloud. | ||
| caches (list): list of (dir_cache, file_cache) tuples containing | ||
| named checksums to push to the cloud. | ||
| jobs (int): number of jobs that can be running simultaneously. | ||
| remote (dvc.remote.base.RemoteBASE): optional remote to push to. | ||
| By default remote from core.remote config option is used. | ||
| show_checksums (bool): show checksums instead of file names in | ||
| information messages. | ||
| drop_index (bool): clear local index for the remote | ||
| """ | ||
| return self.repo.cache.local.push( | ||
| cache, | ||
| caches, | ||
| jobs=jobs, | ||
| remote=self.get_remote(remote, "push"), | ||
| show_checksums=show_checksums, | ||
| drop_index=drop_index, | ||
| ) | ||
|
|
||
| def pull(self, cache, jobs=None, remote=None, show_checksums=False): | ||
| def pull( | ||
| self, | ||
| caches, | ||
| jobs=None, | ||
| remote=None, | ||
| show_checksums=False, | ||
| drop_index=False, | ||
| ): | ||
| """Pull data items in a cloud-agnostic way. | ||
|
|
||
| Args: | ||
| cache (NamedCache): named checksums to pull from the cloud. | ||
| caches (list): list of (dir_cache, file_cache) tuples containing | ||
| named checksums to pull from the cloud. | ||
| jobs (int): number of jobs that can be running simultaneously. | ||
| remote (dvc.remote.base.RemoteBASE): optional remote to pull from. | ||
| By default remote from core.remote config option is used. | ||
| show_checksums (bool): show checksums instead of file names in | ||
| information messages. | ||
| drop_index (bool): clear local index for the remote | ||
| """ | ||
| remote = self.get_remote(remote, "pull") | ||
| downloaded_items_num = self.repo.cache.local.pull( | ||
| cache, jobs=jobs, remote=remote, show_checksums=show_checksums | ||
| caches, | ||
| jobs=jobs, | ||
| remote=remote, | ||
| show_checksums=show_checksums, | ||
| drop_index=drop_index, | ||
| ) | ||
|
|
||
| if not remote.verify: | ||
| self._save_pulled_checksums(cache) | ||
| self._save_pulled_checksums(caches) | ||
|
|
||
| return downloaded_items_num | ||
|
|
||
| def _save_pulled_checksums(self, cache): | ||
| for checksum in cache["local"].keys(): | ||
| cache_file = self.repo.cache.local.checksum_to_path_info(checksum) | ||
| if self.repo.cache.local.exists(cache_file): | ||
| # We can safely save here, as existing corrupted files will be | ||
| # removed upon status, while files corrupted during download | ||
| # will not be moved from tmp_file (see `RemoteBASE.download()`) | ||
| self.repo.state.save(cache_file, checksum) | ||
|
|
||
| def status(self, cache, jobs=None, remote=None, show_checksums=False): | ||
| for dir_cache, file_cache in cache: | ||
| checksums = set(file_cache["local"].keys()) | ||
| if dir_cache is not None: | ||
| checksums.update(dir_cache["local"].keys()) | ||
| for checksum in checksums: | ||
| cache_file = self.repo.cache.local.checksum_to_path_info( | ||
| checksum | ||
| ) | ||
| if self.repo.cache.local.exists(cache_file): | ||
| # We can safely save here, as existing corrupted files will | ||
| # be removed upon status, while files corrupted during | ||
| # download will not be moved from tmp_file | ||
| # (see `RemoteBASE.download()`) | ||
| self.repo.state.save(cache_file, checksum) | ||
|
Comment on lines
+123
to
+127
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment getting long π |
||
|
|
||
| def status( | ||
| self, | ||
| caches, | ||
| jobs=None, | ||
| remote=None, | ||
| show_checksums=False, | ||
| drop_index=False, | ||
| ): | ||
| """Check status of data items in a cloud-agnostic way. | ||
|
|
||
| Args: | ||
| cache (NamedCache): named checksums to check status for. | ||
| caches (list): list of (dir_cache, file_cache) tuples containg | ||
| named checksums to check status for. | ||
| jobs (int): number of jobs that can be running simultaneously. | ||
| remote (dvc.remote.base.RemoteBASE): optional remote to compare | ||
| cache to. By default remote from core.remote config option | ||
| is used. | ||
| show_checksums (bool): show checksums instead of file names in | ||
| information messages. | ||
| drop_index (bool): clear local index for the remote | ||
| """ | ||
| remote = self.get_remote(remote, "status") | ||
| return self.repo.cache.local.status( | ||
| cache, jobs=jobs, remote=remote, show_checksums=show_checksums | ||
| caches, | ||
| jobs=jobs, | ||
| remote=remote, | ||
| show_checksums=show_checksums, | ||
| drop_index=drop_index, | ||
| ) | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about "specified remote" since sync commands don't always receive a -r arg. Maybe just remove the word "specified".
Also, "drop index" may not mean anything to a casual user, should this be a little more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in the other 2 sync commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
--clear-indexor--reset-index?