Browse Source

libnetwork: remove most of kvstore

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 năm trước cách đây
mục cha
commit
37cbdeb1f2

+ 9 - 19
libnetwork/datastore/datastore.go

@@ -8,6 +8,7 @@ import (
 
 	"github.com/docker/docker/libnetwork/discoverapi"
 	store "github.com/docker/docker/libnetwork/internal/kvstore"
+	"github.com/docker/docker/libnetwork/internal/kvstore/boltdb"
 	"github.com/docker/docker/libnetwork/types"
 )
 
@@ -138,27 +139,16 @@ func Key(key ...string) string {
 
 // newClient used to connect to KV Store
 func newClient(kv string, addr string, config *store.Config) (*Store, error) {
-	if config == nil {
-		config = &store.Config{}
+	if kv != string(store.BOLTDB) {
+		return nil, fmt.Errorf("unsupported KV store")
 	}
 
-	var addrs []string
-
-	if kv == string(store.BOLTDB) {
-		// Parse file path
-		addrs = strings.Split(addr, ",")
-	} else {
-		// Parse URI
-		parts := strings.SplitN(addr, "/", 2)
-		addrs = strings.Split(parts[0], ",")
-
-		// Add the custom prefix to the root chain
-		if len(parts) == 2 {
-			rootChain = append([]string{parts[1]}, defaultRootChain...)
-		}
+	if config == nil {
+		config = &store.Config{}
 	}
 
-	s, err := store.New(store.Backend(kv), addrs, config)
+	// Parse file path
+	s, err := boltdb.New(strings.Split(addr, ","), config)
 	if err != nil {
 		return nil, err
 	}
@@ -390,7 +380,7 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error {
 	previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()}
 
 	if kvObject.Skip() {
-		goto del_cache
+		goto deleteCache
 	}
 
 	if err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
@@ -400,7 +390,7 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error {
 		return err
 	}
 
-del_cache:
+deleteCache:
 	// cleanup the cache only if AtomicDelete went through successfully
 	if ds.cache != nil {
 		// If persistent store is skipped, sequencing needs to

+ 0 - 5
libnetwork/drivers/overlay/overlay_test.go

@@ -6,14 +6,9 @@ import (
 	"testing"
 
 	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/internal/kvstore/boltdb"
 	"github.com/docker/docker/pkg/plugingetter"
 )
 
-func init() {
-	boltdb.Register()
-}
-
 type driverTester struct {
 	t *testing.T
 	d *driver

+ 0 - 5
libnetwork/internal/kvstore/boltdb/boltdb.go

@@ -45,11 +45,6 @@ const (
 	transientTimeout = time.Duration(10) * time.Second
 )
 
-// Register registers boltdb to libkv
-func Register() {
-	store.AddStore(store.BOLTDB, New)
-}
-
 // New opens a new BoltDB connection to the specified path and bucket
 func New(endpoints []string, options *store.Config) (store.Store, error) {
 	if len(endpoints) > 1 {

+ 0 - 38
libnetwork/internal/kvstore/kvstore_manage.go

@@ -1,38 +0,0 @@
-package kvstore
-
-import (
-	"fmt"
-	"sort"
-	"strings"
-)
-
-// Initialize creates a new Store object, initializing the client
-type Initialize func(addrs []string, options *Config) (Store, error)
-
-var (
-	// Backend initializers
-	initializers = make(map[Backend]Initialize)
-
-	supportedBackend = func() string {
-		keys := make([]string, 0, len(initializers))
-		for k := range initializers {
-			keys = append(keys, string(k))
-		}
-		sort.Strings(keys)
-		return strings.Join(keys, ", ")
-	}()
-)
-
-// New creates an instance of store
-func New(backend Backend, addrs []string, options *Config) (Store, error) {
-	if init, exists := initializers[backend]; exists {
-		return init(addrs, options)
-	}
-
-	return nil, fmt.Errorf("%s %s", ErrBackendNotSupported.Error(), supportedBackend)
-}
-
-// AddStore adds a new store backend to libkv
-func AddStore(store Backend, init Initialize) {
-	initializers[store] = init
-}

+ 0 - 7
libnetwork/store.go

@@ -7,16 +7,9 @@ import (
 
 	"github.com/containerd/containerd/log"
 	"github.com/docker/docker/libnetwork/datastore"
-	"github.com/docker/docker/libnetwork/internal/kvstore/boltdb"
 )
 
-func registerKVStores() {
-	boltdb.Register()
-}
-
 func (c *Controller) initStores() error {
-	registerKVStores()
-
 	c.mu.Lock()
 	defer c.mu.Unlock()