-
Notifications
You must be signed in to change notification settings - Fork 6k
dxf: add manual recovery mode #59641
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
Changes from all commits
c18a294
83bb880
6703cb5
7109a9f
c70fa69
ce55c0a
9941b6d
27e3283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,26 +15,84 @@ | |||||||||
package integrationtests | ||||||||||
|
||||||||||
import ( | ||||||||||
"context" | ||||||||||
"fmt" | ||||||||||
"sync/atomic" | ||||||||||
"testing" | ||||||||||
"time" | ||||||||||
|
||||||||||
"github.com/pingcap/errors" | ||||||||||
"github.com/pingcap/tidb/pkg/disttask/framework/proto" | ||||||||||
"github.com/pingcap/tidb/pkg/disttask/framework/storage" | ||||||||||
"github.com/pingcap/tidb/pkg/disttask/framework/taskexecutor/execute" | ||||||||||
"github.com/pingcap/tidb/pkg/disttask/framework/testutil" | ||||||||||
"github.com/pingcap/tidb/pkg/testkit" | ||||||||||
"github.com/stretchr/testify/require" | ||||||||||
) | ||||||||||
|
||||||||||
func TestRetryErrOnNextSubtasksBatch(t *testing.T) { | ||||||||||
func TestOnTaskError(t *testing.T) { | ||||||||||
c := testutil.NewTestDXFContext(t, 2, 16, true) | ||||||||||
registerExampleTask(t, c.MockCtrl, testutil.GetPlanErrSchedulerExt(c.MockCtrl, c.TestContext), c.TestContext, nil) | ||||||||||
submitTaskAndCheckSuccessForBasic(c.Ctx, t, "key1", c.TestContext) | ||||||||||
} | ||||||||||
|
||||||||||
func TestPlanNotRetryableOnNextSubtasksBatchErr(t *testing.T) { | ||||||||||
c := testutil.NewTestDXFContext(t, 2, 16, true) | ||||||||||
t.Run("retryable error on OnNextSubtasksBatch", func(t *testing.T) { | ||||||||||
registerExampleTask(t, c.MockCtrl, testutil.GetPlanErrSchedulerExt(c.MockCtrl, c.TestContext), c.TestContext, nil) | ||||||||||
submitTaskAndCheckSuccessForBasic(c.Ctx, t, "key1", c.TestContext) | ||||||||||
}) | ||||||||||
|
||||||||||
t.Run("non retryable error on OnNextSubtasksBatch", func(t *testing.T) { | ||||||||||
registerExampleTask(t, c.MockCtrl, testutil.GetPlanNotRetryableErrSchedulerExt(c.MockCtrl), c.TestContext, nil) | ||||||||||
task := testutil.SubmitAndWaitTask(c.Ctx, t, "key2-1", "", 1) | ||||||||||
require.Equal(t, proto.TaskStateReverted, task.State) | ||||||||||
registerExampleTask(t, c.MockCtrl, testutil.GetStepTwoPlanNotRetryableErrSchedulerExt(c.MockCtrl), c.TestContext, nil) | ||||||||||
task = testutil.SubmitAndWaitTask(c.Ctx, t, "key2-2", "", 1) | ||||||||||
require.Equal(t, proto.TaskStateReverted, task.State) | ||||||||||
}) | ||||||||||
|
||||||||||
prepareForAwaitingResolutionTestFn := func(t *testing.T, taskKey string) int64 { | ||||||||||
subtaskErrRetryable := atomic.Bool{} | ||||||||||
executorExt := testutil.GetTaskExecutorExt(c.MockCtrl, | ||||||||||
func(task *proto.Task) (execute.StepExecutor, error) { | ||||||||||
return testutil.GetCommonStepExecutor(c.MockCtrl, task.Step, func(ctx context.Context, subtask *proto.Subtask) error { | ||||||||||
if !subtaskErrRetryable.Load() { | ||||||||||
return errors.New("non retryable subtask error") | ||||||||||
} | ||||||||||
return nil | ||||||||||
}), nil | ||||||||||
}, | ||||||||||
func(error) bool { | ||||||||||
return subtaskErrRetryable.Load() | ||||||||||
}, | ||||||||||
) | ||||||||||
testutil.RegisterExampleTask(t, testutil.GetPlanErrSchedulerExt(c.MockCtrl, c.TestContext), | ||||||||||
executorExt, testutil.GetCommonCleanUpRoutine(c.MockCtrl)) | ||||||||||
tm, err := storage.GetTaskManager() | ||||||||||
require.NoError(t, err) | ||||||||||
taskID, err := tm.CreateTask(c.Ctx, taskKey, proto.TaskTypeExample, 1, "", | ||||||||||
2, proto.ExtraParams{ManualRecovery: true}, nil) | ||||||||||
require.NoError(t, err) | ||||||||||
require.Eventually(t, func() bool { | ||||||||||
task, err := tm.GetTaskByID(c.Ctx, taskID) | ||||||||||
require.NoError(t, err) | ||||||||||
return task.State == proto.TaskStateAwaitingResolution | ||||||||||
}, 10*time.Second, 100*time.Millisecond) | ||||||||||
subtaskErrRetryable.Store(true) | ||||||||||
return taskID | ||||||||||
} | ||||||||||
|
||||||||||
t.Run("task enter awaiting-resolution state if ManualRecovery set, success after manual recover", func(t *testing.T) { | ||||||||||
taskKey := "key3-1" | ||||||||||
taskID := prepareForAwaitingResolutionTestFn(t, taskKey) | ||||||||||
tk := testkit.NewTestKit(t, c.Store) | ||||||||||
tk.MustExec(fmt.Sprintf("update mysql.tidb_background_subtask set state='pending' where state='failed' and task_key= %d", taskID)) | ||||||||||
tk.MustExec(fmt.Sprintf("update mysql.tidb_global_task set state='running' where id = %d", taskID)) | ||||||||||
Comment on lines
+85
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task ID is being used directly in the SQL query, which could lead to SQL injection vulnerabilities. Use parameterized queries to avoid potential issues.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
task := testutil.WaitTaskDone(c.Ctx, t, taskKey) | ||||||||||
require.Equal(t, proto.TaskStateSucceed, task.State) | ||||||||||
}) | ||||||||||
|
||||||||||
registerExampleTask(t, c.MockCtrl, testutil.GetPlanNotRetryableErrSchedulerExt(c.MockCtrl), c.TestContext, nil) | ||||||||||
task := testutil.SubmitAndWaitTask(c.Ctx, t, "key1", "", 1) | ||||||||||
require.Equal(t, proto.TaskStateReverted, task.State) | ||||||||||
registerExampleTask(t, c.MockCtrl, testutil.GetStepTwoPlanNotRetryableErrSchedulerExt(c.MockCtrl), c.TestContext, nil) | ||||||||||
task = testutil.SubmitAndWaitTask(c.Ctx, t, "key2", "", 1) | ||||||||||
require.Equal(t, proto.TaskStateReverted, task.State) | ||||||||||
t.Run("task enter awaiting-resolution state if ManualRecovery set, cancel also works", func(t *testing.T) { | ||||||||||
taskKey := "key4-1" | ||||||||||
taskID := prepareForAwaitingResolutionTestFn(t, taskKey) | ||||||||||
require.NoError(t, c.TaskMgr.CancelTask(c.Ctx, taskID)) | ||||||||||
task := testutil.WaitTaskDone(c.Ctx, t, taskKey) | ||||||||||
require.Equal(t, proto.TaskStateReverted, task.State) | ||||||||||
}) | ||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task key is being used directly in the SQL query, which could lead to SQL injection vulnerabilities. Use parameterized queries to avoid potential issues.
Copilot uses AI. Check for mistakes.