From d266b8fb50271ef52fa38aae61360ecb739cdd52 Mon Sep 17 00:00:00 2001 From: Mingyu Chen Date: Mon, 24 Oct 2022 09:42:28 +0800 Subject: [PATCH] [fix](restore) fix wrong replica allcation after restore (#13575) How to reproduce: 1. create a table with replica allocation, eg: ``` "replication_allocation"="tag.location.group_01:1, tag.location.group_02:1, tag.location.group_03:1" ``` 2. Backup this table 3. Restore this table with specific replication allocation, eg: `"replication_allocation" = "tag.location.default: 3"` 4. After restore, executing `show create table xxx`, you will be the `replication_allocation` is still: ``` "replication_allocation"="tag.location.group_01:1, tag.location.group_02:1, tag.location.group_03:1" ``` Not what we expected 5. But if you execute `show partitions from xxx`, the replication allocation of each partition is what we expected: ``` "replication_allocation" = "tag.location.default: 3" ``` This is because when doing restore job, we forget to set the "default" replica allocation property of the table. And the result of `show create table` is got from "default" replica allocation property, not from the real replica property of each partition --- .../src/main/java/org/apache/doris/backup/RestoreJob.java | 2 +- .../src/main/java/org/apache/doris/catalog/OlapTable.java | 4 ++-- .../main/java/org/apache/doris/catalog/TableProperty.java | 4 +++- .../test/java/org/apache/doris/catalog/OlapTableTest.java | 8 ++++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java index 87463ee2be..dad2bf3b11 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java @@ -672,7 +672,7 @@ public class RestoreJob extends AbstractJob { } // Reset properties to correct values. - remoteOlapTbl.resetPropertiesForRestore(reserveDynamicPartitionEnable); + remoteOlapTbl.resetPropertiesForRestore(reserveDynamicPartitionEnable, replicaAlloc); // DO NOT set remote table's new name here, cause we will still need the origin name later // remoteOlapTbl.setName(jobInfo.getAliasByOriginNameIfSet(tblInfo.name)); 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 faf009a1dd..79265f3451 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 @@ -425,9 +425,9 @@ public class OlapTable extends Table { /** * Reset properties to correct values. */ - public void resetPropertiesForRestore(boolean reserveDynamicPartitionEnable) { + public void resetPropertiesForRestore(boolean reserveDynamicPartitionEnable, ReplicaAllocation replicaAlloc) { if (tableProperty != null) { - tableProperty.resetPropertiesForRestore(reserveDynamicPartitionEnable); + tableProperty.resetPropertiesForRestore(reserveDynamicPartitionEnable, replicaAlloc); } // remove colocate property. setColocateGroup(null); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableProperty.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableProperty.java index 2883cf6917..14b518910e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableProperty.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableProperty.java @@ -118,7 +118,8 @@ public class TableProperty implements Writable { * * @return this for chained */ - public TableProperty resetPropertiesForRestore(boolean reserveDynamicPartitionEnable) { + public TableProperty resetPropertiesForRestore(boolean reserveDynamicPartitionEnable, + ReplicaAllocation replicaAlloc) { // disable dynamic partition if (properties.containsKey(DynamicPartitionProperty.ENABLE)) { if (!reserveDynamicPartitionEnable) { @@ -126,6 +127,7 @@ public class TableProperty implements Writable { } executeBuildDynamicProperty(); } + setReplicaAlloc(replicaAlloc); return this; } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java index c5de47f6e1..871389d6dd 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java @@ -89,11 +89,14 @@ public class OlapTableTest { olapTable.setTableProperty(tableProperty); olapTable.setColocateGroup("test_group"); Assert.assertTrue(olapTable.isColocateTable()); + Assert.assertTrue(olapTable.getDefaultReplicaAllocation() == ReplicaAllocation.DEFAULT_ALLOCATION); - olapTable.resetPropertiesForRestore(false); + ReplicaAllocation replicaAlloc = new ReplicaAllocation((short) 4); + olapTable.resetPropertiesForRestore(false, replicaAlloc); Assert.assertEquals(tableProperty.getProperties(), olapTable.getTableProperty().getProperties()); Assert.assertFalse(tableProperty.getDynamicPartitionProperty().isExist()); Assert.assertFalse(olapTable.isColocateTable()); + Assert.assertEquals((short) 4, olapTable.getDefaultReplicaAllocation().getTotalReplicaNum()); // restore with dynamic partition keys properties = Maps.newHashMap(); @@ -109,12 +112,13 @@ public class OlapTableTest { tableProperty = new TableProperty(properties); olapTable.setTableProperty(tableProperty); - olapTable.resetPropertiesForRestore(false); + olapTable.resetPropertiesForRestore(false, ReplicaAllocation.DEFAULT_ALLOCATION); Map expectedProperties = Maps.newHashMap(properties); expectedProperties.put(DynamicPartitionProperty.ENABLE, "false"); Assert.assertEquals(expectedProperties, olapTable.getTableProperty().getProperties()); Assert.assertTrue(olapTable.getTableProperty().getDynamicPartitionProperty().isExist()); Assert.assertFalse(olapTable.getTableProperty().getDynamicPartitionProperty().getEnable()); + Assert.assertEquals((short) 3, olapTable.getDefaultReplicaAllocation().getTotalReplicaNum()); } }