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
5c9f2304
Commit
5c9f2304
authored
Mar 22, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed deadlock problem for go routines
parent
fe009bef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
18 deletions
+27
-18
assignment3/src/main.go
assignment3/src/main.go
+2
-3
assignment3/src/raft/raft.go
assignment3/src/raft/raft.go
+23
-14
assignment3/src/raft/server.go
assignment3/src/raft/server.go
+2
-1
No files found.
assignment3/src/main.go
View file @
5c9f2304
...
...
@@ -10,11 +10,10 @@ const (
)
func
main
()
{
dummyCh
:=
make
(
chan
bool
)
commitCh
:=
make
(
chan
raft
.
LogEntry
)
dummyCh
:=
make
(
chan
bool
,
1
)
fmt
.
Println
(
"Started"
)
for
i
:=
1
;
i
<=
5
;
i
++
{
go
raft
.
Start
(
i
,
commitCh
,
dummyCh
,
true
)
go
raft
.
Start
(
i
,
true
)
}
if
<-
dummyCh
{
fmt
.
Println
(
"khattam"
)
...
...
assignment3/src/raft/raft.go
View file @
5c9f2304
...
...
@@ -13,14 +13,14 @@ import (
//constant values used
const
(
CLIENT_PORT
=
9000
LOG_PORT
=
20000
ACK_TIMEOUT
=
5
MIN_TIMEOUT
=
300
MAX_TIMEOUT
=
500
LEADER
=
iota
CANDIDATE
FOLLOWER
CLIENT_PORT
=
9000
LOG_PORT
=
20000
ACK_TIMEOUT
=
5
MIN_TIMEOUT
=
300
MAX_TIMEOUT
=
500
LEADER
=
10
CANDIDATE
=
20
FOLLOWER
=
30
VOTED_FOR
=
"votedFor"
CURRENT_TERM
=
"currentTerm"
FILE_WRITTEN
=
0
...
...
@@ -261,20 +261,20 @@ func (e ErrRedirect) Error() string {
func
(
rft
*
Raft
)
loop
()
{
state
:=
FOLLOWER
for
{
rft
.
Info
.
Println
(
"hello"
)
switch
state
{
case
FOLLOWER
:
state
=
rft
.
follower
()
// case CANDIDATE:
// state = candidate()
// case LEADER:
// state = leader()
default
:
return
case
CANDIDATE
:
state
=
rft
.
candidate
()
case
LEADER
:
state
=
rft
.
leader
()
}
}
}
func
getTimer
()
*
time
.
Timer
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
return
time
.
NewTimer
(
time
.
Millisecond
*
time
.
Duration
((
rand
.
Intn
(
MAX_TIMEOUT
)
+
MIN_TIMEOUT
)
%
MAX_TIMEOUT
))
}
...
...
@@ -304,6 +304,7 @@ func (rft *Raft) follower() int {
//start candidate timeout
electionTimeout
:=
getTimer
()
for
{
rft
.
Info
.
Println
(
"xyz"
)
//wrap in select
select
{
case
<-
electionTimeout
.
C
:
...
...
@@ -378,3 +379,11 @@ func (rft *Raft) follower() int {
}
}
}
func
(
rft
*
Raft
)
candidate
()
int
{
return
1
}
func
(
rft
*
Raft
)
leader
()
int
{
return
1
}
assignment3/src/raft/server.go
View file @
5c9f2304
...
...
@@ -23,8 +23,9 @@ func getLogger(serverId int, toDebug bool) (l *log.Logger) {
return
l
}
func
Start
(
serverId
int
,
commitCh
chan
LogEntry
,
dummyCh
chan
bool
,
toDebug
bool
)
{
func
Start
(
serverId
int
,
toDebug
bool
)
{
eventCh
:=
make
(
chan
RaftEvent
)
commitCh
:=
make
(
chan
LogEntry
)
clusterConfig
,
_
:=
NewClusterConfig
(
5
)
rft
,
_
:=
NewRaft
(
clusterConfig
,
serverId
,
commitCh
,
eventCh
,
true
)
if
rafts
==
nil
{
...
...
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