Thursday, 2 January 2014

MINTEMPL: a minimal template of a storage-engine

some days ago I posted the code of a storage-engine: DUMMY.

This engine was, as the name suggested, a dummy-engine, it did absolutely nothing.

So let's try another engine, which is also silly but contains all the features needed for a storage engine: MINimal TEMPLate.

It contains everything that a storage-engine needs so you can use it in practice (but you shouldn't).

It is silly because it is nothing else than a MyIsam-engine with another name, because the class is derived from MyIsam as you can see in the header-file ha_mintempl.h.

You will find the code of this engine here.

Simply download this file, extract the contents to the storage-folge of MySQL or MariaDB, call cmake and recompile. The steps needed are described in detail here


MariaDB

When I tried to load the storage engine I encountered an error:
MariaDB [(none)]> install plugin mintempl soname 'ha_mintempl.so';
ERROR 1126 (HY000): Can't open shared library '/home/august/MariaDB/pgm/lib/plugin/ha_mintempl.so' (errno: 2 undefined symbol: _ZN9ha_myisam5cloneEPKcP11st_mem_root)
MariaDB [(none)]> 

In this case please look in the folder storage/MinTemplate/CMakeFiles/mintempl.dir into the file link.txt.
In this file you have to add the library libmyisam.a so that the sources will be linked using this library. So I added this text to the contents of this file at the end of the line: -L../myisam/ -lmyisam

When I deleted the file ha_mintempl.so and recompiled everything it worked: I could install this little plugin in MariaDB without an error.

a warning: the file link.txt is generated by cmake. The next time cmake will run it can overwrite this file so you can loose these modifications.

You can find a more detailed explanation of the error-message on the MariaDB-mailing list here.

MySQL

No modifications were needed fpr MySQL.


Tests

I did some tests with this engine to check that it works. You will find the results in the sources in MinTemplate/Skripte/Tests.sql.

What is it good for?

As written before it does not look like a good idea to create another engine with the functionality of an existing one (and giving it a name of my own), but this approach allowed me to play with the code without implementing a full engine or modifying existing code. In a later post I will use it, implement some functions by adding the code of these functions by myself and still have a full engine (with proven code).


differences

If you compare the code of thi engine with the DUMMY-engine presented earlier you will see that this engine needs less code. The reason for this is that it is derived from an existing engine which already contained the code we needed to implement in the DUMMY-engine.