Remove kvstore deps from datastore package
Currently datastore has dependencies on various kv backends. This is undesirable if datastore had to be used as a backend agnostic store management package with it's cache layer. This PR aims to achieve that. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
0eb215c7e6
commit
89e72d8888
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/libkv/store"
|
"github.com/docker/libkv/store"
|
||||||
|
"github.com/docker/libkv/store/boltdb"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
_ "github.com/docker/libnetwork/testutils"
|
_ "github.com/docker/libnetwork/testutils"
|
||||||
)
|
)
|
||||||
|
@ -16,6 +17,10 @@ const (
|
||||||
defaultPrefix = "/tmp/libnetwork/test/bitseq"
|
defaultPrefix = "/tmp/libnetwork/test/bitseq"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
boltdb.Register()
|
||||||
|
}
|
||||||
|
|
||||||
func randomLocalStore() (datastore.DataStore, error) {
|
func randomLocalStore() (datastore.DataStore, error) {
|
||||||
tmp, err := ioutil.TempFile("", "libnetwork-")
|
tmp, err := ioutil.TempFile("", "libnetwork-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/libkv/store"
|
"github.com/docker/libkv/store"
|
||||||
"github.com/docker/libkv/store/boltdb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type kvMap map[string]KVObject
|
type kvMap map[string]KVObject
|
||||||
|
@ -42,9 +41,7 @@ func (c *cache) kmap(kvObject KVObject) (kvMap, error) {
|
||||||
|
|
||||||
kvList, err := c.ds.store.List(keyPrefix)
|
kvList, err := c.ds.store.List(keyPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// In case of BoltDB it may return ErrBoltBucketNotFound when no writes
|
if err == store.ErrKeyNotFound {
|
||||||
// have ever happened on the db bucket. So check for both err codes
|
|
||||||
if err == store.ErrKeyNotFound || err == boltdb.ErrBoltBucketNotFound {
|
|
||||||
// If the store doesn't have anything then there is nothing to
|
// If the store doesn't have anything then there is nothing to
|
||||||
// populate in the cache. Just bail out.
|
// populate in the cache. Just bail out.
|
||||||
goto out
|
goto out
|
||||||
|
|
|
@ -9,10 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/libkv"
|
"github.com/docker/libkv"
|
||||||
"github.com/docker/libkv/store"
|
"github.com/docker/libkv/store"
|
||||||
"github.com/docker/libkv/store/boltdb"
|
|
||||||
"github.com/docker/libkv/store/consul"
|
|
||||||
"github.com/docker/libkv/store/etcd"
|
|
||||||
"github.com/docker/libkv/store/zookeeper"
|
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
"github.com/docker/libnetwork/types"
|
"github.com/docker/libnetwork/types"
|
||||||
)
|
)
|
||||||
|
@ -148,13 +144,6 @@ func makeDefaultScopes() map[string]*ScopeCfg {
|
||||||
var defaultRootChain = []string{"docker", "network", "v1.0"}
|
var defaultRootChain = []string{"docker", "network", "v1.0"}
|
||||||
var rootChain = defaultRootChain
|
var rootChain = defaultRootChain
|
||||||
|
|
||||||
func init() {
|
|
||||||
consul.Register()
|
|
||||||
zookeeper.Register()
|
|
||||||
etcd.Register()
|
|
||||||
boltdb.Register()
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultScopes returns a map of default scopes and it's config for clients to use.
|
// DefaultScopes returns a map of default scopes and it's config for clients to use.
|
||||||
func DefaultScopes(dataDir string) map[string]*ScopeCfg {
|
func DefaultScopes(dataDir string) map[string]*ScopeCfg {
|
||||||
if dataDir != "" {
|
if dataDir != "" {
|
||||||
|
@ -411,6 +400,9 @@ func (ds *datastore) PutObjectAtomic(kvObject KVObject) error {
|
||||||
|
|
||||||
_, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil)
|
_, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == store.ErrKeyExists {
|
||||||
|
return ErrKeyModified
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,6 +563,9 @@ func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
|
if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
|
||||||
|
if err == store.ErrKeyExists {
|
||||||
|
return ErrKeyModified
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libkv/store/boltdb"
|
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
"github.com/docker/libnetwork/netlabel"
|
"github.com/docker/libnetwork/netlabel"
|
||||||
|
@ -35,7 +34,7 @@ func (d *driver) initStore(option map[string]interface{}) error {
|
||||||
|
|
||||||
func (d *driver) populateNetworks() error {
|
func (d *driver) populateNetworks() error {
|
||||||
kvol, err := d.store.List(datastore.Key(bridgePrefix), &networkConfiguration{})
|
kvol, err := d.store.List(datastore.Key(bridgePrefix), &networkConfiguration{})
|
||||||
if err != nil && err != datastore.ErrKeyNotFound && err != boltdb.ErrBoltBucketNotFound {
|
if err != nil && err != datastore.ErrKeyNotFound {
|
||||||
return fmt.Errorf("failed to get bridge network configurations from store: %v", err)
|
return fmt.Errorf("failed to get bridge network configurations from store: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libkv/store/boltdb"
|
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
"github.com/docker/libnetwork/netlabel"
|
"github.com/docker/libnetwork/netlabel"
|
||||||
|
@ -60,7 +59,7 @@ func (d *driver) initStore(option map[string]interface{}) error {
|
||||||
// populateNetworks is invoked at driver init to recreate persistently stored networks
|
// populateNetworks is invoked at driver init to recreate persistently stored networks
|
||||||
func (d *driver) populateNetworks() error {
|
func (d *driver) populateNetworks() error {
|
||||||
kvol, err := d.store.List(datastore.Key(ipvlanPrefix), &configuration{})
|
kvol, err := d.store.List(datastore.Key(ipvlanPrefix), &configuration{})
|
||||||
if err != nil && err != datastore.ErrKeyNotFound && err != boltdb.ErrBoltBucketNotFound {
|
if err != nil && err != datastore.ErrKeyNotFound {
|
||||||
return fmt.Errorf("failed to get ipvlan network configurations from store: %v", err)
|
return fmt.Errorf("failed to get ipvlan network configurations from store: %v", err)
|
||||||
}
|
}
|
||||||
// If empty it simply means no ipvlan networks have been created yet
|
// If empty it simply means no ipvlan networks have been created yet
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libkv/store/boltdb"
|
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
"github.com/docker/libnetwork/netlabel"
|
"github.com/docker/libnetwork/netlabel"
|
||||||
|
@ -60,7 +59,7 @@ func (d *driver) initStore(option map[string]interface{}) error {
|
||||||
// populateNetworks is invoked at driver init to recreate persistently stored networks
|
// populateNetworks is invoked at driver init to recreate persistently stored networks
|
||||||
func (d *driver) populateNetworks() error {
|
func (d *driver) populateNetworks() error {
|
||||||
kvol, err := d.store.List(datastore.Key(macvlanPrefix), &configuration{})
|
kvol, err := d.store.List(datastore.Key(macvlanPrefix), &configuration{})
|
||||||
if err != nil && err != datastore.ErrKeyNotFound && err != boltdb.ErrBoltBucketNotFound {
|
if err != nil && err != datastore.ErrKeyNotFound {
|
||||||
return fmt.Errorf("failed to get macvlan network configurations from store: %v", err)
|
return fmt.Errorf("failed to get macvlan network configurations from store: %v", err)
|
||||||
}
|
}
|
||||||
// If empty it simply means no macvlan networks have been created yet
|
// If empty it simply means no macvlan networks have been created yet
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/libkv/store/boltdb"
|
||||||
"github.com/docker/libnetwork/bitseq"
|
"github.com/docker/libnetwork/bitseq"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
|
@ -25,6 +26,10 @@ const (
|
||||||
dsDataKey = "ipam/" + ipamapi.DefaultIPAM + "/data"
|
dsDataKey = "ipam/" + ipamapi.DefaultIPAM + "/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
boltdb.Register()
|
||||||
|
}
|
||||||
|
|
||||||
// Allocator provides per address space ipv4/ipv6 book keeping
|
// Allocator provides per address space ipv4/ipv6 book keeping
|
||||||
type Allocator struct {
|
type Allocator struct {
|
||||||
// Predefined pools for default address spaces
|
// Predefined pools for default address spaces
|
||||||
|
|
|
@ -4,9 +4,20 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/libkv/store/boltdb"
|
||||||
|
"github.com/docker/libkv/store/consul"
|
||||||
|
"github.com/docker/libkv/store/etcd"
|
||||||
|
"github.com/docker/libkv/store/zookeeper"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func registerKVStores() {
|
||||||
|
consul.Register()
|
||||||
|
zookeeper.Register()
|
||||||
|
etcd.Register()
|
||||||
|
boltdb.Register()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
|
func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
|
||||||
store, err := datastore.NewDataStore(scope, scfg)
|
store, err := datastore.NewDataStore(scope, scfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,6 +31,8 @@ func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) initStores() error {
|
func (c *controller) initStores() error {
|
||||||
|
registerKVStores()
|
||||||
|
|
||||||
c.Lock()
|
c.Lock()
|
||||||
if c.cfg == nil {
|
if c.cfg == nil {
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue