Skip to content

Commit 9ee44d2

Browse files
committed
readable
1 parent 3cda401 commit 9ee44d2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

core/src/main/java/org/elasticsearch/index/engine/KeepUntilGlobalCheckpointDeletionPolicy.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,21 @@ public void onInit(List<? extends IndexCommit> commits) throws IOException {
4747

4848
@Override
4949
public void onCommit(List<? extends IndexCommit> commits) throws IOException {
50+
final int keptIndex = indexOfKeptCommits(commits);
51+
for (int i = 0; i < keptIndex; i++) {
52+
commits.get(i).delete();
53+
}
54+
}
55+
56+
// commits are sorted by age (the 0th one is the oldest commit).
57+
private int indexOfKeptCommits(List<? extends IndexCommit> commits) throws IOException {
5058
final long globalCheckpoint = globalCheckpointSupplier.getAsLong();
5159
for (int i = commits.size() - 1; i >= 0; i--) {
5260
if (localCheckpoint(commits.get(i)) <= globalCheckpoint) {
53-
i--; // This is the youngest commit whose local checkpoint <= global checkpoint - reserve it, then delete all previous ones.
54-
for (; i >= 0; i--) {
55-
commits.get(i).delete();
56-
}
57-
break;
61+
return i;
5862
}
5963
}
64+
return -1;
6065
}
6166

6267
private static long localCheckpoint(IndexCommit commit) throws IOException {

0 commit comments

Comments
 (0)