Skip to content

Commit

Permalink
Add WithMetaStore to overlay snapshotter to allow bringing your own
Browse files Browse the repository at this point in the history
Signed-off-by: Robbie Buxton <138501839+rbpdt@users.noreply.github.com>
  • Loading branch information
Robbie Buxton authored and pull[bot] committed Feb 27, 2024
1 parent c9723bd commit d00d37b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions snapshots/overlay/overlay.go
Expand Up @@ -44,6 +44,7 @@ const upperdirKey = "containerd.io/snapshot/overlay.upperdir"
type SnapshotterConfig struct {
asyncRemove bool
upperdirLabel bool
ms MetaStore
mountOptions []string
}

Expand Down Expand Up @@ -77,9 +78,24 @@ func WithMountOptions(options []string) Opt {
}
}

type MetaStore interface {
TransactionContext(ctx context.Context, writable bool) (context.Context, storage.Transactor, error)
WithTransaction(ctx context.Context, writable bool, fn storage.TransactionCallback) error
Close() error
}

// WithMetaStore allows the MetaStore to be created outside the snapshotter
// and passed in.
func WithMetaStore(ms MetaStore) Opt {
return func(config *SnapshotterConfig) error {
config.ms = ms
return nil
}
}

type snapshotter struct {
root string
ms *storage.MetaStore
ms MetaStore
asyncRemove bool
upperdirLabel bool
options []string
Expand All @@ -106,9 +122,11 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
if !supportsDType {
return nil, fmt.Errorf("%s does not support d_type. If the backing filesystem is xfs, please reformat with ftype=1 to enable d_type support", root)
}
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
if err != nil {
return nil, err
if config.ms == nil {
config.ms, err = storage.NewMetaStore(filepath.Join(root, "metadata.db"))
if err != nil {
return nil, err
}
}

if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
Expand All @@ -132,7 +150,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {

return &snapshotter{
root: root,
ms: ms,
ms: config.ms,
asyncRemove: config.asyncRemove,
upperdirLabel: config.upperdirLabel,
options: config.mountOptions,
Expand Down

0 comments on commit d00d37b

Please sign in to comment.