Remove JournalWriter.append(Indexed) 63/110663/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Mar 2024 09:24:04 +0000 (10:24 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Mar 2024 10:11:51 +0000 (11:11 +0100)
This method is only used in a single test and can be realized via the
usual append(E) method. Remove it.

JIRA: CONTROLLER-2101
Change-Id: Ie1ec3507c18d9970be4968c9239b08ad8323f3a9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/FileChannelJournalSegmentWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/MappedJournalSegmentWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java
atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java

index 7e9b81035d1420242bf6da21de68a05d3881b937..4d3aa783637828ef189c5af5ec54e51d5698b0f3 100644 (file)
@@ -167,22 +167,6 @@ final class FileChannelJournalSegmentWriter<E> extends JournalSegmentWriter<E> {
     }
   }
 
-  @Override
-  void append(Indexed<E> entry) {
-    final long nextIndex = getNextIndex();
-
-    // If the entry's index is greater than the next index in the segment, skip some entries.
-    if (entry.index() > nextIndex) {
-      throw new IndexOutOfBoundsException("Entry index is not sequential");
-    }
-
-    // If the entry's index is less than the next index, truncate the segment.
-    if (entry.index() < nextIndex) {
-      truncate(entry.index() - 1);
-    }
-    append(entry.entry());
-  }
-
   @Override
   @SuppressWarnings("unchecked")
   <T extends E> Indexed<T> append(T entry) {
index d552d84be84b944172c714cab27db92f3b19fd10..15b9ba57f5667d2fe03b60a6cbfe151f3ab6a577 100644 (file)
@@ -71,13 +71,6 @@ abstract sealed class JournalSegmentWriter<E> permits FileChannelJournalSegmentW
      */
     abstract <T extends E> Indexed<T> append(T entry);
 
-    /**
-     * Appends an indexed entry to the log.
-     *
-     * @param entry The indexed entry to append.
-     */
-    abstract void append(Indexed<E> entry);
-
     /**
      * Resets the head of the segment to the given index.
      *
index f5ee18b2e6a573927e51c347fc33457056303aef..95284978bd9af283b696366b85d80acb7cde5ffc 100644 (file)
@@ -50,13 +50,6 @@ public interface JournalWriter<E> {
    */
   <T extends E> Indexed<T> append(T entry);
 
-  /**
-   * Appends an indexed entry to the log.
-   *
-   * @param entry The indexed entry to append.
-   */
-  void append(Indexed<E> entry);
-
   /**
    * Commits entries up to the given index.
    *
index 22c03be39f6ffb1f91ecab4dbd453437750fd9fb..18aba4879e042a72b34b5b37a133e7d1e69830fe 100644 (file)
@@ -168,22 +168,6 @@ final class MappedJournalSegmentWriter<E> extends JournalSegmentWriter<E> {
     }
   }
 
-  @Override
-  void append(Indexed<E> entry) {
-    final long nextIndex = getNextIndex();
-
-    // If the entry's index is greater than the next index in the segment, skip some entries.
-    if (entry.index() > nextIndex) {
-      throw new IndexOutOfBoundsException("Entry index is not sequential");
-    }
-
-    // If the entry's index is less than the next index, truncate the segment.
-    if (entry.index() < nextIndex) {
-      truncate(entry.index() - 1);
-    }
-    append(entry.entry());
-  }
-
   @Override
   @SuppressWarnings("unchecked")
   <T extends E> Indexed<T> append(T entry) {
index ad900b003e84e67fc0334975794a8410732729c9..6f73990b6fd44ddd8ea1654871300885a87d8a6f 100644 (file)
@@ -78,30 +78,11 @@ final class SegmentedJournalWriter<E> implements JournalWriter<E> {
       }
     }
 
-    moveToNextSegment();
-    return currentWriter.append(entry);
-  }
-
-  @Override
-  public void append(Indexed<E> entry) {
-    try {
-      currentWriter.append(entry);
-      return;
-    } catch (BufferOverflowException e) {
-      if (currentSegment.index() == currentWriter.getNextIndex()) {
-        throw e;
-      }
-    }
-
-    moveToNextSegment();
-    currentWriter.append(entry);
-  }
-
-  private void moveToNextSegment() {
     currentWriter.flush();
     currentSegment.releaseWriter();
     currentSegment = journal.getNextSegment();
     currentWriter = currentSegment.acquireWriter();
+    return currentWriter.append(entry);
   }
 
   @Override
index 222d0bfe391307e7b49528be431cf82c37523665..f574f900b145de2f4889158bb9bfbb9b154acd70 100644 (file)
@@ -110,7 +110,7 @@ public abstract class AbstractJournalTest {
       assertEquals(1, indexed.index());
 
       assertEquals(2, writer.getNextIndex());
-      writer.append(new Indexed<>(2, ENTRY, 0));
+      writer.append(ENTRY);
       reader.reset(2);
       indexed = reader.next();
       assertEquals(2, indexed.index());
@@ -174,7 +174,7 @@ public abstract class AbstractJournalTest {
       // Truncate the journal and write a different entry.
       writer.truncate(1);
       assertEquals(2, writer.getNextIndex());
-      writer.append(new Indexed<>(2, ENTRY, 0));
+      writer.append(ENTRY);
       reader.reset(2);
       indexed = reader.next();
       assertEquals(2, indexed.index());