refactor(localdb): one replication predicate shared by table registration and the alarm drain gate (#603)

The drain gate counted SyncListenPort; a port with no ApiKey shares nothing (fail-closed
passive endpoint), and an ApiKey-only passive node shares its queue but was never gated.

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-08 06:56:00 -04:00
parent 1b37b2f2b0
commit 4f6231fa40
6 changed files with 94 additions and 18 deletions
@@ -177,12 +177,11 @@ public static class ServiceCollectionExtensions
// possibly deliver its events. Scoping the gate to "is my queue actually shared?" is what
// keeps the two scopes from disagreeing.
// BOTH halves of a pair share the queue, but only one of them dials: the initiator sets
// Replication:PeerAddress, its partner only sets SyncListenPort and waits. Testing the dial
// side alone would leave the listening half permanently ungated — one drainer per pair by
// accident rather than by role, and the wrong one whenever the roles swap.
var replicated =
!string.IsNullOrWhiteSpace(configuration["LocalDb:Replication:PeerAddress"])
|| !string.IsNullOrWhiteSpace(configuration["LocalDb:SyncListenPort"]);
// Replication:PeerAddress, its partner carries the shared ApiKey and waits. The predicate is
// LocalDbReplicationPolicy - the same one LocalDbSetup uses to decide which nodes capture
// changes at all. It deliberately does NOT count SyncListenPort: the passive endpoint is
// fail-closed on the key, so a port with no ApiKey shares nothing and must keep draining.
var replicated = LocalDbReplicationPolicy.IsConfigured(configuration);
if (!replicated)
{