diff --git a/client/pd_service_discovery.go b/client/pd_service_discovery.go index e39ff7f9c50..d7016afa1cc 100644 --- a/client/pd_service_discovery.go +++ b/client/pd_service_discovery.go @@ -18,6 +18,7 @@ import ( "context" "reflect" "sort" + "strings" "sync" "sync/atomic" "time" @@ -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) } } @@ -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])