Skip to content

Commit 3ed487c

Browse files
Expose method for additional files between index commits (#138133)
This is a simple PR that only exposes a method to return the list of additional files between 2 lucene commits.
1 parent 4be381f commit 3ed487c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

server/src/main/java/org/elasticsearch/common/lucene/Lucene.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@
8787
import java.util.Arrays;
8888
import java.util.Collection;
8989
import java.util.Collections;
90+
import java.util.HashSet;
9091
import java.util.List;
9192
import java.util.Map;
9293
import java.util.Objects;
94+
import java.util.Set;
95+
import java.util.stream.Collectors;
9396

9497
public class Lucene {
9598

@@ -128,6 +131,14 @@ public static Iterable<String> files(SegmentInfos infos) throws IOException {
128131
return Iterables.flatten(list);
129132
}
130133

134+
/**
135+
* Returns the additional files that the {@param current} index commit introduces compared to the {@param previous} one.
136+
*/
137+
public static Set<String> additionalFileNames(IndexCommit previous, IndexCommit current) throws IOException {
138+
final Set<String> previousFiles = previous != null ? new HashSet<>(previous.getFileNames()) : Set.of();
139+
return current.getFileNames().stream().filter(f -> previousFiles.contains(f) == false).collect(Collectors.toUnmodifiableSet());
140+
}
141+
131142
/**
132143
* Returns the number of documents in the index referenced by this {@link SegmentInfos}
133144
*/

server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import java.util.Map;
3030
import java.util.Set;
3131
import java.util.function.LongSupplier;
32-
import java.util.stream.Collectors;
32+
33+
import static org.elasticsearch.common.lucene.Lucene.additionalFileNames;
3334

3435
/**
3536
* An {@link IndexDeletionPolicy} that coordinates between Lucene's commits and the retention of translog generation files,
@@ -130,7 +131,7 @@ public void onCommit(List<? extends IndexCommit> commits) throws IOException {
130131
assert assertSafeCommitUnchanged(safeCommit);
131132
if (commitsListener != null) {
132133
if (newCommit != null) {
133-
final Set<String> additionalFiles = listOfNewFileNames(previousLastCommit, newCommit);
134+
final Set<String> additionalFiles = additionalFileNames(previousLastCommit, newCommit);
134135
commitsListener.onNewAcquiredCommit(newCommit, additionalFiles);
135136
}
136137
if (deletedCommits != null) {
@@ -303,11 +304,6 @@ private static int indexOfKeptCommits(List<? extends IndexCommit> commits, long
303304
return 0;
304305
}
305306

306-
private static Set<String> listOfNewFileNames(IndexCommit previous, IndexCommit current) throws IOException {
307-
final Set<String> previousFiles = previous != null ? new HashSet<>(previous.getFileNames()) : Set.of();
308-
return current.getFileNames().stream().filter(f -> previousFiles.contains(f) == false).collect(Collectors.toUnmodifiableSet());
309-
}
310-
311307
/**
312308
* Checks whether the deletion policy is holding on to externally acquired index commits
313309
*/

0 commit comments

Comments
 (0)