feat: aurora connection tracker plugin#250
Conversation
…er-wrapper into feat/aurora-connection-tracker
…and OpenedConnectionTracker - Wire AuroraConnectionTrackerPluginFactory in ConnectionPluginChainBuilder - Implement AuroraConnectionTrackerPlugin constructor, fields, and SubscribedMethods - Create OpenedConnectionTracker with static tracking map, singleton background pruning task, PruneNullConnections, and ClearCache
…a-provider-wrapper into feat/aurora-connection-tracker
There was a problem hiding this comment.
Pull request overview
This PR implements the Aurora Connection Tracker Plugin for the .NET AWS wrapper. It tracks all opened database connections keyed by RDS instance endpoint and aliases (when no RDS instance endpoint is found) and closes stale connections to the old writer after a cluster failover, preventing applications from accidentally using connections that now point to a reader.
Changes:
- New
AuroraConnectionTrackerPluginandOpenedConnectionTrackerclasses providing connection lifecycle interception and thread-safe tracking - Plugin registration in
ConnectionPluginChainBuilderandPluginCodes - Supporting spec docs (requirements and design) and resource strings for logging
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
AuroraConnectionTrackerPlugin.cs |
Core plugin: intercepts open/execute/close to track connections and detect writer changes |
OpenedConnectionTracker.cs |
Thread-safe tracking map; handles populate, invalidate, remove, and background pruning |
AuroraConnectionTrackerPluginFactory.cs |
Factory that creates plugin instances |
ConnectionPluginChainBuilder.cs |
Registers the new plugin factory and assigns execution weight 400 |
PluginCodes.cs |
Adds the "auroraConnectionTracker" plugin code constant |
Resources.resx |
Adds localized log/error message strings for the tracker |
requirements.md |
Spec requirements document for the feature |
design.md |
Detailed design document including architecture, data models, and testing strategy |
Files not reviewed (1)
- AwsWrapperDataProvider/Properties/Resources.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/AuroraConnectionTrackerPlugin.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Show resolved
Hide resolved
…r786/aws-advanced-dotnet-data-provider-wrapper into feat/aurora-connection-tracker
…er-wrapper into feat/aurora-connection-tracker
…er-wrapper into feat/aurora-connection-tracker
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Outdated
Show resolved
Hide resolved
| try | ||
| { | ||
| string cleanHost = RdsUtils.RemovePort(key); | ||
| if (!RdsUtils.IsRdsInstance(cleanHost)) |
There was a problem hiding this comment.
We should try to see if this host is tracked regardless, in case it is a custom endpoint
There was a problem hiding this comment.
Yes, will be updated as part of tracking custom endpoints change.
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/AuroraConnectionTrackerPlugin.cs
Outdated
Show resolved
Hide resolved
...rDataProvider/Driver/Plugins/AuroraConnectionTracker/AuroraConnectionTrackerPluginFactory.cs
Outdated
Show resolved
Hide resolved
…prove host tracking
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/AuroraConnectionTrackerPlugin.cs
Show resolved
Hide resolved
|
Let's make sure the existing integration test is passing and that we fix the existing linting errors |
…er-wrapper into feat/aurora-connection-tracker
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/AuroraConnectionTrackerPlugin.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/AuroraConnectionTrackerPlugin.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider.Dialect.MySqlClient/MySqlClientDialect.cs
Outdated
Show resolved
Hide resolved
AwsWrapperDataProvider.Dialect.MySqlConnector/MySqlConnectorDialect.cs
Outdated
Show resolved
Hide resolved
...perDataProvider.Tests/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTrackerTests.cs
Outdated
Show resolved
Hide resolved
| /// <param name="connection">The database connection to track.</param> | ||
| public void PopulateOpenedConnectionQueue(HostSpec hostSpec, DbConnection connection) | ||
| { | ||
| EnsurePruneLoopRunning(); |
There was a problem hiding this comment.
Do we need this verification here if we already have it in the constructor?
There was a problem hiding this comment.
This is kept for two potential cases: (1) if the background prune task faults unexpectedly and silently dies, or (2) ReleaseResources() is called but the same tracker instance continues to be used, the constructor won't re-run, so the loop stays dead. This check ensures that every time we track a new connection, we verify the loop is still running and restart it if needed. The cost is negligible- one lock check per connection open.
AwsWrapperDataProvider/Driver/Plugins/AuroraConnectionTracker/OpenedConnectionTracker.cs
Outdated
Show resolved
Hide resolved
| { | ||
| { PluginCodes.ConnectTime, new Lazy<IConnectionPluginFactory>(() => new ConnectTimePluginFactory()) }, | ||
| { PluginCodes.ExecutionTime, new Lazy<IConnectionPluginFactory>(() => new ExecutionTimePluginFactory()) }, | ||
| { PluginCodes.AuroraConnectionTracker, new Lazy<IConnectionPluginFactory>(() => new AuroraConnectionTrackerPluginFactory()) }, |
There was a problem hiding this comment.
I think this particular list follows the alphabetical order
There was a problem hiding this comment.
Not really. But I've updated the sequence to match plugin weights order, same as in PluginWeightByPluginFactoryType.
…lization sequence to match plugin weight
Summary
feat: add aurora connection tracker plugin
Description
Adds the aurora connection tracker plugin. This plugin tracks all the opened connections. In the event of a cluster failover, this plugin will close all the impacted connections. If no plugins are explicitly specified, this plugin is enabled by default.
Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.