Permalink
Browse files

add innodb-read-committed option

  • Loading branch information...
1 parent 14a4f1e commit a3a546c5283f36e06585763d2e320e75de3c90b6 @mind04 mind04 committed with Habbie Jul 12, 2013
Showing with 41 additions and 25 deletions.
  1. +1 −0 .gitignore
  2. +9 −8 modules/gmysqlbackend/gmysqlbackend.cc
  3. +29 −16 modules/gmysqlbackend/smysql.cc
  4. +2 −1 modules/gmysqlbackend/smysql.hh
View
@@ -38,3 +38,4 @@ lt~obsolete.m4
pdns-*.tar.gz
.*DS_Store
*~
+pdns.pid
@@ -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 AhuException("Unable to launch "+mode+" connection: "+e.txtReason());
@@ -48,6 +48,7 @@ class gMySQLFactory : public BackendFactory
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");
@@ -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)
@@ -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();

0 comments on commit a3a546c

Please sign in to comment.