深入理解MySQL 5.7 GTID系列(五) gtid_executed&gtid_purged什么时候更新

摘要: 本节将集中讨论下面三种GTID更新的时机,这部分相当重要,后面的故障案列会和这节有关。下面先来看一下他们的定义: mysql.gtid_executed表:GTID持久化的介质,MySQL启动阶段会读取这个表来获取gtid_executed变量的值。

本节将集中讨论下面三种GTID更新的时机,这部分相当重要,后面的故障案列会和这节有关。下面先来看一下他们的定义:

mysql.gtid_executed表:GTID持久化的介质,MySQL启动阶段会读取这个表来获取gtid_executed变量的值。

gtid_executed变量(show global variables):MySQL数据库已经执行了哪些GTID事务,处于内存中。show slave status中的executed_gtid_set也取自这里。

gtid_purged变量(show global variables):由于BINLOG文件的删除(如purge binary logfiles或者超过expire_logs_days设置)已经丢失的GTID事务,同时在搭建备库的我们使用set global gtid_purged变量来提示MySQL哪些GTID事务我已经执行过了。

这也是我们DBA通常能够观察到的几种GTID,有了前文的描述我们知道其中mysql.gtid_executed表是一种GTID持久化的介质,而gtid_executed变量和gtid_purged变量则对应了,gtid_state中的executed_gtidslost_gtids内存数据。他们分别表示MySQL数据库执行了哪些GTID事务,有哪些GTID事务由于BINLOG文件的删除已经丢失了。

其次我们先来达成一个共识gtid_executed变量一定是实时更新的不管主库和从库。我们的讨论分为主库,从库和通用从源码的角度进行详细讨论。并且约定都是打开GTID的情况下。最后给出最终总结。

一、主库修改时机

(1) BINLOG关闭

不生成gtid,mysql.gtid_executed/gtid_executed变量/gtid_purged变量均不更新。

(2)BINLOG打开

mysql.gtid_executed表修改时机

BINLOG发生切换(rotate)的时候保存直到上一个BINLOG文件执行过的全部GTID,它不是实时更新的。

栈帧如下:

#0Gtid_table_persistor::save(this=0x2f9f9c0,gtid_set=0x7ffff03595a0)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_persist.cc:425#10x0000000001803dbein Gtid_state::save(this=0x2ff8bb0,gtid_set=0x7ffff03595a0)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:796#20x0000000001803f62in Gtid_state::save_gtids_of_last_binlog_into_table(this=0x2ff8bb0,on_rotation=true)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:835#30x000000000185266din MYSQL_BIN_LOG::new_file_impl(this=0x2dffc80,need_lock_log=false,extra_description_event=0x0)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:6751#40x00000000018520a7in MYSQL_BIN_LOG::new_file_without_locking(this=0x2dffc80,extra_description_event=0x0)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:6636#50x0000000001853e67in MYSQL_BIN_LOG::rotate(this=0x2dffc80,force_rotate=true,check_purge=0x7ffff0359c4b)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:7292

其主要逻辑在gtid_state::save_gtids_of_last_binlog_into_table 中我们在随后的部分讨论这个函数逻辑。

gtid_executed变量修改时机

如前文所述ordered_commit flush阶段生成GTID,在COMMIT阶段才计入gtid_executed变量,它是实时更新的。

栈帧如下:

#0Gtid_set::_add_gtid(this=0x2ff8d38,sidno=1,gno=16)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid.h:1135#10x0000000001804576in Gtid_set::_add_gtid(this=0x2ff8d38,gtid=...)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid.h:1166#20x00000000018024bain Gtid_state::update_gtids_impl(this=0x2ff8bb0,thd=0x7fff2c000b70,is_commit=true)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:304#30x00000000018020dfin Gtid_state::update_on_commit(this=0x2ff8bb0,thd=0x7fff2c000b70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:148#40x00000000018573d4in MYSQL_BIN_LOG::process_commit_stage_queue(this=0x2dffc80,thd=0x7fff2c000b70,first=0x7fff2c000b70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:8646#50x0000000001858b51in MYSQL_BIN_LOG::ordered_commit(this=0x2dffc80,thd=0x7fff2c000b70,all=false,skip_commit=false)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:9304

其主要逻辑在gtid_state::update_gtids_impl中我们在随后的部分讨论这个函数逻辑。

gtid_purged变量修改时机

MySQL触发的清理BINLOG的情况下,比如purge binary logs to或者超过参数expire_logs_days设置的天数后自动删除,需要将丢失的GTID计入这个变量中。

栈帧如下:

#0MYSQL_BIN_LOG::init_gtid_sets(this=0x2e00280,all_gtids=0x0,lost_gtids=0x2fcaee8,verify_checksum=false,need_lock=false,trx_parser=0x0,gtid_partial_trx=0x0,is_server_starting=false)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:4333#10x0000000001850b8ein MYSQL_BIN_LOG::purge_logs(this=0x2e00280,to_log=0x7fff57a74ad0"/root/mysql5.7.14/percona-server-5.7.14-7/mysql-test/var/mysqld.1/test.000202",included=false,need_lock_index=true,need_update_threads=true,decrease_log_space=0x0,auto_purge=false)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:6036#20x0000000001848ecfin purge_master_logs(thd=0x7fff49200dc0,to_log=0x7fff492051a8"test.000202")at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:2815

其主要逻辑在MySQL_BIN_LOG::PURGE_LOGS中,我们随后查看其代码片段,同时MySQL_BIN_LOG::INIT_GTID_SETS函数是一个及其重要的函数,主要用在:

MySQL启动时候初始化整个GTID_STATE中的各种GTID_SET

MySQL删除BINLOG(如purge binary logfiles或者超过expire_logs_days设置)后需要确认gtid_purged变量(及gtid_state.lost_gtids)的值的时候。

随后我会单独一节来讲解MySQL GTID模块的初始化还会讲解这个函数。

二、主库修改时机源码函数分析

这里就对上面提到的主要逻辑函数进行分析

gtid_state::save_gtids_of_last_binlog_into_table函数逻辑

logged_gtids_last_binlog.add_interval_memory(PREALLOCATED_INTERVAL_COUNT,iv);//这里构建一个logged_gtids_last_binlog集合来保存切换后需要写入表和previous_gtids_logged的Gtid/*

logged_gtids_last_binlog= executed_gtids - previous_gtids_logged -

gtids_only_in_table

*/global_sid_lock->wrlock();//ret=(logged_gtids_last_binlog.add_gtid_set(&executed_gtids)!=//将当前执行过的Gtid全部加入logged_gtids_last_binlog 列如:executed_gtids start=1, end=27 RETURN_STATUS_OK);if(!ret){logged_gtids_last_binlog.remove_gtid_set(&previous_gtids_logged);//获得上一个binlog文件包含的全部Gtid,并且做一个差集 列如:previous_gtids_logged 为start=1, end=25//做完差集后logged_gtids_last_binlog为start=26, end=27logged_gtids_last_binlog.remove_gtid_set(>ids_only_in_table);//此处主库一定为空,除非异常情况if(!logged_gtids_last_binlog.is_empty()){/* Prepare previous_gtids_logged for next binlog on binlog rotation */if(on_rotation)ret=previous_gtids_logged.add_gtid_set(&logged_gtids_last_binlog);//将这个start=26, end=27的Gtid集合加入到previous_gtids_logged中,这样previous_gtids_logged也完整了global_sid_lock->unlock();/* Save set of GTIDs of the last binlog into gtid_executed table */if(!ret)ret=save(&logged_gtids_last_binlog);//将这个start=26, end=27的Gtid集合写入到表mysql.gtid_executed表中}

gtid_state::update_gtids_impl函数代码片段

while(g.sidno!=0){if(g.sidno!=prev_sidno)sid_locks.lock(g.sidno);owned_gtids.remove_gtid(g);//从owned_gtid中去掉git.next();g=git.get();if(is_commit)executed_gtids._add_gtid(g);//将这个Gtid加入到executed_gtids}

mysql_binlog::purge_logs函数代码片段

if(!is_relay_log){global_sid_lock->wrlock();error=init_gtid_sets(NULL,const_cast(gtid_state->get_lost_gtids()),opt_master_verify_checksum,false/*false=don't need lock*/,NULL/*trx_parser*/,NULL/*gtid_partial_trx*/);//这里我看到将gtid_state->lost_gtids直接传入给了init_gtid_sets//init_gtid_sets会做正向查找获得gtid_state->lost_gtids这个函数稍后//详细讨论global_sid_lock->unlock();if(error)gotoerr;}

三、从库修改时机

(1) BINLOG关闭或者BINLOG开启参数log_slave_updates关闭的情况

将他们放到一起因为他们的表现完全一样。

mysql.gtid_executed表修改时机

前面已经说过这种情况下从库没有办法通过BINLOG来持久化sql_thread执行过的GTID事务,只能通过实时更新mysql.gtid_executed表来保存,所以必须要要实时将GTID持久化到mysql.gtid_executed表中。实际上实时保存mysql.gtid_executed发生在commitpreper阶段之前,也就是最开始。但是对于主库来讲由于还没有生成GTID,那么则不能写入

栈帧如下:

#0commit_owned_gtids(thd=0x7fffec000970,all=false,need_clear_owned_gtid_ptr=0x7ffff08bf2cb)at/mysql/mysql-5.7.17/sql/handler.cc:1571#10x0000000000f465c3in ha_commit_trans(thd=0x7fffec000970,all=false,ignore_global_read_lock=false)at/mysql/mysql-5.7.17/sql/handler.cc:1669#20x0000000001686f0din trans_commit_stmt(thd=0x7fffec000970)at/mysql/mysql-5.7.17/sql/transaction.cc:458#30x000000000180fb16in rows_event_stmt_cleanup(rli=0x3937d30,thd=0x7fffec000970)at/mysql/mysql-5.7.17/sql/log_event.cc:11124#40x000000000180f801in Rows_log_event::do_apply_event(this=0x7fffec018020,rli=0x3937d30)at/mysql/mysql-5.7.17/sql/log_event.cc:11026#50x00000000017f7b7bin Log_event::apply_event(this=0x7fffec018020,rli=0x3937d30)at/mysql/mysql-5.7.17/sql/log_event.cc:3324#60x00000000018690a6in apply_event_and_update_pos(ptr_ev=0x7ffff08bf830,thd=0x7fffec000970,rli=0x3937d30)at/mysql/mysql-5.7.17/sql/rpl_slave.cc:4702#70x000000000186a75ein exec_relay_log_event(thd=0x7fffec000970,rli=0x3937d30)at/mysql/mysql-5.7.17/sql/rpl_slave.cc:5212#80x0000000001870d07in handle_slave_sql(arg=0x38cc1c0)at/mysql/mysql-5.7.17/sql/rpl_slave.cc:7320

其主要逻辑包含在commit_owned_gtids中。

GTID_EXECUTED变量修改时机

这个和主库一样实时更新,不做讨论。

gtid_purged变量修改时机

由于压根没有binlog来记录已经执行过的Gtid事务,所以gtid_purged变量实时更新

其更改处于整个ha_commit_trans的结尾如下:

if(need_clear_owned_gtid){thd->server_status&=~SERVER_STATUS_IN_TRANS;/*

Release the owned GTID when binlog is disabled, or binlog is

enabled and log_slave_updates is disabled with slave SQL thread

or slave worker thread.

*/if(error)gtid_state->update_on_rollback(thd);elsegtid_state->update_on_commit(thd);}

栈帧如下(这个栈帧取值5.7.17):

#0Gtid_set::_add_gtid(this=0x2f9ef40,sidno=2,gno=33083)at/mysql/mysql-5.7.17/sql/rpl_gtid.h:1136#10x00000000017e9990in Gtid_set::_add_gtid(this=0x2f9ef40,gtid=...)at/mysql/mysql-5.7.17/sql/rpl_gtid.h:1167#20x00000000017e906ein Gtid_state::update_gtids_impl_own_gtid(this=0x2f9eca0,thd=0x7fffec000970,is_commit=true)at/mysql/mysql-5.7.17/sql/rpl_gtid_state.cc:939#30x00000000017e6f3fin Gtid_state::update_gtids_impl(this=0x2f9eca0,thd=0x7fffec000970,is_commit=true)at/mysql/mysql-5.7.17/sql/rpl_gtid_state.cc:240#40x00000000017e6d25in Gtid_state::update_on_commit(this=0x2f9eca0,thd=0x7fffec000970)at/mysql/mysql-5.7.17/sql/rpl_gtid_state.cc:201#50x0000000000f46d46in ha_commit_trans(thd=0x7fffec000970,all=true,ignore_global_read_lock=false)at/mysql/mysql-5.7.17/sql/handler.cc:1846#60x000000000168676bin trans_commit(thd=0x7fffec000970)at/mysql/mysql-5.7.17/sql/transaction.cc:239#70x0000000001802aaain Xid_log_event::do_commit(this=0x7fffec013c60,thd_arg=0x7fffec000970)at/mysql/mysql-5.7.17/sql/log_event.cc:6824#80x00000000018034d7in Xid_apply_log_event::do_apply_event(this=0x7fffec013ca8,rli=0x3937d30)at/mysql/mysql-5.7.17/sql/log_event.cc:7049

当然其处理逻辑在gtid_state::update_gtids_impl_own_gtid中。

(2)BINLOG开启同时参数log_slave_updates开启的情况

这种情况sql_thread执行过的GTID事务可以通过BINLOG

进行维护,所以mysql.gtid_executed表和gtid_purged变量不需要实时更新。

mysql.gtid_executed表修改时机

和主库一致。及在进行日志切换的时候进行更新,不做讨论

gtid_executed变量修改时机

和主库一样实时更新,不做讨论

gtid_purged变量修改时机

和主库一致,BINLOG删除时更新,不做讨论

四、从库修改时机源码函数分析

commit_owned_gtids函数逻辑:

//如果 binlog 没有开启包括(log_bin=0 和 sql_log_bin =0 )或者 开启了binlog 但是slave线程并且slave update 没有开启,都会记录gtid到表//但是这里要注意一点在主库上如果binlog不开启那么thd->owned_gtid.sidno ==0 因为这个时候Gtid都没有生成,生成阶段为order_commit的commit阶段if((!opt_bin_log||(thd->slave_thread&&!opt_log_slave_updates))&&(all||!thd->in_multi_stmt_transaction_mode())&&//all 代表是否是显示begin 事务in_multi_stmt_transaction_mode则相反!thd->is_operating_gtid_table_implicitly&&//是否是GTID_NEXT方式 flase!thd->is_operating_substatement_implicitly)//是否是子语句 flase{/*

If the binary log is disabled for this thread (either by

log_bin=0 or sql_log_bin=0 or by log_slave_updates=0 for a

slave thread), then the statement will not be written to

the binary log. In this case, we should save its GTID into

mysql.gtid_executed table and @@GLOBAL.GTID_EXECUTED as it

did when binlog is enabled.

*/if(thd->owned_gtid.sidno>0){error=gtid_state->save(thd);//就是这里进行了mysql.gtid_executed表的实时更新*need_clear_owned_gtid_ptr=true;}elseif(thd->owned_gtid.sidno==THD::OWNED_SIDNO_ANONYMOUS)*need_clear_owned_gtid_ptr=true;}

gtid_state::update_gtids_impl_own_gtid 函数逻辑片段,这个函数是5.7.17的,5.7.14没有逻辑放到了gtid_state::update_gtids_impl

if(is_commit){DBUG_EXECUTE_IF("rpl_gtid_update_on_commit_simulate_out_of_memory",DBUG_SET("+d,rpl_gtid_get_free_interval_simulate_out_of_memory"););/*

Any session adds transaction owned GTID into global executed_gtids.

If binlog is disabled, we report @@GLOBAL.GTID_PURGED from

executed_gtids, since @@GLOBAL.GTID_PURGED and @@GLOBAL.GTID_EXECUTED

are always same, so we did not save gtid into lost_gtids for every

transaction for improving performance.

If binlog is enabled and log_slave_updates is disabled, slave

SQL thread or slave worker thread adds transaction owned GTID

into global executed_gtids, lost_gtids and gtids_only_in_table.

*/executed_gtids._add_gtid(thd->owned_gtid);//加入executed_gtids集合thd->rpl_thd_ctx.session_gtids_ctx().notify_after_gtid_executed_update(thd);if(thd->slave_thread&&opt_bin_log&&!opt_log_slave_updates)//如果是slave线程同时binlog开启了并且log_slave_updates关闭了//如果binlog关闭则使用 executed_gtids这样提高性能前面的注释说了{lost_gtids._add_gtid(thd->owned_gtid);//写入lost_gtids也就是更新参数gtid_purged变量gtids_only_in_table._add_gtid(thd->owned_gtid);}}

五、通用更改时机

1、mysql.gtid_executed表修改时机

在reset master的时候清空本表

栈帧如下:

#0Gtid_table_persistor::delete_all(this=0x2f9f9c0,table=0x7fff2c0116a0)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_persist.cc:795#10x000000000180a4efin Gtid_table_persistor::reset(this=0x2f9f9c0,thd=0x7fff2c000b70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_persist.cc:689#20x0000000001801f2ein Gtid_state::clear(this=0x2ff8bb0,thd=0x7fff2c000b70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:36#30x000000000184fee6in MYSQL_BIN_LOG::reset_logs(this=0x2dffe80,thd=0x7fff2c000b70,delete_only=false)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:5586#40x0000000001872308in reset_master(thd=0x7fff2c000b70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_master.cc:587

其主要逻辑在gtid_state::clear中。

set global gitd_purged的时候,设置本表

栈帧如下:

#0Gtid_table_persistor::save(this=0x2f9f9c0,gtid_set=0x7ffff0359a70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_persist.cc:425#10x000000000180400ain Gtid_state::save(this=0x2ff8bb0,gtid_set=0x7ffff0359a70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:796#20x0000000001803c25in Gtid_state::add_lost_gtids(this=0x2ff8bb0,gtid_set=0x7ffff0359a70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:737#30x00000000016778f3in Sys_var_gtid_purged::global_update(this=0x2de9fe0,thd=0x7fff2c000b70,var=0x7fff2c006630)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/sys_vars.cc:5888#40x00000000014d5cd1in sys_var::update(this=0x2de9fe0,thd=0x7fff2c000b70,var=0x7fff2c006630)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/set_var.cc:184#50x00000000014d74eein set_var::update(this=0x7fff2c006630,thd=0x7fff2c000b70)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/set_var.cc:812#60x00000000014d6d1ain sql_set_variables(thd=0x7fff2c000b70,var_list=0x7fff2c003528)at/root/mysql5.7.14/percona-server-5.7.14-7/sql/set_var.cc:669

其主要逻辑在gtid_state::add_lost_gtids中。

2、gtid_executed变量修改时机

在reset master的时候清空本变量

栈帧同上

在set global gitd_purged的时候,设置本变量

栈帧同上

在MySQL启动的时候初始化设置GTID_EXECUTED变量,这个将在后面章节详细描述描述步骤。

3、gtid_purged变量修改时机

在reset master的时候清空本变量

栈帧同上

在set global gitd_purged的时候,设置本变量

栈帧同上

在mysql启动的时候初始化设置GTID_EXECUTED变量,这个将在后面章节详细描述描述步骤。

六、通用更改时机源码函数分析

gtid_state::clear函数逻辑

intGtid_state::clear(THD*thd){....// the wrlock implies that no other thread can hold any of the mutexessid_lock->assert_some_wrlock();lost_gtids.clear();//此处清空gtid_purged变量executed_gtids.clear();//此处清空gtid_executed变量gtids_only_in_table.clear();//清空only in table Gtid setprevious_gtids_logged.clear();//清空 previous gtids logged Gtid set/* Reset gtid_executed table. */if((ret=gtid_table_persistor->reset(thd))==1)//此处清空mysql.gtid_executed表{/*

Gtid table is not ready to be used, so failed to

open it. Ignore the error.

*/thd->clear_error();ret=0;}next_free_gno=1;DBUG_RETURN(ret);}

gtid_state::add_lost_gtids函数逻辑

enum_return_status Gtid_state::add_lost_gtids(constGtid_set*gtid_set){......if(save(gtid_set))//此处将set gtid_purge的值加入到mysql.gtid_executed表中RETURN_REPORTED_ERROR;PROPAGATE_REPORTED_ERROR(gtids_only_in_table.add_gtid_set(gtid_set));PROPAGATE_REPORTED_ERROR(lost_gtids.add_gtid_set(gtid_set));//此处将set gtid_purge的值加入到gtid_purge变量中PROPAGATE_REPORTED_ERROR(executed_gtids.add_gtid_set(gtid_set));//此处将set gtid_purge的值加入到gtid_executed变量中lock_sidnos(gtid_set);broadcast_sidnos(gtid_set);unlock_sidnos(gtid_set);DBUG_RETURN(RETURN_STATUS_OK);}

七、本节小结

为了方便这里将上面的重点文字描述进行提取,去掉源码部分,方便大家阅读

1、主库修改时机

(1)BINLOG关闭

不生成gtid,mysql.gtid_executed/gtid_executed变量/gtid_purged变量均不更新。

(2)BINLOG打开

mysql.gtid_executed表修改时机

BINLOG发生切换(rotate)的时候保存直到上一个BINLOG文件执行过的全部GTID,它不是实时更新的。

gtid_executed变量修改时机

如前文所述ordered_commit flush阶段生成GTID,在COMMIT阶段才计入gtid_executed变量,它是实时更新的。

gtid_purged变量修改时机

MySQL触发的清理BINLOG的情况下,比如purge binary logs to或者超过参数expire_logs_days设置的天数后自动删除,需要将丢失的GTID计入这个变量中。

2、从库修改时机

(1) BINLOG关闭或者BINLOG开启参数log_slave_updates关闭的情况

mysql.gtid_executed表修改时机

实时将GTID持久化到mysql.gtid_executed表中。

gtid_executed量修改时机

它是实时更新的。

gtid_purged变量修改时机

由于压根没有BINLOG来记录已经执行过的GTID事务,所以gtid_purged变量实时更新

(2)BINLOG开启同时参数log_slave_updates开启的情况

mysql.gtid_executed表修改时机

进行日志切换的时候进行更新,同主库。

gtid_executed变量修改时机

实时更新,同主库。

gtid_purged变量修改时机

BINLOG删除时更新,同主库。

3、通用修改时机

mysql.gtid_executed表修改时机

(1)在reset master的时候清空本表。

(2)在set global gitd_purged的时候,设置本表。

gtid_executed变量修改时机

(1)在reset master的时候清空本变量。

(2)在set global gitd_purged的时候,设置本变量。

(3)在MySQL启动的时候初始化设置gtid_executed变量。

gtid_purged变量修改时机

(1)在reset master的时候清空本变量。

(2)在set global gitd_purged的时候,设置本变量。

(3)在MySQL启动的时候初始化设置gtid_purged变量。

此外reset master命令除了完成上述功能还会清理BINLOG,重新初始化BINLOG从序号1开始。而set global gitd_purged参数一般只有在reset master后使用,用于搭建GTID从库或者处理GTID从库故障。

学习完本节至少能学习到:

1、主库和从库对于mysql.gtid_executed表,gtid_executed变量,gitd_purged变量

在各种情况下的修改时机

2、reset master做了什么关于GTID相关的工作

3、set global gitd_purged做了什么关于GTID相关的工作

原文发布时间为:2018-01-28

本文作者:高鹏(重庆八怪)

本文来自云栖社区合作伙伴“老叶茶馆”,了解相关信息可以关注“老叶茶馆”微信公众号

如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:yqgroup@service.aliyun.com 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。

原文链接

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

推荐阅读更多精彩内容