Skip to content

Commit

Permalink
[BugFix] Fix the loss of bucket info after disable the dynamic partit…
Browse files Browse the repository at this point in the history
…ion (StarRocks#22595)

If user create table using dynamic partition with dynamic_partition.buckets.
After they `SET ('dynamic_partition.enable' = 'true')` the buckets info is lost.
The pull request fix this by eliminate the remove the buckets info
  • Loading branch information
chaoyli authored and xiangguangyxg committed May 9, 2023
1 parent bb886b5 commit 17794b7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
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

0 comments on commit 17794b7

Please sign in to comment.