[improvement](restore) set table property 'dynamic_partition.enable' to false after restore (#8852)

when restore table with dynamic partition properties, 'dynamic_partition.enable' is set to the backup time value.
but Doris could not turn on dynamic partition automatically when restore.
So we cloud see table never do dynamic partition with dynamic_partition.enable is set to 'true'.
This commit is contained in:
morrySnow
2022-04-07 11:34:01 +08:00
committed by GitHub
parent ce50c4d826
commit 64d18364db
4 changed files with 67 additions and 0 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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))

View File

@ -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<String, String> 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<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());
}
}