Commit 15d84480 authored by Sushant Mahajan's avatar Sushant Mahajan

integrated logger

parents 810d396e 208cfc10
......@@ -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
......
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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment