Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs733
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sushant Mahajan
cs733
Commits
8051e299
Commit
8051e299
authored
Feb 05, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added rpc calls to followers
parent
a212f611
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
assignment2/replic_kvstore.go
assignment2/replic_kvstore.go
+23
-5
No files found.
assignment2/replic_kvstore.go
View file @
8051e299
...
...
@@ -58,6 +58,10 @@ type Args struct {
X
int
}
type
Reply
struct
{
X
int
}
type
AppendEntries
struct
{}
var
cluster_config
*
ClusterConfig
...
...
@@ -95,8 +99,8 @@ func (entry *LogEntryData) Committed() bool {
//make raft implement the append function
func
(
raft
*
Raft
)
Append
(
data
[]
byte
)
(
LogEntry
,
error
)
{
if
raft
.
id
!=
0
{
return
nil
,
ErrRedirect
(
0
)
if
raft
.
id
!=
1
{
return
nil
,
ErrRedirect
(
1
)
}
temp
:=
new
(
LogEntryData
)
temp
.
id
=
1
...
...
@@ -104,7 +108,20 @@ func (raft *Raft) Append(data []byte) (LogEntry, error) {
temp
.
data
=
data
raft
.
log_array
=
append
(
raft
.
log_array
,
temp
)
//broadcast to other servers
ackChan
:=
make
(
chan
int
)
for
_
,
server
:=
range
cluster_config
.
Servers
[
1
:
]
{
go
func
(
ackChan
chan
int
)
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Hostname
+
":"
+
strconv
.
Itoa
(
server
.
LogPort
))
if
err
!=
nil
{
log
.
Fatal
(
"Dialing:"
,
err
)
}
reply
:=
new
(
Reply
)
args
:=
&
Args
{
7
}
appendCall
:=
client
.
Go
(
"AppendEntries.AppendEntriesRPC"
,
args
,
reply
,
nil
)
//let go allocate done channel
appendCall
=
<-
appendCall
.
Done
ackChan
<-
reply
.
X
}(
ackChan
)
}
//wait for acks
//send commit on channel
raft
.
commitCh
<-
temp
...
...
@@ -141,8 +158,8 @@ func start_rpc(this_server *ServerConfig) {
//rpc.Register()
}
func
(
t
*
AppendEntries
)
AppendEntriesRPC
(
args
*
Args
,
reply
*
int
)
error
{
*
reply
=
args
.
X
func
(
t
*
AppendEntries
)
AppendEntriesRPC
(
args
*
Args
,
reply
*
Reply
)
error
{
reply
.
X
=
args
.
X
return
nil
}
...
...
@@ -164,6 +181,7 @@ func initializeInterServerCommunication(this_server *ServerConfig) {
}
func
main
()
{
log
.
Println
(
"Start"
)
server_id
,
err
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
if
err
!=
nil
{
fmt
.
Println
(
"argument "
,
os
.
Args
[
1
],
"is not string"
)
...
...
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