kvraft

package
v0.0.0-...-d482dbc Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK             = "OK"
	ErrNoKey       = "ErrNoKey"
	ErrWrongLeader = "ErrWrongLeader"
)
View Source
const (
	GET    = "Get"
	PUT    = "Put"
	APPEND = "Append"
)
View Source
const (
	TIMEOUT = 100 // if the raft donot response the request in 1000 ms, we think it is
)

Variables

This section is empty.

Functions

func Debug

func Debug(topic logTopic, format string, a ...interface{})

func DebugReceiveGet

func DebugReceiveGet(kv *KVServer, args *GetArgs)

func DebugReceivePutAppend

func DebugReceivePutAppend(kv *KVServer, args *PutAppendArgs)

func DebugReplyGet

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

func DebugReplyPutAppend

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

Types

type Clerk

type Clerk struct {
	// 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.

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
	// You'll have to add definitions here.
	ClientId  int64
	ClientSeq uint64
}

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) DeSerilizeState

func (kv *KVServer) DeSerilizeState(snapshot []byte)

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. for your convenience, we supply code to set rf.dead (without needing a lock), and a killed() method to test rf.dead in long-running loops. you can also add your own code to Kill(). you're not required to do anything about this, but it may be convenient (for example) to suppress debug output from a Kill()ed instance.

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.
	Type      string
	Key       string
	Value     string
	ClientId  int64
	ClientSeq uint64
	ServerId  int
	ServerSeq int64
}

type OpResult

type OpResult struct {
	Error Err
	Value string
}

type PutAppendArgs

type PutAppendArgs struct {
	Key   string
	Value string
	Op    string // "Put" or "Append"
	// You'll have to add definitions here.
	// Field names must start with capital letters,
	// otherwise RPC will break.
	ClientId  int64
	ClientSeq uint64
}

Put or Append

type PutAppendReply

type PutAppendReply struct {
	Err Err
}

Jump to

Keyboard shortcuts

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