Skip to content

Commit

Permalink
client: backport ErrClientTSOStreamClosed
Browse files Browse the repository at this point in the history
Signed-off-by: lance6716 <[email protected]>
  • Loading branch information
lance6716 committed Aug 31, 2023
1 parent 71e8929 commit 4a9dde8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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 @@ package pd
import (
"context"
"fmt"
"io"
"math/rand"
"strings"
"sync"
Expand Down Expand Up @@ -1090,14 +1091,22 @@ func (c *client) processTSORequests(stream pdpb.PD_TsoClient, dcLocation string,
}

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 @@ func addrsToUrls(addrs []string) []string {

// 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

0 comments on commit 4a9dde8

Please sign in to comment.