Skip to content

Commit

Permalink
[BugFix] Fix partition ttl loss after FE restart (#51028)
Browse files Browse the repository at this point in the history
Signed-off-by: meegoo <[email protected]>
(cherry picked from commit 99b2440)
  • Loading branch information
meegoo authored and mergify[bot] committed Sep 20, 2024
1 parent 9401984 commit 7b7d3a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.starrocks.binlog.BinlogConfig;
import com.starrocks.common.AnalysisException;
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;
Expand Down Expand Up @@ -343,6 +344,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<String, PeriodDuration> ttlDuration = PropertyAnalyzer.analyzePartitionTTL(properties);
if (ttlDuration != null) {
partitionTTL = ttlDuration.second;
}
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,10 +107,13 @@ public void testPartitionTTLNumberSerialization() throws IOException {

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

0 comments on commit 7b7d3a3

Please sign in to comment.