Skip to content

Commit eec1d4f

Browse files
authored
lightning: reduce the "unable to get keyspace name" log level to DEBUG (#54243)
close #54232
1 parent eaa6032 commit eec1d4f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lightning/pkg/importer/import.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ func NewImportControllerWithPauser(
407407
}
408408
p.TaskType = taskType
409409

410+
// TODO: we should not need to check config here.
411+
// Instead, we should perform the following during switch mode:
412+
// 1. for each tikv, try to switch mode without any ranges.
413+
// 2. if it returns normally, it means the store is using a raft-v1 engine.
414+
// 3. if it returns the `partitioned-raft-kv only support switch mode with range set` error,
415+
// it means the store is a raft-v2 engine and we will include the ranges from now on.
410416
isRaftKV2, err := common.IsRaftKV2(ctx, db)
411417
if err != nil {
412418
log.FromContext(ctx).Warn("check isRaftKV2 failed", zap.Error(err))

lightning/pkg/server/lightning.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,16 @@ func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, o *opti
566566
keyspaceName = taskCfg.TikvImporter.KeyspaceName
567567
if keyspaceName == "" {
568568
keyspaceName, err = getKeyspaceName(db)
569+
if err != nil && common.IsAccessDeniedNeedConfigPrivilegeError(err) {
570+
// if the cluster is not multitenant we don't really need to know about the keyspace.
571+
// since the doc does not say we require CONFIG privilege,
572+
// spelling out the Access Denied error just confuses the users.
573+
// hide such allowed errors unless log level is DEBUG.
574+
o.logger.Info("keyspace is unspecified and target user has no config privilege, assuming dedicated cluster")
575+
if o.logger.Level() > zapcore.DebugLevel {
576+
err = nil
577+
}
578+
}
569579
if err != nil {
570580
o.logger.Warn("unable to get keyspace name, lightning will use empty keyspace name", zap.Error(err))
571581
}

pkg/lightning/common/util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,3 +696,9 @@ func IsRaftKV2(ctx context.Context, db *sql.DB) (bool, error) {
696696
}
697697
return false, rows.Err()
698698
}
699+
700+
// IsAccessDeniedNeedConfigPrivilegeError checks if err is generated from a query to TiDB which failed due to missing CONFIG privilege.
701+
func IsAccessDeniedNeedConfigPrivilegeError(err error) bool {
702+
e, ok := err.(*mysql.MySQLError)
703+
return ok && e.Number == errno.ErrSpecificAccessDenied && strings.Contains(e.Message, "CONFIG")
704+
}

0 commit comments

Comments
 (0)