From c3823a489a3ac8f6f4f60617afbb2189832e34d9 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Mon, 3 Apr 2023 14:20:30 +0800 Subject: [PATCH] *: make code clear by rename `isServing` to `isRunning` Signed-off-by: lhy1024 --- pkg/mcs/resource_manager/server/server.go | 10 +++++----- pkg/mcs/tso/server/server.go | 12 ++++++------ server/server.go | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/mcs/resource_manager/server/server.go b/pkg/mcs/resource_manager/server/server.go index 939bd37d4d1..a2ce35edf56 100644 --- a/pkg/mcs/resource_manager/server/server.go +++ b/pkg/mcs/resource_manager/server/server.go @@ -52,8 +52,8 @@ import ( // Server is the resource manager server, and it implements bs.Server. type Server struct { - // Server state. 0 is not serving, 1 is serving. - isServing int64 + // Server state. 0 is not running, 1 is running. + isRunning int64 ctx context.Context serverLoopCtx context.Context @@ -196,7 +196,7 @@ func (s *Server) campaignLeader() { // Close closes the server. func (s *Server) Close() { - if !atomic.CompareAndSwapInt64(&s.isServing, 1, 0) { + if !atomic.CompareAndSwapInt64(&s.isRunning, 1, 0) { // server is already closed return } @@ -247,7 +247,7 @@ func (s *Server) IsServing() bool { // IsClosed checks if the server loop is closed func (s *Server) IsClosed() bool { - return s != nil && atomic.LoadInt64(&s.isServing) == 0 + return s != nil && atomic.LoadInt64(&s.isRunning) == 0 } // AddServiceReadyCallback adds callbacks when the server becomes the leader, if there is embedded etcd, or the primary otherwise. @@ -411,7 +411,7 @@ func (s *Server) startServer() (err error) { log.Error("failed to regiser the service", zap.String("service-name", utils.ResourceManagerServiceName), errs.ZapError(err)) return err } - atomic.StoreInt64(&s.isServing, 1) + atomic.StoreInt64(&s.isRunning, 1) return nil } diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 5a9ae2e92b6..db8e8a239f2 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -75,8 +75,8 @@ var _ tso.ElectionMember = (*member.Participant)(nil) type Server struct { diagnosticspb.DiagnosticsServer - // Server state. 0 is not serving, 1 is serving. - isServing int64 + // Server state. 0 is not running, 1 is running. + isRunning int64 // Server start timestamp startTimestamp int64 @@ -157,7 +157,7 @@ func (s *Server) Run() error { // Close closes the server. func (s *Server) Close() { - if !atomic.CompareAndSwapInt64(&s.isServing, 1, 0) { + if !atomic.CompareAndSwapInt64(&s.isRunning, 1, 0) { // server is already closed return } @@ -200,7 +200,7 @@ func (s *Server) AddStartCallback(callbacks ...func()) { // IsServing implements basicserver. It returns whether the server is the leader // if there is embedded etcd, or the primary otherwise. func (s *Server) IsServing() bool { - return atomic.LoadInt64(&s.isServing) == 1 && s.keyspaceGroupManager.GetElectionMember(mcsutils.DefaultKeySpaceGroupID).IsLeader() + return atomic.LoadInt64(&s.isRunning) == 1 && s.keyspaceGroupManager.GetElectionMember(mcsutils.DefaultKeySpaceGroupID).IsLeader() } // GetLeaderListenUrls gets service endpoints from the leader in election group. @@ -225,7 +225,7 @@ func (s *Server) ClusterID() uint64 { // IsClosed checks if the server loop is closed func (s *Server) IsClosed() bool { - return atomic.LoadInt64(&s.isServing) == 0 + return atomic.LoadInt64(&s.isRunning) == 0 } // GetTSOAllocatorManager returns the manager of TSO Allocator. @@ -460,7 +460,7 @@ func (s *Server) startServer() (err error) { return err } - atomic.StoreInt64(&s.isServing, 1) + atomic.StoreInt64(&s.isRunning, 1) return nil } diff --git a/server/server.go b/server/server.go index 7586cc23fe2..116644ee241 100644 --- a/server/server.go +++ b/server/server.go @@ -121,8 +121,8 @@ var ( type Server struct { diagnosticspb.DiagnosticsServer - // Server state. - isServing int64 + // Server state. 0 is not running, 1 is running. + isRunning int64 // Server start timestamp startTimestamp int64 @@ -456,7 +456,7 @@ func (s *Server) startServer(ctx context.Context) error { } // Server has started. - atomic.StoreInt64(&s.isServing, 1) + atomic.StoreInt64(&s.isRunning, 1) serverMaxProcs.Set(float64(runtime.GOMAXPROCS(0))) return nil } @@ -468,7 +468,7 @@ func (s *Server) AddCloseCallback(callbacks ...func()) { // Close closes the server. func (s *Server) Close() { - if !atomic.CompareAndSwapInt64(&s.isServing, 1, 0) { + if !atomic.CompareAndSwapInt64(&s.isRunning, 1, 0) { // server is already closed return } @@ -513,7 +513,7 @@ func (s *Server) Close() { // IsClosed checks whether server is closed or not. func (s *Server) IsClosed() bool { - return atomic.LoadInt64(&s.isServing) == 0 + return atomic.LoadInt64(&s.isRunning) == 0 } // Run runs the pd server.