Skip to content

Commit

Permalink
Stronger preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Apr 10, 2017
1 parent 9120bf9 commit c63543b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1348,19 +1348,19 @@ public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Transl
}

/**
* Gets the minimum generation that could contain the sequence number, or the current generation if there is no generation with the
* specified sequence number between the minimum and maximum sequence numbers.
* Gets the minimum generation that could contain any sequence number after the specified sequence number, or the current generation if
* there is no generation that could any such sequence number.
*
* @param seqNo the sequence number
* @return the minimum generation for the sequence number, or the current generation
* @return the minimum generation for the sequence number
*/
public TranslogGeneration getMinGenerationForSeqNo(final long seqNo) {
try (ReleasableLock ignored = writeLock.acquire()) {
final long minTranslogFileGeneration = readers
.stream()
.filter(r -> {
final Checkpoint checkpoint = r.getCheckpoint();
return checkpoint.minSeqNo <= seqNo && seqNo <= checkpoint.maxSeqNo;
return seqNo <= checkpoint.maxSeqNo;
})
.mapToLong(TranslogReader::getGeneration)
.min()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2201,22 +2201,30 @@ public void testMinGenerationForSeqNo() throws IOException {
}
}

final Set<Long> seenSeqNos = new HashSet<>();
for (final Map.Entry<Long, List<Long>> entry : generations.entrySet()) {
final long min = entry.getValue().stream().min(Long::compareTo).orElse(Long.MIN_VALUE);
final long max = entry.getValue().stream().max(Long::compareTo).orElse(Long.MAX_VALUE);
for (long seqNo = min; seqNo <= max; seqNo++) {
if (seenSeqNos.add(seqNo)) {
assertThat(
translog.getMinGenerationForSeqNo(seqNo).translogFileGeneration,
equalTo(entry.getKey()));
}
}
final Map<Long, Long> maxSeqNoByGeneration =
generations
.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().stream().max(Long::compareTo).orElse(Long.MAX_VALUE)));

for (long seqNo = 0; seqNo < operations; seqNo++) {
final long finalLongSeqNo = seqNo;
final Long operand =
maxSeqNoByGeneration
.entrySet()
.stream()
.filter(e -> finalLongSeqNo <= e.getValue())
.map(Map.Entry::getKey).min(Long::compareTo)
.orElse(Long.MIN_VALUE);
assertThat(translog.getMinGenerationForSeqNo(seqNo).translogFileGeneration, equalTo(operand));
}

assertThat(seenSeqNos, equalTo(new HashSet<>(seqNos)));
}



public void testSimpleCommit() throws IOException {
final int operations = randomIntBetween(1, 4096);
long seqNo = 0;
Expand Down

0 comments on commit c63543b

Please sign in to comment.