Skip to content

Commit 8fe6317

Browse files
committed
[opt](load) Add config to control commit lock scope for tables
1 parent 60a0d1c commit 8fe6317

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,14 @@ 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 = {"是否在事务提交时对所有表启用提交锁。设置为 true 时,所有表都会使用提交锁。"
3285+
+ "设置为 false 时,仅对 Merge-On-Write 表使用提交锁。默认值为 true。",
3286+
"Whether to enable commit lock for all tables during transaction commit."
3287+
+ "If true, commit lock will be applied to all tables."
3288+
+ "If false, commit lock will only be applied to Merge-On-Write tables."
3289+
+ "Default value is true." })
3290+
public static boolean enable_commit_lock_for_all_tables = true;
3291+
32843292
@ConfField(mutable = true, description = {"存算分离模式下是否开启大事务提交,默认false"})
32853293
public static boolean enable_cloud_txn_lazy_commit = false;
32863294

@@ -3307,11 +3315,11 @@ public static int metaServiceRpcRetryTimes() {
33073315
public static int max_get_tablet_stat_task_threads_num = 4;
33083316

33093317
@ConfField(mutable = true, description = {"存算分离模式下schema change失败是否重试",
3310-
"Whether to enable retry when schema change failed in cloud model, default is true."})
3318+
"Whether to enable retry when schema change failed in cloud model, default is true."})
33113319
public static boolean enable_schema_change_retry_in_cloud_mode = true;
3312-
3320+
33133321
@ConfField(mutable = true, description = {"存算分离模式下schema change重试次数",
3314-
"Max retry times when schema change failed in cloud model, default is 3."})
3322+
"Max retry times when schema change failed in cloud model, default is 3."})
33153323
public static int schema_change_max_retry_time = 3;
33163324

33173325
// ATTN: DONOT add any config not related to cloud mode here

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)