Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Dec 11, 2024
1 parent 11fbaa4 commit dddb935
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 24 additions & 16 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,32 +419,40 @@ func (c *RaftCluster) checkSchedulingService() {
// checkTSOService checks the TSO service.
func (c *RaftCluster) checkTSOService() {
if !c.opt.GetMicroServiceConfig().IsTSODynamicSwitchingEnabled() {
if err := c.startTSOJobsIfNeeded(); err != nil {
if err := c.switchToInternalTSO(); err != nil {
log.Error("failed to start TSO jobs", errs.ZapError(err))
return
}
if c.IsServiceIndependent(constant.TSOServiceName) {
c.UnsetServiceIndependent(constant.TSOServiceName)
}
return
}

servers, err := discovery.Discover(c.etcdClient, constant.TSOServiceName)
if err != nil || len(servers) == 0 {
if err := c.startTSOJobsIfNeeded(); err != nil {
log.Error("failed to start TSO jobs", errs.ZapError(err))
if err := c.switchToInternalTSO(); err != nil {
log.Error("failed to switch to internal TSO", errs.ZapError(err))
return
}
if c.IsServiceIndependent(constant.TSOServiceName) {
log.Info("TSO is provided by PD")
c.UnsetServiceIndependent(constant.TSOServiceName)
}
} else {
c.stopTSOJobsIfNeeded()
if !c.IsServiceIndependent(constant.TSOServiceName) {
log.Info("TSO is provided by TSO server")
c.SetServiceIndependent(constant.TSOServiceName)
}
} else if len(servers) > 0 {
c.switchToExternalTSO()
}
}

func (c *RaftCluster) switchToInternalTSO() error {
if err := c.startTSOJobsIfNeeded(); err != nil {
return err
}
if c.IsServiceIndependent(constant.TSOServiceName) {
c.UnsetServiceIndependent(constant.TSOServiceName)
log.Info("successfully switched to internal TSO")
}
return nil
}

func (c *RaftCluster) switchToExternalTSO() {
c.stopTSOJobsIfNeeded()
if !c.IsServiceIndependent(constant.TSOServiceName) {
c.SetServiceIndependent(constant.TSOServiceName)
log.Info("successfully switched to external TSO")
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/server/tso/tso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func checkAndReturnTimestampResponse(re *require.Assertions, req *pdpb.TsoReques
re.GreaterOrEqual(uint32(timestamp.GetLogical())>>timestamp.GetSuffixBits(), req.GetCount())
return timestamp
}

func TestLogicalOverflow(t *testing.T) {
re := require.New(t)

Expand Down

0 comments on commit dddb935

Please sign in to comment.