MySQL:binlog_do_db statement模式和row格式的不同

一、整體過濾規(guī)則在函數(shù)

今天收到這個需求军援,不由的稍微看了一下宠进,整體過濾規(guī)則為:
Rpl_filter::db_ok

二、語句模式:

#0  Rpl_filter::db_ok (this=0x2f3ba10, db=0x0) at /opt/percona-server-locks-detail-5.7.22/sql/rpl_filter.cc:165
#1  0x000000000181a00f in THD::decide_logging_format (this=0x7fff90000b70, tables=0x7fff90006770) at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:10844
#2  0x00000000014e5bde in lock_tables (thd=0x7fff90000b70, tables=0x7fff90006770, count=1, flags=0) at /opt/percona-server-locks-detail-5.7.22/sql/sql_base.cc:6850
#3  0x000000000178c5a4 in Sql_cmd_insert::mysql_insert (this=0x7fff90006cf8, thd=0x7fff90000b70, table_list=0x7fff90006770) at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:617
#4  0x0000000001793615 in Sql_cmd_insert::execute (this=0x7fff90006cf8, thd=0x7fff90000b70) at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:3121
#5  0x000000000156bc46 in mysql_execute_command (thd=0x7fff90000b70, first_level=true) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3746
#6  0x0000000001571bed in mysql_parse (thd=0x7fff90000b70, parser_state=0x7fffec14e5b0) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901
#7  0x000000000156673d in dispatch_command (thd=0x7fff90000b70, com_data=0x7fffec14ed90, command=COM_QUERY) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490
#8  0x00000000015655c5 in do_command (thd=0x7fff90000b70) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1021
#9  0x00000000016a635c in handle_connection (arg=0x3bc97f0) at /opt/percona-server-locks-detail-5.7.22/sql/conn_handler/connection_handler_per_thread.cc:312
#10 0x00000000018ce0ca in pfs_spawn_thread (arg=0x4001e00) at /opt/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
#11 0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthread.so.0
#12 0x00007ffff66748dd in clone () from /lib64/libc.so.6
Breakpoint 1, Rpl_filter::db_ok (this=0x2f3ba10, db=0x0) at /opt/percona-server-locks-detail-5.7.22/sql/rpl_filter.cc:165
165       DBUG_ENTER("Rpl_filter::db_ok");
(gdb) bt
#0  Rpl_filter::db_ok (this=0x2f3ba10, db=0x0) at /opt/percona-server-locks-detail-5.7.22/sql/rpl_filter.cc:165
#1  0x0000000001812d57 in MYSQL_BIN_LOG::write_event (this=0x2dc09e0 <mysql_bin_log>, event_info=0x7fffec14c0f0) at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:7621
#2  0x000000000181d87a in THD::binlog_query (this=0x7fff90000b70, qtype=THD::ROW_QUERY_TYPE, query_arg=0x7fff90005bf0 "insert into test.tu10 values(10)", query_len=32, is_trans=true, 
    direct=false, suppress_use=false, errcode=0) at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:12437
#3  0x000000000178d046 in Sql_cmd_insert::mysql_insert (this=0x7fff90006cf8, thd=0x7fff90000b70, table_list=0x7fff90006770) at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:866
#4  0x0000000001793615 in Sql_cmd_insert::execute (this=0x7fff90006cf8, thd=0x7fff90000b70) at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:3121
#5  0x000000000156bc46 in mysql_execute_command (thd=0x7fff90000b70, first_level=true) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3746
#6  0x0000000001571bed in mysql_parse (thd=0x7fff90000b70, parser_state=0x7fffec14e5b0) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901
#7  0x000000000156673d in dispatch_command (thd=0x7fff90000b70, com_data=0x7fffec14ed90, command=COM_QUERY) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490
#8  0x00000000015655c5 in do_command (thd=0x7fff90000b70) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1021
#9  0x00000000016a635c in handle_connection (arg=0x3bc97f0) at /opt/percona-server-locks-detail-5.7.22/sql/conn_handler/connection_handler_per_thread.cc:312
#10 0x00000000018ce0ca in pfs_spawn_thread (arg=0x4001e00) at /opt/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
#11 0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthrea

這里THD::decide_logging_format 有響應(yīng)的控制萝风,我們可以稍微看到如下邏輯:

!(variables.binlog_format == BINLOG_FORMAT_STMT &&
        !binlog_filter->db_ok(m_db.str))

而m_db則是 current db也就是登陸的db嘀掸。所以按照的登陸db進(jìn)行過濾

三、row格式:

這個過濾是在 check_table_binlog_row_based完成的规惰,判斷是binlog_filter->db_ok(table->s->db.str)睬塌,我們可以看到這個db明顯是表所在的db。而不是當(dāng)前登錄的db歇万。并且是每次open table后判斷一次而已揩晴,一旦判斷完成根據(jù)check_table_binlog_row_based的邏輯則修改了table->s->cached_row_logging_check=0,以后都會進(jìn)行判斷了贪磺,效率也會高一些硫兰。

(gdb) bt
#0  Rpl_filter::db_ok (this=0x2f3ba10, db=0x7fff9000fc08 "test") at /opt/percona-server-locks-detail-5.7.22/sql/rpl_filter.cc:165
#1  0x0000000000f634ec in check_table_binlog_row_based (thd=0x7fff90000b70, table=0x7fff90010820) at /opt/percona-server-locks-detail-5.7.22/sql/handler.cc:8177
#2  0x0000000000f638b3 in binlog_log_row (table=0x7fff90010820, before_record=0x0, after_record=0x7fff90011720 "\375\n", 
    log_func=0xf692d4 <Write_rows_log_event::binlog_row_logging_function(THD*, TABLE*, bool, unsigned char const*, unsigned char const*)>)
    at /opt/percona-server-locks-detail-5.7.22/sql/handler.cc:8288
#3  0x0000000000f6428e in handler::ha_write_row (this=0x7fff900111e0, buf=0x7fff90011720 "\375\n") at /opt/percona-server-locks-detail-5.7.22/sql/handler.cc:8473
#4  0x000000000178fb3e in write_record (thd=0x7fff90000b70, table=0x7fff90010820, info=0x7fffec14d000, update=0x7fffec14d080)
    at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:1881
#5  0x000000000178cca0 in Sql_cmd_insert::mysql_insert (this=0x7fff90006cf8, thd=0x7fff90000b70, table_list=0x7fff90006770) at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:773
#6  0x0000000001793615 in Sql_cmd_insert::execute (this=0x7fff90006cf8, thd=0x7fff90000b70) at /opt/percona-server-locks-detail-5.7.22/sql/sql_insert.cc:3121
#7  0x000000000156bc46 in mysql_execute_command (thd=0x7fff90000b70, first_level=true) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3746
#8  0x0000000001571bed in mysql_parse (thd=0x7fff90000b70, parser_state=0x7fffec14e5b0) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901
#9  0x000000000156673d in dispatch_command (thd=0x7fff90000b70, com_data=0x7fffec14ed90, command=COM_QUERY) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490
#10 0x00000000015655c5 in do_command (thd=0x7fff90000b70) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1021
#11 0x00000000016a635c in handle_connection (arg=0x3bc97f0) at /opt/percona-server-locks-detail-5.7.22/sql/conn_handler/connection_handler_per_thread.cc:312
#12 0x00000000018ce0ca in pfs_spawn_thread (arg=0x4001e00) at /opt/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
#13 0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthread.so.0
#14 0x00007ffff66748dd in clone () from /lib64/libc.so.6
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市寒锚,隨后出現(xiàn)的幾起案子劫映,更是在濱河造成了極大的恐慌,老刑警劉巖刹前,帶你破解...
    沈念sama閱讀 221,548評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件泳赋,死亡現(xiàn)場離奇詭異,居然都是意外死亡腮郊,警方通過查閱死者的電腦和手機(jī)摹蘑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,497評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來轧飞,“玉大人衅鹿,你說我怎么就攤上這事撒踪。” “怎么了大渤?”我有些...
    開封第一講書人閱讀 167,990評論 0 360
  • 文/不壞的土叔 我叫張陵制妄,是天一觀的道長。 經(jīng)常有香客問我泵三,道長耕捞,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,618評論 1 296
  • 正文 為了忘掉前任烫幕,我火速辦了婚禮俺抽,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘较曼。我一直安慰自己磷斧,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 68,618評論 6 397
  • 文/花漫 我一把揭開白布捷犹。 她就那樣靜靜地躺著弛饭,像睡著了一般。 火紅的嫁衣襯著肌膚如雪萍歉。 梳的紋絲不亂的頭發(fā)上侣颂,一...
    開封第一講書人閱讀 52,246評論 1 308
  • 那天,我揣著相機(jī)與錄音枪孩,去河邊找鬼憔晒。 笑死,一個胖子當(dāng)著我的面吹牛蔑舞,可吹牛的內(nèi)容都是我干的丛晌。 我是一名探鬼主播,決...
    沈念sama閱讀 40,819評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼斗幼,長吁一口氣:“原來是場噩夢啊……” “哼澎蛛!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蜕窿,我...
    開封第一講書人閱讀 39,725評論 0 276
  • 序言:老撾萬榮一對情侶失蹤谋逻,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后桐经,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體毁兆,經(jīng)...
    沈念sama閱讀 46,268評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,356評論 3 340
  • 正文 我和宋清朗相戀三年阴挣,在試婚紗的時候發(fā)現(xiàn)自己被綠了气堕。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,488評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖茎芭,靈堂內(nèi)的尸體忽然破棺而出揖膜,到底是詐尸還是另有隱情,我是刑警寧澤梅桩,帶...
    沈念sama閱讀 36,181評論 5 350
  • 正文 年R本政府宣布壹粟,位于F島的核電站,受9級特大地震影響宿百,放射性物質(zhì)發(fā)生泄漏趁仙。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,862評論 3 333
  • 文/蒙蒙 一垦页、第九天 我趴在偏房一處隱蔽的房頂上張望雀费。 院中可真熱鬧,春花似錦痊焊、人聲如沸坐儿。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,331評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至炭菌,卻和暖如春罪佳,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背黑低。 一陣腳步聲響...
    開封第一講書人閱讀 33,445評論 1 272
  • 我被黑心中介騙來泰國打工赘艳, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人克握。 一個月前我還...
    沈念sama閱讀 48,897評論 3 376
  • 正文 我出身青樓蕾管,卻偏偏與公主長得像,于是被迫代替她去往敵國和親菩暗。 傳聞我的和親對象是個殘疾皇子掰曾,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,500評論 2 359

推薦閱讀更多精彩內(nèi)容