From: Razvan Becheriu Date: Tue, 9 Jun 2020 09:46:08 +0000 (+0300) Subject: [#1239] csv lease file is now kea thread safe X-Git-Tag: Kea-1.7.9~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af1b43f8e717525d187e718bc8799b1dc0b78126;p=thirdparty%2Fkea.git [#1239] csv lease file is now kea thread safe --- diff --git a/src/lib/dhcpsrv/csv_lease_file4.cc b/src/lib/dhcpsrv/csv_lease_file4.cc index a66da20321..0336be7933 100644 --- a/src/lib/dhcpsrv/csv_lease_file4.cc +++ b/src/lib/dhcpsrv/csv_lease_file4.cc @@ -42,6 +42,22 @@ CSVLeaseFile4::openInternal(const bool seek_to_end) { clearStatistics(); } +void +CSVLeaseFile4::close() { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(mutex_); + closeInternal(); + } else { + closeInternal(); + } +} + +void +CSVLeaseFile4::closeInternal() { + // Call the base class to close the file + VersionedCSVFile::close(); +} + void CSVLeaseFile4::append(const Lease4& lease) { if (MultiThreadingMgr::instance().getMode()) { diff --git a/src/lib/dhcpsrv/csv_lease_file4.h b/src/lib/dhcpsrv/csv_lease_file4.h index 477adf7561..5802c368d7 100644 --- a/src/lib/dhcpsrv/csv_lease_file4.h +++ b/src/lib/dhcpsrv/csv_lease_file4.h @@ -50,6 +50,9 @@ public: /// the base class may do so. virtual void open(const bool seek_to_end = false); + /// @brief Closes the lease file. + virtual void close(); + /// @brief Appends the lease record to the CSV file. /// /// This function doesn't throw exceptions itself. In theory, exceptions @@ -98,6 +101,11 @@ private: /// the base class may do so. virtual void openInternal(const bool seek_to_end = false); + /// @brief Closes the lease file. + /// + /// Should be called in a thread safe context. + virtual void closeInternal(); + /// @brief Appends the lease record to the CSV file. /// /// Should be called in a thread safe context. diff --git a/src/lib/dhcpsrv/csv_lease_file6.cc b/src/lib/dhcpsrv/csv_lease_file6.cc index cb8ea894c8..2b32d56891 100644 --- a/src/lib/dhcpsrv/csv_lease_file6.cc +++ b/src/lib/dhcpsrv/csv_lease_file6.cc @@ -34,6 +34,22 @@ CSVLeaseFile6::open(const bool seek_to_end) { } } +void +CSVLeaseFile6::close() { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(mutex_); + closeInternal(); + } else { + closeInternal(); + } +} + +void +CSVLeaseFile6::closeInternal() { + // Call the base class to close the file + VersionedCSVFile::close(); +} + void CSVLeaseFile6::openInternal(const bool seek_to_end) { // Call the base class to open the file diff --git a/src/lib/dhcpsrv/csv_lease_file6.h b/src/lib/dhcpsrv/csv_lease_file6.h index 41cc949efd..e8d048e47a 100644 --- a/src/lib/dhcpsrv/csv_lease_file6.h +++ b/src/lib/dhcpsrv/csv_lease_file6.h @@ -49,6 +49,9 @@ public: /// the base class may do so. virtual void open(const bool seek_to_end = false); + /// @brief Closes the lease file. + virtual void close(); + /// @brief Appends the lease record to the CSV file. /// /// This function doesn't throw exceptions itself. In theory, exceptions @@ -94,6 +97,11 @@ private: /// the base class may do so. virtual void openInternal(const bool seek_to_end = false); + /// @brief Closes the lease file. + /// + /// Should be called in a thread safe context. + virtual void closeInternal(); + /// @brief Appends the lease record to the CSV file. /// /// Should be called in a thread safe context. diff --git a/src/lib/util/csv_file.h b/src/lib/util/csv_file.h index e595539de4..d4f7596711 100644 --- a/src/lib/util/csv_file.h +++ b/src/lib/util/csv_file.h @@ -387,7 +387,7 @@ public: void append(const CSVRow& row) const; /// @brief Closes the CSV file. - void close(); + virtual void close(); /// @brief Checks if the CSV file exists and can be opened for reading. ///