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
10833484
Commit
10833484
authored
Feb 05, 2015
by
Harshit Pande
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raft constructor
parent
a8826caf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
8 deletions
+31
-8
assignment2/replic_kvstore.go
assignment2/replic_kvstore.go
+31
-8
No files found.
assignment2/replic_kvstore.go
View file @
10833484
...
...
@@ -2,9 +2,9 @@ package main
import
(
//"log"
//"net"
//"net/rpc"
"fmt"
"net"
"net/rpc"
"os"
"reflect"
"strconv"
...
...
@@ -48,15 +48,22 @@ type SharedLog interface {
}
type
Raft
struct
{
//some good stuff needs to go here
commitCh
chan
*
LogEntryData
cluster
*
ClusterConfig
//cluster
id
uint64
//leader
commitCh
chan
LogEntry
log_array
[]
LogEntryData
commitCh
chan
*
LogEntryData
cluster_config
*
ClusterConfig
//cluster
id
uint64
//this server
}
var
cluster_config
*
ClusterConfig
func
NewRaft
(
config
*
ClusterConfig
,
thisServerId
int
,
commitCh
chan
*
LogEntry
)
(
*
Raft
,
error
)
{
rft
:=
new
(
Raft
)
rft
.
commitCh
=
commitCh
rft
.
cluster_config
=
config
rft
.
id
=
thisServerId
return
rft
,
nil
}
//goroutine that monitors channel for commiting log entry
func
monitor_commitCh
(
c
<-
chan
*
LogEntryData
)
{
//unidirectional -- can only read from the channel
for
{
...
...
@@ -87,13 +94,20 @@ func (raft *Raft) Append(data []byte) (LogEntry, error) {
return
nil
,
raft
.
Id
}
temp
:=
LogEntry
{
1
,
data
,
false
}
raft
.
log_array
=
append
(
raft
.
log_array
,
temp
)
//broadcast to other servers
//wait for acks
//send commit on channel
raft
.
commitCh
<-
temp
}
func
AppendEntriesRPC
()
type
RPChandle
struct
{
}
func
(
r
*
RPChandle
)
AppendEntriesRPC
(
log_entry
LogEntryData
)
bool
{
return
true
}
func
NewServerConfig
(
server_id
int
)
(
*
ServerConfig
,
error
)
{
server
:=
new
(
ServerConfig
)
...
...
@@ -121,6 +135,10 @@ func (e ErrRedirect) Error() string {
return
"Redirect to server "
+
strconv
.
Itoa
(
cluster_config
.
Servers
[
0
]
.
Id
)
}
func
start_rpc
(
this_server
*
ServerConfig
)
{
rpc
.
Register
()
}
func
main
()
{
server_id
,
err
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
if
err
!=
nil
{
...
...
@@ -136,4 +154,9 @@ func main() {
fmt
.
Println
(
reflect
.
TypeOf
(
this_server
))
fmt
.
Println
(
reflect
.
TypeOf
(
cluster_config
))
go
start_rpc
(
this_server
)
var
dummy_input
string
fmt
.
Scanln
(
&
dummy_input
)
}
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