Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix the loss of bucket info after disable the dynamic partition #22595

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ public static Map<String, String> analyzeDynamicPartition(Map<String, String> pr
checkBuckets(bucketsValue);
properties.remove(DynamicPartitionProperty.BUCKETS);
analyzedProperties.put(DynamicPartitionProperty.BUCKETS, bucketsValue);
} else {
String bucketsValue = "0";
checkBuckets(bucketsValue);
properties.remove(DynamicPartitionProperty.BUCKETS);
analyzedProperties.put(DynamicPartitionProperty.BUCKETS, bucketsValue);
}
if (properties.containsKey(DynamicPartitionProperty.ENABLE)) {
String enableValue = properties.get(DynamicPartitionProperty.ENABLE);
Expand Down Expand Up @@ -430,10 +425,14 @@ public static void checkAndSetDynamicPartitionProperty(OlapTable olapTable, Map<
TableProperty tableProperty = olapTable.getTableProperty();
if (tableProperty != null) {
tableProperty.modifyTableProperties(dynamicPartitionProperties);
tableProperty.buildDynamicProperty();
} else {
olapTable.setTableProperty(new TableProperty(dynamicPartitionProperties).buildDynamicProperty());
tableProperty = new TableProperty(dynamicPartitionProperties);
olapTable.setTableProperty(tableProperty);
}
if (!tableProperty.getProperties().containsKey(DynamicPartitionProperty.BUCKETS)) {
tableProperty.modifyTableProperties(DynamicPartitionProperty.BUCKETS, "0");
}
tableProperty.buildDynamicProperty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,56 @@ public void test1AutoTabletWithDynamicPartition() throws Exception {
Assert.assertEquals(bucketNum, 20);
}

@Test
public void test1AutoTabletWithModifyDynamicPartitionProperty() throws Exception {
PseudoCluster cluster = PseudoCluster.getInstance();
cluster.runSql("db_for_auto_tablets",
" CREATE TABLE test_modify_dynamic_partition_property (" +
" k1 date," +
" k2 int(11)," +
" k3 smallint(6)," +
" v1 varchar(2048)," +
" v2 datetime" +
" ) ENGINE=OLAP" +
" DUPLICATE KEY(k1, k2, k3) " +
" PARTITION BY RANGE(k1)" +
" (PARTITION p20230306 VALUES [('2023-03-06'), ('2023-03-07')))" +
" DISTRIBUTED BY HASH(k2) BUCKETS 10" +
" PROPERTIES (" +
" 'replication_num' = '1'," +
" 'dynamic_partition.enable' = 'true'," +
" 'dynamic_partition.time_unit' = 'DAY'," +
" 'dynamic_partition.time_zone' = 'Asia/Shanghai'," +
" 'dynamic_partition.start' = '-1'," +
" 'dynamic_partition.end' = '3'," +
" 'dynamic_partition.buckets' = '3'," +
" 'dynamic_partition.prefix' = 'p');");
Thread.sleep(1000); // wait for the dynamic partition created
Database db = GlobalStateMgr.getCurrentState().getDb("db_for_auto_tablets");
if (db == null) {
return;
}

OlapTable table = (OlapTable) db.getTable("test_modify_dynamic_partition_property");
if (table == null) {
return;
}

cluster.runSql("db_for_auto_tablets", "ALTER TABLE test_modify_dynamic_partition_property SET ('dynamic_partition.enable' = 'false')");
cluster.runSql("db_for_auto_tablets", "ALTER TABLE test_modify_dynamic_partition_property ADD PARTITION p20230306 VALUES [('2023-03-06'), ('2023-03-07'))");
cluster.runSql("db_for_auto_tablets", "ALTER TABLE test_modify_dynamic_partition_property SET ('dynamic_partition.enable' = 'true')");

int bucketNum = 0;
db.readLock();
try {
Partition partition = table.getPartition("p20230306");
bucketNum = partition.getDistributionInfo().getBucketNum();
} finally {
db.readUnlock();
}
Assert.assertEquals(bucketNum, 20);
}

@Test
public void test1AutoTabletWithColocate() throws Exception {
PseudoCluster cluster = PseudoCluster.getInstance();
Expand Down