MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / _add_conn_if_under_max

Method _add_conn_if_under_max

cassandra/pool.py:701–735  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

699 self._scheduled_for_creation -= 1
700
701 def _add_conn_if_under_max(self):
702 max_conns = self._session.cluster.get_max_connections_per_host(self.host_distance)
703 with self._lock:
704 if self.is_shutdown:
705 return True
706
707 if self.open_count >= max_conns:
708 return True
709
710 self.open_count += 1
711
712 log.debug("Going to open new connection to host %s", self.host)
713 try:
714 conn = self._session.cluster.connection_factory(self.host.endpoint, on_orphaned_stream_released=self.on_orphaned_stream_released)
715 if self._keyspace:
716 conn.set_keyspace_blocking(self._session.keyspace)
717 self._next_trash_allowed_at = time.time() + _MIN_TRASH_INTERVAL
718 with self._lock:
719 new_connections = self._connections[:] + [conn]
720 self._connections = new_connections
721 log.debug("Added new connection (%s) to pool for host %s, signaling availability",
722 id(conn), self.host)
723 self._signal_available_conn()
724 return True
725 except (ConnectionException, socket.error) as exc:
726 log.warning("Failed to add new connection to pool for host %s: %s", self.host, exc)
727 with self._lock:
728 self.open_count -= 1
729 if self._session.cluster.signal_connection_failure(self.host, exc, is_host_addition=False):
730 self.shutdown()
731 return False
732 except AuthenticationFailed:
733 with self._lock:
734 self.open_count -= 1
735 return False
736
737 def _await_available_conn(self, timeout):
738 with self._conn_available_condition:

Callers 2

_retrying_replaceMethod · 0.95

Calls 7

shutdownMethod · 0.95
set_keyspace_blockingMethod · 0.80
connection_factoryMethod · 0.45
timeMethod · 0.45

Tested by

no test coverage detected