|
92 | 92 | CommitMaxBackoff = uint64(40000) |
93 | 93 | ) |
94 | 94 |
|
| 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() func() { |
| 104 | + if !supportActiveActiveCommit.CompareAndSwap(true, false) { |
| 105 | + return func() {} |
| 106 | + } |
| 107 | + |
| 108 | + return func() { |
| 109 | + supportActiveActiveCommit.Store(true) |
| 110 | + } |
| 111 | +} |
| 112 | + |
95 | 113 | type kvstore interface { |
96 | 114 | // GetRegionCache gets the RegionCache. |
97 | 115 | GetRegionCache() *locate.RegionCache |
@@ -1504,6 +1522,10 @@ func sendTxnHeartBeat( |
1504 | 1522 |
|
1505 | 1523 | // checkAsyncCommit checks if async commit protocol is available for current transaction commit, true is returned if possible. |
1506 | 1524 | func (c *twoPhaseCommitter) checkAsyncCommit() bool { |
| 1525 | + if supportActiveActiveCommit.Load() { |
| 1526 | + return false |
| 1527 | + } |
| 1528 | + |
1507 | 1529 | // Disable async commit in local transactions |
1508 | 1530 | if c.txn.GetScope() != oracle.GlobalTxnScope { |
1509 | 1531 | return false |
@@ -1535,6 +1557,10 @@ func (c *twoPhaseCommitter) checkAsyncCommit() bool { |
1535 | 1557 |
|
1536 | 1558 | // checkOnePC checks if 1PC protocol is available for current transaction. |
1537 | 1559 | func (c *twoPhaseCommitter) checkOnePC() bool { |
| 1560 | + if supportActiveActiveCommit.Load() { |
| 1561 | + return false |
| 1562 | + } |
| 1563 | + |
1538 | 1564 | // Disable 1PC in local transactions |
1539 | 1565 | if c.txn.GetScope() != oracle.GlobalTxnScope { |
1540 | 1566 | return false |
|
0 commit comments