fix(grpc-data): H1 cursors bind an opaque namespace/view tag besides (realm, identifier) (review 2)
The realm folds mapped/raw into Raw (and every other index into Uns), so (realm, identifier) alone could resume a raw node's cursor on the same identifier in a mapped namespace. Items and cursor state now carry a binding tag: the SDK adapter (and the events path) passes the node's namespace URI, restoring the pre-port namespace-qualified binding; a peer passes its view tag. The peer key binds it too.
This commit is contained in:
@@ -164,7 +164,7 @@ public sealed class HistoryReadPortPagingFuzzTests(HistoryReadPortServerFixture
|
||||
|
||||
private (uint Status, List<string> Values, byte[]? Cp) PortRead(HistoryReadRawVariant details, AddressSpaceRealm realm, string id, byte[]? cp)
|
||||
{
|
||||
var outcome = fx.Nm.ReadHistory(details, [new HistoryReadPortItem(realm, id, cp)],
|
||||
var outcome = fx.Nm.ReadHistory(details, [new HistoryReadPortItem(realm, id, cp, BindingTag: fx.Nm.HistoryBindingTag(fx.Nodes["dbl"].NodeId))],
|
||||
fx.Nm.SessionHistoryContinuationScope(session: null), CancellationToken.None)[0];
|
||||
// The operation slot, as the override's errors[i] (Status folds GoodNoData in; pinned by the parity tests).
|
||||
return (outcome.Error?.StatusCode.Code ?? StatusCodes.BadHistoryOperationUnsupported.Code,
|
||||
|
||||
@@ -410,6 +410,38 @@ public sealed class HistoryReadPortParityTests(HistoryReadPortServerFixture fx)
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_cursor_is_bound_to_its_namespace_not_only_realm_and_identifier()
|
||||
{
|
||||
await RunAsync(async () =>
|
||||
{
|
||||
var source = new ParitySource();
|
||||
source.Series["P.raw"] = Enumerable.Range(0, 6).Select(i => S((double)i, i)).ToList();
|
||||
fx.Nm.HistorianDataSource = source;
|
||||
var (realm, id, nodeId) = fx.Nodes["raw"];
|
||||
var details = new HistoryReadRawVariant(T(0), T(100), 2, ReturnBounds: false);
|
||||
var local = fx.Nm.HistoryBindingTag(nodeId);
|
||||
// mapped/raw folds into the Raw realm: the same (Raw, identifier) in the projected namespace is ANOTHER node.
|
||||
var mapped = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ProjectedDataIds.RawNamespaceUri;
|
||||
local.ShouldNotBe(mapped);
|
||||
var scope = fx.Nm.SessionHistoryContinuationScope(session: null);
|
||||
|
||||
HistoryReadNodeOutcome Read(string tag, byte[]? cp) =>
|
||||
fx.Nm.ReadHistory(details, [new HistoryReadPortItem(realm, id, cp, BindingTag: tag)], scope, CancellationToken.None)[0];
|
||||
|
||||
Read(mapped, Read(local, null).ContinuationPoint).Status.Code.ShouldBe(StatusCodes.BadContinuationPointInvalid.Code);
|
||||
Read(local, Read(mapped, null).ContinuationPoint).Status.Code.ShouldBe(StatusCodes.BadContinuationPointInvalid.Code);
|
||||
Read(local, Read(local, null).ContinuationPoint).Status.Code.ShouldBe(StatusCodes.Good.Code);
|
||||
|
||||
// The SDK adapter tags with the same value: an override-issued cursor resumes through the port with the local
|
||||
// tag and is refused with the mapped one.
|
||||
var sdk = Raw(T(0), T(100), 2, bounds: false);
|
||||
Read(local, ReadOverrideRaw(sdk, "raw", null).Cp).Status.Code.ShouldBe(StatusCodes.Good.Code);
|
||||
Read(mapped, ReadOverrideRaw(sdk, "raw", null).Cp).Status.Code.ShouldBe(StatusCodes.BadContinuationPointInvalid.Code);
|
||||
await Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_outcome_status_carries_GoodNoData_and_Bad_operation_statuses_verbatim()
|
||||
{
|
||||
@@ -509,7 +541,8 @@ public sealed class HistoryReadPortParityTests(HistoryReadPortServerFixture fx)
|
||||
{
|
||||
var items = nodes.Select((n, i) => new HistoryReadPortItem(
|
||||
fx.Nodes[n.Key].Realm, fx.Nodes[n.Key].Id, n.Cp,
|
||||
details is ReadProcessedDetails p ? p.AggregateType[i] : default)).ToArray();
|
||||
details is ReadProcessedDetails p ? p.AggregateType[i] : default,
|
||||
BindingTag: fx.Nm.HistoryBindingTag(fx.Nodes[n.Key].NodeId), NodeId: fx.Nodes[n.Key].NodeId)).ToArray();
|
||||
var outcomes = fx.Nm.ReadHistory(HistoryReadVariant.From(details), items,
|
||||
fx.Nm.SessionHistoryContinuationScope(session: null), CancellationToken.None);
|
||||
// A slot the port leaves unset is the one the SDK seeded before the override ran (an empty, Good result).
|
||||
|
||||
+9
-6
@@ -20,13 +20,14 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
private static HistoryContinuationState State(string identifier = "Plant/dev/t1", long epoch = 3, AddressSpaceRealm realm = AddressSpaceRealm.Raw) =>
|
||||
new("WW.T1", DateTime.UnixEpoch, DateTime.UnixEpoch.AddDays(1), 0, 10)
|
||||
{
|
||||
BoundRealm = realm, BoundIdentifier = identifier, AddressSpaceEpoch = epoch,
|
||||
BoundRealm = realm, BoundIdentifier = identifier, BoundTag = "view-1", AddressSpaceEpoch = epoch,
|
||||
};
|
||||
|
||||
private static PeerHistoryContinuationKey Key(
|
||||
string principal = Principal, string incarnation = Incarnation, long epoch = 3,
|
||||
AddressSpaceRealm realm = AddressSpaceRealm.Raw, string identifier = "Plant/dev/t1", string hash = Hash) =>
|
||||
new(principal, incarnation, epoch, realm, identifier, hash);
|
||||
AddressSpaceRealm realm = AddressSpaceRealm.Raw, string identifier = "Plant/dev/t1", string hash = Hash,
|
||||
string? tag = "view-1") =>
|
||||
new(principal, incarnation, epoch, realm, identifier, tag, hash);
|
||||
|
||||
private static PeerHistoryContinuationStore Store(int capacity = 8, ManualClock? clock = null, TimeSpan? idle = null) =>
|
||||
new(Principal, Incarnation, capacity, idle, clock ?? new ManualClock());
|
||||
@@ -63,6 +64,8 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
("epoch bump", Key(epoch: 4)),
|
||||
("realm", Key(realm: AddressSpaceRealm.Uns)),
|
||||
("identifier", Key(identifier: "Plant/dev/t2")),
|
||||
("binding tag", Key(tag: "view-2")),
|
||||
("no binding tag", Key(tag: null)),
|
||||
("details hash", Key(hash: "hash-b")),
|
||||
};
|
||||
foreach (var (name, key) in cases)
|
||||
@@ -209,7 +212,7 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
var store = Store();
|
||||
var scope = new PeerHistoryContinuationScope(store, Principal, () => Incarnation);
|
||||
var details = new HistoryReadRawVariant(DateTime.UnixEpoch, DateTime.UnixEpoch.AddHours(1), 10, ReturnBounds: false);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, details);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, details, Tag: "view-1");
|
||||
|
||||
var token = scope.Save(State(), binding)!;
|
||||
scope.TryTake(token, binding with { Details = details with { NumValuesPerNode = 11 } }).ShouldBeNull("other details");
|
||||
@@ -230,7 +233,7 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
var incarnation = Incarnation;
|
||||
var scope = new PeerHistoryContinuationScope(store, Principal, () => incarnation);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3,
|
||||
new HistoryReadRawVariant(DateTime.UnixEpoch, DateTime.UnixEpoch.AddHours(1), 10, ReturnBounds: false));
|
||||
new HistoryReadRawVariant(DateTime.UnixEpoch, DateTime.UnixEpoch.AddHours(1), 10, ReturnBounds: false), Tag: "view-1");
|
||||
|
||||
var token = scope.Save(State(), binding)!;
|
||||
incarnation = "inc-2";
|
||||
@@ -246,7 +249,7 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
var store = Store();
|
||||
var owner = new PeerHistoryContinuationScope(store, Principal, () => Incarnation);
|
||||
var other = new PeerHistoryContinuationScope(store, "someone-else", () => Incarnation);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, null);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, null, Tag: "view-1");
|
||||
|
||||
Should.Throw<ArgumentException>(() => other.Save(State(), binding), "a store never holds another principal's cursor");
|
||||
var token = owner.Save(State(), binding)!;
|
||||
|
||||
Reference in New Issue
Block a user