Move {Journal,ByteBuf}Reader.firstIndex() 87/111687/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 14 May 2024 11:45:08 +0000 (13:45 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 14 May 2024 11:46:02 +0000 (13:46 +0200)
Similar to lastIndex(), firstIndex() is a journal-level thing. Move it
out.

JIRA: CONTROLLER-2115
Change-Id: I7257194d65dbd47960bf6be4af12ea56056d3c9f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufJournal.java
atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java
atomix-storage/src/main/java/io/atomix/storage/journal/Journal.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalReader.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufReader.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalReader.java
atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java

index cae71fffcbfbbceefcb13bdb712502db6a645a28..8a7083c93101c9cec5c1310409ddc73f659509c0 100644 (file)
@@ -23,10 +23,17 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
  */
 @NonNullByDefault
 public interface ByteBufJournal extends AutoCloseable {
+    /**
+     * Return the index of the first entry in the journal.
+     *
+     * @return the index of the first entry in the journal
+     */
+    long firstIndex();
+
     /**
      * Return the index of the last entry in the journal.
      *
-     * @return the last index, or zero if there are no entries.
+     * @return the last index, or zero if there are no entries
      */
     long lastIndex();
 
index ad447025372696eee68380772f9f739f02804431..80135118b926810b4a6ab8680c611a9aed81b4ff 100644 (file)
@@ -41,13 +41,6 @@ public interface ByteBufReader extends AutoCloseable {
         T mapEntry(long index, ByteBuf bytes);
     }
 
-    /**
-     * Returns the first index in the journal.
-     *
-     * @return The first index in the journal
-     */
-    long firstIndex();
-
     /**
      * Returns the next reader index.
      *
index b80324e9a1fc1efde276219e28b271e64f20a4e0..996c0832030844610067a71e6ad129b98642f74d 100644 (file)
@@ -23,6 +23,13 @@ import io.atomix.storage.journal.JournalReader.Mode;
  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
  */
 public interface Journal<E> extends AutoCloseable {
+    /**
+     * Return the index of the first entry in the journal.
+     *
+     * @return the index of the first entry in the journal
+     */
+    long firstIndex();
+
     /**
      * Return the index of the last entry in the journal.
      *
index 8f49aa2ebcabd1c26e59bd091f74e9b540ad6cae..4dd5c935f65632c2fccbbb81c4ff4ae72eb50258 100644 (file)
@@ -58,13 +58,6 @@ public interface JournalReader<E> extends AutoCloseable {
         T mapEntry(long index, E entry, int size);
     }
 
-    /**
-     * Returns the first index in the journal.
-     *
-     * @return the first index in the journal
-     */
-    long getFirstIndex();
-
     /**
      * Returns the next reader index.
      *
index 2c6ccb5599edfe3a2294647c85ea5eefa7160c5f..2468ee2d9bd249660582dad98b6d3fc7393ec14d 100644 (file)
@@ -99,6 +99,11 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
             .sum();
     }
 
+    @Override
+    public long firstIndex() {
+        return firstSegment().firstIndex();
+    }
+
     @Override
     public long lastIndex() {
         return lastSegment().lastIndex();
index d7eb68e8478811c1ff81c279bb38b8a7f9933132..215255a4dc788ac6f9b7361fae9a4e70bebbdc51 100644 (file)
@@ -38,11 +38,6 @@ sealed class SegmentedByteBufReader implements ByteBufReader permits SegmentedCo
         nextIndex = currentSegment.firstIndex();
     }
 
-    @Override
-    public final long firstIndex() {
-        return journal.firstSegment().firstIndex();
-    }
-
     @Override
     public final long nextIndex() {
         return nextIndex;
index 11970ba083ce6d3521ac7616c1d4e154adf489c7..d143ee42fd843cbb44b5cf5bc0bc221435a8089a 100644 (file)
@@ -34,6 +34,11 @@ public final class SegmentedJournal<E> implements Journal<E> {
         writer = new SegmentedJournalWriter<>(journal.writer(), mapper);
     }
 
+    @Override
+    public long firstIndex() {
+        return journal.firstIndex();
+    }
+
     @Override
     public long lastIndex() {
         return journal.lastIndex();
index db0531acec56350076a538434c90e9f917e859aa..99fdbb64b1577e14bfe05e3ccf7e67e11cfe691c 100644 (file)
@@ -34,11 +34,6 @@ final class SegmentedJournalReader<E> implements JournalReader<E> {
         this.mapper = requireNonNull(mapper);
     }
 
-    @Override
-    public long getFirstIndex() {
-        return reader.firstIndex();
-    }
-
     @Override
     public long getNextIndex() {
         return reader.nextIndex();
index 5cb516b7b668b425269d5d8622309eff1f5d96ce..03b5ab4c36464f1f5d893c4f103f7bdac9302b25 100644 (file)
@@ -375,7 +375,7 @@ public abstract class AbstractJournalTest {
 
             // Ensure the reader starts at the first physical index in the journal.
             assertEquals(entriesPerSegment + 1, reader.getNextIndex());
-            assertEquals(reader.getFirstIndex(), reader.getNextIndex());
+            assertEquals(journal.firstIndex(), reader.getNextIndex());
             assertEquals(entriesPerSegment + 1, assertNext(reader).index());
             assertEquals(entriesPerSegment + 2, reader.getNextIndex());
         }