fix(boltdb): close cache and history dbs on exit

Signed-off-by: Chris Goller <goller@gmail.com>
This commit is contained in:
Chris Goller
2023-08-30 17:47:24 -05:00
parent 05eb728753
commit 4d4fc4dbd9
3 changed files with 18 additions and 1 deletions

View File

@@ -754,6 +754,7 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err
Entitlements: cfg.Entitlements,
TraceCollector: tc,
HistoryDB: historyDB,
CacheStore: cacheStorage,
LeaseManager: w.LeaseManager(),
ContentStore: w.ContentStore(),
HistoryConfig: cfg.History,

View File

@@ -12,6 +12,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/services/content/contentserver"
"github.com/docker/distribution/reference"
"github.com/hashicorp/go-multierror"
"github.com/mitchellh/hashstructure/v2"
controlapi "github.com/moby/buildkit/api/services/control"
apitypes "github.com/moby/buildkit/api/types"
@@ -29,6 +30,7 @@ import (
"github.com/moby/buildkit/session/grpchijack"
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/solver/bboltcachestorage"
"github.com/moby/buildkit/solver/llbsolver"
"github.com/moby/buildkit/solver/llbsolver/proc"
"github.com/moby/buildkit/solver/pb"
@@ -61,6 +63,7 @@ type Opt struct {
Entitlements []string
TraceCollector sdktrace.SpanExporter
HistoryDB *bbolt.DB
CacheStore *bboltcachestorage.Store
LeaseManager *leaseutil.Manager
ContentStore *containerdsnapshot.Store
HistoryConfig *config.HistoryConfig
@@ -123,7 +126,16 @@ func NewController(opt Opt) (*Controller, error) {
}
func (c *Controller) Close() error {
return c.opt.WorkerController.Close()
rerr := c.opt.HistoryDB.Close()
if err := c.opt.WorkerController.Close(); err != nil {
rerr = multierror.Append(rerr, err)
}
if err := c.opt.CacheStore.Close(); err != nil {
rerr = multierror.Append(rerr, err)
}
return rerr
}
func (c *Controller) Register(server *grpc.Server) {

View File

@@ -54,6 +54,10 @@ func (s *Store) Exists(id string) bool {
return exists
}
func (s *Store) Close() error {
return s.db.Close()
}
func (s *Store) Walk(fn func(id string) error) error {
ids := make([]string, 0)
if err := s.db.View(func(tx *bolt.Tx) error {