From 1b8a2338abba2d5a55a36648ca698599329b69e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=B2=9A?= <36239017+YuJuncen@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:08:17 +0800 Subject: [PATCH] restore: set config value to default when failed to get config from tikv (#36051) close pingcap/tidb#36053 --- br/pkg/conn/conn.go | 8 +++++--- br/pkg/conn/conn_test.go | 35 +++++++++++++++++++++++++++++++++-- br/pkg/task/restore.go | 5 +---- br/pkg/task/restore_raw.go | 5 +---- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/br/pkg/conn/conn.go b/br/pkg/conn/conn.go index 5adbe0a33ab1c..fff775bf1c1d7 100644 --- a/br/pkg/conn/conn.go +++ b/br/pkg/conn/conn.go @@ -281,7 +281,8 @@ func (mgr *Mgr) GetTS(ctx context.Context) (uint64, error) { } // GetMergeRegionSizeAndCount returns the tikv config `coprocessor.region-split-size` and `coprocessor.region-split-key`. -func (mgr *Mgr) GetMergeRegionSizeAndCount(ctx context.Context, client *http.Client) (uint64, uint64, error) { +// returns the default config when failed. +func (mgr *Mgr) GetMergeRegionSizeAndCount(ctx context.Context, client *http.Client) (uint64, uint64) { regionSplitSize := DefaultMergeRegionSizeBytes regionSplitKeys := DefaultMergeRegionKeyCount type coprocessor struct { @@ -310,9 +311,10 @@ func (mgr *Mgr) GetMergeRegionSizeAndCount(ctx context.Context, client *http.Cli return nil }) if err != nil { - return 0, 0, errors.Trace(err) + log.Warn("meet error when getting config from TiKV; using default", logutil.ShortError(err)) + return DefaultMergeRegionSizeBytes, DefaultMergeRegionKeyCount } - return regionSplitSize, regionSplitKeys, nil + return regionSplitSize, regionSplitKeys } // GetConfigFromTiKV get configs from all alive tikv stores. diff --git a/br/pkg/conn/conn_test.go b/br/pkg/conn/conn_test.go index 01ce8bc08203e..fc822fac123d9 100644 --- a/br/pkg/conn/conn_test.go +++ b/br/pkg/conn/conn_test.go @@ -292,6 +292,38 @@ func TestGetMergeRegionSizeAndCount(t *testing.T) { regionSplitSize: DefaultMergeRegionSizeBytes, regionSplitKeys: DefaultMergeRegionKeyCount, }, + { + stores: []*metapb.Store{ + { + Id: 1, + State: metapb.StoreState_Up, + Labels: []*metapb.StoreLabel{ + { + Key: "engine", + Value: "tiflash", + }, + }, + }, + { + Id: 2, + State: metapb.StoreState_Up, + Labels: []*metapb.StoreLabel{ + { + Key: "engine", + Value: "tikv", + }, + }, + }, + }, + content: []string{ + "", + // Assuming the TiKV has failed due to some reason. + "", + }, + // no tikv detected in this case + regionSplitSize: DefaultMergeRegionSizeBytes, + regionSplitKeys: DefaultMergeRegionKeyCount, + }, { stores: []*metapb.Store{ { @@ -388,8 +420,7 @@ func TestGetMergeRegionSizeAndCount(t *testing.T) { httpCli := mockServer.Client() mgr := &Mgr{PdController: &pdutil.PdController{}} mgr.PdController.SetPDClient(pdCli) - rs, rk, err := mgr.GetMergeRegionSizeAndCount(ctx, httpCli) - require.NoError(t, err) + rs, rk := mgr.GetMergeRegionSizeAndCount(ctx, httpCli) require.Equal(t, ca.regionSplitSize, rs) require.Equal(t, ca.regionSplitKeys, rk) mockServer.Close() diff --git a/br/pkg/task/restore.go b/br/pkg/task/restore.go index 83c22a29e61db..0a1ba11cad84e 100644 --- a/br/pkg/task/restore.go +++ b/br/pkg/task/restore.go @@ -494,10 +494,7 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf // according to https://github.com/pingcap/tidb/issues/34167. // we should get the real config from tikv to adapt the dynamic region. httpCli := httputil.NewClient(mgr.GetTLSConfig()) - mergeRegionSize, mergeRegionCount, err = mgr.GetMergeRegionSizeAndCount(ctx, httpCli) - if err != nil { - return errors.Trace(err) - } + mergeRegionSize, mergeRegionCount = mgr.GetMergeRegionSizeAndCount(ctx, httpCli) } keepaliveCfg.PermitWithoutStream = true diff --git a/br/pkg/task/restore_raw.go b/br/pkg/task/restore_raw.go index 6c15cd9989512..7b80ac18b4d87 100644 --- a/br/pkg/task/restore_raw.go +++ b/br/pkg/task/restore_raw.go @@ -80,10 +80,7 @@ func RunRestoreRaw(c context.Context, g glue.Glue, cmdName string, cfg *RestoreR // according to https://github.com/pingcap/tidb/issues/34167. // we should get the real config from tikv to adapt the dynamic region. httpCli := httputil.NewClient(mgr.GetTLSConfig()) - mergeRegionSize, mergeRegionCount, err = mgr.GetMergeRegionSizeAndCount(ctx, httpCli) - if err != nil { - return errors.Trace(err) - } + mergeRegionSize, mergeRegionCount = mgr.GetMergeRegionSizeAndCount(ctx, httpCli) } keepaliveCfg := GetKeepalive(&cfg.Config)