Skip to content

Commit 0db0ebb

Browse files
committed
[opt](load) Add config to control commit lock scope for tables
1 parent 9a324bc commit 0db0ebb

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

fe/fe-common/src/main/java/org/apache/doris/common/Config.java

+9
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,15 @@ public static int metaServiceRpcRetryTimes() {
32813281
@ConfField(mutable = true, description = {"存算分离模式下commit阶段等锁超时时间,默认5s"})
32823282
public static int try_commit_lock_timeout_seconds = 5;
32833283

3284+
@ConfField(mutable = true, description = {
3285+
"是否在事务提交时对所有表启用提交锁。设置为 true 时,所有表都会使用提交锁。"
3286+
+ "设置为 false 时,仅对 Merge-On-Write 表使用提交锁。默认值为 true。",
3287+
"Whether to enable commit lock for all tables during transaction commit."
3288+
+ "If true, commit lock will be applied to all tables."
3289+
+ "If false, commit lock will only be applied to Merge-On-Write tables."
3290+
+ "Default value is true." })
3291+
public static boolean enable_commit_lock_for_all_tables = true;
3292+
32843293
@ConfField(mutable = true, description = {"存算分离模式下是否开启大事务提交,默认false"})
32853294
public static boolean enable_cloud_txn_lazy_commit = false;
32863295

fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,21 @@ private void commitTransactionWithSubTxns(long dbId, List<Table> tableList, long
11661166
executeCommitTxnRequest(commitTxnRequest, transactionId, false, null);
11671167
}
11681168

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+
11701184
private void beforeCommitTransaction(List<Table> tableList, long transactionId, long timeoutMillis)
11711185
throws UserException {
11721186
for (int i = 0; i < tableList.size(); i++) {
@@ -1180,29 +1194,21 @@ private void beforeCommitTransaction(List<Table> tableList, long transactionId,
11801194
}
11811195
}
11821196

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);
11931201
// DELETE_BITMAP_LOCK_ERR will be retried on be
11941202
throw new UserException(InternalErrorCode.DELETE_BITMAP_LOCK_ERR,
11951203
"get table cloud commit lock timeout, tableList=("
1196-
+ StringUtils.join(mowTableList, ",") + ")");
1204+
+ StringUtils.join(tablesToLock, ",") + ")");
11971205
}
11981206
}
11991207

12001208
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);
12061212
}
12071213

12081214
@Override

0 commit comments

Comments
 (0)