Переглянути джерело

libnetwork/internal/kvstore: remove unused WriteOptions

The WriteOptions struct was only used to set the "IsDir" option. This option
was added in https://github.com/docker/libkv/commit/d635a8e32b67f1ac511b7fcc15d524dedb9f549b
and was only supported by the etcd libkv store.

The BoltDB store does not support this option, making the WriteOptions
struct fully redundant.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 роки тому
батько
коміт
c37b58bbc3

+ 3 - 3
libnetwork/datastore/datastore.go

@@ -382,7 +382,7 @@ func (ds *datastore) PutObjectAtomic(kvObject KVObject) error {
 		previous = nil
 	}
 
-	_, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil)
+	_, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous)
 	if err != nil {
 		if err == store.ErrKeyExists {
 			return ErrKeyModified
@@ -437,7 +437,7 @@ func (ds *datastore) putObjectWithKey(kvObject KVObject, key ...string) error {
 	if kvObjValue == nil {
 		return types.BadRequestErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...))
 	}
-	return ds.store.Put(Key(key...), kvObjValue, nil)
+	return ds.store.Put(Key(key...), kvObjValue)
 }
 
 // GetObject returns a record matching the key
@@ -474,7 +474,7 @@ func (ds *datastore) ensureParent(parent string) error {
 	if exists {
 		return nil
 	}
-	return ds.store.Put(parent, []byte{}, &store.WriteOptions{IsDir: true})
+	return ds.store.Put(parent, []byte{})
 }
 
 func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {

+ 3 - 3
libnetwork/datastore/mock_store.go

@@ -38,7 +38,7 @@ func (s *MockStore) Get(key string) (*store.KVPair, error) {
 }
 
 // Put a value at "key"
-func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error {
+func (s *MockStore) Put(key string, value []byte) error {
 	mData := s.db[key]
 	if mData == nil {
 		mData = &MockData{value, 0}
@@ -78,7 +78,7 @@ func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVP
 
 // AtomicPut put a value at "key" if the key has not been
 // modified in the meantime, throws an error if this is the case
-func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
+func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair) (bool, *store.KVPair, error) {
 	mData := s.db[key]
 
 	if previous == nil {
@@ -93,7 +93,7 @@ func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPai
 			return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
 		} // Else OK.
 	}
-	err := s.Put(key, newValue, nil)
+	err := s.Put(key, newValue)
 	if err != nil {
 		return false, nil, err
 	}

+ 2 - 2
libnetwork/internal/kvstore/boltdb/boltdb.go

@@ -167,7 +167,7 @@ func (b *BoltDB) Get(key string) (*store.KVPair, error) {
 }
 
 // Put the key, value pair. index number metadata is prepended to the value
-func (b *BoltDB) Put(key string, value []byte, opts *store.WriteOptions) error {
+func (b *BoltDB) Put(key string, value []byte) error {
 	var (
 		dbIndex uint64
 		db      *bolt.DB
@@ -350,7 +350,7 @@ func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) (bool, error)
 
 // AtomicPut puts a value at "key" if the key has not been
 // modified since the last Put, throws an error if this is the case
-func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
+func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair) (bool, *store.KVPair, error) {
 	var (
 		val     []byte
 		dbIndex uint64

+ 2 - 8
libnetwork/internal/kvstore/kvstore.go

@@ -39,7 +39,7 @@ type Config struct {
 // backend for libkv
 type Store interface {
 	// Put a value at the specified key
-	Put(key string, value []byte, options *WriteOptions) error
+	Put(key string, value []byte) error
 
 	// Get a value given its key
 	Get(key string) (*KVPair, error)
@@ -61,7 +61,7 @@ type Store interface {
 
 	// AtomicPut performs an atomic CAS operation on a single value.
 	// Pass previous = nil to create a new key.
-	AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *KVPair, error)
+	AtomicPut(key string, value []byte, previous *KVPair) (bool, *KVPair, error)
 
 	// AtomicDelete performs an atomic delete of a single value.
 	AtomicDelete(key string, previous *KVPair) (bool, error)
@@ -76,9 +76,3 @@ type KVPair struct {
 	Value     []byte
 	LastIndex uint64
 }
-
-// WriteOptions contains optional request parameters
-type WriteOptions struct {
-	IsDir bool
-	TTL   time.Duration
-}