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
92709071
Commit
92709071
authored
Feb 05, 2015
by
Harshit Pande
Browse files
Options
Browse Files
Download
Plain Diff
raft constructor
parents
10833484
79fb8fc8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
assignment2/replic_kvstore.go
assignment2/replic_kvstore.go
+20
-16
No files found.
assignment2/replic_kvstore.go
View file @
92709071
...
...
@@ -3,8 +3,8 @@ package main
import
(
//"log"
"fmt"
"net"
"net/rpc"
//
"net"
//
"net/rpc"
"os"
"reflect"
"strconv"
...
...
@@ -48,15 +48,15 @@ type SharedLog interface {
}
type
Raft
struct
{
log_array
[]
LogEntryData
commitCh
chan
*
LogEntryData
log_array
[]
*
LogEntryData
commitCh
chan
LogEntry
cluster_config
*
ClusterConfig
//cluster
id
uint64
//this server
id
int
//this server id
}
var
cluster_config
*
ClusterConfig
func
NewRaft
(
config
*
ClusterConfig
,
thisServerId
int
,
commitCh
chan
*
LogEntry
)
(
*
Raft
,
error
)
{
func
NewRaft
(
config
*
ClusterConfig
,
thisServerId
int
,
commitCh
chan
LogEntry
)
(
*
Raft
,
error
)
{
rft
:=
new
(
Raft
)
rft
.
commitCh
=
commitCh
rft
.
cluster_config
=
config
...
...
@@ -65,12 +65,11 @@ func NewRaft(config *ClusterConfig, thisServerId int, commitCh chan *LogEntry) (
}
//goroutine that monitors channel for commiting log entry
func
monitor_commitCh
(
c
<-
chan
*
LogEntryData
)
{
//unidirectional -- can only read from the channel
func
monitor_commitCh
(
c
<-
chan
LogEntry
)
{
//unidirectional -- can only read from the channel
for
{
var
temp
*
LogEntryData
temp
=
<-
c
//receive from the channel
temp
.
committed
=
true
//var temp LogEntry
temp
:=
<-
c
//receive from the channel
temp
.
(
*
LogEntryData
)
.
committed
=
true
//now update key value store here
}
}
...
...
@@ -90,15 +89,20 @@ func (entry *LogEntryData) Committed() bool {
//make raft implement the append function
func
(
raft
*
Raft
)
Append
(
data
[]
byte
)
(
LogEntry
,
error
)
{
if
raft
.
server
.
I
d
!=
0
{
return
nil
,
raft
.
Id
if
raft
.
i
d
!=
0
{
return
nil
,
ErrRedirect
(
0
)
}
temp
:=
LogEntry
{
1
,
data
,
false
}
temp
:=
new
(
LogEntryData
)
temp
.
id
=
1
temp
.
committed
=
false
temp
.
data
=
data
raft
.
log_array
=
append
(
raft
.
log_array
,
temp
)
//broadcast to other servers
//wait for acks
//send commit on channel
raft
.
commitCh
<-
temp
return
temp
,
nil
}
type
RPChandle
struct
{
...
...
@@ -132,11 +136,11 @@ func NewClusterConfig(num_servers int) (*ClusterConfig, error) {
}
func
(
e
ErrRedirect
)
Error
()
string
{
return
"Redirect to server "
+
strconv
.
Itoa
(
cluster_config
.
Servers
[
0
]
.
Id
)
return
"Redirect to server "
+
strconv
.
Itoa
(
0
)
}
func
start_rpc
(
this_server
*
ServerConfig
)
{
rpc
.
Register
()
//
rpc.Register()
}
func
main
()
{
...
...
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