51ak帶你看MYSQL5.7源碼1:main入口函數

来源:https://www.cnblogs.com/wokofo/archive/2018/03/22/8624538.html
-Advertisement-
Play Games

嘗試一點點的記錄下 自己看MYSQL源碼的歷程 51ak帶你看MYSQL源碼1:main入口函數 ...


從事DBA工作多年

MYSQL源碼也是頭一次接觸

嘗試記錄下自己看MYSQL5.7源碼的歷程

 

目錄:

51ak帶你看MYSQL5.7源碼1:main入口函數

51ak帶你看MYSQL5.7源碼2:編譯現有的代碼

 

 

去MYSQL官網下源碼:https://dev.mysql.com/downloads/mysql/

選 SOURCE  CODE  

 

 下載解壓。選VS code來查看,

用VS打開發現這些目錄 ,根據瞭解到的目錄結構說明,我們關註標紅的兩個目錄,SQL是MYSQL的核心代碼 ,STORGE里是各個存儲引擎的代碼

 

打開sql/main.cc 發現只有一個函數,引用了同級目錄下的mysqld_main(int argc, char **argv); 

 

F12跟過去,到了msyqld.cc下的這個過程 ,這裡就是整個SERVER進程 的入口

 

接下來就一個巨大的代碼段,來啟動MYSQLD進程 

我按個人的理解加了註釋如下:

#ifdef _WIN32
int win_main(int argc, char **argv)
#else
int mysqld_main(int argc, char **argv)
#endif
{
  /*
    Perform basic thread library and malloc initialization,
    to be able to read defaults files and parse options.
  */
  my_progname= argv[0]; /*註: 記下mysql進程名*/


#ifndef _WIN32 
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
  pre_initialize_performance_schema();
#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
  // For windows, my_init() is called from the win specific mysqld_main
  if (my_init())                 // init my_sys library & pthreads
  {
    sql_print_error("my_init() failed.");
    flush_error_log_messages();
    return 1;
  }
#endif /* _WIN32 */

  orig_argc= argc; 
  orig_argv= argv;
  my_getopt_use_args_separator= TRUE;
  my_defaults_read_login_file= FALSE;
  /*註: 這裡是去讀配置文件里的啟動項,讀的時候還帶入了argv ,應該是argv優行,*/
  if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv))
  {
    flush_error_log_messages();
    return 1;
  }
  my_getopt_use_args_separator= FALSE;
  defaults_argc= argc;
  defaults_argv= argv;
  remaining_argc= argc;
  remaining_argv= argv;

  /* Must be initialized early for comparison of options name */
  system_charset_info= &my_charset_utf8_general_ci;

  /* Write mysys error messages to the error log. */
  local_message_hook= error_log_print;

  int ho_error;

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
  /*
    Initialize the array of performance schema instrument configurations.
  */
  init_pfs_instrument_array();
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
 /*註: 這裡跟過去發現還是在處理啟動變數*/
  ho_error= handle_early_options();

#if !defined(_WIN32) && !defined(EMBEDDED_LIBRARY)

  if (opt_bootstrap && opt_daemonize)
  {
    fprintf(stderr, "Bootstrap and daemon options are incompatible.\n");
    exit(MYSQLD_ABORT_EXIT);
  }

  if (opt_daemonize && log_error_dest == disabled_my_option &&
      (isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)))
  {
    fprintf(stderr, "Please enable --log-error option or set appropriate "
                    "redirections for standard output and/or standard error "
                    "in daemon mode.\n");
    exit(MYSQLD_ABORT_EXIT);
  }

  if (opt_daemonize)
  {
    if (chdir("/") < 0)
    {
      fprintf(stderr, "Cannot change to root director: %s\n",
                      strerror(errno));
      exit(MYSQLD_ABORT_EXIT);
    }

    if ((pipe_write_fd= mysqld::runtime::mysqld_daemonize()) < 0)
    {
      fprintf(stderr, "mysqld_daemonize failed \n");
      exit(MYSQLD_ABORT_EXIT);
    }
  }
#endif
 /*註: 還是在處理啟動變數。。。*/
  init_sql_statement_names();
  sys_var_init();
  ulong requested_open_files;
  adjust_related_options(&requested_open_files);

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
  if (ho_error == 0)
  {
    if (!opt_help && !opt_bootstrap)
    {
      /* Add sizing hints from the server sizing parameters. */
      pfs_param.m_hints.m_table_definition_cache= table_def_size;
      pfs_param.m_hints.m_table_open_cache= table_cache_size;
      pfs_param.m_hints.m_max_connections= max_connections;
      pfs_param.m_hints.m_open_files_limit= requested_open_files;
      pfs_param.m_hints.m_max_prepared_stmt_count= max_prepared_stmt_count;

      PSI_hook= initialize_performance_schema(&pfs_param);
      if (PSI_hook == NULL && pfs_param.m_enabled)
      {
        pfs_param.m_enabled= false;
        sql_print_warning("Performance schema disabled (reason: init failed).");
      }
    }
  }
#else
  /*
    Other provider of the instrumentation interface should
    initialize PSI_hook here:
    - HAVE_PSI_INTERFACE is for the instrumentation interface
    - WITH_PERFSCHEMA_STORAGE_ENGINE is for one implementation
      of the interface,
    but there could be alternate implementations, which is why
    these two defines are kept separate.
  */
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */

#ifdef HAVE_PSI_INTERFACE
  /*
    Obtain the current performance schema instrumentation interface,
    if available.
  */
  if (PSI_hook)
  {
    PSI *psi_server= (PSI*) PSI_hook->get_interface(PSI_CURRENT_VERSION);
    if (likely(psi_server != NULL))
    {
      set_psi_server(psi_server);

      /*
        Now that we have parsed the command line arguments, and have initialized
        the performance schema itself, the next step is to register all the
        server instruments.
      */
      init_server_psi_keys();
      /* Instrument the main thread */
      PSI_thread *psi= PSI_THREAD_CALL(new_thread)(key_thread_main, NULL, 0);
      PSI_THREAD_CALL(set_thread_os_id)(psi);
      PSI_THREAD_CALL(set_thread)(psi);

      /*
        Now that some instrumentation is in place,
        recreate objects which were initialised early,
        so that they are instrumented as well.
      */
      my_thread_global_reinit();
    }
  }
#endif /* HAVE_PSI_INTERFACE */
 /*註: ERRLOG初始化*/
  init_error_log();

  /* Initialize audit interface globals. Audit plugins are inited later. */
  mysql_audit_initialize();

#ifndef EMBEDDED_LIBRARY
  Srv_session::module_init();
#endif

  /*
    Perform basic query log initialization. Should be called after
    MY_INIT, as it initializes mutexes.
  */
   /*註: QUERYLOG初始化*/
  query_logger.init();

  if (ho_error)
  {
    /*
      Parsing command line option failed,
      Since we don't have a workable remaining_argc/remaining_argv
      to continue the server initialization, this is as far as this
      code can go.
      This is the best effort to log meaningful messages:
      - messages will be printed to stderr, which is not redirected yet,
      - messages will be printed in the NT event log, for windows.
    */
    flush_error_log_messages();
    /*
      Not enough initializations for unireg_abort()
      Using exit() for windows.
    */
    exit (MYSQLD_ABORT_EXIT);
  }

  if (init_common_variables())
    unireg_abort(MYSQLD_ABORT_EXIT);        // Will do exit
 /*註: 系統信號初始化*/
  my_init_signals();

  size_t guardize= 0;
#ifndef _WIN32
  int retval= pthread_attr_getguardsize(&connection_attrib, &guardize);
  DBUG_ASSERT(retval == 0);
  if (retval != 0)
    guardize= my_thread_stack_size;
#endif

#if defined(__ia64__) || defined(__ia64)
  /*
    Peculiar things with ia64 platforms - it seems we only have half the
    stack size in reality, so we have to double it here
  */
  guardize= my_thread_stack_size;
#endif

  my_thread_attr_setstacksize(&connection_attrib,
                            my_thread_stack_size + guardize);

  {
    /* Retrieve used stack size;  Needed for checking stack overflows */
    size_t stack_size= 0;
    my_thread_attr_getstacksize(&connection_attrib, &stack_size);

    /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
    if (stack_size && stack_size < (my_thread_stack_size + guardize))
    {
      sql_print_warning("Asked for %lu thread stack, but got %ld",
                        my_thread_stack_size + guardize, (long) stack_size);
#if defined(__ia64__) || defined(__ia64)
      my_thread_stack_size= stack_size / 2;
#else
      my_thread_stack_size= static_cast<ulong>(stack_size - guardize);
#endif
    }
  }

#ifndef DBUG_OFF
  test_lc_time_sz();
  srand(static_cast<uint>(time(NULL)));
#endif

#ifndef _WIN32
  if ((user_info= check_user(mysqld_user)))
  {
#if HAVE_CHOWN
    if (unlikely(opt_initialize))
    {
      /* need to change the owner of the freshly created data directory */
      MY_STAT stat;
      char errbuf[MYSYS_STRERROR_SIZE];
      bool must_chown= true;

      /* fetch the directory's owner */
      if (!my_stat(mysql_real_data_home, &stat, MYF(0)))
      {
        sql_print_information("Can't read data directory's stats (%d): %s."
                              "Assuming that it's not owned by the same user/group",
                              my_errno(),
                              my_strerror(errbuf, sizeof(errbuf), my_errno()));
      }
      /* Don't change it if it's already the same as SElinux stops this */
      else if(stat.st_uid == user_info->pw_uid &&
              stat.st_gid == user_info->pw_gid)
        must_chown= false;

      if (must_chown &&
          chown(mysql_real_data_home, user_info->pw_uid, user_info->pw_gid)
         )
      {
        sql_print_error("Can't change data directory owner to %s", mysqld_user);
        unireg_abort(1);
      }
    }
#endif


#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
    if (locked_in_memory) // getuid() == 0 here
      set_effective_user(user_info);
    else
#endif
      set_user(mysqld_user, user_info);
  }
#endif // !_WIN32

  /*
   initiate key migration if any one of the migration specific
   options are provided.
  */
   /*註: 這一段應該是跟遷移有關的,不是很懂*/
  if (opt_keyring_migration_source ||
      opt_keyring_migration_destination ||
      migrate_connect_options)
  {
    Migrate_keyring mk;
    if (mk.init(remaining_argc, remaining_argv,
                opt_keyring_migration_source,
                opt_keyring_migration_destination,
                opt_keyring_migration_user,
                opt_keyring_migration_host,
                opt_keyring_migration_password,
                opt_keyring_migration_socket,
                opt_keyring_migration_port))
    {
      sql_print_error(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
                      "failed");
      log_error_dest= "stderr";
      flush_error_log_messages();
      unireg_abort(MYSQLD_ABORT_EXIT);
    }

    if (mk.execute())
    {
      sql_print_error(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
                      "failed");
      log_error_dest= "stderr";
      flush_error_log_messages();
      unireg_abort(MYSQLD_ABORT_EXIT);
    }

    sql_print_information(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
                          "successfull");
    log_error_dest= "stderr";
    flush_error_log_messages();
    unireg_abort(MYSQLD_SUCCESS_EXIT);
  }

  /*
   We have enough space for fiddling with the argv, continue
  */
  /*註:設置DATA變數*/
  if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
  {
    sql_print_error("failed to set datadir to %s", mysql_real_data_home);
    unireg_abort(MYSQLD_ABORT_EXIT);        /* purecov: inspected */
  }
  /*註:設置BINLOG*/
  //If the binlog is enabled, one needs to provide a server-id
  if (opt_bin_log && !(server_id_supplied) )
  {
    sql_print_error("You have enabled the binary log, but you haven't provided "
                    "the mandatory server-id. Please refer to the proper "
                    "server start-up parameters documentation");
    unireg_abort(MYSQLD_ABORT_EXIT);
  }

  /* 
   The subsequent calls may take a long time : e.g. innodb log read.
   Thus set the long running service control manager timeout
  */
#if defined(_WIN32)
  Service.SetSlowStarting(slow_start_timeout);
#endif
  /*註:這個很重要。核心模塊在這裡啟動了*/
  if (init_server_components())
    unireg_abort(MYSQLD_ABORT_EXIT);

  /*
    Each server should have one UUID. We will create it automatically, if it
    does not exist.
   */
  if (init_server_auto_options())
  {
    sql_print_error("Initialization of the server's UUID failed because it could"
                    " not be read from the auto.cnf file. If this is a new"
                    " server, the initialization failed because it was not"
                    " possible to generate a new UUID.");
    unireg_abort(MYSQLD_ABORT_EXIT);
  }

  /*註:下麵這段跟SID有關*/
  /*
    Add server_uuid to the sid_map.  This must be done after
    server_uuid has been initialized in init_server_auto_options and
    after the binary log (and sid_map file) has been initialized in
    init_server_components().

    No error message is needed: init_sid_map() prints a message.

    Strictly speaking, this is not currently needed when
    opt_bin_log==0, since the variables that gtid_state->init
    initializes are not currently used in that case.  But we call it
    regardless to avoid possible future bugs if gtid_state ever
    needs to do anything else.
  */
  global_sid_lock->wrlock();
  int gtid_ret= gtid_state->init();
  global_sid_lock->unlock();

  if (gtid_ret)
    unireg_abort(MYSQLD_ABORT_EXIT);

  // Initialize executed_gtids from mysql.gtid_executed table.
  if (gtid_state->read_gtid_executed_from_table() == -1)
    unireg_abort(1);

  if (opt_bin_log)
  {
    /*
      Initialize GLOBAL.GTID_EXECUTED and GLOBAL.GTID_PURGED from
      gtid_executed table and binlog files during server startup.
    */
    Gtid_set *executed_gtids=
      const_cast<Gtid_set *>(gtid_state->get_executed_gtids());
    Gtid_set *lost_gtids=
      const_cast<Gtid_set *>(gtid_state->get_lost_gtids());
    Gtid_set *gtids_only_in_table=
      const_cast<Gtid_set *>(gtid_state->get_gtids_only_in_table());
    Gtid_set *previous_gtids_logged=
      const_cast<Gtid_set *>(gtid_state->get_previous_gtids_logged());

    Gtid_set purged_gtids_from_binlog(global_sid_map, global_sid_lock);
    Gtid_set gtids_in_binlog(global_sid_map, global_sid_lock);
    Gtid_set gtids_in_binlog_not_in_table(global_sid_map, global_sid_lock);

    if (mysql_bin_log.init_gtid_sets(&gtids_in_binlog,
                                     &purged_gtids_from_binlog,
                                     opt_master_verify_checksum,
                                     true/*true=need lock*/,
                                     NULL/*trx_parser*/,
                                     NULL/*gtid_partial_trx*/,
                                     true/*is_server_starting*/))
      unireg_abort(MYSQLD_ABORT_EXIT);

    global_sid_lock->wrlock();

    purged_gtids_from_binlog.dbug_print("purged_gtids_from_binlog");
    gtids_in_binlog.dbug_print("gtids_in_binlog");

    if (!gtids_in_binlog.is_empty() &&
        !gtids_in_binlog.is_subset(executed_gtids))
    {
      gtids_in_binlog_not_in_table.add_gtid_set(&gtids_in_binlog);
      if (!executed_gtids->is_empty())
        gtids_in_binlog_not_in_table.remove_gtid_set(executed_gtids);
      /*
        Save unsaved GTIDs into gtid_executed table, in the following
        four cases:
          1. the upgrade case.
          2. the case that a slave is provisioned from a backup of
             the master and the slave is cleaned by RESET MASTER
             and RESET SLAVE before this.
          3. the case that no binlog rotation happened from the
             last RESET MASTER on the server before it crashes.
          4. The set of GTIDs of the last binlog is not saved into the
             gtid_executed table if server crashes, so we save it into
             gtid_executed table and executed_gtids during recovery
             from the crash.
      */
      if (gtid_state->save(&gtids_in_binlog_not_in_table) == -1)
      {
        global_sid_lock->unlock();
        unireg_abort(MYSQLD_ABORT_EXIT);
      }
      executed_gtids->add_gtid_set(&gtids_in_binlog_not_in_table);
    }

    /* gtids_only_in_table= executed_gtids - gtids_in_binlog */
    if (gtids_only_in_table->add_gtid_set(executed_gtids) !=
        RETURN_STATUS_OK)
    {
      global_sid_lock->unlock();
      unireg_abort(MYSQLD_ABORT_EXIT);
    }
    gtids_only_in_table->remove_gtid_set(&gtids_in_binlog);
    /*
      lost_gtids = executed_gtids -
                   (gtids_in_binlog - purged_gtids_from_binlog)
                 = gtids_only_in_table + purged_gtids_from_binlog;
    */
    DBUG_ASSERT(lost_gtids->is_empty());
    if (lost_gtids->add_gtid_set(gtids_only_in_table) != RETURN_STATUS_OK ||
        lost_gtids->add_gtid_set(&purged_gtids_from_binlog) !=
        RETURN_STATUS_OK)
    {
      global_sid_lock->unlock();
      unireg_abort(MYSQLD_ABORT_EXIT);
    }

    /* Prepare previous_gtids_logged for next binlog */
    if (previous_gtids_logged->add_gtid_set(&gtids_in_binlog) !=
        RETURN_STATUS_OK)
    {
      global_sid_lock->unlock();
      unireg_abort(MYSQLD_ABORT_EXIT);
    }

    /*
      Write the previous set of gtids at this point because during
      the creation of the binary log this is not done as we cannot
      move the init_gtid_sets() to a place before openning the binary
      log. This requires some investigation.

      /Alfranio
    */
    Previous_gtids_log_event prev_gtids_ev(&gtids_in_binlog);

    global_sid_lock->unlock();

    (prev_gtids_ev.common_footer)->checksum_alg=
      static_cast<enum_binlog_checksum_alg>(binlog_checksum_options);

    if (prev_gtids_ev.write(mysql_bin_log.get_log_file()))
      unireg_abort(MYSQLD_ABORT_EXIT);
    mysql_bin_log.add_bytes_written(
      prev_gtids_ev.common_header->data_written);

    if (flush_io_cache(mysql_bin_log.get_log_file()) ||
        mysql_file_sync(mysql_bin_log.get_log_file()->file, MYF(MY_WME)))
      unireg_abort(MYSQLD_ABORT_EXIT);
    mysql_bin_log.update_binlog_end_pos();

    (void) RUN_HOOK(server_state, after_engine_recovery, (NULL));
  }

  /*註: 網路相關的初始化*/
  if (init_ssl())
    unireg_abort(MYSQLD_ABORT_EXIT);
  if (network_init())
    unireg_abort(MYSQLD_ABORT_EXIT);

#ifdef _WIN32
#ifndef EMBEDDED_LIBRARY
  if (opt_require_secure_transport &&
      !opt_enable_shared_memory && !opt_use_ssl &&
      !opt_initialize && !opt_bootstrap)
  {
    sql_print_error("Server is started with --require-secure-transport=ON "
                    "but no secure transports (SSL or Shared Memory) are "
                    "configured.");
    unireg_abort(MYSQLD_ABORT_EXIT);
  }
#endif

#endif

  /*
   Initialize my_str_malloc(), my_str_realloc() and my_str_free()
  */
  my_str_malloc= &my_str_malloc_mysqld;
  my_str_free= &my_str_free_mysqld;
  my_str_realloc= &my_str_realloc_mysqld;

  error_handler_hook= my_message_sql;

  /* Save pid of this process in a file */
  if (!opt_bootstrap)
    create_pid_file();


  /* Read the optimizer cost model configuration tables */
  if (!opt_bootstrap)
    reload_optimizer_cost_constants();

  if (mysql_rm_tmp_tables() || acl_init(opt_noacl) ||
      my_tz_init((THD *)0, default_tz_name, opt_bootstrap) ||
      grant_init(opt_noacl))
  {
    abort_loop= true;

    delete_pid_file(MYF(MY_WME));

    unireg_abort(MYSQLD_ABORT_EXIT);
  }

  if (!opt_bootstrap)
    servers_init(0);

  if (!opt_noacl)
  {
#ifdef HAVE_DLOPEN
    udf_init();
#endif
  }

  /*註:設置SHOW STATUS時的變數*/
  init_status_vars();
  /* If running with bootstrap, do not start replication. */
  if (opt_bootstrap)
    opt_skip_slave_start= 1;

  /*註:初始化BINLOG的值了*/
  check_binlog_cache_size(NULL);
  check_binlog_stmt_cache_size(NULL);

  binlog_unsafe_map_init();

  /* If running with bootstrap, do not start replication. */
  if (!opt_bootstrap)
  {
    // Make @@slave_skip_errors show the nice human-readable value.
    set_slave_skip_errors(&opt_slave_skip_errors);

    /*
      init_slave() must be called after the thread keys are created.
    */
    if (server_id != 0)
      init_slave(); /* Ignoring errors while configuring replication. */
  }

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
  initialize_performance_schema_acl(opt_bootstrap);
  /*
    Do not check the structure of the performance schema tables
    during bootstrap:
    - the tables are not supposed to exist yet, bootstrap will create them
    - a check would print spurious error messages
  */
  if (! opt_bootstrap)
    check_performance_schema();
#endif

  initialize_information_schema_acl();

  execute_ddl_log_recovery();
  (void) RUN_HOOK(server_state, after_recovery, (NULL));

  if (Events::init(opt_noacl || opt_bootstrap))
    unireg_abort(MYSQLD_ABORT_EXIT);

#ifndef _WIN32
  //  Start signal handler thread.
  start_signal_handler();
#endif

  /*註:啟動了*/
  if (opt_bootstrap)
  {
    start_processing_signals();

    int error= bootstrap(mysql_stdin);
    unireg_abort(error ? MYSQLD_ABORT_EXIT : MYSQLD_SUCCESS_EXIT);
  }

  if (opt_init_file && *opt_init_file)
  {
    if (read_init_file(opt_init_file))
      unireg_abort(MYSQLD_ABORT_EXIT);
  }

  /*
    Event must be invoked after error_handler_hook is assigned to
    my_message_sql, otherwise my_message will not cause the event to abort.
  */
  if (mysql_audit_notify(AUDIT_EVENT(MYSQL_AUDIT_SERVER_STARTUP_STARTUP),
                         (const char **) argv, argc))
    unireg_abort(MYSQLD_ABORT_EXIT);

#ifdef _WIN32
  create_shutdown_thread();
#endif
  start_handle_manager();

  create_compress_gtid_table_thread();

  sql_print_information(ER_DEFAULT(ER_STARTUP),
                        my_progname,
                        server_version,
#ifdef HAVE_SYS_UN_H
                        (opt_bootstrap ? (char*) "" : mysqld_unix_port),
#else
                        (char*) "",
#endif
                         mysqld_port,
                         MYSQL_COMPILATION_COMMENT);
#if defined(_WIN32)
  Service.SetRunning();
#endif

  start_processing_signals();

#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
  /* engine specific hook, to be made generic */
  if (ndb_wait_setup_func && ndb_wait_setup_func(opt_ndb_wait_setup))
  {
    sql_print_warning("NDB : Tables not available after %lu seconds."
                      "  Consider increasing --ndb-wait-setup value",
                      opt_ndb_wait_setup);
  }
#endif

  if (!opt_bootstrap)
  {
    /*
      Execute an I_S query to implicitly check for tables using the deprecated
      partition engine. No need to do this during bootstrap. We ignore the
      return value from the query execution. Note that this must be done after
      NDB is initialized to avoid polluting the server with invalid table shares.
    */
    if (!opt_disable_partition_check)
    {
      sql_print_information(
              "Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' "
              "to get a list of tables using the deprecated partition "
              "engine.");

      sql_print_information("Beginning of list of non-natively partitioned tables");
      (void) bootstrap_single_query(
              "SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES "
              "WHERE CREATE_OPTIONS LIKE '%partitioned%';");
      sql_print_information("End of list of non-natively partitioned tables");
    }
  }

  /*
    Set opt_super_readonly here because if opt_super_readonly is set
    in get_option, it will create problem while setting up event scheduler.
  */
  set_super_read_only_post_init();

  DBUG_PRINT("info", ("Block, listening for incoming connections"));

  (void)MYSQL_SET_STAGE(0 ,__FILE__, __LINE__);

  server_operational_state= SERVER_OPERATING;

  (void) RUN_HOOK(server_state, before_handle_connection, (NULL));

  /*註:設置連接池*/
#if defined(_WIN32)
  setup_conn_event_handler_threads();
#else
  mysql_mutex_lock(&LOCK_socket_listener_active);
  // Make it possible for the signal handler to kill the listener.
  socket_listener_active= true;
  mysql_mutex_unlock(&LOCK_socket_listener_active);

  if (opt_daemonize)
    mysqld::runtime::signal_parent(pipe_write_fd,1);

  mysqld_socket_acceptor->connection_event_loop();
#endif /* _WIN32 */
  server_operational_state= SERVER_SHUTTING_DOWN;

  DBUG_PRINT("info", ("No longer listening for incoming connections"));

  mysql_audit_notify(MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN,
                     MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_SHUTDOWN,
                     MYSQLD_SUCCESS_EXIT);

  terminate_compress_gtid_table_thread();
  /*
    Save set of GTIDs of the last binlog into gtid_executed table
    on server shutdown.
  */
  if (opt_bin_log)
    if (gtid_state->save_gtids_of_last_binlog_into_table(false))
      sql_print_warning("Failed to save the set of Global Transaction "
                        "Identifiers of the last binary log into the "
                        "mysql.gtid_executed table while the server was "
                        "shutting down. The next server restart will make "
                        "another attempt to save Global Transaction "
                        "Identifiers into the table.");

#ifndef _WIN32
  mysql_mutex_lock(&LOCK_socket_listener_active);
  // Notify the signal handler that we have stopped listening for connections.
  socket_listener_active= false;
  mysql_cond_broadcast(&COND_socket_listener_active);
  mysql_mutex_unlock(&LOCK_socket_listener_active);
#endif // !_WIN32

#ifdef HAVE_PSI_THREAD_INTERFACE
  /*
    Disable the main thread instrumentation,
    to avoid recording events during the shutdown.
  */
  PSI_THREAD_CALL(delete_current_thread)();
#endif

  DBUG_PRINT("info", ("Waiting for shutdown proceed"));
  int ret= 0;
#ifdef _WIN32
  if (shutdown_thr_handle.handle)
    ret= my_thread_join(&shutdown_thr_handle, NULL);
  shutdown_thr_handle.handle= NULL;
  if (0 != ret)
    sql_print_warning("Could not join shutdown thread. error:%d", ret);
#else
  if (signal_thread_id.thread != 0)
    ret= my_thread_join(&signal_thread_id, NULL);
  signal_thread_id.thread= 0;
  if (0 != ret)
    sql_print_warning("Could not join signal_thread. error:%d", ret);
#endif
  /*註:請理退出*/
  clean_up(1);
  mysqld_exit(MYSQLD_SUCCESS_EXIT);
}

  

好了,第一天,只看這一節代碼就夠了

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 初來乍到。 瞭解下,溫故。 十大經典排序演算法: https://www.cnblogs.com/onepixel/articles/7674659.html ...
  • 無需軟體windows如何加密文件夾,在百部百科上看到,放在博客中以便查看。 ...
  • 一、建立虛擬機(沒有在筆記中出現的視圖按照預設安裝即可、綠色背景圖片註意不要太過於關註上邊的文字抓要是關於分區表設置的借鑒) 二、安裝系統 註意此處。如果是想設置GTP格式的分區表可以看下麵的綠色背景圖片否則可直接略過 下麵的兩張圖片可省略配置 ...
  • 貼上內容來源https://www.cnblogs.com/Alier/p/6358447.html 1 備份原來的更新源 2 修改更新源 打開sources.list (這就是存放更新源的文件) 1.阿裡源 將下麵所有內容複製,粘貼並覆蓋sources.list文件中的所有內容 2.清華源 進入網 ...
  • 從事DBA工作多年 MYSQL源碼也是頭一次接觸 嘗試記錄下自己看MYSQL5.7源碼的歷程 目錄: 51ak帶你看MYSQL5.7源碼1:main入口函數 51ak帶你看MYSQL5.7源碼2:編譯現有的代碼 現在把剛纔在VSCODE里看到的源碼,安裝成服務。 測試機:CENTOS6 (虛機配置為 ...
  • 準備環境 官方鏈接:https://github.com/Qihoo360/Atlas/wiki/Atlas%E7%9A%84%E5%AE%89%E8%A3%85 主從搭建:http://www.cnblogs.com/cypress/p/8610279.html 一、配置主從資料庫訪問連接 開啟對 ...
  • 一:什麼是索引 索引本身是一個獨立的存儲單位,在該單位裡邊有記錄著數據表某個欄位和欄位對應的物理空間。索引內部有演算法支持,可以使查詢速度非常快。 有了索引,我們根據索引為條件進行數據查詢,速度就非常快 1,索引本身有“演算法”支持,可以快速定位我們要找到的關鍵字(欄位) 2,索引欄位與物理地址有直接對 ...
  • 分割線 Thu Mar 22 14:47:41 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.4 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...