diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d16a2b8..47ad7198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - **Behavior change:** a successful failover during ActiveRecord's connection check (`active?`) no longer raises `FailoverSuccessError`: no statement of the application's was in flight, so the adapter reconnects silently, as ActiveRecord does for a dead connection, and the next statement runs on the new writer. `TransactionStateUnknownError` is still raised when an ActiveRecord transaction was open, because that transaction was lost; otherwise `active?` returns `false`. A failover during `reset!` completes the reset on the new writer instead of raising. `active?` returns `false`, and `reset!` raises `ActiveRecord::ConnectionFailed`, when failover fails. `aws_mysql2` and `aws_trilogy` are unchanged by these `active?`/`reset!` changes. - Hardened every ActiveRecord adapter (`aws_postgresql`, `aws_mysql2`, `aws_trilogy`) against any other code path that touches the raw connection outside `with_raw_connection` after a failover. The wrapper's `Method invoked against old connection` error is now flagged `needs_reconfiguration`, so the adapter's exception translation clears ActiveRecord's prepared statement cache and re-applies the connection's settings on the first such failure, instead of every statement prepared before the failover failing until the connection is discarded. - **Behavior change:** that error is still an `AwsError` with the same message, but `needs_reconfiguration` is now `true` (`connection_broken` stays `false`). Code that inspects `needs_reconfiguration` on wrapper errors will now see it set. +- Fixed failover retrying instance hosts that can't be resolved until `failover_timeout_sec` (default 300 s) when the connection host isn't a recognized RDS endpoint (an IP address or your own domain name) and `cluster_instance_host_pattern` isn't set. With `failover` or `gdb_failover` loaded (`failover` is in the default plugin list) on an Aurora or RDS Multi-AZ DB cluster, the wrapper now logs a warning when the first connection to such a host opens, and failover raises `FailoverFailedError` immediately, with a message that names `cluster_instance_host_pattern`. For `gdb_failover` on a database identified as a regional cluster rather than a Global Database (for example with `wrapper_dialect: aurora-pg`), the message explains that `global_cluster_instance_host_patterns` doesn't apply. A future major version will raise an error at connect for this configuration ([PR #235](https://github.com/aws/aws-advanced-ruby-driver-wrapper/pull/235), [documentation](https://aws.github.io/aws-advanced-wrapper-docs/ruby/enhanced-failover#host-pattern)). + - **Behavior change:** if bare instance identifiers resolve in your environment (for example through a DNS search domain), failover used to succeed in this configuration and now fails immediately. Set `cluster_instance_host_pattern: "?"` to keep the previous behavior. ## [1.1.0] - 2026-11-05 diff --git a/lib/aws_advanced_ruby_driver_wrapper.rb b/lib/aws_advanced_ruby_driver_wrapper.rb index e0622380..0efb6548 100644 --- a/lib/aws_advanced_ruby_driver_wrapper.rb +++ b/lib/aws_advanced_ruby_driver_wrapper.rb @@ -72,6 +72,7 @@ def self.clear_caches Utils::RdsUtils.clear_cache Services::DialectService.known_endpoint_dialects.clear Services::HostService.clear_id_cache + Plugins::FailoverPlugin::MISSING_PATTERN_WARNED_HOSTS.clear if defined?(Plugins::FailoverPlugin) end # Runs in a forked child (see ForkHook). Only the forking thread survives a fork, so every background diff --git a/lib/aws_advanced_ruby_driver_wrapper/host/global_aurora_host_list_provider.rb b/lib/aws_advanced_ruby_driver_wrapper/host/global_aurora_host_list_provider.rb index da9025ee..75eddc2a 100644 --- a/lib/aws_advanced_ruby_driver_wrapper/host/global_aurora_host_list_provider.rb +++ b/lib/aws_advanced_ruby_driver_wrapper/host/global_aurora_host_list_provider.rb @@ -48,6 +48,12 @@ def force_refresh(verify_writer, timeout_sec) nil end + # Instance hosts come from the region templates in global_cluster_instance_host_patterns, which is + # required, so they never depend on the bare instance template built for a non-RDS connection host. + def instance_host_pattern_missing? + false + end + private def build_instance_templates_by_region diff --git a/lib/aws_advanced_ruby_driver_wrapper/host/rds_host_list_provider.rb b/lib/aws_advanced_ruby_driver_wrapper/host/rds_host_list_provider.rb index 461558a2..494fd0d1 100644 --- a/lib/aws_advanced_ruby_driver_wrapper/host/rds_host_list_provider.rb +++ b/lib/aws_advanced_ruby_driver_wrapper/host/rds_host_list_provider.rb @@ -46,6 +46,8 @@ def initialize(service_container:, topology_utils:) props = @service_container.connection_service.wrapper_props @cluster_id = PropertyDefinition::CLUSTER_ID.get_string(props) @instance_template = build_instance_template(props) + @instance_host_pattern_missing = PropertyDefinition::CLUSTER_INSTANCE_HOST_PATTERN.get(props).nil? && + @instance_template.host == Utils::RdsUtils::BARE_INSTANCE_HOST_PATTERN validate_host_pattern!(@instance_template.host) @rds_url_type = Utils::RdsUtils.identify_rds_type(initial_host_info.host) @@ -107,6 +109,17 @@ def stop_monitor @service_container.monitor_service.stop_and_remove(:cluster_topology, @cluster_id) end + # Whether DB instance hosts can't be derived from the topology. This is the case when the connection + # host isn't a recognized RDS endpoint and cluster_instance_host_pattern isn't set: the instance template + # is then a bare '?', so instance hosts are bare instance identifiers that usually don't resolve. An + # explicitly set '?' pattern doesn't count: it is how users whose environment resolves bare instance + # identifiers (e.g. through a DNS search domain) opt out of the warning and of failing over immediately. + # + # @return [Boolean] + def instance_host_pattern_missing? + @instance_host_pattern_missing + end + private def stored_topology diff --git a/lib/aws_advanced_ruby_driver_wrapper/plugins/failover_plugin.rb b/lib/aws_advanced_ruby_driver_wrapper/plugins/failover_plugin.rb index 1578c256..b0857d10 100644 --- a/lib/aws_advanced_ruby_driver_wrapper/plugins/failover_plugin.rb +++ b/lib/aws_advanced_ruby_driver_wrapper/plugins/failover_plugin.rb @@ -41,6 +41,12 @@ class FailoverPlugin TELEMETRY_WRITER_FAILOVER = 'failover to writer host' TELEMETRY_READER_FAILOVER = 'failover to replica' + PLUGIN_CODE = 'failover' + + # Connection hosts already warned about a missing cluster_instance_host_pattern, so that the warning is + # logged once per host rather than once per connection. + MISSING_PATTERN_WARNED_HOSTS = Concurrent::Set.new + def initialize(service_container, props = ::Concurrent::Map.new) @service_container = service_container @wrapper_props = props @@ -65,28 +71,9 @@ def initialize(service_container, props = ::Concurrent::Map.new) def connect(host_info, driver_props, is_initial_connection, pipeline_callable) init_failover_mode - - unless PropertyDefinition::ENABLE_CONNECT_FAILOVER.get_bool(@wrapper_props) - return verified_connection(is_initial_connection, host_info, driver_props, pipeline_callable) - end - - topology_host = host_service.hosts.find { |h| h.host_and_port == host_info&.host_and_port } - - if !topology_host.nil? && topology_host.availability == Host::HostAvailability::UNAVAILABLE - host_service.refresh_host_list - return connect_via_failover(is_initial_connection) - end - - begin - conn = verified_connection(is_initial_connection, host_info, driver_props, pipeline_callable) - host_service.refresh_host_list if is_initial_connection - conn - rescue StandardError => e - raise unless trigger_failover?(e) - - host_service.set_availability(host_info, Host::HostAvailability::UNAVAILABLE) - connect_via_failover(is_initial_connection) - end + conn = connect_with_failover(host_info, driver_props, is_initial_connection, pipeline_callable) + warn_if_instance_host_pattern_missing if is_initial_connection + conn end def execute(method_name, pipeline_callable, *, **, &) @@ -117,6 +104,103 @@ def execute(method_name, pipeline_callable, *, **, &) private + def connect_with_failover(host_info, driver_props, is_initial_connection, pipeline_callable) + unless PropertyDefinition::ENABLE_CONNECT_FAILOVER.get_bool(@wrapper_props) + return verified_connection(is_initial_connection, host_info, driver_props, pipeline_callable) + end + + topology_host = host_service.hosts.find { |h| h.host_and_port == host_info&.host_and_port } + + if !topology_host.nil? && topology_host.availability == Host::HostAvailability::UNAVAILABLE + host_service.refresh_host_list + return connect_via_failover(is_initial_connection) + end + + begin + conn = verified_connection(is_initial_connection, host_info, driver_props, pipeline_callable) + host_service.refresh_host_list if is_initial_connection + conn + rescue StandardError => e + raise unless trigger_failover?(e) + + host_service.set_availability(host_info, Host::HostAvailability::UNAVAILABLE) + connect_via_failover(is_initial_connection) + end + end + + # Failover needs DB instance hosts it can resolve. Whether it has them is only known once the initial + # connection has settled the dialect: cluster dialects (Aurora, RDS Multi-AZ DB cluster) then use an + # RdsHostListProvider, which reports whether the instance host pattern is missing. A single instance or a + # community database never has one, so it isn't affected. A missing pattern is logged as a warning, once + # per host, and the connection is still returned; failover then fails immediately (see + # #raise_if_instance_host_pattern_missing). + def warn_if_instance_host_pattern_missing + return unless instance_host_pattern_missing? + + host = connection_service.initial_host_info&.host + return unless MISSING_PATTERN_WARNED_HOSTS.add?(host) + + logger.warn("#{missing_instance_host_pattern_problem(host)}. Failover will fail with FailoverFailedError. " \ + "#{missing_instance_host_pattern_fix}") + end + + # Failover can't reach any DB instance when the instance host pattern is missing, since the instance hosts + # are bare instance identifiers. Failing right away, with the same explanation as the warning logged at + # connect, is better than retrying them until failover_timeout_sec. + # + # @raise [Errors::FailoverFailedError] if the instance host pattern is missing + def raise_if_instance_host_pattern_missing + return unless instance_host_pattern_missing? + + host = connection_service.initial_host_info&.host + raise Errors::FailoverFailedError, + "Failover is not possible. #{missing_instance_host_pattern_problem(host)}. #{missing_instance_host_pattern_fix}" + end + + def instance_host_pattern_missing? + provider = host_service.host_list_provider + provider.respond_to?(:instance_host_pattern_missing?) && provider.instance_host_pattern_missing? + end + + # @return [Boolean] whether wrapper_plugins was set by the user. This plugin is loaded, so it is in the list. + def plugin_requested_explicitly? + @wrapper_props.key?(PropertyDefinition::PLUGINS.name) + end + + # The warning logged at connect and the error raised by failover are both built from the methods below, so + # they describe the problem and its fix the same way. + + # @return [String] a clause, without trailing punctuation, saying why the instance hosts can't be built + def missing_instance_host_pattern_reason(host) + "The connection host '#{host}' is not a recognized RDS endpoint and " \ + "#{PropertyDefinition::CLUSTER_INSTANCE_HOST_PATTERN.name} is not set" + end + + # @return [String] what to set cluster_instance_host_pattern to, phrased to follow "Set" or "set" + def instance_host_pattern_setting + "#{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 '?' if bare instance identifiers " \ + 'resolve in your environment)' + end + + # @return [String] a clause, without trailing punctuation, describing the problem + def missing_instance_host_pattern_problem(host) + "#{missing_instance_host_pattern_reason(host)}, so the #{self.class::PLUGIN_CODE} plugin cannot build " \ + 'DB instance hosts from the cluster topology' + end + + # @return [String] the fixes, as one or more full sentences + def missing_instance_host_pattern_fix + plugin_code = self.class::PLUGIN_CODE + remedy = if plugin_requested_explicitly? + "remove #{plugin_code} from #{PropertyDefinition::PLUGINS.name}" + else + "set #{PropertyDefinition::PLUGINS.name} to a list without #{plugin_code} (it is enabled by default)" + end + + "Set #{instance_host_pattern_setting}, or #{remedy}." + end + def connect_via_failover(is_initial_connection) begin failover @@ -310,6 +394,7 @@ def failover_reader failover_deadline = failover_start + @failover_timeout logger.info { 'Starting reader failover' } + raise_if_instance_host_pattern_missing unless host_service.force_refresh_host_list?(verify_writer: false, timeout_sec: 0) raise Errors::FailoverFailedError, 'The request to discover the new topology was unsuccessful' @@ -337,6 +422,7 @@ def failover_writer result = nil logger.info { 'Starting writer failover' } + raise_if_instance_host_pattern_missing begin unless host_service.force_refresh_host_list?(verify_writer: true, timeout_sec: @failover_timeout) diff --git a/lib/aws_advanced_ruby_driver_wrapper/plugins/gdb/gdb_failover_plugin.rb b/lib/aws_advanced_ruby_driver_wrapper/plugins/gdb/gdb_failover_plugin.rb index fcb2c6a8..0056b954 100644 --- a/lib/aws_advanced_ruby_driver_wrapper/plugins/gdb/gdb_failover_plugin.rb +++ b/lib/aws_advanced_ruby_driver_wrapper/plugins/gdb/gdb_failover_plugin.rb @@ -15,6 +15,7 @@ # limitations under the License. require_relative '../failover_plugin' +require_relative '../../db_dialects/dialect_codes' require_relative '../../errors' require_relative '../../host/host_role' require_relative '../../property_definition' @@ -39,6 +40,7 @@ module Gdb # regions are never selected. class GdbFailoverPlugin < FailoverPlugin TELEMETRY_FAILOVER = 'global database failover' + PLUGIN_CODE = 'gdb_failover' def initialize(service_container, props = ::Concurrent::Map.new) super @@ -216,6 +218,7 @@ def failover_with_plan def failover_plan # This is expected to return once the topology has stabilized, i.e. once the cluster # control plane has already chosen a new writer. + raise_if_instance_host_pattern_missing unless host_service.force_refresh_host_list?(verify_writer: true, timeout_sec: @failover_timeout) raise Errors::FailoverFailedError, 'The request to discover the new topology timed out or was unsuccessful' end @@ -418,6 +421,27 @@ def failover_reader def failover_writer raise NotImplementedError, "#{self.class} performs failover via #failover" end + + # The instance host pattern can only be missing when the database was identified as a regional cluster: + # for a Global Database, instance hosts come from global_cluster_instance_host_patterns, which is + # required. On a regional cluster that setting is not read, so the problem and fix explain how to have + # the database treated as a Global Database, or how to configure the regional cluster instead. + def missing_instance_host_pattern_problem(host) + "#{missing_instance_host_pattern_reason(host)}. 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" + end + + def missing_instance_host_pattern_fix + "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) and set #{PropertyDefinition::GLOBAL_CLUSTER_INSTANCE_HOST_PATTERNS.name}. For a standalone " \ + "cluster, use the failover plugin instead, and set #{instance_host_pattern_setting}." + end + + def global_dialect_code + driver_dialect.database_engine == :mysql ? DialectCodes::GLOBAL_AURORA_MYSQL : DialectCodes::GLOBAL_AURORA_PG + end end end end diff --git a/lib/aws_advanced_ruby_driver_wrapper/utils/rds_utils.rb b/lib/aws_advanced_ruby_driver_wrapper/utils/rds_utils.rb index 3a517243..97d0660b 100644 --- a/lib/aws_advanced_ruby_driver_wrapper/utils/rds_utils.rb +++ b/lib/aws_advanced_ruby_driver_wrapper/utils/rds_utils.rb @@ -46,6 +46,10 @@ module Utils module RdsUtils extend self + # The instance host pattern derived for a host that isn't a recognized RDS endpoint. It has no domain, + # so hosts built from it are bare instance identifiers. + BARE_INSTANCE_HOST_PATTERN = '?' + # Authoritative allow-list of AWS regions that can host an RDS/Aurora endpoint. KNOWN_REGIONS = %w[ af-south-1 @@ -394,11 +398,11 @@ def rds_instance_name(host) def rds_instance_host_pattern(host) prepared = prepared_host(host) - return '?' if blank?(prepared) + return BARE_INSTANCE_HOST_PATTERN if blank?(prepared) groups = cache_match(prepared, *DNS_PATTERNS) domain = groups&.[]('domain') - domain ? "?.#{domain}" : '?' + domain ? "?.#{domain}" : BARE_INSTANCE_HOST_PATTERN end def rds_region(host) diff --git a/skills/ruby-wrapper-configuration-assistant/SKILL.md b/skills/ruby-wrapper-configuration-assistant/SKILL.md index 134195a5..7d8f2c16 100644 --- a/skills/ruby-wrapper-configuration-assistant/SKILL.md +++ b/skills/ruby-wrapper-configuration-assistant/SKILL.md @@ -560,7 +560,7 @@ production: cluster_instance_host_pattern: "?.XXX.us-east-1.rds.amazonaws.com" ``` -The wrapper can't recognize the host as an RDS endpoint, so it can't build per-instance hostnames from topology. Set `cluster_instance_host_pattern` (`?` = instance identifier). Set `cluster_id` only if the process connects to more than one cluster (§3.12). Leave out `initial_connection` (nothing to resolve). For `iam`, also set `iam_host` to a real RDS endpoint. For `gdb_failover`, use region-prefixed `global_cluster_instance_host_patterns` and `failover_home_region`. `bg` does not support CNAME aliases. +The wrapper can't recognize the host as an RDS endpoint, so it can't build per-instance hostnames from topology. Set `cluster_instance_host_pattern` (`?` = instance identifier). Before `[Unreleased]`, without it failover retried the bare instance names until `failover_timeout_sec` and then raised `FailoverFailedError`; from `[Unreleased]`, the wrapper logs a `WARN` at connect and failover raises `FailoverFailedError` immediately. If bare instance names resolve in the app's environment (e.g. a DNS search domain), `cluster_instance_host_pattern: "?"` keeps failing over to them. Set `cluster_id` only if the process connects to more than one cluster (§3.12). Leave out `initial_connection` (nothing to resolve). For `iam`, also set `iam_host` to a real RDS endpoint. For `gdb_failover`, use region-prefixed `global_cluster_instance_host_patterns` and `failover_home_region`. `bg` does not support CNAME aliases. ### 3.12 Multiple clusters in one app - `cluster_id` per cluster @@ -758,7 +758,7 @@ Detects that the cluster promoted a different instance and reconnects the connec | `failover_timeout_sec` | Float | `300.0` | Maximum time allowed to reconnect to a new writer or reader after failover starts. It only affects the case where failover can't find a target: with `strict_writer`, no writer becomes reachable; with `strict_reader` / `reader_or_writer`, no matching instance is reachable. A normal failover finishes well within it, so lowering it makes requests fail fast (with `FailoverFailedError`) only in that outage case. Failover connects directly to instance endpoints it knows from topology; it doesn't wait for the cluster endpoint's DNS to update. So the 40-60 second DNS delay after a failover (§5.3) is not a reason to increase `failover_timeout_sec`. | | `failover_reader_host_selector_strategy` | String | `random` | Strategy used to select a reader during reader failover (§7). | | `enable_connect_failover` | Boolean | `false` | Enables cluster-aware failover when the **initial** connection fails because of a network exception. The initial connection may be redirected to another instance. | -| `cluster_instance_host_pattern` | String | auto-derived for RDS endpoints | Pattern used to build instance endpoints when the host is not a recognizable RDS endpoint (`?` = instance identifier). Required for IP addresses and custom domains. | +| `cluster_instance_host_pattern` | String | auto-derived for RDS endpoints | Pattern used to build instance endpoints when the host is not a recognizable RDS endpoint (`?` = instance identifier). Required for IP addresses and custom domains. [Unreleased] Without it on an Aurora / Multi-AZ DB cluster: a `WARN` at connect, and failover raises `FailoverFailedError` immediately; an explicit `?` opts out. | | `cluster_id` | String | `'1'` | Shares one topology monitor and cache between connections to the same cluster (§3.12). A Global Database is one cluster for `gdb_failover` connections in any region. | | `cluster_topology_refresh_rate_sec` | Float | `5.0` | Interval at which the topology monitor refreshes a stable cluster. | | `cluster_topology_high_refresh_rate_sec` | Float | `0.1` | Interval between topology updates during the high-rate period (writer discovery, and typically about 30 seconds after a new writer is detected). | @@ -786,7 +786,7 @@ Region-aware failover for Aurora Global Database. Introduces a **home region** a | `failover_home_region` | String | parsed from URL | The AWS region the application runs in. Required when the endpoint carries no region. | | `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, and the only host pattern a Global Database needs: `cluster_instance_host_pattern` isn't required there. Only read for `global-aurora-*` dialects. If the database is identified as a regional cluster instead (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset), this setting is ignored and `cluster_instance_host_pattern` applies, as with `failover`. [Unreleased] In that case, behind an IP / own domain without `cluster_instance_host_pattern`, `gdb_failover` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. Fix: for a Global Database, set `wrapper_dialect` to `global-aurora-pg` / `global-aurora-mysql` and keep this setting; for a standalone cluster, use `failover` with `cluster_instance_host_pattern`. | | `accessible_regions` | String | all regions | Comma-separated regions the application can reach. Failover only considers nodes in these regions; topology monitoring still tracks every region. Must include the home region if set. | | `failover_timeout_sec` | Float | `300.0` | As `failover`. | | `failover_reader_host_selector_strategy` | String | `random` | As `failover`. | @@ -1529,7 +1529,8 @@ All under `AwsAdvancedRubyDriverWrapper::Errors`, subclasses of `AwsError`: | `ActiveRecord::ConnectionFailed ... FailoverFailedError` | Failover could not reach a new instance within `failover_timeout_sec` (not a success) | Check cluster health and reachability of instance endpoints (security groups, `cluster_instance_host_pattern` for IP/CNAME hosts); the pool will replace the connection | | A request or job fails with `FailoverSuccessError` under Active Record (the process keeps running; later work uses the reconnected connection) | The adapter re-raises it unchanged after reconnecting | Rescue it and replay idempotent work (§9.3) | | Session settings (timezone, search path, statement timeout) lost after failover | Not declared under `variables:` | Move them under `variables:` (§13.4) | -| Failover doesn't work behind an IP address or own domain name; topology never resolves | No `cluster_instance_host_pattern`, so per-instance hostnames can't be built | Set `cluster_instance_host_pattern` (§3.11) | +| [Unreleased] `WARN` at connect: `The connection host '' is not a recognized RDS endpoint and cluster_instance_host_pattern is not set, so the failover plugin cannot build DB instance hosts ...` | IP address or own domain name in front of an Aurora / Multi-AZ DB cluster, no `cluster_instance_host_pattern` | Set `cluster_instance_host_pattern` (§3.11), or remove `failover` from `wrapper_plugins` | +| Failover doesn't work behind an IP address or own domain name. Before `[Unreleased]`: `FailoverFailedError` after `failover_timeout_sec`; from `[Unreleased]`: `FailoverFailedError: Failover is not possible. ...` immediately | No `cluster_instance_host_pattern`, so per-instance hostnames are bare instance names | Set `cluster_instance_host_pattern` (§3.11); `?` if bare instance names resolve in the app's environment | | Topology from one cluster appears in another / failover reconnects to the wrong cluster | Several clusters share the default `cluster_id` | Distinct `cluster_id` per cluster | | Topology monitor uses the wrong user or database, or ignores timeout overrides | The monitor keeps the context of the first connection that created it for that `cluster_id` | Put `topology_monitoring_*` settings on every connection sharing the `cluster_id` | | Global Database connection fails at setup | Missing `global_cluster_instance_host_patterns`, or missing `failover_home_region` on the global endpoint | Set both (§5.2) | diff --git a/skills/ruby-wrapper-troubleshooting-assistant/SKILL.md b/skills/ruby-wrapper-troubleshooting-assistant/SKILL.md index 0639712b..79563f22 100644 --- a/skills/ruby-wrapper-troubleshooting-assistant/SKILL.md +++ b/skills/ruby-wrapper-troubleshooting-assistant/SKILL.md @@ -260,7 +260,7 @@ How it works, in brief: the `failover` plugin starts failover when a call fails 1. Is `failover` (or `gdb_failover`) loaded? Setting `wrapper_plugins` replaces the defaults, so `wrapper_plugins: iam` drops failover. 2. Was the error a network error? Statement timeouts, query cancellations, deadlocks, lock wait timeouts, constraint violations, and authentication failures don't trigger failover. With `mysql2` before 1.1.0, a `read_timeout` and MySQL's idle disconnect (error 4031) don't either (see below). -3. Was there a host list? With `DEBUG` on, `Skipping failover for : no topology available.` means the wrapper had no host list at all. That's unusual - the host list normally holds at least the host the app connected to - so if it persists, collect `DEBUG` logs and escalate (§7). (An IP address or own domain name without `cluster_instance_host_pattern` doesn't cause this line: failover does start, but the instance hostnames it builds are bare instance names that usually don't resolve, so it ends in `FailoverFailedError` - set `cluster_instance_host_pattern`.) +3. Was there a host list? With `DEBUG` on, `Skipping failover for : no topology available.` means the wrapper had no host list at all. That's unusual - the host list normally holds at least the host the app connected to - so if it persists, collect `DEBUG` logs and escalate (§7). (An IP address or own domain name without `cluster_instance_host_pattern` doesn't cause this line: failover does start, but the instance hostnames it would build are bare instance names that usually don't resolve. Before `[Unreleased]`, it retries them and ends in `FailoverFailedError` after `failover_timeout_sec`; from `[Unreleased]`, it raises `FailoverFailedError: Failover is not possible. ...` immediately, and a `WARN` was already logged at connect (§5). Set `cluster_instance_host_pattern`.) 4. Was the connection closed by the app? `Connection was explicitly closed, skipping failover`. 5. Did it fail while opening a connection? Failover covers calls on an open connection. A connection that fails to open - including a new connection an Active Record pool opens - is only redirected to another instance with `enable_connect_failover: true`. @@ -295,6 +295,7 @@ end | Message | Meaning | Check | |---|---|---| +| [Unreleased] `Failover is not possible. The connection host '' is not a recognized RDS endpoint and cluster_instance_host_pattern is not set ...` | The wrapper can't build DB instance hosts, so it didn't try to fail over. Raised immediately; a `WARN` with the same text was logged at connect | Set `cluster_instance_host_pattern` (e.g. `?.XXX.us-east-1.rds.amazonaws.com`, or `?` if bare instance names resolve). Retrying or raising `failover_timeout_sec` won't help | | `The request to discover the new topology timed out or was unsuccessful` (writer failover, `gdb_failover`) / `The request to discover the new topology was unsuccessful` (reader failover) | Writer failover: the topology monitor couldn't confirm a writer within `failover_timeout_sec`. Reader failover: the wrapper couldn't get a host list from the monitor | The monitor connects to every instance endpoint: reachability (§3.3), credentials, TLS. With `DEBUG`, look for `[] Connection to failed: ` (network and TLS failures), `[] Instance Monitor : ` (credential rejections on instance connections appear here, not as `Connection to ... failed`), and `Failed to open monitoring connection`. On PostgreSQL, a misspelled `topology_monitoring_*` option makes every monitor connection fail with `invalid connection option` | | `Unable to connect to a writer instance` / `Writer failover timed out after s. Unable to connect to a new writer instance.` | A writer was identified but the app couldn't connect to it in time | Reachability of that instance endpoint, credentials (e.g. IAM token for the instance host), cluster health | | `Unable to connect to a reader instance` | `strict_reader` / `reader_or_writer` found no usable reader | Are there healthy readers? Before 1.1.0: is `failover_reader_host_selector_strategy` `random` or a registered selector (known issue, §6.4)? From 1.1.0 a bad name is rejected at setup, but a selector that raises is logged (`Failed to select a reader using the '' host selection strategy: ...`) and treated as finding no reader | @@ -343,6 +344,7 @@ Raising `failover_timeout_sec` doesn't help any of these unless the cluster itse **Global Database (`gdb_failover`):** - Connection fails at setup - `global_cluster_instance_host_patterns` missing or malformed (§4.2), or `failover_home_region` missing on the global endpoint / IP / own domain. +- [Unreleased] Warning at connect `... The database was identified as a regional cluster rather than an Aurora Global Database, so global_cluster_instance_host_patterns does not apply ...`, then `FailoverFailedError: Failover is not possible. ...` on failover. The host is an IP / own domain name, `cluster_instance_host_pattern` isn't set, and the database was detected as regional (`wrapper_dialect: aurora-pg` / `aurora-mysql`, or a single-region Global Database with `wrapper_dialect` unset; detection needs more than one region). `global_cluster_instance_host_patterns` is only read for `global-aurora-*` dialects; on a regional dialect, `cluster_instance_host_pattern` applies instead. Fix for a Global Database: set `wrapper_dialect` to `global-aurora-pg` / `global-aurora-mysql` and keep `global_cluster_instance_host_patterns` (the only host pattern a Global Database needs; `cluster_instance_host_pattern` isn't required). Fix for a standalone cluster: use `failover` with `cluster_instance_host_pattern`. - Warning `Unable to determine region of writer . Please ensure you have set the global_cluster_instance_host_patterns setting.` - the patterns don't cover the writer's region. - After a cross-region switchover the connection can't write - `out_of_home_failover_mode` is a home-reader mode; use `strict_writer` for writer connections. The INFO line `The GDB primary is now , which is in region '' rather than the home region ''. Using out_of_home_failover_mode=.` shows which mode applied. - IAM on the global endpoint fails - add `initial_connection`, and grant `rds:DescribeGlobalClusters`. @@ -418,6 +420,7 @@ Lines are tagged with the `cluster_id` in brackets where one applies, e.g. `[1] | DEBUG | `Writer failover duration: ms` / `Reader failover duration: ms` | How long it took (logged whether it succeeded or failed) | | DEBUG | `Established connection to: ` | Failover succeeded; the connection now points at this host | | DEBUG | `Stale DNS data detected. Opening a connection to ` | The cluster endpoint resolved to a reader; the plugin went straight to the writer instance | +| WARN | [Unreleased] `The connection host '' is not a recognized RDS endpoint and cluster_instance_host_pattern is not set, so the failover plugin cannot build DB instance hosts from the cluster topology. Failover will fail with FailoverFailedError. ...` | Logged once per host at connect: an IP / own domain name in front of an Aurora or Multi-AZ DB cluster without the pattern. Any failover raises `FailoverFailedError` immediately (§4.4). Set `cluster_instance_host_pattern`, or `?` if bare instance names resolve | A healthy writer failover reads: `Detected error` → `Starting writer failover` → `Writer changed: A -> B` (or `Writer verified: B` / `Writer found: B`, depending on which monitor reached the new writer first) → `Writer failover duration` → `Established connection to: B` (reader failover logs `Established connection to:` before its duration line). A `Starting writer failover` that ends on the same host means the connection was lost but the writer didn't change (§4.4). @@ -477,7 +480,7 @@ Where they apply: `failover` + `initial_connection` on Aurora clusters and RDS M | `wrapper_plugins` | `failover,initial_connection` | Comma-separated string, not a list | | `wrapper_dialect` | auto-detected | `aurora-pg`, `global-aurora-pg`, `multi-az-pg-cluster`, `rds-pg`, `pg`, `aurora-mysql`, `global-aurora-mysql`, `multi-az-mysql-cluster`, `rds-mysql`, `mysql` | | `cluster_id` | `'1'` | Distinct per cluster; the same for every entry on one cluster. A Global Database is one cluster for `gdb_failover` connections in any region (§4.4). Quote numeric values in YAML | -| `cluster_instance_host_pattern` | derived for RDS hosts | Required for IP / own domain with failover: `?.XXX..rds.amazonaws.com` | +| `cluster_instance_host_pattern` | derived for RDS hosts | Required for IP / own domain with failover: `?.XXX..rds.amazonaws.com`. [Unreleased] Missing on a cluster: a `WARN` at connect, and failover fails immediately; an explicit `?` opts out | | `failover_mode` | `reader_or_writer` on `-ro-` endpoints, else `strict_writer` | `strict_writer`, `strict_reader`, `reader_or_writer` | | `failover_timeout_sec` | `300.0` | Seconds, not milliseconds | | `enable_connect_failover` | `false` | Failover when opening a connection fails | diff --git a/spec/unit/failover_plugin_spec.rb b/spec/unit/failover_plugin_spec.rb index 82dee416..c5d4b982 100644 --- a/spec/unit/failover_plugin_spec.rb +++ b/spec/unit/failover_plugin_spec.rb @@ -79,9 +79,12 @@ refresh_host_list: nil, force_refresh_host_list?: true, set_availability: nil, - select_host: reader_host) + select_host: reader_host, + host_list_provider: host_list_provider) end + let(:host_list_provider) { nil } + let(:connection_service) do double('connection_service', current_connection: connection, @@ -340,6 +343,197 @@ end end + describe 'missing cluster_instance_host_pattern' do + let(:non_rds_host) { AwsAdvancedRubyDriverWrapper::Host::HostInfo.new(host: '10.0.0.12', port: '5432') } + let(:pipeline_callable) { -> { connection } } + let(:pattern_missing) { true } + let(:host_list_provider) { double('rds_host_list_provider', instance_host_pattern_missing?: pattern_missing) } + let(:log_output) { StringIO.new } + let(:original_logger) { AwsAdvancedRubyDriverWrapper.logger } + + before do + allow(connection_service).to receive(:initial_host_info).and_return(non_rds_host) + described_class::MISSING_PATTERN_WARNED_HOSTS.clear + original_logger + # A logger at the default level, so the test also shows the warning is visible without debug logging. + AwsAdvancedRubyDriverWrapper.logger = Logger.new(log_output, level: Logger::INFO) + end + + after do + AwsAdvancedRubyDriverWrapper.logger = original_logger + described_class::MISSING_PATTERN_WARNED_HOSTS.clear + end + + context 'when failover is listed explicitly in wrapper_plugins' do + before { props[:wrapper_plugins] = 'failover,initial_connection' } + + it 'returns the connection and logs a warning naming the host and both fixes' do + expect(plugin.connect(non_rds_host, props, true, pipeline_callable)).to eq(connection) + expect(log_output.string).to include('WARN') + expect(log_output.string).to include("'10.0.0.12' is not a recognized RDS endpoint") + expect(log_output.string).to include('Failover will fail with FailoverFailedError') + expect(log_output.string).to include('Set cluster_instance_host_pattern') + expect(log_output.string).to include('?.XXX.us-east-1.rds.amazonaws.com') + expect(log_output.string).to include('remove failover from wrapper_plugins') + end + + it 'keeps the initial connection open' do + expect(driver_dialect).not_to receive(:close_connection) + plugin.connect(non_rds_host, props, true, pipeline_callable) + end + + it 'does not check connections other than the initial one' do + expect(plugin.connect(non_rds_host, props, false, pipeline_callable)).to eq(connection) + expect(log_output.string).to be_empty + end + + context 'when the dialect is not a cluster dialect' do + # Single RDS instances and community databases use a host list provider without instance templates. + let(:host_list_provider) { double('connection_string_host_list_provider') } + + it 'returns the connection without logging a warning' do + expect(plugin.connect(non_rds_host, props, true, pipeline_callable)).to eq(connection) + expect(log_output.string).to be_empty + end + end + + context 'when the host is a recognized RDS endpoint or cluster_instance_host_pattern is set' do + let(:pattern_missing) { false } + + it 'returns the connection without logging a warning' do + expect(plugin.connect(non_rds_host, props, true, pipeline_callable)).to eq(connection) + expect(log_output.string).to be_empty + end + end + end + + context 'when failover comes from the default plugin list' do + it 'returns the connection and logs a warning naming the host and both fixes' do + expect(plugin.connect(non_rds_host, props, true, pipeline_callable)).to eq(connection) + expect(log_output.string).to include('WARN') + expect(log_output.string).to include("'10.0.0.12' is not a recognized RDS endpoint") + expect(log_output.string).to include('Set cluster_instance_host_pattern') + expect(log_output.string).to include('set wrapper_plugins to a list without failover') + end + + it 'logs the warning again after the caches are cleared' do + plugin.connect(non_rds_host, props, true, pipeline_callable) + AwsAdvancedRubyDriverWrapper.clear_caches + described_class.new(service_container, props).connect(non_rds_host, props, true, pipeline_callable) + + expect(log_output.string.scan('is not a recognized RDS endpoint').size).to eq(2) + end + + it 'logs the warning once per host' do + plugin.connect(non_rds_host, props, true, pipeline_callable) + described_class.new(service_container, props).connect(non_rds_host, props, true, pipeline_callable) + + expect(log_output.string.scan('is not a recognized RDS endpoint').size).to eq(1) + end + + context 'when the host is a recognized RDS endpoint or cluster_instance_host_pattern is set' do + let(:pattern_missing) { false } + + it 'does not log a warning' do + plugin.connect(non_rds_host, props, true, pipeline_callable) + expect(log_output.string).to be_empty + end + end + end + + describe 'during failover' do + before do + plugin.connect(non_rds_host, props, true, pipeline_callable) + allow(host_service).to receive(:force_refresh_host_list?).and_return(true) + end + + it 'fails writer failover immediately, without discovering the topology or connecting' do + expect(host_service).not_to receive(:force_refresh_host_list?) + expect(retry_util).not_to receive(:connect_to_writer) + + expect { plugin.send(:failover) } + .to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverFailedError) { |error| + expect(error.message).to start_with('Failover is not possible. ') + expect(error.message).to include("'10.0.0.12' is not a recognized RDS endpoint and cluster_instance_host_pattern is not set") + expect(error.message).to include('Set cluster_instance_host_pattern') + expect(error.message).to include('set wrapper_plugins to a list without failover') + } + end + + it 'fails reader failover immediately' do + plugin.instance_variable_set(:@failover_mode, failover_mode::READER_OR_WRITER) + expect(host_service).not_to receive(:force_refresh_host_list?) + expect(plugin_manager).not_to receive(:connect) + + expect { plugin.send(:failover) } + .to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverFailedError, /cluster_instance_host_pattern is not set/) + end + + it 'counts the attempt as a failed failover' do + counters = described_class::FailoverCounters.new( + triggered: double('triggered', inc: nil), succeeded: double('succeeded', inc: nil), failed: double('failed', inc: nil) + ) + plugin.instance_variable_set(:@writer_failover_counters, counters) + expect(counters.failed).to receive(:inc) + + expect { plugin.send(:failover) }.to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverFailedError) + end + + context 'when a network error interrupts a call' do + let(:network_error) { StandardError.new('connection reset') } + + before do + allow(dialect_service).to receive(:network_error?).with(network_error).and_return(true) + allow(session_state_service).to receive(:in_transaction?).and_return(true) + end + + it 'rolls back the open transaction and raises FailoverFailedError caused by the original error' do + expect(driver_dialect).to receive(:execute).with(connection, 'ROLLBACK') + expect(host_service).not_to receive(:force_refresh_host_list?) + + expect { plugin.execute('connection.exec', -> { raise network_error }) } + .to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverFailedError) { |error| + expect(error.message).to include('cluster_instance_host_pattern is not set') + expect(error.cause).to eq(network_error) + } + end + + it 're-raises the original error when the connection was closed explicitly' do + plugin.execute(AwsAdvancedRubyDriverWrapper::RubyMethod::CONNECTION_CLOSE.name, -> {}) + + expect { plugin.execute('connection.exec', -> { raise network_error }) }.to raise_error(network_error) + end + end + + it 'raises FailoverFailedError when a call finds the connection closed' do + allow(driver_dialect).to receive(:closed?).and_return(true) + + expect { plugin.execute('connection.exec', -> { :result }) } + .to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverFailedError, /cluster_instance_host_pattern is not set/) + end + + it 'raises FailoverFailedError when a connect is failed over with enable_connect_failover' do + props[:enable_connect_failover] = true + network_error = StandardError.new('connection refused') + allow(dialect_service).to receive(:network_error?).with(network_error).and_return(true) + + expect { plugin.connect(non_rds_host, props, false, -> { raise network_error }) } + .to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverFailedError, /cluster_instance_host_pattern is not set/) + end + + context 'when the instance host pattern is not missing' do + let(:pattern_missing) { false } + + it 'fails over as usual' do + writer_result = AwsAdvancedRubyDriverWrapper::Utils::RetryUtil::Result.new(new_connection, writer_host) + allow(retry_util).to receive(:connect_to_writer).and_return(writer_result) + + expect { plugin.send(:failover) }.to raise_error(AwsAdvancedRubyDriverWrapper::Errors::FailoverSuccessError) + end + end + end + end + describe 'verified_connection (stale DNS)' do let(:pipeline_callable) { -> { connection } } diff --git a/spec/unit/host/global_aurora_host_list_provider_spec.rb b/spec/unit/host/global_aurora_host_list_provider_spec.rb index 56675a54..5279ea84 100644 --- a/spec/unit/host/global_aurora_host_list_provider_spec.rb +++ b/spec/unit/host/global_aurora_host_list_provider_spec.rb @@ -134,6 +134,18 @@ end end + describe '#instance_host_pattern_missing?' do + context 'when connecting with a custom domain and no cluster_instance_host_pattern' do + let(:initial_host_info) { AwsAdvancedRubyDriverWrapper::Host::HostInfo.new(host: 'db.example.com', port: 5432) } + let(:wrapper_props) { { global_cluster_instance_host_patterns: instance_templates_str } } + + it 'is false because instance hosts come from global_cluster_instance_host_patterns' do + expect(provider.instance_template.host).to eq('?') + expect(provider.instance_host_pattern_missing?).to be(false) + end + end + end + describe '#force_refresh' do it 'returns nil on timeout' do result = provider.force_refresh(false, 0.1) diff --git a/spec/unit/host/rds_host_list_provider_spec.rb b/spec/unit/host/rds_host_list_provider_spec.rb index 70d683db..490208b5 100644 --- a/spec/unit/host/rds_host_list_provider_spec.rb +++ b/spec/unit/host/rds_host_list_provider_spec.rb @@ -157,6 +157,48 @@ end end + describe '#instance_host_pattern_missing?' do + it 'is false for a recognized RDS endpoint' do + expect(provider.instance_host_pattern_missing?).to be(false) + end + + context 'when connecting with an IP address and no cluster_instance_host_pattern' do + let(:initial_host_info) { AwsAdvancedRubyDriverWrapper::Host::HostInfo.new(host: '10.0.0.12', port: 5432) } + + it 'is true' do + expect(provider.instance_template.host).to eq('?') + expect(provider.instance_host_pattern_missing?).to be(true) + end + end + + context 'when connecting with a custom domain and no cluster_instance_host_pattern' do + let(:initial_host_info) { AwsAdvancedRubyDriverWrapper::Host::HostInfo.new(host: 'db.example.com', port: 5432) } + + it 'is true' do + expect(provider.instance_host_pattern_missing?).to be(true) + end + end + + context 'when connecting with an IP address and cluster_instance_host_pattern explicitly set to ?' do + # Bare instance identifiers may resolve in the user's environment, e.g. through a DNS search domain. + let(:initial_host_info) { AwsAdvancedRubyDriverWrapper::Host::HostInfo.new(host: '10.0.0.12', port: 5432) } + let(:wrapper_props) { { cluster_instance_host_pattern: '?' } } + + it 'is false' do + expect(provider.instance_host_pattern_missing?).to be(false) + end + end + + context 'when connecting with a custom domain and cluster_instance_host_pattern set' do + let(:initial_host_info) { AwsAdvancedRubyDriverWrapper::Host::HostInfo.new(host: 'db.example.com', port: 5432) } + let(:wrapper_props) { { cluster_instance_host_pattern: '?.abc123.us-east-2.rds.amazonaws.com' } } + + it 'is false' do + expect(provider.instance_host_pattern_missing?).to be(false) + end + end + end + describe '#refresh' do context 'when topology is cached' do let(:cached_topology) do diff --git a/spec/unit/plugins/gdb/gdb_failover_plugin_spec.rb b/spec/unit/plugins/gdb/gdb_failover_plugin_spec.rb index fa49720f..b4b93bce 100644 --- a/spec/unit/plugins/gdb/gdb_failover_plugin_spec.rb +++ b/spec/unit/plugins/gdb/gdb_failover_plugin_spec.rb @@ -74,9 +74,12 @@ def host_info(host, role) hosts: topology, refresh_host_list: nil, force_refresh_host_list?: true, - set_availability: nil) + set_availability: nil, + host_list_provider: host_list_provider) end + let(:host_list_provider) { nil } + let(:initial_host) { home_writer } let(:connection_service) do @@ -117,6 +120,79 @@ def init plugin.send(:init_failover_mode) end + describe 'missing instance host pattern' do + let(:initial_host) { host_info('10.0.0.12', host_role::WRITER) } + let(:pattern_missing) { true } + let(:host_list_provider) { double('host_list_provider', instance_host_pattern_missing?: pattern_missing) } + let(:log_output) { StringIO.new } + let(:original_logger) { AwsAdvancedRubyDriverWrapper.logger } + + before do + props[:wrapper_plugins] = 'gdb_failover' + props[:failover_home_region] = 'us-east-1' + allow(driver_dialect).to receive(:database_engine).and_return(:postgresql) + described_class::MISSING_PATTERN_WARNED_HOSTS.clear + original_logger + AwsAdvancedRubyDriverWrapper.logger = Logger.new(log_output, level: Logger::INFO) + end + + after do + AwsAdvancedRubyDriverWrapper.logger = original_logger + described_class::MISSING_PATTERN_WARNED_HOSTS.clear + end + + context 'when the database was identified as a regional cluster' do + it 'returns the connection and warns that global_cluster_instance_host_patterns does not apply, and how to fix it' do + expect(plugin.connect(initial_host, props, true, -> { connection })).to eq(connection) + + message = log_output.string + expect(message).to include('WARN') + expect(message).to include("'10.0.0.12' is not a recognized RDS endpoint and cluster_instance_host_pattern is not set") + expect(message).to include('regional cluster rather than an Aurora Global Database') + expect(message).to include('global_cluster_instance_host_patterns does not apply') + expect(message).to include('Failover will fail with FailoverFailedError') + expect(message).to include("set wrapper_dialect to 'global-aurora-pg'") + expect(message).to include('only detected when it spans more than one region') + expect(message).to include('and set global_cluster_instance_host_patterns.') + expect(message).to include('use the failover plugin instead, and set cluster_instance_host_pattern') + end + end + + context 'when the driver is a MySQL driver' do + before { allow(driver_dialect).to receive(:database_engine).and_return(:mysql) } + + it 'names the MySQL Global Database dialect' do + plugin.connect(initial_host, props, true, -> { connection }) + expect(log_output.string).to include("set wrapper_dialect to 'global-aurora-mysql'") + end + end + + context 'when the database was identified as a Global Database' do + # GlobalAuroraHostListProvider builds instance hosts from global_cluster_instance_host_patterns. + let(:pattern_missing) { false } + + it 'returns the connection without logging a warning' do + expect(plugin.connect(initial_host, props, true, -> { connection })).to eq(connection) + expect(log_output.string).to be_empty + end + end + + context 'during failover' do + before { plugin.connect(initial_host, props, true, -> { connection }) } + + it 'fails immediately, without discovering the topology' do + expect(host_service).not_to receive(:force_refresh_host_list?) + + expect { plugin.send(:failover) } + .to raise_error(errors::FailoverFailedError) { |error| + expect(error.message).to start_with('Failover is not possible. ') + expect(error.message).to include('global_cluster_instance_host_patterns does not apply') + expect(error.message).to include("set wrapper_dialect to 'global-aurora-pg'") + } + end + end + end + describe 'mode initialization' do it 'derives the home region from a region-bearing initial endpoint' do init