Add content and snapshot store references
Update database object to hold reference to the data stores. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
447a0a9452
commit
2ab70f21ac
@ -25,10 +25,17 @@ type contentStore struct {
|
|||||||
// NewContentStore returns a namespaced content store using an existing
|
// NewContentStore returns a namespaced content store using an existing
|
||||||
// content store interface.
|
// content store interface.
|
||||||
func NewContentStore(db *DB, cs content.Store) content.Store {
|
func NewContentStore(db *DB, cs content.Store) content.Store {
|
||||||
return &contentStore{
|
db.storeL.Lock()
|
||||||
|
defer db.storeL.Unlock()
|
||||||
|
|
||||||
|
if db.cs == nil {
|
||||||
|
db.cs = &contentStore{
|
||||||
Store: cs,
|
Store: cs,
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return db.cs
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *contentStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
|
func (cs *contentStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
|
||||||
|
@ -23,7 +23,7 @@ func createContentStore(ctx context.Context, root string) (content.Store, func()
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewContentStore(db, cs), func() error {
|
return NewContentStore(NewDB(db), cs), func() error {
|
||||||
return db.Close()
|
return db.Close()
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
package metadata
|
package metadata
|
||||||
|
|
||||||
import "github.com/boltdb/bolt"
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/boltdb/bolt"
|
||||||
|
)
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
db *bolt.DB
|
db *bolt.DB
|
||||||
|
|
||||||
|
storeL sync.Mutex
|
||||||
|
ss map[string]*snapshotter
|
||||||
|
cs *contentStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDB(db *bolt.DB) *DB {
|
func NewDB(db *bolt.DB) *DB {
|
||||||
return &DB{
|
return &DB{
|
||||||
db: db,
|
db: db,
|
||||||
|
ss: map[string]*snapshotter{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,20 @@ type snapshotter struct {
|
|||||||
// NewSnapshotter returns a new Snapshotter which namespaces the given snapshot
|
// NewSnapshotter returns a new Snapshotter which namespaces the given snapshot
|
||||||
// using the provided name and metadata store.
|
// using the provided name and metadata store.
|
||||||
func NewSnapshotter(db *DB, name string, sn snapshot.Snapshotter) snapshot.Snapshotter {
|
func NewSnapshotter(db *DB, name string, sn snapshot.Snapshotter) snapshot.Snapshotter {
|
||||||
return &snapshotter{
|
db.storeL.Lock()
|
||||||
|
defer db.storeL.Unlock()
|
||||||
|
|
||||||
|
ss, ok := db.ss[name]
|
||||||
|
if !ok {
|
||||||
|
ss = &snapshotter{
|
||||||
Snapshotter: sn,
|
Snapshotter: sn,
|
||||||
name: name,
|
name: name,
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
db.ss[name] = ss
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss
|
||||||
}
|
}
|
||||||
|
|
||||||
func createKey(id uint64, namespace, key string) string {
|
func createKey(id uint64, namespace, key string) string {
|
||||||
|
@ -28,7 +28,7 @@ func newSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, fun
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sn := NewSnapshotter(db, "naive", snapshotter)
|
sn := NewSnapshotter(NewDB(db), "naive", snapshotter)
|
||||||
|
|
||||||
return sn, func() error {
|
return sn, func() error {
|
||||||
return db.Close()
|
return db.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user