mysql中雙1控制原始碼分析

2021-10-24 09:37:20 字數 4569 閱讀 9169

1、innodb_flush_log_at_trx_commit引數討論

引數含義:該引數主要是是來控制redo log的刷盤策略,有原始碼的呼叫棧可知,該引數生效的地方如下:

#0  log_buffer_flush_to_disk (sync=true) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/storage/innobase/log/log0log.cc:1419

#1 0x00000000019b1999 in innobase_flush_logs (hton=0x2e34060, binlog_group_flush=true) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/storage/innobase/handler/ha_innodb.cc:4214

#2 0x0000000000f25af3 in flush_handlerton (thd=0x0, plugin=0x7fffec12a128, arg=0x7fffec12a1c4) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/handler.cc:2471

#3 0x000000000155fccf in plugin_foreach_with_mask (thd=0x0, funcs=0x7fffec12a1a0, type=1, state_mask=4294967287, arg=0x7fffec12a1c4) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/sql_plugin.cc:2426

#4 0x000000000155fd8f in plugin_foreach_with_mask (thd=0x0, func=0xf25a95 , type=1, state_mask=8, arg=0x7fffec12a1c4) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/sql_plugin.cc:2441

#5 0x0000000000f25b4f in ha_flush_logs (db_type=0x0, binlog_group_flush=true) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/handler.cc:2481

#6 0x00000000017e1e07 in mysql_bin_log::process_flush_stage_queue (this=0x2d850e0 , total_bytes_var=0x7fffec12a2e8, rotate_var=0x7fffec12a2e7, out_queue_var=0x7fffec12a2d8)

at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/binlog.cc:8652

#7 0x00000000017e33c2 in mysql_bin_log::ordered_commit (this=0x2d850e0 , thd=0x7fff30000b70, all=false, skip_commit=false) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/binlog.cc:9304

#8 0x00000000017e1ab8 in mysql_bin_log::commit (this=0x2d850e0 , thd=0x7fff30000b70, all=false) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/binlog.cc:8552

#9 0x0000000000f245e9 in ha_commit_trans (thd=0x7fff30000b70, all=false, ignore_global_read_lock=false) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/handler.cc:1796

#10 0x0000000001634116 in trans_commit_stmt (thd=0x7fff30000b70) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/transaction.cc:458

#11 0x0000000001535908 in mysql_execute_command (thd=0x7fff30000b70, first_level=true) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/sql_parse.cc:5004

#12 0x0000000001536f3f in mysql_parse (thd=0x7fff30000b70, parser_state=0x7fffec12c690) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/sql_parse.cc:5582

#13 0x000000000152c7ca in dispatch_command (thd=0x7fff30000b70, com_data=0x7fffec12cdf0, command=com_query) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/sql_parse.cc:1458

#14 0x000000000152b6fe in do_command (thd=0x7fff30000b70) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/sql_parse.cc:999

#15 0x0000000001663c68 in handle_connection (arg=0x6d99650) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/sql/conn_handler/connection_handler_per_thread.cc:303

#16 0x00000000018b6cb0 in pfs_spawn_thread (arg=0x6dd6e00) at /mysql/zxz/mysqlsourcetest/mysql-5.7.21/storage/perfschema/pfs.cc:2190

#17 0x00007ffff7bc6dd5 in start_thread () from /lib64/libpthread.so.0

#18 0x00007ffff6817ead in clone () from /lib64/libc.so.6

在 innobase_flush_log函式中innodb_flush_log_at_trx_commit有如下的組合策略y

/* if !binlog_group_flush, we got invoked by flush logs or similar.

else, we got invoked by binlog group commit during flush stage. */

if (binlog_group_flush && srv_flush_log_at_trx_commit == 0)

/* flush the redo log buffer to the redo log file.

sync it to disc if we are in flush logs, or if

innodb_flush_log_at_trx_commit=1

(write and sync at each commit). */

log_buffer_flush_to_disk(!binlog_group_flush

|| srv_flush_log_at_trx_commit == 1);

由於binlog_group_flush值始終未為true,因此有以下三種刷盤策略:

a、innodb_flush_log_at_trx_commi為0

log_buffer_flush_to_disk函式不會被呼叫,因此不會做redo刷盤,更不會做sync,依賴於master執行緒

b、innodb_flush_log_at_trx_commi為1

會呼叫log_buffer_flush_to_disk(true),需要在事物每次提交時做redo刷盤,也需要做sync

c、innodb_flush_log_at_trx_commi為2

會呼叫log_buffer_flush_to_disk(false),因此需要做redo刷盤,不做sync,依賴os的刷盤機制;

2、sync_binlog引數討論

引數含義:該引數主要用來控制binlog的刷盤機制

1、sync_binlog!=1

影響1:會在flush階段結束後,喚醒dump執行緒傳送binlog

2、sync_binlog=1或者sync_binlog=0

影響1:會進入stage_manager.wait_count_or_timeout的邏輯,該函式主要由兩個引數來進行控制binlog_group_commit_sync_delay和binlog_group_commit_sync_no_delay_count來決定是否需要等待足夠數量的組提交後進行提交;

影響2:根據binlog的設定來決定是否進行刷盤;依據的條件是(sync_period && ++sync_counter >= sync_period);

影響3:如果binlog=1,這裡將會喚醒dump執行緒進行event的傳送

MySql原始碼分析

2.請求資料流 原始碼才是王道。1.主函式sql mysqld.cc中,如下 標準入口函式 int main int argc,char ar 2.監聽連線 sql mysqld.cc handle connections sockets pthread handler t handle conne...

cvDilate 原始碼分析 1

在cv.h檔案中對cvdilate的定義如下 cvapi void cvdilate const cvarr src,cvarr dst,iplconvkernel element cv default null int iterations cv default 1 iplconvkernel 指...

leveldb原始碼分析1

leveldb是乙個key value型的儲存引擎,由google開發,並宣布在bsd許可下開放源 plain git clone plain cd leveldb make all 此時生成libleveldb.a庫檔案。拷貝leveldb的標頭檔案到 usr include下 plain cp ...