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