Create metadata db object
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
acba0f50ef
commit
56c1b79a4c
@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
|
||||||
"github.com/containerd/containerd/archive"
|
"github.com/containerd/containerd/archive"
|
||||||
"github.com/containerd/containerd/archive/compression"
|
"github.com/containerd/containerd/archive/compression"
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
@ -38,7 +37,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewWalkingDiff(metadata.NewContentStore(md.(*bolt.DB), c.(content.Store)))
|
return NewWalkingDiff(metadata.NewContentStore(md.(*metadata.DB), c.(content.Store)))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
state: ic.State,
|
state: ic.State,
|
||||||
monitor: monitor.(runtime.TaskMonitor),
|
monitor: monitor.(runtime.TaskMonitor),
|
||||||
tasks: runtime.NewTaskList(),
|
tasks: runtime.NewTaskList(),
|
||||||
db: m.(*bolt.DB),
|
db: m.(*metadata.DB),
|
||||||
address: ic.Address,
|
address: ic.Address,
|
||||||
events: ic.Events,
|
events: ic.Events,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
@ -127,7 +127,7 @@ type Runtime struct {
|
|||||||
|
|
||||||
monitor runtime.TaskMonitor
|
monitor runtime.TaskMonitor
|
||||||
tasks *runtime.TaskList
|
tasks *runtime.TaskList
|
||||||
db *bolt.DB
|
db *metadata.DB
|
||||||
events *events.Exchange
|
events *events.Exchange
|
||||||
|
|
||||||
config *Config
|
config *Config
|
||||||
|
@ -19,7 +19,7 @@ func WithTransactionContext(ctx context.Context, tx *bolt.Tx) context.Context {
|
|||||||
|
|
||||||
// view gets a bolt db transaction either from the context
|
// view gets a bolt db transaction either from the context
|
||||||
// or starts a new one with the provided bolt database.
|
// or starts a new one with the provided bolt database.
|
||||||
func view(ctx context.Context, db *bolt.DB, fn func(*bolt.Tx) error) error {
|
func view(ctx context.Context, db *DB, fn func(*bolt.Tx) error) error {
|
||||||
tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
|
tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return db.View(fn)
|
return db.View(fn)
|
||||||
@ -29,7 +29,7 @@ func view(ctx context.Context, db *bolt.DB, fn func(*bolt.Tx) error) error {
|
|||||||
|
|
||||||
// update gets a writable bolt db transaction either from the context
|
// update gets a writable bolt db transaction either from the context
|
||||||
// or starts a new one with the provided bolt database.
|
// or starts a new one with the provided bolt database.
|
||||||
func update(ctx context.Context, db *bolt.DB, fn func(*bolt.Tx) error) error {
|
func update(ctx context.Context, db *DB, fn func(*bolt.Tx) error) error {
|
||||||
tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
|
tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return db.Update(fn)
|
return db.Update(fn)
|
||||||
|
@ -19,12 +19,12 @@ import (
|
|||||||
|
|
||||||
type contentStore struct {
|
type contentStore struct {
|
||||||
content.Store
|
content.Store
|
||||||
db *bolt.DB
|
db *DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 *bolt.DB, cs content.Store) content.Store {
|
func NewContentStore(db *DB, cs content.Store) content.Store {
|
||||||
return &contentStore{
|
return &contentStore{
|
||||||
Store: cs,
|
Store: cs,
|
||||||
db: db,
|
db: db,
|
||||||
@ -353,7 +353,7 @@ type namespacedWriter struct {
|
|||||||
content.Writer
|
content.Writer
|
||||||
ref string
|
ref string
|
||||||
namespace string
|
namespace string
|
||||||
db *bolt.DB
|
db *DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
|
func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
|
||||||
|
21
metadata/db.go
Normal file
21
metadata/db.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package metadata
|
||||||
|
|
||||||
|
import "github.com/boltdb/bolt"
|
||||||
|
|
||||||
|
type DB struct {
|
||||||
|
db *bolt.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDB(db *bolt.DB) *DB {
|
||||||
|
return &DB{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DB) View(fn func(*bolt.Tx) error) error {
|
||||||
|
return m.db.View(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DB) Update(fn func(*bolt.Tx) error) error {
|
||||||
|
return m.db.Update(fn)
|
||||||
|
}
|
@ -19,12 +19,12 @@ import (
|
|||||||
type snapshotter struct {
|
type snapshotter struct {
|
||||||
snapshot.Snapshotter
|
snapshot.Snapshotter
|
||||||
name string
|
name string
|
||||||
db *bolt.DB
|
db *DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 *bolt.DB, name string, sn snapshot.Snapshotter) snapshot.Snapshotter {
|
func NewSnapshotter(db *DB, name string, sn snapshot.Snapshotter) snapshot.Snapshotter {
|
||||||
return &snapshotter{
|
return &snapshotter{
|
||||||
Snapshotter: sn,
|
Snapshotter: sn,
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/containerd/containerd/content/local"
|
"github.com/containerd/containerd/content/local"
|
||||||
"github.com/containerd/containerd/events"
|
"github.com/containerd/containerd/events"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
|
"github.com/containerd/containerd/metadata"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
metrics "github.com/docker/go-metrics"
|
metrics "github.com/docker/go-metrics"
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
@ -179,7 +180,11 @@ func loadPlugins(config *Config) ([]*plugin.Registration, error) {
|
|||||||
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return bolt.Open(filepath.Join(ic.Root, "meta.db"), 0644, nil)
|
db, err := bolt.Open(filepath.Join(ic.Root, "meta.db"), 0644, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return metadata.NewDB(db), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -28,17 +28,17 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewService(m.(*bolt.DB), ic.Events), nil
|
return NewService(m.(*metadata.DB), ic.Events), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
db *bolt.DB
|
db *metadata.DB
|
||||||
publisher events.Publisher
|
publisher events.Publisher
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(db *bolt.DB, publisher events.Publisher) api.ContainersServer {
|
func NewService(db *metadata.DB, publisher events.Publisher) api.ContainersServer {
|
||||||
return &Service{db: db, publisher: publisher}
|
return &Service{db: db, publisher: publisher}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
|
||||||
api "github.com/containerd/containerd/api/services/content/v1"
|
api "github.com/containerd/containerd/api/services/content/v1"
|
||||||
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
@ -56,7 +55,9 @@ func NewService(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cs := metadata.NewContentStore(m.(*bolt.DB), c.(content.Store))
|
|
||||||
|
cs := metadata.NewContentStore(m.(*metadata.DB), c.(content.Store))
|
||||||
|
|
||||||
return &Service{
|
return &Service{
|
||||||
store: cs,
|
store: cs,
|
||||||
publisher: ic.Events,
|
publisher: ic.Events,
|
||||||
|
@ -28,17 +28,17 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewService(m.(*bolt.DB), ic.Events), nil
|
return NewService(m.(*metadata.DB), ic.Events), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
db *bolt.DB
|
db *metadata.DB
|
||||||
publisher events.Publisher
|
publisher events.Publisher
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(db *bolt.DB, publisher events.Publisher) imagesapi.ImagesServer {
|
func NewService(db *metadata.DB, publisher events.Publisher) imagesapi.ImagesServer {
|
||||||
return &Service{
|
return &Service{
|
||||||
db: db,
|
db: db,
|
||||||
publisher: publisher,
|
publisher: publisher,
|
||||||
|
@ -29,19 +29,19 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewService(m.(*bolt.DB), ic.Events), nil
|
return NewService(m.(*metadata.DB), ic.Events), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
db *bolt.DB
|
db *metadata.DB
|
||||||
publisher events.Publisher
|
publisher events.Publisher
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ api.NamespacesServer = &Service{}
|
var _ api.NamespacesServer = &Service{}
|
||||||
|
|
||||||
func NewService(db *bolt.DB, publisher events.Publisher) api.NamespacesServer {
|
func NewService(db *metadata.DB, publisher events.Publisher) api.NamespacesServer {
|
||||||
return &Service{
|
return &Service{
|
||||||
db: db,
|
db: db,
|
||||||
publisher: publisher,
|
publisher: publisher,
|
||||||
|
@ -3,7 +3,6 @@ package snapshot
|
|||||||
import (
|
import (
|
||||||
gocontext "context"
|
gocontext "context"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
|
||||||
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
||||||
snapshotapi "github.com/containerd/containerd/api/services/snapshot/v1"
|
snapshotapi "github.com/containerd/containerd/api/services/snapshot/v1"
|
||||||
"github.com/containerd/containerd/api/types"
|
"github.com/containerd/containerd/api/types"
|
||||||
@ -50,7 +49,7 @@ func newService(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
snapshotters := make(map[string]snapshot.Snapshotter)
|
snapshotters := make(map[string]snapshot.Snapshotter)
|
||||||
for name, sn := range rawSnapshotters {
|
for name, sn := range rawSnapshotters {
|
||||||
snapshotters[name] = metadata.NewSnapshotter(md.(*bolt.DB), name, sn.(snapshot.Snapshotter))
|
snapshotters[name] = metadata.NewSnapshotter(md.(*metadata.DB), name, sn.(snapshot.Snapshotter))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(snapshotters) == 0 {
|
if len(snapshotters) == 0 {
|
||||||
|
@ -63,7 +63,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cs := metadata.NewContentStore(m.(*bolt.DB), ct.(content.Store))
|
cs := metadata.NewContentStore(m.(*metadata.DB), ct.(content.Store))
|
||||||
runtimes := make(map[string]runtime.Runtime)
|
runtimes := make(map[string]runtime.Runtime)
|
||||||
for _, rr := range rt {
|
for _, rr := range rt {
|
||||||
r := rr.(runtime.Runtime)
|
r := rr.(runtime.Runtime)
|
||||||
@ -71,7 +71,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
return &Service{
|
return &Service{
|
||||||
runtimes: runtimes,
|
runtimes: runtimes,
|
||||||
db: m.(*bolt.DB),
|
db: m.(*metadata.DB),
|
||||||
store: cs,
|
store: cs,
|
||||||
publisher: ic.Events,
|
publisher: ic.Events,
|
||||||
}, nil
|
}, nil
|
||||||
@ -79,7 +79,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
runtimes map[string]runtime.Runtime
|
runtimes map[string]runtime.Runtime
|
||||||
db *bolt.DB
|
db *metadata.DB
|
||||||
store content.Store
|
store content.Store
|
||||||
publisher events.Publisher
|
publisher events.Publisher
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/events"
|
"github.com/containerd/containerd/events"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
|
"github.com/containerd/containerd/metadata"
|
||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
@ -68,7 +69,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
// TODO(mlaventure): windows needs a stat monitor
|
// TODO(mlaventure): windows needs a stat monitor
|
||||||
monitor: nil,
|
monitor: nil,
|
||||||
tasks: runtime.NewTaskList(),
|
tasks: runtime.NewTaskList(),
|
||||||
db: m.(*bolt.DB),
|
db: m.(*metadata.DB),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load our existing containers and kill/delete them. We don't support
|
// Load our existing containers and kill/delete them. We don't support
|
||||||
@ -89,7 +90,7 @@ type windowsRuntime struct {
|
|||||||
|
|
||||||
monitor runtime.TaskMonitor
|
monitor runtime.TaskMonitor
|
||||||
tasks *runtime.TaskList
|
tasks *runtime.TaskList
|
||||||
db *bolt.DB
|
db *metadata.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *windowsRuntime) ID() string {
|
func (r *windowsRuntime) ID() string {
|
||||||
|
Loading…
Reference in New Issue
Block a user