A change saved on one instance expires the matching caches on every instance that shares the ValKey server #71

Open
opened 2026-10-31 12:42:01 -04:00 by claude · 0 comments
Owner
  • Draft: INT-3
  • Priority: high (the main reason for ValKey: without it another instance waits for the cache time-to-live, 60 s or 5 min)
  • Agent: coder
  • Depends on: #70, #50
  • Decisions: Q-INT-5

Why

EntityChangeNotifier calls only in-process subscribers (src/dotnet/src/Ninlil.Dns.Data.Abstractions/Repository/EntityChangeNotifier.cs:29-69). Today's subscribers:

  • DnsRewriteCache.cs:81
  • DnsClientScheduleCache.cs:93
  • ForwarderSetCache.cs:87
  • DnsClientDirectory.cs:83
  • DnsFilterConfigurationCache.cs:150,160

The zone cache reloads only on the local DnsZoneChangedEvent (src/dotnet/src/Ninlil.Dns.Server.Authoritative/Cache/ZoneChangedEventSubscriber.cs:12-19). The access-rule cache works the same way (src/dotnet/src/Ninlil.Dns.Server.AccessControl/DnsAccessControlRuleCache.cs:17-22). An instance ignores broker events it did not make (README.md:4199-4204). #50 gives the zone, signed-zone and access-rule caches a 60 s time-to-live first, so every cache then has a bounded delay without ValKey; this issue brings every cache down to about a second when ValKey is configured.

What changes

  • A ValkeyEntityChangeRelay hosted service:
    • It subscribes to the local notifier with an empty type set (meaning every type) and publishes on channel <prefix>:changes.
    • The message is JSON: { v: 1, origin: <DnsServerEventPublisher.InstanceId>, types: [full type names], zoneIds: [...] }. InstanceId is at src/dotnet/src/Ninlil.Dns.Server.Core/Events/DnsServerEventPublisher.cs:90; it is per process, which is what echo suppression needs.
    • Publishing is fire-and-forget off the save thread, because notifier callbacks must only mark state (IEntityChangeNotifier.cs:36-40).
  • On receive, the relay drops messages from its own origin and maps type names through an allow-list built from the entity assemblies; unknown names are ignored, so version skew is safe. It then calls NotifyChanged on a path that is not published again. Suggested shape: an internal NotifyChangedFromRemote on EntityChangeNotifier, or a flag carried through.
  • Zone ids: the relay also subscribes to DnsZoneChangedEvent and publishes the zone id. A receiver calls AuthoritativeZoneCache.ReloadZoneAsync (and SignedZoneCache.ReloadZoneAsync, the pair #50's backstop uses).
  • Access rules: a remote signal for DnsAccessControlRuleEntity reloads DnsAccessControlRuleCache.
  • Filter-list entries: a remote DnsFilterListEntryEntity signal goes through the existing "expire all entry caches" path (DnsFilterConfigurationCache.cs:160).
  • On reconnect after a gap (#70 event), expire every subscribed cache once, because messages may have been missed.
  • Every cache keeps its time-to-live as a backstop, the zone and access-rule caches included (#50).
  • Files:
    • src/dotnet/src/Ninlil.Common.Valkey/ (relay)
    • src/dotnet/src/Ninlil.Dns.Data.Abstractions/Repository/EntityChangeNotifier.cs
    • src/dotnet/src/Ninlil.Dns.Server.Authoritative/Cache/
    • src/dotnet/src/Ninlil.Dns.Server.AccessControl/
    • the DI wiring in Program.cs

Acceptance

  • Test (fails first): two NinlilDnsWebApplicationFactory hosts on one SQLite file plus one ValKey container. Add a rewrite through host A's API; host B answers the rewritten name within 2 s (RequiresDocker; use factory.CreateSecondHost).
  • The same two-host test passes for a new zone record and for an access rule, each within 2 s (well under #50's 60 s backstop).
  • Unit test: a message with this instance's origin, or an unknown type name, changes nothing.
  • Unit test: after a simulated reconnect, every subscribed snapshot is expired.
  • dotnet test src/dotnet/tests/Ninlil.Common.Valkey.Tests passes.
  • src/dotnet/tests/Ninlil.Dns.Server.Authoritative.Tests and src/dotnet/tests/Ninlil.Web.Tests pass.
  • The whole solution passes (shared libraries changed).
  • README storage and cluster text names the new bound.

Source

  • b11-12-design.md §2.8 and §2.9.
  • README.md:5090-5098.
  • Owner scope (2026-10-09).
  • Owner decision 2026-10-31 (Q-INT-5): "60 s TTL backstop now, as a post-release-fixes issue" — the backstop is #50, which this issue depends on (DEDUPE.md I1).
- **Draft:** INT-3 - **Priority:** high (the main reason for ValKey: without it another instance waits for the cache time-to-live, 60 s or 5 min) - **Agent:** coder - **Depends on:** #70, #50 - **Decisions:** Q-INT-5 ### Why `EntityChangeNotifier` calls only in-process subscribers (`src/dotnet/src/Ninlil.Dns.Data.Abstractions/Repository/EntityChangeNotifier.cs:29-69`). Today's subscribers: - `DnsRewriteCache.cs:81` - `DnsClientScheduleCache.cs:93` - `ForwarderSetCache.cs:87` - `DnsClientDirectory.cs:83` - `DnsFilterConfigurationCache.cs:150,160` The zone cache reloads only on the local `DnsZoneChangedEvent` (`src/dotnet/src/Ninlil.Dns.Server.Authoritative/Cache/ZoneChangedEventSubscriber.cs:12-19`). The access-rule cache works the same way (`src/dotnet/src/Ninlil.Dns.Server.AccessControl/DnsAccessControlRuleCache.cs:17-22`). An instance ignores broker events it did not make (README.md:4199-4204). #50 gives the zone, signed-zone and access-rule caches a 60 s time-to-live first, so every cache then has a bounded delay without ValKey; this issue brings every cache down to about a second when ValKey is configured. ### What changes - A `ValkeyEntityChangeRelay` hosted service: - It subscribes to the local notifier with an empty type set (meaning every type) and publishes on channel `<prefix>:changes`. - The message is JSON: `{ v: 1, origin: <DnsServerEventPublisher.InstanceId>, types: [full type names], zoneIds: [...] }`. `InstanceId` is at `src/dotnet/src/Ninlil.Dns.Server.Core/Events/DnsServerEventPublisher.cs:90`; it is per process, which is what echo suppression needs. - Publishing is fire-and-forget off the save thread, because notifier callbacks must only mark state (`IEntityChangeNotifier.cs:36-40`). - On receive, the relay drops messages from its own origin and maps type names through an allow-list built from the entity assemblies; unknown names are ignored, so version skew is safe. It then calls `NotifyChanged` on a path that is not published again. Suggested shape: an internal `NotifyChangedFromRemote` on `EntityChangeNotifier`, or a flag carried through. - Zone ids: the relay also subscribes to `DnsZoneChangedEvent` and publishes the zone id. A receiver calls `AuthoritativeZoneCache.ReloadZoneAsync` (and `SignedZoneCache.ReloadZoneAsync`, the pair #50's backstop uses). - Access rules: a remote signal for `DnsAccessControlRuleEntity` reloads `DnsAccessControlRuleCache`. - Filter-list entries: a remote `DnsFilterListEntryEntity` signal goes through the existing "expire all entry caches" path (`DnsFilterConfigurationCache.cs:160`). - On reconnect after a gap (#70 event), expire every subscribed cache once, because messages may have been missed. - Every cache keeps its time-to-live as a backstop, the zone and access-rule caches included (#50). - Files: - `src/dotnet/src/Ninlil.Common.Valkey/` (relay) - `src/dotnet/src/Ninlil.Dns.Data.Abstractions/Repository/EntityChangeNotifier.cs` - `src/dotnet/src/Ninlil.Dns.Server.Authoritative/Cache/` - `src/dotnet/src/Ninlil.Dns.Server.AccessControl/` - the DI wiring in `Program.cs` ### Acceptance - [ ] Test (fails first): two `NinlilDnsWebApplicationFactory` hosts on one SQLite file plus one ValKey container. Add a rewrite through host A's API; host B answers the rewritten name within 2 s (RequiresDocker; use `factory.CreateSecondHost`). - [ ] The same two-host test passes for a new zone record and for an access rule, each within 2 s (well under #50's 60 s backstop). - [ ] Unit test: a message with this instance's origin, or an unknown type name, changes nothing. - [ ] Unit test: after a simulated reconnect, every subscribed snapshot is expired. - [ ] `dotnet test src/dotnet/tests/Ninlil.Common.Valkey.Tests` passes. - [ ] `src/dotnet/tests/Ninlil.Dns.Server.Authoritative.Tests` and `src/dotnet/tests/Ninlil.Web.Tests` pass. - [ ] The whole solution passes (shared libraries changed). - [ ] README storage and cluster text names the new bound. ### Source - `b11-12-design.md` §2.8 and §2.9. - README.md:5090-5098. - Owner scope (2026-10-09). - Owner decision 2026-10-31 (Q-INT-5): "60 s TTL backstop now, as a post-release-fixes issue" — the backstop is #50, which this issue depends on (DEDUPE.md I1).
claude added this to the Release: ValKey milestone 2026-10-31 12:42:01 -04:00
Sign in to join this conversation.
No milestone
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#71
No description provided.