Skip to content

Commit f9fa7b8

Browse files
committed
fix test
Signed-off-by: Wenqi Mou <[email protected]>
1 parent 723eb28 commit f9fa7b8

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

br/pkg/registry/registration.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,31 +247,30 @@ func (r *Registry) ResumeOrCreateRegistration(ctx context.Context, info Registra
247247
zap.String("uuid", operationUUID),
248248
zap.Strings("filters", info.FilterStrings))
249249
return taskID, nil
250-
} else {
251-
// task exists but was either created by another process or has been running
252-
// check if it's in running state
253-
runningRows, _, err := execCtx.ExecRestrictedSQL(
254-
kv.WithInternalSourceType(ctx, kv.InternalTxnBR),
255-
nil,
256-
fmt.Sprintf(getRunningTaskIDSQLTemplate, RegistrationDBName, RegistrationTableName),
257-
filterStrings, info.StartTS, info.RestoredTS, info.UpstreamClusterID, info.WithSysTable, info.Cmd)
258-
if err != nil {
259-
return 0, errors.Annotatef(err, "failed to check for running task")
260-
}
250+
}
251+
// task exists but was either created by another process or has been running
252+
// check if it's in running state
253+
runningRows, _, err := execCtx.ExecRestrictedSQL(
254+
kv.WithInternalSourceType(ctx, kv.InternalTxnBR),
255+
nil,
256+
fmt.Sprintf(getRunningTaskIDSQLTemplate, RegistrationDBName, RegistrationTableName),
257+
filterStrings, info.StartTS, info.RestoredTS, info.UpstreamClusterID, info.WithSysTable, info.Cmd)
258+
if err != nil {
259+
return 0, errors.Annotatef(err, "failed to check for running task")
260+
}
261261

262-
if len(runningRows) > 0 {
263-
taskID := runningRows[0].GetUint64(0)
264-
log.Warn("task already exists and is running",
265-
zap.Uint64("restore_id", taskID))
266-
return 0, errors.Annotatef(berrors.ErrInvalidArgument,
267-
"task with ID %d already exists and is running", taskID)
268-
}
269-
// Task exists but is not running - unexpected state
270-
log.Warn("task exists but is in an unexpected state",
271-
zap.Uint64("restore_id", taskID),
272-
zap.String("uuid", foundUUID))
273-
return 0, errors.New("task exists but is in an unexpected state")
262+
if len(runningRows) > 0 {
263+
taskID := runningRows[0].GetUint64(0)
264+
log.Warn("task already exists and is running",
265+
zap.Uint64("restore_id", taskID))
266+
return 0, errors.Annotatef(berrors.ErrInvalidArgument,
267+
"task with ID %d already exists and is running", taskID)
274268
}
269+
// Task exists but is not running - unexpected state
270+
log.Warn("task exists but is in an unexpected state",
271+
zap.Uint64("restore_id", taskID),
272+
zap.String("uuid", foundUUID))
273+
return 0, errors.New("task exists but is in an unexpected state")
275274
}
276275

277276
// no existing task found, create a new one
@@ -389,6 +388,8 @@ func (r *Registry) GetRegistrationsByMaxID(ctx context.Context, maxID uint64) ([
389388
}
390389

391390
for _, row := range rows {
391+
log.Info("found existing restore task", zap.Uint64("restore_id", row.GetUint64(0)),
392+
zap.Uint64("max_id", maxID))
392393
var (
393394
filterStrings = row.GetString(1)
394395
startTS = row.GetUint64(2)

br/pkg/restore/log_client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ func TestRepairIngestIndexFromCheckpoint(t *testing.T) {
21362136
_, err = tk.Exec("DROP DATABASE __TiDB_BR_Temporary_Log_Restore_Checkpoint")
21372137
require.NoError(t, err)
21382138
}()
2139-
logCheckpointMetaManager, err := checkpoint.NewLogTableMetaManager(g, s.Mock.Domain, checkpoint.LogRestoreCheckpointDatabaseName)
2139+
logCheckpointMetaManager, err := checkpoint.NewLogTableMetaManager(g, s.Mock.Domain, checkpoint.LogRestoreCheckpointDatabaseName, 1)
21402140
require.NoError(t, err)
21412141
defer logCheckpointMetaManager.Close()
21422142
require.NoError(t, logCheckpointMetaManager.SaveCheckpointIngestIndexRepairSQLs(ctx, &checkpoint.CheckpointIngestIndexRepairSQLs{

br/pkg/restore/misc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ LISTDBS:
9292
if tidbutil.IsMemOrSysDB(dbName) {
9393
continue
9494
}
95-
if IsBRInternalDB(dbName) {
95+
if IsBRInternalDB(db.Name.O) {
9696
continue
9797
}
9898
tables, err := m.ListSimpleTables(db.ID)

tests/realtikvtest/brietest/brie_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func TestExistedTables(t *testing.T) {
194194
require.NoError(t, err)
195195

196196
_, err = session.ResultSetToStringSlice(context.Background(), tk.Session(), res)
197-
require.ErrorContains(t, err, "table already exists")
197+
// due to previous restore didn't succeed with checkpoint enabled
198+
require.ErrorContains(t, err, "it is already being restored by task")
198199
}()
199200
select {
200201
case <-time.After(20 * time.Second):

0 commit comments

Comments
 (0)