Documentation ¶
Index ¶
- Constants
- Variables
- func Append(cfg *config, ck *Clerk, key string, value string)
- func Color(colorString string) func(...interface{}) string
- func Dlog(format string, a ...interface{}) (n int, err error)
- func GenericTest(t *testing.T, part string, nclients int, unreliable bool, crash bool, ...)
- func GenericTestLinearizability(t *testing.T, part string, nclients int, nservers int, unreliable bool, ...)
- func Get(cfg *config, ck *Clerk, key string) string
- func MicroSecondNow() int64
- func NextValue(prev string, val string) string
- func Put(cfg *config, ck *Clerk, key string, value string)
- type Clerk
- type Err
- type GetArgs
- type GetReply
- type KVServer
- type Op
- type PutAppendArgs
- type PutAppendReply
- type Record
Constants ¶
const ( NO_RAFT_LEADER = -1 OpInterval = 100 * time.Millisecond )
const ( OK = "OK" ErrNoKey = "ErrNoKey" ErrDupCommand = "ErrDupCommand" ErrStaleLeader = "ErrStaleLeader" ErrWrongLeader = "ErrWrongLeader" GetOp = "GET" PutOp = "Put" AppendOp = "Append" )
Variables ¶
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 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 MicroSecondNow ¶
func MicroSecondNow() int64
Types ¶
type Clerk ¶
type Clerk struct { ID int SerialNumber int64 RaftLeaderID int // contains filtered or unexported fields }
func (*Clerk) Get ¶
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) PutAppend ¶
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 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) 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) PutAppend ¶
func (kv *KVServer) PutAppend(args *PutAppendArgs, reply *PutAppendReply)
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
}