This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-4.0-preview
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 801e21c2af84c818c145530861d5f817e2129411
Author: walter <[email protected]>
AuthorDate: Tue Apr 16 22:53:00 2024 +0800

    [fix](restore) Reset index id for restore (#33648)
---
 .../java/org/apache/doris/catalog/OlapTable.java   | 25 +++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index f35968ee22a..b90deafb407 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -669,17 +669,27 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
             // entry.getKey() is the new partition id, use it to get the 
restore specified
             // replica allocation
             ReplicaAllocation replicaAlloc = 
partitionInfo.getReplicaAllocation(entry.getKey());
+            // save the materialized indexes before create new index, to avoid 
ids confliction
+            // between two cluster.
+            Map<Long, MaterializedIndex> idToIndex = Maps.newHashMap();
             for (Map.Entry<Long, String> entry2 : origIdxIdToName.entrySet()) {
                 MaterializedIndex idx = partition.getIndex(entry2.getKey());
                 long newIdxId = indexNameToId.get(entry2.getValue());
-                int schemaHash = indexIdToMeta.get(newIdxId).getSchemaHash();
                 idx.setIdForRestore(newIdxId);
+                idToIndex.put(newIdxId, idx);
                 if (newIdxId != baseIndexId) {
-                    // not base table, reset
+                    // not base table, delete it.
                     partition.deleteRollupIndex(entry2.getKey());
+                }
+            }
+            for (Map.Entry<Long, MaterializedIndex> entry2 : 
idToIndex.entrySet()) {
+                Long idxId = entry2.getKey();
+                MaterializedIndex idx = entry2.getValue();
+                if (idxId != baseIndexId) {
+                    // not base table, add it.
                     partition.createRollupIndex(idx);
                 }
-
+                int schemaHash = indexIdToMeta.get(idxId).getSchemaHash();
                 // generate new tablets in origin tablet order
                 int tabletNum = idx.getTablets().size();
                 idx.clearTabletsForRestore();
@@ -712,6 +722,15 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
             partition.setIdForRestore(entry.getKey());
         }
 
+        // reset the indexes and update the indexes in materialized index meta 
too.
+        List<Index> indexes = this.indexes.getIndexes();
+        for (Index idx : indexes) {
+            idx.setIndexId(env.getNextId());
+        }
+        for (Map.Entry<Long, MaterializedIndexMeta> entry : 
indexIdToMeta.entrySet()) {
+            entry.getValue().setIndexes(indexes);
+        }
+
         return Status.OK;
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to