X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FReplicatedLogImpl.java;h=c32839c490eb0b53d69192b2c58f4a141fe422f0;hb=d1d24d3742ffcda5e16a1d35e15a5627d5eb05f9;hp=fdb630538130aa2ac1bfcdac43b6f5ad3808a1ba;hpb=1d643894797401ebec8e2242c234779675ca37c3;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ReplicatedLogImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ReplicatedLogImpl.java index fdb6305381..c32839c490 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ReplicatedLogImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ReplicatedLogImpl.java @@ -10,8 +10,7 @@ package org.opendaylight.controller.cluster.raft; import akka.japi.Procedure; import java.util.Collections; import java.util.List; -import org.opendaylight.controller.cluster.DataPersistenceProvider; -import org.opendaylight.controller.cluster.raft.RaftActor.DeleteEntries; +import org.opendaylight.controller.cluster.raft.base.messages.DeleteEntries; import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior; /** @@ -22,51 +21,39 @@ class ReplicatedLogImpl extends AbstractReplicatedLogImpl { private long dataSizeSinceLastSnapshot = 0L; private final RaftActorContext context; - private final DataPersistenceProvider persistence; private final RaftActorBehavior currentBehavior; private final Procedure deleteProcedure = new Procedure() { @Override - public void apply(DeleteEntries param) { - dataSize = 0; - for (ReplicatedLogEntry entry : journal) { - dataSize += entry.size(); - } + public void apply(DeleteEntries notUsed) { } }; static ReplicatedLog newInstance(Snapshot snapshot, RaftActorContext context, - DataPersistenceProvider persistence, RaftActorBehavior currentBehavior) { + RaftActorBehavior currentBehavior) { return new ReplicatedLogImpl(snapshot.getLastAppliedIndex(), snapshot.getLastAppliedTerm(), - snapshot.getUnAppliedEntries(), context, persistence, currentBehavior); + snapshot.getUnAppliedEntries(), context, currentBehavior); } - static ReplicatedLog newInstance(RaftActorContext context, - DataPersistenceProvider persistence, RaftActorBehavior currentBehavior) { + static ReplicatedLog newInstance(RaftActorContext context, RaftActorBehavior currentBehavior) { return new ReplicatedLogImpl(-1L, -1L, Collections.emptyList(), context, - persistence, currentBehavior); + currentBehavior); } private ReplicatedLogImpl(long snapshotIndex, long snapshotTerm, List unAppliedEntries, - RaftActorContext context, DataPersistenceProvider persistence, RaftActorBehavior currentBehavior) { + RaftActorContext context, RaftActorBehavior currentBehavior) { super(snapshotIndex, snapshotTerm, unAppliedEntries); this.context = context; - this.persistence = persistence; this.currentBehavior = currentBehavior; } @Override public void removeFromAndPersist(long logEntryIndex) { - int adjustedIndex = adjustedIndex(logEntryIndex); - - if (adjustedIndex < 0) { - return; - } - // FIXME: Maybe this should be done after the command is saved - journal.subList(adjustedIndex , journal.size()).clear(); - - persistence.persist(new DeleteEntries(adjustedIndex), deleteProcedure); + long adjustedIndex = removeFrom(logEntryIndex); + if(adjustedIndex >= 0) { + context.getPersistenceProvider().persist(new DeleteEntries(adjustedIndex), deleteProcedure); + } } @Override @@ -83,21 +70,20 @@ class ReplicatedLogImpl extends AbstractReplicatedLogImpl { } // FIXME : By adding the replicated log entry to the in-memory journal we are not truly ensuring durability of the logs - journal.add(replicatedLogEntry); + append(replicatedLogEntry); // When persisting events with persist it is guaranteed that the // persistent actor will not receive further commands between the // persist call and the execution(s) of the associated event // handler. This also holds for multiple persist calls in context // of a single command. - persistence.persist(replicatedLogEntry, + context.getPersistenceProvider().persist(replicatedLogEntry, new Procedure() { @Override public void apply(ReplicatedLogEntry evt) throws Exception { int logEntrySize = replicatedLogEntry.size(); - dataSize += logEntrySize; - long dataSizeForCheck = dataSize; + long dataSizeForCheck = dataSize(); dataSizeSinceLastSnapshot += logEntrySize;