Rename ByteBufJournal 89/111689/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 14 May 2024 12:29:25 +0000 (14:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 14 May 2024 12:31:29 +0000 (14:31 +0200)
Split out the base interfaces into controller.raft.journal, allowing us
to split out the implementation as well.

JIRA: CONTROLLER-2115
Change-Id: I429872d92da6b4044b393e2a0d5e05f5c9823ee4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.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/SegmentedByteBufWriter.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedCommitsByteBufReader.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/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java
atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/EntryReader.java [moved from atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java with 90% similarity]
atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/EntryWriter.java [moved from atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java with 93% similarity]
atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/FromByteBufMapper.java [moved from atomix-storage/src/main/java/io/atomix/storage/journal/FromByteBufMapper.java with 95% similarity]
atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/RaftJournal.java [moved from atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufJournal.java with 80% similarity]
atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/ToByteBufMapper.java [moved from atomix-storage/src/main/java/io/atomix/storage/journal/ToByteBufMapper.java with 96% similarity]
atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/package-info.java [new file with mode: 0644]
opendaylight/md-sal/sal-akka-segmented-journal/src/main/java/org/opendaylight/controller/akka/segjournal/SegmentedJournalActor.java

index 75c8e25b459c224fd362c86e0fbb057a362bb1c6..12b5eb7ce6f55f8f769e073e73209b39c75afbe2 100644 (file)
@@ -25,6 +25,7 @@ import java.io.EOFException;
 import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.controller.raft.journal.ToByteBufMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 8ae7dbed707a1e89385b15f0080ac005a6554364..cb9d3614bd1f48834f966ec9c4f5229b36b9f618 100644 (file)
@@ -25,6 +25,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
+import org.opendaylight.controller.raft.journal.FromByteBufMapper;
+import org.opendaylight.controller.raft.journal.ToByteBufMapper;
 
 /**
  * Support for serialization of {@link Journal} entries.
index 2468ee2d9bd249660582dad98b6d3fc7393ec14d..ad4b1801e10669ae93df6b78a9eb23974842c4cd 100644 (file)
@@ -32,23 +32,26 @@ import java.util.function.BiFunction;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.controller.raft.journal.EntryReader;
+import org.opendaylight.controller.raft.journal.EntryWriter;
+import org.opendaylight.controller.raft.journal.RaftJournal;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A {@link ByteBufJournal} Implementation.
+ * A {@link RaftJournal} Implementation.
  */
-public final class SegmentedByteBufJournal implements ByteBufJournal {
+public final class SegmentedByteBufJournal implements RaftJournal {
     private static final Logger LOG = LoggerFactory.getLogger(SegmentedByteBufJournal.class);
     private static final int SEGMENT_BUFFER_FACTOR = 3;
 
     private final ConcurrentNavigableMap<Long, JournalSegment> segments = new ConcurrentSkipListMap<>();
-    private final Collection<ByteBufReader> readers = ConcurrentHashMap.newKeySet();
+    private final Collection<EntryReader> readers = ConcurrentHashMap.newKeySet();
     private final @NonNull ByteBufAllocator allocator;
     private final @NonNull StorageLevel storageLevel;
     private final @NonNull File directory;
     private final @NonNull String name;
-    private final @NonNull ByteBufWriter writer;
+    private final @NonNull EntryWriter writer;
     private final int maxSegmentSize;
     private final int maxEntrySize;
     @Deprecated(forRemoval = true)
@@ -110,18 +113,18 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
     }
 
     @Override
-    public ByteBufWriter writer() {
+    public EntryWriter writer() {
         return writer;
     }
 
     @Override
-    public ByteBufReader openReader(final long index) {
+    public EntryReader openReader(final long index) {
         return openReader(index, SegmentedByteBufReader::new);
     }
 
     @NonNullByDefault
-    private ByteBufReader openReader(final long index,
-            final BiFunction<SegmentedByteBufJournal, JournalSegment, ByteBufReader> constructor) {
+    private EntryReader openReader(final long index,
+            final BiFunction<SegmentedByteBufJournal, JournalSegment, EntryReader> constructor) {
         final var reader = constructor.apply(this, segment(index));
         reader.reset(index);
         readers.add(reader);
@@ -129,7 +132,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
     }
 
     @Override
-    public ByteBufReader openCommitsReader(final long index) {
+    public EntryReader openCommitsReader(final long index) {
         return openReader(index, SegmentedCommitsByteBufReader::new);
     }
 
index 72a954325c3350a1b05c32296210a1cab16c1757..7f7a903f57a4aa3a8a39f9f6039c4f3516f66ea0 100644 (file)
@@ -20,11 +20,13 @@ import static java.util.Objects.requireNonNull;
 
 import io.netty.buffer.ByteBuf;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.raft.journal.EntryReader;
+import org.opendaylight.controller.raft.journal.FromByteBufMapper;
 
 /**
- * A {@link ByteBufReader} implementation.
+ * A {@link EntryReader} implementation.
  */
-sealed class SegmentedByteBufReader implements ByteBufReader permits SegmentedCommitsByteBufReader {
+sealed class SegmentedByteBufReader implements EntryReader permits SegmentedCommitsByteBufReader {
     final @NonNull SegmentedByteBufJournal journal;
 
     private JournalSegment currentSegment;
index 1875a71b32cc0f1b5b45539f22dc61af886c8081..464a75e4b77f8179ac37f945381cbe2e3a51c5b4 100644 (file)
@@ -19,10 +19,13 @@ package io.atomix.storage.journal;
 import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
+import org.opendaylight.controller.raft.journal.EntryWriter;
+import org.opendaylight.controller.raft.journal.ToByteBufMapper;
+
 /**
- * A {@link ByteBufWriter} implementation.
+ * A {@link EntryWriter} implementation.
  */
-final class SegmentedByteBufWriter implements ByteBufWriter {
+final class SegmentedByteBufWriter implements EntryWriter {
     private final SegmentedByteBufJournal journal;
 
     private JournalSegment currentSegment;
index 135549a9a197f67953c89fa79a7b14f4d6846a30..f3aa325de3859a5816d3e60f0f1d53ee9af1f138 100644 (file)
 package io.atomix.storage.journal;
 
 import io.netty.buffer.ByteBuf;
+import org.opendaylight.controller.raft.journal.EntryReader;
 
 /**
- * A {@link ByteBufReader} traversing only committed entries.
+ * A {@link EntryReader} traversing only committed entries.
  */
 final class SegmentedCommitsByteBufReader extends SegmentedByteBufReader {
     SegmentedCommitsByteBufReader(final SegmentedByteBufJournal journal, final JournalSegment segment) {
index 501e650dc59baa28a5db15f2964eebc6a1e903b3..a3cb3ad29c68ae68f09a80118fcc1570d6657c00 100644 (file)
@@ -20,16 +20,19 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.raft.journal.FromByteBufMapper;
+import org.opendaylight.controller.raft.journal.RaftJournal;
+import org.opendaylight.controller.raft.journal.ToByteBufMapper;
 
 /**
- * A {@link Journal} implementation based on a {@link ByteBufJournal}.
+ * A {@link Journal} implementation based on a {@link RaftJournal}.
  */
 public final class SegmentedJournal<E> implements Journal<E> {
     private final @NonNull SegmentedJournalWriter<E> writer;
     private final @NonNull FromByteBufMapper<E> readMapper;
-    private final @NonNull ByteBufJournal journal;
+    private final @NonNull RaftJournal journal;
 
-    public SegmentedJournal(final ByteBufJournal journal, final FromByteBufMapper<E> readMapper,
+    public SegmentedJournal(final RaftJournal journal, final FromByteBufMapper<E> readMapper,
             final ToByteBufMapper<E> writeMapper) {
         this.journal = requireNonNull(journal, "journal is required");
         this.readMapper = requireNonNull(readMapper, "readMapper cannot be null");
index 12ad0a437c3a7905273f495b470b98926a176bb0..4021518ef5273eba5486b36b5f0142f9bf040f07 100644 (file)
@@ -20,16 +20,18 @@ import static java.util.Objects.requireNonNull;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.controller.raft.journal.EntryReader;
+import org.opendaylight.controller.raft.journal.FromByteBufMapper;
 
 /**
- * A {@link JournalReader} backed by a {@link ByteBufReader}.
+ * A {@link JournalReader} backed by a {@link EntryReader}.
  */
 @NonNullByDefault
 final class SegmentedJournalReader<E> implements JournalReader<E> {
     private final FromByteBufMapper<E> mapper;
-    private final ByteBufReader reader;
+    private final EntryReader reader;
 
-    SegmentedJournalReader(final ByteBufReader reader, final FromByteBufMapper<E> mapper) {
+    SegmentedJournalReader(final EntryReader reader, final FromByteBufMapper<E> mapper) {
         this.reader = requireNonNull(reader);
         this.mapper = requireNonNull(mapper);
     }
index f945a40c2f55fba3301215686b26ad3d6e855e85..9d266147e3855d7a8538ef45b6e42e4636e14991 100644 (file)
@@ -19,16 +19,18 @@ package io.atomix.storage.journal;
 import static java.util.Objects.requireNonNull;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.controller.raft.journal.EntryWriter;
+import org.opendaylight.controller.raft.journal.ToByteBufMapper;
 
 /**
- * A {@link JournalWriter} backed by a {@link ByteBufWriter}.
+ * A {@link JournalWriter} backed by a {@link EntryWriter}.
  */
 @NonNullByDefault
 final class SegmentedJournalWriter<E> implements JournalWriter<E> {
     private final ToByteBufMapper<E> mapper;
-    private final ByteBufWriter writer;
+    private final EntryWriter writer;
 
-    SegmentedJournalWriter(final ByteBufWriter writer, final ToByteBufMapper<E> mapper) {
+    SegmentedJournalWriter(final EntryWriter writer, final ToByteBufMapper<E> mapper) {
         this.writer = requireNonNull(writer);
         this.mapper = requireNonNull(mapper);
     }
similarity index 90%
rename from atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java
rename to atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/EntryReader.java
index c43e0ea8954553d7ee5e3875b873e5777b90c4b0..eff722ef84aeb4a1b2faca72168223539381265a 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.atomix.storage.journal;
+package org.opendaylight.controller.raft.journal;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 
 /**
- * A reader of {@link ByteBufJournal} entries.
+ * A reader of {@link RaftJournal} entries.
  */
 @NonNullByDefault
-public interface ByteBufReader extends AutoCloseable {
+public interface EntryReader extends AutoCloseable {
     /**
      * Returns the next reader index.
      *
similarity index 93%
rename from atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java
rename to atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/EntryWriter.java
index eee75cb8f6b37ef0517acd1fc2d6d5532ce7fd09..18a0d081cdaa4b9727ffb120d3e03cb11da9eb84 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.atomix.storage.journal;
+package org.opendaylight.controller.raft.journal;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * A writer of {@link ByteBufJournal} entries.
+ * A writer of {@link RaftJournal} entries.
  */
 @NonNullByDefault
-public interface ByteBufWriter {
+public interface EntryWriter {
     /**
      * Returns the next index to be written.
      *
similarity index 95%
rename from atomix-storage/src/main/java/io/atomix/storage/journal/FromByteBufMapper.java
rename to atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/FromByteBufMapper.java
index 5a0c736d57a9cf2227b232faa13657e51e23fe9c..73955d3105041f81853400fd56873e444c79440d 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.atomix.storage.journal;
+package org.opendaylight.controller.raft.journal;
 
 import io.netty.buffer.ByteBuf;
 import org.eclipse.jdt.annotation.NonNullByDefault;
similarity index 80%
rename from atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufJournal.java
rename to atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/RaftJournal.java
index 8a7083c93101c9cec5c1310409ddc73f659509c0..e02b399208190cc7177461ee9954f25528510bc5 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.atomix.storage.journal;
+package org.opendaylight.controller.raft.journal;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * A journal of byte arrays. Provides the ability to write modify entries via {@link ByteBufWriter} and read them
- * back via {@link ByteBufReader}.
+ * A journal of byte arrays. Provides the ability to write modify entries via {@link EntryWriter} and read them
+ * back via {@link EntryReader}.
  */
 @NonNullByDefault
-public interface ByteBufJournal extends AutoCloseable {
+public interface RaftJournal extends AutoCloseable {
     /**
      * Return the index of the first entry in the journal.
      *
@@ -42,23 +42,23 @@ public interface ByteBufJournal extends AutoCloseable {
      *
      * @return The journal writer.
      */
-    ByteBufWriter writer();
+    EntryWriter writer();
 
     /**
-     * Opens a new {@link ByteBufReader} reading all entries.
+     * Opens a new {@link EntryReader} reading all entries.
      *
      * @param index The index at which to start the reader.
      * @return A new journal reader.
      */
-    ByteBufReader openReader(long index);
+    EntryReader openReader(long index);
 
     /**
-     * Opens a new {@link ByteBufReader} reading only committed entries.
+     * Opens a new {@link EntryReader} reading only committed entries.
      *
      * @param index The index at which to start the reader.
      * @return A new journal reader.
      */
-    ByteBufReader openCommitsReader(long index);
+    EntryReader openCommitsReader(long index);
 
     /**
      * Compacts the journal up to the given index.
similarity index 96%
rename from atomix-storage/src/main/java/io/atomix/storage/journal/ToByteBufMapper.java
rename to atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/ToByteBufMapper.java
index 268eacdb21d75b2c783b4c796f12328da99c9c85..95fe3446e35354cae27e4c49117d56125a5d38e5 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.atomix.storage.journal;
+package org.opendaylight.controller.raft.journal;
 
 import io.netty.buffer.ByteBuf;
 import java.io.EOFException;
diff --git a/atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/package-info.java b/atomix-storage/src/main/java/org/opendaylight/controller/raft/journal/package-info.java
new file mode 100644 (file)
index 0000000..821103b
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Storage primitives for a RAFT journal.
+ */
+package org.opendaylight.controller.raft.journal;
index 49cfaf080cb7e9fa37afc435bd69e5421635823f..0b7808391162327188cc871c69caf75422b88c4c 100644 (file)
@@ -23,13 +23,11 @@ import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Timer;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Stopwatch;
-import io.atomix.storage.journal.FromByteBufMapper;
 import io.atomix.storage.journal.Indexed;
 import io.atomix.storage.journal.JournalSerdes;
 import io.atomix.storage.journal.SegmentedByteBufJournal;
 import io.atomix.storage.journal.SegmentedJournal;
 import io.atomix.storage.journal.StorageLevel;
-import io.atomix.storage.journal.ToByteBufMapper;
 import java.io.File;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
@@ -39,6 +37,8 @@ import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 import org.opendaylight.controller.cluster.common.actor.MeteringBehavior;
 import org.opendaylight.controller.cluster.reporting.MetricsReporter;
+import org.opendaylight.controller.raft.journal.FromByteBufMapper;
+import org.opendaylight.controller.raft.journal.ToByteBufMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.Future;