Update metadata plugin initialization
Updates metadata plugin to require content and snapshotter plugins be loaded and initializes with those plugins, keeping the metadata database structure static after initialization. Service plugins now only require metadata plugin access snapshotter or content stores through metadata, which was already required behavior of the services. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -1,26 +1,40 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
)
|
||||
|
||||
type DB struct {
|
||||
db *bolt.DB
|
||||
|
||||
storeL sync.Mutex
|
||||
ss map[string]*snapshotter
|
||||
cs *contentStore
|
||||
ss map[string]snapshot.Snapshotter
|
||||
cs content.Store
|
||||
}
|
||||
|
||||
func NewDB(db *bolt.DB) *DB {
|
||||
func NewDB(db *bolt.DB, cs content.Store, ss map[string]snapshot.Snapshotter) *DB {
|
||||
return &DB{
|
||||
db: db,
|
||||
ss: map[string]*snapshotter{},
|
||||
ss: ss,
|
||||
cs: cs,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *DB) ContentStore() content.Store {
|
||||
if m.cs == nil {
|
||||
return nil
|
||||
}
|
||||
return newContentStore(m, m.cs)
|
||||
}
|
||||
|
||||
func (m *DB) Snapshotter(name string) snapshot.Snapshotter {
|
||||
sn, ok := m.ss[name]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return newSnapshotter(m, name, sn)
|
||||
}
|
||||
|
||||
func (m *DB) View(fn func(*bolt.Tx) error) error {
|
||||
return m.db.View(fn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user