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, version: check and wait if cluster is incompatible #2695
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f70d62e
server, version: check and wait if cluster incompatible
overvenus fa19c27
address comments
overvenus 4272028
Merge branch 'master' into warn-incompatible
overvenus 7aaebfc
cdc: start status http server first
overvenus 8489d01
Merge branch 'warn-incompatible' of github.com:overvenus/ticdc into w…
overvenus 629b974
Merge branch 'master' into warn-incompatible
overvenus 92448ee
Merge branch 'warn-incompatible' of https://github.com/overvenus/ticd…
overvenus File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
"github.com/pingcap/ticdc/pkg/config" | ||
cerror "github.com/pingcap/ticdc/pkg/errors" | ||
"github.com/pingcap/ticdc/pkg/httputil" | ||
"github.com/pingcap/ticdc/pkg/retry" | ||
"github.com/pingcap/ticdc/pkg/util" | ||
"github.com/pingcap/ticdc/pkg/version" | ||
tidbkv "github.com/pingcap/tidb/kv" | ||
|
@@ -137,18 +138,7 @@ func (s *Server) Run(ctx context.Context) error { | |
return errors.Trace(err) | ||
} | ||
|
||
// To not block CDC server startup, we need to warn instead of error | ||
// when TiKV is incompatible. | ||
errorTiKVIncompatible := false | ||
for _, pdEndpoint := range s.pdEndpoints { | ||
err = version.CheckClusterVersion(ctx, s.pdClient, pdEndpoint, conf.Security, errorTiKVIncompatible) | ||
if err == nil { | ||
break | ||
} | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
checkAndWaitClusterVersion(ctx, s.pdClient, s.pdEndpoints, conf.Security) | ||
|
||
kv.InitWorkerPool() | ||
kvStore, err := kv.CreateTiStore(strings.Join(s.pdEndpoints, ","), conf.Security) | ||
|
@@ -367,3 +357,25 @@ func findBestDataDir(candidates []string) (result string, ok bool) { | |
|
||
return result, ok | ||
} | ||
|
||
func checkAndWaitClusterVersion( | ||
ctx context.Context, pdClient pd.Client, pdEndpoints []string, security *config.SecurityConfig, | ||
) { | ||
const backoffOneSecond = 1000 | ||
const errorTiKVIncompatible = true | ||
|
||
retry.Do(ctx, func() error { | ||
var err error | ||
for _, pdEndpoint := range pdEndpoints { | ||
err = version.CheckClusterVersion( | ||
ctx, pdClient, pdEndpoint, security, errorTiKVIncompatible) | ||
if err == nil { | ||
break | ||
} | ||
Comment on lines
+360
to
+362
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two scenarios have logic conflicts here.
|
||
log.Warn("check version", zap.Error(err)) | ||
} | ||
return err | ||
}, retry.WithInfiniteTries(), | ||
retry.WithBackoffBaseDelay(backoffOneSecond), retry.WithBackoffMaxDelay(backoffOneSecond)) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,9 @@ import ( | |
) | ||
|
||
var ( | ||
// minPDVersion is the version of the minimal compatible PD. | ||
// MinPDVersion is the version of the minimal compatible PD. | ||
// TODO bump 5.2.0-alpha once PD releases. | ||
minPDVersion *semver.Version = semver.New("5.1.0-alpha") | ||
MinPDVersion *semver.Version = semver.New("5.1.0-alpha") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this version be updated to 5.2.0-alpha, ditto for |
||
// maxPDVersion is the version of the maximum compatible PD. | ||
// Compatible versions are in [minPDVersion, maxPDVersion) | ||
// 9999.0.0 disables the check effectively in the master branch. | ||
|
@@ -127,10 +127,10 @@ func CheckClusterVersion( | |
return cerror.WrapError(cerror.ErrNewSemVersion, err) | ||
} | ||
|
||
minOrd := ver.Compare(*minPDVersion) | ||
minOrd := ver.Compare(*MinPDVersion) | ||
if minOrd < 0 { | ||
arg := fmt.Sprintf("PD %s is not supported, the minimal compatible version is %s", | ||
removeVAndHash(pdVer.Version), minPDVersion) | ||
removeVAndHash(pdVer.Version), MinPDVersion) | ||
return cerror.ErrVersionIncompatible.GenWithStackByArgs(arg) | ||
} | ||
maxOrd := ver.Compare(*maxPDVersion) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package version | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/pingcap/kvproto/pkg/metapb" | ||
pd "github.com/tikv/pd/client" | ||
) | ||
|
||
// MockPDClient mocks a pd client for tests. | ||
type MockPDClient struct { | ||
pd.Client | ||
GetAllStoresFunc func() []*metapb.Store | ||
GetVersionFunc func() string | ||
GetStatusCodeFunc func() int | ||
} | ||
|
||
// GetAllStores impls pd.Client.GetAllStores | ||
func (m *MockPDClient) GetAllStores(ctx context.Context, opts ...pd.GetStoreOption) ([]*metapb.Store, error) { | ||
if m.GetAllStoresFunc != nil { | ||
return m.GetAllStoresFunc(), nil | ||
} | ||
return []*metapb.Store{}, nil | ||
} | ||
|
||
func (m *MockPDClient) ServeHTTP(resp http.ResponseWriter, _ *http.Request) { | ||
// set status code at first, else will not work | ||
if m.GetStatusCodeFunc != nil { | ||
resp.WriteHeader(m.GetStatusCodeFunc()) | ||
} | ||
|
||
if m.GetVersionFunc != nil { | ||
_, _ = resp.Write([]byte(fmt.Sprintf(`{"version":"%s"}`, m.GetVersionFunc()))) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the parameter
errorTiKVIncompatible
can be removed from functionCheckClusterVersion