Skip to content

Commit b4201b6

Browse files
authored
feat: gdb support (#1184)
1 parent bd3df4c commit b4201b6

43 files changed

Lines changed: 1847 additions & 873 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aws_advanced_python_wrapper/aurora_connection_tracker_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from aws_advanced_python_wrapper.pep249_methods import DbApiMethod
3939
from aws_advanced_python_wrapper.plugin import Plugin, PluginFactory
4040
from aws_advanced_python_wrapper.utils.log import Logger
41-
from aws_advanced_python_wrapper.utils.rdsutils import RdsUtils
41+
from aws_advanced_python_wrapper.utils.rds_utils import RdsUtils
4242

4343
logger = Logger(__name__)
4444

aws_advanced_python_wrapper/aurora_initial_connection_strategy_plugin.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from aws_advanced_python_wrapper.utils.properties import (Properties,
3232
WrapperProperties)
3333
from aws_advanced_python_wrapper.utils.rds_url_type import RdsUrlType
34-
from aws_advanced_python_wrapper.utils.rdsutils import RdsUtils
34+
from aws_advanced_python_wrapper.utils.rds_utils import RdsUtils
3535

3636

3737
class AuroraInitialConnectionStrategyPlugin(Plugin):
@@ -45,7 +45,7 @@ def subscribed_methods(self) -> Set[str]:
4545

4646
def __init__(self, plugin_service: PluginService):
4747
super()
48-
self._plugin_service = plugin_service
48+
self._plugin_service: PluginService = plugin_service
4949
self._rds_utils = RdsUtils()
5050

5151
def connect(self, target_driver_func: Callable, driver_dialect: DriverDialect, host_info: HostInfo, props: Properties,
@@ -207,6 +207,20 @@ def _get_reader(self, props: Properties) -> Optional[HostInfo]:
207207
and strategy is not None
208208
and self._plugin_service.accepts_strategy(HostRole.READER, strategy)):
209209
try:
210+
original_host = self._plugin_service.current_host_info
211+
url_type = self._rds_utils.identify_rds_type(original_host.host) if original_host else None
212+
213+
if url_type and url_type.has_region:
214+
aws_region = self._rds_utils.get_rds_region(original_host.host)
215+
if aws_region:
216+
hosts_in_region = []
217+
for h in self._plugin_service.all_hosts:
218+
h_region = self._rds_utils.get_rds_region(h.host)
219+
if h_region and aws_region.lower() == h_region.lower():
220+
hosts_in_region.append(h)
221+
return self._plugin_service.get_host_info_by_strategy(
222+
HostRole.READER, strategy, hosts_in_region)
223+
210224
return self._plugin_service.get_host_info_by_strategy(HostRole.READER, strategy)
211225
except Exception:
212226
# Host isn't found.

aws_advanced_python_wrapper/aws_credentials_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AwsCredentialsManager:
3232
_clients: dict[str, Any] = {}
3333

3434
@staticmethod
35-
def get_session(host_info: HostInfo, props: Properties, region: str) -> Session:
35+
def get_session(host_info: HostInfo, props: Properties, region: Optional[str] = None) -> Session:
3636
profile_name = WrapperProperties.AWS_PROFILE.get(props)
3737
host_key = f'{host_info.as_alias()}{region}{profile_name}'
3838

aws_advanced_python_wrapper/blue_green_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from aws_advanced_python_wrapper.utils.messages import Messages
5252
from aws_advanced_python_wrapper.utils.properties import (Properties,
5353
WrapperProperties)
54-
from aws_advanced_python_wrapper.utils.rdsutils import RdsUtils
54+
from aws_advanced_python_wrapper.utils.rds_utils import RdsUtils
5555
from aws_advanced_python_wrapper.utils.telemetry.telemetry import \
5656
TelemetryTraceLevel
5757

aws_advanced_python_wrapper/cluster_topology_monitor.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
from concurrent.futures import ThreadPoolExecutor
2121
from typing import TYPE_CHECKING, Dict, Optional
2222

23+
from aws_advanced_python_wrapper.errors import AwsWrapperError
2324
from aws_advanced_python_wrapper.host_availability import HostAvailability
2425
from aws_advanced_python_wrapper.hostinfo import HostInfo
2526
from aws_advanced_python_wrapper.utils.atomic import AtomicReference
2627
from aws_advanced_python_wrapper.utils.messages import Messages
27-
from aws_advanced_python_wrapper.utils.rdsutils import RdsUtils
28+
from aws_advanced_python_wrapper.utils.rds_utils import RdsUtils
2829
from aws_advanced_python_wrapper.utils.storage.storage_service import (
2930
StorageService, Topology)
3031
from aws_advanced_python_wrapper.utils.thread_safe_connection_holder import \
@@ -35,7 +36,7 @@
3536
from aws_advanced_python_wrapper.pep249 import Connection
3637
from aws_advanced_python_wrapper.plugin_service import PluginService
3738
from aws_advanced_python_wrapper.utils.properties import Properties
38-
from aws_advanced_python_wrapper.host_list_provider import TopologyUtils
39+
from aws_advanced_python_wrapper.host_list_provider import TopologyUtils, GlobalAuroraTopologyUtils
3940

4041
from aws_advanced_python_wrapper.hostinfo import HostRole
4142
from aws_advanced_python_wrapper.utils.log import Logger
@@ -316,9 +317,10 @@ def _open_any_connection_and_update_topology(self) -> Topology:
316317
writer_host_info = self._initial_host_info
317318
self._writer_host_info.set(writer_host_info)
318319
else:
319-
writer_host = self._instance_template.host.replace("?", writer_id)
320-
port = self._instance_template.port \
321-
if self._instance_template.is_port_specified() \
320+
instance_template = self._get_instance_template(writer_id, conn)
321+
writer_host = instance_template.host.replace("?", writer_id)
322+
port = instance_template.port \
323+
if instance_template.is_port_specified() \
322324
else self._initial_host_info.port
323325
writer_host_info = HostInfo(
324326
writer_host,
@@ -438,6 +440,9 @@ def _query_for_topology(self, connection: Connection) -> Topology:
438440
return hosts
439441
return ()
440442

443+
def _get_instance_template(self, instance_id: str, connection: Connection) -> HostInfo:
444+
return self._instance_template
445+
441446
def _update_topology_cache(self, hosts: Topology) -> None:
442447
StorageService.set(self._cluster_id, hosts, Topology)
443448
# Notify waiting threads
@@ -499,8 +504,8 @@ def __call__(self) -> None:
499504

500505
if is_writer:
501506
try:
502-
if self._monitor._topology_utils.get_host_role(
503-
connection, self._monitor._plugin_service.driver_dialect) != HostRole.WRITER:
507+
if self._monitor._plugin_service.get_host_role(
508+
connection) != HostRole.WRITER:
504509
is_writer = False
505510
except Exception as ex:
506511
logger.debug("HostMonitor.InvalidWriterQuery", ex)
@@ -565,3 +570,45 @@ def _calculate_backoff_with_jitter(self, attempt: int) -> int:
565570
backoff = ClusterTopologyMonitorImpl.INITIAL_BACKOFF_MS * (2 ** min(attempt, 6))
566571
backoff = min(backoff, ClusterTopologyMonitorImpl.MAX_BACKOFF_MS)
567572
return int(backoff * (0.5 + random.random() * 0.5))
573+
574+
575+
class GlobalAuroraTopologyMonitor(ClusterTopologyMonitorImpl):
576+
def __init__(
577+
self,
578+
plugin_service: PluginService,
579+
topology_utils: GlobalAuroraTopologyUtils,
580+
cluster_id: str,
581+
initial_host_info: HostInfo,
582+
props: Properties,
583+
instance_template: HostInfo,
584+
refresh_rate_ns: int,
585+
high_refresh_rate_ns: int,
586+
instance_templates_by_region: dict[str, HostInfo]
587+
):
588+
super().__init__(
589+
plugin_service,
590+
topology_utils,
591+
cluster_id,
592+
initial_host_info,
593+
props,
594+
instance_template,
595+
refresh_rate_ns,
596+
high_refresh_rate_ns
597+
)
598+
self._instance_templates_by_region = instance_templates_by_region
599+
self._global_topology_utils = topology_utils
600+
601+
def _get_instance_template(self, instance_id: str, connection: Connection) -> HostInfo:
602+
region = self._global_topology_utils.get_region(instance_id, connection)
603+
if region:
604+
instance_template = self._instance_templates_by_region.get(region)
605+
if instance_template is None:
606+
raise AwsWrapperError(
607+
Messages.get_formatted("GlobalAuroraTopologyMonitor.cannotFindRegionTemplate", region))
608+
return instance_template
609+
return self._instance_template
610+
611+
def _query_for_topology(self, connection: Connection) -> Topology:
612+
result = self._global_topology_utils.query_for_topology_with_regions(
613+
connection, self._instance_templates_by_region)
614+
return result if result is not None else ()

aws_advanced_python_wrapper/credentials_provider_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929

3030
class CredentialsProviderFactory(Protocol):
3131
@abstractmethod
32-
def get_aws_credentials(self, region: str, props: Properties, host_info: HostInfo) -> Optional[Dict[str, str]]:
32+
def get_aws_credentials(self, region: Optional[str], props: Properties, host_info: HostInfo) -> Optional[Dict[str, str]]:
3333
...
3434

3535

3636
class SamlCredentialsProviderFactory(CredentialsProviderFactory):
3737

38-
def get_aws_credentials(self, region: str, props: Properties, host_info: HostInfo) -> Optional[Dict[str, str]]:
38+
def get_aws_credentials(self, region: Optional[str], props: Properties, host_info: HostInfo) -> Optional[Dict[str, str]]:
3939
saml_assertion: str = self.get_saml_assertion(props)
4040
session = AwsCredentialsManager.get_session(host_info, props, region)
4141
sts_client = AwsCredentialsManager.get_client("sts", session, host_info.host, region)

aws_advanced_python_wrapper/custom_endpoint_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636
from enum import Enum
3737

38-
from boto3 import Session
38+
from boto3 import Session # type: ignore
3939

4040
from aws_advanced_python_wrapper.pep249_methods import DbApiMethod
4141
from aws_advanced_python_wrapper.plugin import Plugin, PluginFactory
4242
from aws_advanced_python_wrapper.utils.log import Logger
4343
from aws_advanced_python_wrapper.utils.properties import WrapperProperties
44-
from aws_advanced_python_wrapper.utils.rdsutils import RdsUtils
44+
from aws_advanced_python_wrapper.utils.rds_utils import RdsUtils
4545
from aws_advanced_python_wrapper.utils.sliding_expiration_cache_container import \
4646
SlidingExpirationCacheContainer
4747
from aws_advanced_python_wrapper.utils.telemetry.telemetry import (

0 commit comments

Comments
 (0)