MySQL in InnoDB engine analysis (initialization)

Source: Internet
Author: User

    • MySQL's storage engine is a plug-in form of work, this should be a major feature of MySQL! According to the "in-depth understanding of MySQL" content, the 5.1 version of the storage engine plug-in is not exhaustive, is exactly the feature that was just added. When you add a storage engine to MySQL, you need to change some of the upper-level code, and the fragmented changes will be a bit cumbersome, and the project will be recompiled once. I've heard people say that you can add the engine directly without changing the C + + code. In this case, it is more convenient to toss the storage engine!
    • This code comes from ha_innodb.cc, which is the standard procedure for declaring a storage engine plug-in in MySQL. This code takes advantage of macros. There is a more complete definition in plugin.h.
mysql_declare_plugin (innobase) {mysql_storage_engine_plugin, &innobase_storage_ Engine, Innobase_hton_name, Plugin_author,  "Supports transactions, Row-level locking, and fo Reign Keys ", PLUGIN_LICENSE_GPL, Innobase_init, /* PLUGIN init */ null , /* Plugin Deinit */ Innodb_version_short, Innodb_ Status_variables_export,/* status variables */ innobase_system_variables, Span class= "hljs-comment" >/* 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 "MySQL technology insider: InnoDB Storage engine," a personal feeling that although the name of the book is like the bottom, in fact, it is for operation and maintenance. There is basically no parsing code in the book, which is explained by words and examples. I read it briefly, probably understood something, but obviously didn't feel well enough. Because a lot of doubts in my heart can't explain. "In-depth understanding of MySQL" Inside the demo storage engine is a more detailed explanation, but feel and innodb such "tall" still can't compare. No way, only to bite the bullet on the code! I'm looking at the code with the problem, and the writing is definitely not systematic.
    • The biggest doubt in my mind is, why InnoDB can be multi-threaded? "In-depth" in the engine, CSV and so on are not seen at all the multi-threaded shadow. In a plug-in architecture, InnoDB is actually a dynamic library. This dynamic library realizes the multi-threaded architecture inside, the total sleep is not very practical. If this dynamic library is loaded by another MySQL instance, will there be a problem? (Of course, it felt like I couldn't answer it for a short time.)
    • Back to the point, this InnoDB has a innobase_init field in the storage plug-in declaration. -Innobase_init is a function, which is assigned to whom? Look at the code snippet in Plugin.h.
structst_mysql_plugin{intType/* 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) */  intLicense/* 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 intVersion/* Plugin version (for i_s.plugins) */  structSt_mysql_show_var *status_vars;structSt_mysql_sys_var **system_vars;void* __RESERVED1;/ * reserved for dependency checking * /  unsigned LongFlags/ * Flags for plugin * /};
    • This is the INIT function pointer, which calls the Innobase_init () function when the plugin does not load. The Innobase_init () function calls the Innobase_start_or_create_for_mysql () function. We can take a closer look at this function, the trick of multithreading is in this function. I extracted the code for 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 above several threads, there is an optional purge thread. In general, the InnoDB storage engine will have about eight threads. This conclusion and "MySQL Technology insider" is still very close, we look at the InnoDB version should be different. This is probably the initialization of the multi-threaded architecture of the InnoDB engine, and further research into the INNODB architecture should look at the working functions of each thread, as well as the synchronization and communication mechanisms between them.
As for my "dynamic library being loaded by another MySQL instance". I think in this case, the mechanism of dynamic library is not for the reuse of code, but based on the concept of modular software design. The engine here should not be loaded by another MySQL instance.

MySQL in InnoDB engine analysis (initialization)

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.