public ReplicatorResiliencySpec(ITestOutputHelper helper) : base(SpecConfig, helper) { _sys1 = Sys; _sys3 = ActorSystem.Create(Sys.Name, Sys.Settings.Config); _sys2 = ActorSystem.Create(Sys.Name, Sys.Settings.Config); var settings = ReplicatorSettings.Create(Sys) .WithGossipInterval(TimeSpan.FromSeconds(1.0)) .WithMaxDeltaElements(10) .WithRestartReplicatorOnFailure(true); var props = BackoffSupervisor.Props( Backoff.OnStop( childProps: Replicator.Props(settings), childName: "replicator", minBackoff: TimeSpan.FromSeconds(3), maxBackoff: TimeSpan.FromSeconds(300), randomFactor: 0.2, maxNrOfRetries: -1) .WithFinalStopMessage(m => m is Terminate)) .WithDeploy(Deploy.Local).WithDispatcher(settings.Dispatcher); _replicator1 = _sys1.ActorOf(props, "replicatorSuper"); _replicator2 = _sys2.ActorOf(props, "replicatorSuper"); _replicator3 = _sys3.ActorOf(props, "replicatorSuper"); }
private static Props GetSupervisedReplicator(ReplicatorSettings settings, string name) => BackoffSupervisor.Props( Backoff.OnStop( childProps: Akka.DistributedData.Replicator.Props(settings), childName: name, minBackoff: TimeSpan.FromSeconds(3), maxBackoff: TimeSpan.FromSeconds(300), randomFactor: 0.2, maxNrOfRetries: -1) .WithFinalStopMessage(m => m is Terminate)) .WithDeploy(Deploy.Local).WithDispatcher(settings.Dispatcher);
public void BackoffSupervisorOnStop(ApplicationEnvironment applicationEnvironment) { ActorSystem actorSystem = ActorSystem.Create("app"); // This class represents a configuration object used in creating an // ActorBase actor Props childProps = Props.Create <EchoActor>(); // TimeSpan minBackoff = TimeSpan.FromSeconds(3); TimeSpan maxBackoff = TimeSpan.FromSeconds(30); double randomFactor = 0.2; int maxNrOfRetries = 2; // Builds back-off options for creating a back-off supervisor. BackoffOptions backoffOptions = Backoff.OnStop(childProps, "myEcho", minBackoff, maxBackoff, randomFactor, maxNrOfRetries); Props supervisor = BackoffSupervisor.Props(backoffOptions); IActorRef supervisorActor = actorSystem.ActorOf(supervisor, "echoSupervisor"); supervisorActor.Tell("EchoMessage1"); supervisorActor.Tell(new Exception("File not found exception")); supervisorActor.Tell("EchoMessage2"); }
public void BackoffSupervisorWithAutoResetWithSupervisorStrategy(ApplicationEnvironment applicationEnvironment) { ActorSystem actorSystem = ActorSystem.Create("app"); // This class represents a configuration object used in creating an // ActorBase actor Props childProps = Props.Create <EchoActor>(); // TimeSpan minBackoff = TimeSpan.FromSeconds(3); string childName = "myEcho"; TimeSpan maxBackoff = TimeSpan.FromSeconds(30); double randomFactor = 0.2; int maxNrOfRetries = 2; // Builds back-off options for creating a back-off supervisor. OneForOneStrategy supervisorStrategy = new OneForOneStrategy(exception => { TestUtilities.ConsoleWriteJson(new { Message = $"{GetType().Name} OneForOneStrategy", ExceptionMessage = exception.Message }); TestUtilities.ThreadSleepSeconds(10); if (exception is FileNotFoundException) { return(Directive.Restart); } return(Directive.Escalate); }); BackoffOptions backoffOptions = Backoff.OnStop(childProps, childName, minBackoff, maxBackoff, randomFactor, maxNrOfRetries).WithAutoReset(TimeSpan.FromSeconds(10)).WithSupervisorStrategy(supervisorStrategy); Props supervisor = BackoffSupervisor.Props(backoffOptions); IActorRef supervisorActor = actorSystem.ActorOf(supervisor, "echoSupervisor"); supervisorActor.Tell("EchoMessage1"); supervisorActor.Tell(new FileNotFoundException("File not found exception")); supervisorActor.Tell("EchoMessage2"); supervisorActor.Tell("EchoMessage3"); TestUtilities.MethodEnds(); }
private BackoffOptions OnStopOptions(Props props, int maxNrOfRetries = -1) => Backoff.OnStop(props, "c1", 100.Milliseconds(), 3.Seconds(), 0.2, maxNrOfRetries);
public Props Get(Props childProps) { return(BackoffSupervisor.Props(Backoff.OnStop(childProps, this.ChildName, this.MinBackoff, this.MaxBackoff, this.RandomFactor))); }
/// <summary> /// TBD /// </summary> public ClusterShardingGuardian() { Receive <Start>(start => { try { var settings = start.Settings; var encName = Uri.EscapeDataString(start.TypeName); var coordinatorSingletonManagerName = CoordinatorSingletonManagerName(encName); var coordinatorPath = CoordinatorPath(encName); var replicator = Replicator(settings); var shardRegion = Context.Child(encName).GetOrElse(() => { if (Equals(Context.Child(coordinatorSingletonManagerName), ActorRefs.Nobody)) { var minBackoff = settings.TunningParameters.CoordinatorFailureBackoff; var maxBackoff = new TimeSpan(minBackoff.Ticks * 5); var coordinatorProps = settings.StateStoreMode == StateStoreMode.Persistence ? PersistentShardCoordinator.Props(start.TypeName, settings, start.AllocationStrategy) : DDataShardCoordinator.Props(start.TypeName, settings, start.AllocationStrategy, replicator, _majorityMinCap, settings.RememberEntities); var singletonProps = BackoffSupervisor.Props( Backoff.OnStop( childProps: coordinatorProps, childName: "coordinator", minBackoff: minBackoff, maxBackoff: maxBackoff, randomFactor: 0.2, maxNrOfRetries: -1) .WithFinalStopMessage(m => m is Terminate)) .WithDeploy(Deploy.Local); var singletonSettings = settings.CoordinatorSingletonSettings.WithSingletonName("singleton").WithRole(settings.Role); Context.ActorOf(ClusterSingletonManager.Props(singletonProps, Terminate.Instance, singletonSettings).WithDispatcher(Context.Props.Dispatcher), coordinatorSingletonManagerName); } return(Context.ActorOf(ShardRegion.Props( typeName: start.TypeName, entityProps: start.EntityProps, settings: settings, coordinatorPath: coordinatorPath, extractEntityId: start.ExtractEntityId, extractShardId: start.ExtractShardId, handOffStopMessage: start.HandOffStopMessage, replicator: replicator, majorityMinCap: _majorityMinCap).WithDispatcher(Context.Props.Dispatcher), encName)); }); Sender.Tell(new Started(shardRegion)); } catch (Exception ex) { //TODO: JVM version matches NonFatal. Can / should we do something similar? // don't restart // could be invalid ReplicatorSettings, or InvalidActorNameException // if it has already been started Sender.Tell(new Status.Failure(ex)); } }); Receive <StartProxy>(startProxy => { try { var settings = startProxy.Settings; var encName = Uri.EscapeDataString(startProxy.TypeName + "Proxy"); var coordinatorPath = CoordinatorPath(Uri.EscapeDataString(startProxy.TypeName)); var shardRegion = Context.Child(encName).GetOrElse(() => Context.ActorOf(ShardRegion.ProxyProps( typeName: startProxy.TypeName, settings: settings, coordinatorPath: coordinatorPath, extractEntityId: startProxy.ExtractEntityId, extractShardId: startProxy.ExtractShardId, replicator: Context.System.DeadLetters, majorityMinCap: _majorityMinCap).WithDispatcher(Context.Props.Dispatcher), encName)); Sender.Tell(new Started(shardRegion)); } catch (Exception ex) { //TODO: JVM version matches NonFatal. Can / should we do something similar? // don't restart // could be InvalidActorNameException if it has already been started Sender.Tell(new Status.Failure(ex)); } }); }
private BackoffOptions OnStopOptions(Props props) => Backoff.OnStop(props, "c1", 100.Milliseconds(), 3.Seconds(), 0.2);