Skip to content

Commit c753430

Browse files
committed
feat: add MIT-6.824
1 parent 8cd06d1 commit c753430

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+78026
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

course/2018-MIT-6.824/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.*/
2+
mrtmp.*
3+
824-mrinput-*.txt
4+
/main/diff.out
5+
/mapreduce/x.txt
6+
/pbservice/x.txt
7+
/kvpaxos/x.txt
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package raftkv
2+
3+
import "labrpc"
4+
import "crypto/rand"
5+
import "math/big"
6+
7+
8+
type Clerk struct {
9+
servers []*labrpc.ClientEnd
10+
// You will have to modify this struct.
11+
}
12+
13+
func nrand() int64 {
14+
max := big.NewInt(int64(1) << 62)
15+
bigx, _ := rand.Int(rand.Reader, max)
16+
x := bigx.Int64()
17+
return x
18+
}
19+
20+
func MakeClerk(servers []*labrpc.ClientEnd) *Clerk {
21+
ck := new(Clerk)
22+
ck.servers = servers
23+
// You'll have to add code here.
24+
return ck
25+
}
26+
27+
//
28+
// fetch the current value for a key.
29+
// returns "" if the key does not exist.
30+
// keeps trying forever in the face of all other errors.
31+
//
32+
// you can send an RPC with code like this:
33+
// ok := ck.servers[i].Call("KVServer.Get", &args, &reply)
34+
//
35+
// the types of args and reply (including whether they are pointers)
36+
// must match the declared types of the RPC handler function's
37+
// arguments. and reply must be passed as a pointer.
38+
//
39+
func (ck *Clerk) Get(key string) string {
40+
41+
// You will have to modify this function.
42+
return ""
43+
}
44+
45+
//
46+
// shared by Put and Append.
47+
//
48+
// you can send an RPC with code like this:
49+
// ok := ck.servers[i].Call("KVServer.PutAppend", &args, &reply)
50+
//
51+
// the types of args and reply (including whether they are pointers)
52+
// must match the declared types of the RPC handler function's
53+
// arguments. and reply must be passed as a pointer.
54+
//
55+
func (ck *Clerk) PutAppend(key string, value string, op string) {
56+
// You will have to modify this function.
57+
}
58+
59+
func (ck *Clerk) Put(key string, value string) {
60+
ck.PutAppend(key, value, "Put")
61+
}
62+
func (ck *Clerk) Append(key string, value string) {
63+
ck.PutAppend(key, value, "Append")
64+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package raftkv
2+
3+
const (
4+
OK = "OK"
5+
ErrNoKey = "ErrNoKey"
6+
)
7+
8+
type Err string
9+
10+
// Put or Append
11+
type PutAppendArgs struct {
12+
Key string
13+
Value string
14+
Op string // "Put" or "Append"
15+
// You'll have to add definitions here.
16+
// Field names must start with capital letters,
17+
// otherwise RPC will break.
18+
}
19+
20+
type PutAppendReply struct {
21+
WrongLeader bool
22+
Err Err
23+
}
24+
25+
type GetArgs struct {
26+
Key string
27+
// You'll have to add definitions here.
28+
}
29+
30+
type GetReply struct {
31+
WrongLeader bool
32+
Err Err
33+
Value string
34+
}

0 commit comments

Comments
 (0)