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
9493496f
Commit
9493496f
authored
Feb 09, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
successful run of redirect test
parent
58cf8744
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
13 deletions
+24
-13
assignment2/src/connhandler/connhandler.go
assignment2/src/connhandler/connhandler.go
+15
-6
assignment2/src/raft/raft.go
assignment2/src/raft/raft.go
+0
-4
assignment2/src/server.go
assignment2/src/server.go
+1
-1
assignment2/src/server_test.go
assignment2/src/server_test.go
+8
-2
No files found.
assignment2/src/connhandler/connhandler.go
View file @
9493496f
...
...
@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/gob"
"log"
"net"
"raft"
"strconv"
...
...
@@ -116,7 +117,7 @@ func Write(conn net.Conn, msg string) {
conn
.
Write
(
buf
)
}
func
HandleClient
(
conn
net
.
Conn
,
rft
*
raft
.
Raft
)
{
func
HandleClient
(
conn
net
.
Conn
,
rft
*
raft
.
Raft
,
logger
*
log
.
Logger
)
{
defer
conn
.
Close
()
//channel for every connection for every client
ch
:=
make
(
chan
[]
byte
)
...
...
@@ -125,6 +126,8 @@ func HandleClient(conn net.Conn, rft *raft.Raft) {
for
{
command
:=
new
(
utils
.
Command
)
msg
:=
<-
ch
logger
.
Println
(
"got:"
,
msg
)
if
len
(
msg
)
==
0
{
continue
}
...
...
@@ -132,17 +135,19 @@ func HandleClient(conn net.Conn, rft *raft.Raft) {
flag
:=
false
nr
:=
uint64
(
0
)
tokens
:=
strings
.
Fields
(
string
(
msg
))
if
tokens
[
0
]
==
"
CAS
"
{
n
,
_
:=
strconv
.
ParseUint
(
tokens
[
3
],
10
,
64
)
if
tokens
[
0
]
==
"
cas
"
{
n
,
_
:=
strconv
.
ParseUint
(
tokens
[
4
],
10
,
64
)
nr
=
n
flag
=
true
}
else
if
tokens
[
0
]
==
"
SET
"
{
n
,
_
:=
strconv
.
ParseUint
(
tokens
[
2
],
10
,
64
)
}
else
if
tokens
[
0
]
==
"
set
"
{
n
,
_
:=
strconv
.
ParseUint
(
tokens
[
3
],
10
,
64
)
nr
=
n
flag
=
true
}
if
flag
{
logger
.
Println
(
"numbytes"
,
nr
)
if
v
,
err
:=
readValue
(
ch
,
nr
);
err
{
logger
.
Println
(
"error reading value"
)
Write
(
conn
,
"ERR_CMD_ERR"
)
continue
}
else
{
...
...
@@ -159,6 +164,10 @@ func HandleClient(conn net.Conn, rft *raft.Raft) {
//log.Fatal("encode error:", err)
}
rft
.
Append
(
buffer
.
Bytes
(),
conn
)
if
_
,
err
:=
rft
.
Append
(
buffer
.
Bytes
(),
conn
);
err
!=
nil
{
Write
(
conn
,
"ERR_REDIRECT 127.0.0.1 "
+
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
))
conn
.
Close
()
break
}
}
}
assignment2/src/raft/raft.go
View file @
9493496f
...
...
@@ -131,10 +131,6 @@ func (entry *LogEntryData) Committed() bool {
return
entry
.
committed
}
func
Test
()
{
}
//make raft implement the append function
func
(
rft
*
Raft
)
Append
(
data
[]
byte
,
conn
net
.
Conn
)
(
LogEntry
,
error
)
{
if
rft
.
id
!=
1
{
...
...
assignment2/src/server.go
View file @
9493496f
...
...
@@ -74,7 +74,7 @@ func initClientCommunication(server *raft.ServerConfig, rft *raft.Raft, ch chan
Info
.
Fatal
(
"client accept error: "
+
err
.
Error
())
}
else
{
Info
.
Printf
(
"client new connection established
\n
"
)
go
connhandler
.
HandleClient
(
conn
,
rft
)
go
connhandler
.
HandleClient
(
conn
,
rft
,
Info
)
}
}
ch
<-
true
...
...
assignment2/src/server_test.go
View file @
9493496f
...
...
@@ -4,6 +4,7 @@ package main
import
(
"bytes"
"fmt"
"net"
"os"
"os/exec"
...
...
@@ -34,6 +35,9 @@ func TestAll(t *testing.T) {
//run client that tries connecting to the followers
testConnectFollower
(
t
)
//test no reply
testNoReply
(
t
)
}
//run servers
...
...
@@ -52,7 +56,7 @@ func testServersCommunic(i int, t *testing.T) {
//on trying to connect with the followers the client should get redirect err from the followers
func
testConnectFollower
(
t
*
testing
.
T
)
{
for
i
:=
2
;
i
<
NUM_SERVERS
;
i
++
{
//the followers start at second position
for
i
:=
2
;
i
<
=
NUM_SERVERS
;
i
++
{
//the followers start at second position
server_port
:=
raft
.
CLIENT_PORT
+
i
conn
,
err
:=
net
.
Dial
(
"tcp"
,
":"
+
strconv
.
Itoa
(
server_port
))
if
err
!=
nil
{
...
...
@@ -60,7 +64,9 @@ func testConnectFollower(t *testing.T) {
}
else
{
time
.
Sleep
(
time
.
Millisecond
)
sending
:=
[]
byte
(
"set mykey1 100 3
\r\n
lul
\r\n
"
)
expecting
:=
[]
byte
(
"ERR_REDIRECT 127.0.0.1 "
+
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
+
"
\r\n
"
+
"ERR_REDIRECT 127.0.0.1 "
+
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
+
"
\r\n
"
)
port
:=
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
expecting
:=
[]
byte
(
"ERR_REDIRECT 127.0.0.1 "
+
port
+
"
\r\n
"
)
conn
.
Write
(
sending
)
buffer
:=
make
([]
byte
,
1024
)
conn
.
Read
(
buffer
)
...
...
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