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;
};
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容