Skip to content

Commit

Permalink
tso, server: ensure the reset TSO would NOT be updated at all (#7050)
Browse files Browse the repository at this point in the history
close #7049

Block the TSO update at the very beginning of `UpdateTimestamp` and refine the `updateAfterResetTSO` failpoint.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
JmPotato and ti-chi-bot[bot] authored Sep 6, 2023
1 parent 8e76ada commit 77d1998
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ error = '''
sync max ts failed, %s
'''

["PD:tso:ErrUpdateTimestamp"]
error = '''
update timestamp failed, %s
'''

["PD:typeutil:ErrBytesToUint64"]
error = '''
invalid data, must 8 bytes, but %d
Expand Down
1 change: 1 addition & 0 deletions pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
ErrSyncMaxTS = errors.Normalize("sync max ts failed, %s", errors.RFCCodeText("PD:tso:ErrSyncMaxTS"))
ErrResetUserTimestamp = errors.Normalize("reset user timestamp failed, %s", errors.RFCCodeText("PD:tso:ErrResetUserTimestamp"))
ErrGenerateTimestamp = errors.Normalize("generate timestamp failed, %s", errors.RFCCodeText("PD:tso:ErrGenerateTimestamp"))
ErrUpdateTimestamp = errors.Normalize("update timestamp failed, %s", errors.RFCCodeText("PD:tso:ErrUpdateTimestamp"))
ErrLogicOverflow = errors.Normalize("logic part overflow", errors.RFCCodeText("PD:tso:ErrLogicOverflow"))
ErrProxyTSOTimeout = errors.Normalize("proxy tso timeout", errors.RFCCodeText("PD:tso:ErrProxyTSOTimeout"))
ErrKeyspaceGroupIDInvalid = errors.Normalize("the keyspace group id is invalid, %s", errors.RFCCodeText("PD:tso:ErrKeyspaceGroupIDInvalid"))
Expand Down
3 changes: 3 additions & 0 deletions pkg/tso/tso.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ func (t *timestampOracle) resetUserTimestampInner(leadership *election.Leadershi
// NOTICE: this function should be called after the TSO in memory has been initialized
// and should not be called when the TSO in memory has been reset anymore.
func (t *timestampOracle) UpdateTimestamp(leadership *election.Leadership) error {
if !t.isInitialized() {
return errs.ErrUpdateTimestamp.FastGenByArgs("timestamp in memory has not been initialized")
}
prevPhysical, prevLogical := t.getTSO()
t.metrics.tsoPhysicalGauge.Set(float64(prevPhysical.UnixNano() / int64(time.Millisecond)))
t.metrics.tsoPhysicalGapGauge.Set(float64(time.Since(prevPhysical).Milliseconds()))
Expand Down
8 changes: 6 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package server
import (
"bytes"
"context"
errorspkg "errors"
"fmt"
"math/rand"
"net/http"
Expand Down Expand Up @@ -1669,8 +1670,11 @@ func (s *Server) campaignLeader() {
defer func() {
s.tsoAllocatorManager.ResetAllocatorGroup(tso.GlobalDCLocation)
failpoint.Inject("updateAfterResetTSO", func() {
if err = allocator.UpdateTSO(); err != nil {
panic(err)
if err = allocator.UpdateTSO(); !errorspkg.Is(err, errs.ErrUpdateTimestamp) {
log.Panic("the tso update after reset should return ErrUpdateTimestamp as expected", zap.Error(err))
}
if allocator.IsInitialize() {
log.Panic("the allocator should be uninitialized after reset")
}
})
}()
Expand Down

0 comments on commit 77d1998

Please sign in to comment.