From 702994ca7deab4b9bd16792d074df03760e6d93d Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 25 Jul 2013 17:51:03 -0700 Subject: [PATCH 1/4] update leadername --- server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server.go b/server.go index 66fb4c5dd2..176f5ff25b 100644 --- a/server.go +++ b/server.go @@ -438,6 +438,10 @@ func (s *Server) setCurrentTerm(term uint64, leaderName string, append bool) { s.state = Follower s.leader = leaderName } + + if s.state == Follower { + s.leader = leaderName + } } //-------------------------------------- From f6ce9f12fbc0b652ad750da738c4a42e8c3ca03d Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 25 Jul 2013 17:54:08 -0700 Subject: [PATCH 2/4] refactor --- server.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server.go b/server.go index 176f5ff25b..a05d2ce45d 100644 --- a/server.go +++ b/server.go @@ -434,14 +434,11 @@ func (s *Server) setCurrentTerm(term uint64, leaderName string, append bool) { } // discover new leader - if term == s.currentTerm && s.state == Candidate && append { + if term == s.currentTerm && s.state != Leader && append { s.state = Follower s.leader = leaderName } - if s.state == Follower { - s.leader = leaderName - } } //-------------------------------------- From 4771080625fce9be231c9a96967e5571b734f679 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 27 Jul 2013 21:49:17 -0700 Subject: [PATCH 3/4] expose loglevel api to application --- debug.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/debug.go b/debug.go index 0f5949ce4b..8835ad63f2 100644 --- a/debug.go +++ b/debug.go @@ -16,11 +16,11 @@ const ( Trace = 2 ) -var LogLevel int = 0 +var logLevel int = 0 var logger *log.Logger func init() { - logger = log.New(os.Stdout, "", log.Lmicroseconds) + logger = log.New(os.Stdout, "raft", log.Lmicroseconds) } //------------------------------------------------------------------------------ @@ -29,6 +29,14 @@ func init() { // //------------------------------------------------------------------------------ +func LogLevel() int { + return logLevel +} + +func SetLogLevel(level int) { + logLevel = logLevel +} + //-------------------------------------- // Warnings //-------------------------------------- @@ -58,7 +66,7 @@ func warnln(v ...interface{}) { // Prints to the standard logger if debug mode is enabled. Arguments // are handled in the manner of fmt.Print. func debug(v ...interface{}) { - if LogLevel >= Debug { + if logLevel >= Debug { logger.Print(v...) } } @@ -66,7 +74,7 @@ func debug(v ...interface{}) { // Prints to the standard logger if debug mode is enabled. Arguments // are handled in the manner of fmt.Printf. func debugf(format string, v ...interface{}) { - if LogLevel >= Debug { + if logLevel >= Debug { logger.Printf(format, v...) } } @@ -74,7 +82,7 @@ func debugf(format string, v ...interface{}) { // Prints to the standard logger if debug mode is enabled. Arguments // are handled in the manner of fmt.Println. func debugln(v ...interface{}) { - if LogLevel >= Debug { + if logLevel >= Debug { logger.Println(v...) } } @@ -86,7 +94,7 @@ func debugln(v ...interface{}) { // Prints to the standard logger if trace debugging is enabled. Arguments // are handled in the manner of fmt.Print. func trace(v ...interface{}) { - if LogLevel >= Trace { + if logLevel >= Trace { logger.Print(v...) } } @@ -94,7 +102,7 @@ func trace(v ...interface{}) { // Prints to the standard logger if trace debugging is enabled. Arguments // are handled in the manner of fmt.Printf. func tracef(format string, v ...interface{}) { - if LogLevel >= Trace { + if logLevel >= Trace { logger.Printf(format, v...) } } @@ -102,7 +110,7 @@ func tracef(format string, v ...interface{}) { // Prints to the standard logger if trace debugging is enabled. Arguments // are handled in the manner of debugln. func traceln(v ...interface{}) { - if LogLevel >= Trace { + if logLevel >= Trace { logger.Println(v...) } } From 1f39a46046f717bc9ef7bd7f5b1c600bba3a70ac Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sun, 28 Jul 2013 15:31:25 -0700 Subject: [PATCH 4/4] fix error in setLogLevel --- debug.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug.go b/debug.go index 8835ad63f2..865617e62c 100644 --- a/debug.go +++ b/debug.go @@ -34,7 +34,7 @@ func LogLevel() int { } func SetLogLevel(level int) { - logLevel = logLevel + logLevel = level } //--------------------------------------