Skip to content

Commit

Permalink
Refs #20936: Move Restore method to enable instead of init
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
  • Loading branch information
cferreiragonz committed May 13, 2024
1 parent 08ee62b commit 1a59486
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

virtual bool init(
RTPSParticipantImpl* part) = 0;
Expand Down
66 changes: 36 additions & 30 deletions src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,6 @@ bool PDPServer::init(
return false;
}

std::vector<nlohmann::json> 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<EDPServer*>(mp_EDP);
builtin_endpoints_->enable_pdp_readers(getRTPSParticipant());
Expand Down Expand Up @@ -177,14 +148,49 @@ bool PDPServer::init(
m_discovery.discovery_config.discoveryServer_client_syncperiod));
ping_->restart_timer();

return true;
}

bool PDPServer::enable()
{
std::vector<nlohmann::json> 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)
{
// This vector is empty till backup queue is implemented
process_backup_restore_queue(backup_queue);
}

return true;
return PDP::enable();
}

ParticipantProxyData* PDPServer::createParticipantProxyData(
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a59486

Please sign in to comment.