Skip to content

Commit b5c60a8

Browse files
committed
fix: bugs in host list provider
1 parent aa292db commit b5c60a8

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

aws_advanced_python_wrapper/aurora_connection_tracker_plugin.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,31 @@ def populate_opened_connection_set(self, host_info: HostInfo, conn: Connection):
4949
:param conn: currently opened connection.
5050
"""
5151

52+
# // Check if the connection was established using an instance endpoint
53+
# if (rdsUtils.isRdsInstance(hostSpec.getHost())) {
54+
# trackConnection(hostSpec.getHostAndPort(), conn);
55+
# return;
56+
# }
57+
#
58+
# final String instanceEndpoint = aliases.stream()
59+
# .filter(x -> rdsUtils.isRdsInstance(rdsUtils.removePort(x)))
60+
# .max(String::compareToIgnoreCase)
61+
# .orElse(null);
62+
#
63+
# if (instanceEndpoint == null) {
64+
# LOGGER.finest(
65+
# Messages.get("OpenedConnectionTracker.unableToPopulateOpenedConnectionQueue",
66+
# new Object[] {hostSpec.getHost()}));
67+
# return;
68+
# }
69+
5270
aliases: FrozenSet[str] = host_info.as_aliases()
53-
host: str = host_info.as_alias()
5471

55-
if self._rds_utils.is_rds_instance(host):
56-
self._track_connection(host, conn)
72+
if self._rds_utils.is_rds_instance(host_info.host):
73+
self._track_connection(host_info.as_alias(), conn)
5774
return
5875

59-
instance_endpoint: Optional[str] = next((alias for alias in aliases if self._rds_utils.is_rds_instance(alias)),
76+
instance_endpoint: Optional[str] = next((alias for alias in aliases if self._rds_utils.is_rds_instance(self._rds_utils.remove_port(alias))),
6077
None)
6178
if not instance_endpoint:
6279
logger.debug("OpenedConnectionTracker.UnableToPopulateOpenedConnectionSet")

aws_advanced_python_wrapper/sql_alchemy_connection_provider.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ def __init__(
5757
self,
5858
pool_configurator: Optional[Callable] = None,
5959
pool_mapping: Optional[Callable] = None,
60+
accept_url_func: Optional[Callable] = None,
6061
pool_expiration_check_ns: int = -1,
6162
pool_cleanup_interval_ns: int = -1):
6263
self._pool_configurator = pool_configurator
6364
self._pool_mapping = pool_mapping
65+
self._accept_url_func = accept_url_func
6466

6567
if pool_expiration_check_ns > -1:
6668
SqlAlchemyPooledConnectionProvider._POOL_EXPIRATION_CHECK_NS = pool_expiration_check_ns
@@ -80,6 +82,8 @@ def keys(self):
8082
return self._database_pools.keys()
8183

8284
def accepts_host_info(self, host_info: HostInfo, props: Properties) -> bool:
85+
if self._accept_url_func:
86+
return self._accept_url_func(host_info, props)
8387
url_type = SqlAlchemyPooledConnectionProvider._rds_utils.identify_rds_type(host_info.host)
8488
return RdsUrlType.RDS_INSTANCE == url_type
8589

aws_advanced_python_wrapper/utils/rdsutils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ def _get_group(self, host: str, group: str):
267267
def _get_dns_group(self, host: str):
268268
return self._get_group(host, RdsUtils.DNS_GROUP)
269269

270+
def remove_port(self, url: str):
271+
if not url or not url.strip():
272+
return None
273+
if ":" in url:
274+
return url.split(":")[0]
275+
return url
276+
270277
@staticmethod
271278
def clear_cache():
272279
RdsUtils.CACHE_PATTERNS.clear()

tests/integration/container/test_read_write_splitting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ def test_pooled_connection__cluster_url_failover(
515515
def test_pooled_connection__failover_failed(
516516
self, test_environment: TestEnvironment, test_driver: TestDriver,
517517
rds_utils, conn_utils, proxied_failover_props):
518-
provider = SqlAlchemyPooledConnectionProvider(lambda _, __: {"pool_size": 1})
518+
writer_host = test_environment.get_writer().get_host()
519+
provider = SqlAlchemyPooledConnectionProvider(lambda _, __: {"pool_size": 1}, lambda host_info, props: writer_host in host_info.host)
519520
ConnectionProviderManager.set_connection_provider(provider)
520521

521522
WrapperProperties.PLUGINS.set(proxied_failover_props, "read_write_splitting,failover,host_monitoring")

0 commit comments

Comments
 (0)