Skip to content

Commit

Permalink
adding MySQL.WaitTimeout
Browse files Browse the repository at this point in the history
Summary:
so a connection can wait for longer time before going away.

Test Plan:
entity/questions

DiffCamp Revision: 125818
Reviewed By: mwilliams
CC: hphp-diffs@lists, sgrimm, mwilliams
Revert Plan:
OK
  • Loading branch information
haiping authored and macvicar committed Jun 22, 2010
1 parent d9395ce commit 3156f1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/options.compiled
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ users can use the same machine serving their own source files.
Localize = false # true for native driver that's faster
ConnectTimeout = 1000 # in ms
ReadTimeout = 1000 # in ms
WaitTimeout = -1 # in ms, -1 means "don't set"
SlowQueryThreshold = 1000 # in ms, log slow queries as errors
KillOnTimeout = false
}
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/base/runtime_option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ bool RuntimeOption::MySQLReadOnly = false;
bool RuntimeOption::MySQLLocalize = false;
int RuntimeOption::MySQLConnectTimeout = 1000;
int RuntimeOption::MySQLReadTimeout = 1000;
int RuntimeOption::MySQLWaitTimeout = -1;
int RuntimeOption::MySQLSlowQueryThreshold = 1000; // ms
bool RuntimeOption::MySQLKillOnTimeout = false;

Expand Down Expand Up @@ -674,6 +675,7 @@ void RuntimeOption::Load(Hdf &config) {
MySQLLocalize = mysql["Localize"].getBool();
MySQLConnectTimeout = mysql["ConnectTimeout"].getInt32(1000);
MySQLReadTimeout = mysql["ReadTimeout"].getInt32(1000);
MySQLWaitTimeout = mysql["WaitTimeout"].getInt32(-1);
MySQLSlowQueryThreshold = mysql["SlowQueryThreshold"].getInt32(1000);
MySQLKillOnTimeout = mysql["KillOnTimeout"].getBool();
}
Expand Down
1 change: 1 addition & 0 deletions src/runtime/base/runtime_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class RuntimeOption {
static bool MySQLLocalize; // whether to localize MySQL query results
static int MySQLConnectTimeout;
static int MySQLReadTimeout;
static int MySQLWaitTimeout;
static int MySQLSlowQueryThreshold;
static bool MySQLKillOnTimeout;

Expand Down
17 changes: 13 additions & 4 deletions src/runtime/ext/ext_mysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,19 @@ bool MySQL::connect(CStrRef host, int port, CStrRef socket, CStrRef username,
}
IOStatusHelper io("mysql::connect", host.data(), port);
m_xaction_count = 0;
return mysql_real_connect(m_conn, host.data(), username.data(),
password.data(), NULL, port,
socket.empty() ? NULL : socket.data(),
client_flags);
bool ret = mysql_real_connect(m_conn, host.data(), username.data(),
password.data(), NULL, port,
socket.empty() ? NULL : socket.data(),
client_flags);
if (ret && RuntimeOption::MySQLWaitTimeout > 0) {
String query("set session wait_timeout=");
query += String((int64)(RuntimeOption::MySQLWaitTimeout / 1000));
if (mysql_real_query(m_conn, query.data(), query.size())) {
raise_notice("MySQL::connect: failed setting session wait timeout: %s",
mysql_error(m_conn));
}
}
return ret;
}

bool MySQL::reconnect(CStrRef host, int port, CStrRef socket, CStrRef username,
Expand Down

0 comments on commit 3156f1e

Please sign in to comment.