In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what are the MySQL source code series problems". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First, how on earth is the event of trigger played back, and why is there no primary key conflict?
The last time I shared, I introduced the order of trigger trx events in binlog.
Gtid event
Query event
Table_map_event (table1)
Table_map_event (table2)
Rows_event (table1)
Rows_event (table2)
Xid_event
In fact, when slave plays back, he does not create a connection in the server layer and execute the statement. Instead, you directly call the do_apply_event in each event. Table map event, for example, saves the meta-information of the table.
To write_rows_event, slave calls the function as follows
|-- do_exec_row
|-- write_row
|-- handler::ha_write_row
|-- write_row
You can see that the innodb::write_row at the engine layer is called to insert the data.
To sum up, we can see that when trigger trx plays back in slave, it actually bypasses trigger and hands it over directly to the storage engine to operate the data. So there won't be the problem of primary key conflict that we talked about at the beginning.
2. The actual generation sequence of trx
We say that trx is made up of event. For example, the insert statement contains events that is gtid_log_event, query_log_event
Table_map_log_event, write_rows_log_event, xid_log_event
We say that these events are generated when the last trx is submitted, but they are not. Their actual generation order is as follows:
Gtid event, Xid event is generated in the ordered_commit function. This involves consistent writes of binlog and redo log.
Table map event is generated in the binlog_write_table_map function, which receives parameters such as whether the has trans flag is a transaction and whether need_binlog_rows_query wants to generate rows_query_log_event
In the function binlog_write_table_nap function, binlog_start_trans_and_stmt is called to generate query_log_event in that function
Finally, call write event to cache the generated event in the binlog_chache of the thd.
Generation order: table_map_log_event, query_log_event, [rows_query_log_event]
Cache order: query_log_event, [rows_query_log_event], table_map_log_event
Then generate xid event, and finally generate gtid event in the ordered_commit function
Statement format:
No table_map_event and row_event generation order
Generation order: query_log_event (save statement), query_log_event (begin), xid event, gtid event
Generate table_map_event in binlog_write_table_map, use another constructor of table_map_log_event to get table information from table object and construct table_map_log_event
Then call binlog_start_trans_and_stmt to generate query_log_event (regular trx and xa cases designed in query_log) and then call cache_data 's write_event to write the event.
This is the end of the content of "what are the MySQL source code series problems"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.