Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ static Duration convertToDuration(Object o) {
return (Duration) o;
}

String s = o.toString().trim();
if ("-1".equals(s)) {
return Duration.ofMillis(-1);
}
return TimeUtils.parseDuration(o.toString());
}

Expand All @@ -155,6 +159,9 @@ static String convertToString(Object o) {
return (String) o;
} else if (o.getClass() == Duration.class) {
Duration duration = (Duration) o;
if (duration.toMillis() == -1) {
return "-1";
}
return TimeUtils.formatWithHighestUnit(duration);
} else if (o instanceof List) {
return ((List<?>) o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void testGetterAndSetter() throws Exception {
assertThat(conf.get(DURATION_OPTION).toMillis()).isEqualTo(3);
conf.setString(DURATION_OPTION.key(), "3 s");
assertThat(conf.get(DURATION_OPTION).toMillis()).isEqualTo(3000);
conf.setString(DURATION_OPTION.key(), "-1");
assertThat(conf.get(DURATION_OPTION)).isEqualTo(Duration.ofMillis(-1));

conf.setBytes("test-bytes-key", new byte[] {1, 2, 3, 4, 5});
assertThat(conf.getBytes("test-bytes-key", new byte[0]).length).isEqualTo(5);
Expand Down Expand Up @@ -428,6 +430,20 @@ void testToMap() {
assertThat(conf.toMap().get(DURATION_OPTION.key())).isEqualTo("3 s");
}

@Test
void testTableLogTtlMinusOneParseAndRoundTrip() {
// Parse "-1" as Duration (e.g. table.log.ttl = -1 means never delete logs)
final Configuration conf = new Configuration();
conf.setString(ConfigOptions.TABLE_LOG_TTL.key(), "-1");
assertThat(conf.get(ConfigOptions.TABLE_LOG_TTL)).isEqualTo(Duration.ofMillis(-1));
assertThat(conf.get(ConfigOptions.TABLE_LOG_TTL).toMillis()).isEqualTo(-1L);

// Round-trip: Duration.ofMillis(-1) serializes back to "-1"
final Configuration conf2 = new Configuration();
conf2.set(ConfigOptions.TABLE_LOG_TTL, Duration.ofMillis(-1));
assertThat(conf2.toMap().get(ConfigOptions.TABLE_LOG_TTL.key())).isEqualTo("-1");
}

@Test
void testMapNotContained() {
final Configuration conf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

package org.apache.fluss.server.log.remote;

import org.apache.fluss.config.ConfigOptions;
import org.apache.fluss.remote.RemoteLogSegment;
import org.apache.fluss.server.log.LogTablet;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -181,6 +183,23 @@ void testFindRemoteLogSegmentByTimestamp(boolean partitionTable) throws Exceptio
assertThat(remoteLogTablet.findSegmentByTimestamp(51L)).isNull();
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void testExpiredSegmentsNeverDeletedWhenLogTtlMinusOne(boolean partitionTable)
throws Exception {
conf.set(ConfigOptions.TABLE_LOG_TTL, Duration.ofMillis(-1));
LogTablet logTablet = makeLogTabletAndAddSegments(partitionTable);
RemoteLogTablet remoteLogTablet = buildRemoteLogTablet(logTablet);
List<RemoteLogSegment> remoteLogSegmentList = createRemoteLogSegmentList(logTablet);
remoteLogTablet.addAndDeleteLogSegments(remoteLogSegmentList, Collections.emptyList());
assertThat(remoteLogTablet.allRemoteLogSegments()).hasSize(5);
manualClock.advanceTime(Duration.ofDays(8));
List<RemoteLogSegment> expired =
remoteLogTablet.expiredRemoteLogSegments(manualClock.milliseconds(), null);
assertThat(expired).isEmpty();
assertThat(remoteLogTablet.allRemoteLogSegments()).hasSize(5);
}

RemoteLogSegment createLogSegmentWithMaxTimestamp(
LogTablet logTablet,
long timestamp,
Expand Down