예제 #1
0
        private static void ContinueRebalance <TCoordinator>(this TCoordinator coordinator, IImmutableSet <ShardId> shards) where TCoordinator : IShardCoordinator
        {
            if (coordinator.Log.IsInfoEnabled && (shards.Count > 0 || !coordinator.RebalanceInProgress.IsEmpty))
            {
                coordinator.Log.Info("Starting rebalance for shards [{0}]. Current shards rebalancing: [{1}]",
                                     string.Join(",", shards),
                                     string.Join(",", coordinator.RebalanceInProgress.Keys));
            }

            foreach (var shard in shards)
            {
                if (!coordinator.RebalanceInProgress.ContainsKey(shard))
                {
                    if (coordinator.CurrentState.Shards.TryGetValue(shard, out var rebalanceFromRegion))
                    {
                        coordinator.RebalanceInProgress = coordinator.RebalanceInProgress.SetItem(shard, ImmutableHashSet <IActorRef> .Empty);
                        coordinator.Log.Debug("Rebalance shard [{0}] from [{1}]", shard, rebalanceFromRegion);

                        var regions = coordinator.CurrentState.Regions.Keys.Union(coordinator.CurrentState.RegionProxies);
                        coordinator.Context.ActorOf(RebalanceWorker.Props(shard, rebalanceFromRegion, coordinator.Settings.TunningParameters.HandOffTimeout, regions, coordinator.GracefullShutdownInProgress)
                                                    .WithDispatcher(coordinator.Context.Props.Dispatcher));
                    }
                    else
                    {
                        coordinator.Log.Debug("Rebalance of non-existing shard [{0}] is ignored", shard);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Start a RebalanceWorker to manage the shard rebalance.
        /// Does nothing if the shard is already in the process of being rebalanced.
        /// </summary>
        /// <typeparam name="TCoordinator">TBD</typeparam>
        /// <param name="coordinator">TBD</param>
        /// <param name="shard">TBD</param>
        /// <param name="from">TBD</param>
        /// <param name="isRebalance">TBD</param>
        private static void StartShardRebalanceIfNeeded <TCoordinator>(
            this TCoordinator coordinator,
            ShardId shard,
            IActorRef from,
            bool isRebalance)
            where TCoordinator : IShardCoordinator
        {
            if (!coordinator.RebalanceInProgress.ContainsKey(shard))
            {
                coordinator.RebalanceInProgress = coordinator.RebalanceInProgress.SetItem(shard, ImmutableHashSet <IActorRef> .Empty);

                var regions = coordinator.CurrentState.Regions.Keys.Union(coordinator.CurrentState.RegionProxies);
                coordinator.RebalanceWorkers = coordinator.RebalanceWorkers.Add(coordinator.Context.ActorOf(
                                                                                    RebalanceWorker.Props(shard, from, coordinator.Settings.TuningParameters.HandOffTimeout, regions, isRebalance)
                                                                                    .WithDispatcher(coordinator.Context.Props.Dispatcher)));
            }
        }
        private void ContinueRebalance(IImmutableSet <ShardId> shards)
        {
            foreach (var shard in shards)
            {
                if (!_rebalanceInProgress.Contains(shard))
                {
                    if (_currentState.Shards.TryGetValue(shard, out var rebalanceFromRegion))
                    {
                        _rebalanceInProgress = _rebalanceInProgress.Add(shard);
                        Log.Debug("Rebalance shard [{0}] from [{1}]", shard, rebalanceFromRegion);

                        var regions = _currentState.Regions.Keys.Union(_currentState.RegionProxies);
                        Context.ActorOf(RebalanceWorker.Props(shard, rebalanceFromRegion, Settings.TunningParameters.HandOffTimeout, regions)
                                        .WithDispatcher(Context.Props.Dispatcher));
                    }
                    else
                    {
                        Log.Debug("Rebalance of non-existing shard [{0}] is ignored", shard);
                    }
                }
            }
        }