Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Oct 30, 2024
1 parent d4a8c5d commit 2f0a502
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ func (c *RaftCluster) checkTSOService() {
if c.opt.GetMicroServiceConfig().IsTSODynamicSwitchingEnabled() {
servers, err := discovery.Discover(c.etcdClient, strconv.FormatUint(c.clusterID, 10), constant.TSOServiceName)
if err != nil || len(servers) == 0 {
if err := c.startTSOJobs(); err != nil {
if err := c.startTSOJobsIfNeeded(); err != nil {
log.Error("failed to start TSO jobs", errs.ZapError(err))
return
}
log.Info("TSO is provided by PD")
c.UnsetServiceIndependent(constant.TSOServiceName)
} else {
if err := c.stopTSOJobs(); err != nil {
if err := c.startTSOJobsIfNeeded(); err != nil {
log.Error("failed to stop TSO jobs", errs.ZapError(err))
return
}
Expand All @@ -426,7 +426,7 @@ func (c *RaftCluster) checkTSOService() {
return
}

if err := c.startTSOJobs(); err != nil {
if err := c.startTSOJobsIfNeeded(); err != nil {
log.Error("failed to start TSO jobs", errs.ZapError(err))
return
}
Expand Down Expand Up @@ -457,7 +457,7 @@ func (c *RaftCluster) runServiceCheckJob() {
}
}

func (c *RaftCluster) startTSOJobs() error {
func (c *RaftCluster) startTSOJobsIfNeeded() error {
allocator, err := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation)
if err != nil {
log.Error("failed to get global TSO allocator", errs.ZapError(err))
Expand All @@ -473,7 +473,7 @@ func (c *RaftCluster) startTSOJobs() error {
return nil
}

func (c *RaftCluster) stopTSOJobs() error {
func (c *RaftCluster) stopTSOJobsIfNeeded() error {
allocator, err := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation)
if err != nil {
log.Error("failed to get global TSO allocator", errs.ZapError(err))
Expand Down Expand Up @@ -841,7 +841,7 @@ func (c *RaftCluster) Stop() {
if !c.IsServiceIndependent(constant.SchedulingServiceName) {
c.stopSchedulingJobs()
}
if err := c.stopTSOJobs(); err != nil {
if err := c.stopTSOJobsIfNeeded(); err != nil {
log.Error("failed to stop tso jobs", errs.ZapError(err))
}
c.heartbeatRunner.Stop()
Expand Down

0 comments on commit 2f0a502

Please sign in to comment.