In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "what is the timing for the generation of Gtid and Last_commt/sequnce_number in Mysql 5.7". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the timing of the generation of Gtid and Last_commt/sequnce_number in Mysql 5.7?"
I. Gtid generation type
Here, we first use the interpretation of the source code to give three types:
AUTOMATIC_GROUP
GTID_GROUP
ANONYMOUS_GROUP
AUTOMATIC_GROUP is usually used when Gtid is enabled in the main library, and GTID_GROUP is usually used in the case of preparing the library and using GTID_NEXT.
The source code is explained in detail as follows:
/ * Specifies that the GTID has not been generated yet; it will be generated on commit. It will depend on the GTID_MODE: if GTID_MODE=ON_PERMISSIVE, then the transaction will be assigned a new GTID. This is the default value: thd- > variables.gtid_next has this state when GTID_NEXT= "AUTOMATIC". It is important that AUTOMATIC_GROUP==0 so that the default value for thd- > variables- > gtid_next.type is AUTOMATIC_GROUP. * / AUTOMATIC_GROUP= 0, / * * Specifies that the transaction has been assigned a GTID (UUID:NUMBER). Thd- > variables.gtid_next has this state when GTID_NEXT= "UUID:NUMBER". This is the state of GTID-transactions replicated to the slave. * / GTID_GROUP, / * * Specifies that the transaction is anonymous, i.e., it does not have a GTID and will never be assigned one. Thd- > variables.gtid_next has this state when GTID_NEXT= "ANONYMOUS". This is the state of any transaction generated on a pre-GTID server, or on a server with GTID_MODE==OFF. * / timing of ANONYMOUS_ group II, Gtid and Last_commt/sequnce_number generation
Gtid is actually generated when commit is called when MYSQL_BIN_LOG::ordered_commit is executed until the flush phase generates Gtid event. After generation, the Gtid is added to the Owned_gtids of Gtid_state. In fact, this process not only generates Gtid, but also generates sequence_number and last_commit, and constructs Gtid_event to write to binlog cache and finally writes binlog cache to binlog file. The following is a snippet of the binlog_cache_data::flush function:
If (! error) if ((error= mysql_bin_log.write_gtid (thd, this, & writer)) / / generate Gtid and Last_commt/sequnce_number construct Gtid event and write to binlog cache thd- > commit_error= THD::CE_FLUSH_ERROR;if (! error) error= mysql_bin_log.write_cache (thd, this, & writer); / / write binlog cache to file
The following is a code snippet that generates Gtid and Last_commt/sequnce_number in mysql_bin_log.write_gtid:
If (thd- > variables.gtid_next.type = = AUTOMATIC_GROUP) / / if the Gtid is not specified, you need to call generate_automatic_gtid to generate {if (gtid_state- > generate_automatic_gtid (thd, thd- > get_transaction ()-> get_rpl_transaction_ctx ()-> get_sidno ()). Thd- > get_transaction ()-> get_rpl_transaction_ctx ()-> get_gno ()! = RETURN_STATUS_OK) DBUG_RETURN (true) }. / / generate sequence_number and last_committed int64 relative_sequence_number= trn_ctx- > sequence_number-clock.get_offset (); int64 relative_last_committed= trn_ctx- > last_committed last_committed-clock.get_offset ()
The call stack frame is as follows:
# 0 Gtid_state::get_automatic_gno (this=0x2ff8bb0, sidno=1) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:564#1 0x0000000001803248 in Gtid_state::generate_automatic_gtid (this=0x2ff8bb0, thd=0x7fff2c000b70, specified_sidno=0, specified_gno=0) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/rpl_gtid_state.cc:628#2 0x0000000001845703 in MYSQL_BIN_LOG::write_gtid (this=0x2dffc80, thd=0x7fff2c000b70 Cache_data=0x7fff2c021178, writer=0x7ffff0358810) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:1167#3 0x0000000001846307 in binlog_cache_data::flush (this=0x7fff2c021178, thd=0x7fff2c000b70, bytes_written=0x7ffff03588b8, wrote_xid=0x7ffff0358917) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:1454#4 0x0000000001860e57 in binlog_cache_mngr::flush (this=0x7fff2c020ff0, thd=0x7fff2c000b70, bytes_written=0x7ffff0358918 Wrote_xid=0x7ffff0358917) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:768#5 0x0000000001856d46 in MYSQL_BIN_LOG::flush_thread_caches (this=0x2dffc80, thd=0x7fff2c000b70) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:8470#6 0x0000000001856f77 in MYSQL_BIN_LOG::process_flush_stage_queue (this=0x2dffc80, total_bytes_var=0x7ffff0358a88, rotate_var=0x7ffff0358a87 Out_queue_var=0x7ffff0358a78) at / root/mysql5.7.14/percona-server-5.7.14-7/sql/binlog.cc:8532#7 0x0000000001858593 in MYSQL_BIN_LOG::ordered_commit (this=0x2dffc80, thd=0x7fff2c000b70, all=false, skip_commit=false)
Next we need to take a specific look at what logic the next Gtid depends on. We need to look at the functions Gtid_state::generate_automatic_gtid and Gtid_state::get_automatic_gno logic, which are used to generate a Gtid.
3. Gtid_state::generate_automatic_gtid logic / / If GTID_MODE = ON_PERMISSIVE or ON, generate a new GTID if (get_gtid_mode (GTID_MODE_LOCK_SID) > = GTID_MODE_ON_PERMISSIVE) / / if GTID_MODE is ON_PERMISSIVE and ON, generate GTID {Gtid automatic_gtid= {specified_sidno, specified_gno} If (automatic_gtid.sidno= = 0) / / if it is a standby library, sidno > 0. If it is the main library sidno==0, because the Gtid of the main library is generated at this time, but the standby library is specified to generate automatic_gtid.sidno= get_server_sidno () using GTID_GROUP; / / the sidno lock_sidno (automatic_gtid.sidno) of this server is returned here. / / here to control the if (automatic_gtid.gno= = 0) of multiple threads that occur into GNO / / if it is a standby library, gno > 0, if it is the main library gno= = 0, because the Gtid of the main library is generated at this time, but the standby library uses GTID_GROUP to specify the generation automatic_gtid.gno= get_automatic_gno (automatic_gtid.sidno) / / the end gno if (automatic_gtid.gno! =-1) acquire_ownership (thd, automatic_gtid) of the last specified sidno is returned here; / / this gtid and the above SIDNO:gno are added to the owned_gtids and assigned to the thread to display else ret= RETURN_STATUS_REPORTED_ERROR; unlock_sidno (automatic_gtid.sidno) after this step. / / other threads can be assigned} else / / if it is OFF_PERMISSIVE or OFF status, how to deal with it is not discussed here {/ / If GTID_MODE = OFF or OFF_PERMISSIVE, just mark this thread as / / using an anonymous transaction. Thd- > owned_gtid.sidno= THD::OWNED_SIDNO_ANONYMOUS; thd- > owned_gtid.gno= 0; acquire_anonymous_ownership (); thd- > owned_gtid.dbug_print (NULL, "set owned_gtid (anonymous) in generate_automatic_gtid");} sid_lock- > unlock (); / / release read-write lock
Next, take a look at the generation logic Gtid_state::get_automatic_gno of gno.
4. Gtid_state::generate_automatic_gtid logic while (true) {const Gtid_set::Interval * iv= ivit.get (); / / defines that the Interval pointer points to the beginning of the linked list pointer. If you do the next loop, you will get NULL rpl_gno next_interval_start= iv! = NULL? Iv- > start: MAX_GNO; / / normally will not be NULL, so next_interval_start is equal to the start of the first interval, of course, if initialization will be NULL, / / if Interval- > next = NULL, then there is no interval. While (next_candidate.gno
< next_interval_start && DBUG_EVALUATE_IF("simulate_gno_exhausted", false, true)) //这里next_candidate.gno正常不会小于next_interval_start ,如果Interval->Next = NULL or initialization / / next_interval_start will be made as MAX_GNO, then the condition holds / / DBUG_RETURN (next_candidate.gno) If this gno is returned, GTID generates {if (owned_gtids.get_owner (next_candidate) = = 0) / / if this GTID is already occupied by another thread, next_candidate.gno++; returns this gno. DBUG_RETURN (next_candidate.gno); next_candidate.gno++;} if (iv = = NULL | | DBUG_EVALUATE_IF ("simulate_gno_exhausted", true, false) {my_error (ER_GNO_EXHAUSTED, MYF (0)); DBUG_RETURN (- 1);} next_candidate.gno= iv- > end; / / iv- > end points to the largest value in this range + 1 ivit.next () } at this point, I believe you have a deeper understanding of "what is the timing for the generation of Gtid and Last_commt/sequnce_number in Mysql 5.7". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.