Skip to content

Commit

Permalink
maxEffectiveSeqNo
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Dec 16, 2019
1 parent 3386eca commit 563545c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ private void write(DataOutput out) throws IOException {
out.writeLong(trimmedAboveSeqNo);
}

/**
* Returns the maximum sequence number of operations in this checkpoint after applying {@link #trimmedAboveSeqNo}.
*/
long maxEffectiveSeqNo() {
if (trimmedAboveSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO) {
return maxSeqNo;
} else {
return Math.min(trimmedAboveSeqNo, maxSeqNo);
}
}

static Checkpoint emptyTranslogCheckpoint(final long offset, final long generation, final long globalCheckpoint,
long minTranslogGeneration) {
final long minSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,7 @@ private Stream<? extends BaseTranslogReader> readersAboveMinSeqNo(long minSeqNo)
assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread() :
"callers of readersAboveMinSeqNo must hold a lock: readLock ["
+ readLock.isHeldByCurrentThread() + "], writeLock [" + readLock.isHeldByCurrentThread() + "]";
return Stream.concat(readers.stream(), Stream.of(current))
.filter(reader -> minSeqNo <= SequenceNumbers.min(reader.getCheckpoint().trimmedAboveSeqNo, reader.getCheckpoint().maxSeqNo));
return Stream.concat(readers.stream(), Stream.of(current)).filter(reader -> minSeqNo <= reader.getCheckpoint().maxEffectiveSeqNo());
}

/**
Expand Down Expand Up @@ -1626,7 +1625,7 @@ public TranslogGeneration getMinGenerationForSeqNo(final long seqNo) {
*/
long minTranslogFileGeneration = this.currentFileGeneration();
for (final TranslogReader reader : readers) {
if (seqNo <= SequenceNumbers.min(reader.getCheckpoint().trimmedAboveSeqNo, reader.getCheckpoint().maxSeqNo)) {
if (seqNo <= reader.getCheckpoint().maxEffectiveSeqNo()) {
minTranslogFileGeneration = Math.min(minTranslogFileGeneration, reader.getGeneration());
}
}
Expand Down

0 comments on commit 563545c

Please sign in to comment.