Improvement move pkg cache fs calls to repo plugin - #1993
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1993 +/- ##
==========================================
+ Coverage 59.98% 60.00% +0.02%
==========================================
Files 163 163
Lines 20118 20121 +3
Branches 3519 3519
==========================================
+ Hits 12067 12074 +7
+ Misses 7230 7226 -4
Partials 821 821 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: george.ridal <george.ridal@findesign.com.au>
a8ff4bc to
974a77f
Compare
|
@JeanChristopheMorinPerso I would like to see this adopted in the rez, as I think for such a small change it does empower anyone to take ownership of the cache copy method without the need of too much refactor of rez's core code. |
|
This simple change would unlock Rez adoption for a use case I'm looking at as well. Is there an opportunity to move this forward? I'm happy to pick it up if that would help - rebasing and adding unit tests. It looks like a great enabler for remote payload backends like S3 or other object stores. Super minimal, simple to use, follows existing patterns of providing overridable methods for plugin extensions. |
maxnbk
left a comment
There was a problem hiding this comment.
It would be a good idea.
I've done some initial review today (sorry, I'm definitely trying to get some reviews on some PRs that have been waiting for them for a long time, but the backlog is deep).
My review findings are:
- Overall, it's a good forward step towards better package-caching utility and pluginification. There are some minor issues I would like to see addressed however, either as a matter of safety/consistency, or as a matter of being explicit about the architecture moving forward.
cache_variantis not abstract. There would be a silent no-op for any non-filesystem repo. The base class profiles a default implementation (thecopytree), which works for filesystem repos wherevariant.rootis a local path, but since we want to push forward remote/artifact repos (which this PR is helping to move the goalpost on),variant.rootmay not be a local filesystem path, or may not exist at all. A remote repo that doesn't overridecache_variantwould silently getcopytreecalled on a non-existent path, producing a confusingFileNotFoundErrorinstead of a clear "not supported" message. I would therefore recommend that we makecache_variantraiseNotImplementedErrorby default (similar to howget_package_payload_pathdoes), forcing each repo plugin to explicitly opt-in. If not this, then document that it assumes a local filesystem path, and have the filesystem repo override it explicitly (moving the implementation, not duplicating it).- The original
variant_rootwas gotten withgetattrwhich returnsNoneif the attribute doesn't exist.variant.rootis an@cached_propertyonVariantResourcethat callsself._root(). If_root()returnsNone,variant.rootwould raiseAttributeErroror returnNone. Basically, the failure mode is different thangetattrwith a default. In practice this probably doesn't matter becauseadd_variantalready validatesvariant_rootbefore reaching the copy, but thecache_variantmethod on the base class doesn't have that protection. It's a public method that could be called independently. My suggestion is thatcache_variantis at the wrong abstraction level. The method is onPackageRepository(the repo), but it receives both thevariantand thelocation(cache destination). The repo knows how to read from itself, but the cache knows where to write. The current signature conflates the source and destination concerns. Cleaner split might bePackageRepository.get_variant_payload(variant) -> Iterator[bytes]or-> path, where the repo provides the payload,PackageCachehandles writing to the cache location. Alternatively, if the goal is for the repo to control the full copy,cache_variant(self, variant, cache_rootpath)which is the current approach, but document that the repo owns the full source->dest transfer. It's not that this approach is bad, it's just pragmatic, but worth documenting clearly. - Not a bug in this PR, but a constraint that
cache_variantimplementations need to be aware of: The originalcopytreeuses defaults, so,symlinks=False,_copy_function=copy2. This is fine for filesystem repos, but the cachesget_variant_sizeexplicitly follows symlinks to compute size. If a custom repo overridescache_variantand usessymlinks=True, the cached size would mismatch the actual cached payload. Additionally, the.copying-*sentinel mechanism and the_while_copyingthread assume the copy takes a non-trivial amount of time. A remote repo that does a streaming download might finish instantly or take much longer, but the timeout/stall detection is calibrated for filesystem copy speeds. (Technically this is a problem today, but I am trying to be proactive with how we make these adjustments...)
Some concrete suggestions/nitpicks:
- A docstring on the new method would be nice.
- If
cache_variantwas overridden by all plugins thenimport shutilis dead import code for those plugins. Not a real problem but the import could be moved to the method level or the default should delegate to a utility function. - The tests still pass because effectively the same code is being exercised. However, tests could verify a custom repo plugin can override
cache_variant, verify that the base class default works without an override, and verify error handling whencache_variantfails.
I would only really consider the "default implementation safety" items as important to address, the docstring as an easy add, and the rest are good followups.
|
Hi @maxnbk |
- The api on the repo is now more generic to a copy action rather then a cache action My thinking is that it could be used else where in future, ie rez-cp, a repo nows how to write it payload to a filesystem. - PkgCache now calls variant.resource._cache() as a private method on the resource, this in turn passes itself and the path to copy_variant_payload on its own repo - This has the option of allowing a plugin to override both _cache on the resource and copy_variant_payload on repo Signed-off-by: george.ridal <george.ridal@findesign.com.au>
Signed-off-by: george.ridal <george.ridal@findesign.com.au>
This PR is an attempt to decouple the package cache operation to the repository plugins
This can allow users to customize how the package cache touches the filesystem on a per repository bases either via the cache_variant() call, or on the variant resource
Does this help with the artifact repo direction, could some remote repos use the current cache system via moving these functions to the repository plugin?
I personally would like a way to customize pkg cache operation via a custom filesystem plugin to optimize cache speeds