Add durable CultMesh quickstart witness

This commit is contained in:
Meta Vens 2026-05-21 00:00:15 +01:00
commit 3f5b0b04e4
5 changed files with 194 additions and 4 deletions

View file

@ -34,11 +34,12 @@ the stack. If a design needs another peer-to-peer category, first check whether
it is really Verse policy, peer exchange, or shard authority wearing a fake
mustache.
If you want one concrete path for "typed local document -> raw wire document ->
mesh/runtime watch surface", start with
If you want the smallest durable "open node -> put typed doc -> get typed doc"
path, start with
[`src/GameCult.Mesh/docs/durable-node-quickstart.md`](src/GameCult.Mesh/docs/durable-node-quickstart.md).
If you want the lower-level "typed local document -> raw wire document ->
mesh/runtime watch surface" handoff, follow it with
[`src/GameCult.Mesh/docs/typed-document-path.md`](src/GameCult.Mesh/docs/typed-document-path.md).
That sample shows which package owns each step and where wire provenance stays
visible.
## Repository Scope
@ -256,6 +257,7 @@ Each subproject has a local README with package-specific detail:
- [GameCult.Caching.MessagePack.Analyzers](src/GameCult.Caching.MessagePack.Analyzers/README.md)
- [GameCult.Networking](src/GameCult.Networking/README.md)
- [GameCult.Mesh](src/GameCult.Mesh/README.md)
- [Durable Node Quickstart](src/GameCult.Mesh/docs/durable-node-quickstart.md)
- [Typed Document Path](src/GameCult.Mesh/docs/typed-document-path.md)
- [GameCult.Unity](src/GameCult.Unity/README.md)
- [GameCult.Caching.Tests](tests/GameCult.Caching.Tests/README.md)

View file

@ -26,6 +26,12 @@ var player = await node.Database.GetAsync<PlayerData>(playerKey);
await node.Database.PutAsync(playerKey, player);
```
If you want one inspectable path that starts with a durable local cache file and
ends with a typed read/write through the public CultMesh surface, see
[docs/durable-node-quickstart.md](docs/durable-node-quickstart.md).
If you want the lower-level typed-to-raw handoff that CultNet moves across the
wire, see [docs/typed-document-path.md](docs/typed-document-path.md).
Enable durable authoritative shard logs when a node should serve replica
catch-up after restart:
@ -200,6 +206,7 @@ snapshot's represented log sequence.
## Documentation
- [Public API](docs/public-api.md)
- [Durable Node Quickstart](docs/durable-node-quickstart.md)
- [Typed Document Path](docs/typed-document-path.md)
- [Research Notes](docs/research.md)
- [Verse Model](docs/verses.md)

View file

@ -0,0 +1,116 @@
# Durable Node Quickstart
This is the smallest honest path from a durable local typed document to a
running CultMesh node.
It uses the public surface only:
- `CultMesh.CreateNodeAsync(...)` to open or create the durable node
- `node.Database.PutAsync(...)` and `node.Database.GetAsync(...)` for typed reads
and writes
- `node.FlushAsync()` to persist the current local state before shutdown
## Ownership Split
- CultCache owns the local durable state file, typed document registry, record
keys, and persistence metadata.
- CultNet owns the document registry that turns typed CultCache documents into
schema-v0 wire payloads when the node has to replicate them.
- CultMesh owns the newcomer-facing node and database illusion your game code
talks to.
That means the game writes to `node.Database`, CultMesh routes through CultNet,
and the durable local snapshot still belongs to CultCache.
## Sample
Define one typed document. CultCache owns this model and its schema identity.
```csharp
using GameCult.Caching;
using MessagePack;
[CultDocument("sample.mesh_note", "sample.mesh_note.v0")]
[MessagePackObject]
public sealed class MeshNote
{
[Key(0)]
[CultName]
public string NoteId { get; set; } = string.Empty;
[Key(1)]
public string Body { get; set; } = string.Empty;
}
```
Open a durable node, write the document through CultMesh, flush it, then reopen
the same node and read the document back.
```csharp
using GameCult.Caching;
using GameCult.Mesh;
using GameCult.Networking;
var key = new CultRecordKey("note:intro");
var documents = new CultNetDocumentRegistry()
.Register(CultNetDocumentBinding.ForDocument<MeshNote>());
using (var node = await CultMesh.CreateNodeAsync("world.ccmp", new CultMeshNodeOptions
{
DatabaseOptions = new CultNetDatabaseOptions
{
RuntimeId = "quickstart-local",
DocumentRegistry = documents
}
}))
{
await node.Database.PutAsync(key, new MeshNote
{
NoteId = key.Value,
Body = "hello from a durable CultMesh node"
});
var live = await node.Database.GetAsync<MeshNote>(key);
Console.WriteLine(live?.Body);
await node.FlushAsync();
}
using (var reopened = await CultMesh.CreateNodeAsync("world.ccmp", new CultMeshNodeOptions
{
DatabaseOptions = new CultNetDatabaseOptions
{
RuntimeId = "quickstart-local",
DocumentRegistry = documents
}
}))
{
var stored = await reopened.Database.GetAsync<MeshNote>(key);
Console.WriteLine(stored?.Body);
}
```
What happened:
1. `CultMesh.CreateNodeAsync("world.ccmp", ...)` opened a durable CultCache
snapshot file and wrapped it in a CultMesh node.
2. `node.Database.PutAsync(...)` wrote a typed document through the public
CultMesh database surface.
3. CultNet kept the document registry needed for raw replication and
subscriptions, but the sample did not need to drop into wire messages.
4. `node.FlushAsync()` persisted the local CultCache snapshot so the reopened
node could read the same typed document back.
## Which Layer Owns What?
If you peel this path apart, the authority split stays simple:
- CultCache: `world.ccmp`, schema ids, record keys, typed document payloads,
local indexes, flush/load
- CultNet: `CultNetDocumentRegistry`, raw document puts/snapshots,
subscriptions, shard routing, transport-facing replication
- CultMesh: `CultMeshNode`, `node.Database`, and the "treat this as one
reactive database" surface
If you need the explicit raw-envelope version of the same handoff, see
[typed-document-path.md](typed-document-path.md).

View file

@ -103,6 +103,8 @@ contracts. CultMesh owns the developer-facing mesh entrypoints and higher-level
runtime documentation.
See `src/GameCult.Mesh/README.md` for the public-facing CultMesh API.
For one small end-to-end path from durable local typed state into `node.Database`,
see `src/GameCult.Mesh/docs/durable-node-quickstart.md`.
## Distributed CultCache

View file

@ -1107,6 +1107,57 @@ namespace GameCult.Networking.Tests
Assert.That(Directory.Exists(Path.Combine(rootPath, "world.cultmesh", "shard-logs")), Is.True);
}
[Test]
public async Task CultMeshNode_CanRoundTrip_DurableTypedDocument_Through_PublicDatabaseSurface()
{
var rootPath = Path.Combine(TestContext.CurrentContext.WorkDirectory, "cultmesh-quickstart", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(rootPath);
var cachePath = Path.Combine(rootPath, "world.ccmp");
var documents = new CultNetDocumentRegistry()
.Register(CultNetDocumentBinding.ForDocument<MeshQuickstartNote>());
var key = new CultRecordKey("note:intro");
using (var node = await CultMesh.CreateNodeAsync(cachePath, new CultMeshNodeOptions
{
StartServer = false,
DatabaseOptions = new CultNetDatabaseOptions
{
RuntimeId = "quickstart-local",
DocumentRegistry = documents
}
}))
{
await node.Database.PutAsync(key, new MeshQuickstartNote
{
NoteId = key.Value,
Body = "hello from a durable CultMesh node"
});
var live = await node.Database.GetAsync<MeshQuickstartNote>(key);
Assert.That(node.Store, Is.Not.Null);
Assert.That(live, Is.Not.Null);
Assert.That(live!.Body, Is.EqualTo("hello from a durable CultMesh node"));
await node.FlushAsync();
}
using var reopened = await CultMesh.CreateNodeAsync(cachePath, new CultMeshNodeOptions
{
StartServer = false,
DatabaseOptions = new CultNetDatabaseOptions
{
RuntimeId = "quickstart-local",
DocumentRegistry = documents
}
});
var stored = await reopened.Database.GetAsync<MeshQuickstartNote>(key);
Assert.That(stored, Is.Not.Null);
Assert.That(stored!.NoteId, Is.EqualTo(key.Value));
Assert.That(stored.Body, Is.EqualTo("hello from a durable CultMesh node"));
}
[Test]
public async Task CultNetDatabase_Appends_PerShardMutationLog()
{
@ -2421,6 +2472,18 @@ namespace GameCult.Networking.Tests
Assert.That(client.ReconnectState, Is.EqualTo(ClientReconnectState.Idle));
}
[CultDocument("sample.mesh_note", "sample.mesh_note.v0")]
[MessagePack.MessagePackObject]
public sealed class MeshQuickstartNote
{
[MessagePack.Key(0)]
[CultName]
public string NoteId { get; set; } = string.Empty;
[MessagePack.Key(1)]
public string Body { get; set; } = string.Empty;
}
private sealed class EnvironmentVariableScope : IDisposable
{
private readonly (string Name, string? Value)[] _originalValues;