Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improvement](mv) Catch exception when init sync materialized view context #37701 #37872

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading