]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add innodb-read-committed option
authorKees Monshouwer <mind04@monshouwer.org>
Fri, 12 Jul 2013 10:26:09 +0000 (12:26 +0200)
committermind04 <mind04@monshouwer.org>
Sun, 21 Jul 2013 19:54:50 +0000 (21:54 +0200)
.gitignore
modules/gmysqlbackend/gmysqlbackend.cc
modules/gmysqlbackend/smysql.cc
modules/gmysqlbackend/smysql.hh

index fe9f536591ec49a415be7508af006f3d564c827e..2eaebc25c8281e3fbe667201ca37054e2fb61933 100644 (file)
@@ -38,3 +38,4 @@ lt~obsolete.m4
 pdns-*.tar.gz
 .*DS_Store
 *~
+pdns.pid
\ No newline at end of file
index f223e8668154c1ab6e96781b850cf72f282df3f0..a79ac5256b58a3536b664347816c0c312ba0f69f 100644 (file)
@@ -17,15 +17,15 @@ gMySQLBackend::gMySQLBackend(const string &mode, const string &suffix)  : GSQLBa
 {
   try {
     setDB(new SMySQL(getArg("dbname"),
-                    getArg("host"),
-                    getArgAsNum("port"),
-                    getArg("socket"),
-                    getArg("user"),
-                    getArg("password"),
-                    getArg("group")));
-    
+                     getArg("host"),
+                     getArgAsNum("port"),
+                     getArg("socket"),
+                     getArg("user"),
+                     getArg("password"),
+                     getArg("group"),
+                     mustDo("innodb-read-committed")));
   }
-  
+
   catch(SSqlException &e) {
     L<<Logger::Error<<mode<<" Connection failed: "<<e.txtReason()<<endl;
     throw PDNSException("Unable to launch "+mode+" connection: "+e.txtReason());
@@ -48,6 +48,7 @@ public:
     declare(suffix,"password","Pdns backend password to connect with","");
     declare(suffix,"group", "Pdns backend MySQL 'group' to connect as", "client");
     declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no");
+    declare(suffix,"innodb-read-committed","Use InnoDB READ-COMMITTED tranaction isolation level","yes");
 
     declare(suffix,"basic-query","Basic query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name='%s'");
     declare(suffix,"id-query","Basic with ID query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name='%s' and domain_id=%d");
index 4985ebbe31affec9ad86b6764e74818e44fd3535..b6a97a3d161cfb74a2cb7eca1ab54f19aca3c6dc 100644 (file)
@@ -14,11 +14,13 @@ bool SMySQL::s_dolog;
 pthread_mutex_t SMySQL::s_myinitlock = PTHREAD_MUTEX_INITIALIZER;
 
 SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const string &msocket, const string &user, 
-               const string &password, const string &group)
+               const string &password, const string &group, bool setIsolation)
 {
-  {
-    Lock l(&s_myinitlock);
-    mysql_init(&d_db);
+  int retry=1;
+
+  Lock l(&s_myinitlock);
+  mysql_init(&d_db);
+  do {
 
   #if MYSQL_VERSION_ID >= 50013
     my_bool reconnect = 1;
@@ -31,21 +33,32 @@ SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const
     mysql_options(&d_db, MYSQL_OPT_WRITE_TIMEOUT, &timeout);
   #endif
 
+    if (setIsolation && (retry == 1))
+      mysql_options(&d_db, MYSQL_INIT_COMMAND,"SET SESSION tx_isolation='READ-COMMITTED'");
+
     mysql_options(&d_db, MYSQL_READ_DEFAULT_GROUP, group.c_str());
-    
-    if (!mysql_real_connect(&d_db, host.empty() ? NULL : host.c_str(), 
-                         user.empty() ? NULL : user.c_str(), 
-                         password.empty() ? NULL : password.c_str(),
-                         database.empty() ? NULL : database.c_str(),
-                         port,
-                         msocket.empty() ? NULL : msocket.c_str(),
-                         CLIENT_MULTI_RESULTS)) {
-
-      throw sPerrorException("Unable to connect to database");
+
+    if (!mysql_real_connect(&d_db, host.empty() ? NULL : host.c_str(),
+                          user.empty() ? NULL : user.c_str(),
+                          password.empty() ? NULL : password.c_str(),
+                          database.empty() ? NULL : database.c_str(),
+                          port,
+                          msocket.empty() ? NULL : msocket.c_str(),
+                          CLIENT_MULTI_RESULTS)) {
+
+      if (retry == 0)
+        throw sPerrorException("Unable to connect to database");
+      --retry;
+    } else {
+      if (retry == 0) {
+        mysql_close(&d_db);
+        throw sPerrorException("Please add 'innodb-read-committed=no' to your configuration, and reconsider your storage engine if it does not support transactions.");
+      }
+      retry=-1;
     }
+  } while (retry >= 0);
 
-    d_rres=0;
-  }
+  d_rres=0;
 }
 
 void SMySQL::setLog(bool state)
index 4be990c123de0e412155b9e10e3669e76c6cf9c1..24b69b31dc64cec24c8462f14ef18dd88085a5a1 100644 (file)
@@ -13,7 +13,8 @@ class SMySQL : public SSql
 public:
   SMySQL(const string &database, const string &host="", uint16_t port=0,
          const string &msocket="",const string &user="",
-         const string &password="", const string &group="");
+         const string &password="", const string &group="",
+         bool setIsolation=false);
 
   ~SMySQL();