Browse Source

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>
Sebastiaan van Stijn 2 years ago
parent
commit
acfd3934a7

+ 1 - 1
libnetwork/datastore/datastore.go

@@ -590,7 +590,7 @@ func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
 		goto del_cache
 		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 {
 		if err == store.ErrKeyExists {
 			return ErrKeyModified
 			return ErrKeyModified
 		}
 		}

+ 3 - 3
libnetwork/datastore/mock_store.go

@@ -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
 // AtomicDelete deletes a value at "key" if the key has not
 // been modified in the meantime, throws an error if this is the case
 // 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]
 	mData := s.db[key]
 	if mData != nil && mData.Index != previous.LastIndex {
 	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
 // Close closes the client connection

+ 8 - 17
libnetwork/internal/kvstore/boltdb/boltdb.go

@@ -308,30 +308,26 @@ func (b *BoltDB) List(keyPrefix string) ([]*store.KVPair, error) {
 // AtomicDelete deletes a value at "key" if the key
 // AtomicDelete deletes a value at "key" if the key
 // has not been modified in the meantime, throws an
 // has not been modified in the meantime, throws an
 // error if this is the case
 // 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()
 	b.Lock()
 	defer b.Unlock()
 	defer b.Unlock()
 
 
 	if previous == nil {
 	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()
 	defer b.releaseDBhandle()
 
 
-	err = db.Update(func(tx *bolt.Tx) error {
+	return db.Update(func(tx *bolt.Tx) error {
 		bucket := tx.Bucket(b.boltBucket)
 		bucket := tx.Bucket(b.boltBucket)
 		if bucket == nil {
 		if bucket == nil {
 			return store.ErrKeyNotFound
 			return store.ErrKeyNotFound
 		}
 		}
 
 
-		val = bucket.Get([]byte(key))
+		val := bucket.Get([]byte(key))
 		if val == nil {
 		if val == nil {
 			return store.ErrKeyNotFound
 			return store.ErrKeyNotFound
 		}
 		}
@@ -339,13 +335,8 @@ func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) (bool, error)
 		if dbIndex != previous.LastIndex {
 		if dbIndex != previous.LastIndex {
 			return store.ErrKeyModified
 			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
 // AtomicPut puts a value at "key" if the key has not been

+ 1 - 1
libnetwork/internal/kvstore/kvstore.go

@@ -64,7 +64,7 @@ type Store interface {
 	AtomicPut(key string, value []byte, previous *KVPair) (*KVPair, error)
 	AtomicPut(key string, value []byte, previous *KVPair) (*KVPair, error)
 
 
 	// AtomicDelete performs an atomic delete of a single value.
 	// 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 the store connection
 	Close()
 	Close()