CultNet selection cut1 fix batch: R-A/B/C/D/E/F/G/H/J/M (C#)
Wires v1 into both C# servers (R-A): CultNetDatabaseServer registers CultNetSnapshotRequestV1Message/CultNetDatabaseSubscribeV1Message listeners and Server.cs's pre-verification allowlist gains them; CultNetDatabaseSubscriptionServer's subscribe path is generalised to a shared SubscriptionRequest so v0 (lowered) and v1 selections run the same Subscribe/Watch/Reconcile core, with D6's rule wired in: a hop-bearing selection runs the full reconcile diff on every change instead of the single-row fast path. CultNetDatabase.CurrentAsOf gives both servers a real snapshot watermark. Fixes the confirmed parity and correctness defects from Soul's whole-cut pass: - R-B: cited/cites edges are anchored to the row the direction actually reports against (the citer under cites, the cited row under cited), not filtered by "From is on the page" regardless of direction; order is page-row order then (from, role, to) in code-point order. - R-C: a new CultNetCodePointComparer replaces every StringComparer.Ordinal/ string.CompareOrdinal in the row tiebreak, cursor position and edge order, so an astral key sorts the same way here as it does under Rust's UTF-8 byte comparison. - R-D: CultCache renders a float/double's exact decimal expansion from its IEEE-754 bits via BigInteger (RenderExactFloat/RenderExactDouble), never .NET's shortest round-trip form, which rounded a tie the opposite way from Rust at some values. The now-dead ExpandScientificNotation is deleted. - R-E: MatchesCitation compares a cites target through CultNetSchemaAliasMatching instead of an exact SchemaId string compare; ToEdge and ToRawRecord now emit the same wire schema id (WireSchemaId) for the same row, where ToEdge previously used the descriptor's own id and ToRawRecord the binding's override. - R-F: CultNetSelectionEvaluator.Select validates first, unconditionally - the validate:false/true flag on SelectPage/CreateRawSnapshotResponse is gone, so no public evaluation path can skip the door. Mesh's EnsureV0Compatible runs the new CultNetSelectionValidation.ValidateShape (the declaration-independent half of the door) before its own v0 transport refusals, so Keys=[]/[""] is refused there too. - R-G: Evaluation.TotalMatched is the selection's whole matching count; SelectPage's Matched field now reports it instead of the page's row count. CreateRawSnapshotResponse and CreateShardSnapshotResponse (v0/shard full walks) call the new CultNetDocumentRegistry.SelectAll, which evaluates once via CultNetSelectionEvaluator.EvaluateAll and projects every matched row, instead of looping SelectPage per 200-row page and re-filtering/re-sorting the whole row set each time. - R-H: the cursor digest is length-prefixed for every string and list (AppendString/AppendList) instead of delimiter-joined, closing the collision ["a|b"] == ["a","b"] and ["a,b"] == ["a","b"]. - R-J: any_of on a numeric alias compares TryGetIndexNumber's canonical rendering, not the string getter's culture-dependent ToString(). - R-M: WithBindingSchemaAlias is deleted; both servers' single-change fast path calls CultNetDocumentRegistry.ExpandSchemaBindingAliases instead, the one binding-alias reconciler. The duplicated v0/shard lower-and-page loop is gone with SelectAll above. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
00f4c02dd7
commit
790385364c
10 changed files with 752 additions and 188 deletions
|
|
@ -98,36 +98,9 @@ namespace GameCult.Networking
|
|||
: 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
|
||||
};
|
||||
}
|
||||
// R-M: WithBindingSchemaAlias (a second binding-alias reconciler, scoped to one descriptor) is
|
||||
// deleted - CultNetDocumentRegistry.ExpandSchemaBindingAliases is the one copy every caller
|
||||
// uses, CultNetDatabaseServer and CultNetDatabaseSubscriptionServer included.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -645,26 +618,19 @@ namespace GameCult.Networking
|
|||
{
|
||||
Schemas = CultNetV0SelectionLowering.Lower(filter?.SchemaIds),
|
||||
Keys = CultNetV0SelectionLowering.Lower(filter?.RecordKeys),
|
||||
Projection = CultNetSelectionProjections.Document,
|
||||
Limit = CultNetSelectionEvaluator.LimitMax
|
||||
Projection = CultNetSelectionProjections.Document
|
||||
};
|
||||
bool RowFilter(CultDocumentDescriptor descriptor, CultRecordKey key) =>
|
||||
!string.IsNullOrWhiteSpace(key.Value) && shard.Matches(descriptor.SchemaId, key);
|
||||
|
||||
var documents = new List<CultNetRawDocumentRecord>();
|
||||
string? cursor = null;
|
||||
do
|
||||
{
|
||||
selection.Cursor = cursor;
|
||||
var page = _documents.SelectPage(_cache, selection, ordinalOf: static (_, _) => 0, asOf: 0, validate: false, options: null, rowFilter: RowFilter);
|
||||
documents.AddRange(page.Documents ?? Array.Empty<CultNetRawDocumentRecord>());
|
||||
cursor = page.Next;
|
||||
} while (cursor != null);
|
||||
// R-G: one evaluation answers the whole shard snapshot, not a loop that re-filters and
|
||||
// re-sorts the shard's row set once per 200-row page.
|
||||
var page = _documents.SelectAll(_cache, selection, ordinalOf: static (_, _) => 0, asOf: 0, options: null, rowFilter: RowFilter);
|
||||
|
||||
return new CultNetSnapshotResponseRawMessage
|
||||
{
|
||||
MessageId = string.IsNullOrWhiteSpace(messageId) ? Guid.NewGuid().ToString("N") : messageId,
|
||||
Documents = documents.ToArray(),
|
||||
Documents = page.Documents ?? Array.Empty<CultNetRawDocumentRecord>(),
|
||||
ShardId = shard.ShardId,
|
||||
ShardEpoch = shard.Epoch,
|
||||
ShardLogSequence = GetLatestMutationLogSequence(shard.ShardId)
|
||||
|
|
@ -1304,6 +1270,15 @@ namespace GameCult.Networking
|
|||
public long? LastWriteSequence(string schemaId, CultRecordKey key) =>
|
||||
_lastWriteSequence.TryGetValue((schemaId, key.Value), out var sequence) ? sequence : null;
|
||||
|
||||
/// <summary>
|
||||
/// The current write-sequence watermark this database can present an exact snapshot for (R-A):
|
||||
/// the highest <see cref="LastWriteSequence"/> assigned to any row, 0 when nothing has been
|
||||
/// committed yet. This is the evaluator's <c>asOf</c> for a v1 snapshot or subscription page - it
|
||||
/// advances on every committed write, so a cursor minted against an older watermark refuses as
|
||||
/// <c>cursor_stale</c> once a page's answer could differ.
|
||||
/// </summary>
|
||||
public ulong CurrentAsOf() => _lastWriteSequence.Count == 0 ? 0UL : (ulong)_lastWriteSequence.Values.Max();
|
||||
|
||||
private void RecordMutationLogEntry(
|
||||
CultNetShardMutationLogEntry entry,
|
||||
CultNetShardLogEntryMessage? wireEntry = null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue