Brian "Krow" Aker (krow) wrote,
Brian "Krow" Aker
krow

Building a Storage Engine: Getting the Skeleton to compile

This is the first part, in what hopes to be, a series where I go through the entire process of building a storage engine for MySQL.

The first thing to do is to download the skeleton engine. You can find the latest copy at:

http://hg.tangent.org/skeleton-mysql-engine?ca=tip;type=gz

You will need to untar and uncompress the file. The Skeleton engine is a basic bare bones engines which is a starting point for creating a storage engine project (the memcache, PBXT, AWS, HTTP, Google File system and many other engines all evolved from it).

What you will find once you download the engine and cd into its directory, is that it doesn't have a configure file just yet. To generate one, run the following:


[brian@zim skeleton-mysql-engine]$ sh config/bootstrap
+ aclocal
+ autoheader
+ automake --add-missing --copy
+ autoconf


The concept is that anything which can be generated, should not be checked into the source control system.

At this point you should now have a configure file. What you will now need to do is supply a source tree to compile against. It is important to look at src/Makefile,a before you do this. By default it is set to compile against a normal MySQL tree, but if you are building with a debug tree you will need to change the INCLUDE line in the Makefile.am.


# By default we are set to not compile with debug
INCLUDES = -DMYSQL_DYNAMIC_PLUGIN -DUNIV_MUST_NOT_INLINE -DFORCE_INIT_OF_VARS $(MYSQL_INC)
#INCLUDES = -DMYSQL_DYNAMIC_PLUGIN -DDBUG_ON -DSAFE_MUTEX -DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX $(MYSQL_INC)


This step is a common step that is missed. Really this should be resolved by updating the build tools that are supplied with the MySQL Server.

Next you will need to follow the configure, make, and install steps:


[brian@zim skeleton-mysql-engine]$ ./configure --with-mysql=/home/brian/mysql/memcache-build-5.1/ --libdir=/home/brian/mysql-builds/mysql-5.1.15/lib/mysql/
[brian@zim skeleton-mysql-engine]$ make
[brian@zim skeleton-mysql-engine]$ make install


The --with-mysql should be pointed to a source tree for MySQL. The --libdir can be used to say which lib directory the plugin should be installed in once it is compiled. As long as you have permission to write to your lib directory, your library will be installed in it when you type "make install"

Now we just need to load it:


mysql> INSTALL PLUGIN skeleton SONAME 'libskeleton_engine.so';
Query OK, 0 rows affected (0.00 sec)

mysql> show plugins;
+------------------+--------+--------------------+-----------------------+---------+
| Name | Status | Type | Library | License |
+------------------+--------+--------------------+-----------------------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ndbcluster | ACTIVE | STORAGE ENGINE | NULL | GPL |
| SKELETON | ACTIVE | STORAGE ENGINE | libskeleton_engine.so | GPL |
+------------------+--------+--------------------+-----------------------+---------+
12 rows in set (0.06 sec)


You have now loaded your first storage engine!

If you want to try it out, you can do the following:


mysql> create table foo (a varchar(100), b int) ENGINE=SKELETON;
Query OK, 0 rows affected (0.01 sec)

mysql> show create table foo;
+-------+---------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------+
| foo | CREATE TABLE `foo` (
`a` varchar(100) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=SKELETON DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


Inserting, updating, and deleting will throw an error at this point. Calling select will result in zero rows.

For the next article we will implement a basic select with no indexes.
Subscribe
  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 13 comments