This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new f3d8bce5e3c [fix](Nereids) insert lock all target tables (#47033)
f3d8bce5e3c is described below
commit f3d8bce5e3c74b94743649f433f25d7bc6a07431
Author: morrySnow <[email protected]>
AuthorDate: Thu Jan 16 11:58:17 2025 +0800
[fix](Nereids) insert lock all target tables (#47033)
### What problem does this PR solve?
Related PR: #45045
Problem Summary:
we get target table twice, lock them all
---
.../trees/plans/commands/insert/InsertIntoTableCommand.java | 10 +++++++---
1 file changed, 7 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 c65ce4a282d..76c72f82f90 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
@@ -28,6 +28,7 @@ import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
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;
@@ -72,6 +73,7 @@ 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;
@@ -184,7 +186,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 {}",
@@ -205,9 +209,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]