This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new d266b8fb50 [fix](restore) fix wrong replica allcation after restore 
(#13575)
d266b8fb50 is described below

commit d266b8fb50271ef52fa38aae61360ecb739cdd52
Author: Mingyu Chen <[email protected]>
AuthorDate: Mon Oct 24 09:42:28 2022 +0800

    [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
---
 fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java  | 2 +-
 fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java  | 4 ++--
 .../src/main/java/org/apache/doris/catalog/TableProperty.java     | 4 +++-
 .../src/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<String, String> 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());
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to