Remove JournalWriter.truncate() 62/111662/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 13:08:44 +0000 (15:08 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 14:33:55 +0000 (16:33 +0200)
The truncate(N) operation is completely equivalent to reset(N + 1).
Remove this duplicity, preventing potential confusion.

JIRA: CONTROLLER-2100
Change-Id: If62e55edfd610c87174a6b83a15c0a1a0ab7836c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java
atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java

index 58f9d35291da5d5e9b44869897545e627c9ea896..910759cd17ab565d5bd116d1744c2d5aa7164c46 100644 (file)
@@ -55,16 +55,6 @@ public interface ByteBufWriter {
     // FIXME: throws IOException
     void reset(long index);
 
-    /**
-     * Truncates the log to the given index.
-     *
-     * @param index The index to which to truncate the log.
-     * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index
-     */
-    // FIXME: reconcile with reset()
-    // FIXME: throws IOException
-    void truncate(long index);
-
     /**
      * Flushes written entries to disk.
      */
index 0561c99fe04579a713b12af38cdec7b2b94971e1..649e43e4efda36051f50d28a6cbe44076978219e 100644 (file)
@@ -51,18 +51,8 @@ public interface JournalWriter<E> {
      * @param index the next index to write
      * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index
      */
-    // FIXME: reconcile with reader's reset and truncate()
     void reset(long index);
 
-    /**
-     * Truncates the log to the given index.
-     *
-     * @param index The index to which to truncate the log.
-     * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index
-     */
-    // FIXME: reconcile with reset()
-    void truncate(long index);
-
     /**
      * Flushes written entries to disk.
      */
index 6d50ef642f2b5d9ab4a7a2c782b9ef3de5d20335..5ef55393fe1ddae88306f4c10ea6957222237a90 100644 (file)
@@ -87,14 +87,6 @@ final class SegmentedByteBufWriter implements ByteBufWriter {
         }
     }
 
-    @Override
-    public void truncate(final long index) {
-        if (index < journal.getCommitIndex()) {
-            throw new IndexOutOfBoundsException("Cannot truncate committed index: " + index);
-        }
-        checkedTruncate(index);
-    }
-
     private void checkedTruncate(final long index) {
         // Delete all segments with first indexes greater than the given index.
         while (index < currentSegment.firstIndex() && currentSegment != journal.firstSegment()) {
index 11aa6c2431f8a5b926bf8dda9815e1a551eee5fa..a5e0737940da27faca0633d62dffc97de58f87e6 100644 (file)
@@ -51,11 +51,6 @@ final class SegmentedJournalWriter<E> implements JournalWriter<E> {
         writer.reset(index);
     }
 
-    @Override
-    public void truncate(final long index) {
-        writer.truncate(index);
-    }
-
     @Override
     public void flush() {
         writer.flush();
index 8abc2b2779ccac2df3da6ca20a87996533bc7721..6118f600cd04291385aa58967e2c0bfad4fd86fe 100644 (file)
@@ -153,7 +153,7 @@ public abstract class AbstractJournalTest {
             assertNoNext(reader);
 
             // Truncate the journal and write a different entry.
-            writer.truncate(1);
+            writer.reset(2);
             assertEquals(2, writer.getNextIndex());
             writer.append(ENTRY);
             reader.reset(2);
@@ -204,7 +204,7 @@ public abstract class AbstractJournalTest {
             indexed = assertNext(reader);
             assertEquals(1, indexed.index());
 
-            writer.truncate(0);
+            writer.reset(1);
             assertEquals(0, journal.lastIndex());
             assertEquals(1, writer.getNextIndex());
             indexed = writer.append(ENTRY);
@@ -232,7 +232,7 @@ public abstract class AbstractJournalTest {
                 assertEquals(j, assertNext(reader).index());
             }
 
-            writer.truncate(i - 2);
+            writer.reset(i - 1);
 
             assertNoNext(reader);
             assertEquals(i - 1, writer.append(new TestEntry(32)).index());
@@ -269,7 +269,7 @@ public abstract class AbstractJournalTest {
                     reader.reset(i + 1);
                 }
 
-                writer.truncate(i - 1);
+                writer.reset(i);
                 writer.append(ENTRY);
 
                 assertNext(reader);