From: Tom Pantelis Date: Sat, 21 Feb 2015 05:17:41 +0000 (+0000) Subject: Merge "BUG 2676 : Add a diagnostic log message to detect delay in ApplyState processing" X-Git-Tag: release/lithium~524 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=2a89ae48921724ef5a4ab42dcff6afc74c5b0a4a;hp=f36982b81dc87bd4ba0583f504baab2d718aca64 Merge "BUG 2676 : Add a diagnostic log message to detect delay in ApplyState processing" --- diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java index 65254f2d62..3ec8cc5c58 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java @@ -22,6 +22,7 @@ import com.google.common.base.Stopwatch; import com.google.protobuf.ByteString; import java.io.Serializable; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.opendaylight.controller.cluster.DataPersistenceProvider; import org.opendaylight.controller.cluster.common.actor.AbstractUntypedPersistentActor; import org.opendaylight.controller.cluster.notifications.RoleChanged; @@ -82,6 +83,9 @@ import org.slf4j.LoggerFactory; * */ public abstract class RaftActor extends AbstractUntypedPersistentActor { + + private static final long APPLY_STATE_DELAY_THRESHOLD_IN_NANOS = TimeUnit.MILLISECONDS.toNanos(50L); // 50 millis + protected final Logger LOG = LoggerFactory.getLogger(getClass()); /** @@ -278,6 +282,12 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor { if (message instanceof ApplyState){ ApplyState applyState = (ApplyState) message; + long elapsedTime = (System.nanoTime() - applyState.getStartTime()); + if(elapsedTime >= APPLY_STATE_DELAY_THRESHOLD_IN_NANOS){ + LOG.warn("ApplyState took more time than expected. Elapsed Time = {} ms ApplyState = {}", + TimeUnit.NANOSECONDS.toMillis(elapsedTime), applyState); + } + if(LOG.isDebugEnabled()) { LOG.debug("{}: Applying state for log index {} data {}", persistenceId(), applyState.getReplicatedLogEntry().getIndex(), diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/ApplyState.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/ApplyState.java index 0a7a632880..9299e752d1 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/ApplyState.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/ApplyState.java @@ -9,21 +9,22 @@ package org.opendaylight.controller.cluster.raft.base.messages; import akka.actor.ActorRef; -import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry; - import java.io.Serializable; +import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry; public class ApplyState implements Serializable { private static final long serialVersionUID = 1L; private final ActorRef clientActor; private final String identifier; private final ReplicatedLogEntry replicatedLogEntry; + private final long startTime; public ApplyState(ActorRef clientActor, String identifier, ReplicatedLogEntry replicatedLogEntry) { this.clientActor = clientActor; this.identifier = identifier; this.replicatedLogEntry = replicatedLogEntry; + this.startTime = System.nanoTime(); } public ActorRef getClientActor() { @@ -37,4 +38,17 @@ public class ApplyState implements Serializable { public ReplicatedLogEntry getReplicatedLogEntry() { return replicatedLogEntry; } + + public long getStartTime() { + return startTime; + } + + @Override + public String toString() { + return "ApplyState{" + + "identifier='" + identifier + '\'' + + ", replicatedLogEntry.index =" + replicatedLogEntry.getIndex() + + ", startTime=" + startTime + + '}'; + } }