Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning: release the requirement for NewTargetInfoGetterImpl #53651

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 3 deletions lightning/pkg/importer/get_pre_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ func NewTargetInfoGetterImpl(
case config.BackendTiDB:
backendTargetInfoGetter = tidb.NewTargetInfoGetter(targetDB)
case config.BackendLocal:
if pdHTTPCli == nil {
return nil, common.ErrUnknown.GenWithStack("pd HTTP client is required when using local backend")
}
backendTargetInfoGetter = local.NewTargetInfoGetter(tls, targetDB, pdHTTPCli)
default:
return nil, common.ErrUnknownBackend.GenWithStackByArgs(cfg.TikvImporter.Backend)
Expand Down
14 changes: 10 additions & 4 deletions lightning/pkg/importer/get_pre_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,16 +753,22 @@ func TestGetPreInfoEstimateSourceSize(t *testing.T) {
}

func TestGetPreInfoIsTableEmpty(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
db, mock, err := sqlmock.New()
require.NoError(t, err)
lnConfig := config.NewConfig()
lnConfig.TikvImporter.Backend = config.BackendLocal
_, err = NewTargetInfoGetterImpl(lnConfig, db, nil)
require.ErrorContains(t, err, "pd HTTP client is required when using local backend")
lnConfig.TikvImporter.Backend = config.BackendTiDB
targetGetter, err := NewTargetInfoGetterImpl(lnConfig, db, nil)
require.NoError(t, err)
mock.ExpectQuery("SELECT version()").
WillReturnRows(sqlmock.NewRows([]string{"version()"}).AddRow("8.0.11-TiDB-v8.2.0-alpha-256-qweqweqw"))
err = targetGetter.CheckVersionRequirements(ctx)
require.ErrorContains(t, err, "pd HTTP client is required for component version check in local backend")
require.NoError(t, mock.ExpectationsWereMet())

lnConfig.TikvImporter.Backend = config.BackendTiDB
targetGetter, err = NewTargetInfoGetterImpl(lnConfig, db, nil)
require.NoError(t, err)
require.Equal(t, lnConfig, targetGetter.cfg)

mock.ExpectQuery("SELECT 1 FROM `test_db`.`test_tbl` USE INDEX\\(\\) LIMIT 1").
Expand Down
13 changes: 11 additions & 2 deletions pkg/lightning/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ type targetInfoGetter struct {
pdHTTPCli pdhttp.Client
}

// NewTargetInfoGetter creates an TargetInfoGetter with local backend implementation.
func NewTargetInfoGetter(tls *common.TLS, db *sql.DB, pdHTTPCli pdhttp.Client) backend.TargetInfoGetter {
// NewTargetInfoGetter creates an TargetInfoGetter with local backend
// implementation. `pdHTTPCli` should not be nil when need to check component
// versions in CheckRequirements.
func NewTargetInfoGetter(
tls *common.TLS,
db *sql.DB,
pdHTTPCli pdhttp.Client,
) backend.TargetInfoGetter {
return &targetInfoGetter{
tls: tls,
targetDB: db,
Expand Down Expand Up @@ -293,6 +299,9 @@ func (g *targetInfoGetter) CheckRequirements(ctx context.Context, checkCtx *back
if err := checkTiDBVersion(ctx, versionStr, localMinTiDBVersion, localMaxTiDBVersion); err != nil {
return err
}
if g.pdHTTPCli == nil {
return common.ErrUnknown.GenWithStack("pd HTTP client is required for component version check in local backend")
}
if err := tikv.CheckPDVersion(ctx, g.pdHTTPCli, localMinPDVersion, localMaxPDVersion); err != nil {
return err
}
Expand Down