Add optional timeout parameter for backup rpc
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorSnapshotMessageSupport.java
index 0fe9a1a..60fca8c 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.raft;
 import akka.actor.ActorRef;
 import akka.persistence.SaveSnapshotFailure;
 import akka.persistence.SaveSnapshotSuccess;
+import akka.util.Timeout;
 import com.google.common.annotations.VisibleForTesting;
 import java.util.Collections;
 import java.util.Optional;
@@ -69,7 +70,7 @@ class RaftActorSnapshotMessageSupport {
         } else if (COMMIT_SNAPSHOT.equals(message)) {
             context.getSnapshotManager().commit(-1, -1);
         } else if (message instanceof GetSnapshot) {
-            onGetSnapshot(sender);
+            onGetSnapshot(sender, (GetSnapshot) message);
         } else {
             return false;
         }
@@ -105,16 +106,20 @@ class RaftActorSnapshotMessageSupport {
         context.getSnapshotManager().apply(message);
     }
 
-    private void onGetSnapshot(ActorRef sender) {
+    private void onGetSnapshot(ActorRef sender, GetSnapshot getSnapshot) {
         log.debug("{}: onGetSnapshot", context.getId());
 
+
         if (context.getPersistenceProvider().isRecoveryApplicable()) {
             CaptureSnapshot captureSnapshot = context.getSnapshotManager().newCaptureSnapshot(
                     context.getReplicatedLog().last(), -1, true);
 
+            final FiniteDuration timeout =
+                    getSnapshot.getTimeout().map(Timeout::duration).orElse(snapshotReplyActorTimeout);
+
             ActorRef snapshotReplyActor = context.actorOf(GetSnapshotReplyActor.props(captureSnapshot,
-                    ImmutableElectionTerm.copyOf(context.getTermInformation()), sender,
-                    snapshotReplyActorTimeout, context.getId(), context.getPeerServerInfo(true)));
+                    ImmutableElectionTerm.copyOf(context.getTermInformation()), sender, timeout, context.getId(),
+                    context.getPeerServerInfo(true)));
 
             cohort.createSnapshot(snapshotReplyActor, Optional.empty());
         } else {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.