Skip to content

Commit

Permalink
retry when pd is not boostrapped (pingcap#43)
Browse files Browse the repository at this point in the history
Signed-off-by: David <[email protected]>

Signed-off-by: David <[email protected]>
  • Loading branch information
AmoebaProtozoa authored Sep 5, 2022
1 parent 910a86e commit 53a5c96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/coreos/go-semver/semver"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl/label"
"github.com/pingcap/tidb/ddl/placement"
Expand All @@ -44,6 +45,7 @@ import (
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/sessionctx/binloginfo"
"github.com/pingcap/tidb/sessionctx/variable"
store2 "github.com/pingcap/tidb/store"
"github.com/pingcap/tidb/store/helper"
"github.com/pingcap/tidb/types"
util2 "github.com/pingcap/tidb/util"
Expand Down Expand Up @@ -446,7 +448,14 @@ func removeVAndHash(v string) string {
func CheckTiKVVersion(store kv.Storage, minVersion semver.Version) error {
if store, ok := store.(kv.StorageWithPD); ok {
pdClient := store.GetPDClient()
stores, err := pdClient.GetAllStores(context.Background(), pd.WithExcludeTombstone())

var stores []*metapb.Store
var err error
err = util2.RunWithRetry(util2.DefaultMaxRetries, util2.RetryInterval, func() (bool, error) {
stores, err = pdClient.GetAllStores(context.Background(), pd.WithExcludeTombstone())
return store2.IsNotBootstrappedError(err), err
})

if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sync"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/logutil"
Expand Down Expand Up @@ -73,7 +74,7 @@ func newStoreWithRetry(path string, maxRetries int) (kv.Storage, error) {
err = util.RunWithRetry(maxRetries, util.RetryInterval, func() (bool, error) {
logutil.BgLogger().Info("new store", zap.String("path", path))
s, err = d.Open(path)
return kv.IsTxnRetryableError(err), err
return kv.IsTxnRetryableError(err) || IsNotBootstrappedError(err), err
})

if err == nil {
Expand All @@ -90,3 +91,11 @@ func loadDriver(name string) (kv.Driver, bool) {
d, ok := stores[name]
return d, ok
}

// IsNotBootstrappedError returns true if the error is pd not bootstrapped error.
func IsNotBootstrappedError(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), pdpb.ErrorType_NOT_BOOTSTRAPPED.String())
}

0 comments on commit 53a5c96

Please sign in to comment.