RTI Connext Modern C++ API Version 7.2.0
dds::core::policy::Ownership Class Reference

Specifies whether it is allowed for multiple dds::pub::DataWriter's to write the same instance of the data and if so, how these modifications should be arbitrated. More...

#include <dds/core/policy/CorePolicy.hpp>

Public Member Functions

 Ownership ()
 Creates an ownership policy set to shared. More...
 
 Ownership (dds::core::policy::OwnershipKind the_kind)
 Creates an instance with the specified ownership kind. More...
 
Ownershipkind (dds::core::policy::OwnershipKind the_kind)
 Sets the ownership kind. More...
 
dds::core::policy::OwnershipKind kind () const
 Getter (see setter with the same name) More...
 

Static Public Member Functions

static Ownership Exclusive ()
 Creates a Ownership instance with exclusive kind. More...
 
static Ownership Shared ()
 Creates a Ownership instance with shared kind. More...
 

Detailed Description

Specifies whether it is allowed for multiple dds::pub::DataWriter's to write the same instance of the data and if so, how these modifications should be arbitrated.

Entity:
dds::topic::Topic, dds::sub::DataReader, dds::pub::DataWriter
Status:
dds::core::status::StatusMask::offered_incompatible_qos(), dds::core::status::StatusMask::requested_incompatible_qos()
Properties:
RxO = YES
Changeable = UNTIL ENABLE
See also
OWNERSHIP_STRENGTH

Usage

Along with the OWNERSHIP_STRENGTH, this QoS policy specifies if dds::sub::DataReader entities can receive updates to the same instance (identified by its key) from multiple dds::pub::DataWriter entities at the same time.

There are two kinds of ownership, selected by the setting of the kind: SHARED and EXCLUSIVE.

SHARED ownership

dds::core::policy::OwnershipKind_def::SHARED indicates that RTI Connext does not enforce unique ownership for each instance. In this case, multiple writers can update the same data type instance. The subscriber to the dds::topic::Topic will be able to access modifications from all dds::pub::DataWriter objects, subject to the settings of other QoS that may filter particular samples (e.g. the TIME_BASED_FILTER or HISTORY policy). In any case, there is no "filtering" of modifications made based on the identity of the dds::pub::DataWriter that causes the modification.

EXCLUSIVE ownership

dds::core::policy::OwnershipKind_def::EXCLUSIVE indicates that each instance of a data type can only be modified by one dds::pub::DataWriter. In other words, at any point in time, a single dds::pub::DataWriter owns each instance and is the only one whose modifications will be visible to the dds::sub::DataReader objects. The owner is determined by selecting the dds::pub::DataWriter with the highest value of the dds::core::policy::OwnershipStrength::value that is currently alive, as defined by the LIVELINESS policy, and has not violated its DEADLINE contract with regards to the data instance.

Ownership can therefore change as a result of:

The behavior of the system is as if the determination was made independently by each dds::sub::DataReader. Each dds::sub::DataReader may detect the change of ownership at a different time. It is not a requirement that at a particular point in time all the dds::sub::DataReader objects for that dds::topic::Topic have a consistent picture of who owns each instance.

It is also not a requirement that the dds::pub::DataWriter objects are aware of whether they own a particular instance. There is no error or notification given to a dds::pub::DataWriter that modifies an instance it does not currently own.

The requirements are chosen to (a) preserve the decoupling of publishers and subscriber, and (b) allow the policy to be implemented efficiently.

It is possible that multiple dds::pub::DataWriter objects with the same strength modify the same instance. If this occurs RTI Connext will pick one of the dds::pub::DataWriter objects as the owner. It is not specified how the owner is selected. However, the algorithm used to select the owner guarantees that all dds::sub::DataReader objects will make the same choice of the particular dds::pub::DataWriter that is the owner. It also guarantees that the owner remains the same until there is a change in strength, liveliness, the owner misses a deadline on the instance, or a new dds::pub::DataWriter with higher same strength, or a new dds::pub::DataWriter with same strength that should be deemed the owner according to the policy of the Service, modifies the instance.

Exclusive ownership is on an instance-by-instance basis. That is, a subscriber can receive values written by a lower strength dds::pub::DataWriter as long as they affect instances whose values have not been set by the higher-strength dds::pub::DataWriter.

Compatibility

The value of the dds::core::policy::OwnershipKind_def offered must exactly match the one requested or else they are considered incompatible.

Relationship between registration, liveliness and ownership

The need for registering/unregistering instances stems from two use cases:

  • Detection of loss in topological connectivity

These two use cases also illustrate the semantic differences between the dds::pub::DataWriter::unregister_instance and dds::pub::DataWriter::dispose_instance().

Ownership Resolution on Redundant Systems

It is expected that users may use DDS to set up redundant systems where multiple dds::pub::DataWriter entities are "capable" of writing the same instance. In this situation, the dds::pub::DataWriter entities are configured such that:

  • Either both are writing the instance "constantly"
  • Or else they use some mechanism to classify each other as "primary" and "secondary", such that the primary is the only one writing, and the secondary monitors the primary and only writes when it detects that the primary "writer" is no longer writing.

Both cases above use the dds::core::policy::OwnershipKind_def::EXCLUSIVE and arbitrate themselves by means of the dds::core::policy::OwnershipStrength. Regardless of the scheme, the desired behavior from the dds::sub::DataReader point of view is that dds::sub::DataReader normally receives data from the primary unless the "primary" writer stops writing, in which case the dds::sub::DataReader starts to receive data from the secondary dds::pub::DataWriter.

This approach requires some mechanism to detect that a dds::pub::DataWriter (the primary) is no longer "writing" the data as it should. There are several reasons why this may happen and all must be detected (but not necessarily distinguished):

  • [crash] The writing process is no longer running (e.g. the whole application has crashed)
  • [connectivity loss] Connectivity to the writing application has been lost (e.g. network disconnection)

Arbitrating from a dds::pub::DataWriter to one of a higher strength is simple and the decision can be taken autonomously by the dds::sub::DataReader. Switching ownership from a higher strength dds::pub::DataWriter to one of a lower strength dds::pub::DataWriter requires that the dds::sub::DataReader can make a determination that the stronger dds::pub::DataWriter is "no longer writing the instance".

Case where the data is periodically updated

This determination is reasonably simple when the data is being written periodically at some rate. The dds::pub::DataWriter simply states its offered dds::core::policy::Deadline (maximum interval between updates) and the dds::sub::DataReader automatically monitors that the dds::pub::DataWriter indeed updates the instance at least once per dds::core::policy::Deadline::period. If the deadline is missed, the dds::sub::DataReader considers the dds::pub::DataWriter "not alive" and automatically gives ownership to the next highest-strength dds::pub::DataWriter that is alive.

Case where data is not periodically updated

The case where the dds::pub::DataWriter is not writing data periodically is also a very important use-case. Since the instance is not being updated at any fixed period, the "deadline" mechanism cannot be used to determine ownership. The liveliness solves this situation. Ownership is maintained while the dds::pub::DataWriter is "alive" and for the dds::pub::DataWriter to be alive it must fulfill its dds::core::policy::Liveliness contract. The different means to renew liveliness (automatic, manual) combined by the implied renewal each time data is written handle the three conditions above [crash], [connectivity loss], and [application fault]. Note that to handle [application fault], LIVELINESS must be dds::core::policy::LivelinessKind::MANUAL_BY_TOPIC. The dds::pub::DataWriter can retain ownership by periodically writing data or else calling assert_liveliness if it has no data to write. Alternatively if only protection against [crash] or [connectivity loss] is desired, it is sufficient that some task on the dds::pub::DataWriter process periodically writes data or calls dds::domain::DomainParticipant::assert_liveliness. However, this scenario requires that the dds::sub::DataReader knows what instances are being "written" by the dds::pub::DataWriter. That is the only way that the dds::sub::DataReader deduces the ownership of specific instances from the fact that the dds::pub::DataWriter is still "alive". Hence the need for the dds::pub::DataWriter to "register" and "unregister" instances. Note that while "registration" can be done lazily the first time the dds::pub::DataWriter writes the instance, "unregistration," in general, cannot. Similar reasoning will lead to the fact that unregistration will also require a message to be sent to the dds::sub::DataReader.

Detection of Loss in Topological Connectivity

There are applications that are designed in such a way that their correct operation requires some minimal topological connectivity, that is, the writer needs to have a minimum number of readers or alternatively the reader must have a minimum number of writers.

A common scenario is that the application does not start doing its logic until it knows that some specific writers have the minimum configured readers (e.g the alarm monitor is up).

A more common scenario is that the application logic will wait until some writers appear that can provide some needed source of information (e.g. the raw sensor data that must be processed).

Furthermore, once the application is running it is a requirement that this minimal connectivity (from the source of the data) is monitored and the application informed if it is ever lost. For the case where data is being written periodically, the dds::core::policy::Deadline and the on_deadline_missed listener provides the notification. The case where data is not periodically updated requires the use of the dds::core::policy::Liveliness in combination with register_instance/unregister_instance to detect whether the "connectivity" has been lost, and the notification is provided by means of dds::sub::status::InstanceState::not_alive_no_writers().

In terms of the required mechanisms, the scenario is very similar to the case of maintaining ownership. In both cases, the reader needs to know whether a writer is still "managing the current value of an instance" even though it is not continually writing it and this knowledge requires the writer to keep its liveliness plus some means to know which instances the writer is currently "managing" (i.e. the registered instances).

Semantic Difference between unregister_instance and dispose

dds::pub::DataWriter::dispose_instance() is semantically different from dds::pub::DataWriter::unregister_instance. dds::pub::DataWriter::dispose_instance() indicates that the data instance no longer exists (e.g. a track that has disappeared, a simulation entity that has been destroyed, a record entry that has been deleted, etc.) whereas dds::pub::DataWriter::unregister_instance indicates that the writer is no longer taking responsibility for updating the value of the instance.

Deleting a dds::pub::DataWriter is equivalent to unregistering all the instances it was writing, but is not the same as "disposing" all the instances.

For a dds::topic::Topic with dds::core::policy::OwnershipKind_def::EXCLUSIVE, if the current owner of an instance disposes it, the readers accessing the instance will see the instance_state as being "DISPOSED" and not see the values being written by the weaker writer (even after the stronger one has disposed the instance). This is because the dds::pub::DataWriter that owns the instance is saying that the instance no longer exists (e.g. the master of the database is saying that a record has been deleted) and thus the readers should see it as such.

For a dds::topic::Topic with dds::core::policy::OwnershipKind_def::EXCLUSIVE, if the current owner of an instance unregisters it, then it will relinquish ownership of the instance and thus the readers may see the value updated by another writer (which will then become the owner). This is because the owner said that it no longer will be providing values for the instance and thus another writer can take ownership and provide those values.

Constructor & Destructor Documentation

◆ Ownership() [1/2]

dds::core::policy::Ownership::Ownership ( )
inline

Creates an ownership policy set to shared.

◆ Ownership() [2/2]

dds::core::policy::Ownership::Ownership ( dds::core::policy::OwnershipKind  the_kind)
inlineexplicit

Creates an instance with the specified ownership kind.

Member Function Documentation

◆ kind() [1/2]

Ownership & dds::core::policy::Ownership::kind ( dds::core::policy::OwnershipKind  the_kind)
inline

Sets the ownership kind.

[default] dds::core::policy::OwnershipKind_def::SHARED

◆ kind() [2/2]

dds::core::policy::OwnershipKind dds::core::policy::Ownership::kind ( ) const
inline

Getter (see setter with the same name)

◆ Exclusive()

static Ownership dds::core::policy::Ownership::Exclusive ( )
inlinestatic

Creates a Ownership instance with exclusive kind.

◆ Shared()

static Ownership dds::core::policy::Ownership::Shared ( )
inlinestatic

Creates a Ownership instance with shared kind.