Files

4.1 KiB
Raw Permalink Blame History

S-DISCOVERY-01..04 — Discovery Subsystem (Catalog, Leases, Watches, Selectors, Optional RPC Adapter)

Scope

Implement the P1–P3 native Void::Discovery subsystem per docs/roadmap/subsystems/Discovery.md and docs/roadmap/DEPENDENCIES.md, plus the optional Void::DiscoveryRpc endpoint adapter living strictly above RPC and Discovery:

  1. S-DISCOVERY-01 — Boundary, Error Domain, and Immutable Value Contracts:
    • Module src/Discovery/module.cmake (INTERNAL_DEPS Core Functional Time Async) with zero network, storage, or consensus dependencies.
    • Error domain kDiscoveryErrorDomain = 30 with DiscoveryErrorCode covering validation, conflict, cap exhaustion, expiry, stale/unavailable freshness, cancellation, and self-join diagnosis.
    • Strict endpoint/attribute validation before publication (valid scheme/host/port, weight > 0, max_attributes_per_record = 16, max_metadata_bytes_per_record = 4096, max_services = 1024, max_endpoints_per_service = 256, max_total_records = 10000).
  2. S-DISCOVERY-02 — Pure Catalog, Atomic Static Snapshots, and Local RAII Registrations:
    • Pure Catalog construction creating zero hidden threads.
    • Atomic candidate replace_static() rejecting invalid/conflicting candidates while preserving the active revision; explicit provider_generation bump resets revision domain and emits ResyncRequired.
    • Local move-only RAII Registration handles with explicit LeasePolicy (default 30s TTL / 10s renew interval via injected MonotonicClock; zero TTL rejected as InvalidArgument; unleased explicit mode valid until release; static entries never expire).
    • Duplicate (service, instance) returns Conflict without stealing existing handles.
    • Deterministic resolve() sorted by instance, filtering logically expired records before cleanup runs, respecting ResolvePolicy::allow_stale and Freshness.
  3. S-DISCOVERY-03 — Bounded Watches, Resync, Client Selectors, and Managed Renewal:
    • Bounded watch() (max_watches = 1024, max_events_per_watch = 64, shared 16 MiB event budget) emitting InitialSnapshot, serialized per-watch Delta, and explicit ResyncRequired + full latest Snapshot on overflow or provider-generation reset.
    • Callbacks run outside catalog and watch locks; cancel() stops new admission (including self-cancel inside a callback); join() drains admitted callbacks and diagnoses synchronous self-join (SelfJoin) instead of deadlocking.
    • Catalog::shutdown_and_join() removes local entries, cancels watches, and joins admitted callbacks; destructor only requests stop.
    • WeightedRoundRobinSelector, stable HRW AffinitySelector, and deterministic ManagedLeaseRenewer.
  4. S-DISCOVERY-04 — Optional RPC Integration (DiscoveryRpc):
    • Separate module src/DiscoveryRpc/module.cmake (INTERNAL_DEPS Discovery RPC) so RPC remains completely independent of Discovery.
    • EndpointResolverClient resolves endpoints from Discovery::Catalog, selects via client selector, preserves configured expected_tls_name / identity across IP/address refreshes (rejecting TLS scheme/identity downgrade), and executes unary calls via Void::RPC::Client.

File Ownership

  • include/Void/Discovery/{Types,Catalog}.hpp
  • src/Discovery/{module.cmake,Catalog.cpp}
  • include/Void/DiscoveryRpc/EndpointAdapter.hpp
  • src/DiscoveryRpc/{module.cmake,EndpointAdapter.cpp}
  • tests/standalone/Discovery/Catalog.cpp
  • tests/standalone/DiscoveryRpc/EndpointAdapter.cpp
  • tests/package/DiscoveryOnly/{CMakeLists.txt,main.cpp}
  • tests/package/InstalledComponents.cmake

Acceptance & Verification

  • Standalone Discovery;Testing (-DVOID_WARNINGS_AS_ERRORS=ON) + DiscoveryOnly consumer with _no_external_deps.
  • DiscoveryRpc identity-preserving refresh + RPC round-trip tests; RpcOnly remains Discovery-free.
  • Deterministic fake-clock lease expiry/renewal, atomic bad/good config replacement, duplicate registration conflict, watch overflow -> ResyncRequired, self-cancel/self-join, and selector determinism.
  • Full RelWithDebInfo, Debug ASan+UBSan, and Debug TSan with 0 leaks, 0 UB, 0 races.