Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spooling pruning tests #23651

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -90,11 +90,13 @@ private void prune()
}

@VisibleForTesting
void pruneExpiredBefore(Instant expiredBefore)
long pruneExpiredBefore(Instant expiredBefore)
{
if (closed) {
return;
return 0;
}
long pruned = 0;

try {
List<Location> expiredSegments = new ArrayList<>();
FileIterator iterator = orderDetectingIterator(fileSystem.listFiles(location));
Expand All @@ -109,20 +111,24 @@ void pruneExpiredBefore(Instant expiredBefore)
if (handle.get().isBefore(expiredBefore)) {
expiredSegments.add(file.location());
if (expiredSegments.size() >= batchSize) {
pruned += expiredSegments.size();
pruneExpiredSegments(expiredBefore, expiredSegments);
expiredSegments.clear();
}
}
else if (filesAreOrdered) {
// First non expired segment was found, no need to check the rest
// since we know that files are lexicographically ordered.
pruneExpiredSegments(expiredBefore, expiredSegments);
return;
return pruned + expiredSegments.size();
}
}
pruneExpiredSegments(expiredBefore, expiredSegments);
return pruned + expiredSegments.size();
}
catch (IOException e) {
log.error(e, "Failed to prune segments");
return pruned;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class TestFileSystemSegmentPruner
private static final String TEST_LOCATION = "memory://";

private static final FileSystemSpoolingConfig SPOOLING_CONFIG = new FileSystemSpoolingConfig()
.setLocation(TEST_LOCATION);
.setLocation(TEST_LOCATION)
.setPruningBatchSize(1);

@Test
public void shouldPruneExpiredSegments()
Expand All @@ -68,6 +69,32 @@ public void shouldPruneExpiredSegments()
}
}

@Test
public void shouldPruneExpiredSegmentsOnceAndClear()
{
MemoryFileSystem fileSystem = new MemoryFileSystem();
try (ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor()) {
FileSystemSegmentPruner pruner = new FileSystemSegmentPruner(SPOOLING_CONFIG, _ -> fileSystem, executorService);

Instant now = Instant.now();
QueryId queryId = QueryId.valueOf("prune_expired");

Location _ = createNewDummySegment(fileSystem, queryId, now.minusSeconds(1));
wendigo marked this conversation as resolved.
Show resolved Hide resolved
Location _ = createNewDummySegment(fileSystem, queryId, now.minusSeconds(1));
Location _ = createNewDummySegment(fileSystem, queryId, now.minusSeconds(1));

Location nonExpiredSegment = createNewDummySegment(fileSystem, queryId, now.plusSeconds(1));

assertThat(pruner.pruneExpiredBefore(now.truncatedTo(MILLIS)))
.isEqualTo(3);

List<Location> files = listFiles(fileSystem, queryId);
assertThat(files)
.hasSize(1)
.containsOnly(nonExpiredSegment);
}
}

@Test
public void shouldNotPruneLiveSegments()
{
Expand Down