22.5 Creating the handlerton

The handlerton (short for handler singleton)
defines the storage engine and contains method pointers to those
methods that apply to the storage engine as a whole, as opposed to
methods that work on a per-table basis. Some examples of such
methods include transaction methods to handle commits and
rollbacks.

There are a total of 30 handlerton elements, only a few of which
are mandatory (specifically the first four elements and the
create() method).

The name of the storage engine. This is the name that will be
used when creating tables (CREATE TABLE ... ENGINE =
FOO;).

The value to be displayed in the status
field when a user issues the SHOW STORAGE
ENGINES command.

The storage engine comment, a description of the storage
engine displayed when using the SHOW STORAGE
ENGINES command.

An integer that uniquely identifies the storage engine within
the MySQL server. The constants used by the built-in storage
engines are defined in the handler.h file.
Custom engines should use DB_TYPE_UNKOWN.

A method pointer to the storage engine initializer. This
method is only called once when the server starts to allow the
storage engine class to perform any housekeeping that is
necessary before handlers are instanced.

The slot. Each storage engine has its own memory area
(actually a pointer) in the thd, for
storing per-connection information. It is accessed as
thd->ha_data[foo_hton.slot]. The slot
number is initialized by MySQL after
foo_init() is called. For more information
on the thd, see
#Implementing
ROLLBACK.

The savepoint offset. To store per-savepoint data the storage
engine is provided with an area of a requested size
(0, if no savepoint memory is necessary).

The savepoint offset must be initialized statically to the size of
the needed memory to store per-savepoint information. After
foo_init it is changed to be an offset to the
savepoint storage area and need not be used by the storage engine.
For more information, see
#Specifying the
Savepoint Offset.

Used by transactional storage engines, clean up any memory
allocated in their slot.

A method pointer to the handler's
savepoint_set() method. This is used to
create a savepoint and store it in memory of the requested
size.

A method pointer to the handler's
release_savepoint() method. This is used to
release the resources of a savepoint during a transaction.
It's optionally populated for storage engines that support
savepoints.

HTON_ALTER_NOT_SUPPORTED is used to indicate
that the storage engine cannot accept ALTER
TABLE statements. The FEDERATED
storage engine is an example.
HTON_FLUSH_AFTER_RENAME indicates that
FLUSH LOGS must be called after a table rename.
HTON_NOT_USER_SELECTABLE indicates that the
storage engine should not be shown when a user calls SHOW
STORAGE ENGINES. Used for system storage engines such as
the dummy storage engine for binary logs.