Skip to content

Commit

Permalink
client: fix compatibility problem of pd client (#6244)
Browse files Browse the repository at this point in the history
close #6243

Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored Mar 29, 2023
1 parent 6cf2bd3 commit 1948c24
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions client/pd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"reflect"
"sort"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -360,20 +361,20 @@ func (c *pdServiceDiscovery) initClusterID() error {
defer cancel()
clusterID := uint64(0)
for _, url := range c.GetURLs() {
clusterInfo, err := c.getClusterInfo(ctx, url, c.option.timeout)
if err != nil || clusterInfo.GetHeader() == nil {
members, err := c.getMembers(ctx, url, c.option.timeout)
if err != nil || members.GetHeader() == nil {
log.Warn("[pd] failed to get cluster id", zap.String("url", url), errs.ZapError(err))
continue
}
if clusterID == 0 {
clusterID = clusterInfo.GetHeader().GetClusterId()
clusterID = members.GetHeader().GetClusterId()
continue
}
failpoint.Inject("skipClusterIDCheck", func() {
failpoint.Continue()
})
// All URLs passed in should have the same cluster ID.
if clusterInfo.GetHeader().GetClusterId() != clusterID {
if members.GetHeader().GetClusterId() != clusterID {
return errors.WithStack(errUnmatchedClusterID)
}
}
Expand All @@ -389,8 +390,15 @@ func (c *pdServiceDiscovery) updateServiceMode() {
leaderAddr := c.getLeaderAddr()
if len(leaderAddr) > 0 {
clusterInfo, err := c.getClusterInfo(c.ctx, leaderAddr, c.option.timeout)
// If the method is not supported, we set it to pd mode.
if err != nil {
log.Warn("[pd] failed to get cluster info for the leader", zap.String("leader-addr", leaderAddr), errs.ZapError(err))
// TODO: it's a hack way to solve the compatibility issue.
// we need to remove this after all maintained version supports the method.
if strings.Contains(err.Error(), "Unimplemented") {
c.serviceModeUpdateCb(pdpb.ServiceMode_PD_SVC_MODE)
} else {
log.Warn("[pd] failed to get cluster info for the leader", zap.String("leader-addr", leaderAddr), errs.ZapError(err))
}
return
}
c.serviceModeUpdateCb(clusterInfo.ServiceModes[0])
Expand Down

0 comments on commit 1948c24

Please sign in to comment.