Beispiel #1
0
        private void OnStateChange(object sender, NodeLifecycleState state)
        {
            if (!(sender is INodeLifecycleManager evictionCandidate))
            {
                return;
            }

            if (!_evictionPairs.TryGetValue(evictionCandidate.ManagedNode.IdHash, out EvictionPair evictionPair))
            {
                return;
            }

            if (state == NodeLifecycleState.Active)
            {
                //survived eviction
                if (_logger.IsTrace)
                {
                    _logger.Trace($"Survived eviction process, evictionCandidate: {evictionCandidate.ManagedNode}, replacementCandidate: {evictionPair.ReplacementCandidate.ManagedNode}");
                }
                evictionPair.ReplacementCandidate.LostEvictionProcess();
                CloseEvictionProcess(evictionCandidate);
            }
            else if (state == NodeLifecycleState.Unreachable)
            {
                //lost eviction, being replaced in nodeTable
                _nodeTable.ReplaceNode(evictionCandidate.ManagedNode, evictionPair.ReplacementCandidate.ManagedNode);
                if (_logger.IsTrace)
                {
                    _logger.Trace($"Lost eviction process, evictionCandidate: {evictionCandidate.ManagedNode}, replacementCandidate: {evictionPair.ReplacementCandidate.ManagedNode}");
                }
                CloseEvictionProcess(evictionCandidate);
            }
        }
        private void UpdateState(NodeLifecycleState newState)
        {
            if (newState == NodeLifecycleState.New)
            {
                //if node is just discovered we send ping to confirm it is active
                SendPing();
            }
            else if (newState == NodeLifecycleState.Active)
            {
                //TODO && !ManagedNode.IsDicoveryNode - should we exclude discovery nodes
                //received pong first time
                if (State == NodeLifecycleState.New)
                {
                    var result = _nodeTable.AddNode(ManagedNode);
                    if (result.ResultType == NodeAddResultType.Full)
                    {
                        var evictionCandidate = _discoveryManager.GetNodeLifecycleManager(result.EvictionCandidate.Node);
                        if (evictionCandidate != null)
                        {
                            _evictionManager.StartEvictionProcess(evictionCandidate, this);
                        }
                    }
                }
            }
            else if (newState == NodeLifecycleState.EvictCandidate)
            {
                SendPing();
            }

            State = newState;
            OnStateChanged?.Invoke(this, State);
        }
Beispiel #3
0
    private void UpdateState(NodeLifecycleState newState)
    {
        if (newState == NodeLifecycleState.New)
        {
            //if node is just discovered we send ping to confirm it is active
#pragma warning disable 4014
            SendPingAsync();
#pragma warning restore 4014
        }
        else if (newState == NodeLifecycleState.Active)
        {
            //TODO && !ManagedNode.IsDiscoveryNode - should we exclude discovery nodes
            //received pong first time
            if (State == NodeLifecycleState.New)
            {
                NodeAddResult result = _nodeTable.AddNode(ManagedNode);
                if (result.ResultType == NodeAddResultType.Full && result.EvictionCandidate?.Node is not null)
                {
                    INodeLifecycleManager?evictionCandidate = _discoveryManager.GetNodeLifecycleManager(result.EvictionCandidate.Node);
                    if (evictionCandidate != null)
                    {
                        _evictionManager.StartEvictionProcess(evictionCandidate, this);
                    }
                }
            }
        }
        else if (newState == NodeLifecycleState.EvictCandidate)
        {
            if (State == NodeLifecycleState.EvictCandidate)
            {
                throw new InvalidOperationException("Cannot start more than one eviction process on same node.");
            }

            if (DateTime.UtcNow - _lastPingSent > TimeSpan.FromSeconds(5))
            {
#pragma warning disable 4014
                SendPingAsync();
#pragma warning restore 4014
            }
            else
            {
                // TODO: this is very strange...?
                // seems like we quickly send two state updates here since we do not return after invocation?
                OnStateChanged?.Invoke(this, NodeLifecycleState.Active);
            }
        }

        State = newState;
        OnStateChanged?.Invoke(this, State);
    }
        private void UpdateState(NodeLifecycleState newState)
        {
            if (newState == NodeLifecycleState.New)
            {
                //if node is just discovered we send ping to confirm it is active
                SendPing();
            }
            else if (newState == NodeLifecycleState.Active)
            {
                //TODO && !ManagedNode.IsDiscoveryNode - should we exclude discovery nodes
                //received pong first time
                if (State == NodeLifecycleState.New)
                {
                    NodeAddResult result = _nodeTable.AddNode(ManagedNode);
                    if (result.ResultType == NodeAddResultType.Full)
                    {
                        INodeLifecycleManager evictionCandidate = _discoveryManager.GetNodeLifecycleManager(result.EvictionCandidate.Node);
                        if (evictionCandidate != null)
                        {
                            _evictionManager.StartEvictionProcess(evictionCandidate, this);
                        }
                    }
                }
            }
            else if (newState == NodeLifecycleState.EvictCandidate)
            {
                if (State == NodeLifecycleState.EvictCandidate)
                {
                    throw new InvalidOperationException("Cannot start more than one eviction process on same node.");
                }

                if (DateTime.UtcNow - _lastPingSent > TimeSpan.FromSeconds(5))
                {
                    SendPing();
                }
                else
                {
                    OnStateChanged?.Invoke(this, NodeLifecycleState.Active);
                }
            }

            State = newState;
            OnStateChanged?.Invoke(this, State);
        }