Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcs: fix tso server address compare #8289

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/mcs/tso/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"io"
"net/http"
"strconv"
"strings"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -164,7 +163,7 @@ func (s *Service) FindGroupByKeyspaceID(
Address: member.Address,
// TODO: watch the keyspace groups' primary serving address changes
// to get the latest primary serving addresses of all keyspace groups.
IsPrimary: strings.EqualFold(member.Address, am.GetLeaderAddr()),
IsPrimary: member.CompareAddress(am.GetLeaderAddr()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep consistent with cse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, pd-cse will be switched to release-7.5

})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
if member != nil {
aliveTSONodes := make(map[string]struct{})
kgm.tsoNodes.Range(func(key, _ any) bool {
aliveTSONodes[key.(string)] = struct{}{}
aliveTSONodes[typeutil.TrimScheme(key.(string))] = struct{}{}
return true
})
if len(aliveTSONodes) == 0 {
Expand All @@ -638,7 +638,7 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() {
if member.Priority <= localPriority {
continue
}
if _, ok := aliveTSONodes[member.Address]; ok {
if _, ok := aliveTSONodes[typeutil.TrimScheme(member.Address)]; ok {
resetLeader = true
break
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/utils/typeutil/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ func Float64Equal(a, b float64) bool {

// EqualBaseURLs compares two URLs without scheme.
func EqualBaseURLs(url1, url2 string) bool {
trimScheme := func(s string) string {
return strings.TrimPrefix(strings.TrimPrefix(s, "https://"), "http://")
}
return trimScheme(url1) == trimScheme(url2)
return TrimScheme(url1) == TrimScheme(url2)
}

// TrimScheme trims the scheme from the URL.
func TrimScheme(s string) string {
return strings.TrimPrefix(strings.TrimPrefix(s, "https://"), "http://")
}
Loading