MySQL in InnoDB engine analysis (initialization)

Source: Internet
Author: User
Tags mysql in

    • 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, 5.1 version number when the storage engine plug-in is not complete, 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 are a bit cumbersome, and project compiles once again. I've heard people say that I've been able to join the engine without changing the code for C + +. This kind of words, toss the storage engine's words to be more convenient!

    • 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 have read a "MySQL technology insider: InnoDB Storage Engine", personally feel that the book although the name is like the bottom of the story. In fact, it is still oriented to operation and maintenance. There is basically no parsing code in the book, it is written and examples to explain. I glanced briefly over it. Probably understand a little something, but obviously think not cool enough. Because there are so many doubts in my heart that I can't explain.

      "In-depth understanding of MySQL" Inside the demo storage engine is a more specific explanation, but the feeling and InnoDB this "tall" still can't compare.

      No way, just to bite the bullet in the code. I came to see the code with a question. The writing is certainly not systematic.

    • The biggest doubt in my mind is. Why can InnoDB 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. Let's say that this dynamic library was loaded by another MySQL instance. Will there be any problems? (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. This innobase_init () function is called when the plugin is not loaded.

      The Innobase_init () function calls the Innobase_start_or_create_for_mysql () function.

      We can look at this function in detail. The mystery 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, another optional purge thread.

Under normal circumstances, 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 number 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 far as my "dynamic library is loaded by another MySQL instance".

I think in this case, the mechanism of the 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 into 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.