From: Thomas Markwalder Date: Fri, 17 Apr 2026 13:26:23 +0000 (-0400) Subject: [#4441] Add tranactions to MySQL lease ops X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=ff71104cc4f45ea8f48d31e97de8a36b1b8a69d6;p=thirdparty%2Fkea.git [#4441] Add tranactions to MySQL lease ops /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 --- diff --git a/src/hooks/dhcp/mysql/mysql_lease_mgr.cc b/src/hooks/dhcp/mysql/mysql_lease_mgr.cc index 239763d86e..7447f1e20f 100644 --- a/src/hooks/dhcp/mysql/mysql_lease_mgr.cc +++ b/src/hooks/dhcp/mysql/mysql_lease_mgr.cc @@ -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); diff --git a/src/hooks/dhcp/mysql/mysql_lease_mgr.h b/src/hooks/dhcp/mysql/mysql_lease_mgr.h index 7a51541aad..1f64f1e9e0 100644 --- a/src/hooks/dhcp/mysql/mysql_lease_mgr.h +++ b/src/hooks/dhcp/mysql/mysql_lease_mgr.h @@ -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. diff --git a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h index fd6cea6810..946276e673 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h +++ b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h @@ -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. diff --git a/src/lib/dhcpsrv/sflq_allocator.cc b/src/lib/dhcpsrv/sflq_allocator.cc index 8a3123b7bb..3f842b805c 100644 --- a/src/lib/dhcpsrv/sflq_allocator.cc +++ b/src/lib/dhcpsrv/sflq_allocator.cc @@ -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 diff --git a/src/lib/mysql/mysql_connection.h b/src/lib/mysql/mysql_connection.h index ea040867de..834261323b 100644 --- a/src/lib/mysql/mysql_connection.h +++ b/src/lib/mysql/mysql_connection.h @@ -222,6 +222,8 @@ private: bool committed_; }; +/// @brief Defines a scoped pointer to a transaction. +typedef boost::scoped_ptr ScopedMySqlTransactionPtr; /// @brief Common MySQL Connector Pool ///