Skip to content

Commit

Permalink
Merge branch 'release-8.5' into cherry-pick-8824-to-release-8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Dec 6, 2024
2 parents 063786c + ac87a00 commit 211d06c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ func (c *RaftCluster) startTSOJobsIfNeeded() error {
log.Error("failed to initialize the global TSO allocator", errs.ZapError(err))
return err
}
} else if !c.running {
// If the global TSO allocator is already initialized, but the running flag is false,
// it means there maybe unexpected error happened before.
log.Warn("the global TSO allocator is already initialized before, but the cluster is not running")
}
return nil
}
Expand Down Expand Up @@ -855,6 +859,15 @@ func (c *RaftCluster) runReplicationMode() {
// Stop stops the cluster.
func (c *RaftCluster) Stop() {
c.Lock()
// We need to try to stop tso jobs whatever the cluster is running or not.
// Because we need to call checkTSOService as soon as possible while the cluster is starting,
// which makes the cluster may not be running but the tso job has been started.
// For example, the cluster meets an error when starting, such as cluster is not bootstrapped.
// In this case, the `running` in `RaftCluster` is false, but the tso job has been started.
// Ref: https://github.com/tikv/pd/issues/8836
if err := c.stopTSOJobsIfNeeded(); err != nil {
log.Error("failed to stop tso jobs", errs.ZapError(err))
}
if !c.running {
c.Unlock()
return
Expand All @@ -864,9 +877,6 @@ func (c *RaftCluster) Stop() {
if !c.IsServiceIndependent(constant.SchedulingServiceName) {
c.stopSchedulingJobs()
}
if err := c.stopTSOJobsIfNeeded(); err != nil {
log.Error("failed to stop tso jobs", errs.ZapError(err))
}
c.heartbeatRunner.Stop()
c.miscRunner.Stop()
c.logRunner.Stop()
Expand Down

0 comments on commit 211d06c

Please sign in to comment.