Skip to content

Commit cf44157

Browse files
authored
lightning: init client-go global cfg (#45464) (#45467)
close #45462
1 parent c514581 commit cf44157

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

br/pkg/lightning/importer/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ go_library(
4444
"//br/pkg/utils",
4545
"//br/pkg/version",
4646
"//br/pkg/version/build",
47+
"//config",
4748
"//ddl",
4849
"//errno",
4950
"//keyspace",
@@ -78,6 +79,7 @@ go_library(
7879
"@com_github_pingcap_kvproto//pkg/import_sstpb",
7980
"@com_github_pingcap_kvproto//pkg/metapb",
8081
"@com_github_prometheus_client_golang//prometheus",
82+
"@com_github_tikv_client_go_v2//config",
8183
"@com_github_tikv_pd_client//:client",
8284
"@io_etcd_go_etcd_client_v3//:client",
8385
"@org_golang_google_grpc//:grpc",
@@ -107,7 +109,7 @@ go_test(
107109
],
108110
embed = [":importer"],
109111
flaky = True,
110-
shard_count = 49,
112+
shard_count = 50,
111113
deps = [
112114
"//br/pkg/lightning/backend",
113115
"//br/pkg/lightning/backend/encode",
@@ -159,6 +161,7 @@ go_test(
159161
"@com_github_pingcap_kvproto//pkg/metapb",
160162
"@com_github_stretchr_testify//require",
161163
"@com_github_stretchr_testify//suite",
164+
"@com_github_tikv_client_go_v2//config",
162165
"@com_github_xitongsys_parquet_go//writer",
163166
"@com_github_xitongsys_parquet_go_source//buffer",
164167
"@io_etcd_go_etcd_client_v3//:client",

br/pkg/lightning/importer/import.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/pingcap/tidb/br/pkg/utils"
5353
"github.com/pingcap/tidb/br/pkg/version"
5454
"github.com/pingcap/tidb/br/pkg/version/build"
55+
tidbconfig "github.com/pingcap/tidb/config"
5556
"github.com/pingcap/tidb/errno"
5657
tidbkv "github.com/pingcap/tidb/kv"
5758
"github.com/pingcap/tidb/meta/autoid"
@@ -65,6 +66,7 @@ import (
6566
regexprrouter "github.com/pingcap/tidb/util/regexpr-router"
6667
"github.com/pingcap/tidb/util/set"
6768
"github.com/prometheus/client_golang/prometheus"
69+
tikvconfig "github.com/tikv/client-go/v2/config"
6870
pd "github.com/tikv/pd/client"
6971
"go.uber.org/atomic"
7072
"go.uber.org/multierr"
@@ -357,6 +359,8 @@ func NewImportControllerWithPauser(
357359
}
358360
}
359361

362+
initGlobalConfig(tls.ToTiKVSecurityConfig())
363+
360364
encodingBuilder = local.NewEncodingBuilder(ctx)
361365
regionSizeGetter := &local.TableRegionSizeGetterImpl{
362366
DB: db,
@@ -2358,3 +2362,18 @@ func filterColumns(columnNames []string, extendData mydump.ExtendColumnData, ign
23582362
}
23592363
return filteredColumns, extendValueDatums
23602364
}
2365+
2366+
// check store liveness of tikv client-go requires GlobalConfig to work correctly, so we need to init it,
2367+
// else tikv will report SSL error when tls is enabled.
2368+
// and the SSL error seems affects normal logic of newer TiKV version, and cause the error "tikv: region is unavailable"
2369+
// during checksum.
2370+
// todo: DM relay on lightning physical mode too, but client-go doesn't support passing TLS data as bytes,
2371+
func initGlobalConfig(secCfg tikvconfig.Security) {
2372+
if secCfg.ClusterSSLCA != "" || secCfg.ClusterSSLCert != "" {
2373+
conf := tidbconfig.GetGlobalConfig()
2374+
conf.Security.ClusterSSLCA = secCfg.ClusterSSLCA
2375+
conf.Security.ClusterSSLCert = secCfg.ClusterSSLCert
2376+
conf.Security.ClusterSSLKey = secCfg.ClusterSSLKey
2377+
tidbconfig.StoreGlobalConfig(conf)
2378+
}
2379+
}

br/pkg/lightning/importer/import_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
tmock "github.com/pingcap/tidb/util/mock"
3939
router "github.com/pingcap/tidb/util/table-router"
4040
"github.com/stretchr/testify/require"
41+
tikvconfig "github.com/tikv/client-go/v2/config"
4142
)
4243

4344
func TestNewTableRestore(t *testing.T) {
@@ -415,3 +416,29 @@ func TestFilterColumns(t *testing.T) {
415416
require.Equal(t, expectedDatums, extendDatums)
416417
}
417418
}
419+
420+
func TestInitGlobalConfig(t *testing.T) {
421+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
422+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
423+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)
424+
initGlobalConfig(tikvconfig.Security{})
425+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
426+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
427+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)
428+
429+
initGlobalConfig(tikvconfig.Security{
430+
ClusterSSLCA: "ca",
431+
})
432+
require.NotEmpty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
433+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
434+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)
435+
436+
initGlobalConfig(tikvconfig.Security{})
437+
initGlobalConfig(tikvconfig.Security{
438+
ClusterSSLCert: "cert",
439+
ClusterSSLKey: "key",
440+
})
441+
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
442+
require.NotEmpty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
443+
require.NotEmpty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)
444+
}

0 commit comments

Comments
 (0)