265
Creating a Storage Engine Class
The implementation of the storage engine described here is single-threaded to support a
single session, a single user, and single table requests. A multi-threaded implementation
would detract from the focus of this chapter. Chapter 14 discussed concurrency in more
detail. The MariaDB server communicates with storage engines through a well-defined
handler interface that includes a handlerton, which is a singleton handler that is
connected to a table handler. The handlerton defines the storage engine and contains
pointers to the methods that apply to the persistent memory storage engine.
The first method the storage engine needs to support is to enable the call for a new
handler instance, shown in Listing 13-1.
Listing 13-1. ha_pmdk.cc – Creating a new handler instance
117 static handler *pmdk_create_handler(handlerton *hton,
118
TABLE_SHARE *table,
119
MEM_ROOT *mem_root);
120
121 handlerton *pmdk_hton;
When a handler instance is created, the MariaDB server sends commands to the
handler to perform data storage and retrieve tasks such as opening a table, manipulating
rows, managing indexes, and transactions. When a handler is instantiated, the first
required operation is the opening of a table. Since the storage engine is a single user and
single-threaded implementation, only one handler instance is created.
Various handler methods are also implemented; they apply to the storage engine as
a whole, as opposed to methods like create() and open() that work on a per-table basis.
Some examples of such methods include transaction methods to handle commits and
rollbacks, shown in Listing 13-2.
Listing 13-2. ha_pmdk.cc – Handler methods including transactions, rollback, etc
209 static int pmdk_init_func(void *p)
210 {
...
213
pmdk_hton= (handlerton *)p;
214
pmdk_hton->state= SHOW_OPTION_YES;
215
pmdk_hton->create= pmdk_create_handler;
Chapter 13 enabling persistenCe Using a real-World appliCation
Précédent

- 289/457

Suivant