From: Marcin Siodelski Date: Fri, 25 Jan 2019 15:34:16 +0000 (+0100) Subject: [#396,!205] Server selector is now used for creating audit revisions. X-Git-Tag: 429-Updated-StampedValue-to-support-reals_base~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc08d1b79762495d092e5f6949ad54650f5bc6f8;p=thirdparty%2Fkea.git [#396,!205] Server selector is now used for creating audit revisions. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 903206d132..7c53bdd7f5 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -220,7 +220,7 @@ public: // no new audit revisions are created in any subsequent calls. ScopedAuditRevision audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, - "global parameter set", false); + server_selector, "global parameter set", false); // Try to update the existing row. if (conn_.updateDeleteQuery(MySqlConfigBackendDHCPv4Impl::UPDATE_GLOBAL_PARAMETER4, @@ -755,6 +755,7 @@ public: // no new audit revisions are created in any subsequent calls. ScopedAuditRevision audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "subnet set", true); try { @@ -869,7 +870,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, log_message, cascade_delete); auto count = deleteFromTable(index, server_selector, operation, keys...); @@ -1161,7 +1164,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "shared network set", true); try { @@ -1274,7 +1279,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "global option set", false); if (existing_option) { @@ -1343,7 +1350,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "subnet specific option set", cascade_update); if (existing_option) { @@ -1430,7 +1439,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "pool specific option set", cascade_update); if (existing_option) { @@ -1499,7 +1510,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "shared network specific option set", cascade_update); @@ -1822,7 +1835,9 @@ public: // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision - audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + audit_revision(this, + MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + server_selector, "option definition set", true); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 66fe2187d3..67213e88ab 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -28,10 +28,12 @@ namespace dhcp { MySqlConfigBackendImpl:: ScopedAuditRevision::ScopedAuditRevision(MySqlConfigBackendImpl* impl, const int index, + const ServerSelector& server_selector, const std::string& log_message, bool cascade_transaction) : impl_(impl) { - impl_->initAuditRevision(index, log_message, cascade_transaction); + impl_->createAuditRevision(index, server_selector, log_message, + cascade_transaction); } MySqlConfigBackendImpl:: @@ -82,16 +84,20 @@ MySqlConfigBackendImpl::~MySqlConfigBackendImpl() { } void -MySqlConfigBackendImpl::initAuditRevision(const int index, - const std::string& log_message, - const bool cascade_transaction) { +MySqlConfigBackendImpl::createAuditRevision(const int index, + const ServerSelector& server_selector, + const std::string& log_message, + const bool cascade_transaction) { // Do not touch existing audit revision in case of the cascade update. if (audit_revision_created_) { return; } + auto tag = getServerTag(server_selector, "creating new configuration " + "audit revision"); + MySqlBindingCollection in_bindings = { - MySqlBinding::createString("all"), + MySqlBinding::createString(tag), MySqlBinding::createString(log_message), MySqlBinding::createInteger(static_cast(cascade_transaction)) }; diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index e0f66ee056..251ed136e6 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -32,7 +32,7 @@ class MySqlConfigBackendImpl { protected: /// @brief RAII object used to protect against creating multiple - /// audit revision during cascade configuration updates. + /// audit revisions during cascade configuration updates. /// /// Audit revision is created per a single database transaction. /// It includes log message associated with the configuration @@ -51,13 +51,15 @@ protected: /// 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. + /// revisions can be created. The caller must ensure that + /// the instance of this object exists throughout the whole + /// transaction with the database. class ScopedAuditRevision { public: /// @brief Constructor. /// - /// Initializes new audit revision and sets the flag in the + /// Creates 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. /// @@ -65,6 +67,7 @@ protected: /// @param index index of the query to set session variables /// used for creation of the audit revision and the audit /// entries. + /// @param server_selector Server selector. /// @param log_message log message associated with the audit /// revision to be inserted into the database. /// @param cascade_transaction boolean flag indicating if @@ -73,6 +76,7 @@ protected: /// options) won't be created. ScopedAuditRevision(MySqlConfigBackendImpl* impl, const int index, + const db::ServerSelector& server_selector, const std::string& log_message, bool cascade_transaction); @@ -160,25 +164,23 @@ public: /// @brief Invokes the corresponding stored procedure in MySQL. /// - /// The @c initAuditRevision stored procedure initializes several - /// session variables used when creating new audit revision in the - /// database. That includes setting a log message for the revision, - /// setting the boolean value indicating if the audit entries should - /// be created for DHCP options (that should only be the case when - /// the options are not added as part of the subnet, shared network - /// etc.). Finally, it resets the session variables used internally - /// by the database to corrdinate between the triggers. + /// The @c createAuditRevision stored procedure creates new audit + /// revision and initializes several session variables to be used when + /// the audit entries will be created for the inserted, updated or + /// deleted configuration elements. /// /// @param index query index. + /// @param server_selector Server selector. /// @param log_message log message to be used for the audit revision. /// @param cascade_transaction Boolean value indicating whether the /// configuration modification is performed as part of the ownining /// element modification, e.g. subnet is modified resulting in /// modification of the DHCP options it owns. In that case only the /// audit entry for the owning element should be created. - void initAuditRevision(const int index, - const std::string& log_message, - const bool cascade_transaction); + void createAuditRevision(const int index, + const db::ServerSelector& server_selector, + const std::string& log_message, + const bool cascade_transaction); /// @brief Clears the flag blocking creation of the new audit revisions. ///