Skip to content

Commit

Permalink
[BugFix] Fix storage_cooldown_ttl for automatic partition (StarRocks#…
Browse files Browse the repository at this point in the history
…30021) (StarRocks#30031)

* Fix storage_cooldown_ttl for automatic partition
Signed-off-by: Astralidea <astralidea@163.com>
(cherry picked from commit 37468e6)

Co-authored-by: Felix Li <astralidea@163.com>
  • Loading branch information
mergify[bot] and Astralidea authored Aug 28, 2023
1 parent be7ab5f commit 8326990
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/alter/AlterJobMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,10 @@ public void modifyPartitionsProperty(Database db,
Partition partition = olapTable.getPartition(partitionName);
// 1. date property

if (partitionName.startsWith(ExpressionRangePartitionInfo.SHADOW_PARTITION_PREFIX)) {
continue;
}

if (newDataProperty != null) {
// for storage_cooldown_ttl
if (periodDuration != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,12 @@ public static PeriodDuration analyzeDataCachePartitionDuration(Map<String, Strin
return TimeUtils.parseHumanReadablePeriodOrDuration(text);
}

public static PeriodDuration analyzeStorageCoolDownTTL(Map<String, String> properties) throws AnalysisException {
public static PeriodDuration analyzeStorageCoolDownTTL(Map<String, String> properties,
boolean removeProperties) throws AnalysisException {
String text = properties.get(PROPERTIES_STORAGE_COOLDOWN_TTL);
properties.remove(PROPERTIES_STORAGE_COOLDOWN_TTL);
if (removeProperties) {
properties.remove(PROPERTIES_STORAGE_COOLDOWN_TTL);
}
if (Strings.isNullOrEmpty(text)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3494,7 +3494,7 @@ public void alterTableProperties(Database db, OlapTable table, Map<String, Strin
}
if (properties.containsKey(PropertyAnalyzer.PROPERTIES_STORAGE_COOLDOWN_TTL)) {
try {
PropertyAnalyzer.analyzeStorageCoolDownTTL(properties);
PropertyAnalyzer.analyzeStorageCoolDownTTL(properties, true);
} catch (AnalysisException ex) {
throw new RuntimeException(ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public Table createTable(LocalMetastore metastore, Database db, CreateTableStmt

if (properties != null) {
try {
PeriodDuration duration = PropertyAnalyzer.analyzeStorageCoolDownTTL(properties);
PeriodDuration duration = PropertyAnalyzer.analyzeStorageCoolDownTTL(properties, false);
if (duration != null) {
table.setStorageCoolDownTTL(duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Void visitModifyTablePropertiesClause(ModifyTablePropertiesClause clause,
} else if (properties.containsKey(PropertyAnalyzer.PROPERTIES_STORAGE_COOLDOWN_TTL)) {
String storageCoolDownTTL = properties.get(PropertyAnalyzer.PROPERTIES_STORAGE_COOLDOWN_TTL);
try {
PropertyAnalyzer.analyzeStorageCoolDownTTL(properties);
PropertyAnalyzer.analyzeStorageCoolDownTTL(properties, true);
} catch (AnalysisException e) {
ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,21 @@ public void testPrimaryKeyNotSupportCoolDown() {
" DISTRIBUTED BY HASH(k1)\n" +
" PROPERTIES (\"storage_medium\" = \"SSD\", \"storage_cooldown_ttl\" = \"0 day\");"
));

ExceptionChecker.expectThrowsWithMsg(DdlException.class,
"Invalid data property. storage medium property is not found",
() -> createTable(
"CREATE TABLE `cooldown_ttl_month1_table_with_null`\n" +
" ( `k1` date, `k2` datetime,`k3` string, `k4` varchar(20), " +
"`k5` boolean, `k6` tinyint, `k7` smallint, `k8` int, `k9` bigint, " +
"`k10` largeint, `k11` float, `k12` double, `k13` decimal(27,9))\n" +
" unique KEY(`k1`, `k2`, `k3`, `k4`, `k5`)\n" +
" PARTITION BY time_slice(k2, interval 1 month)\n" +
" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`)\n" +
" PROPERTIES (\"storage_cooldown_ttl\" = \"1 month\");"
));
}



}

0 comments on commit 8326990

Please sign in to comment.