A node that joins a cluster receives the inviter's synced settings and entities within one heartbeat #333

Closed
opened 2026-11-05 20:48:51 -05:00 by claude · 2 comments
Owner

Part of epic #59.

  • Kind: feature
  • Area: dns
  • Priority: medium
  • Milestone: Post-release fixes
  • Agent: coder
  • Depends on: #330, #331, #332
  • Decisions: Q-CL-1, Q-CL-2, Q-CL-5 (#260)

Why

Cluster sync pushes changes only as they happen, so a late joiner holds nothing until each item is written again (ClusterConfigSyncBroadcaster.cs:21-27).

What changes

  • ClusterConfigBackfillRunner runs the pass described in design §2.
  • HandleJoinCompleteAsync records the request for a new peer.
  • The heartbeat starts the pass after a successful probe.
  • The broadcaster gains SendToPeerAsync.
  • No API change.

Acceptance

  • Red first: Backfill_AfterNodeBJoinsNodeA_GivesNodeBEverySyncedSettingAndEntityOfNodeA fails while the pass sends nothing, then passes. The same holds for the other five ClusterJoinBackfillTests in src/dotnet/tests/Ninlil.Web.Tests.
  • The twelve Cluster.Tests listed in design 59-4 pass. dotnet test src/dotnet/tests/Ninlil.Dns.Server.Cluster.Tests, dotnet test src/dotnet/tests/Ninlil.Dns.Server.ClusterSync.Tests and dotnet test src/dotnet/tests/Ninlil.Web.Tests pass, and OpenApiSnapshotTests passes with no snapshot change.
  • Every item in Before you finish that applies is done.

Source

ClusterJoinService.cs:227-311, ClusterHeartbeatBackgroundService.cs:99-193, ClusterChannelController.cs:115-153, ClusterTsigAuthenticationHandler.cs:88-121, bughunt-plan.md:524.

Work package detail

  • Goal: a node that joins gets the inviter's full synced state within one heartbeat interval.
  • Files:
    • Ninlil.Dns.Server.Cluster/Backfill/IClusterConfigBackfillRunner.cs and ClusterConfigBackfillRunner.cs (singleton):
      • bool TryStart(Guid clusterNodeId) returns false while a pass to that peer runs.
      • The pass resolves IEnumerable<IClusterConfigSyncSource> in a new scope, groups by BackfillStage, sends each stage with at most 4 deliveries in flight (SemaphoreSlim), and records completion or failure as in §2. It logs one Information line at start and at the end (item count, skipped count), or a Warning with the first error.
    • Channel/ClusterConfigSyncBroadcaster.cs: add public Task<bool> SendToPeerAsync(ClusterNodeEntity peer, ClusterConfigSyncEnvelope envelope, CancellationToken), refactored from DeliverToOneAsync (:92-141). It returns true on 2xx.
    • Join/ClusterJoinService.cs: in HandleJoinCompleteAsync, for a new peer only (:280-308), add a ClusterPeerConfigBackfillEntity in the same save. JoinAsync adds none (OD-1 = a).
    • Heartbeat/ClusterHeartbeatBackgroundService.cs: ProbeOneAsync reports success. After the round's save (:135), call TryStart for each peer whose probe succeeded and is in ListPendingClusterNodeIdsAsync.
    • Http/ClusterPeerHttpClientFactory.cs: make CreateClient virtual as a test seam, with a comment saying why.
    • Register the runner in Extension/ServiceCollectionClusterExtension.cs.
    • Update the summaries: broadcaster :15-28 (the limitation now names the join backfill), join service, heartbeat.
  • Acceptance:
    • Red (src/dotnet/tests/Ninlil.Web.Tests, new hostless ClusterJoinBackfillTests: nodes A and B each have their own SQLite database, settings file and EphemeralDataProtectionProvider; a loopback sender hands envelopes to B's real appliers, as ClusterChannelController.ConfigSync does). Write the tests first against a runner whose pass sends nothing, so they fail:
      • Backfill_AfterNodeBJoinsNodeA_GivesNodeBEverySyncedSettingAndEntityOfNodeA. Seed A with a role, a user with TOTP, a local list with entries, a subscribed list, an ACL rule, a global rewrite and a scoped one, a forwarder, writes to all five sections including the RabbitMQ password and the reverse-proxy secret, and one deleted rewrite. Assert that B has every item, has no scoped rewrite, has no subscribed-list entries, holds a tombstone for the deleted rewrite, and holds secrets that B's key ring opens while A's ciphertext never appears in any payload.
      • Backfill_ToANodeThatHoldsANewerCopy_KeepsTheNewerCopy
      • Backfill_RunTwice_LeavesNodeBUnchanged
      • Backfill_ToANodeWithItsOwnBootstrapAdmin_KeepsBothAccountsAndFlagsTheCollision (asserts OD-2 = a)
      • Backfill_ToARejoiningNodeThatHoldsARowNodeADeleted_RemovesTheRow
      • Backfill_InterruptedAfterHalfTheEnvelopes_CompletesOnTheNextPass
    • src/dotnet/tests/Ninlil.Dns.Server.Cluster.Tests:
      • HandleJoinCompleteAsync_ForANewPeer_RecordsABackfillRequest
      • HandleJoinCompleteAsync_ForARepeatedCallback_AddsNoSecondRequest
      • JoinAsync_OnTheJoiningNode_RecordsNoRequestForTheInviter
      • HeartbeatRound_ForAPendingPeerWhoseProbeSucceeds_StartsOneBackfill (stub handler through the CreateClient seam, fake runner)
      • HeartbeatRound_ForAPendingPeerWhoseProbeFails_StartsNone
      • TryStart_WhileAPassToThatPeerRuns_ReturnsFalse
      • Pass_WhenEveryDeliverySucceeds_RemovesTheRequest
      • Pass_WhenADeliveryFails_KeepsTheRequestAndRecordsTheError
      • Pass_WhenARequestArrivesDuringThePass_KeepsTheRequest
      • Pass_SendsEachStageBeforeTheNext
      • Pass_NeverHasMoreThanFourDeliveriesInFlight
      • Pass_ToTwoPeersAtOnce_SendsEachTheFullSet
  • Non-goals: healing missed live deliveries (59-5); relaying between peers; a batch endpoint.
  • Gate:
    • dotnet test src/dotnet/tests/Ninlil.Dns.Server.Cluster.Tests
    • dotnet test src/dotnet/tests/Ninlil.Dns.Server.ClusterSync.Tests
    • dotnet test src/dotnet/tests/Ninlil.Web.Tests (OpenApiSnapshotTests must stay green with no snapshot change)
Part of epic #59. - **Kind:** feature - **Area:** dns - **Priority:** medium - **Milestone:** Post-release fixes - **Agent:** coder - **Depends on:** #330, #331, #332 - **Decisions:** Q-CL-1, Q-CL-2, Q-CL-5 (#260) ### Why Cluster sync pushes changes only as they happen, so a late joiner holds nothing until each item is written again (`ClusterConfigSyncBroadcaster.cs:21-27`). ### What changes - `ClusterConfigBackfillRunner` runs the pass described in design §2. - `HandleJoinCompleteAsync` records the request for a new peer. - The heartbeat starts the pass after a successful probe. - The broadcaster gains `SendToPeerAsync`. - No API change. ### Acceptance - [ ] Red first: `Backfill_AfterNodeBJoinsNodeA_GivesNodeBEverySyncedSettingAndEntityOfNodeA` fails while the pass sends nothing, then passes. The same holds for the other five `ClusterJoinBackfillTests` in `src/dotnet/tests/Ninlil.Web.Tests`. - [ ] The twelve Cluster.Tests listed in design 59-4 pass. `dotnet test src/dotnet/tests/Ninlil.Dns.Server.Cluster.Tests`, `dotnet test src/dotnet/tests/Ninlil.Dns.Server.ClusterSync.Tests` and `dotnet test src/dotnet/tests/Ninlil.Web.Tests` pass, and `OpenApiSnapshotTests` passes with no snapshot change. - [ ] Every item in [Before you finish](https://git.lantea.one/lantea-one/ninlil/src/branch/main/AGENTS.md#before-you-finish) that applies is done. ### Source `ClusterJoinService.cs:227-311`, `ClusterHeartbeatBackgroundService.cs:99-193`, `ClusterChannelController.cs:115-153`, `ClusterTsigAuthenticationHandler.cs:88-121`, `bughunt-plan.md:524`. ### Work package detail - **Goal:** a node that joins gets the inviter's full synced state within one heartbeat interval. - **Files:** - `Ninlil.Dns.Server.Cluster/Backfill/IClusterConfigBackfillRunner.cs` and `ClusterConfigBackfillRunner.cs` (singleton): - `bool TryStart(Guid clusterNodeId)` returns false while a pass to that peer runs. - The pass resolves `IEnumerable<IClusterConfigSyncSource>` in a new scope, groups by `BackfillStage`, sends each stage with at most 4 deliveries in flight (`SemaphoreSlim`), and records completion or failure as in §2. It logs one Information line at start and at the end (item count, skipped count), or a Warning with the first error. - `Channel/ClusterConfigSyncBroadcaster.cs`: add `public Task<bool> SendToPeerAsync(ClusterNodeEntity peer, ClusterConfigSyncEnvelope envelope, CancellationToken)`, refactored from `DeliverToOneAsync` (`:92-141`). It returns true on 2xx. - `Join/ClusterJoinService.cs`: in `HandleJoinCompleteAsync`, for a new peer only (`:280-308`), add a `ClusterPeerConfigBackfillEntity` in the same save. `JoinAsync` adds none (OD-1 = a). - `Heartbeat/ClusterHeartbeatBackgroundService.cs`: `ProbeOneAsync` reports success. After the round's save (`:135`), call `TryStart` for each peer whose probe succeeded and is in `ListPendingClusterNodeIdsAsync`. - `Http/ClusterPeerHttpClientFactory.cs`: make `CreateClient` `virtual` as a test seam, with a comment saying why. - Register the runner in `Extension/ServiceCollectionClusterExtension.cs`. - Update the summaries: broadcaster `:15-28` (the limitation now names the join backfill), join service, heartbeat. - **Acceptance:** - **Red** (`src/dotnet/tests/Ninlil.Web.Tests`, new hostless `ClusterJoinBackfillTests`: nodes A and B each have their own SQLite database, settings file and `EphemeralDataProtectionProvider`; a loopback sender hands envelopes to B's real appliers, as `ClusterChannelController.ConfigSync` does). Write the tests first against a runner whose pass sends nothing, so they fail: - `Backfill_AfterNodeBJoinsNodeA_GivesNodeBEverySyncedSettingAndEntityOfNodeA`. Seed A with a role, a user with TOTP, a local list with entries, a subscribed list, an ACL rule, a global rewrite and a scoped one, a forwarder, writes to all five sections including the RabbitMQ password and the reverse-proxy secret, and one deleted rewrite. Assert that B has every item, has no scoped rewrite, has no subscribed-list entries, holds a tombstone for the deleted rewrite, and holds secrets that B's key ring opens while A's ciphertext never appears in any payload. - `Backfill_ToANodeThatHoldsANewerCopy_KeepsTheNewerCopy` - `Backfill_RunTwice_LeavesNodeBUnchanged` - `Backfill_ToANodeWithItsOwnBootstrapAdmin_KeepsBothAccountsAndFlagsTheCollision` (asserts OD-2 = a) - `Backfill_ToARejoiningNodeThatHoldsARowNodeADeleted_RemovesTheRow` - `Backfill_InterruptedAfterHalfTheEnvelopes_CompletesOnTheNextPass` - `src/dotnet/tests/Ninlil.Dns.Server.Cluster.Tests`: - `HandleJoinCompleteAsync_ForANewPeer_RecordsABackfillRequest` - `HandleJoinCompleteAsync_ForARepeatedCallback_AddsNoSecondRequest` - `JoinAsync_OnTheJoiningNode_RecordsNoRequestForTheInviter` - `HeartbeatRound_ForAPendingPeerWhoseProbeSucceeds_StartsOneBackfill` (stub handler through the `CreateClient` seam, fake runner) - `HeartbeatRound_ForAPendingPeerWhoseProbeFails_StartsNone` - `TryStart_WhileAPassToThatPeerRuns_ReturnsFalse` - `Pass_WhenEveryDeliverySucceeds_RemovesTheRequest` - `Pass_WhenADeliveryFails_KeepsTheRequestAndRecordsTheError` - `Pass_WhenARequestArrivesDuringThePass_KeepsTheRequest` - `Pass_SendsEachStageBeforeTheNext` - `Pass_NeverHasMoreThanFourDeliveriesInFlight` - `Pass_ToTwoPeersAtOnce_SendsEachTheFullSet` - **Non-goals:** healing missed live deliveries (59-5); relaying between peers; a batch endpoint. - **Gate:** - `dotnet test src/dotnet/tests/Ninlil.Dns.Server.Cluster.Tests` - `dotnet test src/dotnet/tests/Ninlil.Dns.Server.ClusterSync.Tests` - `dotnet test src/dotnet/tests/Ninlil.Web.Tests` (`OpenApiSnapshotTests` must stay green with no snapshot change)
Author
Owner

Added from the #330 verification: on MongoDB a backup restore wipes cluster peers explicitly, but the backfill request table is excluded from backups and has no cascade, so requests for wiped peers stay behind (and an older build's peer delete leaves one too). The runner here must ignore and delete a request whose peer row no longer exists, or the restore wipe must clear the request table; pick one and test it on MongoDB.

Added from the #330 verification: on MongoDB a backup restore wipes cluster peers explicitly, but the backfill request table is excluded from backups and has no cascade, so requests for wiped peers stay behind (and an older build's peer delete leaves one too). The runner here must ignore and delete a request whose peer row no longer exists, or the restore wipe must clear the request table; pick one and test it on MongoDB.
Author
Owner

Done on feature/59-cluster-join-backfill (4fb48a7c, b848aa4a, bec7911f, 76cc9121); verified (whole solution with Docker; two-node test red with the send stubbed, green with it). Fix round: atomic conditional delete/update of the request on every engine, runner stops and awaits passes at shutdown, test loopback uses the MVC JSON options. Closes when the epic merges into develop.

Done on `feature/59-cluster-join-backfill` (4fb48a7c, b848aa4a, bec7911f, 76cc9121); verified (whole solution with Docker; two-node test red with the send stubbed, green with it). Fix round: atomic conditional delete/update of the request on every engine, runner stops and awaits passes at shutdown, test loopback uses the MVC JSON options. Closes when the epic merges into develop.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#333
No description provided.