Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions br/pkg/lightning/importer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ go_library(
"//br/pkg/utils",
"//br/pkg/version",
"//br/pkg/version/build",
"//config",
"//ddl",
"//errno",
"//keyspace",
Expand Down Expand Up @@ -83,6 +84,7 @@ go_library(
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_tikv_client_go_v2//config",
"@com_github_tikv_pd_client//:client",
"@io_etcd_go_etcd_client_v3//:client",
"@org_golang_google_grpc//:grpc",
Expand Down Expand Up @@ -169,6 +171,7 @@ go_test(
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_stretchr_testify//require",
"@com_github_stretchr_testify//suite",
"@com_github_tikv_client_go_v2//config",
"@com_github_xitongsys_parquet_go//writer",
"@com_github_xitongsys_parquet_go_source//buffer",
"@io_etcd_go_etcd_client_v3//:client",
Expand Down
18 changes: 18 additions & 0 deletions br/pkg/lightning/importer/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/pingcap/tidb/br/pkg/version"
"github.com/pingcap/tidb/br/pkg/version/build"
tidbconfig "github.com/pingcap/tidb/config"
tidbkv "github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/parser"
Expand All @@ -61,6 +62,7 @@ import (
regexprrouter "github.com/pingcap/tidb/util/regexpr-router"
"github.com/pingcap/tidb/util/set"
"github.com/prometheus/client_golang/prometheus"
tikvconfig "github.com/tikv/client-go/v2/config"
pd "github.com/tikv/pd/client"
"go.uber.org/atomic"
"go.uber.org/multierr"
Expand Down Expand Up @@ -1526,6 +1528,7 @@ func (rc *Controller) importTables(ctx context.Context) (finalErr error) {
}
}

initGlobalConfig(rc.tls.ToTiKVSecurityConfig())
// Disable GC because TiDB enables GC already.
kvStore, err = driver.TiKVDriver{}.OpenWithOptions(
fmt.Sprintf("tikv://%s?disableGC=true&keyspaceName=%s", rc.cfg.TiDB.PdAddr, rc.keyspaceName),
Expand Down Expand Up @@ -2227,3 +2230,18 @@ func filterColumns(columnNames []string, extendData mydump.ExtendColumnData, ign
}
return filteredColumns, extendValueDatums
}

// check store liveness of tikv client-go requires GlobalConfig to work correctly, so we need to init it,
// else tikv will report SSL error when tls is enabled.
// and the SSL error seems affects normal logic of newer TiKV version, and cause the error "tikv: region is unavailable"
// during checksum.
// todo: DM relay on lightning physical mode too, but client-go doesn't support passing TLS data as bytes,
func initGlobalConfig(secCfg tikvconfig.Security) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move it to an earlier place? I'm not sure where's the first usage of tikv client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if secCfg.ClusterSSLCA != "" || secCfg.ClusterSSLCert != "" {
conf := tidbconfig.GetGlobalConfig()
conf.Security.ClusterSSLCA = secCfg.ClusterSSLCA
conf.Security.ClusterSSLCert = secCfg.ClusterSSLCert
conf.Security.ClusterSSLKey = secCfg.ClusterSSLKey
tidbconfig.StoreGlobalConfig(conf)
}
}
27 changes: 27 additions & 0 deletions br/pkg/lightning/importer/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
tmock "github.com/pingcap/tidb/util/mock"
router "github.com/pingcap/tidb/util/table-router"
"github.com/stretchr/testify/require"
tikvconfig "github.com/tikv/client-go/v2/config"
)

func TestNewTableRestore(t *testing.T) {
Expand Down Expand Up @@ -412,3 +413,29 @@ func TestFilterColumns(t *testing.T) {
require.Equal(t, expectedDatums, extendDatums)
}
}

func TestInitGlobalConfig(t *testing.T) {
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)
initGlobalConfig(tikvconfig.Security{})
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)

initGlobalConfig(tikvconfig.Security{
ClusterSSLCA: "ca",
})
require.NotEmpty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)

initGlobalConfig(tikvconfig.Security{})
initGlobalConfig(tikvconfig.Security{
ClusterSSLCert: "cert",
ClusterSSLKey: "key",
})
require.Empty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCA)
require.NotEmpty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLCert)
require.NotEmpty(t, tikvconfig.GetGlobalConfig().Security.ClusterSSLKey)
}