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
ce25b4bb
Commit
ce25b4bb
authored
Feb 08, 2015
by
Bharath Radhakrishnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logger added
parent
567b3b54
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
9 deletions
+38
-9
assignment2/replic_kvstore.go
assignment2/replic_kvstore.go
+38
-9
No files found.
assignment2/replic_kvstore.go
View file @
ce25b4bb
...
...
@@ -2,6 +2,7 @@ package main
import
(
"fmt"
"io/ioutil"
"log"
"net"
"net/rpc"
...
...
@@ -15,6 +16,12 @@ const (
CLIENT_PORT
=
9000
)
// Logger
var
Info
*
log
.
Logger
// Flag for enabling/disabling logging functionality
var
DEBUG
=
true
type
Lsn
uint64
//Log sequence number, unique for all time.
type
ErrRedirect
int
// See Log.Append. Implements Error interface.
...
...
@@ -131,7 +138,7 @@ func (raft *Raft) Append(data []byte) (LogEntry, error) {
go
func
(
ackChan
chan
int
)
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Hostname
+
":"
+
strconv
.
Itoa
(
server
.
LogPort
))
if
err
!=
nil
{
log
.
Fatal
(
"Dialing:"
,
err
)
Info
.
Fatal
(
"Dialing:"
,
err
)
}
reply
:=
new
(
Reply
)
args
:=
&
Args
{
7
}
...
...
@@ -186,34 +193,56 @@ func initializeInterServerCommunication(this_server *ServerConfig) {
rpc
.
Register
(
appendRpc
)
listener
,
e
:=
net
.
Listen
(
"tcp"
,
":"
+
strconv
.
Itoa
(
this_server
.
LogPort
))
if
e
!=
nil
{
log
.
Fatal
(
"listen error:"
,
e
)
Info
.
Fatal
(
"listen error:"
,
e
)
}
for
{
if
conn
,
err
:=
listener
.
Accept
();
err
!=
nil
{
log
.
Fatal
(
"accept error: "
+
err
.
Error
())
Info
.
Fatal
(
"accept error: "
+
err
.
Error
())
}
else
{
log
.
Printf
(
"new connection established
\n
"
)
Info
.
Printf
(
"new connection established
\n
"
)
go
rpc
.
ServeConn
(
conn
)
}
}
}
// Initialize Logger
func
initializeLogger
(
serverId
int
)
{
// Logger Initializaion
if
!
DEBUG
{
Info
=
log
.
New
(
ioutil
.
Discard
,
"INFO: "
,
log
.
Ldate
|
log
.
Ltime
|
log
.
Lshortfile
)
}
else
{
f
,
err
:=
os
.
OpenFile
(
strconv
.
Itoa
(
serverId
+
CLIENT_PORT
),
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_APPEND
,
0666
)
if
err
!=
nil
{
fmt
.
Println
(
"error opening file: %v"
,
err
)
}
defer
f
.
Close
()
Info
=
log
.
New
(
f
,
"INFO: "
,
log
.
Ldate
|
log
.
Ltime
|
log
.
Lshortfile
)
}
Info
.
Println
(
"Initialized server"
)
}
func
main
()
{
log
.
Println
(
"Start"
)
server_id
,
err
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
if
err
!=
nil
{
fmt
.
Println
(
"argument "
,
os
.
Args
[
1
],
"is not string"
)
Info
.
Println
(
"argument "
,
os
.
Args
[
1
],
"is not string"
)
}
initializeLogger
(
server_id
)
Info
.
Println
(
"Start"
)
this_server
,
_
:=
NewServerConfig
(
server_id
)
num_servers
,
err2
:=
strconv
.
Atoi
((
os
.
Args
[
2
]))
if
err2
!=
nil
{
fmt
.
Println
(
"argument "
,
os
.
Args
[
2
],
"is not string"
)
Info
.
Println
(
"argument "
,
os
.
Args
[
2
],
"is not string"
)
}
cluster_config
,
_
:=
NewClusterConfig
(
num_servers
)
fmt
.
Println
(
reflect
.
TypeOf
(
this_server
))
fmt
.
Println
(
reflect
.
TypeOf
(
cluster_config
))
Info
.
Println
(
reflect
.
TypeOf
(
this_server
))
Info
.
Println
(
reflect
.
TypeOf
(
cluster_config
))
initializeInterServerCommunication
(
this_server
)
var
dummy_input
string
...
...
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