diff --git a/libnetwork/datastore/datastore.go b/libnetwork/datastore/datastore.go index 66f05b7a1f..87b59c35f3 100644 --- a/libnetwork/datastore/datastore.go +++ b/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) + pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous) if err != nil { if err == store.ErrKeyExists { return ErrKeyModified diff --git a/libnetwork/datastore/mock_store.go b/libnetwork/datastore/mock_store.go index fa1d80130c..69746c3e4b 100644 --- a/libnetwork/datastore/mock_store.go +++ b/libnetwork/datastore/mock_store.go @@ -78,26 +78,25 @@ 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) (bool, *store.KVPair, error) { +func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair) (*store.KVPair, error) { mData := s.db[key] if previous == nil { if mData != nil { - return false, nil, types.BadRequestErrorf("atomic put failed because key exists") + return nil, types.BadRequestErrorf("atomic put failed because key exists") } // Else OK. } else { if mData == nil { - return false, nil, types.BadRequestErrorf("atomic put failed because key exists") + return nil, types.BadRequestErrorf("atomic put failed because key exists") } if mData != nil && mData.Index != previous.LastIndex { - return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index") + return nil, types.BadRequestErrorf("atomic put failed due to mismatched Index") } // Else OK. } - err := s.Put(key, newValue) - if err != nil { - return false, nil, err + if err := s.Put(key, newValue); err != nil { + return nil, err } - return true, &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil + return &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil } // AtomicDelete deletes a value at "key" if the key has not diff --git a/libnetwork/internal/kvstore/boltdb/boltdb.go b/libnetwork/internal/kvstore/boltdb/boltdb.go index d1c49fb80f..d38d2d0332 100644 --- a/libnetwork/internal/kvstore/boltdb/boltdb.go +++ b/libnetwork/internal/kvstore/boltdb/boltdb.go @@ -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) (bool, *store.KVPair, error) { +func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair) (*store.KVPair, error) { var ( val []byte dbIndex uint64 @@ -363,7 +363,7 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair) (bo dbval := make([]byte, libkvmetadatalen) if db, err = b.getDBhandle(); err != nil { - return false, nil, err + return nil, err } defer b.releaseDBhandle() @@ -400,16 +400,9 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair) (bo return (bucket.Put([]byte(key), dbval)) }) if err != nil { - return false, nil, err + return nil, err } - - updated := &store.KVPair{ - Key: key, - Value: value, - LastIndex: dbIndex, - } - - return true, updated, nil + return &store.KVPair{Key: key, Value: value, LastIndex: dbIndex}, nil } // Close the db connection to the BoltDB diff --git a/libnetwork/internal/kvstore/kvstore.go b/libnetwork/internal/kvstore/kvstore.go index 657a76f8c6..6fb4116fae 100644 --- a/libnetwork/internal/kvstore/kvstore.go +++ b/libnetwork/internal/kvstore/kvstore.go @@ -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) (bool, *KVPair, error) + AtomicPut(key string, value []byte, previous *KVPair) (*KVPair, error) // AtomicDelete performs an atomic delete of a single value. AtomicDelete(key string, previous *KVPair) (bool, error)