コード例 #1
0
ファイル: Follower.cs プロジェクト: dradoaica/rebalancer-net
        private async Task RespondToRebalancing(CancellationToken rebalancingToken)
        {
            try
            {
                RebalancingResult result = await ProcessStatusChangeAsync(rebalancingToken);

                switch (result)
                {
                case RebalancingResult.Complete:
                    logger.Info(clientId, "Follower - Rebalancing complete");
                    break;

                case RebalancingResult.Cancelled:
                    logger.Info(clientId, "Follower - Rebalancing cancelled");
                    break;

                default:
                    logger.Error(clientId,
                                 $"Follower - A non-supported RebalancingResult has been returned: {result}");
                    events.Add(FollowerEvent.PotentialInconsistentState);
                    break;
                }
            }
            catch (ZkSessionExpiredException)
            {
                logger.Warn(clientId, "Follower - The session was lost during rebalancing");
                events.Add(FollowerEvent.SessionExpired);
            }
            catch (ZkOperationCancelledException)
            {
                logger.Warn(clientId, "Follower - The rebalancing has been cancelled");
            }
            catch (InconsistentStateException e)
            {
                logger.Error(clientId,
                             "Follower - An error occurred potentially leaving the client in an inconsistent state. Termination of the client or creationg of a new session will follow",
                             e);
                events.Add(FollowerEvent.PotentialInconsistentState);
            }
            catch (TerminateClientException e)
            {
                logger.Error(clientId, "Follower - A fatal error occurred, aborting", e);
                events.Add(FollowerEvent.FatalError);
            }
            catch (Exception e)
            {
                logger.Error(clientId, "Follower - Rebalancing failed.", e);
                events.Add(FollowerEvent.PotentialInconsistentState);
            }
        }
コード例 #2
0
        private async Task TriggerRebalancing(CancellationToken rebalancingToken)
        {
            try
            {
                await zooKeeperService.WatchResourcesChildrenAsync(this);

                await zooKeeperService.WatchNodesAsync(this);

                RebalancingResult result = await RebalanceAsync(rebalancingToken);

                switch (result)
                {
                case RebalancingResult.Complete:
                    logger.Info(clientId, "Coordinator - Rebalancing complete");
                    break;

                case RebalancingResult.Cancelled:
                    logger.Info(clientId, "Coordinator - Rebalancing cancelled");
                    break;
                }

                lastRebalancingResult = result;
            }
            catch (ZkSessionExpiredException e)
            {
                logger.Error(clientId, "Coordinator - The current session has expired", e);
                events.Add(CoordinatorEvent.SessionExpired);
                lastRebalancingResult = RebalancingResult.Failed;
            }
            catch (ZkStaleVersionException e)
            {
                logger.Error(clientId,
                             "Coordinator - A stale znode version was used, aborting rebalancing.", e);
                events.Add(CoordinatorEvent.NoLongerCoordinator);
                lastRebalancingResult = RebalancingResult.Failed;
            }
            catch (ZkInvalidOperationException e)
            {
                lastRebalancingResult = RebalancingResult.Failed;
                logger.Error(clientId,
                             "Coordinator - An invalid ZooKeeper operation occurred, aborting rebalancing.",
                             e);
                events.Add(CoordinatorEvent.PotentialInconsistentState);
            }
            catch (InconsistentStateException e)
            {
                lastRebalancingResult = RebalancingResult.Failed;
                logger.Error(clientId,
                             "Coordinator - An error occurred potentially leaving the client in an inconsistent state, aborting rebalancing.",
                             e);
                events.Add(CoordinatorEvent.PotentialInconsistentState);
            }
            catch (TerminateClientException e)
            {
                lastRebalancingResult = RebalancingResult.Failed;
                logger.Error(clientId,
                             "Coordinator - A fatal error has occurred, aborting rebalancing.",
                             e);
                events.Add(CoordinatorEvent.FatalError);
            }
            catch (ZkOperationCancelledException)
            {
                logger.Warn(clientId, "Coordinator - Rebalancing cancelled");
                lastRebalancingResult = RebalancingResult.Cancelled;
            }
            catch (Exception e)
            {
                lastRebalancingResult = RebalancingResult.Failed;
                logger.Error(clientId,
                             "Coordinator - An unexpected error has occurred, aborting rebalancing.", e);
                events.Add(CoordinatorEvent.PotentialInconsistentState);
            }
        }