Skip to content

Commit

Permalink
[fix](restore) Reset next version for restored partitions (#38321)
Browse files Browse the repository at this point in the history
  • Loading branch information
w41ter authored and dataroaring committed Aug 16, 2024
1 parent 56a6813 commit 9530db5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 @@ -1139,8 +1140,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,
ReplicaAllocation replicaAlloc) {
@VisibleForTesting
protected Partition resetPartitionForRestore(OlapTable localTbl, OlapTable remoteTbl, String partName,
ReplicaAllocation replicaAlloc) {
Preconditions.checkState(localTbl.getPartition(partName) == null);
Partition remotePart = remoteTbl.getPartition(partName);
Preconditions.checkNotNull(remotePart);
Expand Down Expand Up @@ -1170,6 +1172,7 @@ 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);

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 Down Expand Up @@ -306,4 +309,28 @@ public void testSerialization() throws IOException, AnalysisException {
in.close();
Files.delete(path);
}

@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 9530db5

Please sign in to comment.