Skip to content

Commit

Permalink
Handle feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
  • Loading branch information
binshi-bing committed Jun 28, 2023
1 parent 3144857 commit 3a48751
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions client/tso_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,16 +720,16 @@ func (c *tsoClient) processRequests(
c.finishRequest(requests, 0, 0, 0, err)
return err
}
// `logical` is the largest ts's logical part here, we need to do the subtracting before we finish each TSO request.
firstLogical := tsoutil.AddLogical(logical, -count+1, suffixBits)
curTSOInfo := &tsoInfo{
tsoServer: stream.getServerAddr(),
reqKeyspaceGroupID: reqKeyspaceGroupID,
respKeyspaceGroupID: respKeyspaceGroupID,
respReceivedAt: time.Now(),
physical: physical,
logical: logical, // `logical` is the returned largest ts's logical part
logical: tsoutil.AddLogical(firstLogical, count-1, suffixBits),
}
// Get the first logical from the largest logic returned to do the subtracting before we finish each TSO request.
firstLogical := tsoutil.AddLogical(logical, -count+1, suffixBits)
c.compareAndSwapTS(dcLocation, curTSOInfo, physical, firstLogical)
c.finishRequest(requests, physical, firstLogical, suffixBits, nil)
return nil
Expand All @@ -740,12 +740,11 @@ func (c *tsoClient) compareAndSwapTS(
curTSOInfo *tsoInfo,
physical, firstLogical int64,
) {
prevVal, loaded := c.lastTSOInfoMap.Swap(dcLocation, curTSOInfo)
val, loaded := c.lastTSOInfoMap.LoadOrStore(dcLocation, curTSOInfo)
if !loaded {
return
}
lastTSOInfo := prevVal.(*tsoInfo)

lastTSOInfo := val.(*tsoInfo)
if lastTSOInfo.respKeyspaceGroupID != curTSOInfo.respKeyspaceGroupID {
log.Info("[tso] keyspace group changed",
zap.String("dc-location", dcLocation),
Expand Down Expand Up @@ -773,6 +772,12 @@ func (c *tsoClient) compareAndSwapTS(
zap.Time("cur-response-received-at", curTSOInfo.respReceivedAt),
)
}
lastTSOInfo.tsoServer = curTSOInfo.tsoServer
lastTSOInfo.reqKeyspaceGroupID = curTSOInfo.reqKeyspaceGroupID
lastTSOInfo.respKeyspaceGroupID = curTSOInfo.respKeyspaceGroupID
lastTSOInfo.respReceivedAt = curTSOInfo.respReceivedAt
lastTSOInfo.physical = curTSOInfo.physical
lastTSOInfo.logical = curTSOInfo.logical
}

func (c *tsoClient) finishRequest(requests []*tsoRequest, physical, firstLogical int64, suffixBits uint32, err error) {
Expand Down

0 comments on commit 3a48751

Please sign in to comment.