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

br: fix checksum incomplete when context is done #44583

Merged
merged 3 commits into from
Jun 16, 2023
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
13 changes: 12 additions & 1 deletion br/pkg/checksum/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,16 @@ func (exec *Executor) Execute(
updateChecksumResponse(checksumResp, resp)
updateFn()
}
return checksumResp, nil
return checksumResp, checkContextDone(ctx)
}

// The coprocessor won't return the error if the context is done,
// so sometimes BR would get the incomplete result.
// checkContextDone makes sure the result is not affected by CONTEXT DONE.
func checkContextDone(ctx context.Context) error {
Leavrth marked this conversation as resolved.
Show resolved Hide resolved
ctxErr := ctx.Err()
if ctxErr != nil {
return errors.Annotate(ctxErr, "context is cancelled by other error")
}
return nil
}
29 changes: 29 additions & 0 deletions br/pkg/checksum/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ func getTableInfo(t *testing.T, mock *mock.Cluster, db, table string) *model.Tab
return tableInfo.Meta()
}

func TestChecksumContextDone(t *testing.T) {
mock, err := mock.NewCluster()
require.NoError(t, err)
require.NoError(t, mock.Start())
defer mock.Stop()

tk := testkit.NewTestKit(t, mock.Storage)
tk.MustExec("use test")

tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 (a int, b int, key i1(a, b), primary key (a));")
tk.MustExec("insert into t1 values (10, 10);")
tableInfo1 := getTableInfo(t, mock, "test", "t1")
exe, err := checksum.NewExecutorBuilder(tableInfo1, math.MaxUint64).
SetConcurrency(variable.DefChecksumTableConcurrency).
Build()
require.NoError(t, err)

ctx := context.Background()
cctx, cancel := context.WithCancel(ctx)

cancel()

resp, err := exe.Execute(cctx, mock.Storage.GetClient(), func() { t.Log("request done") })
t.Log(err)
t.Log(resp)
require.Error(t, err)
}

func TestChecksum(t *testing.T) {
mock, err := mock.NewCluster()
require.NoError(t, err)
Expand Down