[fix](restore) Reset the db name of the materialized index stmt #39710 (#39848)

cherry pick from #39710, #39855
This commit is contained in:
walter
2024-08-26 16:51:50 +08:00
committed by GitHub
parent 357394bb3e
commit 9412ba56ae
5 changed files with 141 additions and 7 deletions

View File

@ -609,8 +609,8 @@ public class BackupJob extends AbstractJob {
}
}
LOG.info("snapshot for partition {}, version: {}",
partition.getId(), visibleVersion);
LOG.info("snapshot for partition {}, version: {}, job: {}",
partition.getId(), visibleVersion, label);
}
return Status.OK;
}

View File

@ -744,7 +744,8 @@ public class RestoreJob extends AbstractJob {
}
// reset all ids in this table
Status st = remoteOlapTbl.resetIdsForRestore(env, db, replicaAlloc, reserveReplica);
String srcDbName = jobInfo.dbName;
Status st = remoteOlapTbl.resetIdsForRestore(env, db, replicaAlloc, reserveReplica, srcDbName);
if (!st.ok()) {
status = st;
return;

View File

@ -122,8 +122,15 @@ public class MaterializedIndexMeta implements Writable, GsonPostProcessable {
return indexId;
}
public void resetIndexIdForRestore(long id) {
public void resetIndexIdForRestore(long id, String srcDbName, String dbName) {
indexId = id;
// the source db name is not setted in old BackupMeta, keep compatible with the old one.
// See InitMaterializationContextHook.java:createSyncMvContexts for details.
if (defineStmt != null && srcDbName != null) {
String newStmt = defineStmt.originStmt.replaceAll(srcDbName, dbName);
defineStmt = new OriginStatement(newStmt, defineStmt.idx);
}
}
public KeysType getKeysType() {

View File

@ -578,7 +578,7 @@ public class OlapTable extends Table implements MTMVRelatedTableIf {
}
public Status resetIdsForRestore(Env env, Database db, ReplicaAllocation restoreReplicaAlloc,
boolean reserveReplica) {
boolean reserveReplica, String srcDbName) {
// ATTN: The meta of the restore may come from different clusters, so the
// original ID in the meta may conflict with the ID of the new cluster. For
// example, if a newly allocated ID happens to be the same as an original ID,
@ -604,7 +604,7 @@ public class OlapTable extends Table implements MTMVRelatedTableIf {
baseIndexId = newIdxId;
}
MaterializedIndexMeta indexMeta = origIdxIdToMeta.get(entry.getKey());
indexMeta.resetIndexIdForRestore(newIdxId);
indexMeta.resetIndexIdForRestore(newIdxId, srcDbName, db.getFullName());
indexIdToMeta.put(newIdxId, indexMeta);
indexNameToId.put(entry.getValue(), newIdxId);
}
@ -1603,7 +1603,7 @@ public class OlapTable extends Table implements MTMVRelatedTableIf {
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);
indexMeta.resetIndexIdForRestore(indexId, null, null);
}
}