Seconds_Behind_Master的计算

     MySQL复制中seconds_behind_master的计算
     
1.seconds_behind_master定义为从库相对于主库的延迟时间。
    具体的计算公式为:
        clock_of_slave - last_timestamp_executed_by_SQL_thread-clock_diff_with_master.
        
    备注:位于rpl_mi.h中定义了clock_diff_with_master,该值为从库相对于主库的时间差。
          /*
     The difference in seconds between the clock of the master and the clock of
     the slave (second - first). It must be signed as it may be <0 or >0.
     clock_diff_with_master is computed when the I/O thread starts; for this the
     I/O thread does a SELECT UNIX_TIMESTAMP() on the master.
     "how late the slave is compared to the master" is computed like this:
     clock_of_slave - last_timestamp_executed_by_SQL_thread - clock_diff_with_master
  */
  long clock_diff_with_master;
  //  clock_diff_with_master
  // mi->clock_diff_with_master=
      (long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10));
      master_row[0]就是在主库上执行SELECT UNIX_TIMESTAMP()的操作。
      从如下到(rpl_slave.cc)可以看出:
      start_slave_thread->  //启动start slave
            handle_slave_io-> //启动start io thread
                get_master_version_and_clock //获取当前slave和主机之间的时间差(clock_diff_with_master)
                
   /*
    Used to defer stopping the SQL thread to give it a chance
    to finish up the current group of events.
    The timestamp is set and reset in @c sql_slave_killed().
  */
  time_t last_event_start_time; //slave端最后执行的reply log的最后一个事件的时间
  
    

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值