@@ -416,7 +416,9 @@ private int totalOperations(long minGeneration) {
416
416
public int estimateTotalOperationsFromMinSeq (long minSeqNo ) {
417
417
try (ReleasableLock ignored = readLock .acquire ()) {
418
418
ensureOpen ();
419
- return readersAboveMinSeqNo (minSeqNo ).mapToInt (BaseTranslogReader ::totalOperations ).sum ();
419
+ return readersBetweenMinAndMaxSeqNo (minSeqNo , Long .MAX_VALUE )
420
+ .mapToInt (BaseTranslogReader ::totalOperations )
421
+ .sum ();
420
422
}
421
423
}
422
424
@@ -433,16 +435,6 @@ private long sizeInBytesByMinGen(long minGeneration) {
433
435
}
434
436
}
435
437
436
- /**
437
- * Returns the size in bytes of the translog files with ops above the given seqNo
438
- */
439
- private long sizeOfGensAboveSeqNoInBytes (long minSeqNo ) {
440
- try (ReleasableLock ignored = readLock .acquire ()) {
441
- ensureOpen ();
442
- return readersAboveMinSeqNo (minSeqNo ).mapToLong (BaseTranslogReader ::sizeInBytes ).sum ();
443
- }
444
- }
445
-
446
438
/**
447
439
* Creates a new translog for the specified generation.
448
440
*
@@ -598,10 +590,19 @@ public Snapshot newSnapshotFromGen(long minGeneration) throws IOException {
598
590
}
599
591
600
592
public Snapshot newSnapshotFromMinSeqNo (long minSeqNo ) throws IOException {
593
+ return newSnapshotBetweenMinAndMaxSeqNo (minSeqNo , Long .MAX_VALUE );
594
+ }
595
+
596
+ /**
597
+ * Returns a snapshot with operations having a sequence number equal or greater than <code>minSeqNo</code> and
598
+ * equal or lesser than <code>maxSeqNo</code>.
599
+ */
600
+ public Snapshot newSnapshotBetweenMinAndMaxSeqNo (long minSeqNo , long maxSeqNo ) throws IOException {
601
601
try (ReleasableLock ignored = readLock .acquire ()) {
602
602
ensureOpen ();
603
- TranslogSnapshot [] snapshots = readersAboveMinSeqNo (minSeqNo ).map (BaseTranslogReader ::newSnapshot )
604
- .toArray (TranslogSnapshot []::new );
603
+ TranslogSnapshot [] snapshots = readersBetweenMinAndMaxSeqNo (minSeqNo , maxSeqNo )
604
+ .map (BaseTranslogReader ::newSnapshot )
605
+ .toArray (TranslogSnapshot []::new );
605
606
return newMultiSnapshot (snapshots );
606
607
}
607
608
}
@@ -627,14 +628,16 @@ private Snapshot newMultiSnapshot(TranslogSnapshot[] snapshots) throws IOExcepti
627
628
}
628
629
}
629
630
630
- private Stream <? extends BaseTranslogReader > readersAboveMinSeqNo (long minSeqNo ) {
631
+ private Stream <? extends BaseTranslogReader > readersBetweenMinAndMaxSeqNo (long minSeqNo , long maxSeqNo ) {
631
632
assert readLock .isHeldByCurrentThread () || writeLock .isHeldByCurrentThread () :
632
- "callers of readersAboveMinSeqNo must hold a lock: readLock ["
633
+ "callers of readersBetweenMinAndMaxSeqNo must hold a lock: readLock ["
633
634
+ readLock .isHeldByCurrentThread () + "], writeLock [" + readLock .isHeldByCurrentThread () + "]" ;
635
+
634
636
return Stream .concat (readers .stream (), Stream .of (current ))
635
637
.filter (reader -> {
636
- final long maxSeqNo = reader .getCheckpoint ().maxSeqNo ;
637
- return maxSeqNo == SequenceNumbers .UNASSIGNED_SEQ_NO || maxSeqNo >= minSeqNo ;
638
+ final Checkpoint checkpoint = reader .getCheckpoint ();
639
+ return checkpoint .maxSeqNo == SequenceNumbers .UNASSIGNED_SEQ_NO ||
640
+ checkpoint .minSeqNo <= maxSeqNo && checkpoint .maxSeqNo >= minSeqNo ;
638
641
});
639
642
}
640
643
0 commit comments