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 (
...
@@ -10,11 +10,10 @@ const (
)
)
func
main
()
{
func
main
()
{
dummyCh
:=
make
(
chan
bool
)
dummyCh
:=
make
(
chan
bool
,
1
)
commitCh
:=
make
(
chan
raft
.
LogEntry
)
fmt
.
Println
(
"Started"
)
fmt
.
Println
(
"Started"
)
for
i
:=
1
;
i
<=
5
;
i
++
{
for
i
:=
1
;
i
<=
5
;
i
++
{
go
raft
.
Start
(
i
,
commitCh
,
dummyCh
,
true
)
go
raft
.
Start
(
i
,
true
)
}
}
if
<-
dummyCh
{
if
<-
dummyCh
{
fmt
.
Println
(
"khattam"
)
fmt
.
Println
(
"khattam"
)
...
...
assignment3/src/raft/raft.go
View file @
5c9f2304
...
@@ -13,14 +13,14 @@ import (
...
@@ -13,14 +13,14 @@ import (
//constant values used
//constant values used
const
(
const
(
CLIENT_PORT
=
9000
CLIENT_PORT
=
9000
LOG_PORT
=
20000
LOG_PORT
=
20000
ACK_TIMEOUT
=
5
ACK_TIMEOUT
=
5
MIN_TIMEOUT
=
300
MIN_TIMEOUT
=
300
MAX_TIMEOUT
=
500
MAX_TIMEOUT
=
500
LEADER
=
iota
LEADER
=
10
CANDIDATE
CANDIDATE
=
20
FOLLOWER
FOLLOWER
=
30
VOTED_FOR
=
"votedFor"
VOTED_FOR
=
"votedFor"
CURRENT_TERM
=
"currentTerm"
CURRENT_TERM
=
"currentTerm"
FILE_WRITTEN
=
0
FILE_WRITTEN
=
0
...
@@ -261,20 +261,20 @@ func (e ErrRedirect) Error() string {
...
@@ -261,20 +261,20 @@ func (e ErrRedirect) Error() string {
func
(
rft
*
Raft
)
loop
()
{
func
(
rft
*
Raft
)
loop
()
{
state
:=
FOLLOWER
state
:=
FOLLOWER
for
{
for
{
rft
.
Info
.
Println
(
"hello"
)
switch
state
{
switch
state
{
case
FOLLOWER
:
case
FOLLOWER
:
state
=
rft
.
follower
()
state
=
rft
.
follower
()
// case CANDIDATE:
case
CANDIDATE
:
// state = candidate()
state
=
rft
.
candidate
()
// case LEADER:
case
LEADER
:
// state = leader()
state
=
rft
.
leader
()
default
:
return
}
}
}
}
}
}
func
getTimer
()
*
time
.
Timer
{
func
getTimer
()
*
time
.
Timer
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
return
time
.
NewTimer
(
time
.
Millisecond
*
time
.
Duration
((
rand
.
Intn
(
MAX_TIMEOUT
)
+
MIN_TIMEOUT
)
%
MAX_TIMEOUT
))
return
time
.
NewTimer
(
time
.
Millisecond
*
time
.
Duration
((
rand
.
Intn
(
MAX_TIMEOUT
)
+
MIN_TIMEOUT
)
%
MAX_TIMEOUT
))
}
}
...
@@ -304,6 +304,7 @@ func (rft *Raft) follower() int {
...
@@ -304,6 +304,7 @@ func (rft *Raft) follower() int {
//start candidate timeout
//start candidate timeout
electionTimeout
:=
getTimer
()
electionTimeout
:=
getTimer
()
for
{
for
{
rft
.
Info
.
Println
(
"xyz"
)
//wrap in select
//wrap in select
select
{
select
{
case
<-
electionTimeout
.
C
:
case
<-
electionTimeout
.
C
:
...
@@ -378,3 +379,11 @@ func (rft *Raft) follower() int {
...
@@ -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) {
...
@@ -23,8 +23,9 @@ func getLogger(serverId int, toDebug bool) (l *log.Logger) {
return
l
return
l
}
}
func
Start
(
serverId
int
,
commitCh
chan
LogEntry
,
dummyCh
chan
bool
,
toDebug
bool
)
{
func
Start
(
serverId
int
,
toDebug
bool
)
{
eventCh
:=
make
(
chan
RaftEvent
)
eventCh
:=
make
(
chan
RaftEvent
)
commitCh
:=
make
(
chan
LogEntry
)
clusterConfig
,
_
:=
NewClusterConfig
(
5
)
clusterConfig
,
_
:=
NewClusterConfig
(
5
)
rft
,
_
:=
NewRaft
(
clusterConfig
,
serverId
,
commitCh
,
eventCh
,
true
)
rft
,
_
:=
NewRaft
(
clusterConfig
,
serverId
,
commitCh
,
eventCh
,
true
)
if
rafts
==
nil
{
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