File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
core/src/main/java/org/elasticsearch/index/engine Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments