Documentation ¶
Index ¶
- Variables
- type KeyValueStore
- func (kv *KeyValueStore) Apply(operation *raft.Operation) interface{}
- func (kv *KeyValueStore) Get(key string) string
- func (kv *KeyValueStore) NeedSnapshot(logSize int) bool
- func (kv *KeyValueStore) Put(key string, value string) string
- func (kv *KeyValueStore) Restore(snapshotReader io.Reader) error
- func (kv *KeyValueStore) Snapshot(snapshotWriter io.Writer) error
- type Server
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotLeader is returned by a server when an operation is // submitted to it but it is not the leader. The client should // try submitting the operation to a different server. ErrNotLeader = status.Error( codes.FailedPrecondition, "keyValueServer: this node is not the leader", ) // ErrTimeout is returned when a submitted operation times out. // This typically occurs if there are network partitions. The // client should try submitting the operation to a different server. ErrTimeout = status.Error( codes.Unavailable, "keyValueServer: the submitted operation timed out", ) )
Functions ¶
This section is empty.
Types ¶
type KeyValueStore ¶
type KeyValueStore struct {
// contains filtered or unexported fields
}
KeyValueStore is a data structure that stores key-value pairs.
func NewKeyValueStore ¶
func NewKeyValueStore() *KeyValueStore
NewKeyValueStore creates a new instance of a key-value store.
func (*KeyValueStore) Apply ¶
func (kv *KeyValueStore) Apply(operation *raft.Operation) interface{}
Apply applies an operation to the key-value store.
func (*KeyValueStore) Get ¶
func (kv *KeyValueStore) Get(key string) string
Get returns the value of a key. If the key does not exist, an empty string is returned.
func (*KeyValueStore) NeedSnapshot ¶
func (kv *KeyValueStore) NeedSnapshot(logSize int) bool
NeedSnapshot returns true if a snapshot should be taken of the key-value store and false otherwise.
func (*KeyValueStore) Put ¶
func (kv *KeyValueStore) Put(key string, value string) string
Put sets the value of a key and returns the value it was set to.
type Server ¶
type Server struct { pb.UnimplementedKeyValueServer // contains filtered or unexported fields }
Server is a simple key-value server that is replicated using raft.
func NewServer ¶
NewServer creates a new Server instance with the provided ID, address, and raft node.
Click to show internal directories.
Click to hide internal directories.