libnetwork/internal/kvstore: AtomicDelete(): remove unused "deleted" return
This boolean was not used anywhere, so we can remove it. Also cleaning up the implementation a bit. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
b576682bdc
commit
acfd3934a7
4 changed files with 13 additions and 22 deletions
|
@ -590,7 +590,7 @@ func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
|
|||
goto del_cache
|
||||
}
|
||||
|
||||
if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
|
||||
if err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
|
||||
if err == store.ErrKeyExists {
|
||||
return ErrKeyModified
|
||||
}
|
||||
|
|
|
@ -101,12 +101,12 @@ func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPai
|
|||
|
||||
// AtomicDelete deletes 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) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
|
||||
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) error {
|
||||
mData := s.db[key]
|
||||
if mData != nil && mData.Index != previous.LastIndex {
|
||||
return false, types.BadRequestErrorf("atomic delete failed due to mismatched Index")
|
||||
return types.BadRequestErrorf("atomic delete failed due to mismatched Index")
|
||||
}
|
||||
return true, s.Delete(key)
|
||||
return s.Delete(key)
|
||||
}
|
||||
|
||||
// Close closes the client connection
|
||||
|
|
|
@ -308,30 +308,26 @@ func (b *BoltDB) List(keyPrefix string) ([]*store.KVPair, error) {
|
|||
// AtomicDelete deletes a value at "key" if the key
|
||||
// has not been modified in the meantime, throws an
|
||||
// error if this is the case
|
||||
func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
|
||||
var (
|
||||
val []byte
|
||||
db *bolt.DB
|
||||
err error
|
||||
)
|
||||
func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) error {
|
||||
b.Lock()
|
||||
defer b.Unlock()
|
||||
|
||||
if previous == nil {
|
||||
return false, store.ErrPreviousNotSpecified
|
||||
return store.ErrPreviousNotSpecified
|
||||
}
|
||||
if db, err = b.getDBhandle(); err != nil {
|
||||
return false, err
|
||||
db, err := b.getDBhandle()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer b.releaseDBhandle()
|
||||
|
||||
err = db.Update(func(tx *bolt.Tx) error {
|
||||
return db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(b.boltBucket)
|
||||
if bucket == nil {
|
||||
return store.ErrKeyNotFound
|
||||
}
|
||||
|
||||
val = bucket.Get([]byte(key))
|
||||
val := bucket.Get([]byte(key))
|
||||
if val == nil {
|
||||
return store.ErrKeyNotFound
|
||||
}
|
||||
|
@ -339,13 +335,8 @@ func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) (bool, error)
|
|||
if dbIndex != previous.LastIndex {
|
||||
return store.ErrKeyModified
|
||||
}
|
||||
err := bucket.Delete([]byte(key))
|
||||
return err
|
||||
return bucket.Delete([]byte(key))
|
||||
})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
// AtomicPut puts a value at "key" if the key has not been
|
||||
|
|
|
@ -64,7 +64,7 @@ type Store interface {
|
|||
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)
|
||||
AtomicDelete(key string, previous *KVPair) error
|
||||
|
||||
// Close the store connection
|
||||
Close()
|
||||
|
|
Loading…
Add table
Reference in a new issue