@@ -26,6 +26,7 @@ import (
26
26
"github.com/pingcap/kvproto/pkg/kvrpcpb"
27
27
"github.com/pingcap/tidb/pkg/store/mockstore/unistore"
28
28
"github.com/stretchr/testify/suite"
29
+ "github.com/tikv/client-go/v2/config"
29
30
"github.com/tikv/client-go/v2/config/retry"
30
31
tikverr "github.com/tikv/client-go/v2/error"
31
32
"github.com/tikv/client-go/v2/oracle"
@@ -466,3 +467,42 @@ func (s *testPipelinedMemDBSuite) TestPipelinedDMLFailedByPKRollback() {
466
467
s .NotNil (err )
467
468
s .ErrorContains (err , "ttl manager is closed" )
468
469
}
470
+
471
+ func (s * testPipelinedMemDBSuite ) TestPipelinedDMLFailedByPKMaxTTLExceeded () {
472
+ originManagedTTLVal := atomic .LoadUint64 (& transaction .ManagedLockTTL )
473
+ originMaxPipelinedTxnTTL := atomic .LoadUint64 (& transaction .MaxPipelinedTxnTTL )
474
+ atomic .StoreUint64 (& transaction .ManagedLockTTL , 100 ) // set to 100ms
475
+ atomic .StoreUint64 (& transaction .MaxPipelinedTxnTTL , 200 ) // set to 200ms
476
+ updateGlobalConfig (func (conf * config.Config ) {
477
+ conf .MaxTxnTTL = 200 // set to 200ms
478
+ })
479
+ defer func () {
480
+ atomic .StoreUint64 (& transaction .ManagedLockTTL , originManagedTTLVal )
481
+ atomic .StoreUint64 (& transaction .MaxPipelinedTxnTTL , originMaxPipelinedTxnTTL )
482
+ restoreGlobalConfFunc ()
483
+ }()
484
+
485
+ txn , err := s .store .Begin (tikv .WithPipelinedMemDB ())
486
+ s .Nil (err )
487
+ txn .Set ([]byte ("key1" ), []byte ("value1" ))
488
+ txnProbe := transaction.TxnProbe {KVTxn : txn }
489
+ flushed , err := txnProbe .GetMemBuffer ().Flush (true )
490
+ s .Nil (err )
491
+ s .True (flushed )
492
+ s .Nil (txn .GetMemBuffer ().FlushWait ())
493
+ s .Equal (txnProbe .GetCommitter ().GetPrimaryKey (), []byte ("key1" ))
494
+
495
+ s .True (txnProbe .GetCommitter ().IsTTLRunning ())
496
+
497
+ s .Eventuallyf (func () bool {
498
+ return ! txnProbe .GetCommitter ().IsTTLRunning ()
499
+ }, 5 * time .Second , 100 * time .Millisecond , "ttl manager should stop after max ttl" )
500
+
501
+ txn .Set ([]byte ("key2" ), []byte ("value2" ))
502
+ flushed , err = txn .GetMemBuffer ().Flush (true )
503
+ s .Nil (err )
504
+ s .True (flushed )
505
+ err = txn .GetMemBuffer ().FlushWait ()
506
+ s .NotNil (err )
507
+ s .ErrorContains (err , "ttl manager is closed" )
508
+ }
0 commit comments