Do not expose descriptor from JournalSegmentFile 29/111629/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 May 2024 22:48:01 +0000 (00:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 May 2024 00:08:13 +0000 (02:08 +0200)
JournalSegmentFile should expose interesting mapping -- the descriptor
is really an internal thing.

JIRA: CONTROLLER-2099
Change-Id: I2276cee3c4cb15d961aaa1b7f72d618f10dd744e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java

index b73d942c036d7c12d760fe23c31c91a36e7f0e8e..2128b87e20241021235337050be23f3276abb1a0 100644 (file)
@@ -74,7 +74,7 @@ final class JournalSegment {
    * @return The segment's starting index.
    */
   long firstIndex() {
-    return file.descriptor().index();
+    return file.firstIndex();
   }
 
   /**
@@ -233,11 +233,10 @@ final class JournalSegment {
 
   @Override
   public String toString() {
-    final var descriptor = file.descriptor();
     return MoreObjects.toStringHelper(this)
-        .add("id", descriptor.id())
-        .add("version", descriptor.version())
-        .add("index", descriptor.index())
-        .toString();
+      .add("id", file.segmentId())
+      .add("version", file.version())
+      .add("index", file.firstIndex())
+      .toString();
   }
 }
index 825baa27a2ca47bfb05374e964d1c3817ce32d64..04e22a1659787792c87d7767f3505f60f7518f84 100644 (file)
@@ -84,12 +84,30 @@ final class JournalSegmentFile {
     }
 
     /**
-     * Returns the segment descriptor.
+     * Returns the segment version.
      *
-     * @return The segment descriptor.
+     * @return the segment version
      */
-    @NonNull JournalSegmentDescriptor descriptor() {
-        return descriptor;
+    int version() {
+        return descriptor.version();
+    }
+
+    /**
+     * Returns the segment identifier.
+     *
+     * @return the segment identifier
+     */
+    long segmentId() {
+        return descriptor.id();
+    }
+
+    /**
+     * Returns the index of first entry stored in this file.
+     *
+     * @return the index of first entry stored in this file
+     */
+    long firstIndex() {
+        return descriptor.index();
     }
 
     int maxSize() {
index 23a5419b8333befb67031b187d3efad17a35a9a9..1ae77fa35114ed62678dd14bf1c7926c2800e09e 100644 (file)
@@ -342,7 +342,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
     final var index = currentSegment.lastIndex() + 1;
     final var lastSegment = getLastSegment();
-    currentSegment = createSegment(lastSegment != null ? lastSegment.file().descriptor().id() + 1 : 1, index);
+    currentSegment = createSegment(lastSegment != null ? lastSegment.file().segmentId() + 1 : 1, index);
     segments.put(index, currentSegment);
     return currentSegment;
   }
@@ -436,7 +436,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
         }
 
         // Load the segment.
-        LOG.debug("Loaded disk segment: {} ({})", segmentFile.descriptor().id(), segmentFile.path());
+        LOG.debug("Loaded disk segment: {} ({})", segmentFile.segmentId(), segmentFile.path());
 
         // Add the segment to the segments list.
         final var segment = new JournalSegment(segmentFile, storageLevel, maxEntrySize, indexDensity);