diff --git a/core/src/main/java/org/elasticsearch/index/translog/Translog.java b/core/src/main/java/org/elasticsearch/index/translog/Translog.java index e0e2354e9e4f8..8dbfd54a0fb4d 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/core/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -127,7 +127,7 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC private final TranslogConfig config; private final LongSupplier globalCheckpointSupplier; private final String translogUUID; - private final AtomicBoolean foldingGeneration = new AtomicBoolean(); + private final AtomicBoolean rollingGeneration = new AtomicBoolean(); /** * Creates a new Translog instance. This method will create a new transaction log unless the given {@link TranslogGeneration} is @@ -424,14 +424,14 @@ public Location add(final Operation operation) throws IOException { ensureOpen(); location = current.add(bytes, operation.seqNo()); } - if (shouldFoldGeneration() && foldingGeneration.compareAndSet(false, true)) { - // we have to check the condition again lest we could fold twice in a race - if (shouldFoldGeneration()) { + if (shouldRollGeneration() && rollingGeneration.compareAndSet(false, true)) { + // we have to check the condition again lest we could roll twice in a race + if (shouldRollGeneration()) { try (ReleasableLock ignored = writeLock.acquire()) { - this.foldGeneration(); + this.rollGeneration(); } - final boolean wasFoldingGeneration = foldingGeneration.getAndSet(false); - assert wasFoldingGeneration; + final boolean wasRolling = rollingGeneration.getAndSet(false); + assert wasRolling; } } return location; @@ -455,13 +455,13 @@ public Location add(final Operation operation) throws IOException { } /** - * Tests whether or not the current generation of the translog should be folded into a new + * Tests whether or not the current generation of the translog should be rolled into a new * generation. This test is based on the size of the current generation compared to the * configured generation threshold size. * - * @return {@code true} if the current generation should be folded into a new generation + * @return {@code true} if the current generation should be rolled into a new generation */ - private boolean shouldFoldGeneration() { + private boolean shouldRollGeneration() { final long size = this.current.sizeInBytes(); final long threshold = this.indexSettings.getGenerationThresholdSize().getBytes(); return size > threshold; @@ -1348,12 +1348,12 @@ public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Transl } /** - * Fold the current translog generation into a new generation. This does not commit the + * Roll 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. * * @throws IOException if an I/O exception occurred during any file operations */ - void foldGeneration() throws IOException { + void rollGeneration() throws IOException { assert writeLock.isHeldByCurrentThread(); try { final TranslogReader reader = current.closeIntoReader(); @@ -1383,7 +1383,7 @@ public long prepareCommit() throws IOException { currentCommittingGeneration); } currentCommittingGeneration = current.getGeneration(); - foldGeneration(); + rollGeneration(); } return 0L; } diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index f56a9879c4d3b..b345c0be29496 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -2089,33 +2089,33 @@ public void testTranslogOpSerialization() throws Exception { assertEquals(delete, serializedDelete); } - public void testFoldGeneration() throws IOException { + public void testRollGeneration() throws IOException { final long generation = translog.currentFileGeneration(); - final int folds = randomIntBetween(1, 16); + final int rolls = randomIntBetween(1, 16); int totalOperations = 0; int seqNo = 0; - for (int i = 0; i < folds; i++) { + for (int i = 0; i < rolls; i++) { final int operations = randomIntBetween(1, 128); for (int j = 0; j < operations; j++) { translog.add(new Translog.NoOp(seqNo++, 0, "test")); totalOperations++; } try (ReleasableLock ignored = translog.writeLock.acquire()) { - translog.foldGeneration(); + translog.rollGeneration(); } assertThat(translog.currentFileGeneration(), equalTo(generation + i + 1)); assertThat(translog.totalOperations(), equalTo(totalOperations)); } - for (int i = 0; i <= folds; i++) { + for (int i = 0; i <= rolls; i++) { assertFileIsPresent(translog, generation + i); } translog.commit(); - assertThat(translog.currentFileGeneration(), equalTo(generation + folds + 1)); + assertThat(translog.currentFileGeneration(), equalTo(generation + rolls + 1)); assertThat(translog.totalOperations(), equalTo(0)); - for (int i = 0; i <= folds; i++) { + for (int i = 0; i <= rolls; i++) { assertFileDeleted(translog, generation + i); } - assertFileIsPresent(translog, generation + folds + 1); + assertFileIsPresent(translog, generation + rolls + 1); } public void testGenerationThreshold() throws IOException { @@ -2126,24 +2126,24 @@ public void testGenerationThreshold() throws IOException { .put("index.translog.generation_threshold_size", generationThreshold + "b") .build(); long seqNo = 0; - long folds = 0; + long rolls = 0; final TranslogConfig config = getTranslogConfig(translogDir, settings); try (Translog translog = new Translog(config, null, () -> SequenceNumbersService.UNASSIGNED_SEQ_NO)) { final long generation = translog.currentFileGeneration(); for (int i = 0; i < randomIntBetween(32, 128); i++) { - assertThat(translog.currentFileGeneration(), equalTo(generation + folds)); + assertThat(translog.currentFileGeneration(), equalTo(generation + rolls)); final Location location = translog.add(new Translog.NoOp(seqNo++, 0, "test")); if (location.translogLocation + location.size > generationThreshold) { - folds++; - assertThat(translog.currentFileGeneration(), equalTo(generation + folds)); - for (int j = 0; j < folds; j++) { + rolls++; + assertThat(translog.currentFileGeneration(), equalTo(generation + rolls)); + for (int j = 0; j < rolls; j++) { assertFileIsPresent(translog, generation + j); } } } - for (int j = 0; j < folds; j++) { + for (int j = 0; j < rolls; j++) { assertFileIsPresent(translog, generation + j); } }