Skip to content

Commit

Permalink
cmd, server: check the release version before starting the pd-server (#…
Browse files Browse the repository at this point in the history
…7981)

close #7978

Move the release version check before the startup to ensure we can know it as soon as possible.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
JmPotato and ti-chi-bot[bot] authored Mar 27, 2024
1 parent 423e36c commit 5c58ddd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down

0 comments on commit 5c58ddd

Please sign in to comment.