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

[20936] Change backup restore order #4740

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
{
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class PDP : public fastdds::statistics::rtps::IProxyQueryable
*/
bool enable();

/**
* @brief Perform actions before enabling the Participant Discovery Protocol if needed
*/
virtual void pre_enable_actions();

/**
* @brief Disable the Participant Discovery Protocol
*/
Expand Down
66 changes: 35 additions & 31 deletions src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,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 @@ -178,14 +149,47 @@ bool PDPServer::init(
m_discovery.discovery_config.discoveryServer_client_syncperiod));
ping_->restart_timer();

return true;
}

void PDPServer::pre_enable_actions()
{
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;
}

ParticipantProxyData* PDPServer::createParticipantProxyData(
Expand Down
6 changes: 6 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,12 @@ class PDPServer : public fastrtps::rtps::PDP
bool init(
fastrtps::rtps::RTPSParticipantImpl* part) override;

/**
* @brief Checks if a backup file needs to be restored for
* DiscoveryProtocol_t::BACKUP before enabling the Participant Discovery Protocol
*/
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
Expand Down
Loading