Skip to content

Commit 171433c

Browse files
authored
Fix ConcurrentModificationException in RemoteFsTimestampAwareTranslog.trimUnreferencedReaders (#17028)
* Fix ConcurrentModificationException in RemoteFsTimestampAwareTranslog.trimUnreferencedReaders Signed-off-by: Sachin Kale <sachinpkale@gmail.com> * Address PR comments Signed-off-by: Sachin Kale <sachinpkale@gmail.com> --------- Signed-off-by: Sachin Kale <sachinpkale@gmail.com>
1 parent e397903 commit 171433c

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,18 @@ protected void trimUnreferencedReaders(boolean indexDeleted, boolean trimLocal)
125125
}
126126

127127
// Update file tracker to reflect local translog state
128-
Optional<Long> minLiveGeneration = readers.stream().map(BaseTranslogReader::getGeneration).min(Long::compareTo);
129-
if (minLiveGeneration.isPresent()) {
130-
List<String> staleFilesInTracker = new ArrayList<>();
131-
for (String file : fileTransferTracker.allUploaded()) {
132-
if (file.endsWith(TRANSLOG_FILE_SUFFIX)) {
133-
long generation = Translog.parseIdFromFileName(file);
134-
if (generation < minLiveGeneration.get()) {
135-
staleFilesInTracker.add(file);
136-
staleFilesInTracker.add(Translog.getCommitCheckpointFileName(generation));
137-
}
128+
long minLiveGeneration = getMinFileGeneration();
129+
List<String> staleFilesInTracker = new ArrayList<>();
130+
for (String file : fileTransferTracker.allUploaded()) {
131+
if (file.endsWith(TRANSLOG_FILE_SUFFIX)) {
132+
long generation = Translog.parseIdFromFileName(file);
133+
if (generation < minLiveGeneration) {
134+
staleFilesInTracker.add(file);
135+
staleFilesInTracker.add(Translog.getCommitCheckpointFileName(generation));
138136
}
139-
fileTransferTracker.delete(staleFilesInTracker);
140137
}
141138
}
139+
fileTransferTracker.delete(staleFilesInTracker);
142140

143141
// This is to ensure that after the permits are acquired during primary relocation, there are no further modification on remote
144142
// store.

0 commit comments

Comments
 (0)