Skip to content

Commit

Permalink
lightning: add timeout for "write" RPC (#48355) (#48398)
Browse files Browse the repository at this point in the history
close #46321, close #48352
  • Loading branch information
ti-chi-bot authored Nov 8, 2023
1 parent 90214cd commit f4dc06f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions br/pkg/lightning/backend/local/region_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ func (local *Backend) doWrite(ctx context.Context, j *regionJob) error {
failpoint.Return(err)
})

var cancel context.CancelFunc
ctx, cancel = context.WithTimeoutCause(ctx, 15*time.Minute, common.ErrWriteTooSlow)
defer cancel()

apiVersion := local.tikvCodec.GetAPIVersion()
clientFactory := local.importClientFactory
kvBatchSize := local.KVWriteBatchSize
Expand Down
8 changes: 7 additions & 1 deletion br/pkg/lightning/common/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ var retryableErrorIDs = map[errors.ErrorID]struct{}{
drivererr.ErrUnknown.ID(): {},
}

// ErrWriteTooSlow is used to get rid of the gRPC blocking issue.
// there are some strange blocking issues of gRPC like
// https://github.com/pingcap/tidb/issues/48352
// https://github.com/pingcap/tidb/issues/46321 and I don't know why 😭
var ErrWriteTooSlow = errors.New("write too slow, maybe gRPC is blocked forever")

func isSingleRetryableError(err error) bool {
err = errors.Cause(err)

switch err {
case nil, context.Canceled, context.DeadlineExceeded, io.EOF, sql.ErrNoRows:
return false
case mysql.ErrInvalidConn, driver.ErrBadConn:
case mysql.ErrInvalidConn, driver.ErrBadConn, ErrWriteTooSlow:
return true
}

Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/common/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
func TestIsRetryableError(t *testing.T) {
require.False(t, IsRetryableError(context.Canceled))
require.False(t, IsRetryableError(context.DeadlineExceeded))
require.True(t, IsRetryableError(ErrWriteTooSlow))
require.False(t, IsRetryableError(io.EOF))
require.False(t, IsRetryableError(&net.AddrError{}))
require.False(t, IsRetryableError(&net.DNSError{}))
Expand Down

0 comments on commit f4dc06f

Please sign in to comment.