-
Notifications
You must be signed in to change notification settings - Fork 0
/
early_exit.go
40 lines (35 loc) · 957 Bytes
/
early_exit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
//
// a word-count application "plugin" for MapReduce.
//
// go build -buildmode=plugin wc_long.go
//
import (
"strconv"
"strings"
"time"
"6.824/mr"
)
//
// The map function is called once for each file of input.
// This map function just returns 1 for each file
//
func Map(filename string, contents string) []mr.KeyValue {
kva := []mr.KeyValue{}
kva = append(kva, mr.KeyValue{filename, "1"})
return kva
}
//
// The reduce function is called once for each key generated by the
// map tasks, with a list of all the values created for that key by
// any map task.
//
func Reduce(key string, values []string) string {
// some reduce tasks sleep for a long time; potentially seeing if
// a worker will accidentally exit early
if strings.Contains(key, "sherlock") || strings.Contains(key, "tom") {
time.Sleep(time.Duration(3 * time.Second))
}
// return the number of occurrences of this file.
return strconv.Itoa(len(values))
}