Skip to content

Commit

Permalink
Remove generation parameter from fold
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Mar 16, 2017
1 parent c88e788 commit 7e69ae8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public Location add(final Operation operation) throws IOException {
// we have to check the condition again lest we could fold twice in a race
if (shouldFoldGeneration()) {
try (ReleasableLock ignored = writeLock.acquire()) {
this.foldGeneration(current.getGeneration());
this.foldGeneration();
}
final boolean wasFoldingGeneration = foldingGeneration.getAndSet(false);
assert wasFoldingGeneration;
Expand Down Expand Up @@ -1352,23 +1352,22 @@ public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Transl
* Fold the current translog generation into a new generation. This does not commit the
* translog. The translog write lock must be held by the current thread.
*
* @param generation the current translog generation
* @throws IOException if an I/O exception occurred during any file operations
*/
void foldGeneration(final long generation) throws IOException {
void foldGeneration() throws IOException {
assert writeLock.isHeldByCurrentThread();
try {
final TranslogReader reader = current.closeIntoReader();
readers.add(reader);
final Path checkpoint = location.resolve(CHECKPOINT_FILE_NAME);
assert Checkpoint.read(checkpoint).generation == generation;
assert Checkpoint.read(checkpoint).generation == current.getGeneration();
final Path generationCheckpoint =
location.resolve(getCommitCheckpointFileName(generation));
location.resolve(getCommitCheckpointFileName(current.getGeneration()));
Files.copy(checkpoint, generationCheckpoint);
IOUtils.fsync(generationCheckpoint, false);
IOUtils.fsync(generationCheckpoint.getParent(), true);
// create a new translog file; this will sync it and update the checkpoint data;
current = createWriter(generation + 1);
current = createWriter(current.getGeneration() + 1);
logger.trace("current translog set to [{}]", current.getGeneration());
} catch (final Exception e) {
IOUtils.closeWhileHandlingException(this); // tragic event
Expand All @@ -1384,9 +1383,8 @@ public long prepareCommit() throws IOException {
throw new IllegalStateException("already committing a translog with generation: " +
currentCommittingGeneration);
}
final long generation = current.getGeneration();
currentCommittingGeneration = generation;
foldGeneration(generation);
currentCommittingGeneration = current.getGeneration();
foldGeneration();
} catch (final Exception e) {
IOUtils.closeWhileHandlingException(this); // tragic event
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ public void testFoldGeneration() throws IOException {
totalOperations++;
}
try (ReleasableLock ignored = translog.writeLock.acquire()) {
translog.foldGeneration(generation + i);
translog.foldGeneration();
}
assertThat(translog.currentFileGeneration(), equalTo(generation + i + 1));
assertThat(translog.totalOperations(), equalTo(totalOperations));
Expand Down

0 comments on commit 7e69ae8

Please sign in to comment.