Commit ce3f113b authored by Sushant Mahajan's avatar Sushant Mahajan

added some logging at important locations

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