Просмотр исходного кода

Return store.ErrKeyExists on AtomicPut

When using AtomicPut with 'previous' set at nil, it interprets
that the Key should be created with the AtomicPut. Instead of
returning a generic error, we return store.ErrKeyExists if the
key exists in the store during the operation.

Signed-off-by: Alexandre Beslic <abronan@docker.com>
Alexandre Beslic 9 лет назад
Родитель
Сommit
dcf8828165

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

@@ -381,7 +381,7 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair, opt
 		// doesn't exist in the DB.
 		val = bucket.Get([]byte(key))
 		if previous == nil && len(val) != 0 {
-			return store.ErrKeyModified
+			return store.ErrKeyExists
 		}
 		if previous != nil {
 			if len(val) == 0 {

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

@@ -35,6 +35,8 @@ var (
 	ErrKeyNotFound = errors.New("Key not found in store")
 	// ErrPreviousNotSpecified is thrown when the previous value is not specified for an atomic operation
 	ErrPreviousNotSpecified = errors.New("Previous K/V pair should be provided for the Atomic operation")
+	// ErrKeyExists is thrown when the previous value exists in the case of an AtomicPut
+	ErrKeyExists = errors.New("Previous K/V pair exists, cannnot complete Atomic operation")
 )
 
 // Config contains the options for a storage client