Documentation ¶
Overview ¶
Package tinykv provides concurrent primitive operations for a hashmap-based storage. The primitives are Put/Get/Incr/Del. They are all thread-safe and mutually exclusive with each other.
RPC interfaces for the basic operations are intended for the extended services, which could wrap the KVStore and then enhance it.
Index ¶
- type Client
- func (c *Client) Close()
- func (c *Client) Del(key string) (oldValue string, existed bool)
- func (c *Client) Get(key string) (value string, existed bool)
- func (c *Client) Incr(key string, delta int) (oldValue string, existed bool)
- func (c *Client) Put(key string, value string) (oldValue string, existed bool)
- type KVStore
- func (ks *KVStore) Del(key string) (oldValue string, existed bool)
- func (ks *KVStore) Get(key string) (value string, existed bool)
- func (ks *KVStore) Incr(key string, delta int) (newVal string, existed bool, err error)
- func (ks *KVStore) Put(key, value string) (oldValue string, existed bool)
- func (ks *KVStore) RPCDel(args *kv.DelArgs, reply *kv.Reply) (err error)
- func (ks *KVStore) RPCGet(args *kv.GetArgs, reply *kv.Reply) error
- func (ks *KVStore) RPCIncr(args *kv.IncrArgs, reply *kv.Reply) (err error)
- func (ks *KVStore) RPCPut(args *kv.PutArgs, reply *kv.Reply) error
- type KVStoreService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KVStore ¶
type KVStore struct { // RwLock is the public Read-Write Mutex, which can // be used in the extended KV-Store. RwLock sync.RWMutex // contains filtered or unexported fields }
KVStore is the hashmap-based storage.
func (*KVStore) Del ¶
Del deletes the specific key-value pair. If it exists before, the existed flag is true. Otherwise, it's false.
It's thread-safe and mutually exclusive with other operations.
func (*KVStore) Get ¶
Get the corresponding value for a specific key. If the key exists, the value is not nil and the existed flag is true. Otherwise, the value is nil and the flag is false.
It's thread-safe and mutually exclusive with other operations.
func (*KVStore) Incr ¶
Incr the corresponding value by delta for a specific key. If the key exists and its value is numeric, then return the new value, and the existed flag is true without any error. If the corresponding value is not numberic, the NumError is returned. If the key doesn't exist, the delta will be set as the value of the key, and the new value is delta, existed flag is false without any error.
It's thread-safe and mutually exclusive with other operations.
func (*KVStore) Put ¶
Put the key-value pair into the stroage and return the old value and existed flag. If the key exists before, then the flag will be true and the old value is not nil. Otherwise, the old value is nil and the existed flag is false.
It's thread-safe and mutually exclusive with other operations.
type KVStoreService ¶
type KVStoreService struct { *KVStore // contains filtered or unexported fields }
KVStoreService provides the RPC service for KVStore.
func NewKVStoreService ¶
func NewKVStoreService(network, addr string) *KVStoreService
NewKVStoreService inits a KV-Store service.
func (*KVStoreService) IsDead ¶
func (ks *KVStoreService) IsDead() bool
IsDead returns whether the KVStore service is dead or not. If dead, the RPC requests can be served until the service recovers.
func (*KVStoreService) Kill ¶
func (ks *KVStoreService) Kill()
Kill closes the kvstore service, which makes the service dead.
func (*KVStoreService) Serve ¶
func (ks *KVStoreService) Serve()
Serve starts the KVStore service to serve the RPC requests.