好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 詳解MySQL的Seconds_Behind_Master

詳解MySQL的Seconds_Behind_Master

熱門標簽:呂梁外呼系統 html地圖標注并導航 催天下外呼系統 400電話變更申請 武漢電銷機器人電話 大豐地圖標注app 北京金倫外呼系統 400電話辦理服務價格最實惠 南太平洋地圖標注

Seconds_Behind_Master

對于mysql主備實例,seconds_behind_master是衡量master與slave之間延時的一個重要參數。通過在slave上執行"show slave status;"可以獲取seconds_behind_master的值。

原始實現

Definition:The number of seconds that the slave SQL thread is behind processing the master binary log.

Type:time_t(long)

計算方式如下:

rpl_slave.cc::show_slave_status_send_data()
if ((mi->get_master_log_pos() == mi->rli->get_group_master_log_pos()) 
       (!strcmp(mi->get_master_log_name(),
                mi->rli->get_group_master_log_name()))) {
     if (mi->slave_running == MYSQL_SLAVE_RUN_CONNECT)
       protocol->store(0LL);
     else
       protocol->store_null();
   } else {
     long time_diff = ((long)(time(0) - mi->rli->last_master_timestamp) -
                       mi->clock_diff_with_master);
     protocol->store(
         (longlong)(mi->rli->last_master_timestamp ? max(0L, time_diff) : 0));
   }

主要分為以下兩種情況:

  • SQL線程等待IO線程獲取主機binlog,此時seconds_behind_master為0,表示備機與主機之間無延時;
  • SQL線程處理relay log,此時seconds_behind_master通過(long)(time(0) – mi->rli->last_master_timestamp) – mi->clock_diff_with_master計算得到;

last_master_timestamp

定義:

主庫binlog中事件的時間。

type: time_t (long)

計算方式:

last_master_timestamp根據備機是否并行復制有不同的計算方式。

非并行復制:

rpl_slave.cc:exec_relay_log_event()
if ((!rli->is_parallel_exec() || rli->last_master_timestamp == 0) 
    !(ev->is_artificial_event() || ev->is_relay_log_event() ||
     (ev->common_header->when.tv_sec == 0) ||
     ev->get_type_code() == binary_log::FORMAT_DESCRIPTION_EVENT ||
     ev->server_id == 0))
{
 rli->last_master_timestamp= ev->common_header->when.tv_sec +
                             (time_t) ev->exec_time;
 DBUG_ASSERT(rli->last_master_timestamp >= 0);
}

在該模式下,last_master_timestamp表示為每一個event的結束時間,其中when.tv_sec表示event的開始時間,exec_time表示事務的執行時間。該值的計算在apply_event之前,所以event還未執行時,last_master_timestamp已經被更新。由于exec_time僅在Query_log_event中存在,所以last_master_timestamp在應用一個事務的不同event階段變化。以一個包含兩條insert語句的事務為例,在該代碼段的調用時,打印出event的類型、時間戳和執行時間

create table t1(a int PRIMARY KEY AUTO_INCREMENT ,b longblob) engine=innodb;
begin;
insert into t1(b) select repeat('a',104857600);
insert into t1(b) select repeat('a',104857600);
commit;

10T06:41:32.628554Z 11 [Note] [MY-000000] [Repl] event_type: 33 GTID_LOG_EVENT

2020-02-10T06:41:32.628601Z 11 [Note] [MY-000000] [Repl] event_time: 1581316890

2020-02-10T06:41:32.628614Z 11 [Note] [MY-000000] [Repl] event_exec_time: 0

2020-02-10T06:41:32.628692Z 11 [Note] [MY-000000] [Repl] event_type: 2   QUERY_EVENT

2020-02-10T06:41:32.628704Z 11 [Note] [MY-000000] [Repl] event_time: 1581316823

2020-02-10T06:41:32.628713Z 11 [Note] [MY-000000] [Repl] event_exec_time: 35

2020-02-10T06:41:32.629037Z 11 [Note] [MY-000000] [Repl] event_type: 19   TABLE_MAP_EVENT

2020-02-10T06:41:32.629057Z 11 [Note] [MY-000000] [Repl] event_time: 1581316823

2020-02-10T06:41:32.629063Z 11 [Note] [MY-000000] [Repl] event_exec_time: 0

2020-02-10T06:41:33.644111Z 11 [Note] [MY-000000] [Repl] event_type: 30    WRITE_ROWS_EVENT

2020-02-10T06:41:33.644149Z 11 [Note] [MY-000000] [Repl] event_time: 1581316823

2020-02-10T06:41:33.644156Z 11 [Note] [MY-000000] [Repl] event_exec_time: 0

2020-02-10T06:41:43.520272Z 0 [Note] [MY-011953] [InnoDB] Page cleaner took 9185ms to flush 3 and evict 0 pages

2020-02-10T06:42:05.982458Z 11 [Note] [MY-000000] [Repl] event_type: 19   TABLE_MAP_EVENT

2020-02-10T06:42:05.982488Z 11 [Note] [MY-000000] [Repl] event_time: 1581316858

2020-02-10T06:42:05.982495Z 11 [Note] [MY-000000] [Repl] event_exec_time: 0

2020-02-10T06:42:06.569345Z 11 [Note] [MY-000000] [Repl] event_type: 30    WRITE_ROWS_EVENT

2020-02-10T06:42:06.569376Z 11 [Note] [MY-000000] [Repl] event_time: 1581316858

2020-02-10T06:42:06.569384Z 11 [Note] [MY-000000] [Repl] event_exec_time: 0

2020-02-10T06:42:16.506176Z 0 [Note] [MY-011953] [InnoDB] Page cleaner took 9352ms to flush 8 and evict 0 pages

2020-02-10T06:42:37.202507Z 11 [Note] [MY-000000] [Repl] event_type: 16    XID_EVENT

2020-02-10T06:42:37.202539Z 11 [Note] [MY-000000] [Repl] event_time: 1581316890

2020-02-10T06:42:37.202546Z 11 [Note] [MY-000000] [Repl] event_exec_time: 0

并行復制:

rpl_slave.cc   mts_checkpoint_routine
ts = rli->gaq->empty()
          ? 0
          : reinterpret_castSlave_job_group *>(rli->gaq->head_queue())->ts;
 rli->reset_notified_checkpoint(cnt, ts, true);
 /* end-of "Coordinator::"commit_positions" */

在該模式下備機上存在一個分發隊列gaq,如果gaq為空,則設置last_commit_timestamp為0;如果gaq不為空,則此時維護一個checkpoint點lwm,lwm之前的事務全部在備機上執行完成,此時last_commit_timestamp被更新為lwm所在事務執行完成后的時間。該時間類型為time_t類型。

ptr_group->ts = common_header->when.tv_sec +
                   (time_t)exec_time;  // Seconds_behind_master related
rli->rli_checkpoint_seqno++;
if (update_timestamp) {
 mysql_mutex_lock(data_lock);
 last_master_timestamp = new_ts;
 mysql_mutex_unlock(data_lock);
}

在并行復制下,event執行完成之后才會更新last_master_timestamp,所以非并行復制和并行復制下的seconds_behind_master會存在差異。

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.
  • type: long
rpl_slave.cc::get_master_version_and_clock()
if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) 
     (master_res= mysql_store_result(mysql)) 
     (master_row= mysql_fetch_row(master_res)))
 {
   mysql_mutex_lock(mi->data_lock);
   mi->clock_diff_with_master=
     (long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10));
   DBUG_EXECUTE_IF("dbug.mts.force_clock_diff_eq_0",
     mi->clock_diff_with_master= 0;);
   mysql_mutex_unlock(mi->data_lock);
 }

該差值僅被計算一次,在master與slave建立聯系時處理。

其他

exec_time

定義:

  • the difference from the statement's original start timestamp and the time at which it completed executing.
  • type: unsigned long
struct timeval end_time;
ulonglong micro_end_time = my_micro_time();
my_micro_time_to_timeval(micro_end_time, end_time);
exec_time = end_time.tv_sec - thd_arg->query_start_in_secs();

時間函數

(1)time_t time(time_t timer) time_t為long類型,返回的數值僅精確到秒;

(2)int gettimeofday (struct timeval *tv, struct timezone *tz) 可以獲得微秒級的當前時間;

(3)timeval結構

#include time.h>
stuct timeval {
   time_t tv_sec; /*seconds*/
   suseconds_t tv_usec; /*microseconds*/
}

總結

使用seconds_behind_master衡量主備延時只能精確到秒級別,且在某些場景下,seconds_behind_master并不能準確反映主備之間的延時。主備異常時,可以結合seconds_behind_master源碼進行具體分析。

以上就是詳解MySQL的Seconds_Behind_Master的詳細內容,更多關于MySQL Seconds_Behind_Master的資料請關注腳本之家其它相關文章!

您可能感興趣的文章:
  • MySQL 發生同步延遲時Seconds_Behind_Master還為0的原因
  • python3文件復制、延遲文件復制任務的實現方法
  • docker實現mysql主從復制的示例代碼
  • MySQL數據庫 Load Data 多種用法
  • MySQL數據庫Shell import_table數據導入
  • Mysql數據庫的主從同步配置
  • Mysql實現簡易版搜索引擎的示例代碼
  • MySQL命令無法輸入中文問題的解決方式
  • 當面試官問mysql中char與varchar的區別
  • MySQL的從庫Seconds_Behind_Master延遲總結

標簽:麗水 西寧 自貢 南充 龍巖 無錫 迪慶 徐州

巨人網絡通訊聲明:本文標題《詳解MySQL的Seconds_Behind_Master》,本文關鍵詞  詳解,MySQL,的,Seconds,Behind,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《詳解MySQL的Seconds_Behind_Master》相關的同類信息!
  • 本頁收集關于詳解MySQL的Seconds_Behind_Master的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 另类射图| 亚洲一级在线| 欧美在线观看在线观看| 国产综合一区| 717在线电影理论片| 一面膜奶一面桶| 精品成人无码亚洲AV无码浮生影院 | xxxxx69日本| 日韩三级大片| 新视觉6080高清电视剧2024| 亚洲日韩精品欧美一区二区三区| 99久久久国产精品免费蜜臀苹果| 美女污app| 女人洗澡一级特黄毛片| 色综合久久天天综合网| 96精品成人无码A片观看金桔 | 紧身牛仔裤人妻中字在线| 中文字幕与公奈奈美| bl双性啊好烫尿进来了| 国产精品成人va在线观看入口| 亚洲性受XiaO77| 操妈男孩| 紧缚奴隷护士麻绳调教| 久久逼网| 意大利理伦片激情艳女| 日本黄色电影在线| 日本熟妇BBBBBBW| 国内精品一级毛片免费看| 中文字幕无码人妻少妇免费视频| 在线观看免费播放黄污| h文大全| 公洗澡的30分钟内葵司154| 啊灬啊灬啊灬快灬高潮学生姝| 男人狂扒美女尿口动漫| 天干天干天夜夜爽啪| 甘洛县| 轻轻的顶开老师的两瓣 | porno18日本老师hd| 美女视频黄频a免费观看| 中文字幕 亚洲精品 欧美激情| 色老头网址|