MySQL DBA's Blog

handler和handlerton

很久之前看过Understanding MySQL Internals的一些片段。最近很烦,于是又翻了翻(纯发泄)。

handlerton提供的是存储引擎的一些特性。比如记录点、提交、回滚。同一个引擎跨表的操作需要在handlerton里面完成,比如说引擎的初始化,跨表的事务。
handler提供了表的基本操作。比如打开关闭表、扫描数据索引,都可以在handler里面找到相应的接口。每个handler的子类进行初始化对象的时候,必须向构造函数传递一个handlerton对象的引用。
handler类有很多纯虚函数,必须要在handler的子类里面实现。这些函数决定了存储引擎的底层io方式,包括数据存取和索引。
ha_example.h里可以很方便地找到这些纯虚函数:
int open(const char *name, int mode, uint test_if_locked); // required
int close(void); // required
int rnd_init(bool scan); //required
int rnd_next(uchar *buf); ///< required
int rnd_pos(uchar *buf, uchar *pos); ///< required
void position(const uchar *record); ///< required
int info(uint); ///< required
int external_lock(THD *thd, int lock_type); ///< required
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); ///< required
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); ///< required

貌似有点困了。改日用GDB调试一下EXAMPLE引擎,再上来写一个~

Tags: , ,

Leave a Reply