Repository navigation
feat: add Directory.asGit - #9730
Conversation
9f18b64 to
4a5a8ad
Compare
3f6d2c6 to
bf6559d
Compare
sipsma
left a comment
There was a problem hiding this comment.
super cool! only significant comment is around the ref releasing
|
|
||
| LLB *pb.Definition | ||
| LLB *pb.Definition | ||
| Result bkcache.ImmutableRef // only valid when returned by dagop |
There was a problem hiding this comment.
I might have not gotten to this part of the code yet but do we ever release these (this one and the one in File)? If not then the object will get cached until the session is closed and then the ref will leak
There was a problem hiding this comment.
🤔 From my understanding, we only need to Release non-returned Refs (e.g. the cloned git repository in the git source implementation), but any returned Refs (e.g. the checked out git repo in the same) aren't. Which makes sense, once it's returned, buildkit is then responsible for cleaning up the ref, if you return a released ref, you're sure to get odd results.
The only scenario we'd need to release this is in the case of an error - but I don't think there's a possibility for an error between returning this, and immediately loading it into FSDagOp.Exec where it's returned. So I don't think Releaseing is necessary here? We already handle all the error cases in the function bodies where we create and set Result.
There was a problem hiding this comment.
buildkit is then responsible for cleaning up the ref
Is it? There's obviously way too many layers of abstraction we have to deal with here so I may be forgetting something but I can't think of where buildkit would release e.g. the Result we set in Container.asTarball.
Actually, if that is true and buildkit is free to release the result even though we have an open ref to it, that would mean it could prune it and then we could be trying to use a ref that doesn't exist anymore.
if you return a released ref, you're sure to get odd results.
Right, what I'm saying is that when an object with a Result is removed from dagql cache, we should release the Result at that time. So the ref stays open until we don't have it in memory anymore. It's essentially manual memory management, but in Go 🎉😭
Again apologies if I'm totally missing something here, the dots just aren't connecting yet
There was a problem hiding this comment.
Oh, I think I get where the confusion is potentially. The Result shouldn't propagate through the entire dagql graph - or through the cache at all. It should be impure so it never enters the dagql cache (but since that's removed, not sure how I do that now).
The Result is only read from the Load in the DagOp - but then the rest of the graph sees a "normal" Directory, with an LLB op that is that DagOp.
So actually I think this is a bit wrong now:
Lines 101 to 109 in 3aae0ee
I think we want it to not store anything to the dagql cache - since it could return a Result, which isn't valid outside of that single Exec.
Does that make sense?
There was a problem hiding this comment.
The Result shouldn't propagate through the entire dagql graph - or through the cache at all. It should be impure so it never enters the dagql cache (but since that's removed, not sure how I do that now).
Okay that explains more yeah, it's just not apparent at first because of the spaghetti around the self-invoking ops (which isn't a criticism at all, it's just the hoops we have to jump through w/ buildkit until we get to the other side of this whole effort).
As a last resort we can add DoNotCache to IDs (only difference w/ previous Impure is that it wouldn't "propagate" and instead just behave the same as fields marked DoNotCache).
But I'd like to avoid that mainly since I don't want to add more complexity to IDs just for the sake of this temporary bridge. At least, I can't think of any reason we'd ever need, in the long-run, self-invoking APIs where the inner result cannot be cached due to reasons like this.
Other more preferable options I can think of:
- Add support for a callback that runs when a
CachedResultin the dagql cache is Released, building on top of the stuff added in cache result wrapping and context cancel management in dagql cache #9774- That feels likely to be something we'd have more use for in the long-run in addition to solving this short term problem
- Figure out a way to get
DoNotCachesettable from custom cache key funcs, dealing with what I mentioned here replace impurity with mix of custom cache keys + field spec settings #9719 (comment)- Then we can look at the dagop context and decide whether to cache or not
- My only hesitation is that this seems like something better to during the migration of dagql cache to sqlite (and all the associated features that'll entail), but we can figure something out earlier than that too
I'm happy to try to help out with this since it's obviously getting way out of scope of what you were doing. I'll try 1 quick and see what it looks like, might not be that bad.
There was a problem hiding this comment.
Neaaaat 🎉 thanks, that's really so much better 😆
5fad493 to
d8e18d7
Compare
|
@jedevc after my commit for #9730 (comment) I saw a flake in It turns out it was happening before my commit too, but I figured it out and fixed here: d8e18d7 It was really tricky, but basically
The patch just incorporates the git endpoint url into the content-based cache key for those sources. This means we get less caching but only for the very very specific scenario of "two repos with bit-by-bit identical module source", but I think that's exceptionally rare anywhere outside our integ tests, so not a big deal imo. |
| case dagql.Instance[*Directory]: | ||
| if inst.Self.Result != nil { | ||
| ref := worker.NewWorkerRefResult(inst.Self.Result, opt.Worker) | ||
| ref := worker.NewWorkerRefResult(inst.Self.Result.Clone(), opt.Worker) |
There was a problem hiding this comment.
Ah neat, yup, I think this is what I was confused by - we need to Clone here, since otherwise we would be potentially double released refs.
LGTM 🎉
These are exclusively used in modulesource.go, so we should move them to there. Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
This allows returning `File`s and `Directory`s more easily, using a wrapped immutable cache ref - this avoids needing our nasty hack to import from the host file system: we can just write directly to our cache ref. To get this working with `Container.asTarball` though, we needed a little reworking, so that's it's possible to get a reasonable filename for the tarball. Potentially this doesn't work if the filename is *completely* unknown until running the function? So, the `DirectoryDagOp` becomes a generic `FSDagOp` able to handle both `Directory`s and `File`s. Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
d8e18d7 to
3fc5d19
Compare
|
Oop, noticed that somewhere some change was adding Should be good now 🎉 @sipsma the changes you've made look good to me, just need an approval now, and should be good to merge whenever! |
| // For git sources, we currently need to mix in the actual git endpoint | ||
| // in order to ensure that we don't get cache hits on repositories that | ||
| // have the same content but different auth. If we get a cache hit on | ||
| // a repo we don't have auth for subsequent operations can break. | ||
| // Given that scenarios in which two different git repos have the exact | ||
| // same bit-by-bit module source are expected to be rare, this shouldn't | ||
| // be a big compromise. | ||
| if src.Git != nil { | ||
| inputs = append(inputs, src.Git.CloneRef) | ||
| } |
There was a problem hiding this comment.
Hm, @sipsma I've seen a similar flake happening: https://v3.dagger.cloud/dagger/traces/10d54381586861dbb1835770e95c9215?span=55f4d468d718aff1
In the above, the bitbucket clone fails because we don't have access to the gitlab credentials. It feels like the buildkit edge merging equivalent of what you just fixed here?
I'm guessing that what's happening is that we're edge merging these two git sources because technically they have the same commit, so can be merged. This would be fine, I think, but, I think we also have double caching of Git.tree for remotes - it's getting cached at the dagop level, and then again at the git source level. There are two ops here, which is making things confusing, and definitely isn't helping.
The right fix here will be to have this as a dagql interface I think, so that one of the implementations can get wrapped, and the other not. But adding core interfaces is a bit tricky, so gonna try and have a bit more of a think on how to fix this.
There was a problem hiding this comment.
My best guess at a fix is in #9840. I think that should resolve this, but even if it doesn't, it should hopefully make a bit clearer to see what's actually going on.
* chore: move matchVersion helpers to modulesource.go These are exclusively used in modulesource.go, so we should move them to there. Signed-off-by: Justin Chadwell <[email protected]> * tests: refactor GitTest to avoid testutil.Query Signed-off-by: Justin Chadwell <[email protected]> * feat: add Directory.asGit Signed-off-by: Justin Chadwell <[email protected]> * feat: refactor dagop usage This allows returning `File`s and `Directory`s more easily, using a wrapped immutable cache ref - this avoids needing our nasty hack to import from the host file system: we can just write directly to our cache ref. To get this working with `Container.asTarball` though, we needed a little reworking, so that's it's possible to get a reasonable filename for the tarball. Potentially this doesn't work if the filename is *completely* unknown until running the function? So, the `DirectoryDagOp` becomes a generic `FSDagOp` able to handle both `Directory`s and `File`s. Signed-off-by: Justin Chadwell <[email protected]> * chore: suggestions from review Signed-off-by: Justin Chadwell <[email protected]> * add support for result release callbacks, use on dir/file Signed-off-by: Erik Sipsma <[email protected]> * fix sdk call cache hits on repos w/ different auth Signed-off-by: Erik Sipsma <[email protected]> * fix: extractLLBDependencies with nil data Signed-off-by: Justin Chadwell <[email protected]> --------- Signed-off-by: Justin Chadwell <[email protected]> Signed-off-by: Erik Sipsma <[email protected]> Co-authored-by: Erik Sipsma <[email protected]>

Revives #9098.
This PR follows up on the work in #9395, by adding a new
Directory.asGitAPI. This allows for importing a directory and performing git operations on it. This was really hard to do efficiently at all without some sort of buildkit caching integration.Note - we still need to do some nasty shuffling around in a temporary directory - however, I have an idea for how to clean this up later, just need to tinker around.