Use the transactor interface in metadata

The boltdb instance in metadata is only used for getting transactions
and can also be overriden via the context to have a wider control of the
transaction boundary. Using the transactor interface allows callers of
metadata to have more control of the transaction lifecycle.

Since boltdb must be fsync'ed on commit, operations which perform many
database operations can be costly and slow. While providing transactor
via context can be used to group together operations, it does not
provide a way to manage the commit fsyncs more globally.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2024-06-25 07:12:30 -07:00
parent 741c4bde51
commit 8f9607eed5
3 changed files with 16 additions and 13 deletions

View File

@@ -27,14 +27,15 @@ import (
"time"
eventstypes "github.com/containerd/containerd/api/events"
"github.com/containerd/log"
bolt "go.etcd.io/bbolt"
"github.com/containerd/containerd/v2/core/content"
"github.com/containerd/containerd/v2/core/events"
"github.com/containerd/containerd/v2/core/snapshots"
"github.com/containerd/containerd/v2/internal/cleanup"
"github.com/containerd/containerd/v2/pkg/gc"
"github.com/containerd/containerd/v2/pkg/namespaces"
"github.com/containerd/log"
bolt "go.etcd.io/bbolt"
)
const (
@@ -80,7 +81,7 @@ type dbOptions struct {
// while proxying data shared across namespaces to backend
// datastores for content and snapshots.
type DB struct {
db *bolt.DB
db Transactor
ss map[string]*snapshotter
cs *contentStore
@@ -115,7 +116,7 @@ type DB struct {
// NewDB creates a new metadata database using the provided
// bolt database, content store, and snapshotters.
func NewDB(db *bolt.DB, cs content.Store, ss map[string]snapshots.Snapshotter, opts ...DBOpt) *DB {
func NewDB(db Transactor, cs content.Store, ss map[string]snapshots.Snapshotter, opts ...DBOpt) *DB {
m := &DB{
db: db,
ss: make(map[string]*snapshotter, len(ss)),