[fix](restore) Reset index id for MaterializedIndexMeta (#33831)

This commit is contained in:
walter
2024-04-18 17:06:31 +08:00
committed by yiguolei
parent 46fa64f34b
commit c8a92b82cc
2 changed files with 17 additions and 1 deletions

View File

@ -122,6 +122,10 @@ public class MaterializedIndexMeta implements Writable, GsonPostProcessable {
return indexId;
}
public void resetIndexIdForRestore(long id) {
indexId = id;
}
public KeysType getKeysType() {
return keysType;
}

View File

@ -591,7 +591,9 @@ public class OlapTable extends Table implements MTMVRelatedTableIf {
// base index
baseIndexId = newIdxId;
}
indexIdToMeta.put(newIdxId, origIdxIdToMeta.get(entry.getKey()));
MaterializedIndexMeta indexMeta = origIdxIdToMeta.get(entry.getKey());
indexMeta.resetIndexIdForRestore(newIdxId);
indexIdToMeta.put(newIdxId, indexMeta);
indexNameToId.put(entry.getValue(), newIdxId);
}
@ -1530,6 +1532,16 @@ public class OlapTable extends Table implements MTMVRelatedTableIf {
this.indexNameToId.put(indexName, indexId);
MaterializedIndexMeta indexMeta = MaterializedIndexMeta.read(in);
indexIdToMeta.put(indexId, indexMeta);
// HACK: the index id in MaterializedIndexMeta is not equals to the index id
// saved in OlapTable, because the table restore from snapshot is not reset
// the MaterializedIndexMeta correctly.
if (indexMeta.getIndexId() != indexId) {
LOG.warn("HACK: the index id {} in materialized index meta of {} is not equals"
+ " to the index saved in table {} ({}), reset it to {}",
indexMeta.getIndexId(), indexName, name, id, indexId);
indexMeta.resetIndexIdForRestore(indexId);
}
}
// partition and distribution info