Skip to content

Commit

Permalink
lightning: fix missing configurable keyspace name (#43685)
Browse files Browse the repository at this point in the history
close #43684
  • Loading branch information
zeminzhou committed May 12, 2023
1 parent 3e4538d commit 2ba3400
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion br/pkg/lightning/lightning.go
Expand Up @@ -550,7 +550,8 @@ func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, o *opti

var keyspaceName string
if taskCfg.TikvImporter.Backend == config.BackendLocal {
if taskCfg.TikvImporter.KeyspaceName == "" {
keyspaceName = taskCfg.TikvImporter.KeyspaceName
if keyspaceName == "" {
keyspaceName, err = getKeyspaceName(db)
if err != nil {
o.logger.Warn("unable to get keyspace name, lightning will use empty keyspace name", zap.Error(err))
Expand Down
7 changes: 5 additions & 2 deletions br/pkg/lightning/lightning_serial_test.go
Expand Up @@ -63,11 +63,12 @@ func TestRun(t *testing.T) {
path, _ := filepath.Abs(".")
ctx := context.Background()
db, mock, err := sqlmock.New()
logger, buffer := log.MakeTestLogger()
require.NoError(t, err)
o := &options{
promRegistry: lightning.promRegistry,
promFactory: lightning.promFactory,
logger: log.L(),
logger: logger,
db: db,
}
cfgCheckpoint := config.Config{
Expand All @@ -91,10 +92,12 @@ func TestRun(t *testing.T) {
cfgKeyspaceName.Checkpoint = cfgCheckpoint.Checkpoint
err = lightning.run(ctx, cfgKeyspaceName, o)
require.EqualError(t, err, "[Lightning:Checkpoint:ErrUnknownCheckpointDriver]unknown checkpoint driver 'invalid'")
require.Contains(t, buffer.String(), `"acquired keyspace name","keyspaceName":""`)

err = lightning.run(ctx, cfgKeyspaceName, o)
cfgKeyspaceName.TikvImporter.KeyspaceName = "test"
err = lightning.run(ctx, cfgKeyspaceName, o)
require.EqualError(t, err, "[Lightning:Checkpoint:ErrUnknownCheckpointDriver]unknown checkpoint driver 'invalid'")
require.Contains(t, buffer.String(), `"acquired keyspace name","keyspaceName":"test"`)
require.NoError(t, mock.ExpectationsWereMet())

err = lightning.run(ctx, &config.Config{
Expand Down

0 comments on commit 2ba3400

Please sign in to comment.