diff --git a/errors.toml b/errors.toml index 06848a79d1e..95324df1888 100644 --- a/errors.toml +++ b/errors.toml @@ -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 diff --git a/pkg/errs/errno.go b/pkg/errs/errno.go index a5e05219dfa..91cd4a78c4f 100644 --- a/pkg/errs/errno.go +++ b/pkg/errs/errno.go @@ -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")) diff --git a/pkg/tso/tso.go b/pkg/tso/tso.go index e7906e01c48..93392cecfcf 100644 --- a/pkg/tso/tso.go +++ b/pkg/tso/tso.go @@ -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())) diff --git a/server/server.go b/server/server.go index 55fc8b886f8..a72c1c23f0c 100644 --- a/server/server.go +++ b/server/server.go @@ -17,6 +17,7 @@ package server import ( "bytes" "context" + errorspkg "errors" "fmt" "math/rand" "net/http" @@ -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") } }) }()