Pārlūkot izejas kodu

API Change: AtomicPut with previous = nil is create.

AtomicPut can now be used to Compare-and-Swap against the state
where the key doesn't yet exist.  E.g. a race where two clients
create the same key: one succeeds, the other fails.

Pass nil for the previous argument of AtomicPut for this
behavior.  Before, this would cause an error.

Implements this change for all three backends.
Spike Curtis 10 gadi atpakaļ
vecāks
revīzija
a2d4e1c246
1 mainītis faili ar 2 papildinājumiem un 1 dzēšanām
  1. 2 1
      libnetwork/internal/kvstore/kvstore.go

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

@@ -77,7 +77,8 @@ type Store interface {
 	// DeleteTree deletes a range of keys under a given directory
 	// DeleteTree deletes a range of keys under a given directory
 	DeleteTree(directory string) error
 	DeleteTree(directory string) error
 
 
-	// Atomic operation on a single value
+	// Atomic CAS operation on a single value.
+	// Pass previous = nil to create a new key.
 	AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *KVPair, error)
 	AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *KVPair, error)
 
 
 	// Atomic delete of a single value
 	// Atomic delete of a single value