[feature](mtmv)after creating a materialized view, if other operations fail, roll back (#28621)

after create mtmv, if create job failed,need drop mtmv
This commit is contained in:
zhangdong
2023-12-19 17:25:31 +08:00
committed by GitHub
parent 111185407c
commit a871409259
2 changed files with 17 additions and 2 deletions

View File

@ -134,6 +134,8 @@ import org.apache.doris.datasource.hive.HMSCachedClient;
import org.apache.doris.datasource.hive.HMSCachedClientFactory;
import org.apache.doris.datasource.property.constants.HMSProperties;
import org.apache.doris.external.elasticsearch.EsRepository;
import org.apache.doris.nereids.trees.plans.commands.info.DropMTMVInfo;
import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
import org.apache.doris.persist.AlterDatabasePropertyInfo;
import org.apache.doris.persist.AutoIncrementIdUpdateLog;
import org.apache.doris.persist.ColocatePersistInfo;
@ -2591,7 +2593,20 @@ public class InternalCatalog implements CatalogIf<Database> {
throw e;
}
if (olapTable instanceof MTMV) {
Env.getCurrentEnv().getMtmvService().createMTMV((MTMV) olapTable);
try {
Env.getCurrentEnv().getMtmvService().createMTMV((MTMV) olapTable);
} catch (Throwable t) {
LOG.warn("create mv failed, start rollback, error msg: " + t.getMessage());
try {
DropMTMVInfo dropMTMVInfo = new DropMTMVInfo(
new TableNameInfo(olapTable.getDatabase().getFullName(), olapTable.getName()), true);
Env.getCurrentEnv().dropTable(dropMTMVInfo.translateToLegacyStmt());
} catch (Throwable throwable) {
LOG.warn("rollback mv failed, please drop mv by manual, error msg: " + t.getMessage());
}
throw t;
}
}
}

View File

@ -470,7 +470,7 @@ public class MTMVUtil {
try {
table = getTable(baseTableInfo);
} catch (AnalysisException e) {
e.printStackTrace();
LOG.warn("get table failed, {}", baseTableInfo, e);
return false;
}
if (excludedTriggerTables.contains(table.getName())) {