Skip to content

Commit

Permalink
refine test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 5, 2024
1 parent b68f198 commit 8bde4a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
defer kgm.wg.Done()

failpoint.Inject("fastPrimaryPriorityCheck", func() {
kgm.primaryPriorityCheckInterval = 200 * time.Millisecond
kgm.primaryPriorityCheckInterval = 1 * time.Second
})

ticker := time.NewTicker(kgm.primaryPriorityCheckInterval)
Expand Down Expand Up @@ -635,11 +635,11 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
}
// If there is a alive member with higher priority, reset the leader.
resetLeader := false
for _, member := range kg.Members {
if member.Priority <= localPriority {
for _, m := range kg.Members {
if m.Priority <= localPriority {
continue
}
if _, ok := aliveTSONodes[typeutil.TrimScheme(member.Address)]; ok {
if _, ok := aliveTSONodes[typeutil.TrimScheme(m.Address)]; ok {
resetLeader = true
break
}
Expand All @@ -650,10 +650,12 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
default:
allocator, err := kgm.GetAllocatorManager(kg.ID)
if err != nil {
log.Error("failed to get allocator manager", zap.Error(err))
continue
}
globalAllocator, err := allocator.GetAllocator(GlobalDCLocation)
if err != nil {
log.Error("failed to get global allocator", zap.Error(err))
continue
}
// only members of specific group are valid primary candidates.
Expand All @@ -668,6 +670,7 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
zap.Int("local-priority", localPriority))
if err := utils.TransferPrimary(kgm.etcdClient, globalAllocator.(*GlobalTSOAllocator).GetExpectedPrimaryLease(),
constant.TSOServiceName, kgm.GetServiceConfig().GetName(), "", kg.ID, memberMap); err != nil {
log.Error("failed to transfer primary", zap.Error(err))
continue
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,16 +1044,16 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() {

var err error
defaultPriority := constant.DefaultKeyspaceGroupReplicaPriority
clusterID := rand.Uint64()
clusterID, err := etcdutil.InitOrGetClusterID(suite.etcdClient, "/pd/cluster_id")

Check failure on line 1047 in pkg/tso/keyspace_group_manager_test.go

View workflow job for this annotation

GitHub Actions / statics

ineffectual assignment to err (ineffassign)
clusterIDStr := strconv.FormatUint(clusterID, 10)

rootPath := path.Join("/pd", clusterIDStr)
cfg1 := suite.createConfig()
cfg2 := suite.createConfig()
svcAddr1 := cfg1.GetAdvertiseListenAddr()
svcAddr2 := cfg2.GetAdvertiseListenAddr()

// Register TSO server 1
cfg1.Name = "tso1"
err = suite.registerTSOServer(re, clusterIDStr, svcAddr1, cfg1)
re.NoError(err)
defer func() {
Expand Down Expand Up @@ -1102,6 +1102,7 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() {
checkTSO(ctx, re, &wg, mgr1, ids)

// Create the Second TSO server.
cfg2.Name = "tso2"
err = suite.registerTSOServer(re, clusterIDStr, svcAddr2, cfg2)
re.NoError(err)
mgr2 := suite.newKeyspaceGroupManager(1, clusterID, cfg2)
Expand Down Expand Up @@ -1150,8 +1151,7 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() {
func (suite *keyspaceGroupManagerTestSuite) registerTSOServer(
re *require.Assertions, clusterID, svcAddr string, cfg *TestServiceConfig,
) error {
// Register TSO server 1
serviceID := &discovery.ServiceRegistryEntry{ServiceAddr: cfg.GetAdvertiseListenAddr()}
serviceID := &discovery.ServiceRegistryEntry{ServiceAddr: cfg.GetAdvertiseListenAddr(), Name: cfg.Name}
serializedEntry, err := serviceID.Serialize()
re.NoError(err)
serviceKey := discovery.RegistryPath(clusterID, constant.TSOServiceName, svcAddr)
Expand Down

0 comments on commit 8bde4a5

Please sign in to comment.