Skip to content

Commit

Permalink
first init:MIT.6.824
Browse files Browse the repository at this point in the history
  • Loading branch information
izualzhy committed Oct 10, 2017
1 parent 60116a3 commit 045f3ec
Show file tree
Hide file tree
Showing 98 changed files with 332,562 additions and 0 deletions.
Binary file added 6.824/..gitignore.un~
Binary file not shown.
5 changes: 5 additions & 0 deletions 6.824/.gitignore
@@ -0,0 +1,5 @@
pkg/
api.key
*-handin.tar.gz
cscope.files
cscope.out
Binary file added 6.824/.make_env.sh.un~
Binary file not shown.
49 changes: 49 additions & 0 deletions 6.824/Makefile
@@ -0,0 +1,49 @@
# This is the Makefile helping you submit the labs.
# Just create 6.824/api.key with your API key in it,
# and submit your lab with the following command:
# $ make [lab1|lab2a|lab2b|lab2c|lab3a|lab3b|lab4a|lab4b]

LABS=" lab1 lab2a lab2b lab2c lab3a lab3b lab4a lab4b "

%:
@echo "Preparing $@-handin.tar.gz"
@echo "Checking for committed temporary files..."
@if git ls-files | grep -E 'mrtmp|mrinput' > /dev/null; then \
echo "" ; \
echo "OBS! You have committed some large temporary files:" ; \
echo "" ; \
git ls-files | grep -E 'mrtmp|mrinput' | sed 's/^/\t/' ; \
echo "" ; \
echo "Follow the instructions at http://stackoverflow.com/a/308684/472927" ; \
echo "to remove them, and then run make again." ; \
echo "" ; \
exit 1 ; \
fi
@if echo $(LABS) | grep -q " $@ " ; then \
echo "Tarring up your submission..." ; \
tar cvzf $@-handin.tar.gz \
"--exclude=src/main/pg-*.txt" \
"--exclude=src/main/diskvd" \
"--exclude=src/mapreduce/824-mrinput-*.txt" \
"--exclude=mrtmp.*" \
"--exclude=src/main/diff.out" \
Makefile src; \
if ! test -e api.key ; then \
echo "Missing $(PWD)/api.key. Please create the file with your key in it or submit the $@-handin.tar.gz via the web interface."; \
else \
echo "Are you sure you want to submit $@? Enter 'yes' to continue:"; \
read line; \
if test "$$line" != "yes" ; then echo "Giving up submission"; exit; fi; \
if test `stat -c "%s" "$@-handin.tar.gz" 2>/dev/null || stat -f "%z" "$@-handin.tar.gz"` -ge 20971520 ; then echo "File exceeds 20MB."; exit; fi; \
mv api.key api.key.fix ; \
cat api.key.fix | tr -d '\n' > api.key ; \
rm api.key.fix ; \
curl -F file=@$@-handin.tar.gz -F "key=<api.key" \
https://6824.scripts.mit.edu/2017/handin.py/upload > /dev/null || { \
echo ; \
echo "Submit seems to have failed."; \
echo "Please upload the tarball manually on the submission website."; } \
fi; \
else \
echo "Bad target $@. Usage: make [$(LABS)]"; \
fi
3 changes: 3 additions & 0 deletions 6.824/make_env.sh
@@ -0,0 +1,3 @@
#!/bin/bash

export GOPATH=$PWD
7 changes: 7 additions & 0 deletions 6.824/src/.gitignore
@@ -0,0 +1,7 @@
*.*/
mrtmp.*
824-mrinput-*.txt
/main/diff.out
/mapreduce/x.txt
/pbservice/x.txt
/kvpaxos/x.txt
64 changes: 64 additions & 0 deletions 6.824/src/kvraft/client.go
@@ -0,0 +1,64 @@
package raftkv

import "labrpc"
import "crypto/rand"
import "math/big"


type Clerk struct {
servers []*labrpc.ClientEnd
// You will have to modify this struct.
}

func nrand() int64 {
max := big.NewInt(int64(1) << 62)
bigx, _ := rand.Int(rand.Reader, max)
x := bigx.Int64()
return x
}

func MakeClerk(servers []*labrpc.ClientEnd) *Clerk {
ck := new(Clerk)
ck.servers = servers
// You'll have to add code here.
return ck
}

//
// fetch the current value for a key.
// returns "" if the key does not exist.
// keeps trying forever in the face of all other errors.
//
// you can send an RPC with code like this:
// ok := ck.servers[i].Call("RaftKV.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. and reply must be passed as a pointer.
//
func (ck *Clerk) Get(key string) string {

// You will have to modify this function.
return ""
}

//
// shared by Put and Append.
//
// you can send an RPC with code like this:
// ok := ck.servers[i].Call("RaftKV.PutAppend", &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. and reply must be passed as a pointer.
//
func (ck *Clerk) PutAppend(key string, value string, op string) {
// You will have to modify this function.
}

func (ck *Clerk) Put(key string, value string) {
ck.PutAppend(key, value, "Put")
}
func (ck *Clerk) Append(key string, value string) {
ck.PutAppend(key, value, "Append")
}
34 changes: 34 additions & 0 deletions 6.824/src/kvraft/common.go
@@ -0,0 +1,34 @@
package raftkv

const (
OK = "OK"
ErrNoKey = "ErrNoKey"
)

type Err string

// Put or Append
type PutAppendArgs struct {
Key string
Value string
Op string // "Put" or "Append"
// You'll have to add definitions here.
// Field names must start with capital letters,
// otherwise RPC will break.
}

type PutAppendReply struct {
WrongLeader bool
Err Err
}

type GetArgs struct {
Key string
// You'll have to add definitions here.
}

type GetReply struct {
WrongLeader bool
Err Err
Value string
}

0 comments on commit 045f3ec

Please sign in to comment.