Skip to content

Commit 9aa0001

Browse files
author
Razvan Becheriu
committed
[#3710] addressed review comments
1 parent d29fbd9 commit 9aa0001

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed

src/lib/dhcpsrv/legal_log_mgr_factory.cc

+28
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ LegalLogMgrFactory::addBackend(DatabaseConnection::ParameterMap& parameters, Man
118118
pool_[id] = pair<DatabaseConnection::ParameterMap, LegalLogMgrPtr>(parameters, backend);
119119
}
120120

121+
void
122+
LegalLogMgrFactory::delAllBackends() {
123+
pool_.clear();
124+
}
125+
126+
void
127+
LegalLogMgrFactory::delAllBackends(const std::string& db_type) {
128+
auto it = pool_.begin();
129+
130+
while (it != pool_.end()) {
131+
if (it->second.second && it->second.second->getType() == db_type) {
132+
it = pool_.erase(it);
133+
} else {
134+
++it;
135+
}
136+
}
137+
}
138+
121139
LegalLogMgrPtr&
122140
LegalLogMgrFactory::instance(ManagerID id) {
123141
auto it = pool_.find(id);
@@ -234,6 +252,16 @@ LegalLogMgrFactory::getDBVersions() {
234252
return (result);
235253
}
236254

255+
bool
256+
LegalLogMgrFactory::haveInstance(std::string type) {
257+
for (auto const& backend : pool_) {
258+
if (backend.second.second && backend.second.second->getType() == type) {
259+
return (true);
260+
}
261+
}
262+
return (false);
263+
}
264+
237265
} // end of namespace isc::dhcp
238266
} // end of namespace isc
239267

src/lib/dhcpsrv/legal_log_mgr_factory.h

+7-26
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ class LegalLogMgrFactory : public boost::noncopyable {
8787
static void addBackend(db::DatabaseConnection::ParameterMap& parameters, ManagerID id = 0);
8888

8989
/// @brief Removes all backends from the pool.
90-
static void delAllBackends() {
91-
pool_.clear();
92-
}
90+
static void delAllBackends();
91+
92+
/// @brief Deletes all backends of the given type from the pool.
93+
///
94+
/// @param db_type backend to remove.
95+
static void delAllBackends(const std::string& db_type);
9396

9497
/// @brief Returns the forensic backend manager with specified ID.
9598
///
@@ -98,21 +101,6 @@ class LegalLogMgrFactory : public boost::noncopyable {
98101
/// @return the forensic backend manager instance or null pointer.
99102
static LegalLogMgrPtr& instance(ManagerID id = 0);
100103

101-
/// @brief Deletes all backends of the given type from the pool.
102-
///
103-
/// @param db_type backend to remove.
104-
static void delAllBackends(const std::string& db_type) {
105-
auto it = pool_.begin();
106-
107-
while (it != pool_.end()) {
108-
if (it->second.second && it->second.second->getType() == db_type) {
109-
it = pool_.erase(it);
110-
} else {
111-
++it;
112-
}
113-
}
114-
}
115-
116104
/// @brief Sets the forensic backend manager parameters.
117105
///
118106
/// @param parameters database parameters.
@@ -182,14 +170,7 @@ class LegalLogMgrFactory : public boost::noncopyable {
182170
/// @brief Returns true is respective backend store is present, false otherwise.
183171
///
184172
/// @param type the backend store type to check if it exists.
185-
static bool haveInstance(std::string type) {
186-
for (auto const& backend : pool_) {
187-
if (backend.second.second && backend.second.second->getType() == type) {
188-
return (true);
189-
}
190-
}
191-
return (false);
192-
}
173+
static bool haveInstance(std::string type);
193174

194175
/// @brief Get the hook I/O service.
195176
///

src/lib/mysql/mysql_connection.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,13 @@ MySqlConnection::openDatabase() {
282282
MYSQL* status = mysql_real_connect(mysql_, host, user, password, name,
283283
port, NULL, CLIENT_FOUND_ROWS);
284284
if (status != mysql_) {
285+
// Mark this connection as no longer usable.
286+
markUnusable();
287+
285288
std::string error_message = mysql_error(mysql_);
286289

287290
auto const& rec = reconnectCtl();
288291
if (rec && DatabaseConnection::retry_) {
289-
// Mark this connection as no longer usable.
290-
markUnusable();
291292

292293
// Start the connection recovery.
293294
startRecoverDbConnection();

src/lib/pgsql/pgsql_connection.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,16 @@ PgSqlConnection::openDatabaseInternal(bool logging) {
414414
}
415415

416416
if (PQstatus(new_conn) != CONNECTION_OK) {
417+
// Mark this connection as no longer usable.
418+
markUnusable();
419+
417420
// If we have a connection object, we have to call finish
418421
// to release it, but grab the error message first.
419422
std::string error_message = PQerrorMessage(new_conn);
420423
PQfinish(new_conn);
421424

422425
auto const& rec = reconnectCtl();
423426
if (rec && DatabaseConnection::retry_) {
424-
// Mark this connection as no longer usable.
425-
markUnusable();
426427

427428
// Start the connection recovery.
428429
startRecoverDbConnection();

0 commit comments

Comments
 (0)