/// <inheritdoc /> public async Task <Host> RefreshNodeListAsync( IConnectionEndPoint currentEndPoint, IConnection connection, ISerializer serializer) { ControlConnection.Logger.Info("Refreshing node list"); // safe guard against concurrent changes of this field var localIsPeersV2 = _isPeersV2; var localTask = SendSystemLocalRequestAsync(connection, serializer); var peersTask = SendSystemPeersRequestAsync(localIsPeersV2, connection, serializer); await Task.WhenAll(localTask, peersTask).ConfigureAwait(false); var peersResponse = peersTask.Result; localIsPeersV2 = peersResponse.IsPeersV2; var rsPeers = _config.MetadataRequestHandler.GetRowSet(peersResponse.Response); var localRow = _config.MetadataRequestHandler.GetRowSet(localTask.Result).FirstOrDefault(); if (localRow == null) { ControlConnection.Logger.Error("Local host metadata could not be retrieved"); throw new DriverInternalError("Local host metadata could not be retrieved"); } _metadata.Partitioner = localRow.GetValue <string>("partitioner"); var host = GetAndUpdateLocalHost(currentEndPoint, localRow); UpdatePeersInfo(localIsPeersV2, rsPeers, host); ControlConnection.Logger.Info("Node list retrieved successfully"); return(host); }
/// <inheritdoc /> public async Task <Host> RefreshNodeListAsync(IConnectionEndPoint currentEndPoint, IConnection connection, ProtocolVersion version) { ControlConnection.Logger.Info("Refreshing node list"); var queriesRs = await Task.WhenAll( _config.MetadataRequestHandler.SendMetadataRequestAsync( connection, version, TopologyRefresher.SelectLocal, QueryProtocolOptions.Default), _config.MetadataRequestHandler.SendMetadataRequestAsync( connection, version, TopologyRefresher.SelectPeers, QueryProtocolOptions.Default)) .ConfigureAwait(false); var localRow = _config.MetadataRequestHandler.GetRowSet(queriesRs[0]).FirstOrDefault(); var rsPeers = _config.MetadataRequestHandler.GetRowSet(queriesRs[1]); if (localRow == null) { ControlConnection.Logger.Error("Local host metadata could not be retrieved"); throw new DriverInternalError("Local host metadata could not be retrieved"); } _metadata.Partitioner = localRow.GetValue <string>("partitioner"); var host = GetAndUpdateLocalHost(currentEndPoint, localRow); UpdatePeersInfo(rsPeers, host); ControlConnection.Logger.Info("Node list retrieved successfully"); return(host); }
internal Connection(Serializer serializer, IConnectionEndPoint endPoint, Configuration configuration, IStartupRequestFactory startupRequestFactory) { _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _startupRequestFactory = startupRequestFactory ?? throw new ArgumentNullException(nameof(startupRequestFactory)); _tcpSocket = new TcpSocket(endPoint, configuration.SocketOptions, configuration.ProtocolOptions.SslOptions); _idleTimer = new Timer(IdleTimeoutHandler, null, Timeout.Infinite, Timeout.Infinite); }
public IConnection CreateUnobserved(ISerializer serializer, IConnectionEndPoint endPoint, Configuration configuration) { return(new Connection( serializer, endPoint, configuration, new StartupRequestFactory(configuration.StartupOptionsFactory), NullConnectionObserver.Instance)); }
public IConnection Create(ISerializer serializer, IConnectionEndPoint endpoint, Configuration configuration, IConnectionObserver connectionObserver) { var connection = _func(endpoint); var queue = CreatedConnections.GetOrAdd(endpoint.GetHostIpEndPointWithFallback(), _ => new ConcurrentQueue <IConnection>()); queue.Enqueue(connection); OnCreate?.Invoke(connection); return(connection); }
public Task <Host> RefreshNodeListAsync(IConnectionEndPoint currentEndPoint, IConnection connection, ISerializer serializer) { foreach (var h in _hosts) { if (_metadata.GetHost(h.Key) == null) { var host = _metadata.AddHost(h.Key); host.SetInfo(h.Value); } } _metadata.Partitioner = "Murmur3Partitioner"; return(Task.FromResult(_metadata.Hosts.First())); }
/// <summary> /// Parses system.local response, creates the local Host and adds it to the Hosts collection. /// </summary> private Host GetAndUpdateLocalHost(IConnectionEndPoint endPoint, IRow row) { var hostIpEndPoint = endPoint.GetOrParseHostIpEndPoint(row, _config.AddressTranslator, _config.ProtocolOptions.Port); var host = _metadata.GetHost(hostIpEndPoint) ?? _metadata.AddHost(hostIpEndPoint, endPoint.ContactPoint); // Update cluster name, DC and rack for the one node we are connected to var clusterName = row.GetValue <string>("cluster_name"); if (clusterName != null) { _metadata.ClusterName = clusterName; } host.SetInfo(row); return(host); }
internal Connection( Serializer serializer, IConnectionEndPoint endPoint, Configuration configuration, IStartupRequestFactory startupRequestFactory, IConnectionObserver connectionObserver) { _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _startupRequestFactory = startupRequestFactory ?? throw new ArgumentNullException(nameof(startupRequestFactory)); _tcpSocket = new TcpSocket(endPoint, configuration.SocketOptions, configuration.ProtocolOptions.SslOptions); _idleTimer = new Timer(IdleTimeoutHandler, null, Timeout.Infinite, Timeout.Infinite); _connectionObserver = connectionObserver; _timerEnabled = configuration.MetricsEnabled && configuration.MetricsOptions.EnabledNodeMetrics.Contains(NodeMetric.Timers.CqlMessages); }
/// <summary> /// Parses system.local response, creates the local Host and adds it to the Hosts collection. /// </summary> private Host GetAndUpdateLocalHost(IConnectionEndPoint endPoint, IRow row) { var hostIpEndPoint = endPoint.GetHostIpEndPoint() ?? GetRpcEndPoint(false, row, _config.AddressTranslator, _config.ProtocolOptions.Port); if (hostIpEndPoint == null) { throw new DriverInternalError("Could not parse the node's ip address from system tables."); } var host = _metadata.GetHost(hostIpEndPoint) ?? _metadata.AddHost(hostIpEndPoint, endPoint.ContactPoint); // Update cluster name, DC and rack for the one node we are connected to var clusterName = row.GetValue <string>("cluster_name"); if (clusterName != null) { _metadata.ClusterName = clusterName; } host.SetInfo(row); return(host); }
public bool Equals(IConnectionEndPoint other) { return(Equals((object)other)); }
public IConnection Create( ISerializer serializer, IConnectionEndPoint endPoint, Configuration configuration, IConnectionObserver connectionObserver) { return(new Connection( serializer, endPoint, configuration, new StartupRequestFactory(configuration.StartupOptionsFactory), connectionObserver)); }
public bool Equals(IConnectionEndPoint other) { return(SocketIpEndPoint.Equals(other.SocketIpEndPoint)); }
public IConnection Create(Serializer serializer, IConnectionEndPoint endPoint, Configuration configuration) { return(new Connection(serializer, endPoint, configuration)); }
private static string GetMessage(IConnectionEndPoint endPoint, int maxRequestsPerConnection, int connectionLength) { return $"All connections to host {endPoint.EndpointFriendlyName} are busy, {maxRequestsPerConnection} requests " + $"are in-flight on {(connectionLength > 0 ? "each " : "")}{connectionLength} connection(s)"; }
public Connection(Serializer serializer, IConnectionEndPoint endPoint, Configuration configuration) : this(serializer, endPoint, configuration, new StartupRequestFactory(configuration.StartupOptionsFactory)) { }
internal OperationTimedOutException(IConnectionEndPoint endPoint, int timeout) : base($"The host {endPoint} did not reply before timeout {timeout}ms") { }
public IConnection CreateUnobserved(ISerializer serializer, IConnectionEndPoint endPoint, Configuration configuration) { return(Create(serializer, endPoint, configuration, NullConnectionObserver.Instance)); }
/// <summary> /// Creates a new instance of TcpSocket using the endpoint and options provided. /// </summary> public TcpSocket(IConnectionEndPoint endPoint, SocketOptions options, SSLOptions sslOptions) { EndPoint = endPoint; Options = options; SSLOptions = sslOptions; }