Skip to content

Commit 43201b6

Browse files
committed
*: disable async commit
Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
1 parent 70d01fd commit 43201b6

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

.github/workflows/integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Integration Test
22

33
on:
44
push:
5-
branches: [ master, tidb-8.5 ]
5+
branches: [ master, tidb-8.5, "feature/*" ]
66
pull_request:
7-
branches: [ master, tidb-8.5 ]
7+
branches: [ master, tidb-8.5, "feature/*" ]
88

99
jobs:
1010

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Unit Test
22

33
on:
44
push:
5-
branches: [master, tidb-8.5]
5+
branches: [master, tidb-8.5, "feature/*"]
66
pull_request:
7-
branches: [master, tidb-8.5]
7+
branches: [master, tidb-8.5, "feature/*"]
88

99
jobs:
1010
test:

integration_tests/2pc_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,9 @@ func (s *testCommitterSuite) TestResolveMixed() {
22222222
// TestSecondaryKeys tests that when async commit is enabled, each prewrite message includes an
22232223
// accurate list of secondary keys.
22242224
func (s *testCommitterSuite) TestPrewriteSecondaryKeys() {
2225+
transaction.DisableActiveActiveCommitSupportForTest()
2226+
defer transaction.RestoreActiveActiveCommitSupportForTest()
2227+
22252228
// Prepare two regions first: (, 100) and [100, )
22262229
region, _, _, _ := s.cluster.GetRegionByKey([]byte{50})
22272230
newRegionID := s.cluster.AllocID()
@@ -2256,6 +2259,9 @@ func (s *testCommitterSuite) TestPrewriteSecondaryKeys() {
22562259
}
22572260

22582261
func (s *testCommitterSuite) TestAsyncCommit() {
2262+
transaction.DisableActiveActiveCommitSupportForTest()
2263+
defer transaction.RestoreActiveActiveCommitSupportForTest()
2264+
22592265
ctx := context.Background()
22602266
pk := []byte("tpk")
22612267
pkVal := []byte("pkVal")
@@ -2344,6 +2350,9 @@ func restoreGlobalConfFunc() (restore func()) {
23442350
}
23452351

23462352
func (s *testCommitterSuite) TestAsyncCommitCheck() {
2353+
transaction.DisableActiveActiveCommitSupportForTest()
2354+
defer transaction.RestoreActiveActiveCommitSupportForTest()
2355+
23472356
defer restoreGlobalConfFunc()()
23482357
updateGlobalConfig(func(conf *config.Config) {
23492358
conf.TiKVClient.AsyncCommit.KeysLimit = 16

integration_tests/async_commit_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (c *unistoreClientWrapper) SendRequestAsync(ctx context.Context, addr strin
8787
func (c *unistoreClientWrapper) SetEventListener(listener tikv.ClientEventListener) {}
8888

8989
func (s *testAsyncCommitCommon) setUpTest() {
90+
transaction.DisableActiveActiveCommitSupportForTest()
9091
if *withTiKV {
9192
s.store = NewTestStore(s.T())
9293
return
@@ -105,6 +106,7 @@ func (s *testAsyncCommitCommon) setUpTest() {
105106

106107
func (s *testAsyncCommitCommon) tearDownTest() {
107108
s.store.Close()
109+
transaction.RestoreActiveActiveCommitSupportForTest()
108110
}
109111

110112
func (s *testAsyncCommitCommon) putAlphabets(enableAsyncCommit bool) {

txnkv/transaction/2pc.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ var (
9292
CommitMaxBackoff = uint64(40000)
9393
)
9494

95+
// supportActiveActiveCommit indicates whether the active-active commit protocol is supported.
96+
// If it is true (by default), we should not use async-commit or 1PC to ensure the commit timestamp
97+
// should follow the `tso-unique-index` constraint.
98+
var supportActiveActiveCommit = atomicutil.NewBool(true)
99+
100+
// DisableActiveActiveCommitSupportForTest disables the active-active commit for test,
101+
// which will make async-commit and 1PC work without the `tso-unique-index` constraint.
102+
// It should only be used in test.
103+
func DisableActiveActiveCommitSupportForTest() {
104+
supportActiveActiveCommit.Store(false)
105+
}
106+
107+
// RestoreActiveActiveCommitSupportForTest restores the default value of active-active commit support for test.
108+
// It should only be used in test.
109+
func RestoreActiveActiveCommitSupportForTest() {
110+
supportActiveActiveCommit.Store(true)
111+
}
112+
95113
type kvstore interface {
96114
// GetRegionCache gets the RegionCache.
97115
GetRegionCache() *locate.RegionCache
@@ -1504,6 +1522,10 @@ func sendTxnHeartBeat(
15041522

15051523
// checkAsyncCommit checks if async commit protocol is available for current transaction commit, true is returned if possible.
15061524
func (c *twoPhaseCommitter) checkAsyncCommit() bool {
1525+
if supportActiveActiveCommit.Load() {
1526+
return false
1527+
}
1528+
15071529
// Disable async commit in local transactions
15081530
if c.txn.GetScope() != oracle.GlobalTxnScope {
15091531
return false
@@ -1535,6 +1557,10 @@ func (c *twoPhaseCommitter) checkAsyncCommit() bool {
15351557

15361558
// checkOnePC checks if 1PC protocol is available for current transaction.
15371559
func (c *twoPhaseCommitter) checkOnePC() bool {
1560+
if supportActiveActiveCommit.Load() {
1561+
return false
1562+
}
1563+
15381564
// Disable 1PC in local transactions
15391565
if c.txn.GetScope() != oracle.GlobalTxnScope {
15401566
return false

0 commit comments

Comments
 (0)