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);
        }
示例#2
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);
        }