void FreeConnection(CassandraConnection connection) { connection.Dispose(); AtomicValue <int> val; _allocatedConnections.TryGetValue(connection.GetHostAdress(), out val); var no = Interlocked.Decrement(ref val.RawValue); }
CassandraConnection AllocateConnection(IPAddress endPoint, out Exception outExc) { CassandraConnection nconn = null; outExc = null; try { nconn = new CassandraConnection(this, endPoint, _protocolOptions, _socketOptions, _clientOptions, _authProvider); var streamId = nconn.AllocateStreamId(); var options = ProcessExecuteOptions(nconn.ExecuteOptions(streamId)); if (!string.IsNullOrEmpty(_keyspace)) { nconn.SetKeyspace(_keyspace); } } catch (Exception ex) { if (nconn != null) { nconn.Dispose(); } if (CassandraConnection.IsStreamRelatedException(ex)) { HostIsDown(endPoint); outExc = ex; return(null); } else { throw ex; } } _logger.Info("Allocated new connection"); return(nconn); }
void FreeConnection(CassandraConnection connection) { connection.Dispose(); AtomicValue<int> val; _allocatedConnections.TryGetValue(connection.GetHostAdress(), out val); var no = Interlocked.Decrement(ref val.RawValue); }
CassandraConnection AllocateConnection(IPAddress endPoint, HostDistance hostDistance, out Exception outExc) { CassandraConnection nconn = null; outExc = null; try { int no = 1; if (!_allocatedConnections.TryAdd(endPoint, new AtomicValue<int>(1))) { AtomicValue<int> val; _allocatedConnections.TryGetValue(endPoint, out val); no = Interlocked.Increment(ref val.RawValue); if (no > _poolingOptions.GetMaxConnectionPerHost(hostDistance)) { Interlocked.Decrement(ref val.RawValue); outExc = new ToManyConnectionsPerHost(); return null; } } nconn = new CassandraConnection(this, endPoint, _protocolOptions, _socketOptions, _clientOptions, _authProvider); var streamId = nconn.AllocateStreamId(); var options = ProcessExecuteOptions(nconn.ExecuteOptions(streamId)); if (!string.IsNullOrEmpty(_keyspace)) nconn.SetKeyspace(_keyspace); } catch (Exception ex) { if (nconn != null) { nconn.Dispose(); nconn = null; } AtomicValue<int> val; _allocatedConnections.TryGetValue(endPoint, out val); Interlocked.Decrement(ref val.RawValue); if (CassandraConnection.IsStreamRelatedException(ex)) { HostIsDown(endPoint); outExc = ex; return null; } else throw ex; } _logger.Info("Allocated new connection"); return nconn; }
CassandraConnection AllocateConnection(IPAddress endPoint, out Exception outExc) { CassandraConnection nconn = null; outExc = null; try { nconn = new CassandraConnection(this, endPoint, _protocolOptions, _socketOptions, _clientOptions, _authProvider); var options = nconn.ExecuteOptions(); if (!string.IsNullOrEmpty(_keyspace)) { nconn.SetKeyspace(_keyspace); } } catch (Exception ex) { if (nconn != null) nconn.Dispose(); if (CassandraConnection.IsStreamRelatedException(ex)) { HostIsDown(endPoint); outExc = ex; return null; } else throw ex; } _logger.Info("Allocated new connection"); return nconn; }
CassandraConnection AllocateConnection(IPAddress endPoint, out Exception outExc) { CassandraConnection nconn = null; outExc = null; try { nconn = new CassandraConnection(this, endPoint, _protocolOptions, _socketOptions, _clientOptions, _authProvider); var options = nconn.ExecuteOptions(); if (!string.IsNullOrEmpty(_keyspace)) { var keyspaceId = CqlQueryTools.CqlIdentifier(_keyspace); string retKeyspaceId; try { retKeyspaceId = ProcessSetKeyspace(nconn.Query(GetUseKeyspaceCQL(keyspaceId), ConsistencyLevel.Ignore,false)); } catch (InvalidException) { throw; } catch (QueryValidationException) { return null; } if (CqlQueryTools.CqlIdentifier(retKeyspaceId) != CqlQueryTools.CqlIdentifier(keyspaceId)) { var ex = new DriverInternalError("USE query returned " + retKeyspaceId + ". We expected " + keyspaceId + "."); _logger.Error(ex); throw ex; } lock(_preparedQueries) foreach (var prepQ in _preparedQueries) { try { byte[] queryid; RowSetMetadata metadata; ProcessPrepareQuery(nconn.PrepareQuery(prepQ.Key), out metadata, out queryid); } catch (QueryValidationException) { return null; } //TODO: makesure that ids are equal; } } } catch (Exception ex) { if (nconn != null) nconn.Dispose(); if (CassandraConnection.IsStreamRelatedException(ex)) { outExc = ex; return null; } else throw ex; } _logger.Info("Allocated new connection"); return nconn; }
CassandraConnection AllocateConnection(IPAddress endPoint, HostDistance hostDistance, out Exception outExc) { CassandraConnection nconn = null; outExc = null; try { int no = 1; if (!_allocatedConnections.TryAdd(endPoint, new AtomicValue <int>(1))) { AtomicValue <int> val; _allocatedConnections.TryGetValue(endPoint, out val); no = Interlocked.Increment(ref val.RawValue); if (no > _poolingOptions.GetMaxConnectionPerHost(hostDistance)) { Interlocked.Decrement(ref val.RawValue); outExc = new ToManyConnectionsPerHost(); return(null); } } RETRY: nconn = new CassandraConnection(this, endPoint, _protocolOptions, _socketOptions, _clientOptions, _authProvider, _authInfoProvider, _binaryProtocolVersion); var streamId = nconn.AllocateStreamId(); try { var options = ProcessExecuteOptions(nconn.ExecuteOptions(streamId)); } catch (CassandraConnectionBadProtocolVersionException) { if (_binaryProtocolVersion == 1) { throw; } else { _binaryProtocolVersion = 1; goto RETRY; } } if (!string.IsNullOrEmpty(_keyspace)) { nconn.SetKeyspace(_keyspace); } } catch (Exception ex) { if (nconn != null) { nconn.Dispose(); nconn = null; } AtomicValue <int> val; _allocatedConnections.TryGetValue(endPoint, out val); Interlocked.Decrement(ref val.RawValue); if (CassandraConnection.IsStreamRelatedException(ex)) { HostIsDown(endPoint); outExc = ex; return(null); } else { throw ex; } } _logger.Info("Allocated new connection"); return(nconn); }