The MySQL/MariaDB build process is complex, so it is easiest to build within the MySQL/MariaDB source tree. (I wasted basically a whole day trying to build a storage engine plugin outside the tree.)
Inside the MariaDB root, create a new directory, storage/memem
.
$ mkdir storage/memem
The blackhole storage engine is the smallest existing one. So we'll copy from it and rename the minimum from it to get a new engine to compile and be usable from the server.
$ cp storage/blackhole/* storage/memem/
$ mv storage/memem/ha_blackhole.cc storage/memem/ha_memem.cc
$ mv storage/memem/ha_blackhole.h storage/memem/ha_memem.h
And make the following changes. To CMakeLists.txt
:
$ diff storage/memem/CMakeLists.txt storage/blackhole/CMakeLists.txt
16,17c16,17
< SET(MEMEM_SOURCES ha_memem.cc ha_memem.h)
< MYSQL_ADD_PLUGIN(memem ${MEMEM_SOURCES} STORAGE_ENGINE)
---
> SET(BLACKHOLE_SOURCES ha_blackhole.cc ha_blackhole.h)
> MYSQL_ADD_PLUGIN(blackhole ${BLACKHOLE_SOURCES} STORAGE_ENGINE)
And do a case-insensitive find-and-replace of "blackhole" with "memem".
Now in your CMake build directory run (I'll assume it's in build
, a directory within the MariaDB source root):
$ cmake ..
$ make -j8
Start the server and client, and you should see MEMEM
listed as a plugin.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 11.4.0-MariaDB-debug Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show plugins;
+-------------------------------+----------+--------------------+---------+---------+
| Name | Status | Type | Library | License |
+-------------------------------+----------+--------------------+---------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
... lots of stuff ...
| MEMEM | ACTIVE | STORAGE ENGINE | NULL | GPL |
... more stuff ...
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
+-------------------------------+----------+--------------------+---------+---------+
72 rows in set (0.002 sec)
And you can create a table with it just like with the blackhole engine.
MariaDB [test]> drop table x;
Query OK, 0 rows affected (0.002 sec)
MariaDB [test]> create table x (i int) engine = memem;
Query OK, 0 rows affected (0.003 sec)
MariaDB [test]> insert into x values (1);
Query OK, 1 row affected (0.000 sec)
MariaDB [test]> select * from x;
Empty set (0.000 sec)
Tada!