Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Server] Restore durable subscriptions on Server Restart #3025

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

romanett
Copy link
Contributor

@romanett romanett commented Mar 4, 2025

Proposed changes

This PR Enables the Server to persist existing durable subscriptions (incl message queue) on a server shutdown (incl. MonitoredItems & event / datatchange queues). And restore them after a server restart.

The persisting is done by extending Subscription & MonitoredItem with a method that converts the internal state of the object into a format that can be json serialized.

For this Subscription has a new Method public IStoredSubscription ToStorableSubscription().
The IMonitoredItem interface is extended with a new Method IStoredMonitoredItem ToStorableMonitoredItem().
Both Subscription & Monitoreditem have a new constructor accepting an IStoredSubscription/IStoredMonitoredItem.

The MasterNodeManager has a new Method

public virtual void RestoreMonitoredItems(
     IList<IStoredMonitoredItem> itemsToRestore,
     IList<IMonitoredItem> monitoredItems,
     IUserIdentity savedOwnerIdentity)

Also INodeManager is extended with a new Method

 void RestoreMonitoredItems(
     IList<IStoredMonitoredItem> itemsToRestore,
     IList<IMonitoredItem> monitoredItems,
     IUserIdentity savedOwnerIdentity)

Those methods are only called (& need to be implemented) if durable subscriptions will be supported by the server.

They will be called by the SubscriptionManager on Startup if subscriptions to restore a found.

The SubscriptionManager has access to an Interface ISubscriptionStore that is registered globally in the server.

The Interface has methods for Storing & Restoring Subscriptions & providing access to durable queues after a restart.
In the reference server the SubscriptionStore impementation communicates with the IMonitoredItemQueueManager to store & restore durable queues.

On Shutdown the SubscriptionManager will initate the storing process if an ISubscriptionStore is registered & durable subscriptions are enabled & present on the server.

In the reference server the serializable objects are written into a file in the current exectuting directory.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

Open Issues:

  • Restore of Event Filter fails with Opc.Ua.ServiceResultException: FilterOperand is not supported.

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 80.47210% with 91 lines in your changes missing coverage. Please review.

Project coverage is 57.01%. Comparing base (ef9387b) to head (8bd75a1).

Files with missing lines Patch % Lines
...Server/Subscription/MonitoredItem/MonitoredItem.cs 74.07% 20 Missing and 8 partials ⚠️
...aries/Opc.Ua.Server/NodeManager/CoreNodeManager.cs 38.09% 9 Missing and 4 partials ⚠️
...ies/Opc.Ua.Server/NodeManager/MasterNodeManager.cs 71.79% 6 Missing and 5 partials ⚠️
.../Opc.Ua.Server/Subscription/SubscriptionManager.cs 81.03% 8 Missing and 3 partials ⚠️
...braries/Opc.Ua.Server/NodeManager/SamplingGroup.cs 0.00% 10 Missing ⚠️
...ies/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs 85.45% 3 Missing and 5 partials ⚠️
.../Opc.Ua.Server/NodeManager/SamplingGroupManager.cs 0.00% 7 Missing ⚠️
...braries/Opc.Ua.Server/Subscription/Subscription.cs 97.74% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3025      +/-   ##
==========================================
+ Coverage   56.70%   57.01%   +0.30%     
==========================================
  Files         356      356              
  Lines       68110    68529     +419     
  Branches    13950    14009      +59     
==========================================
+ Hits        38619    39069     +450     
+ Misses      25339    25295      -44     
- Partials     4152     4165      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant