From 22e7c99378f0ec5149820c328538cbaf56b48cd4 Mon Sep 17 00:00:00 2001 From: zhanghe Date: Mon, 16 Dec 2024 11:13:26 +0800 Subject: [PATCH] [BugFix]The OP_DROP_TABLE_V2 event is not triggered when an error is reported for dropping a materialized view. (#53951) Signed-off-by: edwinhzhang (cherry picked from commit eefc8230d92a40e43a797d6a1fd5c52901583a58) --- .../com/starrocks/catalog/MaterializedView.java | 17 ++++++++++++++++- .../java/com/starrocks/qe/DDLStmtExecutor.java | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java b/fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java index 2726f8360fcf1..798ceca82b605 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java @@ -896,7 +896,22 @@ public void onDrop(Database db, boolean force, boolean replay) { // 2. Remove from base tables List baseTableInfos = getBaseTableInfos(); for (BaseTableInfo baseTableInfo : ListUtils.emptyIfNull(baseTableInfos)) { - Optional baseTableOpt = MvUtils.getTableWithIdentifier(baseTableInfo); + Optional
baseTableOpt; + try { + baseTableOpt = MvUtils.getTableWithIdentifier(baseTableInfo); + } catch (Exception e) { + if (!(baseTableInfo.isInternalCatalog())) { + GlobalStateMgr.getCurrentState().getConnectorTblMetaInfoMgr(). + removeConnectorTableInfo(baseTableInfo.getCatalogName(), + baseTableInfo.getDbName(), + baseTableInfo.getTableIdentifier(), + ConnectorTableInfo.builder().setRelatedMaterializedViews( + Sets.newHashSet(mvId)).build()); + } + LOG.error("Failed to get base table: {}", baseTableInfo, e); + continue; + } + if (baseTableOpt.isPresent()) { Table baseTable = baseTableOpt.get(); baseTable.removeRelatedMaterializedView(mvId); diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java index d8923fc50d1ad..632165b273fa4 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java @@ -177,7 +177,8 @@ public static ShowResultSet execute(StatementBase stmt, ConnectContext context) } else if (re.getCause() instanceof IOException) { throw (IOException) re.getCause(); } else if (re.getCause() != null) { - throw new DdlException(re.getCause().getMessage(), re); + throw new DdlException(re.getCause().getMessage() != null ? + re.getCause().getMessage() : re.getMessage(), re); } else { throw re; }