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
15d84480
Commit
15d84480
authored
Feb 08, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Plain Diff
integrated logger
parents
810d396e
208cfc10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
10 deletions
+44
-10
assignment2/replic_kvstore.go
assignment2/replic_kvstore.go
+33
-7
assignment2/runner.go
assignment2/runner.go
+11
-3
No files found.
assignment2/replic_kvstore.go
View file @
15d84480
...
...
@@ -2,6 +2,7 @@ package main
import
(
"fmt"
"io/ioutil"
"log"
"net"
"net/rpc"
...
...
@@ -17,6 +18,12 @@ const (
ACK_TIMEOUT
=
5
)
// 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.
...
...
@@ -153,7 +160,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
}
...
...
@@ -209,32 +216,51 @@ 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
{
Info
=
log
.
New
(
os
.
Stdout
,
"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
)
Info
.
Println
(
reflect
.
TypeOf
(
this_server
))
Info
.
Println
(
reflect
.
TypeOf
(
cluster_config
))
initializeInterServerCommunication
(
this_server
)
var
dummy_input
string
...
...
assignment2/runner.go
View file @
15d84480
package
main
import
(
//"os"
"fmt"
"os"
//"log"
"os/exec"
"strconv"
...
...
@@ -16,12 +16,20 @@ const (
func
TestServersCommunic
(
i
int
)
{
cmd
:=
exec
.
Command
(
"go"
,
"run"
,
"replic_kvstore.go"
,
strconv
.
Itoa
(
i
+
1
),
strconv
.
Itoa
(
NUM_SERVERS
))
out
,
err
:=
cmd
.
CombinedOutput
(
)
f
,
err
:=
os
.
OpenFile
(
strconv
.
Itoa
(
i
),
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_TRUNC
,
0666
)
if
err
!=
nil
{
fmt
.
Println
(
"error opening file: %v"
,
err
)
}
defer
f
.
Close
()
cmd
.
Stdout
=
f
cmd
.
Stderr
=
f
cmd
.
Run
()
/*if err != nil {
fmt.Println(err)
}
fmt
.
Println
(
string
(
out
))
fmt.Println(string(out))
*/
}
func
main
()
{
...
...
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