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

client: backport ErrClientTSOStreamClosed #7021

Merged
merged 1 commit into from
Sep 4, 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
16 changes: 14 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import (
"context"
"fmt"
"io"
"math/rand"
"strings"
"sync"
Expand Down Expand Up @@ -1090,14 +1091,22 @@
}

if err := stream.Send(req); err != nil {
err = errors.WithStack(err)
if err == io.EOF {
err = errs.ErrClientTSOStreamClosed
} else {
err = errors.WithStack(err)

Check warning on line 1097 in client/client.go

View check run for this annotation

Codecov / codecov/patch

client/client.go#L1097

Added line #L1097 was not covered by tests
}
c.finishTSORequest(requests, 0, 0, 0, err)
return err
}
tsoBatchSendLatency.Observe(float64(time.Since(tbc.batchStartTime)))
resp, err := stream.Recv()
if err != nil {
err = errors.WithStack(err)
if err == io.EOF {
err = errs.ErrClientTSOStreamClosed

Check warning on line 1106 in client/client.go

View check run for this annotation

Codecov / codecov/patch

client/client.go#L1106

Added line #L1106 was not covered by tests
} else {
err = errors.WithStack(err)
}
c.finishTSORequest(requests, 0, 0, 0, err)
return err
}
Expand Down Expand Up @@ -1810,6 +1819,9 @@

// IsLeaderChange will determine whether there is a leader change.
func IsLeaderChange(err error) bool {
if err == errs.ErrClientTSOStreamClosed {
return true
}
errMsg := err.Error()
return strings.Contains(errMsg, errs.NotLeaderErr) || strings.Contains(errMsg, errs.MismatchLeaderErr)
}
Expand Down
1 change: 1 addition & 0 deletions client/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
// client errors
var (
ErrClientCreateTSOStream = errors.Normalize("create TSO stream failed, %s", errors.RFCCodeText("PD:client:ErrClientCreateTSOStream"))
ErrClientTSOStreamClosed = errors.Normalize("encountered TSO stream being closed unexpectedly", errors.RFCCodeText("PD:client:ErrClientTSOStreamClosed"))
ErrClientGetTSOTimeout = errors.Normalize("get TSO timeout", errors.RFCCodeText("PD:client:ErrClientGetTSOTimeout"))
ErrClientGetTSO = errors.Normalize("get TSO failed, %v", errors.RFCCodeText("PD:client:ErrClientGetTSO"))
ErrClientGetLeader = errors.Normalize("get leader from %v error", errors.RFCCodeText("PD:client:ErrClientGetLeader"))
Expand Down
Loading