]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make mysql timeout configurable 3788/head
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 27 Apr 2016 13:00:19 +0000 (15:00 +0200)
committermind04 <mind04@monshouwer.org>
Wed, 27 Apr 2016 16:11:40 +0000 (18:11 +0200)
docs/markdown/authoritative/backend-generic-mysql.md
modules/gmysqlbackend/gmysqlbackend.cc
modules/gmysqlbackend/smysql.cc
modules/gmysqlbackend/smysql.hh

index 9176cd850045bac66fef4d3c11954215e5deda3e..40ef860baf26d342b635bac7b25ba888d14785e8 100644 (file)
@@ -79,6 +79,9 @@ Enable DNSSEC processing for this backend. Default=no.
 ## `gmysql-innodb-read-committed`
 Use the InnoDB READ-COMMITTED transaction isolation level. Default=yes.
 
+## `gmysql-timeout`
+The timeout in seconds for each attempt to read from, or write to the server. A value of 0 will disable the timeout. Default: 10
+
 # Default Schema
 ```
 !!include=../modules/gmysqlbackend/schema.mysql.sql
index bce59d1c4d02d146771e035e36b4cc64ab70560a..9f23fb16501b3bfc780b4bb77d23f69cd5fa9d91 100644 (file)
@@ -25,7 +25,8 @@ gMySQLBackend::gMySQLBackend(const string &mode, const string &suffix)  : GSQLBa
                      getArg("user"),
                      getArg("password"),
                      getArg("group"),
-                     mustDo("innodb-read-committed")));
+                     mustDo("innodb-read-committed"),
+                     getArgAsNum("timeout")));
   }
 
   catch(SSqlException &e) {
@@ -50,6 +51,7 @@ public:
     declare(suffix,"password","Pdns backend password to connect with","");
     declare(suffix,"group", "Pdns backend MySQL 'group' to connect as", "client");
     declare(suffix,"innodb-read-committed","Use InnoDB READ-COMMITTED transaction isolation level","yes");
+    declare(suffix,"timeout", "The timeout in seconds for each attempt to read/write to the server", "10");
 
     declare(suffix,"dnssec","Enable DNSSEC processing","no");
 
index 367b496190ce14835b37bc2427e0954f9143e426..ef7da26d5352b04480928402467ddf067a8dbdc3 100644 (file)
@@ -321,7 +321,7 @@ private:
 };
 
 SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const string &msocket, const string &user,
-               const string &password, const string &group, bool setIsolation)
+               const string &password, const string &group, bool setIsolation, unsigned int timeout)
 {
   int retry=1;
 
@@ -337,9 +337,10 @@ SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const
 #endif
 
 #if MYSQL_VERSION_ID >= 50100
-    unsigned int timeout = 180;
-    mysql_options(&d_db, MYSQL_OPT_READ_TIMEOUT, &timeout);
-    mysql_options(&d_db, MYSQL_OPT_WRITE_TIMEOUT, &timeout);
+    if(timeout) {
+      mysql_options(&d_db, MYSQL_OPT_READ_TIMEOUT, &timeout);
+      mysql_options(&d_db, MYSQL_OPT_WRITE_TIMEOUT, &timeout);
+    }
 #endif
 
 #if MYSQL_VERSION_ID >= 50500
@@ -399,7 +400,7 @@ void SMySQL::execute(const string& query)
 
   int err;
   if((err=mysql_query(&d_db,query.c_str())))
-    throw sPerrorException("Failed to execute mysql_query '" + query + "', perhaps connection died? Err="+itoa(err));
+    throw sPerrorException("Failed to execute mysql_query '" + query + "' Err="+itoa(err));
 }
 
 void SMySQL::startTransaction() {
index 0968722d32f83c25091c519903abef07fd6c9458..85cb8afc1045a1dc14ee5031c8d2f161d94f496e 100644 (file)
@@ -14,7 +14,7 @@ public:
   SMySQL(const string &database, const string &host="", uint16_t port=0,
          const string &msocket="",const string &user="",
          const string &password="", const string &group="",
-         bool setIsolation=false);
+         bool setIsolation=false, unsigned int timeout=10);
 
   ~SMySQL();