tinykv

package
v0.0.0-...-9789875 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SrvAddr string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(srvAddr string) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Del

func (c *Client) Del(key string) (oldValue string, existed bool)

func (*Client) Get

func (c *Client) Get(key string) (value string, existed bool)

func (*Client) Incr

func (c *Client) Incr(key string, delta int) (oldValue string, existed bool)

func (*Client) Put

func (c *Client) Put(key string, value string) (oldValue string, existed bool)

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 NewKVStore

func NewKVStore() *KVStore

NewKVStore inits a KVStore.

func (*KVStore) Del

func (ks *KVStore) Del(key string) (oldValue string, existed bool)

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

func (ks *KVStore) Get(key string) (value string, existed bool)

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

func (ks *KVStore) Incr(key string, delta int) (newVal string, existed bool, err error)

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

func (ks *KVStore) Put(key, value string) (oldValue string, existed bool)

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.

func (*KVStore) RPCDel

func (ks *KVStore) RPCDel(args *kv.DelArgs, reply *kv.Reply) (err error)

RPCDel is the RPC interface for Del operation.

func (*KVStore) RPCGet

func (ks *KVStore) RPCGet(args *kv.GetArgs, reply *kv.Reply) error

RPCGet is the RPC interface for Get operation.

func (*KVStore) RPCIncr

func (ks *KVStore) RPCIncr(args *kv.IncrArgs, reply *kv.Reply) (err error)

RPCIncr is the RPC interface for Incr operation.

func (*KVStore) RPCPut

func (ks *KVStore) RPCPut(args *kv.PutArgs, reply *kv.Reply) error

RPCPut is the RPC interface for Put operation.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL