github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/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 PersistConnection bool 32 } 33 34 // Store represents the backend K/V storage 35 // Each store should support every call listed 36 // here. Or it couldn't be implemented as a K/V 37 // backend for libkv 38 type Store interface { 39 // Put a value at the specified key 40 Put(key string, value []byte) error 41 42 // Get a value given its key 43 Get(key string) (*KVPair, error) 44 45 // Exists verifies if a Key exists in the store. 46 Exists(key string) (bool, error) 47 48 // List the content of a given prefix 49 List(directory string) ([]*KVPair, error) 50 51 // AtomicPut performs an atomic CAS operation on a single value. 52 // Pass previous = nil to create a new key. 53 AtomicPut(key string, value []byte, previous *KVPair) (*KVPair, error) 54 55 // AtomicDelete performs an atomic delete of a single value. 56 AtomicDelete(key string, previous *KVPair) 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 }