diff --git a/src/kvraft1/client.go b/src/kvraft1/client.go index 0159fae..2c4fb45 100644 --- a/src/kvraft1/client.go +++ b/src/kvraft1/client.go @@ -19,12 +19,39 @@ func MakeClerk(clnt *tester.Clnt, servers []string) kvtest.IKVClerk { return ck } +// Get fetches the current value and version for a key. It returns +// ErrNoKey if the key does not exist. It keeps trying forever in the +// face of all other errors. +// +// You can send an RPC to server i with code like this: +// ok := ck.clnt.Call(ck.servers[i], "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. Additionally, reply must be passed as a pointer. func (ck *Clerk) Get(key string) (string, rpc.Tversion, rpc.Err) { // You will have to modify this function. return "", 0, "" } +// Put updates key with value only if the version in the +// request matches the version of the key at the server. If the +// versions numbers don't match, the server should return +// ErrVersion. If Put receives an ErrVersion on its first RPC, Put +// should return ErrVersion, since the Put was definitely not +// performed at the server. If the server returns ErrVersion on a +// resend RPC, then Put must return ErrMaybe to the application, since +// its earlier RPC might have been processed by the server successfully +// but the response was lost, and the the Clerk doesn't know if +// the Put was performed or not. +// +// You can send an RPC to server i with code like this: +// ok := ck.clnt.Call(ck.servers[i], "KVServer.Put", &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. Additionally, reply must be passed as a pointer. func (ck *Clerk) Put(key string, value string, version rpc.Tversion) rpc.Err { // You will have to modify this function. return "" diff --git a/src/kvraft1/kvraft1.test b/src/kvraft1/kvraft1.test deleted file mode 100644 index cf53a80..0000000 Binary files a/src/kvraft1/kvraft1.test and /dev/null differ diff --git a/src/kvraft1/rsm/rsm.go b/src/kvraft1/rsm/rsm.go index c5dba42..a145c10 100644 --- a/src/kvraft1/rsm/rsm.go +++ b/src/kvraft1/rsm/rsm.go @@ -46,7 +46,9 @@ type RSM struct { // 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. diff --git a/src/kvraft1/rsm/rsm.test b/src/kvraft1/rsm/rsm.test deleted file mode 100644 index e1419fe..0000000 Binary files a/src/kvraft1/rsm/rsm.test and /dev/null differ diff --git a/src/kvraft1/server.go b/src/kvraft1/server.go index 75197e7..2aaba61 100644 --- a/src/kvraft1/server.go +++ b/src/kvraft1/server.go @@ -19,6 +19,11 @@ type KVServer struct { // Your definitions here. } +// To type-cast req to the right type, take a look at Go's type switches or type +// assertions below: +// +// https://go.dev/tour/methods/16 +// https://go.dev/tour/methods/15 func (kv *KVServer) DoOp(req any) any { // Your code here return nil diff --git a/src/tester1/group.go b/src/tester1/group.go index 3d36240..d12a32c 100644 --- a/src/tester1/group.go +++ b/src/tester1/group.go @@ -150,19 +150,19 @@ func (sg *ServerGrp) cleanup() { } } -// attach server i to servers listed in to -// caller must hold cfg.mu +// attach server i to servers listed in to caller must hold cfg.mu. func (sg *ServerGrp) connect(i int, to []int) { //log.Printf("connect peer %d to %v\n", i, to) sg.connected[i] = true - // outgoing socket files - sg.srvs[i].connect(to) + // connect outgoing end points + sg.srvs[i].connect(sg, to) - // incoming socket files + // connect incoming end points to me for j := 0; j < len(to); j++ { - if sg.IsConnected(j) { + if sg.IsConnected(to[j]) { + //log.Printf("connect %d (%v) to %d", to[j], sg.srvs[to[j]].endNames[i], i) endname := sg.srvs[to[j]].endNames[i] sg.net.Enable(endname, true) } diff --git a/src/tester1/srv.go b/src/tester1/srv.go index 4703b3f..e31a55c 100644 --- a/src/tester1/srv.go +++ b/src/tester1/srv.go @@ -1,7 +1,7 @@ package tester import ( - // "log" + //"log" "sync" "6.5840/labrpc" @@ -46,12 +46,16 @@ func (s *Server) startServer(gid Tgid) *Server { return srv } -func (s *Server) connect(to []int) { +// connect s to servers listed in to +func (s *Server) connect(sg *ServerGrp, to []int) { s.mu.Lock() defer s.mu.Unlock() for j := 0; j < len(to); j++ { - endname := s.endNames[to[j]] - s.net.Enable(endname, true) + if sg.IsConnected(to[j]) { + //log.Printf("connect %d to %d (%v)", s.id, to[j], s.endNames[to[j]]) + endname := s.endNames[to[j]] + s.net.Enable(endname, true) + } } }