@@ -165,7 +165,6 @@ protected void afterIfSuccessful() throws Exception {
165165
166166 if (translog .isOpen ()) {
167167 if (translog .currentFileGeneration () > 1 ) {
168- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (Long .MAX_VALUE );
169168 translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (Long .MAX_VALUE );
170169 translog .trimUnreferencedReaders ();
171170 assertFileDeleted (translog , translog .currentFileGeneration () - 1 );
@@ -479,7 +478,6 @@ public void testStats() throws IOException {
479478 }
480479 }
481480 translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (randomLongBetween (3 , Long .MAX_VALUE ));
482- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (randomLongBetween (3 , Long .MAX_VALUE ));
483481 translog .trimUnreferencedReaders ();
484482 {
485483 final TranslogStats stats = stats ();
@@ -506,8 +504,7 @@ public void testUncommittedOperations() throws Exception {
506504 }
507505 assertThat (translog .stats ().getUncommittedOperations (), equalTo (uncommittedOps ));
508506 if (frequently ()) {
509- deletionPolicy .setLocalCheckpointOfSafeCommit (randomLongBetween (deletionPolicy .getLocalCheckpointOfSafeCommit (), i ));
510- deletionPolicy .setLocalCheckpointOfLastCommit (i );
507+ deletionPolicy .setLocalCheckpointOfSafeCommit (i );
511508 assertThat (translog .stats ().getUncommittedOperations (), equalTo (operationsInLastGen ));
512509 uncommittedOps = operationsInLastGen ;
513510 }
@@ -625,7 +622,7 @@ public void testSnapshotWithNewTranslog() throws IOException {
625622
626623 Translog .Snapshot snapshot2 = translog .newSnapshot ();
627624 toClose .add (snapshot2 );
628- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (2 );
625+ translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (2 );
629626 assertThat (snapshot2 , containsOperationsInAnyOrder (ops ));
630627 assertThat (snapshot2 .totalOperations (), equalTo (ops .size ()));
631628 } finally {
@@ -972,7 +969,6 @@ public void doRun() throws BrokenBarrierException, InterruptedException, IOExcep
972969 translog .rollGeneration ();
973970 // expose the new checkpoint (simulating a commit), before we trim the translog
974971 lastCommittedLocalCheckpoint .set (localCheckpoint );
975- deletionPolicy .setLocalCheckpointOfLastCommit (localCheckpoint );
976972 deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpoint );
977973 translog .trimUnreferencedReaders ();
978974 }
@@ -1360,7 +1356,7 @@ public void testBasicRecovery() throws IOException {
13601356 Integer .toString (op ).getBytes (Charset .forName ("UTF-8" )))));
13611357 final boolean commit = commitOften ? frequently () : rarely ();
13621358 if (commit && op < translogOperations - 1 ) {
1363- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (op );
1359+ translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (op );
13641360 minUncommittedOp = op + 1 ;
13651361 translogGeneration = translog .getGeneration ();
13661362 }
@@ -1816,7 +1812,6 @@ public void testOpenForeignTranslog() throws IOException {
18161812 if (randomBoolean ()) {
18171813 translog .rollGeneration ();
18181814 translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (op );
1819- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (op );
18201815 translog .trimUnreferencedReaders ();
18211816 firstUncommitted = op + 1 ;
18221817 }
@@ -2219,7 +2214,6 @@ public void testRecoveryFromAFutureGenerationCleansUp() throws IOException {
22192214 TranslogConfig config = translog .getConfig ();
22202215 final TranslogDeletionPolicy deletionPolicy = new TranslogDeletionPolicy ();
22212216 deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpoint );
2222- deletionPolicy .setLocalCheckpointOfLastCommit (randomLongBetween (localCheckpoint , Long .MAX_VALUE ));
22232217 translog = new Translog (config , translog .getTranslogUUID (), deletionPolicy ,
22242218 () -> SequenceNumbers .NO_OPS_PERFORMED , primaryTerm ::get , seqNo -> {});
22252219 assertThat (translog .getMinFileGeneration (), equalTo (1L ));
@@ -2268,7 +2262,6 @@ public void testRecoveryFromFailureOnTrimming() throws IOException {
22682262 }
22692263 }
22702264 deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpoint );
2271- deletionPolicy .setLocalCheckpointOfLastCommit (randomLongBetween (localCheckpoint , op ));
22722265 minGenForRecovery = translog .getMinGenerationForSeqNo (localCheckpoint + 1 ).translogFileGeneration ;
22732266 fail .failRandomly ();
22742267 try {
@@ -2278,7 +2271,6 @@ public void testRecoveryFromFailureOnTrimming() throws IOException {
22782271 }
22792272 }
22802273 final TranslogDeletionPolicy deletionPolicy = new TranslogDeletionPolicy ();
2281- deletionPolicy .setLocalCheckpointOfLastCommit (randomLongBetween (localCheckpoint , Long .MAX_VALUE ));
22822274 deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpoint );
22832275 try (Translog translog = new Translog (config , translogUUID , deletionPolicy ,
22842276 () -> SequenceNumbers .NO_OPS_PERFORMED , primaryTerm ::get , seqNo -> {})) {
@@ -2626,7 +2618,6 @@ public void testWithRandomException() throws IOException {
26262618 unsynced .clear ();
26272619 failableTLog .rollGeneration ();
26282620 committing = true ;
2629- failableTLog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (opsAdded );
26302621 failableTLog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (opsAdded );
26312622 syncedDocs .clear ();
26322623 failableTLog .trimUnreferencedReaders ();
@@ -2671,7 +2662,6 @@ public void testWithRandomException() throws IOException {
26712662 if (randomBoolean ()) {
26722663 try {
26732664 TranslogDeletionPolicy deletionPolicy = new TranslogDeletionPolicy ();
2674- deletionPolicy .setLocalCheckpointOfLastCommit (localCheckpointOfSafeCommit );
26752665 deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpointOfSafeCommit );
26762666 IOUtils .close (getFailableTranslog (fail , config , randomBoolean (), false , generationUUID , deletionPolicy ));
26772667 } catch (TranslogException | MockDirectoryWrapper .FakeIOException ex ) {
@@ -2684,7 +2674,6 @@ public void testWithRandomException() throws IOException {
26842674 fail .failNever (); // we don't wanna fail here but we might since we write a new checkpoint and create a new tlog file
26852675 TranslogDeletionPolicy deletionPolicy = new TranslogDeletionPolicy ();
26862676 deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpointOfSafeCommit );
2687- deletionPolicy .setLocalCheckpointOfLastCommit (localCheckpointOfSafeCommit );
26882677 if (generationUUID == null ) {
26892678 // we never managed to successfully create a translog, make it
26902679 generationUUID = Translog .createEmptyTranslog (config .getTranslogPath (),
@@ -2868,12 +2857,15 @@ public void testRollGeneration() throws Exception {
28682857 Stream .concat (translog .getReaders ().stream (), Stream .of (translog .getCurrent ()))
28692858 .filter (r -> r .getCheckpoint ().minSeqNo >= 0 )
28702859 .collect (Collectors .toList ()));
2860+ int retainedOps = Stream .concat (translog .getReaders ().stream (), Stream .of (translog .getCurrent ()))
2861+ .filter (r -> r .getCheckpoint ().generation >= minRetainedReader .generation )
2862+ .mapToInt (r -> r .getCheckpoint ().numOps )
2863+ .sum ();
28712864 deletionPolicy .setLocalCheckpointOfSafeCommit (
28722865 randomLongBetween (minRetainedReader .getCheckpoint ().minSeqNo , minRetainedReader .getCheckpoint ().maxSeqNo ) - 1 );
2873- deletionPolicy .setLocalCheckpointOfLastCommit (seqNo );
28742866 translog .trimUnreferencedReaders ();
28752867 assertThat (translog .currentFileGeneration (), equalTo (generation + rolls ));
2876- assertThat (translog .stats ().getUncommittedOperations (), equalTo (0 ));
2868+ assertThat (translog .stats ().getUncommittedOperations (), equalTo (retainedOps ));
28772869 // immediate cleanup
28782870 for (long i = 0 ; i < minRetainedReader .generation ; i ++) {
28792871 assertFileDeleted (translog , i );
@@ -2967,7 +2959,6 @@ public void testSimpleCommit() throws IOException {
29672959 }
29682960 }
29692961 translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (randomLongBetween (0 , operations ));
2970- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (randomLongBetween (operations , Long .MAX_VALUE ));
29712962 }
29722963
29732964 public void testAcquiredLockIsPassedToDeletionPolicy () throws IOException {
@@ -2981,8 +2972,6 @@ public void testAcquiredLockIsPassedToDeletionPolicy() throws IOException {
29812972 if (rarely ()) {
29822973 translog .getDeletionPolicy ().setLocalCheckpointOfSafeCommit (
29832974 randomLongBetween (deletionPolicy .getLocalCheckpointOfSafeCommit (), i ));
2984- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (
2985- randomLongBetween (deletionPolicy .getLocalCheckpointOfLastCommit (), Long .MAX_VALUE ));
29862975 }
29872976 if (frequently ()) {
29882977 long minGen ;
@@ -3136,9 +3125,6 @@ public void testMaxSeqNo() throws Exception {
31363125 translog .sync ();
31373126 assertThat (translog .getMaxSeqNo (),
31383127 equalTo (maxSeqNoPerGeneration .isEmpty () ? SequenceNumbers .NO_OPS_PERFORMED : Collections .max (maxSeqNoPerGeneration .values ())));
3139- if (randomBoolean ()) {
3140- translog .getDeletionPolicy ().setLocalCheckpointOfLastCommit (randomFrom (maxSeqNoPerGeneration .values ()));
3141- }
31423128 long expectedMaxSeqNo = maxSeqNoPerGeneration .entrySet ().stream ()
31433129 .filter (e -> e .getKey () >= translog .getMinFileGeneration ()).mapToLong (e -> e .getValue ())
31443130 .max ().orElse (SequenceNumbers .NO_OPS_PERFORMED );
0 commit comments