forked from GusSand/golabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diskvd.go
74 lines (65 loc) · 1.75 KB
/
diskvd.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
//
// start a diskvd server. it's a member of some replica
// group, which has other members, and it needs to know
// how to talk to the members of the shardmaster service.
// used by ../diskv/test_test.go
//
// arguments:
// -g groupid
// -m masterport1 -m masterport2 ...
// -s replicaport1 -s replicaport2 ...
// -i my-index-in-server-port-list
// -u unreliable
// -d directory
// -r restart
import "time"
import "diskv"
import "os"
import "fmt"
import "strconv"
import "runtime"
func usage() {
fmt.Printf("Usage: diskvd -g gid -m master... -s server... -i my-index -d dir\n")
os.Exit(1)
}
func main() {
var gid int64 = -1 // my replica group ID
masters := []string{} // ports of shardmasters
replicas := []string{} // ports of servers in my replica group
me := -1 // my index in replicas[]
unreliable := false
dir := "" // store persistent data here
restart := false
for i := 1; i+1 < len(os.Args); i += 2 {
a0 := os.Args[i]
a1 := os.Args[i+1]
if a0 == "-g" {
gid, _ = strconv.ParseInt(a1, 10, 64)
} else if a0 == "-m" {
masters = append(masters, a1)
} else if a0 == "-s" {
replicas = append(replicas, a1)
} else if a0 == "-i" {
me, _ = strconv.Atoi(a1)
} else if a0 == "-u" {
unreliable, _ = strconv.ParseBool(a1)
} else if a0 == "-d" {
dir = a1
} else if a0 == "-r" {
restart, _ = strconv.ParseBool(a1)
} else {
usage()
}
}
if gid < 0 || me < 0 || len(masters) < 1 || me >= len(replicas) || dir == "" {
usage()
}
runtime.GOMAXPROCS(4)
srv := diskv.StartServer(gid, masters, replicas, me, dir, restart)
srv.Setunreliable(unreliable)
// for safety, force quit after 10 minutes.
time.Sleep(10 * 60 * time.Second)
mep, _ := os.FindProcess(os.Getpid())
mep.Kill()
}