feat(grpc-data): H2 origin HistoryRead ingress, header gating, LocalDataConnection history
Service: HistoryRead rpc; history (field 16, Metadata.history, bit 32) emitted only on a call whose header requested history AND whose origin can serve it, otherwise stripped to the v1 shape; un-negotiated HistoryRead is FAILED_PRECONDITION. Origin: Implemented(target) grows by HistoryRead when a historian backend is configured; per-item gate catalog -> export grant + origin ACL HistoryRead -> tagname, every refusal the same BadHistoryOperationUnsupported; per-principal admission (BadTooManyOperations), per-page ceiling, response-byte chunking with single-use chunk tokens; one session per (principal, credential, HTTP/2 connection) cleared on close; wiring faults BadInternalError + error log; caller cancel never a backend outcome. DataOperationPolicy maps HistoryRead.
This commit is contained in:
@@ -3,7 +3,8 @@ using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
||||
|
||||
/// <summary>Strictly caller-bound local data facade; it creates no namespace projection.</summary>
|
||||
public sealed class LocalDataConnection : IDataConnection, IDataConnectionPublicationGate, IDataConnectionDiscoveryGate
|
||||
public sealed class LocalDataConnection : IDataConnection, IDataConnectionPublicationGate, IDataConnectionDiscoveryGate,
|
||||
IDataHistoryService, IDataHistoryTransport
|
||||
{
|
||||
private readonly LocalDataServices _services;
|
||||
private readonly DataAuthenticatedContext _context;
|
||||
@@ -28,5 +29,31 @@ public sealed class LocalDataConnection : IDataConnection, IDataConnectionPublic
|
||||
{ Check(); return _services.WriteAsync(_context, request, cancellationToken); }
|
||||
public Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken)
|
||||
{ Check(); return _services.SubscribeAsync(_context, Target, cancellationToken); }
|
||||
public ValueTask DisposeAsync() { Interlocked.Exchange(ref _disposed, 1); return ValueTask.CompletedTask; }
|
||||
/// <summary>
|
||||
/// Direct runtime-consumer history (H2): this facade is the channel, so its origin continuations live only as long as
|
||||
/// the facade and are cleared on <see cref="DisposeAsync"/>. Answers are never chunked.
|
||||
/// </summary>
|
||||
public Task<IReadOnlyList<DataHistoryReadResult>> ReadAsync(DataHistoryReadRequest request, CancellationToken cancellationToken)
|
||||
{ Check(); return _services.ReadHistoryAsync(_context, Target, request, OwnChannel, chunked: false, cancellationToken); }
|
||||
public Task ReleaseAsync(IReadOnlyList<byte[]> continuations, CancellationToken cancellationToken)
|
||||
{ Check(); return _services.ReleaseHistoryAsync(_context, continuations, OwnChannel, cancellationToken); }
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyList<DataHistoryReadResult>> ReadForTransportAsync(DataHistoryReadRequest request, DataHistoryChannel channel,
|
||||
CancellationToken cancellationToken)
|
||||
{ Check(); return _services.ReadHistoryAsync(_context, Target, request, channel, chunked: true, cancellationToken); }
|
||||
/// <inheritdoc />
|
||||
public Task ReleaseForTransportAsync(IReadOnlyList<byte[]> continuations, DataHistoryChannel channel, CancellationToken cancellationToken)
|
||||
{ Check(); return _services.ReleaseHistoryAsync(_context, continuations, channel, cancellationToken); }
|
||||
private readonly CancellationTokenSource _closed = new();
|
||||
private DataHistoryChannel? _channel;
|
||||
private DataHistoryChannel OwnChannel => _channel ??= new("facade:" + Guid.NewGuid().ToString("N"), _closed.Token);
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _disposed, 1) == 0)
|
||||
{
|
||||
try { _closed.Cancel(); } catch (AggregateException) { }
|
||||
_closed.Dispose();
|
||||
}
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user