From 98c6885ae27b2852666ac0a0a90b1e4e0a5e4e21 Mon Sep 17 00:00:00 2001 From: Mingyu Chen Date: Tue, 28 Nov 2023 10:36:01 +0800 Subject: [PATCH] [opt](plan) only lock olap table when query plan (#27639) For olap table, we need to acquire read lock when plan. Because we need to make sure the partition's version remain unchanged when plan. For other kind of table, no need to lock them. --- .../java/org/apache/doris/catalog/OlapTable.java | 13 ++++++++++++- .../main/java/org/apache/doris/catalog/TableIf.java | 9 +++++++++ .../org/apache/doris/nereids/CascadesContext.java | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index 54c881e682..94df98f000 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -2405,6 +2405,17 @@ public class OlapTable extends Table { @Override public boolean isPartitionColumn(String columnName) { return getPartitionInfo().getPartitionColumns().stream() - .anyMatch(c -> c.getName().equalsIgnoreCase(columnName)); + .anyMatch(c -> c.getName().equalsIgnoreCase(columnName)); + } + + /** + * For olap table, we need to acquire read lock when plan. + * Because we need to make sure the partition's version remain unchanged when plan. + * + * @return + */ + @Override + public boolean needReadLockWhenPlan() { + return true; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java index 0d0d910521..a958ff50d0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java @@ -153,6 +153,15 @@ public interface TableIf { void write(DataOutput out) throws IOException; + /** + * return true if this kind of table need read lock when doing query plan. + * + * @return + */ + default boolean needReadLockWhenPlan() { + return false; + } + /** * Doris table type. */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java index 3c21a988fb..4bcded3bc1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java @@ -536,6 +536,9 @@ public class CascadesContext implements ScheduleContext { cascadesContext.extractTables(plan); } for (TableIf table : cascadesContext.tables.values()) { + if (!table.needReadLockWhenPlan()) { + continue; + } if (!table.tryReadLock(1, TimeUnit.MINUTES)) { close(); throw new RuntimeException(String.format("Failed to get read lock on table: %s", table.getName()));