kvraft

package
v0.0.0-...-c1472f6 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NO_RAFT_LEADER = -1
	OpInterval     = 100 * time.Millisecond
)
View Source
const (
	OK             = "OK"
	ErrNoKey       = "ErrNoKey"
	ErrDupCommand  = "ErrDupCommand"
	ErrStaleLeader = "ErrStaleLeader"
	ErrWrongLeader = "ErrWrongLeader"
	GetOp          = "GET"
	PutOp          = "Put"
	AppendOp       = "Append"
)

Variables

View Source
var (
	NANO_TO_MILLI = int64(1000000)

	Black   = Color("\033[1;30m%s\033[0m")
	Red     = Color("\033[1;31m%s\033[0m")
	Blue    = Color("\033[0;31m%s\033[0m")
	Green   = Color("\033[1;32m%s\033[0m")
	Yellow  = Color("\033[1;33m%s\033[0m")
	Purple  = Color("\033[1;34m%s\033[0m")
	Magenta = Color("\033[1;35m%s\033[0m")
	Teal    = Color("\033[1;36m%s\033[0m")
	White   = Color("\033[1;37m%s\033[0m")
)

Functions

func Append

func Append(cfg *config, ck *Clerk, key string, value string)

func Color

func Color(colorString string) func(...interface{}) string

func Dlog

func Dlog(format string, a ...interface{}) (n int, err error)

func GenericTest

func GenericTest(t *testing.T, part string, nclients int, unreliable bool, crash bool, partitions bool, maxraftstate int)

Basic test is as follows: one or more clients submitting Append/Get operations to set of servers for some period of time. After the period is over, test checks that all appended values are present and in order for a particular key. If unreliable is set, RPCs may fail. If crash is set, the servers crash after the period is over and restart. If partitions is set, the test repartitions the network concurrently with the clients and servers. If maxraftstate is a positive number, the size of the state for Raft (i.e., log size) shouldn't exceed 8*maxraftstate. If maxraftstate is negative, snapshots shouldn't be used.

func GenericTestLinearizability

func GenericTestLinearizability(t *testing.T, part string, nclients int, nservers int, unreliable bool, crash bool, partitions bool, maxraftstate int)

similar to GenericTest, but with clients doing random operations (and using a linearizability checker)

func Get

func Get(cfg *config, ck *Clerk, key string) string

get/put/putappend that keep counts

func MicroSecondNow

func MicroSecondNow() int64

func NextValue

func NextValue(prev string, val string) string

predict effect of Append(k, val) if old value is prev.

func Put

func Put(cfg *config, ck *Clerk, key string, value string)

Types

type Clerk

type Clerk struct {
	ID           int
	SerialNumber int64

	RaftLeaderID int
	// contains filtered or unexported fields
}

func MakeClerk

func MakeClerk(servers []*labrpc.ClientEnd) *Clerk

func (*Clerk) Append

func (ck *Clerk) Append(key string, value string)

func (*Clerk) Get

func (ck *Clerk) Get(key string) string

fetch the current value for a key. returns "" if the key does not exist. keeps trying forever in the face of all other errors.

you can send an RPC with code like this: ok := ck.servers[i].Call("KVServer.Get", &args, &reply)

the types of args and reply (including whether they are pointers) must match the declared types of the RPC handler function's arguments. and reply must be passed as a pointer.

args *GetArgs, reply *GetReply

func (*Clerk) Put

func (ck *Clerk) Put(key string, value string)

func (*Clerk) PutAppend

func (ck *Clerk) PutAppend(key string, value string, op string)

shared by Put and Append.

you can send an RPC with code like this: ok := ck.servers[i].Call("KVServer.PutAppend", &args, &reply)

the types of args and reply (including whether they are pointers) must match the declared types of the RPC handler function's arguments. and reply must be passed as a pointer.

type Err

type Err string

type GetArgs

type GetArgs struct {
	Key          string
	ClientID     int
	SerialNumber int64
}

type GetReply

type GetReply struct {
	Err   Err
	Value string
}

type KVServer

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

func StartKVServer

func StartKVServer(servers []*labrpc.ClientEnd, me int, persister *raft.Persister, maxraftstate int) *KVServer

servers[] contains the ports of the set of servers that will cooperate via Raft to form the fault-tolerant key/value service. me is the index of the current server in servers[]. the k/v server should store snapshots through the underlying Raft implementation, which should call persister.SaveStateAndSnapshot() to atomically save the Raft state along with the snapshot. the k/v server should snapshot when Raft's saved state exceeds maxraftstate bytes, in order to allow Raft to garbage-collect its log. if maxraftstate is -1, you don't need to snapshot. StartKVServer() must return quickly, so it should start goroutines for any long-running work.

func (*KVServer) Get

func (kv *KVServer) Get(args *GetArgs, reply *GetReply)

func (*KVServer) Kill

func (kv *KVServer) Kill()

the tester calls Kill() when a KVServer instance won't be needed again. you are not required to do anything in Kill(), but it might be convenient to (for example) turn off debug output from this instance.

func (*KVServer) Killed

func (kv *KVServer) Killed() bool

func (*KVServer) Persiste

func (kv *KVServer) Persiste()

func (*KVServer) PutAppend

func (kv *KVServer) PutAppend(args *PutAppendArgs, reply *PutAppendReply)

type Op

type Op struct {
	// Your definitions here.
	// Field names must start with capital letters,
	// otherwise RPC will break.
	OpType       string
	Value        string
	Key          string
	SerialNumber int64
	ClientID     int
}

type PutAppendArgs

type PutAppendArgs struct {
	Key          string
	Value        string
	Op           string // "Put" or "Append"
	SerialNumber int64
	ClientID     int
}

Put or Append

type PutAppendReply

type PutAppendReply struct {
	Err Err
}

type Record

type Record struct {
	Err   Err
	Value string
}

Jump to

Keyboard shortcuts

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