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
commit 5115814d1d4f5a5b1f247628da340968208da2e4 Author: zhangdong <493738...@qq.com> AuthorDate: Wed Sep 25 10:38:31 2024 +0800 [enhance](mtmv)Optimize the logic of mtmv lock (#41010) - When deleting a job, do not query and delete it first. Instead, call the method to delete the job directly. If the job does not exist(When the materialized view only creates the table and the job is not yet created, the materialized view is concurrently deleted), throw an exception - When changing mtmv, narrow down the scope of the lock and place it in each sub method --- .../src/main/java/org/apache/doris/alter/Alter.java | 8 -------- .../src/main/java/org/apache/doris/catalog/MTMV.java | 2 ++ .../java/org/apache/doris/mtmv/MTMVJobManager.java | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java index e004565037e..1e1ebb40d9e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java @@ -967,8 +967,6 @@ public class Alter { try { Database db = Env.getCurrentInternalCatalog().getDbOrDdlException(tbl.getDb()); mtmv = (MTMV) db.getTableOrMetaException(tbl.getTbl(), TableType.MATERIALIZED_VIEW); - - mtmv.writeMvLock(); switch (alterMTMV.getOpType()) { case ALTER_REFRESH_INFO: mtmv.alterRefreshInfo(alterMTMV.getRefreshInfo()); @@ -981,8 +979,6 @@ public class Alter { break; case ADD_TASK: mtmv.addTaskResult(alterMTMV.getTask(), alterMTMV.getRelation(), alterMTMV.getPartitionSnapshots()); - Env.getCurrentEnv().getMtmvService() - .refreshComplete(mtmv, alterMTMV.getRelation(), alterMTMV.getTask()); break; default: throw new RuntimeException("Unknown type value: " + alterMTMV.getOpType()); @@ -995,10 +991,6 @@ public class Alter { } catch (UserException e) { // if MTMV has been dropped, ignore this exception LOG.warn(e); - } finally { - if (mtmv != null) { - mtmv.writeMvUnlock(); - } } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java index beda782ecfa..0bd11c40df3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java @@ -197,6 +197,8 @@ public class MTMV extends OlapTable { } this.jobInfo.addHistoryTask(task); this.refreshSnapshot.updateSnapshots(partitionSnapshots, getPartitionNames()); + Env.getCurrentEnv().getMtmvService() + .refreshComplete(this, relation, task); } finally { writeMvUnlock(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java index 1ace738f1d0..8ffcea423d7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java @@ -48,6 +48,8 @@ import org.apache.doris.qe.ConnectContext; import com.google.common.collect.Lists; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List; @@ -55,6 +57,8 @@ import java.util.List; * when do some operation, do something about job */ public class MTMVJobManager implements MTMVHookService { + private static final Logger LOG = LogManager.getLogger(MTMVJobManager.class); + public static final String MTMV_JOB_PREFIX = "inner_mtmv_"; /** @@ -124,16 +128,12 @@ public class MTMVJobManager implements MTMVHookService { */ @Override public void dropMTMV(MTMV mtmv) throws DdlException { - List<MTMVJob> jobs = Env.getCurrentEnv().getJobManager() - .queryJobs(JobType.MV, mtmv.getJobInfo().getJobName()); - if (!CollectionUtils.isEmpty(jobs)) { - try { - Env.getCurrentEnv().getJobManager() - .unregisterJob(jobs.get(0).getJobId()); - } catch (JobException e) { - e.printStackTrace(); - throw new DdlException(e.getMessage()); - } + try { + Env.getCurrentEnv().getJobManager() + .unregisterJob(mtmv.getJobInfo().getJobName(), false); + } catch (JobException e) { + LOG.warn("drop mtmv job failed, mtmvName: {}", mtmv.getName(), e); + throw new DdlException(e.getMessage()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org