CultNet selection cut1, commit 1: the shape, the evaluator, v1 messages
docs/cultnet-selection-cut.md section 2/4/6/7/8: CultNetSelection (schemas, keys, fields, cites, cited, projection, descending, limit, cursor) with its door validation (S1), and CultNetSelectionEvaluator: the single-row Matches fast path (D6) and the full Select (order, hop, cursor, paging). Neither reflects over a document; both read only through the cache's public surface (commit 0). Three v1 messages beside v0 (cultnet.snapshot_request.v1, cultnet.database_subscribe.v1, cultnet.snapshot_response_raw.v1), their schema files under contracts/cultnet, registry entries and dispatch arms. CultNetSchemaAliasMatching goes internal -> public (D4), the one alias matcher. CultNetDatabase gains LastWriteSequence(schemaId, key), confirmed at the one append site (AppendMutationLogEntry) that every committed write takes a shard-log sequence, including a local PutAsync outside any shard. Three engines deleted, one evaluator wired in their place: - CultNetDocumentRegistry: CreateRawSnapshotResponse's reflection loop over cache.AllEntries and MatchesRequestedSchema gone; cache.AllStoredDocuments replaces the reflection entirely. v0 lowers into a Selection and walks the evaluator's own pages so a v0 caller still sees its whole matching set (D3: v0 has no engine of its own). CreateSelectionResponse/SelectPage/ ToRawRecord/CreateSnapshotRequestV1 added. - CultNetDatabaseServer: CreateChangeMessage/CreateRawDocumentRecord/Matches/ MatchesSchema/InferSchemaName (122 lines) deleted; CreateSubscription lowers v0 into a Selection and matches through the evaluator. - CultNetDatabaseSubscriptionServer: CreateAuthorizedChange/CreateChange/ CreateChangeCore/ResolveWireSchemaId/MatchesRequestedSchema/CreateRawRecord (92 lines) deleted, replaced by CreateMatchedRecord. _projectRecord and CreateProjectedSnapshot's collapse are commit 2's, per the map's own deletion line, and are untouched here. Discrepancy found and fixed (not in the map): CultNetDocumentBinding can carry a schema id different from its descriptor's own (CultNetDocumentBinding.ForDocument's schemaId override), which the old per-engine matchers checked and a descriptor-only evaluator cannot see by design (it stays decoupled from CultNetDocumentRegistry). Fixed at the two call sites and in CultNetDocumentRegistry.SelectPage by resolving the binding's schema id into the effective selection before evaluation (CultNetSchemaAliasMatching.WithBindingSchemaAlias, CultNetDocumentRegistry.ExpandSchemaBindingAliases), not in the evaluator. Found by DatabaseSubscription_FiltersLiveChangesByWireSchemaBinding timing out; both call sites now pass. Second discrepancy, reported not fixed: CultNetDatabase.cs:1707 has a fourth, undocumented copy of schema-matching logic (MatchesRequestedSchema, private, serving CreateShardSnapshotResponse), which the map's section 1 audit did not name among "three separate selector engines". Left untouched this commit: it is out of the map's explicit deletes list and touching it risks shard snapshot behavior with no budgeted verification. Verification: dotnet test tests/GameCult.Networking.Tests - 162 passed (150 existing + 12 new), 0 failed; the seven map-named tests all still pass, two rewritten for the new signatures (CreateChangeMessage now takes CultNetSelection; CreateChange/CreateAuthorizedChange collapsed into CreateMatchedRecord, returning CultNetRawDocumentRecord? directly). tests/GameCult.Mesh.Tests - 252 passed, 1 pre-existing skip, 0 failed (no Mesh source touched this commit). tests/GameCult.Caching.Tests - unaffected (188, unchanged from commit 0). Negative greps: GetProperty|GetField|GetCustomAttribute in GameCult.Networking - only against the generic `object change` dispatch (CultNetDatabaseChange<T>) and CultRecordHandle<T> construction, pre-existing and out of this cut's scope, never against a document's declared values. _projectRecord survives in CultNetDatabaseSubscriptionServer.cs (expected, commit 2). CultNetSchemaAliasMatching is the only schema matcher outside the one reported discrepancy. scripts/mutate-dotnet.ps1: the caching mutation runner generalized into a shared dotnet/NUnit harness (Target/TestProject/Entries/ControlFilter), replacing scripts/mutate-cultnet-selection-caching.ps1 with an entries file of the same six mutations (re-verified: all six still KILL). It is now generic to any NUnit project in this repo, not only this campaign's two targets - a candidate to sit beside tools/eureka-mutations.ps1 as the dotnet-side counterpart. Nine new networking entries (S3, S5 x2, S7 x2, S16 x2, S18) all KILLED. Not yet mutation-run: S1, S2, S6, S23 (pinned by tests, not by a committed mutant); S9-S15 (subscription reconcile lowering, v0 no-engine-of-its-own); S17, S20 (pinned by tests only). S19/S21/S22 are cache-layer, covered in commit 0. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
e420410fe9
commit
17d10e017f
19 changed files with 1976 additions and 477 deletions
|
|
@ -44,7 +44,10 @@ namespace GameCult.Networking
|
|||
Reconciled
|
||||
}
|
||||
|
||||
internal static class CultNetSchemaAliasMatching
|
||||
/// <summary>
|
||||
/// The one schema-alias matcher for every runtime-side schema match (docs/cultnet-selection-cut.md, D4).
|
||||
/// </summary>
|
||||
public static class CultNetSchemaAliasMatching
|
||||
{
|
||||
public static bool MatchesAny(IReadOnlyList<string> candidates, string schemaId)
|
||||
{
|
||||
|
|
@ -94,6 +97,37 @@ namespace GameCult.Networking
|
|||
? schemaId.Substring(0, marker)
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A selection whose schema filter also matches a document's wire binding id, when it carries
|
||||
/// one different from its descriptor's own. <see cref="CultDocumentDescriptor"/> knows nothing
|
||||
/// of <c>CultNetDocumentBinding</c>'s optional schema-id override, so a caller that has both in
|
||||
/// hand (the two subscription servers) reconciles them here rather than in the evaluator, which
|
||||
/// stays decoupled from CultNetDocumentRegistry by design.
|
||||
/// </summary>
|
||||
public static CultNetSelection WithBindingSchemaAlias(CultNetSelection selection, CultDocumentDescriptor descriptor, string? bindingSchemaId)
|
||||
{
|
||||
if (selection.Schemas is not { Length: > 0 } ||
|
||||
string.IsNullOrEmpty(bindingSchemaId) ||
|
||||
!selection.Schemas.Contains(bindingSchemaId, StringComparer.Ordinal) ||
|
||||
MatchesAny(selection.Schemas, descriptor))
|
||||
{
|
||||
return selection;
|
||||
}
|
||||
|
||||
return new CultNetSelection
|
||||
{
|
||||
Schemas = null,
|
||||
Keys = selection.Keys,
|
||||
Fields = selection.Fields,
|
||||
Cites = selection.Cites,
|
||||
Cited = selection.Cited,
|
||||
Projection = selection.Projection,
|
||||
Descending = selection.Descending,
|
||||
Limit = selection.Limit,
|
||||
Cursor = selection.Cursor
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -464,6 +498,11 @@ namespace GameCult.Networking
|
|||
new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, long> _nextLogSequences = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, long> _appliedShardSequences = new(StringComparer.Ordinal);
|
||||
// CultNet typed selection, section 2: "ordinal is the sequence of the commit that last wrote
|
||||
// the row". Kept on every append (AppendMutationLogEntry is the one site), keyed by (schemaId,
|
||||
// recordKey) so the evaluator's order and cursor never read a clock.
|
||||
private readonly Dictionary<(string SchemaId, string RecordKey), long> _lastWriteSequence =
|
||||
new();
|
||||
private readonly Subject<object> _changes = new();
|
||||
private bool _disposed;
|
||||
|
||||
|
|
@ -1254,8 +1293,17 @@ namespace GameCult.Networking
|
|||
? null
|
||||
: wireEntry ?? ToLogEntryMessage(entry);
|
||||
RecordMutationLogEntry(entry, storedWireEntry);
|
||||
_lastWriteSequence[(schemaId, key.Value)] = sequence;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The shard-log sequence of the commit that last wrote this row, or null when the row has
|
||||
/// never been committed through this database. The order the CultNet selection evaluator
|
||||
/// pages by (docs/cultnet-selection-cut.md, section 2).
|
||||
/// </summary>
|
||||
public long? LastWriteSequence(string schemaId, CultRecordKey key) =>
|
||||
_lastWriteSequence.TryGetValue((schemaId, key.Value), out var sequence) ? sequence : null;
|
||||
|
||||
private void RecordMutationLogEntry(
|
||||
CultNetShardMutationLogEntry entry,
|
||||
CultNetShardLogEntryMessage? wireEntry = null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue