Skip to content

Commit

Permalink
Move to asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Apr 13, 2017
1 parent 594e9ab commit e6abaf9
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions core/src/main/java/org/elasticsearch/index/translog/Translog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1431,23 +1431,7 @@ public void prepareCommit() throws IOException {
public void commit(final long committedGeneration) throws IOException {
try (ReleasableLock ignored = writeLock.acquire()) {
ensureOpen();
if (committedGeneration > current.generation) {
final String message = String.format(
Locale.ROOT,
"tried to commit generation [%d] later than the current generation [%d]",
committedGeneration,
current.generation);
throw new IllegalStateException(message);
}
final Long min = readers.stream().map(TranslogReader::getGeneration).min(Long::compareTo).orElse(Long.MIN_VALUE);
if (committedGeneration < min) {
final String message = String.format(
Locale.ROOT,
"tried to commit generation [%d] before minimum generation [%d]",
committedGeneration,
min);
throw new IllegalStateException(message);
}
assert assertCommittedGenerationIsInValidRange(committedGeneration);
if (currentCommittingGeneration == NOT_SET_GENERATION) {
prepareCommit();
}
Expand All @@ -1461,6 +1445,15 @@ public void commit(final long committedGeneration) throws IOException {
}
}

private boolean assertCommittedGenerationIsInValidRange(final long committedGeneration) {
assert committedGeneration > current.generation
: "tried to commit generation [" + committedGeneration + "] after current generation [" + current.generation + "]";
final long min = readers.stream().map(TranslogReader::getGeneration).min(Long::compareTo).orElse(Long.MIN_VALUE);
assert committedGeneration < min
: "tried to commit generation [" + committedGeneration + "] before minimum generation [" + min + "]";
return true;
}

/**
* Trims unreferenced translog generations. The guarantee here is that translog generations will be preserved for all outstanding views
* and from the last committed translog generation defined by {@link Translog#lastCommittedTranslogFileGeneration}.
Expand Down

0 comments on commit e6abaf9

Please sign in to comment.