From 044793fea874626b2f75fc5fa8544fbc52c30651 Mon Sep 17 00:00:00 2001 From: Sachin Kale Date: Wed, 15 Jan 2025 15:06:07 +0530 Subject: [PATCH] Fix ConcurrentModificationException in RemoteFsTimestampAwareTranslog.trimUnreferencedReaders Signed-off-by: Sachin Kale --- .../RemoteFsTimestampAwareTranslog.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java b/server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java index 99153324b8372..d6acd3be0def4 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java @@ -125,19 +125,17 @@ protected void trimUnreferencedReaders(boolean indexDeleted, boolean trimLocal) } // Update file tracker to reflect local translog state - Optional minLiveGeneration = readers.stream().map(BaseTranslogReader::getGeneration).min(Long::compareTo); - if (minLiveGeneration.isPresent()) { - List staleFilesInTracker = new ArrayList<>(); - for (String file : fileTransferTracker.allUploaded()) { - if (file.endsWith(TRANSLOG_FILE_SUFFIX)) { - long generation = Translog.parseIdFromFileName(file); - if (generation < minLiveGeneration.get()) { - staleFilesInTracker.add(file); - staleFilesInTracker.add(Translog.getCommitCheckpointFileName(generation)); - } + long minLiveGeneration = getMinFileGeneration(); + List staleFilesInTracker = new ArrayList<>(); + for (String file : fileTransferTracker.allUploaded()) { + if (file.endsWith(TRANSLOG_FILE_SUFFIX)) { + long generation = Translog.parseIdFromFileName(file); + if (generation < minLiveGeneration) { + staleFilesInTracker.add(file); + staleFilesInTracker.add(Translog.getCommitCheckpointFileName(generation)); } - fileTransferTracker.delete(staleFilesInTracker); } + fileTransferTracker.delete(staleFilesInTracker); } // This is to ensure that after the permits are acquired during primary relocation, there are no further modification on remote