Require memberId() for RaftStorage 33/116033/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 24 Mar 2025 10:54:07 +0000 (11:54 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 24 Mar 2025 10:56:00 +0000 (11:56 +0100)
We need a consistent way of logging, make sure RaftStorage has it.

JIRA: CONTROLLER-2134
Change-Id: I67ca04c5c7e45358276775285ea05fd58fb7ce3e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/PekkoRaftStorage.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/PersistenceControl.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/spi/DisabledRaftStorage.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/spi/RaftStorage.java

index a151aafa543e3444790aafdf18e233ca38729bb3..c9de0442d3680e7c3e700e10c7cdac4c619fa0d1 100644 (file)
@@ -29,6 +29,11 @@ final class PekkoRaftStorage extends EnabledRaftStorage {
         this.actor = requireNonNull(actor);
     }
 
+    @Override
+    protected String memberId() {
+        return actor.memberId();
+    }
+
     @Override
     public <T> void persist(final T entry, final Consumer<T> callback) {
         actor.persist(entry, callback::accept);
index 3979e206df072a38d4819b498173c69995973b4c..43bc76b8a4969cca39715927a42244e7e66a06c7 100644 (file)
@@ -47,7 +47,8 @@ final class PersistenceControl extends ForwardingDataPersistenceProvider {
     }
 
     PersistenceControl(final RaftActor raftActor) {
-        this(new DisabledRaftStorage(raftActor, raftActor.self()), new PekkoRaftStorage(raftActor));
+        this(new DisabledRaftStorage(raftActor.memberId(), raftActor, raftActor.self()),
+            new PekkoRaftStorage(raftActor));
     }
 
     @Override
index 46f770e92e90b6e378d44ce131189504a55befd5..b462add4863c2464c48748ff4fde401d851d3513 100644 (file)
@@ -38,14 +38,21 @@ public final class DisabledRaftStorage extends RaftStorage implements ImmediateD
         }
     }
 
+    private final String memberId;
     private final ExecuteInSelfActor actor;
     private final ActorRef actorRef;
 
-    public DisabledRaftStorage(final ExecuteInSelfActor actor, final ActorRef actorRef) {
+    public DisabledRaftStorage(final String memberId, final ExecuteInSelfActor actor, final ActorRef actorRef) {
+        this.memberId = requireNonNull(memberId);
         this.actor = requireNonNull(actor);
         this.actorRef = requireNonNull(actorRef);
     }
 
+    @Override
+    protected String memberId() {
+        return memberId;
+    }
+
     /**
      * {@inheritDoc}
      *
index 7265f70107ffa3b422d2b0316975b602dd8425a4..8996770ca9befd2b40300c261e722e5617282f7d 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.cluster.raft.spi;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
@@ -15,7 +17,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 @NonNullByDefault
 public abstract sealed class RaftStorage implements DataPersistenceProvider
         permits DisabledRaftStorage, EnabledRaftStorage {
-    // Nothing else for now, but there is lot more to come.
     // FIXME: we should bave the concept of being 'open', when we have a thread pool to perform the asynchronous part
     //        of RaftActorSnapshotCohort.createSnapshot(), using virtual-thread-per-task
 
@@ -25,4 +26,20 @@ public abstract sealed class RaftStorage implements DataPersistenceProvider
     //         - for small snapshots just use memory and throw them away as sson as unreferenced
     //         - for large snapshots keep them on disk even after they become unreferenced -- for some time, or journal
     //           activity.
+
+    /**
+     * Returns the member name associated with this storage.
+     *
+     * @return the member name associated with this storage
+     */
+    protected abstract String memberId();
+
+    @Override
+    public final String toString() {
+        return addToStringAtrributes(MoreObjects.toStringHelper(this)).toString();
+    }
+
+    protected ToStringHelper addToStringAtrributes(final ToStringHelper helper) {
+        return helper.add("memberId", memberId());
+    }
 }