@@ -71,6 +71,25 @@ bool TOperationsManager::Load(NTabletFlatExecutor::TTransactionContext& txc) {
71
71
return true ;
72
72
}
73
73
74
+ void TOperationsManager::BreakConflictingTxs (const TLockFeatures& lock) {
75
+ for (auto && i : lock.GetBrokeOnCommit ()) {
76
+ if (auto lockNotify = GetLockOptional (i)) {
77
+ AFL_WARN (NKikimrServices::TX_COLUMNSHARD_TX)(" broken_lock_id" , i);
78
+ lockNotify->SetBroken ();
79
+ }
80
+ }
81
+ for (auto && i : lock.GetNotifyOnCommit ()) {
82
+ if (auto lockNotify = GetLockOptional (i)) {
83
+ lockNotify->AddNotifyCommit (lock.GetLockId ());
84
+ }
85
+ }
86
+ }
87
+
88
+ void TOperationsManager::BreakConflictingTxs (const ui64 txId) {
89
+ auto & lock = GetLockFeaturesForTxVerified (txId);
90
+ BreakConflictingTxs (lock);
91
+ }
92
+
74
93
void TOperationsManager::CommitTransactionOnExecute (
75
94
TColumnShard& owner, const ui64 txId, NTabletFlatExecutor::TTransactionContext& txc, const NOlap::TSnapshot& snapshot) {
76
95
auto & lock = GetLockFeaturesForTxVerified (txId);
@@ -81,6 +100,9 @@ void TOperationsManager::CommitTransactionOnExecute(
81
100
opPtr->CommitOnExecute (owner, txc, snapshot);
82
101
commited.emplace_back (opPtr);
83
102
}
103
+
104
+ BreakConflictingTxs (lock);
105
+
84
106
OnTransactionFinishOnExecute (commited, lock, txId, txc);
85
107
}
86
108
@@ -89,18 +111,6 @@ void TOperationsManager::CommitTransactionOnComplete(
89
111
auto & lock = GetLockFeaturesForTxVerified (txId);
90
112
TLogContextGuard gLogging (
91
113
NActors::TLogContextBuilder::Build (NKikimrServices::TX_COLUMNSHARD_TX)(" commit_tx_id" , txId)(" commit_lock_id" , lock.GetLockId ()));
92
- for (auto && i : lock.GetBrokeOnCommit ()) {
93
- if (auto lockNotify = GetLockOptional (i)) {
94
- AFL_WARN (NKikimrServices::TX_COLUMNSHARD_TX)(" broken_lock_id" , i);
95
- lockNotify->SetBroken ();
96
- }
97
- }
98
-
99
- for (auto && i : lock.GetNotifyOnCommit ()) {
100
- if (auto lockNotify = GetLockOptional (i)) {
101
- lockNotify->AddNotifyCommit (lock.GetLockId ());
102
- }
103
- }
104
114
105
115
TVector<TWriteOperation::TPtr> commited;
106
116
for (auto && opPtr : lock.GetWriteOperations ()) {
@@ -317,10 +327,12 @@ void TOperationsManager::AddEventForLock(
317
327
NOlap::NTxInteractions::TTxConflicts txConflicts;
318
328
auto & txLock = GetLockVerified (lockId);
319
329
writer->CheckInteraction (lockId, InteractionsContext, txConflicts, txNotifications);
320
- for (auto && i : txConflicts) {
321
- if (GetLockOptional (i.first )) {
322
- GetLockVerified (i.first ).AddBrokeOnCommit (i.second );
323
- } else if (txLock.IsCommitted (i.first )) {
330
+ for (auto & [commitLockId, breakLockIds] : txConflicts) {
331
+ if (GetLockOptional (commitLockId)) {
332
+ GetLockVerified (commitLockId).AddBrokeOnCommit (breakLockIds);
333
+ // if txId not found, it means the conflicting tx is already committed or aborted
334
+ } else if (txLock.IsCommitted (commitLockId)) {
335
+ // if the conflicting tx is already committed, we cannot commit the given tx, so break its lock
324
336
txLock.SetBroken ();
325
337
}
326
338
}
0 commit comments