MySQL innodb Engine analysis (initialization), mysqlinnodb

Source: Internet
Author: User

MySQL innodb Engine analysis (initialization), mysqlinnodb

  • MySQL's storage engine works in the form of plug-ins. This should be a major feature of MySQL! According to the deep understanding of MySQL, the plug-ins of the storage engine in version 5.1 are not completely complete. Specifically, they are just added features. When you add a storage engine for MySQL, you need to change some upper-Layer Code. It is a little troublesome to make the scattered changes, and the project must be re-compiled. I have heard from others that you can directly add the engine without changing the C/C ++ code. In this way, it is more convenient to use the storage engine!
  • This code is from ha_innodb.cc, which is the standard process for declaring the storage engine plug-in MySQL. This Code uses macros. The plug-in. h has a complete definition.
mysql_declare_plugin(innobase){  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 */},i_s_innodb_trx,i_s_innodb_locks,i_s_innodb_lock_waits,i_s_innodb_cmp,i_s_innodb_cmp_reset,i_s_innodb_cmpmem,i_s_innodb_cmpmem_resetmysql_declare_plugin_end;    
  • I used to read a book "MySQL technology Insider: innodb Storage engine". I personally think that although this book is named at the bottom layer, it is still O & M oriented. There is basically no code profiling in the book, and it is explained by text and examples. I read it briefly and understood something, but obviously it was not good enough. This is because many questions cannot be explained. The demo storage engine in MySQL is explained in detail, but it still cannot be compared with innodb. No, you have to stick your head to the code! I came to see the code with a question. The writing is definitely not a system.
  • My biggest question is, why does innodb support multithreading? The engine and csv in "deep" cannot see the shadow of multithreading at all. In a plug-in architecture, innodb is actually a dynamic library. This dynamic library implements a multi-threaded architecture, which is not very practical. If the dynamic library is loaded by another MySQL instance, is there a problem? (Of course I cannot answer this question in a short time ).
  • Back to the question, the innodb Storage plug-in Declaration contains an innobase_init field. -Innobase_init is a function. Who is it assigned? Check the code snippet in plugin. h.
struct st_mysql_plugin{  int type;             /* the plugin type (a MYSQL_XXX_PLUGIN value)   */  void *info;           /* pointer to type-specific plugin descriptor   */  const char *name;     /* plugin name                                  */  const char *author;   /* plugin author (for I_S.PLUGINS)              */  const char *descr;    /* general descriptive text (for I_S.PLUGINS)   */  int license;          /* the plugin license (PLUGIN_LICENSE_XXX)      */  int (*init)(void *);  /* the function to invoke when plugin is loaded */  int (*deinit)(void *);/* the function to invoke when plugin is unloaded */  unsigned int version; /* plugin version (for I_S.PLUGINS)             */  struct st_mysql_show_var *status_vars;  struct st_mysql_sys_var **system_vars;  void * __reserved1;   /* reserved for dependency checking             */  unsigned long flags;  /* flags for plugin */};
  • This is the init function pointer. When the plug-in is not loaded, the innobase_init () function is called. The innobase_init () function calls the innobase_start_or_create_for_mysql () function. Let's take a closer look at this function. The multi-threaded xuanjicang is in this function. I extracted the code of the new thread.
    for (i = 0; i < srv_n_file_io_threads; i++) {        n[i] = i;        os_thread_create(io_handler_thread, n + i, thread_ids + i);    }    /*****    *****/        /* Create the thread which watches the timeouts for lock waits */    os_thread_create(&srv_lock_timeout_thread, NULL,             thread_ids + 2 + SRV_MAX_N_IO_THREADS);    /* Create the thread which warns of long semaphore waits */    os_thread_create(&srv_error_monitor_thread, NULL,             thread_ids + 3 + SRV_MAX_N_IO_THREADS);    /* Create the thread which prints InnoDB monitor info */    os_thread_create(&srv_monitor_thread, NULL,             thread_ids + 4 + SRV_MAX_N_IO_THREADS);    /*****    *****/    os_thread_create(&srv_master_thread, NULL, thread_ids         + (1 + SRV_MAX_N_IO_THREADS));

In addition to the preceding threads, there is also an optional purge thread. Generally, the innodb Storage engine has about eight threads. This conclusion is very similar to the MySQL technology insider. We can see that the innodb version is different. This is probably the initialization process of the multi-threaded architecture of the innodb engine. To further study the innodb architecture, we should look at the working functions of various threads and the synchronization and communication mechanisms between them.
For my question about loading a dynamic library by another MySQL instance ". I think in this case, the dynamic library mechanism is based on Modular Software Design instead of code reuse. The engine here should not be loaded by other MySQL instances.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.