This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 7e6fbd6f3cd branch-3.0: [fix](Nereids) insert lock all target tables
#47033 (#47243)
7e6fbd6f3cd is described below
commit 7e6fbd6f3cd250d01366965db1685e742c0a241a
Author: morrySnow <[email protected]>
AuthorDate: Tue Jan 21 10:35:36 2025 +0800
branch-3.0: [fix](Nereids) insert lock all target tables #47033 (#47243)
pick from master #47033
---
.../trees/plans/commands/insert/InsertIntoTableCommand.java | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
index 3a0e7d7c7f3..a7c8c3550ec 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
@@ -27,6 +27,7 @@ import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.profile.ProfileManager.ProfileType;
import org.apache.doris.common.util.DebugUtil;
+import org.apache.doris.common.util.MetaLockUtils;
import org.apache.doris.datasource.hive.HMSExternalTable;
import org.apache.doris.datasource.iceberg.IcebergExternalTable;
import org.apache.doris.datasource.jdbc.JdbcExternalTable;
@@ -61,10 +62,12 @@ import org.apache.doris.qe.StmtExecutor;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -172,7 +175,9 @@ public class InsertIntoTableCommand extends Command
implements ForwardWithSync,
}
// lock after plan and check does table's schema changed to ensure
we lock table order by id.
TableIf newestTargetTableIf =
RelationUtil.getTable(qualifiedTargetTableName, ctx.getEnv());
- newestTargetTableIf.readLock();
+ List<TableIf> targetTables = Lists.newArrayList(targetTableIf,
newestTargetTableIf);
+ targetTables.sort(Comparator.comparing(TableIf::getId));
+ MetaLockUtils.readLockTables(targetTables);
try {
if (targetTableIf.getId() != newestTargetTableIf.getId()) {
LOG.warn("insert plan failed {} times. query id is {}.
table id changed from {} to {}",
@@ -193,9 +198,9 @@ public class InsertIntoTableCommand extends Command
implements ForwardWithSync,
buildResult.physicalSink
);
}
- newestTargetTableIf.readUnlock();
+ MetaLockUtils.readUnlockTables(targetTables);
} catch (Throwable e) {
- newestTargetTableIf.readUnlock();
+ MetaLockUtils.readUnlockTables(targetTables);
// the abortTxn in onFail need to acquire table write lock
if (insertExecutor != null) {
insertExecutor.onFail(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]