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

lightning: add retry for "write to tikv with no leader returned" #43480

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion br/pkg/lightning/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ func (local *local) WriteToTiKV(
}
}

// if there is not leader currently, we should directly return an error
// if there is no leader currently, we should directly return an error
if len(leaderPeerMetas) == 0 {
log.FromContext(ctx).Warn("write to tikv no leader", logutil.Region(region.Region), logutil.Leader(region.Leader),
zap.Uint64("leader_id", leaderID), logutil.SSTMeta(meta),
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/lightning/common/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var retryableErrorMsgList = []string{
// this error happens on when distsql.Checksum calls TiKV
// see https://github.com/pingcap/tidb/blob/2c3d4f1ae418881a95686e8b93d4237f2e76eec6/store/copr/coprocessor.go#L941
"coprocessor task terminated due to exceeding the deadline",
// this error happens when pd is transferring leader and we can retry it again
"write to tikv with no leader returned",
}

func isRetryableFromErrorMessage(err error) bool {
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/lightning/common/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func TestIsRetryableError(t *testing.T) {
require.True(t, IsRetryableError(status.Error(codes.Unavailable, "")))
require.True(t, IsRetryableError(status.Error(codes.DataLoss, "")))

require.True(t, IsRetryableError(errors.Errorf("write to tikv with no leader returned, region '%d', leader: %d", 1, 2)))

// sqlmock errors
require.False(t, IsRetryableError(fmt.Errorf("call to database Close was not expected")))
require.False(t, IsRetryableError(errors.New("call to database Close was not expected")))
Expand Down