[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.
This commit is contained in:
Mingyu Chen
2023-11-28 10:36:01 +08:00
committed by GitHub
parent c83e3318a8
commit 98c6885ae2
3 changed files with 24 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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.
*/

View File

@ -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()));