Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 27, 2023
1 parent 4c2ae43 commit 745992b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions integration_tests/pd_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,34 @@ func (s *apiTestSuite) TestDCLabelClusterMinResolvedTS() {
require.Equal(uint64(150), s.store.GetMinSafeTS(dcLabel))
}

func (s *apiTestSuite) TestInitClusterMinResolvedTSZero() {
util.EnableFailpoints()
require := s.Require()
// Make sure `GetMinSafeTS` return 0 when cluster min resolved ts is 0.
s.store.SetMinSafeTS(oracle.GlobalTxnScope, 50)
require.Equal(uint64(50), s.store.GetMinSafeTS(oracle.GlobalTxnScope))
// Try to get the minimum resolved timestamp of the cluster from PD.
require.NoError(failpoint.Enable("tikvclient/mockFastSafeTSUpdater", `return()`))
defer func() {
require.NoError(failpoint.Disable("tikvclient/mockFastSafeTSUpdater"))
}()
require.NoError(failpoint.Enable("tikvclient/InjectMinResolvedTS", `return(0)`))
mockClient := storeSafeTsMockClient{
Client: s.store.GetTiKVClient(),
}
s.store.SetTiKVClient(&mockClient)
var retryCount int
for s.store.GetMinSafeTS(oracle.GlobalTxnScope) != 0 {
time.Sleep(100 * time.Millisecond)
if retryCount > 5 {
break
}
retryCount++
}
require.Equal(uint64(0), s.store.GetMinSafeTS(oracle.GlobalTxnScope))
require.NoError(failpoint.Disable("tikvclient/InjectMinResolvedTS"))
}

func (s *apiTestSuite) TearDownTest() {
if s.store != nil {
s.Require().Nil(s.store.Close())
Expand Down
9 changes: 9 additions & 0 deletions tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ func (s *KVStore) GetTiKVClient() (client Client) {
// GetMinSafeTS return the minimal safeTS of the storage with given txnScope.
func (s *KVStore) GetMinSafeTS(txnScope string) uint64 {
if val, ok := s.minSafeTS.Load(txnScope); ok {
if val.(uint64) == uint64(math.MaxUint64) {
return 0
}
return val.(uint64)
}
return 0
Expand Down Expand Up @@ -850,3 +853,9 @@ type SchemaVer = transaction.SchemaVer
// MaxTxnTimeUse is the max time a Txn may use (in ms) from its begin to commit.
// We use it to abort the transaction to guarantee GC worker will not influence it.
const MaxTxnTimeUse = transaction.MaxTxnTimeUse

// SetMinSafeTS set the minimal safeTS of the storage with given txnScope.
// Note: it is only used for test.
func (s *KVStore) SetMinSafeTS(txnScope string, safeTS uint64) {
s.minSafeTS.Store(txnScope, safeTS)
}

0 comments on commit 745992b

Please sign in to comment.