libnetwork/internal/kvstore: AtomicPut(): remove unused "created" return

This boolean was not used anywhere, so we can remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-02 19:47:03 +02:00
parent c37b58bbc3
commit b576682bdc
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 13 additions and 21 deletions

View file

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

View file

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

View file

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

View file

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