From 67df4a823e8dbb9e833024b456c8e97ac27f6cfd Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 6 May 2019 16:20:54 +0800 Subject: [PATCH] improve some logs (#1529) Signed-off-by: Ryan Leung --- server/cluster.go | 8 ++++++-- server/coordinator.go | 12 +++++++----- server/leader.go | 12 ++++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/server/cluster.go b/server/cluster.go index bd3ac987a7e..5e7a239a66f 100644 --- a/server/cluster.go +++ b/server/cluster.go @@ -129,10 +129,13 @@ func (c *RaftCluster) start() error { func (c *RaftCluster) runCoordinator() { defer logutil.LogPanic() defer c.wg.Done() - defer c.coordinator.wg.Wait() + defer func() { + c.coordinator.wg.Wait() + log.Info("coordinator has been stopped") + }() c.coordinator.run() <-c.coordinator.ctx.Done() - log.Info("coordinator: Stopped coordinator") + log.Info("coordinator is stopping") } func (c *RaftCluster) stop() { @@ -550,6 +553,7 @@ func (c *RaftCluster) runBackgroundJobs(interval time.Duration) { for { select { case <-c.quit: + log.Info("background jobs has been stopped") return case <-ticker.C: c.checkOperators() diff --git a/server/coordinator.go b/server/coordinator.go index 6e75a6efd49..c9694b3432c 100644 --- a/server/coordinator.go +++ b/server/coordinator.go @@ -123,7 +123,7 @@ func (c *coordinator) patrolRegions() { timer := time.NewTimer(c.cluster.GetPatrolRegionInterval()) defer timer.Stop() - log.Info("coordinator: start patrol regions") + log.Info("coordinator starts patrol regions") start := time.Now() var key []byte for { @@ -131,6 +131,7 @@ func (c *coordinator) patrolRegions() { case <-timer.C: timer.Reset(c.cluster.GetPatrolRegionInterval()) case <-c.ctx.Done(): + log.Info("patrol regions has been stopped") return } @@ -210,19 +211,20 @@ func (c *coordinator) checkRegion(region *core.RegionInfo) bool { func (c *coordinator) run() { ticker := time.NewTicker(runSchedulerCheckInterval) defer ticker.Stop() - log.Info("coordinator: Start collect cluster information") + log.Info("coordinator starts to collect cluster information") for { if c.shouldRun() { - log.Info("coordinator: Cluster information is prepared") + log.Info("coordinator has finished cluster information preparation") break } select { case <-ticker.C: case <-c.ctx.Done(): + log.Info("coordinator stops running") return } } - log.Info("coordinator: Run scheduler") + log.Info("coordinator starts to run schedulers") k := 0 scheduleCfg := c.cluster.opt.load() @@ -437,7 +439,7 @@ func (c *coordinator) runScheduler(s *scheduleController) { } case <-s.Ctx().Done(): - log.Infof("%v stopped: %v", s.GetName(), s.Ctx().Err()) + log.Infof("%v has been stopped: %v", s.GetName(), s.Ctx().Err()) return } } diff --git a/server/leader.go b/server/leader.go index 132c3f158b0..d2ca4a0ea5f 100644 --- a/server/leader.go +++ b/server/leader.go @@ -197,10 +197,13 @@ func (s *Server) memberInfo() (member *pdpb.Member, marshalStr string) { } func (s *Server) campaignLeader() error { - log.Debugf("begin to campaign leader %s", s.Name()) + log.Infof("start to campaign leader %s", s.Name()) lessor := clientv3.NewLease(s.client) - defer lessor.Close() + defer func() { + lessor.Close() + log.Info("exit campaign leader") + }() start := time.Now() ctx, cancel := context.WithTimeout(s.client.Ctx(), requestTimeout) @@ -225,7 +228,7 @@ func (s *Server) campaignLeader() error { return errors.WithStack(err) } if !resp.Succeeded { - return errors.New("campaign leader failed, other server may campaign ok") + return errors.New("failed to campaign leader, other server may campaign ok") } // Make the leader keepalived. @@ -236,7 +239,7 @@ func (s *Server) campaignLeader() error { if err != nil { return errors.WithStack(err) } - log.Debugf("campaign leader ok %s", s.Name()) + log.Infof("campaign leader ok %s", s.Name()) err = s.scheduleOpt.reload(s.kv) if err != nil { @@ -276,6 +279,7 @@ func (s *Server) campaignLeader() error { } case <-tsTicker.C: if err = s.updateTimestamp(); err != nil { + log.Info("failed to update timestamp") return err } etcdLeader := s.GetEtcdLeader()