Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Doug Woos
452-labs
Commits
d5d31f40
Commit
d5d31f40
authored
Mar 09, 2016
by
Irene Y Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding diskvd.go file
parent
70dce50f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
src/main/diskvd.go
src/main/diskvd.go
+74
-0
No files found.
src/main/diskvd.go
0 → 100644
View file @
d5d31f40
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
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment