Skip to content

Commit

Permalink
[fix](Nereids) insert lock all target tables (#47033)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Related PR: #45045

Problem Summary:

we get target table twice, lock them all
  • Loading branch information
morrySnow authored and Your Name committed Jan 17, 2025
1 parent 5ddd8a9 commit bcba791
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -65,6 +66,7 @@
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;
Expand Down Expand Up @@ -172,7 +174,9 @@ public AbstractInsertExecutor initPlan(ConnectContext ctx, StmtExecutor executor
}
// 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 {}",
Expand All @@ -193,9 +197,9 @@ public AbstractInsertExecutor initPlan(ConnectContext ctx, StmtExecutor executor
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);
Expand Down

0 comments on commit bcba791

Please sign in to comment.