In one of my previous posts I was writing about how to read other processes memory [
1]. As an example I tried to get the value of the hard coded MySQL internal InnoDB variable spin_wait_delay (srv_spin_wait_delay).
In this example we were using gdb or the operating system ptrace function to retrieve this value. This method has the disadvantage that it is pretty invasive.
When I was working on a customer support case I had the idea to solve this by the much less invasive method of User-Defined Functions (UDF).
UDF were introduced in MySQL 5.0 [
2]. They provide the feasibility to enlarge the MySQL functionality by adding external code.
The clue is now that you also can use this external code to do some MySQL internal stuff.
My idea was now, instead of using gdb/ptrace to get the value of spin_wait_delay, to write and UDF to get and set this value.
More details about the UDF itself, how to compile and load it you can find on my website [
3].
Then the UDF has to be loaded and activated in the database:
mysql> CREATE FUNCTION spin_wait_delay RETURNS INTEGER SONAME "udf_spin_wait_delay.so";
To remove the UDF again you can use the following command:
mysql> DROP FUNCTION spin_wait_delay;
To check if an UDF is installed or to see which ones are installed the following command gives you the right answer:
mysql> SELECT * FROM mysql.func;
+-----------------+-----+------------------------+----------+
| name | ret | dl | type |
+-----------------+-----+------------------------+----------+
| spin_wait_delay | 2 | udf_spin_wait_delay.so | function |
+-----------------+-----+------------------------+----------+
When the UDF is compiled and properly loaded into the database you can get the value of spin_wait_delay as follows:
mysql> SELECT spin_wait_delay();
+--------------------+
| spin_wait_delay(5) |
+--------------------+
| 5 |
+--------------------+
And now the real nice thing is that you can even set this value as follows:
mysql> SELECT sping_wait_delay(8);
+--------------------+
| spin_wait_delay(8) |
+--------------------+
| 8 |
+--------------------+
With this function we can make a static hard coded InnoDB value dynamically changeable. To make it permanent also after a database restart possibly the functionality of init_file could help you further [
4].
With this concept we can think about implementing many missing things without touching the MySQL code itself or recompiling MySQL. Please let me know what is missing in your opinion and I can try to implement it. Because I am not a programer the help of those guys would be very appreciated.
If anybody sees a problem with this method please let me know. I do not know about such things like thread safe and mutexes etc. But I think at least reading should not harm.
Caution: When you have a crash in your UDF the whole MySQL server will crash. So be careful and test it intensively!
Binaryudf_spin_wait_delay.so (md5 807c6bc09b5dc88a8005788519f2483a)