Move boltdb implementation to storage package

Removes storage interface and replaces with storage functions.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-03-24 17:16:41 -07:00
parent 8affca40bb
commit b319ba7c5a
No known key found for this signature in database
GPG key ID: F58C5D0A4405ACDB
12 changed files with 373 additions and 404 deletions

View file

@ -12,7 +12,6 @@ import (
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/storage"
"github.com/containerd/containerd/snapshot/storage/boltdb"
"github.com/pkg/errors"
"github.com/stevvooe/go-btrfs"
)
@ -32,13 +31,7 @@ func init() {
// TODO: check device for root
return nil, errors.Errorf("btrfs requires \"device\" configuration")
}
ms, err := boltdb.NewMetaStore(ic.Context, filepath.Join(root, "metadata.db"))
if err != nil {
return nil, err
}
return NewSnapshotter(conf.Device, root, ms)
return NewSnapshotter(conf.Device, root)
},
})
}
@ -46,10 +39,10 @@ func init() {
type Snapshotter struct {
device string // maybe we can resolve it with path?
root string // root provides paths for internal storage.
ms storage.MetaStore
ms *storage.MetaStore
}
func NewSnapshotter(device, root string, ms storage.MetaStore) (snapshot.Snapshotter, error) {
func NewSnapshotter(device, root string) (snapshot.Snapshotter, error) {
var (
active = filepath.Join(root, "active")
snapshots = filepath.Join(root, "snapshots")
@ -63,6 +56,10 @@ func NewSnapshotter(device, root string, ms storage.MetaStore) (snapshot.Snapsho
return nil, err
}
}
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
if err != nil {
return nil, err
}
return &Snapshotter{
device: device,
@ -82,7 +79,7 @@ func (b *Snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, erro
return snapshot.Info{}, err
}
defer t.Rollback()
return b.ms.Stat(ctx, key)
return storage.GetInfo(ctx, key)
}
// Walk the committed snapshots.
@ -92,7 +89,7 @@ func (b *Snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
return err
}
defer t.Rollback()
return b.ms.Walk(ctx, fn)
return storage.WalkInfo(ctx, fn)
}
func (b *Snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
@ -116,7 +113,7 @@ func (b *Snapshotter) makeActive(ctx context.Context, key, parent string, readon
}
}()
a, err := b.ms.CreateActive(ctx, key, parent, readonly)
a, err := storage.CreateActive(ctx, key, parent, readonly)
if err != nil {
return nil, err
}
@ -187,7 +184,7 @@ func (b *Snapshotter) Commit(ctx context.Context, name, key string) (err error)
}
}()
id, err := b.ms.Commit(ctx, key, name)
id, err := storage.CommitActive(ctx, key, name)
if err != nil {
return errors.Wrap(err, "failed to commit")
}
@ -225,7 +222,7 @@ func (b *Snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Moun
if err != nil {
return nil, err
}
a, err := b.ms.GetActive(ctx, key)
a, err := storage.GetActive(ctx, key)
t.Rollback()
if err != nil {
return nil, errors.Wrap(err, "failed to get active snapshot")
@ -260,7 +257,7 @@ func (b *Snapshotter) Remove(ctx context.Context, key string) (err error) {
}
}()
id, k, err := b.ms.Remove(ctx, key)
id, k, err := storage.Remove(ctx, key)
if err != nil {
return errors.Wrap(err, "failed to remove snapshot")
}