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

一、整体过滤规则在函数

今天收到这个需求,不由的稍微看了一下,整体过滤规则为:
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 有响应的控制,我们可以稍微看到如下逻辑:

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

而m_db则是 current db也就是登陆的db。所以按照的登陆db进行过滤

三、row格式:

这个过滤是在 check_table_binlog_row_based完成的,判断是binlog_filter->db_ok(table->s->db.str),我们可以看到这个db明显是表所在的db。而不是当前登录的db。并且是每次open table后判断一次而已,一旦判断完成根据check_table_binlog_row_based的逻辑则修改了table->s->cached_row_logging_check=0,以后都会进行判断了,效率也会高一些。

(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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,589评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,615评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,933评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,976评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,999评论 6 393
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,775评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,474评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,359评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,854评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,007评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,146评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,826评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,484评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,029评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,153评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,420评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,107评论 2 356

推荐阅读更多精彩内容