public Status resetIdsForRestore(GlobalStateMgr globalStateMgr, Database db, int restoreReplicationNum,
                                     MvRestoreContext mvRestoreContext) {
        // copy an origin index id to name map
        Map<Long, String> origIdxIdToName = Maps.newHashMap();
        for (Map.Entry<String, Long> entry : indexNameToId.entrySet()) {
            origIdxIdToName.put(entry.getValue(), entry.getKey());
        }

        // reset table id
        setId(globalStateMgr.getNextId());

        // reset all 'indexIdToXXX' map
        for (Map.Entry<Long, String> entry : origIdxIdToName.entrySet()) {
            long newIdxId = globalStateMgr.getNextId();
            if (entry.getValue().equals(name)) {
                // base index
                baseIndexId = newIdxId;
            }
            indexIdToMeta.put(newIdxId, indexIdToMeta.remove(entry.getKey()));
            indexIdToMeta.get(newIdxId).setIndexIdForRestore(newIdxId);
            indexNameToId.put(entry.getValue(), newIdxId);
        }

        // generate a partition name to id map
        Map<String, Long> origPartNameToId = Maps.newHashMap();
        for (Partition partition : idToPartition.values()) {
            origPartNameToId.put(partition.getName(), partition.getId());
            LOG.info("partition id {} sub partition {}", partition.getId(), partition.getSubPartitions());
        }

        // reset partition info and idToPartition map
        if (partitionInfo.isRangePartition()) {
            RangePartitionInfo rangePartitionInfo = (RangePartitionInfo) partitionInfo;
            for (Map.Entry<String, Long> entry : origPartNameToId.entrySet()) {
                long newPartId = globalStateMgr.getNextId();
                rangePartitionInfo.idToDataProperty.put(newPartId,
                        rangePartitionInfo.idToDataProperty.remove(entry.getValue()));
                rangePartitionInfo.idToReplicationNum.remove(entry.getValue());
                rangePartitionInfo.idToReplicationNum.put(newPartId,
                        (short) restoreReplicationNum);
                rangePartitionInfo.getIdToRange(false).put(newPartId,
                        rangePartitionInfo.getIdToRange(false).remove(entry.getValue()));

                rangePartitionInfo.idToInMemory
                        .put(newPartId, rangePartitionInfo.idToInMemory.remove(entry.getValue()));
                idToPartition.get(entry.getValue()).getSubPartitions().forEach(physicalPartition -> {
                    physicalPartitionIdToPartitionId.remove(physicalPartition.getId());
                    physicalPartitionNameToPartitionId.remove(physicalPartition.getName());
                });
                idToPartition.put(newPartId, idToPartition.remove(entry.getValue()));
                Partition partition = idToPartition.get(newPartId);
                partition.setIdForRestore(newPartId);
                partition.getSubPartitions().forEach(physicalPartition -> {
                    if (physicalPartition.getId() != newPartId) {
                        partition.removeSubPartition(physicalPartition.getId());
                        physicalPartition.setIdForRestore(globalStateMgr.getNextId());
                        physicalPartition.setParentId(newPartId);
                        partition.addSubPartition(physicalPartition);
                    }
                    physicalPartitionIdToPartitionId.put(physicalPartition.getId(), newPartId);
                    physicalPartitionNameToPartitionId.put(physicalPartition.getName(), newPartId);
                });
            }
        } else {
            // Single partitioned
            long newPartId = globalStateMgr.getNextId();
            for (Map.Entry<String, Long> entry : origPartNameToId.entrySet()) {
                partitionInfo.idToDataProperty.put(newPartId, partitionInfo.idToDataProperty.remove(entry.getValue()));
                partitionInfo.idToReplicationNum.remove(entry.getValue());
                partitionInfo.idToReplicationNum.put(newPartId, (short) restoreReplicationNum);
                partitionInfo.idToInMemory.put(newPartId, partitionInfo.idToInMemory.remove(entry.getValue()));
                idToPartition.get(entry.getValue()).getSubPartitions().forEach(physicalPartition -> {
                    physicalPartitionIdToPartitionId.remove(physicalPartition.getId());
                    physicalPartitionNameToPartitionId.remove(physicalPartition.getName());
                });
                idToPartition.put(newPartId, idToPartition.remove(entry.getValue()));
                Partition partition = idToPartition.get(newPartId);
                partition.setIdForRestore(newPartId);
                partition.getSubPartitions().forEach(physicalPartition -> {
                    if (physicalPartition.getId() != newPartId) {
                        partition.removeSubPartition(physicalPartition.getId());
                        physicalPartition.setIdForRestore(globalStateMgr.getNextId());
                        physicalPartition.setParentId(newPartId);
                        partition.addSubPartition(physicalPartition);
                    }
                    physicalPartitionIdToPartitionId.put(physicalPartition.getId(), newPartId);
                    physicalPartitionNameToPartitionId.put(physicalPartition.getName(), newPartId);
                });
            }
        }

        // reset replication number for olaptable
        setReplicationNum((short) restoreReplicationNum);

        // for each partition, reset rollup index map
        for (Map.Entry<Long, Partition> entry : idToPartition.entrySet()) {
            Partition partition = entry.getValue();
            for (PhysicalPartition physicalPartition : partition.getSubPartitions()) {
                for (Map.Entry<Long, String> entry2 : origIdxIdToName.entrySet()) {
                    System.out.println("entry2.getValue():" + entry2.getValue()
                            + " baseIndex: " + physicalPartition.getBaseIndex());
                    MaterializedIndex idx = physicalPartition.getIndex(entry2.getKey());
                    long newIdxId = indexNameToId.get(entry2.getValue());
                    int schemaHash = indexIdToMeta.get(newIdxId).getSchemaHash();
                    idx.setIdForRestore(newIdxId);
                    if (newIdxId != baseIndexId) {
                        // not base table, reset
                        physicalPartition.deleteRollupIndex(entry2.getKey());
                        physicalPartition.createRollupIndex(idx);
                    }

                    // generate new tablets in origin tablet order
                    int tabletNum = idx.getTablets().size();
                    idx.clearTabletsForRestore();
                    Status status = createTabletsForRestore(tabletNum, idx, globalStateMgr,
                            partitionInfo.getReplicationNum(entry.getKey()), physicalPartition.getVisibleVersion(),
                            schemaHash, physicalPartition.getId(), physicalPartition.getShardGroupId(), db);
                    if (!status.ok()) {
                        return status;
                    }
                }
            }
        }

        return Status.OK;
    }
@Test
    public void testSetIdForRestore() {
        Database db = UnitTestUtil.createDb(1, 2, 3, 4, 5, 6, 7, KeysType.AGG_KEYS);
        List<Table> tables = db.getTables();
        final long id = 0;
        new MockUp<GlobalStateMgr>() {
            @Mock
            long getNextId() {
                return id;
            }
        };

        for (Table table : tables) {
            if (table.getType() != TableType.OLAP) {
                continue;
            }
            ((OlapTable) table).resetIdsForRestore(GlobalStateMgr.getCurrentState(), db, 3, new MvRestoreContext());
        }
    }