X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fbehaviors%2FAbstractRaftActorBehavior.java;h=075b2873e45332364c09aee83c49e6b23e40780c;hp=04462be0420eaa3f0504be0523b7c9371128273d;hb=4b207b5356775c4b4d231ae979f9f2134f617dd1;hpb=d840c921a370f0704ba2d68faf4cfffda08c4440 diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehavior.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehavior.java index 04462be042..075b2873e4 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehavior.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehavior.java @@ -10,7 +10,6 @@ package org.opendaylight.controller.cluster.raft.behaviors; import akka.actor.ActorRef; import akka.actor.Cancellable; -import akka.event.LoggingAdapter; import java.util.Random; import java.util.concurrent.TimeUnit; import org.opendaylight.controller.cluster.raft.ClientRequestTracker; @@ -24,6 +23,7 @@ import org.opendaylight.controller.cluster.raft.messages.AppendEntries; import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply; import org.opendaylight.controller.cluster.raft.messages.RequestVote; import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply; +import org.slf4j.Logger; import scala.concurrent.duration.FiniteDuration; /** @@ -46,7 +46,7 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior { /** * */ - protected final LoggingAdapter LOG; + protected final Logger LOG; /** * @@ -94,8 +94,8 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior { // 1. Reply false if term < currentTerm (§5.1) if (appendEntries.getTerm() < currentTerm()) { if(LOG.isDebugEnabled()) { - LOG.debug("Cannot append entries because sender term {} is less than {}", - appendEntries.getTerm(), currentTerm()); + LOG.debug("{}: Cannot append entries because sender term {} is less than {}", + context.getId(), appendEntries.getTerm(), currentTerm()); } sender.tell( @@ -136,7 +136,7 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior { RequestVote requestVote) { if(LOG.isDebugEnabled()) { - LOG.debug(requestVote.toString()); + LOG.debug("{}: Received {}", context.getId(), requestVote); } boolean grantVote = false; @@ -349,13 +349,14 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior { } else { //if one index is not present in the log, no point in looping // around as the rest wont be present either - LOG.warning( - "Missing index {} from log. Cannot apply state. Ignoring {} to {}", i, i, index); + LOG.warn( + "{}: Missing index {} from log. Cannot apply state. Ignoring {} to {}", + context.getId(), i, i, index); break; } } if(LOG.isDebugEnabled()) { - LOG.debug("Setting last applied to {}", newLastApplied); + LOG.debug("{}: Setting last applied to {}", context.getId(), newLastApplied); } context.setLastApplied(newLastApplied); @@ -393,7 +394,7 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior { try { close(); } catch (Exception e) { - LOG.error(e, "Failed to close behavior : {}", this.state()); + LOG.error("{}: Failed to close behavior : {}", context.getId(), this.state(), e); } return behavior; @@ -421,4 +422,18 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior { return numMajority; } + + protected long fakeSnapshot(final long minReplicatedToAllIndex, final long currentReplicatedIndex) { + + // we would want to keep the lastApplied as its used while capturing snapshots + long tempMin = Math.min(minReplicatedToAllIndex, + (context.getLastApplied() > -1 ? context.getLastApplied() - 1 : -1)); + + if (tempMin > -1 && context.getReplicatedLog().isPresent(tempMin)) { + context.getReplicatedLog().snapshotPreCommit(tempMin, context.getTermInformation().getCurrentTerm()); + context.getReplicatedLog().snapshotCommit(); + return tempMin; + } + return currentReplicatedIndex; + } }