Skip to content

Commit

Permalink
Removing the use of Stream::peek from GeoIpDownloader::cleanDatabases (
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke authored Jul 9, 2024
1 parent 18aab96 commit 6833aa0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/110666.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 110666
summary: Removing the use of Stream::peek from `GeoIpDownloader::cleanDatabases`
area: Ingest Node
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,19 @@ public void requestReschedule() {
}

private void cleanDatabases() {
long expiredDatabases = state.getDatabases()
List<Map.Entry<String, Metadata>> expiredDatabases = state.getDatabases()
.entrySet()
.stream()
.filter(e -> e.getValue().isValid(clusterService.state().metadata().settings()) == false)
.peek(e -> {
String name = e.getKey();
Metadata meta = e.getValue();
deleteOldChunks(name, meta.lastChunk() + 1);
state = state.put(
name,
new Metadata(meta.lastUpdate(), meta.firstChunk(), meta.lastChunk(), meta.md5(), meta.lastCheck() - 1)
);
updateTaskState();
})
.count();
stats = stats.expiredDatabases((int) expiredDatabases);
.toList();
expiredDatabases.forEach(e -> {
String name = e.getKey();
Metadata meta = e.getValue();
deleteOldChunks(name, meta.lastChunk() + 1);
state = state.put(name, new Metadata(meta.lastUpdate(), meta.firstChunk(), meta.lastChunk(), meta.md5(), meta.lastCheck() - 1));
updateTaskState();
});
stats = stats.expiredDatabases(expiredDatabases.size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ public void testThatRunDownloaderDeletesExpiredDatabases() {
client.addHandler(
UpdatePersistentTaskStatusAction.INSTANCE,
(UpdatePersistentTaskStatusAction.Request request, ActionListener<PersistentTaskResponse> taskResponseListener) -> {

PersistentTasksCustomMetadata.Assignment assignment = mock(PersistentTasksCustomMetadata.Assignment.class);
PersistentTasksCustomMetadata.PersistentTask<?> persistentTask = new PersistentTasksCustomMetadata.PersistentTask<>(
GeoIpDownloader.GEOIP_DOWNLOADER,
Expand All @@ -589,8 +588,8 @@ public void testThatRunDownloaderDeletesExpiredDatabases() {
request.getAllocationId(),
assignment
);
taskResponseListener.onResponse(new PersistentTaskResponse(new PersistentTask<>(persistentTask, request.getState())));
updatePersistentTaskStateCount.incrementAndGet();
taskResponseListener.onResponse(new PersistentTaskResponse(new PersistentTask<>(persistentTask, request.getState())));
}
);
client.addHandler(
Expand Down

0 comments on commit 6833aa0

Please sign in to comment.