Repository navigation
fix: fail fast on failover and warn when cluster_instance_host_pattern is missing for an IP or custom domain - #235
Conversation
…P or custom domain When the connection host isn't a recognized RDS endpoint and cluster_instance_host_pattern isn't set, instance hosts are built as bare instance identifiers that usually don't resolve, so failover retried until failover_timeout_sec (300 s by default). - On Aurora and RDS Multi-AZ DB clusters, connections that list failover explicitly in wrapper_plugins now raise at startup, naming the host and both fixes. With the default plugin list, a warning is logged once per host. - The topology monitor records unresolvable instance hosts as a fatal configuration error, so writer failover raises FailoverFailedError right away. Reader failover and writer connection attempts check for the same condition. Temporary DNS failures and other network errors still retry. - gdb_failover on a database identified as a regional cluster gets its own message explaining that global_cluster_instance_host_patterns doesn't apply. - Driver error handlers gain unknown_host_error? for mysql2, pg and trilogy.
…ttern is missing Connections whose host isn't a recognized RDS endpoint and that don't set cluster_instance_host_pattern now log a warning on Aurora and RDS Multi-AZ DB clusters, whether or not failover is listed explicitly in wrapper_plugins. Failover still fails fast with FailoverFailedError when an instance host can't be resolved. A future major version will raise at connect instead. - The warning says failover will fail, and keeps the fix that applies (remove failover from wrapper_plugins, or set wrapper_plugins without it when the default list is in use). - gdb_failover on a database identified as a regional cluster now warns too, and its failover paths get the same fail-fast as failover: the topology monitor error becomes FailoverFailedError, and its connection attempts use the on_connect_error hook. - CHANGELOG entry moved to Fixed.
| "The connection host '#{host}' is not a recognized RDS endpoint and " \ | ||
| "#{PropertyDefinition::CLUSTER_INSTANCE_HOST_PATTERN.name} is not set, so the #{plugin_code} plugin cannot " \ | ||
| 'build DB instance hosts from the cluster topology, and failover will fail with FailoverFailedError. ' \ | ||
| "Set #{PropertyDefinition::CLUSTER_INSTANCE_HOST_PATTERN.name} to a DNS pattern that resolves to the " \ | ||
| "cluster's instances (for example, '?.XXX.us-east-1.rds.amazonaws.com'), or #{remedy}." |
There was a problem hiding this comment.
I'm curious to what degree we can reuse UnresolvableInstanceHostError in these cases instead of maintaining multiple locations of a similar text block
| "The connection host '#{host}' is not a recognized RDS endpoint, #{pattern_name} is not set, and the " \ | ||
| 'database was identified as a regional cluster rather than an Aurora Global Database, so ' \ | ||
| "#{PropertyDefinition::GLOBAL_CLUSTER_INSTANCE_HOST_PATTERNS.name} does not apply and the #{PLUGIN_CODE} " \ | ||
| 'plugin cannot build DB instance hosts from the cluster topology, and failover will fail with ' \ | ||
| 'FailoverFailedError. If the cluster is a member of a Global ' \ | ||
| "Database, set #{PropertyDefinition::DIALECT.name} to '#{global_dialect_code}' (without it, a Global " \ | ||
| 'Database is only detected when it spans more than one region). For a standalone cluster, use the ' \ | ||
| "failover plugin instead, and set #{pattern_name} to a DNS pattern that resolves to the cluster's " \ | ||
| "instances (for example, '?.XXX.us-east-1.rds.amazonaws.com')." |
There was a problem hiding this comment.
Same comment here on whether we can reuse the message in UnresolvableInstanceHostError
|
|
||
| if unresolvable_due_to_misconfiguration?(e) | ||
| # Retrying can't help, since the host is a bare instance identifier that will never resolve. | ||
| record_fatal_error(Errors::UnresolvableInstanceHostError.new(host_info.host, initial_host_info&.host)) |
There was a problem hiding this comment.
So just in terms of new behaviours introduced this does fail slightly faster than in 1.0.1 but only in cases where it would have definitely timed out?
|
We ran into this in our initial implementation. I think this would be a helpful addition. |
Thank you @steve-gore-snapdocs for letting us know. We'll be sure to include this fix in the next release! |
…host-pattern # Conflicts: # lib/aws_advanced_ruby_driver_wrapper/errors/error_handler.rb # lib/aws_advanced_ruby_driver_wrapper/services/dialect_service.rb
…missing Replace the DNS-based fail-fast with a configuration check. When the connection host isn't a recognized RDS endpoint and cluster_instance_host_pattern isn't set, failover (writer, reader and gdb_failover) now raises FailoverFailedError as soon as it starts, with the same explanation as the warning logged at connect, instead of waiting for instance hosts to fail to resolve. An explicitly set '?' pattern opts out of both, for environments where bare instance identifiers resolve. - Remove the topology monitor's fatal error, the RetryUtil on_connect_error hook, the reader-failover check, and unknown_host_error? from the error handlers, along with UnresolvableInstanceHostError. - Build the warning and the failover error from the same message methods on FailoverPlugin; gdb_failover overrides only its problem and fix wording, and its fix now also says to set global_cluster_instance_host_patterns. - Warnings mention the '?' opt-out and read as separate sentences. - Add specs that go through execute and connect, and flag the behavior change in the CHANGELOG.
…ing cluster_instance_host_pattern Update the configuration and troubleshooting assistants for the new behavior, tagged [Unreleased] with before/after wording: a warning at connect, an immediate FailoverFailedError on failover, the '?' opt-out, and the gdb_failover regional-cluster message.
| | `in_home_failover_mode` | String | depends on URL | Mode while the primary **is** the home region (§9.2). Writer or global writer endpoint → `strict_writer`; other endpoints → `home_reader_or_writer`. | | ||
| | `out_of_home_failover_mode` | String | depends on URL | Mode while the primary **is not** the home region. Same values and derivation as above. | | ||
| | `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. | | ||
| | `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. Only read for `global-aurora-*` dialects. [Unreleased] `gdb_failover` on a database identified as a regional cluster (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset) behind an IP / own domain without `cluster_instance_host_pattern` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. | |
There was a problem hiding this comment.
| | `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. Only read for `global-aurora-*` dialects. [Unreleased] `gdb_failover` on a database identified as a regional cluster (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset) behind an IP / own domain without `cluster_instance_host_pattern` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. | | |
| | `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. Only read for `global-aurora-*` dialects. [Unreleased] `gdb_failover` on a database identified as a regional cluster (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset) behind an IP / own domain without `global_cluster_instance_host_pattern` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. | |
It should be clear what properties need to be set in the gdb and not gdb case - does a user need to set global_cluster_instance_host_patterns and cluster_instance_host_patterns for a gdb? Similar wording exists in the troubleshooting skill
A Global Database only needs global_cluster_instance_host_patterns; on a regional dialect that setting is ignored and cluster_instance_host_pattern applies instead.
Summary
When the connection host isn't a recognized RDS endpoint and
cluster_instance_host_patternisn't set, warn at connect and make failover raiseFailoverFailedErrorimmediately, instead of retrying instance hosts that can't be resolved untilfailover_timeout_sec.Description
When the connection host is an IP address or a custom domain/CNAME and
cluster_instance_host_patternisn't set,RdsHostListProviderfalls back to a bare?instance template. With the previous code, this template passes validation, and nothing is logged. The topology monitor then builds instance hosts as bare instance identifiers, which usually don't resolve. On a failover it retries them untilfailover_timeout_sec(300 s by default), and then raises aFailoverFailedErrorthat doesn't mention the missing setting.Detection
RdsHostListProvider#instance_host_pattern_missing?is true when the template is a bare?andcluster_instance_host_patternwasn't set.RdsHostListProvider, so single instances and community databases aren't affected.GlobalAuroraHostListProvideralways returns false, because it requiresglobal_cluster_instance_host_patterns.cluster_instance_host_pattern: '?'doesn't count as missing. That's the opt-out for environments where bare instance identifiers resolve, for example through a DNS search domain.Warning at connect
FailoverPluginlogs oneWARNper host if the pattern is missing. This happens whetherfailoveris listed explicitly inwrapper_pluginsor comes from the default list, and the connection still opens.cluster_instance_host_pattern(or?if bare identifiers resolve), or removefailoverfromwrapper_plugins.Failover
gdb_failover, check the same condition first. They raiseFailoverFailedError("Failover is not possible. ..." followed by the warning's explanation) without refreshing the topology or connecting.execute(network errors, closed connections) and fromconnectwithenable_connect_failover. The attempt counts as a failed failover in telemetry. An explicitly closed connection still re-raises the original error.gdb_failover
wrapper_dialect: aurora-pg, or a single-region Global Database withwrapper_dialectunset), the message explains thatglobal_cluster_instance_host_patternsdoesn't apply.wrapper_dialectto the global dialect and setglobal_cluster_instance_host_patterns. For a standalone cluster, it says to usefailoverwithcluster_instance_host_pattern.Behavior change
In the rare setup where bare instance identifiers resolve, failover used to succeed and now fails immediately unless
cluster_instance_host_pattern: '?'is set. This is flagged in the CHANGELOG.Docs
Testing
?, and Global Databases;INFOlevel, for explicit and default plugin lists, and again afterclear_caches;executeandconnect, in writer and reader modes and forgdb_failover;bundle exec rspec spec/unitandbundle exec rubocoppass.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.