From 475ca22f69a5158efa42a7c8c85dc94113990925 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Mon, 29 Apr 2024 11:45:44 +0200 Subject: [PATCH 1/2] Refs #20936: Move Restore method to enable instead of init Signed-off-by: cferreiragonz --- .../rtps/builtin/discovery/participant/PDP.h | 2 +- .../discovery/participant/PDPServer.cpp | 66 ++++++++++--------- .../discovery/participant/PDPServer.hpp | 7 ++ 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.h b/src/cpp/rtps/builtin/discovery/participant/PDP.h index fc90bd73199..f628a76e83d 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.h +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.h @@ -129,7 +129,7 @@ class PDP : public fastdds::statistics::rtps::IProxyQueryable * * @return true if enabled correctly, or if already enabled; false otherwise */ - bool enable(); + virtual bool enable(); /** * @brief Disable the Participant Discovery Protocol diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index 0eaed35dc02..63d13679ef0 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -120,35 +120,6 @@ bool PDPServer::init( return false; } - std::vector backup_queue; - if (durability_ == TRANSIENT) - { - nlohmann::json backup_json; - // If the DS is BACKUP, try to restore DDB from file - discovery_db().backup_in_progress(true); - if (read_backup(backup_json, backup_queue)) - { - if (process_backup_discovery_database_restore(backup_json)) - { - EPROSIMA_LOG_INFO(RTPS_PDP_SERVER, "DiscoveryDataBase restored correctly"); - } - } - else - { - EPROSIMA_LOG_INFO(RTPS_PDP_SERVER, - "Error reading backup file. Corrupted or unmissing file, restarting from scratch"); - } - - discovery_db().backup_in_progress(false); - - discovery_db_.persistence_enable(get_ddb_queue_persistence_file_name()); - } - else - { - // Allows the ddb to process new messages from this point - discovery_db_.enable(); - } - // Activate listeners EDPServer* edp = static_cast(mp_EDP); builtin_endpoints_->enable_pdp_readers(getRTPSParticipant()); @@ -178,6 +149,41 @@ bool PDPServer::init( m_discovery.discovery_config.discoveryServer_client_syncperiod)); ping_->restart_timer(); + return true; +} + +bool PDPServer::enable() +{ + std::vector backup_queue; + // Restore the DDB from file if this is a BACKUP server + if (durability_ == TRANSIENT) + { + nlohmann::json backup_json; + // If the DS is BACKUP, try to restore DDB from file + discovery_db().backup_in_progress(true); + if (read_backup(backup_json, backup_queue)) + { + if (process_backup_discovery_database_restore(backup_json)) + { + EPROSIMA_LOG_INFO(RTPS_PDP_SERVER, "DiscoveryDataBase restored correctly"); + } + } + else + { + EPROSIMA_LOG_INFO(RTPS_PDP_SERVER, + "Error reading backup file. Corrupted or unmissing file, restarting from scratch"); + } + + discovery_db().backup_in_progress(false); + + discovery_db_.persistence_enable(get_ddb_queue_persistence_file_name()); + } + else + { + // Allows the ddb to process new messages from this point + discovery_db_.enable(); + } + // Restoring the queue must be done after starting the routine if (durability_ == TRANSIENT) { @@ -185,7 +191,7 @@ bool PDPServer::init( process_backup_restore_queue(backup_queue); } - return true; + return PDP::enable(); } ParticipantProxyData* PDPServer::createParticipantProxyData( diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp index b5b01f6f658..956fad7c65a 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp @@ -79,6 +79,13 @@ class PDPServer : public fastrtps::rtps::PDP bool init( fastrtps::rtps::RTPSParticipantImpl* part) override; + /** + * @brief Enable the Participant Discovery Protocol and checks if a backup file + * needs to be restored for DiscoveryProtocol_t::BACKUP. + * + * @return true if enabled correctly, or if already enabled; false otherwise + */ + bool enable() override; /** * Creates an initializes a new participant proxy from a DATA(p) raw info * @param p ParticipantProxyData from DATA msg deserialization From d490fad4deefd04930a91dbf8bbe5b6196ca1050 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Wed, 12 Jun 2024 13:02:42 +0200 Subject: [PATCH 2/2] Refs #20936: Revision Signed-off-by: cferreiragonz --- src/cpp/rtps/builtin/discovery/participant/PDP.cpp | 8 ++++++++ src/cpp/rtps/builtin/discovery/participant/PDP.h | 7 ++++++- src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp | 4 +--- src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp | 9 ++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp index 235fefc2d89..f5b4cd1d77c 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp @@ -413,6 +413,9 @@ bool PDP::enable() return true; } + // Perform pre-enable actions (if any) + pre_enable_actions(); + // Create lease events on already created proxy data objects for (ParticipantProxyData* pool_item : participant_proxies_pool_) { @@ -443,6 +446,11 @@ bool PDP::enable() return builtin_endpoints_->enable_pdp_readers(mp_RTPSParticipant); } +void PDP::pre_enable_actions() +{ + // Empty implementation +} + void PDP::disable() { // Extract all the participant proxies excluding first one (ourselves) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.h b/src/cpp/rtps/builtin/discovery/participant/PDP.h index f628a76e83d..5c809f2aba1 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.h +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.h @@ -129,7 +129,12 @@ class PDP : public fastdds::statistics::rtps::IProxyQueryable * * @return true if enabled correctly, or if already enabled; false otherwise */ - virtual bool enable(); + bool enable(); + + /** + * @brief Perform actions before enabling the Participant Discovery Protocol if needed + */ + virtual void pre_enable_actions(); /** * @brief Disable the Participant Discovery Protocol diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index 63d13679ef0..f642fe01d45 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -152,7 +152,7 @@ bool PDPServer::init( return true; } -bool PDPServer::enable() +void PDPServer::pre_enable_actions() { std::vector backup_queue; // Restore the DDB from file if this is a BACKUP server @@ -190,8 +190,6 @@ bool PDPServer::enable() // This vector is empty till backup queue is implemented process_backup_restore_queue(backup_queue); } - - return PDP::enable(); } ParticipantProxyData* PDPServer::createParticipantProxyData( diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp index 956fad7c65a..a2904ff6497 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp @@ -80,12 +80,11 @@ class PDPServer : public fastrtps::rtps::PDP fastrtps::rtps::RTPSParticipantImpl* part) override; /** - * @brief Enable the Participant Discovery Protocol and checks if a backup file - * needs to be restored for DiscoveryProtocol_t::BACKUP. - * - * @return true if enabled correctly, or if already enabled; false otherwise + * @brief Checks if a backup file needs to be restored for + * DiscoveryProtocol_t::BACKUP before enabling the Participant Discovery Protocol */ - bool enable() override; + void pre_enable_actions() override; + /** * Creates an initializes a new participant proxy from a DATA(p) raw info * @param p ParticipantProxyData from DATA msg deserialization