开发者社区> 问答> 正文

binlog的ddl中出现注释导致此消息被丢弃?

当dba操作ddl时,例如新增一个字段,如果在命令前有注释的话,canal最终解析不到这个事件。 但是如果没有前面这行注释,就能解析到这条binlog, /** * optional bool isDdl = 10 [default = false]; * *

 ** 标识是否是ddl语句  * * 
*/ public boolean getIsDdl() { return isDdl_; }

也就是说,如果执行ddl时指定了注释:

`# at 708574121 #180403 0:33:33 server id 248037 end_log_pos 708574490 CRC32 0x0e8bdfed Query thread_id=15086636 exec_time=1647 error_code=0 SET TIMESTAMP=1522686813/!/; -- 注释注释 ALTER TABLE on_ord_act_paid03 ADD receivables_mch_id VARCHAR(50) DEFAULT NULL COMMENT 'Foo', MODIFY COLUMN payment_method SMALLINT NOT NULL COMMENT 'Bar' /!/;

#180403 1:01:00 server id 248037 end_log_pos 708574578 CRC32 0x51d11ba5 Query thread_id=15086688 exec_time=0 error_code=0 SET TIMESTAMP=1522688460/!/;` 那么这条binlog的rowChange.getIsDdl()应该目前是返回的false。 如果去掉“-- 注释注释 ”,则返回true。

当前数据库相关信息: Server version: 5.6.21-log Source distribution innodb_version 5.6.21 当前实例的binlog配置信息:

| binlog_cache_size | 2097152 | | binlog_checksum | CRC32 | | binlog_direct_non_transactional_updates | OFF | | binlog_format | ROW | | binlog_max_flush_queue_time | 0 | | binlog_order_commits | ON | | binlog_row_image | FULL | | binlog_rows_query_log_events | OFF | | binlog_stmt_cache_size | 2097152 | | binlogging_impossible_mode | IGNORE_ERROR | | innodb_api_enable_binlog | OFF | | innodb_locks_unsafe_for_binlog | OFF | | log_bin | ON | | log_bin_basename | /data/mysql_3306/mysql-bin | | log_bin_index | /data/mysql_3306/mysql-bin.index | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | simplified_binlog_gtid_recovery | OFF | | sql_log_bin | ON | | sync_binlog | 100 |

mysql.conf

[mysqld] basedir=/usr/local/mysql datadir=/data/mysql_3306 socket=/data/mysql_3306/mysql.sock

port=3306 server_id=248037

log-bin=mysql-bin binlog_format = ROW relay-log=mysqld-relay-bin sync_binlog = 100 relay_log_purge=0

log_slave_updates

query_cache_type = 0 query_cache_size = 0

table_definition_cache = 2048 table_open_cache = 4096 table_open_cache_instances = 8

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

skip-name-resolve back_log = 100 max_connections = 1000 max_connect_errors = 100000 max_allowed_packet = 16M binlog_cache_size = 2M binlog_stmt_cache_size = 2M max_heap_table_size = 256M tmp_table_size = 8M sort_buffer_size = 8M thread_cache_size = 256 ft_min_word_len = 4 thread_stack = 192K long_query_time = 3 tmpdir = /tmp

key_buffer_size = 8M read_buffer_size = 8M join_buffer_size = 8M read_rnd_buffer_size = 8M bulk_insert_buffer_size = 8M

character_set_server = utf8 collation_server = utf8_general_ci transaction_isolation = REPEATABLE-READ

default_storage_engine = InnoDB default_tmp_storage_engine = InnoDB

innodb_buffer_pool_size = 30G innodb_file_per_table = 1 innodb_file_io_threads = 4 innodb_thread_concurrency = 32 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 256M innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_flush_method = O_DIRECT innodb_lock_wait_timeout = 120 innodb_open_files = 32768 innodb_online_alter_log_max_size = 32G

slow_query_log = on long_query_time = 0.5 slow_query_log_file = mysql-slow

[mysql] default-character-set=utf8 sock = /data/mysql_3306/mysql.sock

[mysqld_safe] log-error=/data/mysql_3306/mysqld.err pid-file=/data/mysql_3306/mysqld.pid

原提问者GitHub用户yangyongzhi7

展开
收起
绿子直子 2023-05-09 10:41:23 112 0
1 条回答
写回答
取消 提交回答
  • 尝试使用最新的26版本,已经基于DDL的SQL全解析的方式,可以支持注释

    原回答者GitHub用户agapple

    2023-05-10 10:08:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PolarDB-X 2.0 全局 Binlog 与备份恢复能 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载