libnetwork: remove most of kvstore

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-21 15:02:48 +02:00
parent e4134d5c0d
commit 37cbdeb1f2
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
5 changed files with 9 additions and 74 deletions

View file

@ -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 kv != string(store.BOLTDB) {
return nil, fmt.Errorf("unsupported KV store")
}
if config == nil {
config = &store.Config{}
}
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...)
}
}
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

View file

@ -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

View file

@ -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 {

View file

@ -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
}

View file

@ -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()