Skip to content

Commit a2ab9b9

Browse files
committed
Refs #20936: Move Restore method to enable instead of init
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
1 parent 08ee62b commit a2ab9b9

3 files changed

Lines changed: 44 additions & 31 deletions

File tree

src/cpp/rtps/builtin/discovery/participant/PDP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class PDP : public fastdds::statistics::rtps::IProxyQueryable
129129
*
130130
* @return true if enabled correctly, or if already enabled; false otherwise
131131
*/
132-
bool enable();
132+
virtual bool enable();
133133

134134
virtual bool init(
135135
RTPSParticipantImpl* part) = 0;

src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,35 +119,6 @@ bool PDPServer::init(
119119
return false;
120120
}
121121

122-
std::vector<nlohmann::json> backup_queue;
123-
if (durability_ == TRANSIENT)
124-
{
125-
nlohmann::json backup_json;
126-
// If the DS is BACKUP, try to restore DDB from file
127-
discovery_db().backup_in_progress(true);
128-
if (read_backup(backup_json, backup_queue))
129-
{
130-
if (process_backup_discovery_database_restore(backup_json))
131-
{
132-
EPROSIMA_LOG_INFO(RTPS_PDP_SERVER, "DiscoveryDataBase restored correctly");
133-
}
134-
}
135-
else
136-
{
137-
EPROSIMA_LOG_INFO(RTPS_PDP_SERVER,
138-
"Error reading backup file. Corrupted or unmissing file, restarting from scratch");
139-
}
140-
141-
discovery_db().backup_in_progress(false);
142-
143-
discovery_db_.persistence_enable(get_ddb_queue_persistence_file_name());
144-
}
145-
else
146-
{
147-
// Allows the ddb to process new messages from this point
148-
discovery_db_.enable();
149-
}
150-
151122
// Activate listeners
152123
EDPServer* edp = static_cast<EDPServer*>(mp_EDP);
153124
builtin_endpoints_->enable_pdp_readers(getRTPSParticipant());
@@ -177,14 +148,49 @@ bool PDPServer::init(
177148
m_discovery.discovery_config.discoveryServer_client_syncperiod));
178149
ping_->restart_timer();
179150

151+
return true;
152+
}
153+
154+
bool PDPServer::enable()
155+
{
156+
std::vector<nlohmann::json> backup_queue;
157+
// Restore the DDB from file if this is a BACKUP server
158+
if (durability_ == TRANSIENT)
159+
{
160+
nlohmann::json backup_json;
161+
// If the DS is BACKUP, try to restore DDB from file
162+
discovery_db().backup_in_progress(true);
163+
if (read_backup(backup_json, backup_queue))
164+
{
165+
if (process_backup_discovery_database_restore(backup_json))
166+
{
167+
EPROSIMA_LOG_INFO(RTPS_PDP_SERVER, "DiscoveryDataBase restored correctly");
168+
}
169+
}
170+
else
171+
{
172+
EPROSIMA_LOG_INFO(RTPS_PDP_SERVER,
173+
"Error reading backup file. Corrupted or unmissing file, restarting from scratch");
174+
}
175+
176+
discovery_db().backup_in_progress(false);
177+
178+
discovery_db_.persistence_enable(get_ddb_queue_persistence_file_name());
179+
}
180+
else
181+
{
182+
// Allows the ddb to process new messages from this point
183+
discovery_db_.enable();
184+
}
185+
180186
// Restoring the queue must be done after starting the routine
181187
if (durability_ == TRANSIENT)
182188
{
183189
// This vector is empty till backup queue is implemented
184190
process_backup_restore_queue(backup_queue);
185191
}
186192

187-
return true;
193+
return PDP::enable();
188194
}
189195

190196
ParticipantProxyData* PDPServer::createParticipantProxyData(

src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class PDPServer : public fastrtps::rtps::PDP
7979
bool init(
8080
fastrtps::rtps::RTPSParticipantImpl* part) override;
8181

82+
/**
83+
* @brief Enable the Participant Discovery Protocol and checks if a backup file
84+
* needs to restored for DiscoveryProtocol_t::BACKUP.
85+
*
86+
* @return true if enabled correctly, or if already enabled; false otherwise
87+
*/
88+
bool enable() override;
8289
/**
8390
* Creates an initializes a new participant proxy from a DATA(p) raw info
8491
* @param p ParticipantProxyData from DATA msg deserialization

0 commit comments

Comments
 (0)