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

server: fix join address on ipv6 (#43259) #44084

Merged
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
9 changes: 5 additions & 4 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -646,7 +647,7 @@ func (is *InfoSyncer) StoreTopologyInfo(ctx context.Context) error {
return errors.Trace(err)
}
str := string(hack.String(infoBuf))
key := fmt.Sprintf("%s/%s:%v/info", TopologyInformationPath, is.info.IP, is.info.Port)
key := fmt.Sprintf("%s/%s/info", TopologyInformationPath, net.JoinHostPort(is.info.IP, strconv.Itoa(int(is.info.Port))))
// Note: no lease is required here.
err = util.PutKVToEtcd(ctx, is.etcdCli, keyOpDefaultRetryCnt, key, str)
if err != nil {
Expand Down Expand Up @@ -798,7 +799,7 @@ func (is *InfoSyncer) newTopologySessionAndStoreServerInfo(ctx context.Context,
if is.etcdCli == nil {
return nil
}
logPrefix := fmt.Sprintf("[topology-syncer] %s/%s:%d", TopologyInformationPath, is.info.IP, is.info.Port)
logPrefix := fmt.Sprintf("[topology-syncer] %s/%s", TopologyInformationPath, net.JoinHostPort(is.info.IP, strconv.Itoa(int(is.info.Port))))
session, err := util2.NewSession(ctx, logPrefix, is.etcdCli, retryCnt, TopologySessionTTL)
if err != nil {
return err
Expand All @@ -813,7 +814,7 @@ func (is *InfoSyncer) updateTopologyAliveness(ctx context.Context) error {
if is.etcdCli == nil {
return nil
}
key := fmt.Sprintf("%s/%s:%v/ttl", TopologyInformationPath, is.info.IP, is.info.Port)
key := fmt.Sprintf("%s/%s/ttl", TopologyInformationPath, net.JoinHostPort(is.info.IP, strconv.Itoa(int(is.info.Port))))
return util.PutKVToEtcd(ctx, is.etcdCli, keyOpDefaultRetryCnt, key,
fmt.Sprintf("%v", time.Now().UnixNano()),
clientv3.WithLease(is.topologySession.Lease()))
Expand Down Expand Up @@ -884,7 +885,7 @@ func (is *InfoSyncer) getPrometheusAddr() (string, error) {
if err != nil {
return "", errors.Trace(err)
}
res = fmt.Sprintf("http://%s:%v", prometheus.IP, prometheus.Port)
res = fmt.Sprintf("http://%s", net.JoinHostPort(prometheus.IP, strconv.Itoa(prometheus.Port)))
}
is.prometheusAddr = res
is.modifyTime = time.Now()
Expand Down
4 changes: 2 additions & 2 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,8 +1711,8 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
for _, node := range tidbNodes {
servers = append(servers, ServerInfo{
ServerType: "tidb",
Address: fmt.Sprintf("%s:%d", node.IP, node.Port),
StatusAddr: fmt.Sprintf("%s:%d", node.IP, node.StatusPort),
Address: net.JoinHostPort(node.IP, strconv.Itoa(int(node.Port))),
StatusAddr: net.JoinHostPort(node.IP, strconv.Itoa(int(node.StatusPort))),
Version: FormatTiDBVersion(node.Version, isDefaultVersion),
GitHash: node.GitHash,
StartTimestamp: node.StartTimestamp,
Expand Down
6 changes: 3 additions & 3 deletions server/http_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func sleepWithCtx(ctx context.Context, d time.Duration) {
}

func (s *Server) listenStatusHTTPServer() error {
s.statusAddr = fmt.Sprintf("%s:%d", s.cfg.Status.StatusHost, s.cfg.Status.StatusPort)
s.statusAddr = net.JoinHostPort(s.cfg.Status.StatusHost, strconv.Itoa(int(s.cfg.Status.StatusPort)))
if s.cfg.Status.StatusPort == 0 && !RunInGoTest {
s.statusAddr = fmt.Sprintf("%s:%d", s.cfg.Status.StatusHost, defaultStatusPort)
s.statusAddr = net.JoinHostPort(s.cfg.Status.StatusHost, strconv.Itoa(defaultStatusPort))
}

logutil.BgLogger().Info("for status and metrics report", zap.String("listening on addr", s.statusAddr))
Expand Down Expand Up @@ -477,7 +477,7 @@ func (s *Server) startStatusServerAndRPCServer(serverMux *http.ServeMux) {
logutil.BgLogger().Error("tikv store not etcd background", zap.Error(err))
break
}
selfAddr := fmt.Sprintf("%s:%d", s.cfg.AdvertiseAddress, s.cfg.Status.StatusPort)
selfAddr := net.JoinHostPort(s.cfg.AdvertiseAddress, strconv.Itoa(int(s.cfg.Status.StatusPort)))
service := autoid.New(selfAddr, etcdAddr, store, ebd.TLSConfig())
logutil.BgLogger().Info("register auto service at", zap.String("addr", selfAddr))
pb.RegisterAutoIDAllocServer(grpcServer, service)
Expand Down
6 changes: 4 additions & 2 deletions server/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package server

import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -70,7 +72,7 @@ func handleDownloadFile(handler downloadFileHandler, w http.ResponseWriter, req
name := params[pFileName]
path := handler.filePath
isForwarded := len(req.URL.Query().Get("forward")) > 0
localAddr := fmt.Sprintf("%s:%v", handler.address, handler.statusPort)
localAddr := net.JoinHostPort(handler.address, strconv.Itoa(int(handler.statusPort)))
exist, err := isExists(path)
if err != nil {
writeError(w, err)
Expand Down Expand Up @@ -124,7 +126,7 @@ func handleDownloadFile(handler downloadFileHandler, w http.ResponseWriter, req
if topo.IP == handler.address && topo.StatusPort == handler.statusPort {
continue
}
remoteAddr := fmt.Sprintf("%s:%v", topo.IP, topo.StatusPort)
remoteAddr := net.JoinHostPort(topo.IP, strconv.Itoa(int(topo.StatusPort)))
url := fmt.Sprintf("%s://%s/%s?forward=true", handler.scheme, remoteAddr, handler.urlPath)
resp, err := client.Get(url)
if err != nil {
Expand Down