fix(localdb): adapter review fixes — deterministic pump teardown, always-hosted initiator, backoff clamp

Claude-Session: https://claude.ai/code/session_01BL2Vu1ESDQ9SCN4gVKkdts
This commit is contained in:
Joseph Doherty
2026-07-17 23:13:02 -04:00
parent a64fc26391
commit e92cdc6d3a
6 changed files with 148 additions and 28 deletions
@@ -14,10 +14,10 @@ public static class ReplicationServiceCollectionExtensions
/// Binds and validates <see cref="ReplicationOptions"/> from the <c>"LocalDb:Replication"</c>
/// configuration section, registers the passive <see cref="LocalDbSyncService"/> as a singleton
/// (its single-stream guard must span calls), and registers the initiating
/// <see cref="SyncBackgroundService"/> as a hosted service ONLY when a peer address is configured
/// (a passive node leaves it empty and never dials). Idempotent. Requires
/// <see cref="LocalDbServiceCollectionExtensions.AddZbLocalDb"/> to have been called for the
/// <see cref="ILocalDb"/> the adapters depend on.
/// <see cref="SyncBackgroundService"/> as a hosted service — on a passive node (no
/// <see cref="ReplicationOptions.PeerAddress"/>) it starts and immediately idles. Idempotent.
/// Requires <see cref="LocalDbServiceCollectionExtensions.AddZbLocalDb"/> to have been called
/// for the <see cref="ILocalDb"/> the adapters depend on.
/// </summary>
public static IServiceCollection AddZbLocalDbReplication(
this IServiceCollection services, IConfiguration configuration)
@@ -33,11 +33,7 @@ public static class ReplicationServiceCollectionExtensions
ServiceDescriptor.Singleton<IValidateOptions<ReplicationOptions>, ReplicationOptionsValidator>());
services.AddSingleton<LocalDbSyncService>();
// Read the section directly (before options are built) to decide whether this node initiates.
var peerAddress = configuration.GetSection("LocalDb:Replication")["PeerAddress"];
if (!string.IsNullOrEmpty(peerAddress))
services.AddHostedService<SyncBackgroundService>();
services.AddHostedService<SyncBackgroundService>();
return services;
}