Skip to content

Commit

Permalink
[fix](restore) Reset next version for restored partitions
Browse files Browse the repository at this point in the history
Cherry-pick apache#38321
  • Loading branch information
w41ter committed Jul 25, 2024
1 parent 8ad4390 commit 1eb3998
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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 @@ -1112,8 +1113,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 @@ -1143,6 +1145,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 @@ -348,6 +348,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 1eb3998

Please sign in to comment.