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>
This commit is contained in:
parent
99db1f6a07
commit
dcf8828165
2 changed files with 3 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue