This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"log" | |
"net" | |
"net/rpc" | |
"shared" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net" | |
"net/rpc" | |
"shared" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (wk *Worker) DoTask(arg *DoTaskArgs, _ *struct{}) error { | |
fmt.Printf("%s: given %v task #%d on file %s (nois: %d)\n", | |
wk.name, arg.Phase, arg.TaskNumber, arg.File, arg.NumOtherPhase) | |
switch arg.Phase { | |
case mapPhase: | |
doMap(arg.JobName, arg.TaskNumber, arg.File, arg.NumOtherPhase, wk.Map) | |
case reducePhase: | |
doReduce(arg.JobName, arg.TaskNumber, arg.NumOtherPhase, wk.Reduce) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (mr *Master) Register(args *RegisterArgs, _ *struct{}) error { | |
mr.Lock() | |
defer mr.Unlock() | |
debug("Register: worker %s\n", args.Worker) | |
mr.workers = append(mr.workers, args.Worker) | |
go func() { | |
mr.registerChannel <- args.Worker | |
}() | |
return nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Master struct { | |
sync.Mutex | |
address string | |
registerChannel chan string | |
doneChannel chan bool | |
workers []string // protected by the mutex | |
// per-task info | |
jobName string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Worker struct { | |
sync.Mutex | |
name string | |
Map func(string, string) []KeyValue | |
Reduce func(string, []string) string | |
nRPC int | |
nTasks int | |
l net.Listener | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (mr *Master) schedule(phase jobPhase) { | |
var ntasks int | |
var nios int | |
switch phase { | |
case mapPhase: | |
ntasks = len(mr.files) | |
nios = mr.nReduce | |
case reducePhase: | |
ntasks = mr.nReduce | |
nios = len(mr.files) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func doMap( | |
jobName string, | |
mapTaskNumber int, | |
inFile string, | |
nReduce int, | |
mapF func(file string, contents string) []KeyValue, | |
) { | |
buff, err := ioutil.ReadFile(inFile) | |
if err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"mapreduce" | |
"os" | |
"strconv" | |
"strings" | |
"unicode" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 | |
set fileencoding=utf-8 | |
set encoding=utf-8 | |
set termencoding=utf-8 | |
set guifont=Inconsolata\ for\ Powerline:h14 | |
" <Leader> key | |
let mapleader=";" |