Exemplo n.º 1
0
            public StartProxy(string typeName, ClusterShardingSettings settings, IdExtractor extractEntityId, ShardResolver extractShardId)
            {
                if (string.IsNullOrEmpty(typeName)) throw new ArgumentNullException("typeName", "ClusterSharding start proxy requires type name to be provided");

                TypeName = typeName;
                Settings = settings;
                ExtractEntityId = extractEntityId;
                ExtractShardId = extractShardId;
            }
Exemplo n.º 2
0
            public Start(string typeName, Props entityProps, ClusterShardingSettings settings,
                IdExtractor idIdExtractor, ShardResolver shardResolver, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
            {
                if (string.IsNullOrEmpty(typeName)) throw new ArgumentNullException("typeName", "ClusterSharding start requires type name to be provided");
                if (entityProps == null) throw new ArgumentNullException("entityProps", string.Format("ClusterSharding start requires Props for [{0}] to be provided", typeName));

                TypeName = typeName;
                EntityProps = entityProps;
                Settings = settings;
                IdExtractor = idIdExtractor;
                ShardResolver = shardResolver;
                AllocationStrategy = allocationStrategy;
                HandOffStopMessage = handOffStopMessage;
            }
        public DDataShardCoordinator(string typeName, ClusterShardingSettings settings, IShardAllocationStrategy allocationStrategy, IActorRef replicator, int majorityMinCap, bool rememberEntities)
        {
            _replicator        = replicator;
            _rememberEntities  = rememberEntities;
            Settings           = settings;
            AllocationStrategy = allocationStrategy;
            Log           = Context.GetLogger();
            Cluster       = Cluster.Get(Context.System);
            CurrentState  = PersistentShardCoordinator.State.Empty.WithRememberEntities(settings.RememberEntities);
            RemovalMargin = Cluster.DowningProvider.DownRemovalMargin;
            MinMembers    = string.IsNullOrEmpty(settings.Role)
                ? Cluster.Settings.MinNrOfMembers
                : Cluster.Settings.MinNrOfMembersOfRole.GetValueOrDefault(settings.Role, 1);
            RebalanceTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(Settings.TunningParameters.RebalanceInterval, Settings.TunningParameters.RebalanceInterval, Self, RebalanceTick.Instance, Self);

            _readConsistency     = new ReadMajority(settings.TunningParameters.WaitingForStateTimeout, majorityMinCap);
            _writeConsistency    = new WriteMajority(settings.TunningParameters.UpdatingStateTimeout, majorityMinCap);
            _coordinatorStateKey = new LWWRegisterKey <PersistentShardCoordinator.State>(typeName + "CoordinatorState");
            _allShardsKey        = new GSetKey <string>($"shard-{typeName}-all");
            _allKeys             = rememberEntities
                ? ImmutableHashSet.CreateRange(new IKey <IReplicatedData>[] { _coordinatorStateKey, _allShardsKey })
                : ImmutableHashSet.Create <IKey <IReplicatedData> >(_coordinatorStateKey);

            if (rememberEntities)
            {
                replicator.Tell(Dsl.Subscribe(_allShardsKey, Self));
            }

            Cluster.Subscribe(Self, ClusterEvent.SubscriptionInitialStateMode.InitialStateAsEvents, typeof(ClusterEvent.ClusterShuttingDown));

            // get state from ddata replicator, repeat until GetSuccess
            GetCoordinatorState();
            GetAllShards();

            Context.Become(WaitingForState(_allKeys));
        }
Exemplo n.º 4
0
        private IActorRef Replicator(ClusterShardingSettings settings)
        {
            if (settings.StateStoreMode == StateStoreMode.DData)
            {
                // one replicator per role
                var role = settings.Role ?? string.Empty;
                if (_replicatorsByRole.TryGetValue(role, out var aref))
                {
                    return(aref);
                }
                else
                {
                    var name          = string.IsNullOrEmpty(settings.Role) ? "replicator" : Uri.EscapeDataString(settings.Role) + "Replicator";
                    var replicatorRef = Context.ActorOf(DistributedData.Replicator.Props(GetReplicatorSettings(settings)), name);

                    _replicatorsByRole = _replicatorsByRole.SetItem(role, replicatorRef);
                    return(replicatorRef);
                }
            }
            else
            {
                return(Context.System.DeadLetters);
            }
        }
Exemplo n.º 5
0
 public static Actor.Props Props(string typeName, ShardId shardId, Props entryProps, ClusterShardingSettings settings, IdExtractor idExtractor, ShardResolver shardResolver, object handOffStopMessage)
 {
     return(Actor.Props.Create(() => new PersistentShard(typeName, shardId, entryProps, settings, idExtractor, shardResolver, handOffStopMessage)).WithDeploy(Deploy.Local));
 }
Exemplo n.º 6
0
        public static Props Props(string typeName, ShardId shardId, Func <string, Props> entityProps, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId, object handOffStopMessage, IActorRef replicator, int majorityMinCap)
        {
            switch (settings.StateStoreMode)
            {
            case StateStoreMode.Persistence when settings.RememberEntities:
                return(Actor.Props.Create(() => new PersistentShard(typeName, shardId, entityProps, settings, extractEntityId, extractShardId, handOffStopMessage)).WithDeploy(Deploy.Local));

            case StateStoreMode.DData when settings.RememberEntities:
                return(Actor.Props.Create(() => new DDataShard(typeName, shardId, entityProps, settings, extractEntityId, extractShardId, handOffStopMessage, replicator, majorityMinCap)).WithDeploy(Deploy.Local));

            default:
                return(Actor.Props.Create(() => new Shard(typeName, shardId, entityProps, settings, extractEntityId, extractShardId, handOffStopMessage)).WithDeploy(Deploy.Local));
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Factory method for the <see cref="Actor.Props"/> of the <see cref="ShardRegion"/> actor when used in proxy only mode.
 /// </summary>
 internal static Props ProxyProps(string typeName, ClusterShardingSettings settings, string coordinatorPath, IdExtractor extractEntityId, ShardResolver extractShardId)
 {
     return(Actor.Props.Create(() => new ShardRegion(typeName, null, settings, coordinatorPath, extractEntityId, extractShardId, PoisonPill.Instance)).WithDeploy(Deploy.Local));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Factory method for the <see cref="Actor.Props"/> of the <see cref="ShardRegion"/> actor.
 /// </summary>
 internal static Props Props(string typeName, Props entityProps, ClusterShardingSettings settings, string coordinatorPath, IdExtractor extractEntityId, ShardResolver extractShardId, object handOffStopMessage)
 {
     return(Actor.Props.Create(() => new ShardRegion(typeName, entityProps, settings, coordinatorPath, extractEntityId, extractShardId, handOffStopMessage)).WithDeploy(Deploy.Local));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Factory method for the <see cref="Actor.Props"/> of the <see cref="ShardRegion"/> actor when used in proxy only mode.
 /// </summary>
 /// <param name="typeName">TBD</param>
 /// <param name="settings">TBD</param>
 /// <param name="coordinatorPath">TBD</param>
 /// <param name="extractEntityId">TBD</param>
 /// <param name="extractShardId">TBD</param>
 /// <param name="replicator"></param>
 /// <param name="majorityMinCap"></param>
 /// <returns>TBD</returns>
 internal static Props ProxyProps(string typeName, ClusterShardingSettings settings, string coordinatorPath, ExtractEntityId extractEntityId, ExtractShardId extractShardId, IActorRef replicator, int majorityMinCap)
 {
     return(Actor.Props.Create(() => new ShardRegion(typeName, null, settings, coordinatorPath, extractEntityId, extractShardId, PoisonPill.Instance, replicator, majorityMinCap)).WithDeploy(Deploy.Local));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Factory method for the <see cref="Actor.Props"/> of the <see cref="ShardRegion"/> actor.
 /// </summary>
 /// <param name="typeName">TBD</param>
 /// <param name="entityProps">TBD</param>
 /// <param name="settings">TBD</param>
 /// <param name="coordinatorPath">TBD</param>
 /// <param name="extractEntityId">TBD</param>
 /// <param name="extractShardId">TBD</param>
 /// <param name="handOffStopMessage">TBD</param>
 /// <param name="replicator"></param>
 /// <param name="majorityMinCap"></param>
 /// <returns>TBD</returns>
 internal static Props Props(string typeName, Func <string, Props> entityProps, ClusterShardingSettings settings, string coordinatorPath, ExtractEntityId extractEntityId, ExtractShardId extractShardId, object handOffStopMessage, IActorRef replicator, int majorityMinCap)
 {
     return(Actor.Props.Create(() => new ShardRegion(typeName, entityProps, settings, coordinatorPath, extractEntityId, extractShardId, handOffStopMessage, replicator, majorityMinCap)).WithDeploy(Deploy.Local));
 }
Exemplo n.º 11
0
 internal static Props Props(string typeName, ClusterShardingSettings settings, IShardAllocationStrategy allocationStrategy, IActorRef replicator, int majorityMinCap, bool rememberEntities) =>
 Actor.Props.Create(() => new DDataShardCoordinator(typeName, settings, allocationStrategy, replicator, majorityMinCap, rememberEntities)).WithDeploy(Deploy.Local);
Exemplo n.º 12
0
 /// <summary>
 /// Factory method for the <see cref="Actor.Props"/> of the <see cref="PersistentShardCoordinator"/> actor.
 /// </summary>
 internal static Props Props(string typeName, ClusterShardingSettings settings, IShardAllocationStrategy allocationStrategy)
 {
     return(Actor.Props.Create(() => new PersistentShardCoordinator(typeName, settings, allocationStrategy)).WithDeploy(Deploy.Local));
 }
 /// <summary>
 /// Specify sharding settings that should be used for the sharded daemon process instead of loading from config.
 /// Some settings can not be changed (remember-entities and related settings, passivation, number-of-shards),
 /// changing those settings will be ignored.
 /// </summary>
 /// <param name="shardingSettings">TBD</param>
 public ShardedDaemonProcessSettings WithShardingSettings(ClusterShardingSettings shardingSettings)
 {
     return(new ShardedDaemonProcessSettings(KeepAliveInterval, shardingSettings));
 }
 /// <summary>
 /// Not for user constructions, use factory methods to instantiate.
 /// </summary>
 private ShardedDaemonProcessSettings(TimeSpan keepAliveInterval, ClusterShardingSettings shardingSettings = null)
 {
     KeepAliveInterval = keepAliveInterval;
     ShardingSettings  = shardingSettings;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Specify sharding settings that should be used for the sharded daemon process instead of loading from config.
 /// Some settings can not be changed (remember-entities and related settings, passivation, number-of-shards),
 /// changing those settings will be ignored.
 /// </summary>
 /// <param name="shardingSettings">TBD</param>
 public ShardedDaemonProcessSettings WithShardingSettings(ClusterShardingSettings shardingSettings) => Copy(shardingSettings: shardingSettings);
Exemplo n.º 16
0
 private ShardedDaemonProcessSettings Copy(TimeSpan?keepAliveInterval = null, ClusterShardingSettings shardingSettings = null, string role = null)
 {
     return(new ShardedDaemonProcessSettings(keepAliveInterval ?? KeepAliveInterval, shardingSettings ?? ShardingSettings, role ?? Role));
 }