mysql源碼---核心類 (1)線程類

來源:互聯網
上載者:User

標籤:優先順序   用戶端   mysql   

線程是mysql一個很重要的概念。線程用來處理來自用戶端的串連,線程和串連是1:1的關。線程和THD對象也是1:1對應的關係,有些線程會被設定為優先,而有些線程沒有優先順序,而線程的優先順序設定在sql/mysql_priv.h

#define INTERRUPT_PRIOR -2

#define CONNECT_PRIOR-1

#define WAIT_PRIOR0

#define QUERY_PRIOR2

(THD是mysql線程描述符類)


線程初始化工作:

void THD::init(void)

{

  pthread_mutex_lock(&LOCK_global_system_variables);

  plugin_thdvar_init(this);

  variables.time_format= date_time_format_copy((THD*) 0,

      variables.time_format);

  variables.date_format= date_time_format_copy((THD*) 0,

      variables.date_format);

  variables.datetime_format= date_time_format_copy((THD*) 0,

  variables.datetime_format);

  /*

    variables= global_system_variables above has reset

    variables.pseudo_thread_id to 0. We need to correct it here to

    avoid temporary tables replication failure.

  */

  variables.pseudo_thread_id= thread_id;

  pthread_mutex_unlock(&LOCK_global_system_variables);

  server_status= SERVER_STATUS_AUTOCOMMIT;

  if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)

    server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;

  options= thd_startup_options;


  if (variables.max_join_size == HA_POS_ERROR)

    options |= OPTION_BIG_SELECTS;

  else

    options &= ~OPTION_BIG_SELECTS;


  transaction.all.modified_non_trans_table= transaction.stmt.modified_non_trans_table= FALSE;

  open_options=ha_open_options;

  update_lock_default= (variables.low_priority_updates ?

TL_WRITE_LOW_PRIORITY :

TL_WRITE);

  session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;

  update_charset();

  reset_current_stmt_binlog_row_based();

  bzero((char *) &status_var, sizeof(status_var));

  sql_log_bin_toplevel= options & OPTION_BIN_LOG;


#if defined(ENABLED_DEBUG_SYNC)

  /* Initialize the Debug Sync Facility. See debug_sync.cc. */

  debug_sync_init_thread(this);

#endif /* defined(ENABLED_DEBUG_SYNC) */

}


還有一些cleanup等函數,走在該檔案中實現




本文出自 “Linux營運” 部落格,請務必保留此出處http://2853725.blog.51cto.com/2843725/1544160

mysql源碼---核心類 (1)線程類

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.