X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShard.java;h=db04956f0005ba1f7a8e2b73b5ece7615e37aba3;hb=0c74ca17e0d64c4c2a7555470a5737ebef148890;hp=c2cc1ac05b5dd0bb51a363b66d27d5398042f401;hpb=1b4baa35633543d70488d7b5cd7dd92147b643bc;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index c2cc1ac05b..db04956f00 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -140,7 +140,7 @@ public class Shard extends RaftActor { } commitCoordinator = new ShardCommitCoordinator(store, - TimeUnit.SECONDS.convert(5, TimeUnit.MINUTES), + datastoreContext.getShardCommitQueueExpiryTimeoutInMillis(), datastoreContext.getShardTransactionCommitQueueCapacity(), self(), LOG, this.name); setTransactionCommitTimeout(); @@ -160,7 +160,7 @@ public class Shard extends RaftActor { private void setTransactionCommitTimeout() { transactionCommitTimeout = TimeUnit.MILLISECONDS.convert( - datastoreContext.getShardTransactionCommitTimeoutInSeconds(), TimeUnit.SECONDS); + datastoreContext.getShardTransactionCommitTimeoutInSeconds(), TimeUnit.SECONDS) / 2; } public static Props props(final ShardIdentifier name, @@ -278,9 +278,10 @@ public class Shard extends RaftActor { } @Override - protected LeaderStateChanged newLeaderStateChanged(String memberId, String leaderId) { + protected LeaderStateChanged newLeaderStateChanged(String memberId, String leaderId, short leaderPayloadVersion) { return new ShardLeaderStateChanged(memberId, leaderId, - isLeader() ? Optional.of(store.getDataTree()) : Optional.absent()); + isLeader() ? Optional.of(store.getDataTree()) : Optional.absent(), + leaderPayloadVersion); } private void onDatastoreContext(DatastoreContext context) { @@ -302,14 +303,15 @@ public class Shard extends RaftActor { private void handleTransactionCommitTimeoutCheck() { CohortEntry cohortEntry = commitCoordinator.getCurrentCohortEntry(); if(cohortEntry != null) { - long elapsed = System.currentTimeMillis() - cohortEntry.getLastAccessTime(); - if(elapsed > transactionCommitTimeout) { + if(cohortEntry.isExpired(transactionCommitTimeout)) { LOG.warn("{}: Current transaction {} has timed out after {} ms - aborting", persistenceId(), cohortEntry.getTransactionID(), transactionCommitTimeout); doAbortTransaction(cohortEntry.getTransactionID(), null); } } + + commitCoordinator.cleanupExpiredCohortEntries(); } private static boolean isEmptyCommit(final DataTreeCandidate candidate) { @@ -323,9 +325,9 @@ public class Shard extends RaftActor { // or if cohortEntry has no modifications // we can apply modification to the state immediately if ((!hasFollowers() && !persistence().isRecoveryApplicable()) || isEmptyCommit(candidate)) { - applyModificationToState(getSender(), cohortEntry.getTransactionID(), candidate); + applyModificationToState(cohortEntry.getReplySender(), cohortEntry.getTransactionID(), candidate); } else { - Shard.this.persistData(getSender(), cohortEntry.getTransactionID(), + Shard.this.persistData(cohortEntry.getReplySender(), cohortEntry.getTransactionID(), DataTreeCandidatePayload.create(candidate)); } } @@ -412,7 +414,7 @@ public class Shard extends RaftActor { } private void handleBatchedModifications(BatchedModifications batched) { - // This message is sent to prepare the modificationsa transaction directly on the Shard as an + // This message is sent to prepare the modifications transaction directly on the Shard as an // optimization to avoid the extra overhead of a separate ShardTransaction actor. On the last // BatchedModifications message, the caller sets the ready flag in the message indicating // modifications are complete. The reply contains the cohort actor path (this actor) for the caller @@ -451,14 +453,15 @@ public class Shard extends RaftActor { try { commitCoordinator.handleReadyLocalTransaction(message, getSender(), this); } catch (Exception e) { - LOG.error("{}: Error handling LocalModifications for Tx {}", persistenceId(), + LOG.error("{}: Error handling ReadyLocalTransaction for Tx {}", persistenceId(), message.getTransactionID(), e); getSender().tell(new akka.actor.Status.Failure(e), getSelf()); } } else { ActorSelection leader = getLeader(); if (leader != null) { - LOG.debug("{}: Forwarding LocalModifications to leader {}", persistenceId(), leader); + LOG.debug("{}: Forwarding ReadyLocalTransaction to leader {}", persistenceId(), leader); + message.setRemoteVersion(getCurrentBehavior().getLeaderPayloadVersion()); leader.forward(message, getContext()); } else { noLeaderError(message); @@ -599,6 +602,7 @@ public class Shard extends RaftActor { @Override protected void onRecoveryComplete() { + store.recoveryDone(); //notify shard manager getContext().parent().tell(new ActorInitialized(), getSelf());