Reputation: 76
I want to write a MySQL daemon plugin that monitors queries on other MySQL servers and compares them with queries running on where the daemon is running. Basically this is in a spider engine setting, where a query initiated on the head node get run on the shards. Whenever a query is killed on the head, I want to have a daemon on the shard nodes that will kill the associated query there.
The idea was to initiate a pthread that uses mysql_real_connect
, mysql_real_query
... to access "show processlist" on the head node and compare them with local thread list. If I issue mysql_real_connect
in the thread of the daemon, I get a segmentation fault. I think this is due to a threading issue in mysql_real_connect
. I've used #define MYSQL_SERVER 1
and follow the approach taken in ha_federated::real_connect()
.
Is it actually possible to run mysql_real_connect
from within a daemon plugin?
Thanks for any hints.
Upvotes: 2
Views: 259
Reputation: 76
After meditating over the handlersocker daemon plugin I realised that in order for mysql_real_connect
and friends to work in the daemon thread, a mysql internal thread environment needs to be set up and registered with the server.
This basically involves calling the following in the daemon thread:
my_thread_init();
thd = new THD;
mysql_mutex_lock(&LOCK_thread_count);
thd->thread_id = thread_id++;
mysql_mutex_unlock(&LOCK_thread_count);
thd->store_globals();
... setting up various options in THD ...
mysql_mutex_lock(&LOCK_thread_count);
threads.append(thd);
++thread_count;
mysql_mutex_unlock(&LOCK_thread_count);
Upvotes: 1