kv

package module
v0.0.0-...-3ca32f1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 29 Imported by: 0

README

R-KV

A simple raft-based replicated in-memory key-value store

Documentation

Index

Constants

View Source
const (
	FOLLOWER  = "FOLLOWER"
	CANDIDATE = "CANDIDATE"
	LEADER    = "LEADER"
)
View Source
const Amp = 20
View Source
const BATCH_TIMEOUT = 10
View Source
const CHANNEL_BUFFER_SIZE = 100000

const CHANNEL_BUFFER_SIZE = 100

View Source
const LOG_FILE_TEMPLATE = "raftlogs"
View Source
const MAX_ELECTION_TIMEOUT = 300 * Amp
View Source
const MIN_ELECTION_TIMEOUT = 150 * Amp

Election timeouts in milliseconds

View Source
const NIL_PEER = -1
View Source
const NON_EXISTENT_KEY_MSG = "key does not exist."
View Source
const NOT_LEADER = "Server is not a leader."
View Source
const REQUEST_TERMINATED = "Request was terminated."
View Source
const RPC_TIMEOUT = 10 * time.Second * Amp
View Source
const SIMULATED_PARTITION = "Simulated Partition"
View Source
const UNAVAILABLE_READ_LEASE = "Leader read lease is unavailable"
View Source
const VOTE_FILE_TEMPLATE = "raftvotes"

Variables

This section is empty.

Functions

func BenchEntryPoint

func BenchEntryPoint()

func ClientEntryPoint

func ClientEntryPoint()

func Debugf

func Debugf(format string, args ...any)

func Infof

func Infof(format string, args ...any)

func ResetTimer

func ResetTimer(timer *time.Timer, timeout time.Duration)

func ServerEntryPoint

func ServerEntryPoint()

func SimpleServerEntryPoint

func SimpleServerEntryPoint()

func Use

func Use(args ...any)

Handle irritating unused variable warnings.

Types

type CommittedOperation

type CommittedOperation struct {
	Operation *pb.Operation
	Index     int32
}

type Config

type Config struct {
	Peers       map[int32]string `json:"peers"`
	Partitioned bool
}

func GetConfig

func GetConfig() Config

type Empty

type Empty struct{}

type KVResult

type KVResult struct {
	Value string
	Err   error
}

type KVStore

type KVStore struct {
	// contains filtered or unexported fields
}

func NewKVStore

func NewKVStore() *KVStore

func (*KVStore) Delete

func (kv *KVStore) Delete(key string) error

func (*KVStore) Get

func (kv *KVStore) Get(key string) (string, error)

func (*KVStore) Set

func (kv *KVStore) Set(key, value string)

type PeerId

type PeerId = int32

type PendingOperation

type PendingOperation struct {
	// contains filtered or unexported fields
}

type Persistence

type Persistence struct {
	StoredVote     *pb.StoredVote
	StoredLogs     *pb.StoredLog
	InitialLogSize int
	StartTime      time.Time
}

func (*Persistence) AppendLog

func (p *Persistence) AppendLog(filename string, logs []*pb.LogEntry)

func (*Persistence) ReadLog

func (p *Persistence) ReadLog(filename string) (*pb.StoredLog, error)

func (*Persistence) ReadVote

func (p *Persistence) ReadVote(filename string) (*pb.StoredVote, error)

func (*Persistence) WriteLog

func (p *Persistence) WriteLog(filename string)

func (*Persistence) WriteLogToHandle

func (p *Persistence) WriteLogToHandle(file *os.File, logs []*pb.LogEntry) int

func (*Persistence) WriteVote

func (p *Persistence) WriteVote(filename string)

type Raft

type Raft struct {
	// contains filtered or unexported fields
}

func NewRaft

func NewRaft(addr PeerId, peers map[PeerId]Empty, rpcHandler RpcServer) *Raft

func (*Raft) Debug

func (r *Raft) Debug(msg string, args ...any)

func (*Raft) Info

func (r *Raft) Info(msg string, args ...any)

type RaftRpcServer

type RaftRpcServer struct {
	pb.UnimplementedRaftRpcServer
	// contains filtered or unexported fields
}

func NewRaftRpcServer

func NewRaftRpcServer(id PeerId, config *Config) *RaftRpcServer

func (*RaftRpcServer) AppendEntries

func (*RaftRpcServer) ClearPendingOp

func (rs *RaftRpcServer) ClearPendingOp(opId string)

func (*RaftRpcServer) Delete

func (rs *RaftRpcServer) Delete(ctx context.Context, key *pb.Key) (*pb.Response, error)

func (*RaftRpcServer) FastGet

func (rs *RaftRpcServer) FastGet(ctx context.Context, key *pb.Key) (*pb.Response, error)

func (*RaftRpcServer) Get

func (rs *RaftRpcServer) Get(ctx context.Context, key *pb.Key) (*pb.Response, error)

func (*RaftRpcServer) GetClient

func (rs *RaftRpcServer) GetClient(peerId PeerId) pb.RaftRpcClient

func (*RaftRpcServer) InitPendingOp

func (rs *RaftRpcServer) InitPendingOp(opId string)

func (*RaftRpcServer) Partition

func (rs *RaftRpcServer) Partition(ctx context.Context, in *wrappers.BoolValue) (*empty.Empty, error)

func (*RaftRpcServer) RequestVote

func (*RaftRpcServer) Set

func (rs *RaftRpcServer) Set(ctx context.Context, kvp *pb.KeyValuePair) (*pb.Response, error)

type RpcCommand

type RpcCommand struct {
	Command any
	// contains filtered or unexported fields
}

type RpcServer

type RpcServer interface {
	GetClient(peerId PeerId) pb.RaftRpcClient
}

type SimpleClient

type SimpleClient struct {
	// contains filtered or unexported fields
}

func NewSimpleClient

func NewSimpleClient() *SimpleClient

type SimpleKVRpcServer

type SimpleKVRpcServer struct {
	pb.UnimplementedRaftRpcServer
	// contains filtered or unexported fields
}

func NewKVRpcServer

func NewKVRpcServer() *SimpleKVRpcServer

func (*SimpleKVRpcServer) Delete

func (kvs *SimpleKVRpcServer) Delete(c context.Context, key *pb.Key) (*pb.Response, error)

Return true if key existed previously and was removed, else return false.

func (*SimpleKVRpcServer) Get

func (kvs *SimpleKVRpcServer) Get(c context.Context, key *pb.Key) (*pb.Response, error)

func (*SimpleKVRpcServer) Set

func (kvs *SimpleKVRpcServer) Set(c context.Context, keyValue *pb.KeyValuePair) (*pb.Response, error)

type TestClient

type TestClient struct {
	LeaderId int
	Clients  map[int32]pb.RaftRpcClient
	Config   *Config
	// contains filtered or unexported fields
}

func NewTestClient

func NewTestClient() *TestClient

func (*TestClient) HandleDelete

func (c *TestClient) HandleDelete(arguments string, partitionedIds []int)

func (*TestClient) HandleGet

func (c *TestClient) HandleGet(keystr string, skipQuorum bool, partitionedIds []int, isPartitionedServer bool)

func (*TestClient) HandleSet

func (c *TestClient) HandleSet(arguments string, partitionedIds []int, isPartitionedServer bool)

type Vote

type Vote struct {
	CurrentTerm int32
	VotedFor    PeerId
}

Jump to

Keyboard shortcuts

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