Skip to content

Commit

Permalink
[improvement](mv) Catch exception when init sync materialized view co…
Browse files Browse the repository at this point in the history
…ntext #37701 (#37872)

## Proposed changes

cherry-pick 3.0
pr: #37701
commit: e478570


pr: #37154
commit: 841e39a

---------

Co-authored-by: starocean999 <[email protected]>
  • Loading branch information
seawinde and starocean999 authored Jul 16, 2024
1 parent d643e85 commit 2d7acd0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2990,4 +2990,13 @@ public long getRemoteDataSize() {
public long getReplicaCount() {
return statistics.getReplicaCount();
}

public boolean isShadowIndex(long indexId) {
String indexName = getIndexNameById(indexId);
if (indexName != null && indexName.startsWith(org.apache.doris.alter.SchemaChangeHandler.SHADOW_NAME_PREFIX)) {
return true;
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,38 +145,46 @@ private List<SyncMaterializationContext> createSyncMvContexts(OlapTable olapTabl
keyCount += column.isKey() ? 1 : 0;
}
for (Map.Entry<String, Long> entry : olapTable.getIndexNameToId().entrySet()) {
if (entry.getValue() != baseIndexId) {
MaterializedIndexMeta meta = olapTable.getIndexMetaByIndexId(entry.getValue());
String createMvSql;
if (meta.getDefineStmt() != null) {
// get the original create mv sql
createMvSql = meta.getDefineStmt().originStmt;
} else {
// it's rollup, need assemble create mv sql manually
if (olapTable.getKeysType() == KeysType.AGG_KEYS) {
createMvSql = assembleCreateMvSqlForAggTable(olapTable.getQualifiedName(),
entry.getKey(), meta.getSchema(false), keyCount);
long indexId = entry.getValue();
try {
// when doing schema change, a shadow index would be created and put together with mv indexes
// we must roll out these unexpected shadow indexes here
if (indexId != baseIndexId && !olapTable.isShadowIndex(indexId)) {
MaterializedIndexMeta meta = olapTable.getIndexMetaByIndexId(entry.getValue());
String createMvSql;
if (meta.getDefineStmt() != null) {
// get the original create mv sql
createMvSql = meta.getDefineStmt().originStmt;
} else {
createMvSql =
assembleCreateMvSqlForDupOrUniqueTable(olapTable.getQualifiedName(),
entry.getKey(), meta.getSchema(false));
// it's rollup, need assemble create mv sql manually
if (olapTable.getKeysType() == KeysType.AGG_KEYS) {
createMvSql = assembleCreateMvSqlForAggTable(olapTable.getQualifiedName(),
entry.getKey(), meta.getSchema(false), keyCount);
} else {
createMvSql =
assembleCreateMvSqlForDupOrUniqueTable(olapTable.getQualifiedName(),
entry.getKey(), meta.getSchema(false));
}
}
}
if (createMvSql != null) {
Optional<String> querySql =
new NereidsParser().parseForSyncMv(createMvSql);
if (!querySql.isPresent()) {
LOG.warn(String.format("can't parse %s ", createMvSql));
continue;
if (createMvSql != null) {
Optional<String> querySql =
new NereidsParser().parseForSyncMv(createMvSql);
if (!querySql.isPresent()) {
LOG.warn(String.format("can't parse %s ", createMvSql));
continue;
}
MTMVCache mtmvCache = MaterializedViewUtils.createMTMVCache(querySql.get(),
cascadesContext.getConnectContext());
contexts.add(new SyncMaterializationContext(mtmvCache.getLogicalPlan(),
mtmvCache.getOriginalPlan(), olapTable, meta.getIndexId(), entry.getKey(),
cascadesContext, mtmvCache.getStatistics()));
} else {
LOG.warn(String.format("can't assemble create mv sql for index ", entry.getKey()));
}
MTMVCache mtmvCache = MaterializedViewUtils.createMTMVCache(querySql.get(),
cascadesContext.getConnectContext());
contexts.add(new SyncMaterializationContext(mtmvCache.getLogicalPlan(),
mtmvCache.getOriginalPlan(), olapTable, meta.getIndexId(), entry.getKey(),
cascadesContext, mtmvCache.getStatistics()));
} else {
LOG.warn(String.format("can't assemble create mv sql for index ", entry.getKey()));
}
} catch (Exception exception) {
LOG.warn(String.format("createSyncMvContexts exception, index id is %s, index name is %s",
entry.getValue(), entry.getValue()), exception);
}
}
return contexts;
Expand Down

0 comments on commit 2d7acd0

Please sign in to comment.