Skip to content

Commit

Permalink
refine priority
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 a4ae781 commit b68f198
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/tikv/pd/pkg/election"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/mcs/discovery"
"github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/mcs/utils/constant"
"github.com/tikv/pd/pkg/member"
"github.com/tikv/pd/pkg/slice"
Expand Down Expand Up @@ -647,11 +648,28 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
select {
case <-ctx.Done():
default:
member.ResetLeader()
log.Info("reset primary",
allocator, err := kgm.GetAllocatorManager(kg.ID)
if err != nil {
continue
}
globalAllocator, err := allocator.GetAllocator(GlobalDCLocation)
if err != nil {
continue
}
// only members of specific group are valid primary candidates.
group := kgm.GetKeyspaceGroups()[kg.ID]
memberMap := make(map[string]bool, len(group.Members))
for _, m := range group.Members {
memberMap[m.Address] = true
}
log.Info("tso priority checker moves primary",
zap.String("local-address", kgm.tsoServiceID.ServiceAddr),
zap.Uint32("keyspace-group-id", kg.ID),
zap.Int("local-priority", localPriority))
if err := utils.TransferPrimary(kgm.etcdClient, globalAllocator.(*GlobalTSOAllocator).GetExpectedPrimaryLease(),
constant.TSOServiceName, kgm.GetServiceConfig().GetName(), "", kg.ID, memberMap); err != nil {
continue
}
}
} else {
log.Warn("no need to reset primary as the replicas with higher priority are offline",
Expand Down

0 comments on commit b68f198

Please sign in to comment.