122 lines
8.1 KiB
Markdown
122 lines
8.1 KiB
Markdown
# Discovery subsystem plan — NEW
|
||
|
||
Status: NEW design; all feature tasks PLANNED. Source baseline
|
||
`f1f9ba375b22abf1adcc7c550ec21ac20895c0a4`, inspected 2026-11-24.
|
||
Authority: [requirements](../REQUIREMENTS.md) R-003, R-009, R-011, R-014–R-016;
|
||
[architecture](../ARCHITECTURE.md) C-01–C-05, C-11–C-13.
|
||
|
||
## Baseline and dependency direction
|
||
|
||
No Discovery source/target exists in the assigned baseline. Existing
|
||
[Net Url](../../../include/Void/Net/Url.hpp) provides endpoint parsing, not a membership,
|
||
health or service-discovery protocol; source/graph coverage matched with no recorded issue.
|
||
NEW paths are `include/Void/Discovery`, `src/Discovery` and `tests/standalone/Discovery`.
|
||
Begin with a static immutable endpoint catalog and local in-process registrations.
|
||
Do not require DNS multicast, an external agent, RPC or consensus to discover initial peers.
|
||
|
||
Discovery owns endpoint sets, revisioned snapshots, local registration lifetime and watch
|
||
semantics. [RPC](RPC.md) accepts injected endpoints; its optional Discovery integration
|
||
lives above RPC. [Coordination](Coordination.md) imports no Discovery. A later replicated
|
||
directory adapter belongs in the Replication/platform integration layer and uses separately
|
||
configured bootstrap peers. Discovered leader hints never redefine Raft membership.
|
||
|
||
## NEW native contract and algorithm
|
||
|
||
```cpp
|
||
// NEW illustrative Void::Discovery shapes.
|
||
struct EndpointRecord {
|
||
InstanceId instance; ServiceId service; Endpoint endpoint;
|
||
std::uint32_t weight; Attributes attributes;
|
||
};
|
||
struct Snapshot { Revision revision; std::vector<EndpointRecord> records; Freshness freshness; };
|
||
class Catalog {
|
||
Result<Snapshot> resolve(ServiceId, ResolvePolicy) const;
|
||
Result<Registration> register_local(EndpointRecord, LeasePolicy);
|
||
Result<Watch> watch(ServiceId, Revision after, WatchCallback);
|
||
};
|
||
```
|
||
|
||
Names above are NEW domain types; Endpoint follows Net's endpoint owner, operation options
|
||
remain Async-owned. Catalog construction is pure and creates no thread. Static configuration
|
||
is validated as a complete snapshot then atomically published; duplicate service+instance
|
||
identities, invalid authorities and unsupported metadata cause rejection of the entire
|
||
candidate, preserving the active revision. Revisions are local monotonic values with a
|
||
provider generation; they are not cluster-wide consensus indices.
|
||
|
||
Local registrations return move-only RAII handles retaining catalog state. Release removes
|
||
future snapshots. Leased registration is explicit, default 30-second TTL and renewal every
|
||
10 seconds in an optional managed adapter, measured by injected steady time. Static entries
|
||
never expire. A registration handle without a lease is valid until explicit release; zero
|
||
TTL is invalid rather than an undocumented permanent registration. Local process shutdown
|
||
removes local entries and joins admitted callbacks; destruction alone only requests stop.
|
||
|
||
Resolution snapshots immutable owned values, sorts by instance identity for deterministic
|
||
tests and excludes expired/unready entries by default. Optional stale resolution explicitly
|
||
returns freshness/provider error. Failure detection changes availability hints only; it
|
||
cannot certify uniqueness, leadership or permission. Weighted round-robin selection is an
|
||
optional client-side selector over a snapshot; affinity selection uses stable hashing
|
||
only when requested. Address refresh retains the peer's configured identity, so DNS changes
|
||
do not disable TLS expected-name checks.
|
||
|
||
Watch admission returns an initial complete snapshot followed by revisioned changes.
|
||
Changes are serialized per watch on the injected executor. If its bounded queue loses
|
||
continuity, replace pending deltas with a `resync_required` event and a full latest snapshot;
|
||
do not silently pretend all changes were delivered. Callbacks run outside catalog locks.
|
||
`cancel` stops new admission; `join` waits for already-admitted callbacks. A callback may
|
||
cancel itself, but synchronous self-join is invalid and diagnosed instead of deadlocking.
|
||
No watch callback borrows a temporary catalog buffer.
|
||
|
||
## Upper replicated directory capability
|
||
|
||
After [Replication](Replication.md) readiness, add a separate directory application with
|
||
versioned register/renew/remove commands and quorum-consistent snapshots. Bootstrap endpoints
|
||
and cluster identity remain static operator input; it cannot resolve itself into existence.
|
||
The replicated application assigns revisions from applied log positions. Lease expiry is a
|
||
leader-proposed deterministic command, never each follower independently deleting entries
|
||
from local wall clocks. Connection loss reports unavailable/stale according to caller policy.
|
||
This adapter depends on Discovery's value/watch interfaces, not the reverse. Dynamic Raft
|
||
voting membership remains a separate tested protocol, not an effect of registering an endpoint.
|
||
|
||
## Bounds and failure matrix
|
||
|
||
NEW defaults: 1,024 services, 256 endpoints/service, 10,000 total records, 16 metadata
|
||
fields/4 KiB aggregate per record, 1,024 watches with 64 events/watch and a shared 16 MiB
|
||
event budget. Reject registrations when any cap would be exceeded. Coalesce watch events
|
||
before exhausting the shared budget. Cleanup handles at most 256 expirations/turn; resolution
|
||
also filters logically expired records so deferred cleanup cannot revive them. Optional
|
||
network resolver adapter has 128 outstanding operations and a 5-second total deadline.
|
||
|
||
| Failure | Required outcome | Acceptance |
|
||
| --- | --- | --- |
|
||
| Invalid replacement config | Keep old revision; report structured diagnostics | Atomic bad/good snapshot replacement |
|
||
| Duplicate registration | conflict; do not steal the old handle's registration | Release/replace race |
|
||
| Lease renewal delayed | Expire availability hint; no claim peer is dead | Inject clock/executor delay |
|
||
| Watch queue overflow | Explicit resync, bounded retained events | Slow observer sees coherent snapshot |
|
||
| Endpoint/TLS identity mismatch | Net verification error; no downgrade | DNS/address replacement fixture |
|
||
| Catalog shutdown during callback | Stop admission then join; state retained | Callback reentrancy and self-cancel |
|
||
| Replicated directory loses quorum | Strict lookup unavailable; stale API marks revision/freshness | Partition/stale-result tests |
|
||
| Malicious metadata/cardinality | Reject before publication; no arbitrary metric labels | Max sizes and cap churn |
|
||
|
||
## Task DAG and verification
|
||
|
||
| ID | Phase / dependencies | Scope and acceptance | Recommended role |
|
||
| --- | --- | --- | --- |
|
||
| S-DISCOVERY-01 | P0; baseline | Record NEW interfaces and static bootstrap invariants; no consensus dependency | sol_implementer |
|
||
| S-DISCOVERY-02 | P1; S-DISCOVERY-01, Time/Functional contracts | Immutable catalog and local RAII registrations; conflict/expiry/atomic replacement tests | sol_implementer |
|
||
| S-DISCOVERY-03 | P2; S-DISCOVERY-02, Async scope gate | Bounded watches/selectors and managed renewal adapter; cancel/join/resync tests | sol_implementer |
|
||
| S-DISCOVERY-04 | P3; S-DISCOVERY-03, RPC/Net gates | Optional RPC endpoint adapter, observations and identity-preserving refresh; RPC package remains independent | sol_implementer |
|
||
| S-DISCOVERY-05 | P4; S-DISCOVERY-04, Replication single-group gate | Upper replicated directory, deterministic expiry commands and static bootstrap; quorum/stale contract tests | astra_implementer |
|
||
|
||
CURRENT: only the linked Net parsing surface exists; no Discovery checks ran. PROPOSED
|
||
tests model revisions, reordered renew/release, clock advancement, executor stalls and
|
||
callback overflow, then partition the upper adapter. Add targets before publishing commands;
|
||
see [VALIDATION](../VALIDATION.md), [BUILD-AND-DISTRIBUTION](../BUILD-AND-DISTRIBUTION.md).
|
||
Measure resolve/watch p50/p95/p99, throughput, churn allocations, peak RSS/CPU, maximum
|
||
resync backlog and build cost under [PERFORMANCE](../PERFORMANCE.md).
|
||
|
||
Migration introduces provider-generation/revision schemas explicitly. Replacing a provider
|
||
publishes a full reset snapshot; clients cannot compare unrelated revision domains. Rollback
|
||
retains the static catalog and rejects incompatible provider records, without changing voting
|
||
membership or trust roots. See [MIGRATION](../MIGRATION.md) and
|
||
[DistributedApplications](../platforms/DistributedApplications.md).
|