DatabaseCampaign: MySQL / concurrency fixes

According to
<http://dev.mysql.com/doc/refman/5.5/en/c-api-threaded-clients.html>,
a MySQL connection handle must not be used concurrently with an open
result set and mysql_use_result() in one thread
(DatabaseCampaign::run()), and mysql_query() in another
(DatabaseCampaign::collect_result_thread()).  This indeed leads to
crashes when bounding the outgoing job queue (SERVER_OUT_QUEUE_SIZE),
and maybe even more insidous effects in other cases.  The solution is
to create separate connections for both threads.

Additionally, call mysql_library_init() before spawning any threads.

Change-Id: I2981f2fdc67c9a2cbe8781f1a21654418f621aeb
This commit is contained in:
Horst Schirmeier
2013-12-02 19:33:24 +01:00
parent 0907dfb0ae
commit 33b63651ae
4 changed files with 41 additions and 12 deletions

View File

@ -229,6 +229,9 @@ void Database::cmdline_setup() {
"-h/--hostname \tMYSQL Hostname (default: taken from ~/.my.cnf)");
USERNAME = cmd.addOption("u", "username", Arg::Required,
"-u/--username \tMYSQL Username (default: taken from ~/.my.cnf, or your current user)\n");
// should be called before any threads are spawned
mysql_library_init(0, NULL, NULL);
}
Database * Database::cmdline_connect() {