Skip to content

Commit

Permalink
*: make code clear by rename isServing to isRunning
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Apr 3, 2023
1 parent 1c288c4 commit c3823a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions pkg/mcs/resource_manager/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -460,7 +460,7 @@ func (s *Server) startServer() (err error) {
return err
}

atomic.StoreInt64(&s.isServing, 1)
atomic.StoreInt64(&s.isRunning, 1)
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c3823a4

Please sign in to comment.