protected override Task PerformHealthCheck(ServerNode serverNode, int nodeIndex, JsonOperationContext context)
 {
     return(ExecuteAsync(serverNode, nodeIndex, context, new GetTcpInfoCommand("health-check"), shouldRetry: false, sessionInfo: null, token: CancellationToken.None));
 }
        public override async Task <bool> UpdateTopologyAsync(ServerNode node, int timeout, bool forceUpdate = false, string debugTag = null)
        {
            if (Disposed)
            {
                return(false);
            }
            var lockTaken = await _clusterTopologySemaphore.WaitAsync(timeout).ConfigureAwait(false);

            if (lockTaken == false)
            {
                return(false);
            }
            try
            {
                if (Disposed)
                {
                    return(false);
                }

                using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
                {
                    var command = new GetClusterTopologyCommand(debugTag);
                    await ExecuteAsync(node, null, context, command, shouldRetry : false, sessionInfo : null, token : CancellationToken.None).ConfigureAwait(false);

                    ClusterTopologyLocalCache.TrySaving(TopologyHash, command.Result, Conventions, context);

                    var results     = command.Result;
                    var newTopology = new Topology
                    {
                        Nodes = new List <ServerNode>(
                            from member in results.Topology.Members
                            select new ServerNode
                        {
                            Url        = member.Value,
                            ClusterTag = member.Key
                        }
                            ),
                        Etag = results.Etag
                    };

                    if (_nodeSelector == null)
                    {
                        _nodeSelector = new NodeSelector(newTopology);
                        if (Conventions.ReadBalanceBehavior == ReadBalanceBehavior.FastestNode)
                        {
                            _nodeSelector.ScheduleSpeedTest();
                        }
                    }
                    else if (_nodeSelector.OnUpdateTopology(newTopology, forceUpdate: forceUpdate))
                    {
                        DisposeAllFailedNodesTimers();

                        if (Conventions.ReadBalanceBehavior == ReadBalanceBehavior.FastestNode)
                        {
                            _nodeSelector.ScheduleSpeedTest();
                        }
                    }

                    OnTopologyUpdated(newTopology);
                }
            }
            catch (Exception)
            {
                if (Disposed == false)
                {
                    throw;
                }
            }
            finally
            {
                _clusterTopologySemaphore.Release();
            }

            return(true);
        }
示例#3
0
 private bool Equals(ServerNode other)
 {
     return(string.Equals(Url, other.Url) &&
            string.Equals(Database, other.Database));
 }