-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
remote: skip non-cache looking files when estimating remote size #3557
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -687,7 +687,7 @@ def path_to_checksum(self, path): | |
parts = self.path_cls(path).parts[-2:] | ||
|
||
if not (len(parts) == 2 and parts[0] and len(parts[0]) == 2): | ||
raise ValueError("Bad cache file path") | ||
raise ValueError("Bad cache file path '{}'".format(path)) | ||
|
||
return "".join(parts) | ||
|
||
|
@@ -697,17 +697,18 @@ def checksum_to_path_info(self, checksum): | |
def list_cache_paths(self, prefix=None, progress_callback=None): | ||
raise NotImplementedError | ||
|
||
def all(self): | ||
def all(self, *args, **kwargs): | ||
# NOTE: The list might be way too big(e.g. 100M entries, md5 for each | ||
# is 32 bytes, so ~3200Mb list) and we don't really need all of it at | ||
# the same time, so it makes sense to use a generator to gradually | ||
# iterate over it, without keeping all of it in memory. | ||
for path in self.list_cache_paths(): | ||
for path in self.list_cache_paths(*args, **kwargs): | ||
try: | ||
yield self.path_to_checksum(path) | ||
except ValueError: | ||
# We ignore all the non-cache looking files | ||
pass | ||
logger.debug( | ||
"'%s' doesn't look like a cache file, skipping", path | ||
) | ||
|
||
def gc(self, named_cache): | ||
used = self.extract_used_local_checksums(named_cache) | ||
|
@@ -891,16 +892,14 @@ def cache_exists(self, checksums, jobs=None, name=None): | |
checksums, remote_checksums, remote_size, jobs, name | ||
) | ||
|
||
def _cache_paths_with_max( | ||
self, max_paths, prefix=None, progress_callback=None | ||
): | ||
def _all_with_limit(self, max_paths, prefix=None, progress_callback=None): | ||
count = 0 | ||
for path in self.list_cache_paths(prefix, progress_callback): | ||
yield path | ||
for checksum in self.all(prefix, progress_callback): | ||
yield checksum | ||
count += 1 | ||
if count > max_paths: | ||
logger.debug( | ||
"list_cache_paths() returned max '{}' paths, " | ||
"`all()` returned max '{}' checksums, " | ||
"skipping remaining results".format(max_paths) | ||
) | ||
return | ||
|
@@ -936,13 +935,13 @@ def update(n=1): | |
pbar.update(n * total_prefixes) | ||
|
||
if max_remote_size: | ||
paths = self._cache_paths_with_max( | ||
checksums = self._all_with_limit( | ||
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. Hm, maybe simply |
||
max_remote_size / total_prefixes, prefix, update | ||
) | ||
else: | ||
paths = self.list_cache_paths(prefix, update) | ||
checksums = self.all(prefix, update) | ||
|
||
remote_checksums = set(map(self.path_to_checksum, paths)) | ||
remote_checksums = set(checksums) | ||
if remote_checksums: | ||
remote_size = total_prefixes * len(remote_checksums) | ||
else: | ||
|
@@ -974,10 +973,7 @@ def _cache_exists_traverse( | |
) as pbar: | ||
|
||
def list_with_update(prefix): | ||
paths = self.list_cache_paths( | ||
prefix=prefix, progress_callback=pbar.update | ||
) | ||
return map(self.path_to_checksum, list(paths)) | ||
return self.all(prefix=prefix, progress_callback=pbar.update) | ||
|
||
with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor: | ||
in_remote = executor.map(list_with_update, traverse_prefixes,) | ||
|
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.
This is pretty much a
walk_files
method, but it is not supported in every remote yet, so we are using a legacy implementation for now.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.
Using
walk_files
would've been much more intuitive, esp sincewalk
presumes that it is an iterator, unlikelist_cache_paths
which could be anything.