Class astutedds::dcps::PersistenceService
ClassList > astutedds > dcps > PersistenceService
OMG-compliant DDS Persistence Service. More...
#include <persistence_service.hpp>
Public Functions
| Type | Name |
|---|---|
| PersistenceService (const PersistenceService &) = delete |
|
| PersistenceService (PersistenceService &&) = delete |
|
| std::vector< PersistedSample > | get_samples (const std::string & topic_name) Return all stored samples for the given topic. |
| bool | has_samples (const std::string & topic_name) const Return true when the service has any samples for the topic. |
| void | notify_writer_deleted (const std::string & topic_name) Notify the service that all writers for a topic have been deleted. |
| PersistenceService & | operator= (const PersistenceService &) = delete |
| PersistenceService & | operator= (PersistenceService &&) = delete |
| const std::string & | persistence_dir () const Return the current persistence directory. |
| void | purge_persistent_store (const std::string & topic_name) Permanently delete the on-disk store for a PERSISTENT topic. |
| void | remove_topic (const std::string & topic_name) Remove the in-memory store for a topic immediately. |
| std::size_t | sample_count (const std::string & topic_name) const Return the number of stored samples for the topic. |
| void | set_persistence_dir (const std::string & dir) Set the directory used for PERSISTENT storage. |
| void | store_sample (const std::string & topic_name, DurabilityQosPolicyKind durability, const DurabilityServiceQosPolicy & service_qos, const CacheChange & change) Store a data sample for the given topic. |
Public Static Functions
| Type | Name |
|---|---|
| PersistenceService & | instance () Return the process-level singleton instance. |
Detailed Description
Acts as the backend storage for DataWriters with TRANSIENT or PERSISTENT durability QoS (DDS 1.4 ยง2.2.3.4). The service is a process-level singleton; applications interact with it via the static instance() method.
TRANSIENT mode
Samples are kept in an in-memory ring-buffer governed by the DurabilityServiceQosPolicy of the DataWriter. Data does not outlive the current process.
PERSISTENT mode
Samples are additionally written to a per-topic binary file in persistence_dir_. On startup, or the first time a topic is requested, the service automatically loads any previously persisted samples so that late-joining readers receive data written in earlier process runs.
Cleanup
The DurabilityServiceQosPolicy::service_cleanup_delay field is honoured: after all local writers for a topic are deleted, the service waits that long before purging the in-memory cache (TRANSIENT) or truncating the on-disk file (PERSISTENT).
Thread safety: all public methods are guarded by an internal mutex.
Public Functions Documentation
function PersistenceService [1/3]
astutedds::dcps::PersistenceService::PersistenceService (
const PersistenceService &
) = delete
function PersistenceService [2/3]
astutedds::dcps::PersistenceService::PersistenceService (
PersistenceService &&
) = delete
function get_samples
Return all stored samples for the given topic.
std::vector< PersistedSample > astutedds::dcps::PersistenceService::get_samples (
const std::string & topic_name
)
Called by DomainParticipant when a late-joining DataReader with TRANSIENT or PERSISTENT durability is matched against a writer.
For PERSISTENT topics, the service will load data from disk if the in-memory cache is empty (e.g. first access after a restart).
Parameters:
topic_nameName of the DDS topic.
Returns:
Ordered (oldest-first) vector of persisted samples.
function has_samples
Return true when the service has any samples for the topic.
bool astutedds::dcps::PersistenceService::has_samples (
const std::string & topic_name
) const
function notify_writer_deleted
Notify the service that all writers for a topic have been deleted.
void astutedds::dcps::PersistenceService::notify_writer_deleted (
const std::string & topic_name
)
After the service_cleanup_delay elapses, the in-memory cache is purged. For PERSISTENT topics the on-disk file is NOT removed, ensuring data survives across restarts.
Parameters:
topic_nameName of the DDS topic.
function operator=
PersistenceService & astutedds::dcps::PersistenceService::operator= (
const PersistenceService &
) = delete
function operator=
PersistenceService & astutedds::dcps::PersistenceService::operator= (
PersistenceService &&
) = delete
function persistence_dir
Return the current persistence directory.
inline const std::string & astutedds::dcps::PersistenceService::persistence_dir () const
function purge_persistent_store
Permanently delete the on-disk store for a PERSISTENT topic.
void astutedds::dcps::PersistenceService::purge_persistent_store (
const std::string & topic_name
)
Parameters:
topic_nameName of the DDS topic.
function remove_topic
Remove the in-memory store for a topic immediately.
void astutedds::dcps::PersistenceService::remove_topic (
const std::string & topic_name
)
For PERSISTENT topics the on-disk file is preserved so data can be recovered on the next process start.
Parameters:
topic_nameName of the DDS topic.
function sample_count
Return the number of stored samples for the topic.
std::size_t astutedds::dcps::PersistenceService::sample_count (
const std::string & topic_name
) const
function set_persistence_dir
Set the directory used for PERSISTENT storage.
void astutedds::dcps::PersistenceService::set_persistence_dir (
const std::string & dir
)
Defaults to <cwd>/.astutedds_persistence. Must be called before any PERSISTENT topic is first accessed.
Parameters:
dirAbsolute or relative path to the persistence directory.
function store_sample
Store a data sample for the given topic.
void astutedds::dcps::PersistenceService::store_sample (
const std::string & topic_name,
DurabilityQosPolicyKind durability,
const DurabilityServiceQosPolicy & service_qos,
const CacheChange & change
)
Called by DataWriter::write() when the writer's Durability QoS is TRANSIENT_DURABILITY_QOS or PERSISTENT_DURABILITY_QOS.
The DurabilityServiceQosPolicy governs the in-memory cache limits (history kind, depth, max_samples, max_instances, max_samples_per_instance).
Parameters:
topic_nameName of the DDS topic.durabilityDurability kind (must be TRANSIENT or PERSISTENT).service_qosDurabilityServiceQosPolicy from the DataWriter.changeThe cache-change to store.
Public Static Functions Documentation
function instance
Return the process-level singleton instance.
static PersistenceService & astutedds::dcps::PersistenceService::instance ()
The documentation for this class was generated from the following file include/astutedds/dcps/persistence_service.hpp