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

cmd, server: check the release version before starting the pd-server #7981

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the purpose of the modification to print warning logs to help debug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should directly panic here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will panic in MustParseVersion ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, otherwise it will panic during the leader campaign which might be too late to let the user be aware of the problem.

// 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) {
HuSharp marked this conversation as resolved.
Show resolved Hide resolved
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
Loading