Documentation ¶
Overview ¶
Key Value Service using Raft Module - Client
Key Value Service using Raft Module - Types and Constants ¶
Key Value Service using Raft Module - Configuration ¶
Key Value Service using Raft Module
Index ¶
Constants ¶
const Debug = 0
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Err ¶
type Err string
const ( OK Err = "OK" // client request was replicated, no errors to report! ErrNoKey Err = "ErrNoKey" // no key exists within our key value store ErrWrongLeader Err = "ErrWrongLeader" // a client amde a request to the server that's not the elader ErrStaleRequest Err = "ErrStaleRequest" // a server has already serviced a request with the same or lower request ID. This can arise as a result of handling concurrent requests, failure recovery etc. ErrTimedOut Err = "ErrTimedOut" // the Raft module could not replicate the request within the window of time )
type KVOperation ¶
type KVOperation string
const ( PUT KVOperation = "PUT" APPEND KVOperation = "APPEND" GET KVOperation = "GET" )
type KVServer ¶
type KVServer struct {
// contains filtered or unexported fields
}
The Key Value Service.
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 ¶
Get() fetches the current value for a particular key. A Get() request on a non-existent key returns an empty string.
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)
Append() to a non-existant key acts as a Put() operation, otherwise, Append() appends to the current value of the key.
type Operation ¶
type Operation struct { Key string Value string Name KVOperation ClientID int64 RequestID int }
Operation that Raft replicates.
type PutAppendArgs ¶
type PutAppendArgs struct { Key string Value string Name KVOperation // "Put" or "Append" RequestID int ClientID int64 }
type PutAppendReply ¶
type PutAppendReply struct {
Err Err
}
type ReplicationResult ¶
type ReplicationResult struct { OK bool // signals that the operation was successfully replicated Err Err // if there were any complications with replicating the result, we specify the error RequestID int // the replicated operation has a corresponding request ID, we use this ID to mark the latest seen ID ClientID int64 // each replicated operation has a corresponding client ID. We keep track of the latest request made by a client Value string // represents the value of replicated GET operation }
We send and recieve on channels waiting for the result of replicating an operation. Replication Result is the object that contains result of replicating an operation.