From 3c7d38fd8259ab31fbbd92080a353007ebcbd90a Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Wed, 27 Apr 2016 15:00:19 +0200 Subject: [PATCH] make mysql timeout configurable --- docs/markdown/authoritative/backend-generic-mysql.md | 3 +++ modules/gmysqlbackend/gmysqlbackend.cc | 4 +++- modules/gmysqlbackend/smysql.cc | 11 ++++++----- modules/gmysqlbackend/smysql.hh | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/markdown/authoritative/backend-generic-mysql.md b/docs/markdown/authoritative/backend-generic-mysql.md index 9176cd850..40ef860ba 100644 --- a/docs/markdown/authoritative/backend-generic-mysql.md +++ b/docs/markdown/authoritative/backend-generic-mysql.md @@ -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 diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index bce59d1c4..9f23fb165 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -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"); diff --git a/modules/gmysqlbackend/smysql.cc b/modules/gmysqlbackend/smysql.cc index 367b49619..ef7da26d5 100644 --- a/modules/gmysqlbackend/smysql.cc +++ b/modules/gmysqlbackend/smysql.cc @@ -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() { diff --git a/modules/gmysqlbackend/smysql.hh b/modules/gmysqlbackend/smysql.hh index 0968722d3..85cb8afc1 100644 --- a/modules/gmysqlbackend/smysql.hh +++ b/modules/gmysqlbackend/smysql.hh @@ -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(); -- 2.40.0