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 f6f183017f..30878a29ca 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 @@ -641,6 +641,9 @@ public class RestoreJob extends AbstractJob { return; } + // Reset properties to correct values. + remoteOlapTbl.resetPropertiesForRestore(); + // DO NOT set remote table's new name here, cause we will still need the origin name later // remoteOlapTbl.setName(jobInfo.getAliasByOriginNameIfSet(tblInfo.name)); remoteOlapTbl.setState(allowLoad ? OlapTableState.RESTORE_WITH_LOAD : OlapTableState.RESTORE); 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 13590e5f9c..d23a4609a0 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 @@ -420,6 +420,16 @@ public class OlapTable extends Table { } } + /** + * Reset properties to correct values. + */ + public void resetPropertiesForRestore() { + // disable dynamic partition + if (tableProperty != null) { + tableProperty.resetPropertiesForRestore(); + } + } + public Status resetIdsForRestore(Catalog catalog, Database db, ReplicaAllocation restoreReplicaAlloc) { // table id id = catalog.getNextId(); 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 427b09af0a..7c0d6f277e 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 @@ -102,6 +102,18 @@ public class TableProperty implements Writable { return this; } + /** + * Reset properties to correct values. + * @return this for chained + */ + public TableProperty resetPropertiesForRestore() { + if (properties.containsKey(DynamicPartitionProperty.ENABLE)) { + properties.put(DynamicPartitionProperty.ENABLE, "false"); + executeBuildDynamicProperty(); + } + return this; + } + public TableProperty buildDynamicProperty() throws DdlException { if (properties.containsKey(DynamicPartitionProperty.ENABLE) && Boolean.valueOf(properties.get(DynamicPartitionProperty.ENABLE)) 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 76dea1d59a..cc9d7f47f5 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 @@ -17,6 +17,7 @@ package org.apache.doris.catalog; +import com.google.common.collect.Maps; import mockit.Mock; import mockit.MockUp; @@ -28,12 +29,14 @@ import org.apache.doris.common.util.UnitTestUtil; import com.google.common.collect.Lists; +import org.junit.Assert; import org.junit.Test; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.List; +import java.util.Map; public class OlapTableTest { @@ -73,4 +76,43 @@ public class OlapTableTest { } + @Test + public void testResetPropertiesForRestore() { + // restore with other key + String otherKey = "other_key"; + String otherValue = "other_value"; + + Map properties = Maps.newHashMap(); + properties.put(otherKey, otherValue); + TableProperty tableProperty = new TableProperty(properties); + + OlapTable olapTable = new OlapTable(); + olapTable.setTableProperty(tableProperty); + + olapTable.resetPropertiesForRestore(); + Assert.assertEquals(tableProperty.getProperties(), olapTable.getTableProperty().getProperties()); + Assert.assertFalse(tableProperty.getDynamicPartitionProperty().isExist()); + + // restore with dynamic partition keys + properties = Maps.newHashMap(); + properties.put(DynamicPartitionProperty.ENABLE, "true"); + properties.put(DynamicPartitionProperty.TIME_UNIT, "HOUR"); + properties.put(DynamicPartitionProperty.TIME_ZONE, "Asia/Shanghai"); + properties.put(DynamicPartitionProperty.START, "-2147483648"); + properties.put(DynamicPartitionProperty.END, "3"); + properties.put(DynamicPartitionProperty.PREFIX, "dynamic"); + properties.put(DynamicPartitionProperty.BUCKETS, "10"); + properties.put(DynamicPartitionProperty.REPLICATION_NUM, "3"); + properties.put(DynamicPartitionProperty.CREATE_HISTORY_PARTITION, "false"); + + tableProperty = new TableProperty(properties); + olapTable.setTableProperty(tableProperty); + olapTable.resetPropertiesForRestore(); + + 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()); + } }