From e43bc16703736b5aee4e531619d921e5e99d3acc Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 26 Mar 2024 14:15:27 +0800 Subject: [PATCH] Check the release version before starting the pd-server Signed-off-by: JmPotato --- cmd/pd-server/main.go | 2 ++ server/grpc_service.go | 2 +- server/server.go | 2 +- server/util.go | 14 +++++++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index d0f4e458412..0bf28ccfdea 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -221,6 +221,8 @@ func start(cmd *cobra.Command, args []string, services ...string) { exit(0) } + // Check the PD version first before running. + server.CheckAndGetPDVersion() // New zap logger err = logutil.SetupLogger(cfg.Log, &cfg.Logger, &cfg.LogProps, cfg.Security.RedactInfoLog) if err == nil { diff --git a/server/grpc_service.go b/server/grpc_service.go index b6cdce4c8b8..823f09b530b 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -833,7 +833,7 @@ func (s *GrpcServer) PutStore(ctx context.Context, request *pdpb.PutStoreRequest } log.Info("put store ok", zap.Stringer("store", store)) - CheckPDVersion(s.persistOptions) + CheckPDVersionWithClusterVersion(s.persistOptions) return &pdpb.PutStoreResponse{ Header: s.header(), diff --git a/server/server.go b/server/server.go index 5e8d3dea03b..410de96f63a 100644 --- a/server/server.go +++ b/server/server.go @@ -1800,7 +1800,7 @@ func (s *Server) campaignLeader() { member.ServiceMemberGauge.WithLabelValues(s.mode).Set(0) }) - CheckPDVersion(s.persistOptions) + CheckPDVersionWithClusterVersion(s.persistOptions) log.Info(fmt.Sprintf("%s leader is ready to serve", s.mode), zap.String("leader-name", s.Name())) leaderTicker := time.NewTicker(mcs.LeaderTickInterval) diff --git a/server/util.go b/server/util.go index f88d0146a7f..83455e2a6fe 100644 --- a/server/util.go +++ b/server/util.go @@ -21,6 +21,7 @@ import ( "path/filepath" "strings" + "github.com/coreos/go-semver/semver" "github.com/gorilla/mux" "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/pdpb" @@ -33,14 +34,21 @@ import ( "go.uber.org/zap" ) -// CheckPDVersion checks if PD needs to be upgraded. -func CheckPDVersion(opt *config.PersistOptions) { +// CheckAndGetPDVersion checks and returns the PD version. +func CheckAndGetPDVersion() *semver.Version { pdVersion := versioninfo.MinSupportedVersion(versioninfo.Base) if versioninfo.PDReleaseVersion != "None" { pdVersion = versioninfo.MustParseVersion(versioninfo.PDReleaseVersion) } + return pdVersion +} + +// CheckPDVersionWithClusterVersion checks if PD needs to be upgraded by comparing the PD version with the cluster version. +func CheckPDVersionWithClusterVersion(opt *config.PersistOptions) { + pdVersion := CheckAndGetPDVersion() clusterVersion := *opt.GetClusterVersion() - log.Info("load cluster version", zap.Stringer("cluster-version", clusterVersion)) + log.Info("load pd and cluster version", + zap.Stringer("pd-version", pdVersion), zap.Stringer("cluster-version", clusterVersion)) if pdVersion.LessThan(clusterVersion) { log.Warn( "PD version less than cluster version, please upgrade PD",