Deprecate RaftActor.persistenceId() 07/115007/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 29 Jan 2025 18:01:58 +0000 (19:01 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 29 Jan 2025 18:03:50 +0000 (19:03 +0100)
persistenceId() is something we inherit from AbstractPersistentActor,
which we are getting rid of.

Make RaftActor.getId() public as memberId() and use it instead of
persistenceId().

JIRA: CONTROLLER-2073
Change-Id: If8a76654e9d8102a41548883a90d680db833f9f8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohort.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendHistoryMetadataBuilder.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderLocalDelegateFactory.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java

index ea51159330519fead26cdda6f565e18d11445dd3..e08de573b7c1963020baef7fc5835b949d9204bf 100644 (file)
@@ -136,11 +136,12 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     //            - RAFT instance: shard name + datastore type
     //            - cluster member name
     //        We should call this 'memberId' or something similar and propagate that naming
-    protected final @NonNull String getId() {
+    public final @NonNull String getId() {
         return context.getId();
     }
 
     @Override
+    @Deprecated(since = "11.0.0", forRemoval = true)
     public final @NonNull String persistenceId() {
         return getId();
     }
@@ -153,8 +154,8 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
 
     @Override
     public void preStart() throws Exception {
-        LOG.info("Starting recovery for {} with journal batch size {}", persistenceId(),
-                context.getConfigParams().getJournalRecoveryLogBatchSize());
+        LOG.info("Starting recovery for {} with journal batch size {}", getId(),
+            context.getConfigParams().getJournalRecoveryLogBatchSize());
 
         super.preStart();
 
@@ -251,8 +252,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
 
             possiblyHandleBehaviorMessage(message);
         } else if (message instanceof ApplyJournalEntries applyEntries) {
-            LOG.debug("{}: Persisting ApplyJournalEntries with index={}", persistenceId(), applyEntries.getToIndex());
-
+            LOG.debug("{}: Persisting ApplyJournalEntries with index={}", getId(), applyEntries.getToIndex());
             persistence().persistAsync(applyEntries, NoopProcedure.instance());
         } else if (message instanceof FindLeader) {
             getSender().tell(new FindLeaderReply(getLeaderAddress()), self());
@@ -275,10 +275,10 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
         } else if (!possiblyHandleBehaviorMessage(message)) {
             if (message instanceof JournalProtocol.Response response
                 && delegatingPersistenceProvider.handleJournalResponse(response)) {
-                LOG.debug("{}: handled a journal response", persistenceId());
+                LOG.debug("{}: handled a journal response", getId());
             } else if (message instanceof SnapshotProtocol.Response response
                 && delegatingPersistenceProvider.handleSnapshotResponse(response)) {
-                LOG.debug("{}: handled a snapshot response", persistenceId());
+                LOG.debug("{}: handled a snapshot response", getId());
             } else {
                 handleNonRaftCommand(message);
             }
@@ -286,19 +286,20 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     private void onRequestLeadership(final RequestLeadership message) {
-        LOG.debug("{}: onRequestLeadership {}", persistenceId(), message);
+        LOG.debug("{}: onRequestLeadership {}", getId(), message);
+        final var requestedFollowerId = message.getRequestedFollowerId();
+
         if (!isLeader()) {
             // non-leader cannot satisfy leadership request
             LOG.warn("{}: onRequestLeadership {} was sent to non-leader."
                     + " Current behavior: {}. Sending failure response",
-                    persistenceId(), message, getCurrentBehavior().state());
+                    getId(), message, getCurrentBehavior().state());
             message.getReplyTo().tell(new LeadershipTransferFailedException("Cannot transfer leader to "
-                    + message.getRequestedFollowerId()
-                    + ". RequestLeadership message was sent to non-leader " + persistenceId()), self());
+                    + requestedFollowerId
+                    + ". RequestLeadership message was sent to non-leader " + getId()), self());
             return;
         }
 
-        final String requestedFollowerId = message.getRequestedFollowerId();
         final ActorRef replyTo = message.getReplyTo();
         initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {
             @Override
@@ -308,20 +309,20 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
                     onFailure(raftActorRef);
                 }
 
-                LOG.debug("{}: Leadership transferred successfully to {}", persistenceId(), requestedFollowerId);
+                LOG.debug("{}: Leadership transferred successfully to {}", getId(), requestedFollowerId);
                 replyTo.tell(new Status.Success(null), self());
             }
 
             @Override
             public void onFailure(final ActorRef raftActorRef) {
-                LOG.debug("{}: LeadershipTransfer request from {} failed", persistenceId(), requestedFollowerId);
+                LOG.debug("{}: LeadershipTransfer request from {} failed", getId(), requestedFollowerId);
                 replyTo.tell(new Status.Failure(
                         new LeadershipTransferFailedException(
                                 "Failed to transfer leadership to " + requestedFollowerId
                                         + ". Follower is not ready to become leader")),
                         self());
             }
-        }, message.getRequestedFollowerId(), RaftActorLeadershipTransferCohort.USE_DEFAULT_LEADER_TIMEOUT);
+        }, requestedFollowerId, RaftActorLeadershipTransferCohort.USE_DEFAULT_LEADER_TIMEOUT);
     }
 
     private boolean possiblyHandleBehaviorMessage(final Object message) {
@@ -342,7 +343,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
 
     private void initiateLeadershipTransfer(final RaftActorLeadershipTransferCohort.OnComplete onComplete,
             final @Nullable String followerId, final long newLeaderTimeoutInMillis) {
-        LOG.debug("{}: Initiating leader transfer", persistenceId());
+        LOG.debug("{}: Initiating leader transfer", getId());
 
         RaftActorLeadershipTransferCohort leadershipTransferInProgress = context.getRaftActorLeadershipTransferCohort();
         if (leadershipTransferInProgress == null) {
@@ -366,13 +367,13 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             leadershipTransferInProgress.init();
 
         } else {
-            LOG.debug("{}: prior leader transfer in progress - adding callback", persistenceId());
+            LOG.debug("{}: prior leader transfer in progress - adding callback", getId());
             leadershipTransferInProgress.addOnComplete(onComplete);
         }
     }
 
     private void onShutDown() {
-        LOG.debug("{}: onShutDown", persistenceId());
+        LOG.debug("{}: onShutDown", getId());
 
         if (shuttingDown) {
             return;
@@ -396,13 +397,13 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {
                 @Override
                 public void onSuccess(final ActorRef raftActorRef) {
-                    LOG.debug("{}: leader transfer succeeded - sending PoisonPill", persistenceId());
+                    LOG.debug("{}: leader transfer succeeded - sending PoisonPill", getId());
                     raftActorRef.tell(PoisonPill.getInstance(), raftActorRef);
                 }
 
                 @Override
                 public void onFailure(final ActorRef raftActorRef) {
-                    LOG.debug("{}: leader transfer failed - sending PoisonPill", persistenceId());
+                    LOG.debug("{}: leader transfer failed - sending PoisonPill", getId());
                     raftActorRef.tell(PoisonPill.getInstance(), raftActorRef);
                 }
             }, null, TimeUnit.MILLISECONDS.convert(2, TimeUnit.SECONDS));
@@ -422,7 +423,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     private void onLeaderTransitioning(final LeaderTransitioning leaderTransitioning) {
-        LOG.debug("{}: onLeaderTransitioning: {}", persistenceId(), leaderTransitioning);
+        LOG.debug("{}: onLeaderTransitioning: {}", getId(), leaderTransitioning);
         final var roleChangeNotifier = roleChangeNotifier();
         if (roleChangeNotifier != null && getRaftState() == RaftState.Follower
                 && leaderTransitioning.getLeaderId().equals(getCurrentBehavior().getLeaderId())) {
@@ -440,7 +441,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
                     switchBehavior(behaviorStateTracker.capture(getCurrentBehavior()),
                         RaftActorBehavior.createBehavior(context, newState));
                 }
-                default -> LOG.warn("Switching to behavior : {} - not supported", newState);
+                default -> LOG.warn("{}: Switching to behavior : {} - not supported", getId(), newState);
             }
         }
     }
@@ -547,23 +548,22 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     private void handleApplyState(final ApplyState applyState) {
-        long startTime = System.nanoTime();
+        final long startTime = System.nanoTime();
 
         final var entry = applyState.getReplicatedLogEntry();
         final var payload = entry.getData();
         if (LOG.isDebugEnabled()) {
-            LOG.debug("{}: Applying state for log index {} data {}",
-                persistenceId(), entry.index(), payload);
+            LOG.debug("{}: Applying state for log index {} data {}", getId(), entry.index(), payload);
         }
 
         if (!(payload instanceof NoopPayload) && !(payload instanceof ServerConfigurationPayload)) {
             applyState(applyState.getClientActor(), applyState.getIdentifier(), payload);
         }
 
-        long elapsedTime = System.nanoTime() - startTime;
+        final long elapsedTime = System.nanoTime() - startTime;
         if (elapsedTime >= APPLY_STATE_DELAY_THRESHOLD_IN_NANOS) {
-            LOG.debug("ApplyState took more time than expected. Elapsed Time = {} ms ApplyState = {}",
-                    TimeUnit.NANOSECONDS.toMillis(elapsedTime), applyState);
+            LOG.debug("{}: ApplyState took more time than expected. Elapsed Time = {} ms ApplyState = {}", getId(),
+                TimeUnit.NANOSECONDS.toMillis(elapsedTime), applyState);
         }
 
         // Send the ApplyState message back to self to handle further processing asynchronously.
@@ -578,9 +578,9 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     @Override
     public long snapshotSequenceNr() {
         // When we do a snapshot capture, we also capture and save the sequence-number of the persistent journal,
-        // so that we can delete the persistent journal based on the saved sequence-number
-        // However , when akka replays the journal during recovery, it replays it from the sequence number when the
-        // snapshot was saved and not the number we saved. We would want to override it , by asking akka to use the
+        // so that we can delete the persistent journal based on the saved sequence-number.
+        // However, when Akka replays the journal during recovery, it replays it from the sequence number when the
+        // snapshot was saved and not the number we saved. We would want to override it, by asking Akka to use the
         // last-sequence number known to us.
         return context.getSnapshotManager().getLastSequenceNumber();
     }
@@ -601,7 +601,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             context.getReplicatedLog().lastIndex() + 1, context.currentTerm(), data);
         replicatedLogEntry.setPersistencePending(true);
 
-        LOG.debug("{}: Persist data {}", persistenceId(), replicatedLogEntry);
+        LOG.debug("{}: Persist data {}", getId(), replicatedLogEntry);
 
         final RaftActorContext raftContext = getRaftActorContext();
 
@@ -718,7 +718,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
         String oldRaftPolicy = context.getConfigParams().getCustomRaftPolicyImplementationClass();
         String newRaftPolicy = configParams.getCustomRaftPolicyImplementationClass();
 
-        LOG.debug("{}: RaftPolicy used with prev.config {}, RaftPolicy used with newConfig {}", persistenceId(),
+        LOG.debug("{}: RaftPolicy used with prev.config {}, RaftPolicy used with newConfig {}", getId(),
             oldRaftPolicy, newRaftPolicy);
         context.setConfigParams(configParams);
         if (!Objects.equals(oldRaftPolicy, newRaftPolicy)) {
@@ -730,8 +730,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
                 String previousLeaderId = behavior.getLeaderId();
                 short previousLeaderPayloadVersion = behavior.getLeaderPayloadVersion();
 
-                LOG.debug("{}: Re-initializing to Follower with previous leaderId {}", persistenceId(),
-                        previousLeaderId);
+                LOG.debug("{}: Re-initializing to Follower with previous leaderId {}", getId(), previousLeaderId);
 
                 changeCurrentBehavior(new Follower(context, previousLeaderId, previousLeaderPayloadVersion));
             } else {
@@ -754,7 +753,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             setPersistence(new PersistentDataProvider(this));
 
             if (getCurrentBehavior() != null) {
-                LOG.info("{}: Persistence has been enabled - capturing snapshot", persistenceId());
+                LOG.info("{}: Persistence has been enabled - capturing snapshot", getId());
                 captureSnapshot();
             }
         } else if (!persistent && (currentPersistence == null || currentPersistence.isRecoveryApplicable())) {
@@ -888,7 +887,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             return null;
         }
         String peerAddress = context.getPeerAddress(leaderId);
-        LOG.debug("{}: getLeaderAddress leaderId = {} peerAddress = {}", persistenceId(), leaderId, peerAddress);
+        LOG.debug("{}: getLeaderAddress leaderId = {} peerAddress = {}", getId(), leaderId, peerAddress);
 
         return peerAddress;
     }
@@ -919,13 +918,13 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {
                 @Override
                 public void onSuccess(final ActorRef raftActorRef) {
-                    LOG.debug("{}: leader transfer succeeded after change to non-voting", persistenceId());
+                    LOG.debug("{}: leader transfer succeeded after change to non-voting", getId());
                     ensureFollowerState();
                 }
 
                 @Override
                 public void onFailure(final ActorRef raftActorRef) {
-                    LOG.debug("{}: leader transfer failed after change to non-voting", persistenceId());
+                    LOG.debug("{}: leader transfer failed after change to non-voting", getId());
                     ensureFollowerState();
                 }
 
index 8657f297815479f4a728db98925d2de3b261f3cb..8fd9e12cd1d87375c2a62e9a4c347db84caf8d40 100644 (file)
@@ -100,13 +100,13 @@ public class RaftActorLeadershipTransferCohort {
         raftActor.pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), raftActor) {
             @Override
             protected void doRun() {
-                LOG.debug("{}: pauseLeader successfully completed - doing transfer", raftActor.persistenceId());
+                LOG.debug("{}: pauseLeader successfully completed - doing transfer", raftActor.getId());
                 doTransfer();
             }
 
             @Override
             protected void doCancel() {
-                LOG.debug("{}: pauseLeader timed out - continuing with transfer", raftActor.persistenceId());
+                LOG.debug("{}: pauseLeader timed out - continuing with transfer", raftActor.getId());
                 doTransfer();
             }
         });
@@ -123,7 +123,7 @@ public class RaftActorLeadershipTransferCohort {
             isTransferring = true;
             leader.transferLeadership(this);
         } else {
-            LOG.debug("{}: No longer the leader - skipping transfer", raftActor.persistenceId());
+            LOG.debug("{}: No longer the leader - skipping transfer", raftActor.getId());
             finish(true);
         }
     }
@@ -132,7 +132,7 @@ public class RaftActorLeadershipTransferCohort {
      * This method is invoked to abort leadership transfer on failure.
      */
     public void abortTransfer() {
-        LOG.debug("{}: leader transfer aborted", raftActor.persistenceId());
+        LOG.debug("{}: leader transfer aborted", raftActor.getId());
         finish(false);
     }
 
@@ -140,7 +140,7 @@ public class RaftActorLeadershipTransferCohort {
      * This method is invoked when leadership transfer was carried out and complete.
      */
     public void transferComplete() {
-        LOG.debug("{}: leader transfer complete - waiting for new leader", raftActor.persistenceId());
+        LOG.debug("{}: leader transfer complete - waiting for new leader", raftActor.getId());
 
         // We'll give it a little time for the new leader to be elected to give the derived class a
         // chance to possibly complete work that was suspended while we were transferring. The
@@ -153,14 +153,14 @@ public class RaftActorLeadershipTransferCohort {
         FiniteDuration timeout = FiniteDuration.create(newLeaderTimeoutInMillis, TimeUnit.MILLISECONDS);
         newLeaderTimer = raftActor.getContext().system().scheduler().scheduleOnce(timeout, raftActor.self(),
             (Runnable) () -> {
-                LOG.debug("{}: leader not elected in time", raftActor.persistenceId());
+                LOG.debug("{}: leader not elected in time", raftActor.getId());
                 finish(true);
             }, raftActor.getContext().system().dispatcher(), raftActor.self());
     }
 
     void onNewLeader(final String newLeader) {
         if (newLeader != null && newLeaderTimer != null) {
-            LOG.debug("{}: leader changed to {}", raftActor.persistenceId(), newLeader);
+            LOG.debug("{}: leader changed to {}", raftActor.getId(), newLeader);
             newLeaderTimer.cancel();
             finish(true);
         }
@@ -171,10 +171,10 @@ public class RaftActorLeadershipTransferCohort {
         if (transferTimer.isRunning()) {
             transferTimer.stop();
             if (success) {
-                LOG.info("{}: Successfully transferred leadership to {} in {}", raftActor.persistenceId(),
+                LOG.info("{}: Successfully transferred leadership to {} in {}", raftActor.getId(),
                         raftActor.getLeaderId(), transferTimer);
             } else {
-                LOG.warn("{}: Failed to transfer leadership in {}", raftActor.persistenceId(), transferTimer);
+                LOG.warn("{}: Failed to transfer leadership in {}", raftActor.getId(), transferTimer);
                 raftActor.unpauseLeader();
             }
         }
index 709d8645aa75069204c8062d5e75a63e6c329c22..0405fecdc4d774754c367de38de7f0d2c90b6add 100644 (file)
@@ -123,7 +123,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
     @Override
     protected void applyState(final ActorRef clientActor, final Identifier identifier, final Object data) {
         actorDelegate.applyState(clientActor, identifier, data);
-        LOG.info("{}: applyState called: {}", persistenceId(), data);
+        LOG.info("{}: applyState called: {}", getId(), data);
 
         state.add(data);
     }
@@ -178,13 +178,13 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
 
     @Override
     public void createSnapshot(final ActorRef actorRef, final Optional<OutputStream> installSnapshotStream) {
-        LOG.info("{}: createSnapshot called", persistenceId());
+        LOG.info("{}: createSnapshot called", getId());
         snapshotCohortDelegate.createSnapshot(actorRef, installSnapshotStream);
     }
 
     @Override
     public void applySnapshot(final Snapshot.State newState) {
-        LOG.info("{}: applySnapshot called", persistenceId());
+        LOG.info("{}: applySnapshot called", getId());
         applySnapshotState(newState);
         snapshotCohortDelegate.applySnapshot(newState);
     }
index 78f998466f3e7764bd528c22d282c78c06081992..df46c732bd73cf65be28eefeede8c845673f774f 100644 (file)
@@ -39,7 +39,7 @@ final class DataTreeChangeListenerSupport extends LeaderLocalDelegateFactory<Reg
 
         final DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor, self());
 
-        LOG.debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath());
+        LOG.debug("{}: Registering listenerActor {} for path {}", shardName(), listenerActor, message.getPath());
 
         final ShardDataTree shardDataTree = getShard().getDataStore();
         shardDataTree.registerTreeChangeListener(message.getPath(),
@@ -54,9 +54,9 @@ final class DataTreeChangeListenerSupport extends LeaderLocalDelegateFactory<Reg
 
     @Override
     void onLeadershipChange(final boolean isLeader, final boolean hasLeader) {
-        LOG.debug("{}: onLeadershipChange, isLeader: {}, hasLeader : {}", persistenceId(), isLeader, hasLeader);
+        LOG.debug("{}: onLeadershipChange, isLeader: {}, hasLeader : {}", shardName(), isLeader, hasLeader);
 
-        final EnableNotification msg = new EnableNotification(isLeader, persistenceId());
+        final EnableNotification msg = new EnableNotification(isLeader, shardName());
         for (ActorSelection dataChangeListener : leaderOnlyListenerActors) {
             dataChangeListener.tell(msg, self());
         }
@@ -80,14 +80,14 @@ final class DataTreeChangeListenerSupport extends LeaderLocalDelegateFactory<Reg
 
     @Override
     void onMessage(final RegisterDataTreeChangeListener message, final boolean isLeader, final boolean hasLeader) {
-        LOG.debug("{}: onMessage {}, isLeader: {}, hasLeader: {}", persistenceId(), message, isLeader, hasLeader);
+        LOG.debug("{}: onMessage {}, isLeader: {}, hasLeader: {}", shardName(), message, isLeader, hasLeader);
 
         final ActorRef registrationActor = createActor(DataTreeNotificationListenerRegistrationActor.props());
 
         if (hasLeader && message.isRegisterOnAllInstances() || isLeader) {
             doRegistration(message, registrationActor);
         } else {
-            LOG.debug("{}: Shard does not have a leader - delaying registration", persistenceId());
+            LOG.debug("{}: Shard does not have a leader - delaying registration", shardName());
 
             final var delayedReg = new DelayedDataTreeChangeListenerRegistration(message, registrationActor);
             final Collection<DelayedDataTreeChangeListenerRegistration> delayedRegList;
@@ -103,7 +103,7 @@ final class DataTreeChangeListenerSupport extends LeaderLocalDelegateFactory<Reg
         }
 
         LOG.debug("{}: sending RegisterDataTreeNotificationListenerReply, listenerRegistrationPath = {} ",
-                persistenceId(), registrationActor.path());
+                shardName(), registrationActor.path());
 
         tellSender(new RegisterDataTreeNotificationListenerReply(registrationActor));
     }
@@ -112,7 +112,7 @@ final class DataTreeChangeListenerSupport extends LeaderLocalDelegateFactory<Reg
         final ActorSelection listenerActor = selectActor(message.getListenerActorPath());
 
         // We have a leader so enable the listener.
-        listenerActor.tell(new EnableNotification(true, persistenceId()), self());
+        listenerActor.tell(new EnableNotification(true, shardName()), self());
 
         if (!message.isRegisterOnAllInstances()) {
             // This is a leader-only registration so store a reference to the listener actor so it can be notified
index e2b5130c905f5d310c28105971cd0d588502b309..ba123db37a4f719ca83d24d20df36ab8202f6c79 100644 (file)
@@ -102,12 +102,12 @@ final class FrontendClientMetadataBuilder {
         final var singleHistoryMeta = currentHistories.get(new LocalHistoryIdentifier(clientId, 0));
         if (singleHistoryMeta == null) {
             final var tree = shard.getDataStore();
-            singleHistory = StandaloneFrontendHistory.create(shard.persistenceId(), clientId, tree);
+            singleHistory = StandaloneFrontendHistory.create(shard.getId(), clientId, tree);
         } else {
             singleHistory = singleHistoryMeta.toLeaderState(shard);
         }
 
-        return new LeaderFrontendState.Enabled(shard.persistenceId(), clientId, shard.getDataStore(),
+        return new LeaderFrontendState.Enabled(shard.getId(), clientId, shard.getDataStore(),
             purgedHistories.mutableCopy(), singleHistory, histories);
     }
 
index f869e7ac5ac679658ca146ab38685ebf91d65947..d8d4ddec210b7844f64f8981f0c0b7ca594e5f70 100644 (file)
@@ -84,11 +84,11 @@ final class FrontendHistoryMetadataBuilder implements Identifiable<LocalHistoryI
      */
     @NonNull AbstractFrontendHistory toLeaderState(final @NonNull Shard shard) {
         if (identifier.getHistoryId() == 0) {
-            return StandaloneFrontendHistory.recreate(shard.persistenceId(), identifier.getClientId(),
+            return StandaloneFrontendHistory.recreate(shard.getId(), identifier.getClientId(),
                 shard.getDataStore(), closedTransactions, purgedTransactions);
         }
 
-        return LocalFrontendHistory.recreate(shard.persistenceId(), shard.getDataStore(),
+        return LocalFrontendHistory.recreate(shard.getId(), shard.getDataStore(),
             shard.getDataStore().recreateTransactionChain(identifier, closed), closedTransactions, purgedTransactions);
     }
 }
index 6f78fe7528bd7b551cc8231b70969d350d556a30..61ad66f1f03f28cda0a1a74b2faee5f9da3f8a90 100644 (file)
@@ -36,8 +36,8 @@ abstract class LeaderLocalDelegateFactory<M> {
         return shard;
     }
 
-    protected final String persistenceId() {
-        return shard.persistenceId();
+    protected final String shardName() {
+        return shard.getId();
     }
 
     protected final void tellSender(final Object message) {
index 9e1ece06f51dd5405e62f3ee99247ba7e35af3d0..4b59e721c081ca2642687f1e34bb8a64a5928f21 100644 (file)
@@ -266,7 +266,7 @@ public class Shard extends RaftActor {
 
     @Override
     public final void postStop() throws Exception {
-        LOG.info("Stopping Shard {}", persistenceId());
+        LOG.info("Stopping Shard {}", getId());
 
         super.postStop();
 
@@ -280,8 +280,7 @@ public class Shard extends RaftActor {
 
     @Override
     protected final void handleRecover(final Object message) {
-        LOG.debug("{}: onReceiveRecover: Received message {} from {}", persistenceId(), message.getClass(),
-            getSender());
+        LOG.debug("{}: onReceiveRecover: Received message {} from {}", getId(), message.getClass(), getSender());
 
         super.handleRecover(message);
 
@@ -313,7 +312,7 @@ public class Shard extends RaftActor {
         try (var context = appendEntriesReplyTracker.received(message)) {
             final var maybeError = context.error();
             if (maybeError.isPresent()) {
-                LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(),
+                LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", getId(),
                     maybeError.orElseThrow());
             }
 
@@ -387,12 +386,11 @@ public class Shard extends RaftActor {
                 }
             }
         } catch (RequestException e) {
-            LOG.debug("{}: request {} failed", persistenceId(), envelope, e);
+            LOG.debug("{}: request {} failed", getId(), envelope, e);
             envelope.sendFailure(e, ticker().read() - now);
         } catch (Exception e) {
-            LOG.debug("{}: request {} caused failure", persistenceId(), envelope, e);
-            envelope.sendFailure(new RuntimeRequestException("Request failed to process", e),
-                ticker().read() - now);
+            LOG.debug("{}: request {} caused failure", getId(), envelope, e);
+            envelope.sendFailure(new RuntimeRequestException("Request failed to process", e), ticker().read() - now);
         }
     }
 
@@ -420,7 +418,7 @@ public class Shard extends RaftActor {
     }
 
     private void onMakeLeaderLocal() {
-        LOG.debug("{}: onMakeLeaderLocal received", persistenceId());
+        LOG.debug("{}: onMakeLeaderLocal received", getId());
         if (isLeader()) {
             getSender().tell(new Status.Success(null), self());
             return;
@@ -436,9 +434,10 @@ public class Shard extends RaftActor {
             // request. We can also let the caller retry by sending a flag
             // in the response indicating the request is "reTryable".
             getSender().tell(new Failure(
-                    new LeadershipTransferFailedException("We cannot initiate leadership transfer to local node. "
-                            + "Currently there is no leader for " + persistenceId())),
-                    self());
+                new LeadershipTransferFailedException(
+                    "We cannot initiate leadership transfer to local node. "
+                        + "Currently there is no leader for " + getId())),
+                self());
             return;
         }
 
@@ -455,16 +454,16 @@ public class Shard extends RaftActor {
                 return existing;
             }
             if (cmp > 0) {
-                LOG.debug("{}: rejecting request from outdated client {}", persistenceId(), clientId);
+                LOG.debug("{}: rejecting request from outdated client {}", getId(), clientId);
                 throw new RetiredGenerationException(clientId.getGeneration(),
                     existing.getIdentifier().getGeneration());
             }
 
-            LOG.info("{}: retiring state {}, outdated by request from client {}", persistenceId(), existing, clientId);
+            LOG.info("{}: retiring state {}, outdated by request from client {}", getId(), existing, clientId);
             existing.retire();
             knownFrontends.remove(clientId.getFrontendId());
         } else {
-            LOG.debug("{}: client {} is not yet known", persistenceId(), clientId);
+            LOG.debug("{}: client {} is not yet known", getId(), clientId);
         }
 
         return null;
@@ -504,17 +503,17 @@ public class Shard extends RaftActor {
 
             if (!isLeader() || !isLeaderActive()) {
                 LOG.info("{}: not currently leader, rejecting request {}. isLeader: {}, isLeaderActive: {},"
-                                + "isLeadershipTransferInProgress: {}.",
-                        persistenceId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
+                    + "isLeadershipTransferInProgress: {}.",
+                    getId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
                 throw new NotLeaderException(self());
             }
 
             final ABIVersion selectedVersion = selectVersion(message);
             final LeaderFrontendState frontend;
             if (existing == null) {
-                frontend = new LeaderFrontendState.Enabled(persistenceId(), clientId, store);
+                frontend = new LeaderFrontendState.Enabled(getId(), clientId, store);
                 knownFrontends.put(clientId.getFrontendId(), frontend);
-                LOG.debug("{}: created state {} for client {}", persistenceId(), frontend, clientId);
+                LOG.debug("{}: created state {} for client {}", getId(), frontend, clientId);
             } else {
                 frontend = existing;
             }
@@ -533,8 +532,8 @@ public class Shard extends RaftActor {
         // We are not the leader, hence we want to fail-fast.
         if (!isLeader() || paused || !isLeaderActive()) {
             LOG.debug("{}: not currently active leader, rejecting request {}. isLeader: {}, isLeaderActive: {},"
-                            + "isLeadershipTransferInProgress: {}, paused: {}",
-                    persistenceId(), envelope, isLeader(), isLeaderActive(), isLeadershipTransferInProgress(), paused);
+                + "isLeadershipTransferInProgress: {}, paused: {}",
+                getId(), envelope, isLeader(), isLeaderActive(), isLeadershipTransferInProgress(), paused);
             throw new NotLeaderException(self());
         }
 
@@ -545,7 +544,7 @@ public class Shard extends RaftActor {
             case LocalHistoryRequest<?> req -> getFrontend(req.getTarget().getClientId())
                 .handleLocalHistoryRequest(req, envelope, now);
             default -> {
-                LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request);
+                LOG.warn("{}: rejecting unsupported request {}", getId(), request);
                 throw new UnsupportedRequestException(request);
             }
         };
@@ -635,10 +634,10 @@ public class Shard extends RaftActor {
     @Override
     protected final RaftActorRecoveryCohort getRaftActorRecoveryCohort() {
         if (restoreFromSnapshot == null) {
-            return ShardRecoveryCoordinator.create(store, persistenceId(), LOG);
+            return ShardRecoveryCoordinator.create(store, getId(), LOG);
         }
 
-        return ShardRecoveryCoordinator.forSnapshot(store, persistenceId(), LOG, restoreFromSnapshot.getSnapshot());
+        return ShardRecoveryCoordinator.forSnapshot(store, getId(), LOG, restoreFromSnapshot.getSnapshot());
     }
 
     @Override
@@ -666,17 +665,17 @@ public class Shard extends RaftActor {
     protected final void applyState(final ActorRef clientActor, final Identifier identifier, final Object data) {
         if (data instanceof Payload payload) {
             if (payload instanceof DisableTrackingPayload disableTracking) {
-                LOG.debug("{}: ignoring legacy {}", persistenceId(), disableTracking);
+                LOG.debug("{}: ignoring legacy {}", getId(), disableTracking);
                 return;
             }
 
             try {
                 store.applyReplicatedPayload(identifier, payload);
             } catch (DataValidationFailedException | IOException e) {
-                LOG.error("{}: Error applying replica {}", persistenceId(), identifier, e);
+                LOG.error("{}: Error applying replica {}", getId(), identifier, e);
             }
         } else {
-            LOG.error("{}: Unknown state for {} received {}", persistenceId(), identifier, data);
+            LOG.error("{}: Unknown state for {} received {}", getId(), identifier, data);
         }
     }
 
@@ -690,8 +689,8 @@ public class Shard extends RaftActor {
         if (!isLeader) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug(
-                    "{}: onStateChanged: Closing all transaction chains because shard {} is no longer the leader",
-                    persistenceId(), getId());
+                    "{}: onStateChanged: Closing all transaction chains because shard is no longer the leader",
+                    getId());
             }
 
             paused = false;
@@ -706,7 +705,7 @@ public class Shard extends RaftActor {
 
         if (!isLeader()) {
             if (!knownFrontends.isEmpty()) {
-                LOG.debug("{}: removing frontend state for {}", persistenceId(), knownFrontends.keySet());
+                LOG.debug("{}: removing frontend state for {}", getId(), knownFrontends.keySet());
                 knownFrontends = ImmutableMap.of();
             }
 
@@ -714,13 +713,13 @@ public class Shard extends RaftActor {
         } else {
             // We have become the leader, we need to reconstruct frontend state
             knownFrontends = verifyNotNull(frontendMetadata.toLeaderState(this));
-            LOG.debug("{}: became leader with frontend state for {}", persistenceId(), knownFrontends.keySet());
+            LOG.debug("{}: became leader with frontend state for {}", getId(), knownFrontends.keySet());
         }
     }
 
     @Override
     protected final void pauseLeader(final Runnable operation) {
-        LOG.debug("{}: In pauseLeader, operation: {}", persistenceId(), operation);
+        LOG.debug("{}: In pauseLeader, operation: {}", getId(), operation);
         paused = true;
 
         // Tell-based protocol can replay transaction state, so it is safe to blow it up when we are paused.
@@ -732,7 +731,7 @@ public class Shard extends RaftActor {
 
     @Override
     protected final void unpauseLeader() {
-        LOG.debug("{}: In unpauseLeader", persistenceId());
+        LOG.debug("{}: In unpauseLeader", getId());
         paused = false;
 
         store.setRunOnPendingTransactionsComplete(null);