diff --git a/Aetheria.State.Daemon/Program.cs b/Aetheria.State.Daemon/Program.cs index 4940823b9..43b29090a 100644 --- a/Aetheria.State.Daemon/Program.cs +++ b/Aetheria.State.Daemon/Program.cs @@ -30,9 +30,10 @@ await EnsureVerseAuthorityPolicyAsync(node, options).ConfigureAwait(false); discoveryHost.Update(verseHost); await PublishRuntimeSessionAsync(node, options, startedAtUtc, "starting").ConfigureAwait(false); await PublishStateSurfacesAsync(node, options, startedAtUtc).ConfigureAwait(false); -var latestFrame = AetheriaRuntimeDaemonFrameStore.TryReadFrame(node.StatePath, out var startupFrame) - ? startupFrame - : null; +var latestFrame = await node + .Document(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest) + .LatestAsync() + .ConfigureAwait(false); using var cultMeshRudpHost = StartRtsCultMeshHost(node, options, () => latestFrame); using var rtsPumpCancellation = new CancellationTokenSource(); var rtsPump = RunRtsCultMeshPumpAsync(cultMeshRudpHost, rtsPumpCancellation.Token); @@ -167,7 +168,7 @@ static async Task TickAsync( PreRejectedCommandIds = policyRejectedCommandIds, CumulativeAppliedCommandIds = currentFrame?.CumulativeAppliedCommandIds ?? currentFrame?.AppliedCommandIds ?? Array.Empty(), CumulativeRejectedCommandIds = currentFrame?.CumulativeRejectedCommandIds ?? currentFrame?.RejectedCommandIds ?? Array.Empty(), - Catalog = node.OpenRuntimeCatalog(), + Catalog = node.RuntimeCatalog().Latest(), StarbridgeScenario = starbridgeScenario, StarbridgeSession = starbridgeSession, PublishWitnesses = publishWitnesses, diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 0aa2fc47c..f22531bed 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -8740,6 +8740,13 @@ static void RequireDaemonVersePublication(string root) var requiredDaemonNodeSymbols = new[] { + "public string RuntimeId { get; }", + "public CultMeshDocumentHandle Document(CultRecordKey key)", + "CultMesh.Document(", + "Database.WatchRecord(key)", + "public CultMeshDocumentHandle RuntimeCatalog()", + "AetheriaRuntimeCatalogStore.OpenReadOnly(StatePath)", + "AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest", "PutDaemonProviderAdvertisementAsync(", "GetDaemonProviderAdvertisementAsync(", "PutDaemonHealthAsync(", @@ -8893,6 +8900,9 @@ static void RequireDaemonVersePublication(string root) "ProjectReference Include=\"..\\Aetheria.State\\Aetheria.State.csproj\"", "AetheriaStateNode.OpenAsync(", "startServer: true", + ".Document(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest)", + ".LatestAsync()", + "Catalog = node.RuntimeCatalog().Latest()", "GetStarbridgeScenarioAsync()", "GetStarbridgeSessionAsync()", "StarbridgeScenario = starbridgeScenario", @@ -8927,6 +8937,8 @@ static void RequireDaemonVersePublication(string root) var forbiddenDaemonHostSymbols = new[] { + "AetheriaRuntimeDaemonFrameStore.TryReadFrame(node.StatePath", + "Catalog = node.OpenRuntimeCatalog()", "AetheriaRuntimeDaemonCommandLog.", "DeleteProcessedCommands", "new HttpListener", diff --git a/Aetheria.State/AetheriaStateNode.cs b/Aetheria.State/AetheriaStateNode.cs index f93ff8164..0d3bc31d6 100644 --- a/Aetheria.State/AetheriaStateNode.cs +++ b/Aetheria.State/AetheriaStateNode.cs @@ -7,21 +7,28 @@ using GameCult.Caching; using GameCult.Caching.MessagePack; using GameCult.Mesh; using GameCult.Networking; +using R3; namespace Aetheria.State; public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable { private readonly CultMeshNode _node; + private CultMeshDocumentHandle? _runtimeCatalog; - private AetheriaStateNode(string statePath, CultMeshNode node) + private AetheriaStateNode(string statePath, string runtimeId, CultMeshNode node) { StatePath = statePath; + RuntimeId = string.IsNullOrWhiteSpace(runtimeId) + ? "aetheria-local" + : runtimeId; _node = node; } public string StatePath { get; } + public string RuntimeId { get; } + public CultMeshNode MeshNode => _node; public CultCache Cache => _node.Cache; @@ -62,7 +69,45 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable } }).ConfigureAwait(false); - return new AetheriaStateNode(statePath, node); + return new AetheriaStateNode(statePath, runtimeId, node); + } + + public CultMeshDocumentHandle Document(CultRecordKey key) + where TDocument : class + { + return CultMesh.Document( + key.ToString(), + CultMesh.Verse("aetheria.local", RuntimeId), + async _ => (await Database.GetAsync(key).ConfigureAwait(false))!, + _ => Database.WatchRecord(key) + .Where(change => change.Document != null) + .Select(change => change.Document!), + sources: new[] + { + CultMesh.ProjectionSource(key.ToString()) + }, + routeHint: new CultMeshRouteHint(CultMeshLocalityKind.SharedMemory, "Aetheria typed state node document")); + } + + public CultMeshDocumentHandle RuntimeCatalog() + { + return _runtimeCatalog ??= CultMesh.Document( + "aetheria.catalog.runtime", + CultMesh.Verse("aetheria.local", RuntimeId), + _ => Task.FromResult(AetheriaRuntimeCatalogStore.OpenReadOnly(StatePath)), + _ => Database.WatchRecord( + AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest) + .Where(change => change.Document != null) + .Select(_ => AetheriaRuntimeCatalogStore.OpenReadOnly(StatePath)), + sources: new[] + { + CultMesh.ProjectionSource("catalog:aetheria.runtime"), + CultMesh.ProjectionSource( + "aetheria.catalog.runtime", + AetheriaRuntimeCatalogSnapshot.SchemaId, + "managed Aetheria runtime catalog document") + }, + routeHint: new CultMeshRouteHint(CultMeshLocalityKind.SharedMemory, "Aetheria typed catalog state")); } public Task> PutWorldAsync(AetheriaWorldState world)