Skip to content

Commit

Permalink
server: skip check tiflash version (#36451) (#36455)
Browse files Browse the repository at this point in the history
close #36449
  • Loading branch information
ti-srebot authored Jul 25, 2022
1 parent dc8403b commit 824fddc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 35 deletions.
3 changes: 2 additions & 1 deletion br/pkg/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions br/pkg/lightning/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -501,15 +502,15 @@ 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
}
}

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
Expand Down Expand Up @@ -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{
Expand Down
14 changes: 7 additions & 7 deletions br/pkg/lightning/backend/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 3 additions & 11 deletions br/pkg/lightning/restore/check_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 2 additions & 11 deletions br/pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions util/engine/engine.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 824fddc

Please sign in to comment.