Skip to content

Commit fbd6443

Browse files
committed
fix: initial connection strategy retry and routing
1 parent cc323eb commit fbd6443

7 files changed

Lines changed: 609 additions & 169 deletions

‎aws_advanced_python_wrapper/aio/aurora_initial_connection_strategy_plugin.py‎

Lines changed: 128 additions & 70 deletions
Large diffs are not rendered by default.

‎aws_advanced_python_wrapper/aurora_initial_connection_strategy_plugin.py‎

Lines changed: 203 additions & 70 deletions
Large diffs are not rendered by default.

‎aws_advanced_python_wrapper/resources/aws_advanced_python_wrapper_messages.properties‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ AuroraInitialConnectionStrategyPlugin.InvalidSettingForEndpoint=[AuroraInitialCo
1919
AuroraInitialConnectionStrategyPlugin.InvalidSettingForInstanceEndpoint=[AuroraInitialConnectionStrategyPlugin] Parameter '{}' cannot be set when using an instance endpoint. Please see the Aurora Initial Connection Strategy Plugin documentation for valid setting/endpoint combinations.
2020
AuroraInitialConnectionStrategyPlugin.InvalidPropertyValue=[AuroraInitialConnectionStrategyPlugin] Received an invalid value for parameter '{}'. Received '{}', valid values are {}.
2121
AuroraInitialConnectionStrategyPlugin.Timeout=[AuroraInitialConnectionStrategyPlugin] The Aurora Initial Connection Strategy Plugin attempted to connect but timed out after {}ms. Please ensure that your URL is correct, there are no network issues, and you are connecting to the correct role if '{}' was set.
22-
AuroraInitialConnectionStrategyPlugin.IncorrectRole=[AuroraInitialConnectionStrategyPlugin] The connection opened to '{}' did not have the expected role '{}'. Retrying.
22+
AuroraInitialConnectionStrategyPlugin.TimeoutWithCause=[AuroraInitialConnectionStrategyPlugin] The Aurora Initial Connection Strategy Plugin attempted to connect but timed out after {}ms. Please ensure that your URL is correct, there are no network issues, and you are connecting to the correct role if '{}' was set. The last failure was: {}
23+
AuroraInitialConnectionStrategyPlugin.InvalidSettingForManagedEndpoint=[AuroraInitialConnectionStrategyPlugin] Parameter '{}' cannot be set to '{}' when using a proxy or Limitless shard group endpoint, because substituting an instance host would bypass that endpoint.
24+
AuroraInitialConnectionStrategyPlugin.WaitForTopologyError=[AuroraInitialConnectionStrategyPlugin] An error occurred while waiting for the cluster topology to be fetched: {}. Falling back to connecting via the provided endpoint.
25+
AuroraInitialConnectionStrategyPlugin.IncorrectRole=[AuroraInitialConnectionStrategyPlugin] The connection opened to '{}' should have the role '{}' but has the role '{}'.
2326
AuroraInitialConnectionStrategyPlugin.VerifyReaderConfiguredButNoReadersExist=[AuroraInitialConnectionStrategyPlugin] Parameter '{}' was set to 'reader' but no readers were detected in the topology. The writer will be used as a fallback.
2427
AuroraInitialConnectionStrategyPlugin.WaitingForTopology=[AuroraInitialConnectionStrategyPlugin] Waiting up to {}ms for the cluster topology of '{}' to be fetched before opening a new connection.
2528
AuroraInitialConnectionStrategyPlugin.WaitForTopologyTimeout=[AuroraInitialConnectionStrategyPlugin] Timed out after {}ms while waiting for the cluster topology of '{}' to be fetched. Falling back to connecting via the provided endpoint.

‎docs/PYTHON-WRAPPER-CONFIGURATION-ASSISTANT.md‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,8 +2420,9 @@ and replaces it with the current writer.
24202420
- **In the default list:** yes.
24212421
- **Use with:** Aurora writer and reader cluster endpoints, custom
24222422
cluster endpoints, and the Global Database writer endpoint.
2423-
- With an instance endpoint the only valid setting is `none`, so the
2424-
plugin does not substitute or verify.
2423+
- With an instance endpoint the only valid `endpoint_substitution_role`
2424+
is `none`, so the plugin does not substitute. It verifies the role only
2425+
when `verify_opened_connection_type` is set.
24252426
24262427
**Parameters:**
24272428
@@ -2431,9 +2432,9 @@ and replaces it with the current writer.
24312432
| `reader_initial_connection_host_selector_strategy` | `random` | Deprecated. Read only when `initial_connection_host_selector_strategy` is not set at all. |
24322433
| `endpoint_substitution_role` | (derived) | `writer`, `reader` or `none`. When unset: `writer` for writer cluster and global writer endpoints, `reader` for reader cluster endpoints, `none` for everything else. |
24332434
| `verify_opened_connection_type` | (derived) | `writer`, `reader` or `none`. When unset it follows the same rule as `endpoint_substitution_role`. Invalid values raise `InvalidPropertyValue`. |
2434-
| `inactive_cluster_writer_endpoint_substitution_role` | `writer` | Global Database: whether to replace the writer endpoint of a cluster that is not currently primary. `writer` or `none`. |
2435-
| `verify_inactive_cluster_writer_endpoint_connection_type` | `writer` | Global Database: whether to verify a connection opened through that endpoint is a writer. `writer` or `none`. |
2436-
| `open_connection_retry_timeout_ms` | `30000` | Maximum time in milliseconds for connection retries. |
2435+
| `inactive_cluster_writer_endpoint_substitution_role` | `writer` | Global Database: whether to replace the writer endpoint of a cluster that is not currently primary. `writer` or `none`. Also decides any writer cluster endpoint while the topology is not known yet, such as the first connection a process opens. |
2436+
| `verify_inactive_cluster_writer_endpoint_connection_type` | `writer`, or `none` when unset and `inactive_cluster_writer_endpoint_substitution_role` is `none` | Global Database: whether to verify a connection opened through that endpoint is a writer. `writer` or `none`. |
2437+
| `open_connection_retry_timeout_ms` | `30000` | Maximum time in milliseconds for connection retries. `0` makes one attempt with no retries. |
24372438
| `open_connection_retry_interval_ms` | `1000` | Wait in milliseconds between retries. |
24382439
| `wait_for_initial_topology_ms` | `0` | When above 0, wait up to this long for the topology before the first connection, so the strategy can spread concurrent and pool-prefill connections across instances instead of sending all of them to the one host DNS returns. `0` turns the wait off. |
24392440
| `gdb_accessible_regions` | (all regions) | Skip hosts outside these regions. Sync only in 3.1.0. |
@@ -2448,16 +2449,20 @@ an error:
24482449
| Reader cluster | `reader`, `none` | `reader`, `none` |
24492450
| Custom cluster | `reader`, `none` | `reader`, `none` |
24502451
| Instance | `none` only | `writer`, `reader` or `none` (not restricted) |
2452+
| RDS Proxy or Limitless shard group | `none` only | `writer`, `reader` or `none` (not restricted) |
24512453
24522454
`endpoint_substitution_role=any` is accepted for a custom cluster
24532455
endpoint but raises an unsupported-strategy error at connect in 3.1.0.
24542456
Use `reader` or `none`.
24552457
2456-
**Behavior to tell the user about:** a network error while connecting
2457-
is retried until `open_connection_retry_timeout_ms` runs out, and then
2458-
the plugin raises `AwsWrapperError`. So when the database is down, a
2459-
connect call can take up to 30 seconds with the defaults before it
2460-
fails. A login error is not retried. When a reader is requested but the
2458+
**Behavior to tell the user about:** for writer, reader and global
2459+
writer cluster endpoints, a network error while connecting is retried
2460+
until `open_connection_retry_timeout_ms` runs out, and then the plugin
2461+
raises `AwsWrapperError` naming the last failure. So when the database
2462+
is down, a connect call can take up to 30 seconds with the defaults
2463+
before it fails. When the plugin has nothing to substitute and no role
2464+
to verify (instance endpoints, RDS Proxy, custom cluster endpoints by
2465+
default), it connects once and raises the driver's error. A login error is not retried. When a reader is requested but the
24612466
cluster is without readers, the plugin returns the writer connection, as
24622467
the reader cluster endpoint would.
24632468

0 commit comments

Comments
 (0)