While going over the plugin structure with Calvin I noticed that the daemon plugin example doesn't give much of an example of what you can do. So I hacked a little more on it :)
You can find it here:
What it now demonstrates is how to create a "heart beat" file. Daemon plugins are raw plugins inside of MySQL, you can literally do anything with them. For hacking the server they are an excellent way of making use of your full imagination.
The Example creates a thread when it is first initialized:
static int daemon_example_plugin_init(void *p)
if (pthread_create(&con->heartbeat_thread, &attr, mysql_heartbeat, (void *)con) != 0)
This thread will then write a time stamp to a heartbeat file every five seconds.
When the server is shutdown:
static int daemon_example_plugin_deinit(void *p)
We will kill off the heartbeat thread. Then a final message is written to the file before we exit the plugin's finalize function.
This is a simple example of what can be done but it highlights how to create your own worker threads in the server. Daemon plugins are in the similar vein of prometheus stealing fire from the gods. You can do incredible things with them, but at the same time you can burn yourself badly.
Hopefully tomorrow I can put up a couple more examples that I have to show off some of the other functionally that they provide.
I suspect more then a few of them will twist your mind a bit, and hopefully kick start more people into thinking about what else can be done :)
If you are curious about the internals to MySQL I'll be giving a Tutorial at the MySQL User's Conference coming up in April on the "stuff we forget to document" on the Monday of the conference. I'll also be teaching a three hour tutorial on the internals of the storage engine architecture later that day.
You can register for the conference here: