@@ -1166,7 +1166,21 @@ private void commitTransactionWithSubTxns(long dbId, List<Table> tableList, long
1166
1166
executeCommitTxnRequest (commitTxnRequest , transactionId , false , null );
1167
1167
}
1168
1168
1169
- // add some log and get commit lock, mainly used for mow tables
1169
+ private List <Table > getTablesNeedCommitLock (List <Table > tableList ) {
1170
+ if (Config .enable_commit_lock_for_all_tables ) {
1171
+ // If enabled, lock all tables
1172
+ return tableList .stream ()
1173
+ .sorted (Comparator .comparingLong (Table ::getId ))
1174
+ .collect (Collectors .toList ());
1175
+ } else {
1176
+ // If disabled, only lock MOW tables
1177
+ return tableList .stream ()
1178
+ .filter (table -> table instanceof OlapTable && ((OlapTable ) table ).getEnableUniqueKeyMergeOnWrite ())
1179
+ .sorted (Comparator .comparingLong (Table ::getId ))
1180
+ .collect (Collectors .toList ());
1181
+ }
1182
+ }
1183
+
1170
1184
private void beforeCommitTransaction (List <Table > tableList , long transactionId , long timeoutMillis )
1171
1185
throws UserException {
1172
1186
for (int i = 0 ; i < tableList .size (); i ++) {
@@ -1180,29 +1194,21 @@ private void beforeCommitTransaction(List<Table> tableList, long transactionId,
1180
1194
}
1181
1195
}
1182
1196
1183
- // Get tables that require commit lock - only MOW tables need this:
1184
- // 1. Filter to keep only OlapTables with MOW enabled
1185
- // 2. Sort by table ID to maintain consistent locking order and prevent deadlocks
1186
- List <Table > mowTableList = tableList .stream ()
1187
- .filter (table -> table instanceof OlapTable && ((OlapTable ) table ).getEnableUniqueKeyMergeOnWrite ())
1188
- .sorted (Comparator .comparingLong (Table ::getId ))
1189
- .collect (Collectors .toList ());
1190
- increaseWaitingLockCount (mowTableList );
1191
- if (!MetaLockUtils .tryCommitLockTables (mowTableList , timeoutMillis , TimeUnit .MILLISECONDS )) {
1192
- decreaseWaitingLockCount (mowTableList );
1197
+ List <Table > tablesToLock = getTablesNeedCommitLock (tableList );
1198
+ increaseWaitingLockCount (tablesToLock );
1199
+ if (!MetaLockUtils .tryCommitLockTables (tablesToLock , timeoutMillis , TimeUnit .MILLISECONDS )) {
1200
+ decreaseWaitingLockCount (tablesToLock );
1193
1201
// DELETE_BITMAP_LOCK_ERR will be retried on be
1194
1202
throw new UserException (InternalErrorCode .DELETE_BITMAP_LOCK_ERR ,
1195
1203
"get table cloud commit lock timeout, tableList=("
1196
- + StringUtils .join (mowTableList , "," ) + ")" );
1204
+ + StringUtils .join (tablesToLock , "," ) + ")" );
1197
1205
}
1198
1206
}
1199
1207
1200
1208
private void afterCommitTransaction (List <Table > tableList ) {
1201
- List <Table > mowTableList = tableList .stream ()
1202
- .filter (table -> table instanceof OlapTable && ((OlapTable ) table ).getEnableUniqueKeyMergeOnWrite ())
1203
- .collect (Collectors .toList ());
1204
- decreaseWaitingLockCount (mowTableList );
1205
- MetaLockUtils .commitUnlockTables (mowTableList );
1209
+ List <Table > tablesToUnlock = getTablesNeedCommitLock (tableList );
1210
+ decreaseWaitingLockCount (tablesToUnlock );
1211
+ MetaLockUtils .commitUnlockTables (tablesToUnlock );
1206
1212
}
1207
1213
1208
1214
@ Override
0 commit comments