@@ -448,13 +448,13 @@ public void testSimpleOperationsUpload() throws IOException {
448
448
assertThat (snapshot .totalOperations (), equalTo (ops .size ()));
449
449
}
450
450
451
- assertEquals (translog .allUploaded ().size (), 4 );
451
+ assertEquals (translog .allUploaded ().size (), 2 );
452
452
453
453
addToTranslogAndListAndUpload (translog , ops , new Translog .Index ("1" , 1 , primaryTerm .get (), new byte [] { 1 }));
454
- assertEquals (translog .allUploaded ().size (), 6 );
454
+ assertEquals (translog .allUploaded ().size (), 4 );
455
455
456
456
translog .rollGeneration ();
457
- assertEquals (translog .allUploaded ().size (), 6 );
457
+ assertEquals (translog .allUploaded ().size (), 4 );
458
458
459
459
Set <String > mdFiles = blobStoreTransferService .listAll (
460
460
repository .basePath ().add (shardId .getIndex ().getUUID ()).add (String .valueOf (shardId .id ())).add ("metadata" )
@@ -495,6 +495,38 @@ public void testSimpleOperationsUpload() throws IOException {
495
495
assertArrayEquals (ckp , content );
496
496
}
497
497
}
498
+
499
+ // expose the new checkpoint (simulating a commit), before we trim the translog
500
+ translog .deletionPolicy .setLocalCheckpointOfSafeCommit (0 );
501
+ // simulating the remote segment upload .
502
+ translog .setMinSeqNoToKeep (0 );
503
+ // This should not trim anything
504
+ translog .trimUnreferencedReaders ();
505
+ assertEquals (translog .allUploaded ().size (), 4 );
506
+ assertEquals (
507
+ blobStoreTransferService .listAll (
508
+ repository .basePath ()
509
+ .add (shardId .getIndex ().getUUID ())
510
+ .add (String .valueOf (shardId .id ()))
511
+ .add (String .valueOf (primaryTerm .get ()))
512
+ ).size (),
513
+ 4
514
+ );
515
+
516
+ // This should trim tlog-2.* files as it contains seq no 0
517
+ translog .setMinSeqNoToKeep (1 );
518
+ translog .trimUnreferencedReaders ();
519
+ assertEquals (translog .allUploaded ().size (), 2 );
520
+ assertEquals (
521
+ blobStoreTransferService .listAll (
522
+ repository .basePath ()
523
+ .add (shardId .getIndex ().getUUID ())
524
+ .add (String .valueOf (shardId .id ()))
525
+ .add (String .valueOf (primaryTerm .get ()))
526
+ ).size (),
527
+ 2
528
+ );
529
+
498
530
}
499
531
500
532
private Long populateTranslogOps (boolean withMissingOps ) throws IOException {
@@ -684,6 +716,7 @@ public void doRun() throws BrokenBarrierException, InterruptedException, IOExcep
684
716
// expose the new checkpoint (simulating a commit), before we trim the translog
685
717
lastCommittedLocalCheckpoint .set (localCheckpoint );
686
718
deletionPolicy .setLocalCheckpointOfSafeCommit (localCheckpoint );
719
+ translog .setMinSeqNoToKeep (localCheckpoint + 1 );
687
720
translog .trimUnreferencedReaders ();
688
721
}
689
722
}
0 commit comments