]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1239] csv lease file is now kea thread safe
authorRazvan Becheriu <razvan@isc.org>
Tue, 9 Jun 2020 09:46:08 +0000 (12:46 +0300)
committerRazvan Becheriu <razvan@isc.org>
Tue, 16 Jun 2020 09:02:52 +0000 (09:02 +0000)
src/lib/dhcpsrv/csv_lease_file4.cc
src/lib/dhcpsrv/csv_lease_file4.h
src/lib/dhcpsrv/csv_lease_file6.cc
src/lib/dhcpsrv/csv_lease_file6.h
src/lib/util/csv_file.h

index a66da203213e963b2b37184b983ee34593af95e2..0336be79335eb636f2ae90f6a3f07772217edfdd 100644 (file)
@@ -42,6 +42,22 @@ CSVLeaseFile4::openInternal(const bool seek_to_end) {
     clearStatistics();
 }
 
+void
+CSVLeaseFile4::close() {
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> 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()) {
index 477adf7561f6b562e83043d8a9c26f3850ebfa46..5802c368d721db3f74e61272d65f303b4564955f 100644 (file)
@@ -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.
index cb8ea894c85c6e9a8583626a2523e443ba7e7072..2b32d568912e2eb68796eea8d653c00c5dddb2b3 100644 (file)
@@ -34,6 +34,22 @@ CSVLeaseFile6::open(const bool seek_to_end) {
     }
 }
 
+void
+CSVLeaseFile6::close() {
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> 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
index 41cc949efd5b88f0620eb1bfc37b2e850224383d..e8d048e47a317831fbfad91cad2e067cd3cf6af4 100644 (file)
@@ -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.
index e595539de43a511221a7d226b5d7a76dbe8f4e2b..d4f7596711d73ffc04289f72184baa0e98751bb3 100644 (file)
@@ -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.
     ///