]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#396,!205] Improved commentary in the MySQL CB backend.
authorMarcin Siodelski <marcin@isc.org>
Thu, 24 Jan 2019 12:49:20 +0000 (13:49 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 30 Jan 2019 09:18:59 +0000 (10:18 +0100)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
src/share/database/scripts/mysql/dhcpdb_create.mysql

index 4d6f9cd4b6210b70c0e7cf72de76b73167d20815..4a15d0bfe899804ccbc6388a7df425ef6275a25f 100644 (file)
@@ -842,6 +842,24 @@ public:
         }
     }
 
+    /// @brief Sends a query to delete data from a table.
+    ///
+    /// If creates a new audit revision for this change if such audit
+    /// revision doesn't exist yet (using ScopedAuditRevision mechanism).
+    ///
+    /// @tparam Args type of the arguments to be passed to one of the existing
+    /// @c deleteFromTable methods.
+    /// @param server_selector server selector.
+    /// @param operation operation which results in calling this function. This is
+    /// used for logging purposes.
+    /// @param log_message log message to be associated with the audit revision.
+    /// @param cascade_delete boolean flag indicating if we're performing
+    /// cascade delete. If set to true, the audit entries for the child
+    /// objects (e.g. DHCPoptions) won't be created.
+    /// @param keys arguments to be passed to one of the existing
+    /// @c deleteFromTable methods.
+    ///
+    /// @return Number of deleted entries.
     template<typename... Args>
     uint64_t deleteTransactional(const int index,
                                  const db::ServerSelector& server_selector,
index e19a9b0e5ddba8963bdc36ed5e1d3c43f9adbf7a..9b5f6ce78dd65b9cfc19c10919b29d4d9e747808 100644 (file)
@@ -92,7 +92,7 @@ MySqlConfigBackendImpl::initAuditRevision(const int index,
 
     MySqlBindingCollection in_bindings = {
         MySqlBinding::createString(log_message),
-        MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(!cascade_transaction))
+        MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(cascade_transaction))
     };
     conn_.insertQuery(index, in_bindings);
     audit_revision_created_ = true;
index fcf12fb0af14563fc291b05e5c026baa1d63e79d..e0f66ee056b74d36f2c3804a62c989a13d4b487c 100644 (file)
@@ -29,23 +29,67 @@ namespace dhcp {
 /// This class contains common methods for manipulating data in the
 /// MySQL database, used by all servers.
 class MySqlConfigBackendImpl {
-public:
+protected:
 
+    /// @brief RAII object used to protect against creating multiple
+    /// audit revision during cascade configuration updates.
+    ///
+    /// Audit revision is created per a single database transaction.
+    /// It includes log message associated with the configuration
+    /// change. Single command sent over the control API should
+    /// result in a single audit revision entry in the database.
+    /// A single configuration update often consists of multiple
+    /// insertions, updates and/or deletes in the database. For
+    /// example, a subnet contains pools and DHCP options which are
+    /// inserted to their respective tables. We refer to such update
+    /// as a cascade update. Cascade update should result in a single
+    /// audit revision and an audit entry for a subnet, rather than
+    /// multiple audit revisions and audit entries for the subnet,
+    /// pools and child DHCP options.
+    ///
+    /// Creating an instance of the @c ScopedAuditRevision guards
+    /// against creation of multiple audit revisions when child
+    /// objects are inserted or updated in the database. When the
+    /// instance of this object goes out of scope the new audit
+    /// revisions can be created.
     class ScopedAuditRevision {
     public:
 
+        /// @brief Constructor.
+        ///
+        /// Initializes new audit revision and sets the flag in the
+        /// MySQL CB implementation object which prevents new audit
+        /// revisions to be created while this instance exists.
+        ///
+        /// @param impl pointer to the MySQL CB implementation.
+        /// @param index index of the query to set session variables
+        /// used for creation of the audit revision and the audit
+        /// entries.
+        /// @param log_message log message associated with the audit
+        /// revision to be inserted into the database.
+        /// @param cascade_transaction boolean flag indicating if
+        /// we're performing cascade transaction. If set to true,
+        /// the audit entries for the child objects (e.g. DHCP
+        /// options) won't be created.
         ScopedAuditRevision(MySqlConfigBackendImpl* impl,
                             const int index,
                             const std::string& log_message,
                             bool cascade_transaction);
 
+        /// @brief Destructor.
+        ///
+        /// Clears the flag which is blocking creation of the new
+        /// audit revisions.
         ~ScopedAuditRevision();
 
     private:
-        MySqlConfigBackendImpl* impl_;
 
+        /// @brief Pointer to the MySQL CB implementation.
+        MySqlConfigBackendImpl* impl_;
     };
 
+public:
+
     /// @brief Constructor.
     ///
     /// @param parameters A data structure relating keywords and values
@@ -136,6 +180,9 @@ public:
                            const std::string& log_message,
                            const bool cascade_transaction);
 
+    /// @brief Clears the flag blocking creation of the new audit revisions.
+    ///
+    /// This is used by the @c ScopedAuditRevision object.
     void clearAuditRevision();
 
     /// @brief Sends query to the database to retrieve most recent audit entries.
index e09c988403e1877e379b0a917b557929894ca430..06912f8dc9c8802ea1dfff8ec22fe1056419ad9d 100644 (file)
@@ -1588,7 +1588,7 @@ BEGIN
     # entire subnet. The only case when the object_type will be
     # set to 'dhcp4_options' is when the global option is added.
     # Global options do not have the owner.
-    IF @cascade_transaction == 0 THEN
+    IF @cascade_transaction IS NULL OR @cascade_transaction = 0 THEN
         IF scope_id = 0 THEN
             # If a global option is added or modified, create audit
             # entry for the 'dhcp4_options' table.