49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package kvsrv
|
|
|
|
import (
|
|
"sync"
|
|
|
|
|
|
"6.5840/kvsrv1/rpc"
|
|
"6.5840/labrpc"
|
|
"6.5840/tester1"
|
|
)
|
|
|
|
|
|
type KVServer struct {
|
|
mu sync.Mutex
|
|
|
|
// Your definitions here.
|
|
}
|
|
|
|
func MakeKVServer() *KVServer {
|
|
kv := &KVServer{}
|
|
// Your code here.
|
|
return kv
|
|
}
|
|
|
|
// Get returns the value and version for args.Key, if args.Key
|
|
// exists. Otherwise, Get returns ErrNoKey.
|
|
func (kv *KVServer) Get(args *rpc.GetArgs, reply *rpc.GetReply) {
|
|
// Your code here.
|
|
}
|
|
|
|
// Update the value for a key if args.Version matches the version of
|
|
// the key on the server. If versions don't match, return ErrVersion.
|
|
// If the key doesn't exist, Put installs the value if the
|
|
// args.Version is 0, and returns ErrNoKey otherwise.
|
|
func (kv *KVServer) Put(args *rpc.PutArgs, reply *rpc.PutReply) {
|
|
// Your code here.
|
|
}
|
|
|
|
// You can ignore Kill() for this lab
|
|
func (kv *KVServer) Kill() {
|
|
}
|
|
|
|
|
|
// You can ignore all arguments; they are for replicated KVservers
|
|
func StartKVServer(ends []*labrpc.ClientEnd, gid tester.Tgid, srv int, persister *tester.Persister) []tester.IService {
|
|
kv := MakeKVServer()
|
|
return []tester.IService{kv}
|
|
}
|