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
d8f890f1
Commit
d8f890f1
authored
Feb 09, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exposed method to create new log entry
parent
ce3f113b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
11 deletions
+18
-11
assignment2/src/raft/raft.go
assignment2/src/raft/raft.go
+12
-5
assignment2/src/server_test.go
assignment2/src/server_test.go
+6
-6
No files found.
assignment2/src/raft/raft.go
View file @
d8f890f1
...
...
@@ -83,6 +83,16 @@ func NewRaft(config *ClusterConfig, thisServerId int, commitCh chan LogEntry) (*
return
rft
,
nil
}
func
NewLogEntry
(
id
Lsn
,
data
[]
byte
,
committed
bool
,
conn
net
.
Conn
)
*
LogEntryData
{
entry
:=
new
(
LogEntryData
)
entry
.
id
=
id
entry
.
data
=
data
entry
.
conn
=
conn
entry
.
committed
=
committed
return
entry
}
//goroutine that monitors channel to check if the majority of servers have replied
func
monitorAckChannel
(
rft
*
Raft
,
ack_ch
<-
chan
int
,
log_entry
LogEntry
,
majCh
chan
bool
)
{
acks_received
:=
0
...
...
@@ -136,11 +146,8 @@ func (rft *Raft) Append(data []byte, conn net.Conn) (LogEntry, error) {
if
rft
.
id
!=
1
{
return
nil
,
ErrRedirect
(
1
)
}
temp
:=
new
(
LogEntryData
)
temp
.
id
=
1
temp
.
committed
=
false
temp
.
data
=
data
temp
.
conn
=
conn
temp
:=
NewLogEntry
(
1
,
data
,
false
,
conn
)
rft
.
log_array
=
append
(
rft
.
log_array
,
temp
)
ackChan
:=
make
(
chan
int
)
...
...
assignment2/src/server_test.go
View file @
d8f890f1
...
...
@@ -4,7 +4,7 @@ package main
import
(
"bytes"
"fmt"
//
"fmt"
"net"
"os"
"os/exec"
...
...
@@ -31,7 +31,7 @@ func TestAll(t *testing.T) {
go
testServersCommunic
(
i
,
t
)
}
//wait for some time so that servers are ready
time
.
Sleep
(
4
*
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
//run client that tries connecting to the followers
testConnectFollower
(
t
)
...
...
@@ -62,7 +62,7 @@ func testConnectFollower(t *testing.T) {
if
err
!=
nil
{
t
.
Error
(
"Error in connecting the server at port: "
+
strconv
.
Itoa
(
server_port
))
}
else
{
time
.
Sleep
(
time
.
Millisecond
)
//
time.Sleep(time.Millisecond)
sending
:=
[]
byte
(
"set mykey1 100 3
\r\n
lul
\r\n
"
)
port
:=
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
expecting
:=
[]
byte
(
"ERR_REDIRECT 127.0.0.1 "
+
port
+
"
\r\n
"
)
...
...
@@ -79,7 +79,7 @@ func testConnectFollower(t *testing.T) {
)
}
conn
.
Close
()
time
.
Sleep
(
time
.
Millisecond
)
//
time.Sleep(time.Millisecond)
}
}
}
...
...
@@ -98,7 +98,7 @@ func testNoReply(t *testing.T) {
if
err
!=
nil
{
t
.
Error
(
"Error in connecting the server at port: "
+
strconv
.
Itoa
(
server_port
))
}
else
{
time
.
Sleep
(
time
.
Millisecond
)
//
time.Sleep(time.Millisecond)
for
_
,
pair
:=
range
noreply_cases
{
conn
.
Write
(
pair
.
to_server
)
buffer
:=
make
([]
byte
,
1024
)
...
...
@@ -113,6 +113,6 @@ func testNoReply(t *testing.T) {
}
}
conn
.
Close
()
time
.
Sleep
(
time
.
Millisecond
)
//
time.Sleep(time.Millisecond)
}
}
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