/// <summary> /// Initializes a new instance of the <see cref="Connection" /> class. /// </summary> /// <param name="node"> The node. </param> /// <param name="nr"> The connection nr. </param> public Connection(Node node, int nr) { _node = node; _nr = nr; _config = node.Cluster.Config; //setup support for multiple queries _availableQueryIds = new Queue<short>(); _usedQueryIds = 0; _openRequests = new Dictionary<short, TaskCompletionSource<Frame>>(); //setup locks _writeLock = new SemaphoreSlim(1); _readLock = new SemaphoreSlim(0, int.MaxValue); _readLoopCompleted = new ManualResetEventSlim(true); //_frameSubmitLock is initialized later when protocol version is known //setup state _activeRequests = 0; _load = 0; _connectionState = ConnectionState.Created; _lastActivity = DateTime.UtcNow.Ticks; _maxIdleTicks = TimeSpan.FromSeconds(_config.MaxConnectionIdleTime).Ticks; AllowCleanup = true; Logger.Current.LogVerbose("{0} created", this); }
/// <summary> /// Initializes a new instance of the <see cref="Cluster" /> class. /// </summary> /// <param name="config"> The config. </param> internal Cluster(CqlConnectionStringBuilder config) { //store config _config = config; _loggerManager = new LoggerManager(_config.LoggerFactory, _config.LogLevel); }
/// <summary> /// Initializes the strategy with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public ExclusiveConnectionStrategy(Ring nodes, CqlConnectionStringBuilder config) { _nodes = nodes; _config = config; _connections = new ConcurrentStack<Connection>(); _rndGen = new Random((int)DateTime.UtcNow.Ticks); _connectionCount = _nodes.Sum(n => n.ConnectionCount); if(_connectionCount > 0) _connections.PushRange(_nodes.SelectMany(n => n).ToArray()); }
public async Task BalancedStrategyLowTreshold() { using(ShimsContext.Create()) { //create cluster var config = new CqlConnectionStringBuilder {NewConnectionTreshold = 5}; var cluster = new Cluster(config); //create nodes var n = new Node(IPAddress.Parse("127.0.0.1"), cluster); var n2 = new Node(IPAddress.Parse("127.0.0.2"), cluster); var n3 = new Node(IPAddress.Parse("127.0.0.3"), cluster); var n4 = new Node(IPAddress.Parse("127.0.0.4"), cluster); var nodes = new Ring(); nodes.Update(new List<Node> {n, n2, n3, n4}, "RandomPartitioner", new Logger(new NullLogger(), LogLevel.None)); ShimAllConnections(); var logger = cluster.LoggerManager.GetLogger("BalancedStrategyLowTresholdTest"); IConnectionStrategy strategy = new BalancedConnectionStrategy(nodes, config); const int nr = 8; for(int i = 0; i < nr; i++) { Connection connection; using(logger.ThreadBinding()) { connection = strategy.GetOrCreateConnection(ConnectionScope.Command, PartitionKey.None); } await connection.SendRequestAsync(new QueryFrame("", CqlConsistency.Any, null), logger, 10, CancellationToken.None); } Assert.AreEqual(nodes.Sum(nd => nd.ConnectionCount), nr); Assert.IsTrue(nodes.All(nd => nd.ConnectionCount == nr/4)); } }
/// <summary> /// Initializes the strategies with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public RandomConnectionStrategy(Ring nodes, CqlConnectionStringBuilder config) { _nodes = nodes; _config = config; _rnd = new Random((int)DateTime.UtcNow.Ticks); }
/// <summary> /// Initializes the strategy with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public BalancedConnectionStrategy(Ring nodes, CqlConnectionStringBuilder config) { _nodes = nodes; _config = config; _connectionCount = _nodes.Sum(n => n.ConnectionCount); }
public void TrySetKeepAlive() { var builder = new CqlConnectionStringBuilder( "node=localhost;Logger=Debug;LogLevel=Verbose;Username=cassandra;password=cassandra"); builder.SocketKeepAlive = 10*60*1000; //10 mins using(var connection = new CqlConnection(builder)) { connection.Open(); } }
public void TestConnectionStringValueSerialization() { var builder = new CqlConnectionStringBuilder( "servers=ip1,ip2;SocketKeepAlive=off;SocketSoLinger=10;SocketConnectTimeout=-10"); Assert.AreEqual(-1, builder.SocketKeepAlive); Assert.AreEqual(10, builder.SocketSoLinger); Assert.AreEqual(-1, builder.SocketConnectTimeout); }
public IAuthenticator CreateAuthenticator(CqlConnectionStringBuilder config) { return new PasswordAuthenticator {Username = config.Username, Password = config.Password}; }
/// <summary> /// Initializes the strategy with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public PartitionAwareConnectionStrategy(Ring nodes, CqlConnectionStringBuilder config) { _nodes = nodes; _baseStrategy = new BalancedConnectionStrategy(nodes, config); }
/// <summary> /// Initializes a new instance of the <see cref="CqlConnection" /> class. /// </summary> /// <param name="config"> The config. </param> public CqlConnection(CqlConnectionStringBuilder config) : this(config.ToString()) { }