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;
};


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值