]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1380] call mysql_autocommit on openDatabase
authorRazvan Becheriu <razvan@isc.org>
Fri, 14 Aug 2020 09:34:01 +0000 (12:34 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 14 Aug 2020 09:34:01 +0000 (12:34 +0300)
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/mysql/mysql_connection.cc
src/lib/mysql/tests/mysql_connection_unittest.cc

index ea05b591d6e9c858c82c1f6fac53b49975b60490..bdbd24f8d088cfc856d50e39ed0258cd7a975c85 100644 (file)
@@ -58,18 +58,6 @@ MySqlConfigBackendImpl(const DatabaseConnection::ParameterMap& parameters)
 
     // Open the database.
     conn_.openDatabase();
-
-    // Enable autocommit. In case transaction is explicitly used, this
-    // setting will be overwritten for the transaction. However, there are
-    // cases when lack of autocommit could cause transactions to hang
-    // until commit or rollback is explicitly called. This already
-    // caused issues for some unit tests which were unable to cleanup
-    // the database after the test because of pending transactions.
-    // Use of autocommit will eliminate this problem.
-    my_bool result = mysql_autocommit(conn_.mysql_, 1);
-    if (result != MLM_FALSE) {
-        isc_throw(DbOperationError, mysql_error(conn_.mysql_));
-    }
 }
 
 MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
index 175c3b4ffa9903d4b4db61280e981aac90519b07..196b93d4177072d6724e490d96ce6d28a5bbb891 100644 (file)
@@ -2634,18 +2634,6 @@ MySqlHostDataSourceImpl::createContext() const {
     // Open the database.
     ctx->conn_.openDatabase();
 
-    // Enable autocommit. In case transaction is explicitly used, this
-    // setting will be overwritten for the transaction. However, there are
-    // cases when lack of autocommit could cause transactions to hang
-    // until commit or rollback is explicitly called. This already
-    // caused issues for some unit tests which were unable to cleanup
-    // the database after the test because of pending transactions.
-    // Use of autocommit will eliminate this problem.
-    my_bool result = mysql_autocommit(ctx->conn_.mysql_, 1);
-    if (result != 0) {
-        isc_throw(DbOperationError, mysql_error(ctx->conn_.mysql_));
-    }
-
     // Prepare query statements. Those are will be only used to retrieve
     // information from the database, so they can be used even if the
     // database is read only for the current user.
index d191639fbbe47f738cd98def210b825453b3578f..6d358963451b1a026ae6fcd79598a24e08937634 100644 (file)
@@ -1805,16 +1805,6 @@ MySqlLeaseMgr::createContext() const {
     // Open the database.
     ctx->conn_.openDatabase();
 
-    // Enable autocommit.  To avoid a flush to disk on every commit, the global
-    // parameter innodb_flush_log_at_trx_commit should be set to 2.  This will
-    // cause the changes to be written to the log, but flushed to disk in the
-    // background every second.  Setting the parameter to that value will speed
-    // up the system, but at the risk of losing data if the system crashes.
-    my_bool result = mysql_autocommit(ctx->conn_.mysql_, 1);
-    if (result != 0) {
-        isc_throw(DbOperationError, mysql_error(ctx->conn_.mysql_));
-    }
-
     // Prepare all statements likely to be used.
     ctx->conn_.prepareStatements(tagged_statements.begin(),
                                  tagged_statements.end());
index c95dc0b5b4408536a409a6f7b9e0f915fca8f238..85877f40775db8a6b31f652ca3d0fef2947948a9 100644 (file)
@@ -210,6 +210,24 @@ MySqlConnection::openDatabase() {
     if (status != mysql_) {
         isc_throw(DbOpenError, mysql_error(mysql_));
     }
+
+    // Enable autocommit. In case transaction is explicitly used, this
+    // setting will be overwritten for the transaction. However, there are
+    // cases when lack of autocommit could cause transactions to hang
+    // until commit or rollback is explicitly called. This already
+    // caused issues for some unit tests which were unable to cleanup
+    // the database after the test because of pending transactions.
+    // Use of autocommit will eliminate this problem.
+    my_bool result = mysql_autocommit(mysql_, 1);
+    if (result != 0) {
+        isc_throw(DbOperationError, mysql_error(ctx->conn_.mysql_));
+    }
+
+    // To avoid a flush to disk on every commit, the global parameter
+    // innodb_flush_log_at_trx_commit should be set to 2. This will cause the
+    // changes to be written to the log, but flushed to disk in the background
+    // every second. Setting the parameter to that value will speed up the
+    // system, but at the risk of losing data if the system crashes.
 }
 
 // Get schema version.
index cbd73bba19af96df7f1b3645f08a69d56bd88773..0a12b132a074188e97d9511e6c04180fcea5aa63 100644 (file)
@@ -63,11 +63,6 @@ public:
         try {
             // Open new connection.
             conn_.openDatabase();
-            my_bool result = mysql_autocommit(conn_.mysql_, 1);
-            if (result != 0) {
-                isc_throw(DbOperationError, "failed to set autocommit option "
-                          "for test MySQL connection");
-            }
 
             // Create mysql_connection_test table.
             createTestTable();