Innodb 插件初始化

Innodb插件的加载定义在mysql/include/mysql/Plugin.h中mysql_declare_plugin,具体的调用位置在ha_innodb.cc中,都是以变量的方式定义。Ha_innodb.cc是定义innodb存储引擎的初始化以及相关重要接口的定义。

mysql_declare_plugin(innobase)
{
  MYSQL_STORAGE_ENGINE_PLUGIN, 
  &innobase_storage_engine,//值为 (MYSQL_VERSION_ID << 8)
innobase_hton_name,//值为"InnoDB"
plugin_author,//值为 "Oracle Corporation"
  "Supports transactions, row-level locking, and foreign keys",
  PLUGIN_LICENSE_GPL,
  innobase_init, //ha_innodb.cc中的innobase_init函数
  NULL, /* Plugin Deinit */
  INNODB_VERSION_SHORT,
  innodb_status_variables_export,/* status variables             */
  innobase_system_variables, /* system variables */
  NULL, /* reserved */
  0,    /* flags */
},
……………… //省略
mysql_declare_plugin_end;

innobase_init函数仅仅是在mysql server服务器层面初始化存储存储引擎的handlerton,该类定义了关于innodb操作的接口,比如log的操作、事务的操作。同时也在这个函数内初始化很多innodb的参数。

innodb_status_variables_export的定义为st_mysql_show_var数组,该数组中每个元素定义为innodb status变量的名称和值,具体的定义如下:
    static SHOW_VAR innodb_status_variables_export[]= {
    {"Innodb", (char*) &show_innodb_vars, SHOW_FUNC},
    {NullS, NullS, SHOW_LONG}
};// show_innodb_vars为回调函数

SHOW_VAR定义为:
typedef struct st_mysql_show_var SHOW_VAR;
struct st_mysql_show_var {
  const char *name; //变量名称,show variables like ‘%%’;
  char *value;//变量值
  enum enum_mysql_show_type type;
};

mysql_declare_plugin(innobase),最终的宏替换内容如下:

.... //省略的部分
MYSQL_PLUGIN_EXPORT struct st_mysql_plugin DECLS[]= {
  MYSQL_STORAGE_ENGINE_PLUGIN,
  &innobase_storage_engine,
  innobase_hton_name,
  plugin_author,
  "Supports transactions, row-level locking, and foreign keys",
  PLUGIN_LICENSE_GPL,
  innobase_init, /* Plugin Init */
  NULL, /* Plugin Deinit */
  INNODB_VERSION_SHORT,
  innodb_status_variables_export,/* status variables             */
  innobase_system_variables, /* system variables */
  NULL, /* reserved */
  0,    /* flags */
  },
……
{0,0,0,0,0,0,0,0,0,0,0,0,0}}

而struct st_mysql_plugin结构体的定义如下:

struct st_mysql_plugin
{
  int type;
  void *info;
  const char *name;
  const char *author;
  const char *descr;
  int license;
  int (*init)(MYSQL_PLUGIN); //回调函数
  int (*deinit)(MYSQL_PLUGIN);//目前未使用
  unsigned int version;
  struct st_mysql_show_var *status_vars;
  struct st_mysql_sys_var **system_vars;
  void * __reserved1;
  unsigned long flags;
};

你可能感兴趣的:(Innodb 插件初始化)