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>
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"time" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/libkv/store" |
| 11 |
+ "github.com/docker/libkv/store/boltdb" |
|
| 11 | 12 |
"github.com/docker/libnetwork/datastore" |
| 12 | 13 |
_ "github.com/docker/libnetwork/testutils" |
| 13 | 14 |
) |
| ... | ... |
@@ -16,6 +17,10 @@ const ( |
| 16 | 16 |
defaultPrefix = "/tmp/libnetwork/test/bitseq" |
| 17 | 17 |
) |
| 18 | 18 |
|
| 19 |
+func init() {
|
|
| 20 |
+ boltdb.Register() |
|
| 21 |
+} |
|
| 22 |
+ |
|
| 19 | 23 |
func randomLocalStore() (datastore.DataStore, error) {
|
| 20 | 24 |
tmp, err := ioutil.TempFile("", "libnetwork-")
|
| 21 | 25 |
if err != nil {
|
| ... | ... |
@@ -5,7 +5,6 @@ import ( |
| 5 | 5 |
"sync" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/docker/libkv/store" |
| 8 |
- "github.com/docker/libkv/store/boltdb" |
|
| 9 | 8 |
) |
| 10 | 9 |
|
| 11 | 10 |
type kvMap map[string]KVObject |
| ... | ... |
@@ -42,9 +41,7 @@ func (c *cache) kmap(kvObject KVObject) (kvMap, error) {
|
| 42 | 42 |
|
| 43 | 43 |
kvList, err := c.ds.store.List(keyPrefix) |
| 44 | 44 |
if err != nil {
|
| 45 |
- // In case of BoltDB it may return ErrBoltBucketNotFound when no writes |
|
| 46 |
- // have ever happened on the db bucket. So check for both err codes |
|
| 47 |
- if err == store.ErrKeyNotFound || err == boltdb.ErrBoltBucketNotFound {
|
|
| 45 |
+ if err == store.ErrKeyNotFound {
|
|
| 48 | 46 |
// If the store doesn't have anything then there is nothing to |
| 49 | 47 |
// populate in the cache. Just bail out. |
| 50 | 48 |
goto out |
| ... | ... |
@@ -9,10 +9,6 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/libkv" |
| 11 | 11 |
"github.com/docker/libkv/store" |
| 12 |
- "github.com/docker/libkv/store/boltdb" |
|
| 13 |
- "github.com/docker/libkv/store/consul" |
|
| 14 |
- "github.com/docker/libkv/store/etcd" |
|
| 15 |
- "github.com/docker/libkv/store/zookeeper" |
|
| 16 | 12 |
"github.com/docker/libnetwork/discoverapi" |
| 17 | 13 |
"github.com/docker/libnetwork/types" |
| 18 | 14 |
) |
| ... | ... |
@@ -148,13 +144,6 @@ func makeDefaultScopes() map[string]*ScopeCfg {
|
| 148 | 148 |
var defaultRootChain = []string{"docker", "network", "v1.0"}
|
| 149 | 149 |
var rootChain = defaultRootChain |
| 150 | 150 |
|
| 151 |
-func init() {
|
|
| 152 |
- consul.Register() |
|
| 153 |
- zookeeper.Register() |
|
| 154 |
- etcd.Register() |
|
| 155 |
- boltdb.Register() |
|
| 156 |
-} |
|
| 157 |
- |
|
| 158 | 151 |
// DefaultScopes returns a map of default scopes and it's config for clients to use. |
| 159 | 152 |
func DefaultScopes(dataDir string) map[string]*ScopeCfg {
|
| 160 | 153 |
if dataDir != "" {
|
| ... | ... |
@@ -411,6 +400,9 @@ func (ds *datastore) PutObjectAtomic(kvObject KVObject) error {
|
| 411 | 411 |
|
| 412 | 412 |
_, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil) |
| 413 | 413 |
if err != nil {
|
| 414 |
+ if err == store.ErrKeyExists {
|
|
| 415 |
+ return ErrKeyModified |
|
| 416 |
+ } |
|
| 414 | 417 |
return err |
| 415 | 418 |
} |
| 416 | 419 |
|
| ... | ... |
@@ -571,6 +563,9 @@ func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
|
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 | 573 |
if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
|
| 574 |
+ if err == store.ErrKeyExists {
|
|
| 575 |
+ return ErrKeyModified |
|
| 576 |
+ } |
|
| 574 | 577 |
return err |
| 575 | 578 |
} |
| 576 | 579 |
|
| ... | ... |
@@ -6,7 +6,6 @@ import ( |
| 6 | 6 |
"net" |
| 7 | 7 |
|
| 8 | 8 |
"github.com/Sirupsen/logrus" |
| 9 |
- "github.com/docker/libkv/store/boltdb" |
|
| 10 | 9 |
"github.com/docker/libnetwork/datastore" |
| 11 | 10 |
"github.com/docker/libnetwork/discoverapi" |
| 12 | 11 |
"github.com/docker/libnetwork/netlabel" |
| ... | ... |
@@ -35,7 +34,7 @@ func (d *driver) initStore(option map[string]interface{}) error {
|
| 35 | 35 |
|
| 36 | 36 |
func (d *driver) populateNetworks() error {
|
| 37 | 37 |
kvol, err := d.store.List(datastore.Key(bridgePrefix), &networkConfiguration{})
|
| 38 |
- if err != nil && err != datastore.ErrKeyNotFound && err != boltdb.ErrBoltBucketNotFound {
|
|
| 38 |
+ if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 39 | 39 |
return fmt.Errorf("failed to get bridge network configurations from store: %v", err)
|
| 40 | 40 |
} |
| 41 | 41 |
|
| ... | ... |
@@ -5,7 +5,6 @@ import ( |
| 5 | 5 |
"fmt" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/Sirupsen/logrus" |
| 8 |
- "github.com/docker/libkv/store/boltdb" |
|
| 9 | 8 |
"github.com/docker/libnetwork/datastore" |
| 10 | 9 |
"github.com/docker/libnetwork/discoverapi" |
| 11 | 10 |
"github.com/docker/libnetwork/netlabel" |
| ... | ... |
@@ -60,7 +59,7 @@ func (d *driver) initStore(option map[string]interface{}) error {
|
| 60 | 60 |
// populateNetworks is invoked at driver init to recreate persistently stored networks |
| 61 | 61 |
func (d *driver) populateNetworks() error {
|
| 62 | 62 |
kvol, err := d.store.List(datastore.Key(ipvlanPrefix), &configuration{})
|
| 63 |
- if err != nil && err != datastore.ErrKeyNotFound && err != boltdb.ErrBoltBucketNotFound {
|
|
| 63 |
+ if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 64 | 64 |
return fmt.Errorf("failed to get ipvlan network configurations from store: %v", err)
|
| 65 | 65 |
} |
| 66 | 66 |
// If empty it simply means no ipvlan networks have been created yet |
| ... | ... |
@@ -5,7 +5,6 @@ import ( |
| 5 | 5 |
"fmt" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/Sirupsen/logrus" |
| 8 |
- "github.com/docker/libkv/store/boltdb" |
|
| 9 | 8 |
"github.com/docker/libnetwork/datastore" |
| 10 | 9 |
"github.com/docker/libnetwork/discoverapi" |
| 11 | 10 |
"github.com/docker/libnetwork/netlabel" |
| ... | ... |
@@ -60,7 +59,7 @@ func (d *driver) initStore(option map[string]interface{}) error {
|
| 60 | 60 |
// populateNetworks is invoked at driver init to recreate persistently stored networks |
| 61 | 61 |
func (d *driver) populateNetworks() error {
|
| 62 | 62 |
kvol, err := d.store.List(datastore.Key(macvlanPrefix), &configuration{})
|
| 63 |
- if err != nil && err != datastore.ErrKeyNotFound && err != boltdb.ErrBoltBucketNotFound {
|
|
| 63 |
+ if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 64 | 64 |
return fmt.Errorf("failed to get macvlan network configurations from store: %v", err)
|
| 65 | 65 |
} |
| 66 | 66 |
// If empty it simply means no macvlan networks have been created yet |
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"sync" |
| 7 | 7 |
|
| 8 | 8 |
log "github.com/Sirupsen/logrus" |
| 9 |
+ "github.com/docker/libkv/store/boltdb" |
|
| 9 | 10 |
"github.com/docker/libnetwork/bitseq" |
| 10 | 11 |
"github.com/docker/libnetwork/datastore" |
| 11 | 12 |
"github.com/docker/libnetwork/discoverapi" |
| ... | ... |
@@ -25,6 +26,10 @@ const ( |
| 25 | 25 |
dsDataKey = "ipam/" + ipamapi.DefaultIPAM + "/data" |
| 26 | 26 |
) |
| 27 | 27 |
|
| 28 |
+func init() {
|
|
| 29 |
+ boltdb.Register() |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 28 | 32 |
// Allocator provides per address space ipv4/ipv6 book keeping |
| 29 | 33 |
type Allocator struct {
|
| 30 | 34 |
// Predefined pools for default address spaces |
| ... | ... |
@@ -4,9 +4,20 @@ import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
|
| 6 | 6 |
log "github.com/Sirupsen/logrus" |
| 7 |
+ "github.com/docker/libkv/store/boltdb" |
|
| 8 |
+ "github.com/docker/libkv/store/consul" |
|
| 9 |
+ "github.com/docker/libkv/store/etcd" |
|
| 10 |
+ "github.com/docker/libkv/store/zookeeper" |
|
| 7 | 11 |
"github.com/docker/libnetwork/datastore" |
| 8 | 12 |
) |
| 9 | 13 |
|
| 14 |
+func registerKVStores() {
|
|
| 15 |
+ consul.Register() |
|
| 16 |
+ zookeeper.Register() |
|
| 17 |
+ etcd.Register() |
|
| 18 |
+ boltdb.Register() |
|
| 19 |
+} |
|
| 20 |
+ |
|
| 10 | 21 |
func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
|
| 11 | 22 |
store, err := datastore.NewDataStore(scope, scfg) |
| 12 | 23 |
if err != nil {
|
| ... | ... |
@@ -20,6 +31,8 @@ func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) err |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
func (c *controller) initStores() error {
|
| 23 |
+ registerKVStores() |
|
| 24 |
+ |
|
| 23 | 25 |
c.Lock() |
| 24 | 26 |
if c.cfg == nil {
|
| 25 | 27 |
c.Unlock() |