Skip to content

Commit

Permalink
Merge pull request #55 from earthly/mh/next-cache-ids
Browse files Browse the repository at this point in the history
Cache IDs & fix BK result caching
  • Loading branch information
mikejholly authored Apr 9, 2024
2 parents 194ece3 + 636787b commit 4527e34
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 29 deletions.
1 change: 1 addition & 0 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ func newController(c *cli.Context, cfg *config.Config, shutdownCh chan struct{})
LeaseManager: w.LeaseManager(),
ContentStore: w.ContentStore(),
HistoryConfig: cfg.History,
RootDir: cfg.Root,
})
}

Expand Down
2 changes: 2 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Opt struct {
LeaseManager *leaseutil.Manager
ContentStore *containerdsnapshot.Store
HistoryConfig *config.HistoryConfig
RootDir string
}

type Controller struct { // TODO: ControlService
Expand Down Expand Up @@ -105,6 +106,7 @@ func NewController(opt Opt) (*Controller, error) {
SessionManager: opt.SessionManager,
Entitlements: opt.Entitlements,
HistoryQueue: hq,
RootDir: opt.RootDir,
})
if err != nil {
return nil, errors.Wrap(err, "failed to create solver")
Expand Down
18 changes: 15 additions & 3 deletions solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ type Job struct {
}

type SolverOpt struct {
ResolveOpFunc ResolveOpFunc
DefaultCache CacheManager
ResolveOpFunc ResolveOpFunc
DefaultCache CacheManager
WorkerResultGetter workerResultGetter
CommitRefFunc CommitRefFunc
RootDir string
}

func NewSolver(opts SolverOpt) *Solver {
Expand All @@ -274,7 +277,11 @@ func NewSolver(opts SolverOpt) *Solver {
// TODO: This should be hoisted up a few layers as not to be bound to the
// original solver. For now, we just need a convenient place to initialize
// it once.
simple := newSimpleSolver(opts.ResolveOpFunc, jl)
c, err := newDiskCache(opts.WorkerResultGetter, opts.RootDir)
if err != nil {
panic(err) // TODO: Handle error appropriately once the new solver code is moved.
}
simple := newSimpleSolver(opts.ResolveOpFunc, opts.CommitRefFunc, jl, c)
jl.simple = simple

jl.s = newScheduler(jl)
Expand Down Expand Up @@ -613,6 +620,11 @@ func (j *Job) CloseProgress() {
}

func (j *Job) Discard() error {
// TMP: Hack to prevent actives map deletes.
if true {
return nil
}

j.list.mu.Lock()
defer j.list.mu.Unlock()

Expand Down
3 changes: 3 additions & 0 deletions solver/llbsolver/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ func captureProvenance(ctx context.Context, res solver.CachedResultWithProvenanc
switch op := pp.(type) {
case *ops.SourceOp:
id, pin := op.Pin()
if pin == "" { // Hack: latest cache opt changes led to an empty value here. Investigate.
return nil
}
err := id.Capture(c, pin)
if err != nil {
return err
Expand Down
8 changes: 6 additions & 2 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Opt struct {
WorkerController *worker.Controller
HistoryQueue *HistoryQueue
ResourceMonitor *resources.Monitor
RootDir string
}

type Solver struct {
Expand Down Expand Up @@ -119,8 +120,11 @@ func New(opt Opt) (*Solver, error) {
s.sysSampler = sampler

s.solver = solver.NewSolver(solver.SolverOpt{
ResolveOpFunc: s.resolver(),
DefaultCache: opt.CacheManager,
ResolveOpFunc: s.resolver(),
DefaultCache: opt.CacheManager,
WorkerResultGetter: worker.NewWorkerResultGetter(opt.WorkerController),
CommitRefFunc: worker.FinalizeRef,
RootDir: opt.RootDir,
})
return s, nil
}
Expand Down
Loading

0 comments on commit 4527e34

Please sign in to comment.