Skip to content

Commit

Permalink
[fix](restore) Reset next version for restored partitions (#38344)
Browse files Browse the repository at this point in the history
Cherry-pick #38321
  • Loading branch information
w41ter authored Jul 25, 2024
1 parent 2bbd0aa commit f13363a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 8 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.apache.doris.thrift.TStorageType;
import org.apache.doris.thrift.TTaskType;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
Expand Down Expand Up @@ -1081,8 +1082,9 @@ private void createReplicas(Database db, AgentBatchTask batchTask, OlapTable loc

// reset remote partition.
// reset all id in remote partition, but DO NOT modify any exist catalog objects.
private Partition resetPartitionForRestore(OlapTable localTbl, OlapTable remoteTbl, String partName,
String clusterName, ReplicaAllocation replicaAlloc) {
@VisibleForTesting
protected Partition resetPartitionForRestore(OlapTable localTbl, OlapTable remoteTbl, String partName,
String clusterName, ReplicaAllocation replicaAlloc) {
Preconditions.checkState(localTbl.getPartition(partName) == null);
Partition remotePart = remoteTbl.getPartition(partName);
Preconditions.checkNotNull(remotePart);
Expand All @@ -1092,6 +1094,7 @@ private Partition resetPartitionForRestore(OlapTable localTbl, OlapTable remoteT

// generate new partition id
long newPartId = env.getNextId();
long oldPartId = remotePart.getId();
remotePart.setIdForRestore(newPartId);

// indexes
Expand All @@ -1111,6 +1114,9 @@ private Partition resetPartitionForRestore(OlapTable localTbl, OlapTable remoteT

// save version info for creating replicas
long visibleVersion = remotePart.getVisibleVersion();
remotePart.setNextVersion(visibleVersion + 1);
LOG.info("reset partition {} for restore, visible version: {}, old partition id: {}",
newPartId, visibleVersion, oldPartId);

// tablets
Map<Tag, Integer> nextIndexs = Maps.newHashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ public void setName(String newName) {
}
}

public void setPartitionInfo(PartitionInfo info) {
partitionInfo = info;
}

public boolean hasMaterializedIndex(String indexName) {
return indexNameToId.containsKey(indexName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import org.apache.doris.backup.BackupJobInfo.BackupTabletInfo;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.HashDistributionInfo;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.MaterializedIndex.IndexExtState;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Partition;
import org.apache.doris.catalog.PartitionInfo;
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.catalog.ReplicaAllocation;
import org.apache.doris.catalog.Resource;
import org.apache.doris.catalog.Table;
Expand All @@ -51,6 +54,7 @@
import mockit.Mock;
import mockit.MockUp;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -276,4 +280,27 @@ public void testSignature() throws AnalysisException {
System.out.println("tbl signature: " + tbl.getSignature(BackupHandler.SIGNATURE_VERSION, partNames));
}

@Test
public void testResetPartitionVisibleAndNextVersionForRestore() throws Exception {
long visibleVersion = 1234;
long remotePartId = 123;
String partName = "p20240723";
MaterializedIndex index = new MaterializedIndex();
Partition remotePart = new Partition(remotePartId, partName, index, new HashDistributionInfo());
remotePart.setVisibleVersionAndTime(visibleVersion, 0);
remotePart.setNextVersion(visibleVersion + 10);

OlapTable localTbl = new OlapTable();
localTbl.setPartitionInfo(new PartitionInfo(PartitionType.RANGE));
OlapTable remoteTbl = new OlapTable();
remoteTbl.addPartition(remotePart);
remoteTbl.setPartitionInfo(new PartitionInfo(PartitionType.RANGE));

ReplicaAllocation alloc = new ReplicaAllocation();
job.resetPartitionForRestore(localTbl, remoteTbl, partName, "", alloc);

Partition localPart = remoteTbl.getPartition(partName);
Assert.assertEquals(localPart.getVisibleVersion(), visibleVersion);
Assert.assertEquals(localPart.getNextVersion(), visibleVersion + 1);
}
}

0 comments on commit f13363a

Please sign in to comment.