]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4441] Add tranactions to MySQL lease ops
authorThomas Markwalder <tmark@isc.org>
Fri, 17 Apr 2026 13:26:23 +0000 (09:26 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 17 Apr 2026 17:21:44 +0000 (17:21 +0000)
/src/hooks/dhcp/mysql/mysql_lease_mgr.cc
/src/lib/mysql/mysql_connection.h
    MySqlLeaseMgr::addLeaseCommon()
    MySqlLeaseMgr::updateLeaseCommon()
    MySqlLeaseMgr::deleteLeaseCommon()
    - added scoped transactions

/src/lib/dhcpsrv/sflq_allocator.cc
    SharedFlqAllocator::sanityChecksSflqAllocator6()
    handle alloctor types correctly

    various nits from review comments

src/hooks/dhcp/mysql/mysql_lease_mgr.cc
src/hooks/dhcp/mysql/mysql_lease_mgr.h
src/hooks/dhcp/pgsql/pgsql_lease_mgr.h
src/lib/dhcpsrv/sflq_allocator.cc
src/lib/mysql/mysql_connection.h

index 239763d86e078dd5d35e81c87e39b674ce2d2c68..7447f1e20fd5048ba8b3fcffb904c107e0e0b3ba 100644 (file)
@@ -2389,6 +2389,7 @@ MySqlLeaseMgr::addLeaseCommon(MySqlLeaseContextPtr& ctx,
     checkError(ctx, status, stindex, "unable to bind parameters");
 
     int32_t affected_rows = 0;
+    ScopedMySqlTransactionPtr trans;
     MYSQL_BIND obind[1];
     if (outputs_row_count) {
         // Build the output value bind array.
@@ -2399,6 +2400,7 @@ MySqlLeaseMgr::addLeaseCommon(MySqlLeaseContextPtr& ctx,
         // Bind the output bind array to the statement
         status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), obind);
         checkError(ctx, status, stindex, "unable to bind output");
+        trans.reset(new MySqlTransaction(ctx->conn_));
     }
 
     // Execute the statement
@@ -2430,6 +2432,8 @@ MySqlLeaseMgr::addLeaseCommon(MySqlLeaseContextPtr& ctx,
         if (status != 0) {
             checkError(ctx, status, stindex, "unable to fetch results");
         }
+
+        trans->commit();
     }
 
     // Insert succeeded
@@ -3523,6 +3527,7 @@ MySqlLeaseMgr::updateLeaseCommon(MySqlLeaseContextPtr& ctx,
     checkError(ctx, status, stindex, "unable to bind parameters");
 
     int32_t affected_rows = 0;
+    ScopedMySqlTransactionPtr trans;
     MYSQL_BIND obind[1];
     if (outputs_row_count) {
         // Build the output value bind array.
@@ -3533,6 +3538,7 @@ MySqlLeaseMgr::updateLeaseCommon(MySqlLeaseContextPtr& ctx,
         // Bind the output bind array to the statement
         status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), obind);
         checkError(ctx, status, stindex, "unable to bind output");
+        trans.reset(new MySqlTransaction(ctx->conn_));
     }
 
     // Execute
@@ -3554,6 +3560,8 @@ MySqlLeaseMgr::updateLeaseCommon(MySqlLeaseContextPtr& ctx,
         if (status != 0) {
             checkError(ctx, status, stindex, "unable to fetch results");
         }
+
+        trans->commit();
     }
 
     // Check success case first as it is the most likely outcome.
@@ -3572,7 +3580,7 @@ MySqlLeaseMgr::updateLeaseCommon(MySqlLeaseContextPtr& ctx,
     // one row.
     isc_throw(DbOperationError, "apparently updated more than one lease "
               "that had the address " << lease->addr_.toText()
-              << " row count: " << affected_rows);
+              << ", row count: " << affected_rows);
 }
 
 void
@@ -3727,6 +3735,7 @@ MySqlLeaseMgr::deleteLeaseCommon(MySqlLeaseContextPtr& ctx,
     checkError(ctx, status, stindex, "unable to bind WHERE clause parameter");
 
     int32_t affected_rows = 0;
+    ScopedMySqlTransactionPtr trans;
     MYSQL_BIND obind[1];
     if (outputs_row_count) {
         // Build the output value bind array.
@@ -3737,6 +3746,7 @@ MySqlLeaseMgr::deleteLeaseCommon(MySqlLeaseContextPtr& ctx,
         // Bind the output bind array to the statement
         status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), obind);
         checkError(ctx, status, stindex, "unable to bind output");
+        trans.reset(new MySqlTransaction(ctx->conn_));
     }
 
     // Execute
@@ -3758,6 +3768,8 @@ MySqlLeaseMgr::deleteLeaseCommon(MySqlLeaseContextPtr& ctx,
         if (status != 0) {
             checkError(ctx, status, stindex, "unable to fetch results");
         }
+
+        trans->commit();
     }
 
     return (affected_rows);
index 7a51541aadec86dd48fd2070df5b3377360c8ae8..1f64f1e9e05c6b8209dc5df104d0675ee1fc9a49 100644 (file)
@@ -1302,7 +1302,6 @@ public:
 
     /// @brief Calls stored procedure to create an SFLQ pool for v6.
     ///
-    /// @todo TYPE_NA prohibited or no?
     /// @param start_address first address/prefix in the pool.
     /// @param last_address last address/prefix in the pool.
     /// @param lease_type TYPE_NA or TYPE_PD.
index fd6cea6810cad4c8eaa0225b53b7d4590bcadc53..946276e673cdbf3abbf1f526d30f859dfb40d183 100644 (file)
@@ -1259,7 +1259,6 @@ public:
 
     /// @brief Calls stored procedure to create an SFLQ pool for v6.
     ///
-    /// @todo TYPE_NA prohibited or no?
     /// @param start_address first address/prefix in the pool.
     /// @param last_address last address/prefix in the pool.
     /// @param lease_type TYPE_NA or TYPE_PD.
index 8a3123b7bb7af86fd59ee8be74df35f367cbe326..3f842b805c29ccaf549de16722e6e26b3a8ef194 100644 (file)
@@ -241,8 +241,20 @@ SharedFlqAllocator::sanityChecksSflqAllocator4(Subnet4Ptr subnet) {
 
 void
 SharedFlqAllocator::sanityChecksSflqAllocator6(Subnet6Ptr subnet) {
-    for (auto const lease_type : {Lease::TYPE_NA, Lease::TYPE_PD}) {
-        for (auto const& pool : subnet->getPools(lease_type)) {
+    if (subnet->getAllocatorType() == "shared-flq") {
+        for (auto const& pool : subnet->getPools(Lease::TYPE_NA)) {
+            auto const& capacity(pool->getCapacity());
+            if (capacity > MAX_V6_POOL_SIZE) {
+                isc_throw(BadValue, "pool capacity " << capacity
+                          << " exceeeds limit of " << MAX_V6_POOL_SIZE
+                          << " for shared-flq allocator on V6 pool "
+                          << pool->toText());
+            }
+        }
+    }
+
+    if (subnet->getPdAllocatorType() == "shared-flq") {
+        for (auto const& pool : subnet->getPools(Lease::TYPE_PD)) {
             auto const& capacity(pool->getCapacity());
             if (capacity > MAX_V6_POOL_SIZE) {
                 isc_throw(BadValue, "pool capacity " << capacity
index ea040867de0f1c380b365bc599b8e2e7bb71fa92..834261323bf320f5f1e18119d0528a98439d354c 100644 (file)
@@ -222,6 +222,8 @@ private:
     bool committed_;
 };
 
+/// @brief Defines a scoped pointer to a transaction.
+typedef boost::scoped_ptr<MySqlTransaction> ScopedMySqlTransactionPtr;
 
 /// @brief Common MySQL Connector Pool
 ///