diff --git a/br/pkg/conn/conn.go b/br/pkg/conn/conn.go index 4ccf9f6561a02..cd96e8f68a992 100755 --- a/br/pkg/conn/conn.go +++ b/br/pkg/conn/conn.go @@ -27,6 +27,7 @@ import ( "github.com/pingcap/tidb/br/pkg/version" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" + "github.com/pingcap/tidb/util/engine" "github.com/tikv/client-go/v2/oracle" "github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/txnkv/txnlock" @@ -100,7 +101,7 @@ func GetAllTiKVStores( j := 0 for _, store := range stores { isTiFlash := false - if version.IsTiFlash(store) { + if engine.IsTiFlash(store) { if storeBehavior == SkipTiFlash { continue } else if storeBehavior == ErrorOnTiFlash { diff --git a/br/pkg/lightning/backend/local/local.go b/br/pkg/lightning/backend/local/local.go index 56f4cd0987c62..b0a807f2d7b76 100644 --- a/br/pkg/lightning/backend/local/local.go +++ b/br/pkg/lightning/backend/local/local.go @@ -58,6 +58,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/util/codec" + "github.com/pingcap/tidb/util/engine" "github.com/pingcap/tidb/util/mathutil" tikverror "github.com/tikv/client-go/v2/error" "github.com/tikv/client-go/v2/oracle" @@ -501,7 +502,7 @@ func (local *local) checkMultiIngestSupport(ctx context.Context) error { hasTiFlash := false for _, s := range stores { - if s.State == metapb.StoreState_Up && version.IsTiFlash(s) { + if s.State == metapb.StoreState_Up && engine.IsTiFlash(s) { hasTiFlash = true break } @@ -509,7 +510,7 @@ func (local *local) checkMultiIngestSupport(ctx context.Context) error { for _, s := range stores { // skip stores that are not online - if s.State != metapb.StoreState_Up || version.IsTiFlash(s) { + if s.State != metapb.StoreState_Up || engine.IsTiFlash(s) { continue } var err error @@ -1994,7 +1995,7 @@ func getRegionSplitSizeKeys(ctx context.Context, cli pd.Client, tls *common.TLS) return 0, 0, err } for _, store := range stores { - if store.StatusAddress == "" || version.IsTiFlash(store) { + if store.StatusAddress == "" || engine.IsTiFlash(store) { continue } serverInfo := infoschema.ServerInfo{ diff --git a/br/pkg/lightning/backend/local/local_test.go b/br/pkg/lightning/backend/local/local_test.go index 13112051e59d6..45030633b49c9 100644 --- a/br/pkg/lightning/backend/local/local_test.go +++ b/br/pkg/lightning/backend/local/local_test.go @@ -48,12 +48,12 @@ import ( "github.com/pingcap/tidb/br/pkg/pdutil" "github.com/pingcap/tidb/br/pkg/restore" "github.com/pingcap/tidb/br/pkg/utils" - "github.com/pingcap/tidb/br/pkg/version" tidbkv "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" + "github.com/pingcap/tidb/util/engine" "github.com/pingcap/tidb/util/hack" "github.com/stretchr/testify/require" pd "github.com/tikv/pd/client" @@ -1022,7 +1022,7 @@ func TestMultiIngest(t *testing.T) { return store.State == metapb.StoreState_Up }, func(s *metapb.Store) bool { - return !version.IsTiFlash(s) + return !engine.IsTiFlash(s) }, 0, nil, @@ -1035,7 +1035,7 @@ func TestMultiIngest(t *testing.T) { return store.State == metapb.StoreState_Up }, func(s *metapb.Store) bool { - return version.IsTiFlash(s) + return engine.IsTiFlash(s) }, 0, nil, @@ -1071,10 +1071,10 @@ func TestMultiIngest(t *testing.T) { // test all non-tiflash stores that support multi ingests { func(store *metapb.Store) bool { - return !version.IsTiFlash(store) + return !engine.IsTiFlash(store) }, func(s *metapb.Store) bool { - return !version.IsTiFlash(s) + return !engine.IsTiFlash(s) }, 0, nil, @@ -1110,7 +1110,7 @@ func TestMultiIngest(t *testing.T) { // test grpc return error but no tiflash { func(store *metapb.Store) bool { - return !version.IsTiFlash(store) + return !engine.IsTiFlash(store) }, func(s *metapb.Store) bool { return true @@ -1123,7 +1123,7 @@ func TestMultiIngest(t *testing.T) { // test grpc return error and contains offline tiflash { func(store *metapb.Store) bool { - return !version.IsTiFlash(store) || store.State != metapb.StoreState_Up + return !engine.IsTiFlash(store) || store.State != metapb.StoreState_Up }, func(s *metapb.Store) bool { return true diff --git a/br/pkg/lightning/restore/check_info.go b/br/pkg/lightning/restore/check_info.go index 6927a48d09488..7f181bb7755c3 100644 --- a/br/pkg/lightning/restore/check_info.go +++ b/br/pkg/lightning/restore/check_info.go @@ -38,6 +38,7 @@ import ( "github.com/pingcap/tidb/store/pdtypes" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/util/engine" "github.com/pingcap/tidb/util/mathutil" "go.uber.org/zap" "golang.org/x/exp/slices" @@ -169,15 +170,6 @@ func (rc *Controller) ClusterIsAvailable(ctx context.Context) { } } -func isTiFlash(store *pdtypes.MetaStore) bool { - for _, label := range store.Labels { - if label.Key == "engine" && label.Value == "tiflash" { - return true - } - } - return false -} - func (rc *Controller) checkEmptyRegion(ctx context.Context) error { passed := true message := "Cluster doesn't have too many empty regions" @@ -228,7 +220,7 @@ func (rc *Controller) checkEmptyRegion(ctx context.Context) error { if metapb.StoreState(metapb.StoreState_value[store.Store.StateName]) != metapb.StoreState_Up { continue } - if isTiFlash(store.Store) { + if engine.IsTiFlash(store.Store.Store) { continue } if regionCnt > errorThrehold { @@ -272,7 +264,7 @@ func (rc *Controller) checkRegionDistribution(ctx context.Context) error { if metapb.StoreState(metapb.StoreState_value[store.Store.StateName]) != metapb.StoreState_Up { continue } - if isTiFlash(store.Store) { + if engine.IsTiFlash(store.Store.Store) { continue } stores = append(stores, store) diff --git a/br/pkg/version/version.go b/br/pkg/version/version.go index c790125fd26fa..2a818a6ee4f85 100644 --- a/br/pkg/version/version.go +++ b/br/pkg/version/version.go @@ -18,6 +18,7 @@ import ( "github.com/pingcap/tidb/br/pkg/logutil" "github.com/pingcap/tidb/br/pkg/utils" "github.com/pingcap/tidb/br/pkg/version/build" + "github.com/pingcap/tidb/util/engine" pd "github.com/tikv/pd/client" "go.uber.org/zap" ) @@ -70,16 +71,6 @@ func checkTiFlashVersion(store *metapb.Store) error { return nil } -// IsTiFlash tests whether the store is based on tiflash engine. -func IsTiFlash(store *metapb.Store) bool { - for _, label := range store.Labels { - if label.Key == "engine" && label.Value == "tiflash" { - return true - } - } - return false -} - // VerChecker is a callback for the CheckClusterVersion, decides whether the cluster is suitable to execute restore. // See also: CheckVersionForBackup and CheckVersionForBR. type VerChecker func(store *metapb.Store, ver *semver.Version) error @@ -91,7 +82,7 @@ func CheckClusterVersion(ctx context.Context, client pd.Client, checker VerCheck return errors.Trace(err) } for _, s := range stores { - isTiFlash := IsTiFlash(s) + isTiFlash := engine.IsTiFlash(s) log.Debug("checking compatibility of store in cluster", zap.Uint64("ID", s.GetId()), zap.Bool("TiFlash?", isTiFlash), diff --git a/domain/infosync/info.go b/domain/infosync/info.go index 59dc9ede4c56f..f30db9a53d986 100644 --- a/domain/infosync/info.go +++ b/domain/infosync/info.go @@ -48,6 +48,7 @@ import ( "github.com/pingcap/tidb/types" util2 "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/dbterror" + "github.com/pingcap/tidb/util/engine" "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/pdapi" @@ -450,8 +451,8 @@ func CheckTiKVVersion(store kv.Storage, minVersion semver.Version) error { return err } for _, s := range stores { - // empty version means the store is a mock store. - if s.Version == "" { + // empty version means the store is a mock store. Don't require tiflash version either. + if s.Version == "" || engine.IsTiFlash(s) { continue } ver, err := semver.NewVersion(removeVAndHash(s.Version)) diff --git a/util/engine/engine.go b/util/engine/engine.go new file mode 100644 index 0000000000000..68c369154888e --- /dev/null +++ b/util/engine/engine.go @@ -0,0 +1,29 @@ +// Copyright 2022 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, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package engine + +import ( + "github.com/pingcap/kvproto/pkg/metapb" +) + +// IsTiFlash tests whether the store is based on tiflash engine. +func IsTiFlash(store *metapb.Store) bool { + for _, label := range store.Labels { + if label.Key == "engine" && label.Value == "tiflash" { + return true + } + } + return false +}