Commit ce3f113b authored by Sushant Mahajan's avatar Sushant Mahajan

added some logging at important locations

parent 9493496f
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
*parameters: channel to read data from, threshold number of bytes to read *parameters: channel to read data from, threshold number of bytes to read
*returns: the value string and error state *returns: the value string and error state
*/ */
func readValue(ch chan []byte, n uint64) ([]byte, bool) { func readValue(ch chan []byte, n uint64, logger *log.Logger) ([]byte, bool) {
//now we need to read the value which should have been sent //now we need to read the value which should have been sent
valReadLength := uint64(0) valReadLength := uint64(0)
var v []byte var v []byte
...@@ -48,6 +48,7 @@ func readValue(ch chan []byte, n uint64) ([]byte, bool) { ...@@ -48,6 +48,7 @@ func readValue(ch chan []byte, n uint64) ([]byte, bool) {
//will be true if timeout occurs //will be true if timeout occurs
if err { if err {
logger.Println("Timeout")
break break
} }
} }
...@@ -126,7 +127,7 @@ func HandleClient(conn net.Conn, rft *raft.Raft, logger *log.Logger) { ...@@ -126,7 +127,7 @@ func HandleClient(conn net.Conn, rft *raft.Raft, logger *log.Logger) {
for { for {
command := new(utils.Command) command := new(utils.Command)
msg := <-ch msg := <-ch
logger.Println("got:", msg) logger.Println("got:", msg, string(msg))
if len(msg) == 0 { if len(msg) == 0 {
continue continue
...@@ -146,7 +147,7 @@ func HandleClient(conn net.Conn, rft *raft.Raft, logger *log.Logger) { ...@@ -146,7 +147,7 @@ func HandleClient(conn net.Conn, rft *raft.Raft, logger *log.Logger) {
} }
if flag { if flag {
logger.Println("numbytes", nr) logger.Println("numbytes", nr)
if v, err := readValue(ch, nr); err { if v, err := readValue(ch, nr, logger); err {
logger.Println("error reading value") logger.Println("error reading value")
Write(conn, "ERR_CMD_ERR") Write(conn, "ERR_CMD_ERR")
continue continue
......
...@@ -154,7 +154,7 @@ func (rft *Raft) Append(data []byte, conn net.Conn) (LogEntry, error) { ...@@ -154,7 +154,7 @@ func (rft *Raft) Append(data []byte, conn net.Conn) (LogEntry, error) {
Info.Fatal("Dialing:", err) Info.Fatal("Dialing:", err)
} }
reply := new(Reply) reply := new(Reply)
args := &Args{7} args := temp
appendCall := client.Go("AppendEntries.AppendEntriesRPC", args, reply, nil) //let go allocate done channel appendCall := client.Go("AppendEntries.AppendEntriesRPC", args, reply, nil) //let go allocate done channel
appendCall = <-appendCall.Done appendCall = <-appendCall.Done
ackChan <- reply.X ackChan <- reply.X
......
...@@ -20,16 +20,13 @@ var DEBUG = true ...@@ -20,16 +20,13 @@ var DEBUG = true
type AppendEntries struct{} type AppendEntries struct{}
type Args struct {
X int
}
type Reply struct { type Reply struct {
X int X int
} }
func (t *AppendEntries) AppendEntriesRPC(args *Args, reply *Reply) error { func (t *AppendEntries) AppendEntriesRPC(args *raft.LogEntry, reply *Reply) error {
reply.X = args.X Info.Println("RPC invoked")
reply.X = 1
return nil return nil
} }
......
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