Skip to content

Commit

Permalink
[BugFix] Fix partition ttl loss after FE restart (backport #51028) (#…
Browse files Browse the repository at this point in the history
…51193)

Signed-off-by: meegoo <[email protected]>
Co-authored-by: meegoo <[email protected]>
  • Loading branch information
mergify[bot] and meegoo committed Sep 20, 2024
1 parent 2ad8771 commit 24d954c
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 @@ -48,6 +48,7 @@
import com.starrocks.catalog.constraint.UniqueConstraint;
import com.starrocks.common.Config;
import com.starrocks.common.FeConstants;
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 @@ -376,6 +377,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 24d954c

Please sign in to comment.