From 2e487ffd6440a267288d9489f0127d861f42d269 Mon Sep 17 00:00:00 2001 From: meegoo Date: Fri, 13 Sep 2024 21:19:11 +0800 Subject: [PATCH] [BugFix] Fix partition ttl loss after FE restart Signed-off-by: meegoo --- .../main/java/com/starrocks/catalog/TableProperty.java | 8 ++++++++ .../java/com/starrocks/catalog/TablePropertyTest.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java b/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java index 8cc1b865b2d2c..b1ad971b88872 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java @@ -47,6 +47,7 @@ import com.starrocks.catalog.constraint.ForeignKeyConstraint; import com.starrocks.catalog.constraint.UniqueConstraint; import com.starrocks.common.Config; +import com.starrocks.common.Pair; import com.starrocks.common.io.Text; import com.starrocks.common.io.Writable; import com.starrocks.common.util.PropertyAnalyzer; @@ -451,6 +452,13 @@ public TableProperty buildPartitionTTL() { if (properties.containsKey(PropertyAnalyzer.PROPERTIES_PARTITION_TTL_NUMBER)) { partitionTTLNumber = Integer.parseInt(properties.get(PropertyAnalyzer.PROPERTIES_PARTITION_TTL_NUMBER)); } + + if (properties.containsKey(PropertyAnalyzer.PROPERTIES_PARTITION_TTL)) { + Pair ttlDuration = PropertyAnalyzer.analyzePartitionTTL(properties); + if (ttlDuration != null) { + partitionTTL = ttlDuration.second; + } + } return this; } diff --git a/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java b/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java index 26d021c4b1d08..83fa452d231d7 100644 --- a/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java @@ -18,10 +18,12 @@ package com.starrocks.catalog; import com.starrocks.common.util.PropertyAnalyzer; +import com.starrocks.common.util.TimeUtils; import com.starrocks.persist.OperationType; import org.junit.After; import org.junit.Assert; import org.junit.Test; +import org.threeten.extra.PeriodDuration; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -105,10 +107,13 @@ public void testPartitionTTLNumberSerialization() throws IOException { HashMap properties = new HashMap<>(); properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_LIVE_NUMBER, "2"); + properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_TTL, "1 day"); + PeriodDuration duration = TimeUtils.parseHumanReadablePeriodOrDuration("1 day"); TableProperty tableProperty = new TableProperty(properties); tableProperty.buildPartitionLiveNumber(); tableProperty.buildPartitionTTL(); Assert.assertEquals(2, tableProperty.getPartitionTTLNumber()); + Assert.assertEquals(duration, tableProperty.getPartitionTTL()); tableProperty.write(out); out.flush(); out.close(); @@ -117,13 +122,17 @@ public void testPartitionTTLNumberSerialization() throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); TableProperty newTableProperty = TableProperty.read(in); Assert.assertEquals(2, newTableProperty.getPartitionTTLNumber()); + Assert.assertEquals(duration, tableProperty.getPartitionTTL()); in.close(); // 3. Update again properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_LIVE_NUMBER, "3"); + properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_TTL, "2 day"); + duration = TimeUtils.parseHumanReadablePeriodOrDuration("2 day"); newTableProperty.modifyTableProperties(properties); newTableProperty.buildPartitionLiveNumber(); newTableProperty.buildPartitionTTL(); Assert.assertEquals(3, newTableProperty.getPartitionTTLNumber()); + Assert.assertEquals(duration, newTableProperty.getPartitionTTL()); } }