Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Morris committed Jan 19, 2023
0 parents commit c231a2c
Show file tree
Hide file tree
Showing 66 changed files with 77,316 additions and 0 deletions.
127 changes: 127 additions & 0 deletions .check-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env bash

set -eu

REFERENCE_FILES=(
# lab 1
src/mrapps/crash.go
src/mrapps/indexer.go
src/mrapps/mtiming.go
src/mrapps/nocrash.go
src/mrapps/rtiming.go
src/mrapps/wc.go
src/main/mrsequential.go
src/main/mrcoordinator.go
src/main/mrworker.go

# lab 2
src/raft/persister.go
src/raft/test_test.go
src/raft/config.go
src/labrpc/labrpc.go

# lab 3
src/kvraft/test_test.go
src/kvraft/config.go

# lab 4a
src/shardctrler/test_test.go
src/shardctrler/config.go

# lab 4b
src/shardkv/test_test.go
src/shardkv/config.go
)

main() {
upstream="$1"
labnum="$2"

# make sure we have reference copy of lab, in FETCH_HEAD
git fetch "$upstream" 2>/dev/null || die "unable to git fetch $upstream"

# copy existing directory
tmpdir="$(mktemp -d)"
find src -type s -delete # cp can't copy sockets
cp -r src "$tmpdir"
orig="$PWD"
cd "$tmpdir"

# check out reference files
for f in ${REFERENCE_FILES[@]}; do
mkdir -p "$(dirname $f)"
git --git-dir="$orig/.git" show "FETCH_HEAD:$f" > "$f"
done

case $labnum in
"lab1") check_lab1;;
"lab2a"|"lab2b"|"lab2c"|"lab2d") check_lab2;;
"lab3a"|"lab3b") check_lab3;;
"lab4a") check_lab4a;;
"lab4b") check_lab4b;;
*) die "unknown lab: $labnum";;
esac

cd
rm -rf "$tmpdir"
}

check_lab1() {
check_cmd cd src/mrapps
check_cmd go build -buildmode=plugin wc.go
check_cmd go build -buildmode=plugin indexer.go
check_cmd go build -buildmode=plugin mtiming.go
check_cmd go build -buildmode=plugin rtiming.go
check_cmd go build -buildmode=plugin crash.go
check_cmd go build -buildmode=plugin nocrash.go
check_cmd cd ../main
check_cmd go build mrcoordinator.go
check_cmd go build mrworker.go
check_cmd go build mrsequential.go
}

check_lab2() {
check_cmd cd src/raft
check_cmd go test -c
}

check_lab3() {
check_cmd cd src/kvraft
check_cmd go test -c
}

check_lab4a() {
check_cmd cd src/shardctrler
check_cmd go test -c
}

check_lab4b() {
check_cmd cd src/shardkv
check_cmd go test -c
# also check other labs/parts
cd "$tmpdir"
check_lab4a
cd "$tmpdir"
check_lab3
cd "$tmpdir"
check_lab2
}

check_cmd() {
if ! "$@" >/dev/null 2>&1; then
echo "We tried building your source code with testing-related files reverted to original versions, and the build failed. This copy of your code is preserved in $tmpdir for debugging purposes. Please make sure the code you are trying to hand in does not make changes to test code." >&2
echo >&2
echo "The build failed while trying to run the following command:" >&2
echo >&2
echo "$ $@" >&2
echo " (cwd: ${PWD#$tmpdir/})" >&2
exit 1
fi
}

die() {
echo "$1" >&2
exit 1
}

main "$@"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pkg/
api.key
.api.key.trimmed
*-handin.tar.gz
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is the Makefile helping you submit the labs.
# Just create 6.5840/api.key with your API key in it,
# and submit your lab with the following command:
# $ make [lab1|lab2a|lab2b|lab2c|lab2d|lab3a|lab3b|lab4a|lab4b]

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

%: check-%
@echo "Preparing $@-handin.tar.gz"
@if echo $(LABS) | grep -q " $@ " ; then \
echo "Tarring up your submission..." ; \
COPYFILE_DISABLE=1 tar cvzf $@-handin.tar.gz \
"--exclude=src/main/pg-*.txt" \
"--exclude=src/main/diskvd" \
"--exclude=src/mapreduce/824-mrinput-*.txt" \
"--exclude=src/mapreduce/5840-mrinput-*.txt" \
"--exclude=src/main/mr-*" \
"--exclude=mrtmp.*" \
"--exclude=src/main/diff.out" \
"--exclude=src/main/mrcoordinator" \
"--exclude=src/main/mrsequential" \
"--exclude=src/main/mrworker" \
"--exclude=*.so" \
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; \
cat api.key | tr -d '\n' > .api.key.trimmed ; \
curl --silent --fail --show-error -F file=@$@-handin.tar.gz -F "key=<.api.key.trimmed" \
https://6824.scripts.mit.edu/2023/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

.PHONY: check-%
check-%:
@echo "Checking that your submission builds correctly..."
@./.check-build git://g.csail.mit.edu/6.5840-golabs-2023 $(patsubst check-%,%,$@)
12 changes: 12 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.*/
main/mr-tmp/
mrtmp.*
824-mrinput-*.txt
/main/diff.out
/mapreduce/x.txt
/pbservice/x.txt
/kvpaxos/x.txt
*.so
/main/mrcoordinator
/main/mrsequential
/main/mrworker
3 changes: 3 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module 6.5840

go 1.15
Empty file added src/go.sum
Empty file.
60 changes: 60 additions & 0 deletions src/kvraft/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package kvraft

import "6.5840/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("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. 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("KVServer.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")
}
33 changes: 33 additions & 0 deletions src/kvraft/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kvraft

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

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 {
Err Err
}

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

type GetReply struct {
Err Err
Value string
}
Loading

0 comments on commit c231a2c

Please sign in to comment.