github.com/moby/docker@v26.1.3+incompatible/libnetwork/internal/kvstore/kvstore.go (about) 1 package kvstore 2 3 import ( 4 "errors" 5 "time" 6 ) 7 8 // Backend represents a KV Store Backend 9 type Backend string 10 11 // BOLTDB backend 12 const BOLTDB Backend = "boltdb" 13 14 var ( 15 // ErrBackendNotSupported is thrown when the backend k/v store is not supported by libkv 16 ErrBackendNotSupported = errors.New("Backend storage not supported yet, please choose one of") 17 // ErrKeyModified is thrown during an atomic operation if the index does not match the one in the store 18 ErrKeyModified = errors.New("Unable to complete atomic operation, key modified") 19 // ErrKeyNotFound is thrown when the key is not found in the store during a Get operation 20 ErrKeyNotFound = errors.New("Key not found in store") 21 // ErrPreviousNotSpecified is thrown when the previous value is not specified for an atomic operation 22 ErrPreviousNotSpecified = errors.New("Previous K/V pair should be provided for the Atomic operation") 23 // ErrKeyExists is thrown when the previous value exists in the case of an AtomicPut 24 ErrKeyExists = errors.New("Previous K/V pair exists, cannot complete Atomic operation") 25 ) 26 27 // Config contains the options for a storage client 28 type Config struct { 29 ConnectionTimeout time.Duration 30 Bucket string 31 } 32 33 // Store represents the backend K/V storage 34 // Each store should support every call listed 35 // here. Or it couldn't be implemented as a K/V 36 // backend for libkv 37 type Store interface { 38 // Put a value at the specified key 39 Put(key string, value []byte) error 40 41 // Exists verifies if a Key exists in the store. 42 Exists(key string) (bool, error) 43 44 // List the content of a given prefix 45 List(directory string) ([]*KVPair, error) 46 47 // AtomicPut performs an atomic CAS operation on a single value. 48 // Pass previous = nil to create a new key. 49 AtomicPut(key string, value []byte, previous *KVPair) (*KVPair, error) 50 51 // AtomicDelete performs an atomic delete of a single value. 52 AtomicDelete(key string, previous *KVPair) error 53 54 // Delete deletes a value at "key". Unlike AtomicDelete it doesn't check 55 // whether the deleted key is at a specific version before deleting. 56 Delete(key string) error 57 58 // Close the store connection 59 Close() 60 } 61 62 // KVPair represents {Key, Value, Lastindex} tuple 63 type KVPair struct { 64 Key string 65 Value []byte 66 LastIndex uint64 67 }