MySQL binlog发送

本文主要探讨MySQL数据库的binlog发送过程,重点关注sql_parser.cc文件中如何解析SQL语句,理解binlog在数据库复制和数据恢复中的关键作用。
摘要由CSDN通过智能技术生成

sql_parser.cc 中处理语句

 case COM_BINLOG_DUMP_GTID:
    // TODO: access of protocol_classic should be removed
    error=
      com_binlog_dump_gtid(thd,
        (char *)thd->get_protocol_classic()->get_raw_packet(),
        thd->get_protocol_classic()->get_packet_length());
    break;
  case COM_BINLOG_DUMP:
    // TODO: access of protocol_classic should be removed
    error=
      com_binlog_dump(thd,
        (char*)thd->get_protocol_classic()->get_raw_packet(),
        thd->get_protocol_classic()->get_packet_length());
    break;

普通复制调用com_binlog_dump
kill_zombie_dump_threads(thd);

  query_logger.general_log_print(thd, thd->get_command(), "Log: '%s'  Pos: %ld",
                                 packet + 10, (long) pos);
  mysql_binlog_send(thd, thd->mem_strdup(packet + 10), (my_off_t) pos, NULL, flags);--只要复制没被kill 就一直发送

  unregister_slave(thd, true, true/*need_lock_slave_list=true*/);

void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos,
                       Gtid_set* slave_gtid_executed, uint32 flags)
{
   
  Binlog_sender sender(thd, log_ident, pos, slave_gtid_executed, flags);

  sender.run();
}

void Binlog_sender::run()
{
   
  DBUG_ENTER("Binlog_sender::run");
  File file= -1;
  IO_CACHE log_cache;
  my_off_t start_pos= m_start_pos;
  const char *log_file= m_linfo.log_file_name;
  bool is_index_file_reopened_on_binlog_disable= false;
  init();

  while (!has_error() && !m_thd->killed)
  {
   
    /*
      Faked rotate event is only required in a few cases(see comment of the
      function). But even so, a faked rotate event is always sent before sending
      event log file, even if a rotate log event exists in last binlog and
      was already sent. The slave then gets an extra rotation and records
      two Rotate_log_events.

      The main issue here are some dependencies on mysqlbinlog, that should be
      solved in the future.
    */
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值