Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions docs/NodeManagers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1946,36 +1946,37 @@ It preserves serving type relationships, reference names, encoding ownership and
A replacement must not reparent a serving type, reuse a reference name or encoding for another
type, or change a registered CLR type, XML name or data type definition. Such changes fail before
the decision callback; use new type and encoding identifiers for incompatible definitions.
Preparation also requires the same serving identity and revision at commit: even an unrelated
concurrent metadata addition makes the batch stale and requires preparation again.

Preparation captures its serving view and private metadata under the lifecycle writer, then
releases the writer before invoking factories, address-space creation, reload participants or
NodeId policy preparation. A generation admission protects a current participant while these
callbacks run. Unrelated changes may publish concurrently. Commit rejects a changed serving
view with `InvalidOperationException` before the durable decision; an explicit prepared batch
does not rerun factories or rebase private namespace indexes.

The compatibility `AddAsync`, `ReloadAsync` and `RemoveAsync` extensions retry a routing-view
conflict caused by an independent publication. Each attempt disposes its uncommitted batch
before preparing against the current view, so private namespace indexes are reconstructed
rather than rebased. An addition or replacement factory may therefore run again; it must
support aborted candidates and repeated construction. Use an explicit prepared batch when
application code must control reconstruction. Only conflicts from that batch's own routing
checks permit retry; a nested explicit batch's failure remains an error of the callback that
invoked it. Factory failures, registration ownership changes and failed aborts remain errors.
The extensions never retry after their decision begins or the batch commits.
They permit at most three attempts. Pass a cancellation token to bound waits
within those attempts. Slot-based change sets and explicit prepared units do
not perform these convenience-adapter retries.

Commit also releases the writer while discovering monitored-item transitions. The current
generation remains admitted until discovery ends and the writer revalidates the captured view.
A concurrent publication makes the transaction stale before its durable decision is invoked.
Reference-owner discovery also runs outside the writer and host publication semaphores.
It pins the captured view and admits each existing owner callback through that generation's
gate. Reference edits capture each source's version before later owner callbacks run;
publication revalidates the view, contribution map, and source versions before deciding.
callbacks run. Changes on other NodeManagers may publish concurrently, and a batch prepared
before such a publication still commits: commit moves it onto the newer address space instead of
rejecting it. Only what the batch itself prepared is checked against what changed meanwhile:

- the registrations it replaces or removes must still be current;
- every namespace and server URI index it assigned must still map to the same URI. Two batches
that append different namespaces at the same index conflict;
- every type it registers must still have the serving registration it saw at preparation, and
its supertypes must still exist. The same holds for every encodeable registration it adds;
- reference-owner discovery and the diagnostics conformance image are computed again against the
newer view. They are not a conflict.

A batch that fails these checks is rejected with `NodeManagerLifecycleConflictException` before the
durable decision callback runs; nothing of it is published. The conflict is retryable: dispose the
rejected batch and prepare the changes again against the current address space. Calling `CommitAsync`
again on the rejected batch does not retry it, and an explicit prepared batch never reruns factories.
Other `InvalidOperationException` failures (factory failures, incompatible type definitions, failed
aborts) are not resolved by a retry. A batch begun from an `ILifecycleCapture` keeps its exact-revision
semantics: any newer publication makes it a `NodeManagerLifecycleConflictException`.

Commit also releases the writer while discovering monitored-item transitions and reference owners.
The current generation remains admitted until discovery ends and the writer revalidates the view.
Reference-owner discovery runs outside the writer and host publication semaphores. It pins the
view and admits each existing owner callback through that generation's gate. Reference edits
capture each source's version before later owner callbacks run; publication revalidates the view,
contribution map, and source versions before deciding. When another commit publishes during
discovery, discovery runs again against the newer view (up to eight times before the batch is
rejected as a conflict).

```csharp
await using IPreparedChanges prepared = await lifecycle.PrepareAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ ValueTask DecideAsync(
/// <param name="CallbackPermit">The callback permit captured when preparation began, if any.</param>
/// <param name="Admission">The semantic host admission acquired before mutation ownership.</param>
/// <param name="Progress">The transaction's core-publication progress, distinct from the route swap.</param>
/// <param name="Rebase">
/// Whether the type, factory, namespace and server URI images may have moved since preparation. Only the
/// batch's own registrations are merged onto them, and an overlapping change is a conflict.
/// </param>
internal sealed record NodeManagerPublicationPlan(
ArrayOf<PreparedNodeManager> Candidates,
ArrayOf<IAsyncNodeManager> Removed,
Expand All @@ -396,7 +400,8 @@ internal sealed record NodeManagerPublicationPlan(
PreparedAddressSpaceReferences? References = null,
NodeManagerCallbackPermit? CallbackPermit = null,
INodeManagerBatchAdmission? Admission = null,
AddressSpacePublisher.PublicationProgress? Progress = null);
AddressSpacePublisher.PublicationProgress? Progress = null,
bool Rebase = false);

/// <summary>
/// Decorates publication and observes dispatch without replacing the bound host or its owners.
Expand Down
12 changes: 12 additions & 0 deletions src/Opc.Ua.Server/NodeManager/Lifecycle/IPreparedChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public interface IPreparedChanges : IAsyncDisposable
/// <param name="decideAsync">The external durable decision, or null for an in-memory decision.</param>
/// <param name="cancellationToken">Cancels before publication.</param>
/// <returns>The authoritative committed result.</returns>
/// <exception cref="NodeManagerLifecycleConflictException">
/// Another publication changed an input of the prepared changes; nothing was published. Prepare again to retry.
/// </exception>
ValueTask<LifecycleResult> CommitAsync(
Func<CancellationToken, ValueTask>? decideAsync = null, CancellationToken cancellationToken = default);

Expand All @@ -118,6 +121,9 @@ ValueTask<LifecycleResult> CommitAsync(
/// </param>
/// <param name="cancellationToken">Cancels before publication.</param>
/// <returns>The authoritative committed result.</returns>
/// <exception cref="NodeManagerLifecycleConflictException">
/// Another publication changed an input of the prepared changes; nothing was published. Prepare again to retry.
/// </exception>
ValueTask<LifecycleResult> CommitAsync(
Func<CancellationToken, ValueTask>? decideAsync,
Action publishCommittedState,
Expand All @@ -130,6 +136,9 @@ ValueTask<LifecycleResult> CommitAsync(
/// <param name="publishCommittedState">Optional application state to install after the routing swap.</param>
/// <param name="cancellationToken">Cancels before publication.</param>
/// <returns>The authoritative committed result.</returns>
/// <exception cref="NodeManagerLifecycleConflictException">
/// Another publication changed an input of the prepared changes; nothing was published. Prepare again to retry.
/// </exception>
ValueTask<LifecycleResult> CommitWithDecisionAsync(
Func<NodeManagerDecisionContext, CancellationToken, ValueTask> decideAsync,
Action? publishCommittedState = null,
Expand All @@ -141,6 +150,9 @@ ValueTask<LifecycleResult> CommitWithDecisionAsync(
/// <param name="decisionContext">The context supplied to the durable decision.</param>
/// <param name="cancellationToken">Cancels before publication.</param>
/// <returns>The authoritative committed result.</returns>
/// <exception cref="NodeManagerLifecycleConflictException">
/// Another publication changed an input of the prepared changes; nothing was published. Prepare again to retry.
/// </exception>
ValueTask<LifecycleResult> CommitInMemoryAsync(
NodeManagerDecisionContext decisionContext,
CancellationToken cancellationToken);
Expand Down
3 changes: 3 additions & 0 deletions src/Opc.Ua.Server/NodeManager/Lifecycle/LifecycleChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public static IAsyncNodeManagerFactory AsAsync(this INodeManagerFactory factory)
/// <param name="changes">The additions, replacements and removals.</param>
/// <param name="cancellationToken">Cancels preparation or the pre-publication decision.</param>
/// <returns>The authoritative committed result, including any reconciliation issues.</returns>
/// <exception cref="NodeManagerLifecycleConflictException">
/// Another publication changed an input of the prepared changes; nothing was published. Apply again to retry.
/// </exception>
/// <exception cref="ArgumentNullException"><paramref name="lifecycle"/> is null.</exception>
public static async ValueTask<LifecycleResult> ApplyAsync(
this INodeManagerLifecycle lifecycle,
Expand Down
7 changes: 6 additions & 1 deletion src/Opc.Ua.Server/NodeManager/Lifecycle/LifecycleWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,14 @@ internal void ValidateRevision(IServerInternal? server = null)
lock (m_state)
{
PublicationRevision revision = Revision;
if (!revision.IsCurrent() || (server is not null && !revision.MatchesServer(server)))
if (revision.Owner.m_publicationFailed)
{
throw new InvalidOperationException(
"The NodeManager lifecycle failed after a durable decision; restart the server to recover.");
}
if (!revision.IsCurrent() || (server is not null && !revision.MatchesServer(server)))
{
throw new NodeManagerLifecycleConflictException(
"The publication invocation conflicts with a newer address-space revision.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ internal static bool IsSelected(IDynamicNodeManagerHost host, NodeManagerGenerat
EnsureSameRunningServer(batch.Server, batch.Host, null);
BatchEntry entry = batch.Entries[0];
NodeManagerGeneration predecessor = entry.Current!.Registration.Identity;
if (!ReferenceEquals(batch.Host.RoutingRevision, batch.RoutingRevision) ||
// A commit on other managers moves the view without touching the predecessor; the commit rebases it.
if ((!CanRebase(batch) && !ReferenceEquals(batch.Host.RoutingRevision, batch.RoutingRevision)) ||
!IsSelected(batch.Host, predecessor) || !IsCurrentRegistration(entry.Current.Registration))
{
throw new NodeManagerRoutingConflictException(
Expand Down
Loading
Loading