diff --git a/src/kvsrv/client.go b/src/kvsrv/client.go index 673eedb..af8da70 100644 --- a/src/kvsrv/client.go +++ b/src/kvsrv/client.go @@ -6,6 +6,7 @@ import ( "math/big" "6.5840/labrpc" + "github.com/google/uuid" ) type Clerk struct { @@ -38,13 +39,18 @@ func MakeClerk(server *labrpc.ClientEnd) *Clerk { // must match the declared types of the RPC handler function's // arguments. and reply must be passed as a pointer. func (ck *Clerk) Get(key string) string { + id := uuid.New() args := GetArgs{ - Key: key, + Key: key, + Uuid: id, } reply := GetReply{} ok := false for !ok { ok = ck.server.Call("KVServer.Get", &args, &reply) + if !ok { + log.Println("RPC call failed: GET op") + } } // You will have to modify this function. return reply.Value @@ -60,15 +66,19 @@ func (ck *Clerk) Get(key string) string { // arguments. and reply must be passed as a pointer. func (ck *Clerk) PutAppend(key string, value string, op string) string { // You will have to modify this function. + id := uuid.New() args := PutAppendArgs{ Key: key, Value: value, + Uuid: id, } reply := PutAppendReply{} - ok := ck.server.Call("KVServer."+op, &args, &reply) - - if !ok { - log.Fatalf("RPC call failed: %s op", op) + ok := false + for !ok { + ok := ck.server.Call("KVServer."+op, &args, &reply) + if !ok { + log.Printf("RPC call failed: %s op\n", op) + } } return reply.Value diff --git a/src/kvsrv/common.go b/src/kvsrv/common.go index 8081d93..fe8cbcb 100644 --- a/src/kvsrv/common.go +++ b/src/kvsrv/common.go @@ -7,6 +7,7 @@ type PutAppendArgs struct { // You'll have to add definitions here. // Field names must start with capital letters, // otherwise RPC will break. + Uuid string } type PutAppendReply struct { @@ -16,6 +17,7 @@ type PutAppendReply struct { type GetArgs struct { Key string // You'll have to add definitions here. + Uuid string } type GetReply struct { diff --git a/src/kvsrv/server.go b/src/kvsrv/server.go index c726e83..b07e729 100644 --- a/src/kvsrv/server.go +++ b/src/kvsrv/server.go @@ -17,6 +17,7 @@ func DPrintf(format string, a ...interface{}) (n int, err error) { type KVServer struct { mu sync.Mutex KVStore map[string]string + OpLog map[string]bool // Your definitions here. }