Expose state node document handles
This commit is contained in:
parent
190c692e9f
commit
662652f027
3 changed files with 64 additions and 6 deletions
|
|
@ -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<AetheriaRuntimeDaemonFrameDocument>(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<AetheriaRuntimeDaemonTickResult> TickAsync(
|
|||
PreRejectedCommandIds = policyRejectedCommandIds,
|
||||
CumulativeAppliedCommandIds = currentFrame?.CumulativeAppliedCommandIds ?? currentFrame?.AppliedCommandIds ?? Array.Empty<string>(),
|
||||
CumulativeRejectedCommandIds = currentFrame?.CumulativeRejectedCommandIds ?? currentFrame?.RejectedCommandIds ?? Array.Empty<string>(),
|
||||
Catalog = node.OpenRuntimeCatalog(),
|
||||
Catalog = node.RuntimeCatalog().Latest(),
|
||||
StarbridgeScenario = starbridgeScenario,
|
||||
StarbridgeSession = starbridgeSession,
|
||||
PublishWitnesses = publishWitnesses,
|
||||
|
|
|
|||
|
|
@ -8740,6 +8740,13 @@ static void RequireDaemonVersePublication(string root)
|
|||
|
||||
var requiredDaemonNodeSymbols = new[]
|
||||
{
|
||||
"public string RuntimeId { get; }",
|
||||
"public CultMeshDocumentHandle<TDocument> Document<TDocument>(CultRecordKey key)",
|
||||
"CultMesh.Document<TDocument>(",
|
||||
"Database.WatchRecord<TDocument>(key)",
|
||||
"public CultMeshDocumentHandle<AetheriaRuntimeCatalogSnapshot> 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<AetheriaRuntimeDaemonFrameDocument>(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",
|
||||
|
|
|
|||
|
|
@ -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<AetheriaRuntimeCatalogSnapshot>? _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<TDocument> Document<TDocument>(CultRecordKey key)
|
||||
where TDocument : class
|
||||
{
|
||||
return CultMesh.Document<TDocument>(
|
||||
key.ToString(),
|
||||
CultMesh.Verse("aetheria.local", RuntimeId),
|
||||
async _ => (await Database.GetAsync<TDocument>(key).ConfigureAwait(false))!,
|
||||
_ => Database.WatchRecord<TDocument>(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<AetheriaRuntimeCatalogSnapshot> RuntimeCatalog()
|
||||
{
|
||||
return _runtimeCatalog ??= CultMesh.Document(
|
||||
"aetheria.catalog.runtime",
|
||||
CultMesh.Verse("aetheria.local", RuntimeId),
|
||||
_ => Task.FromResult(AetheriaRuntimeCatalogStore.OpenReadOnly(StatePath)),
|
||||
_ => Database.WatchRecord<AetheriaRuntimeDaemonFrameDocument>(
|
||||
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<CultRecordHandle<AetheriaWorldState>> PutWorldAsync(AetheriaWorldState world)
|
||||
|
|
|
|||
Loading…
Reference in a new issue