Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Your understanding of the Mysql log module and what is a two-stage submission

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Your understanding of Mysql log module and what is a two-stage submission, I believe that many inexperienced people are helpless about this, for this reason this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Mysql's log module is particularly important, as crash-safe and master-slave depend on our log module.

Mysql has two log modules: redolog and binlog.

Let's look at redolog first.

Redolog is redo log in Chinese. What's its use? If every time you update or insert is written to disk, then the IO cost is relatively large, so InnoDB records the record in redolog first and updates it to memory at the same time, thus completing an update or insert!

And redolog is circular write, that is, there is a fixed size, when almost full mysql will update some records to disk, and then clear the updated redolog, to make room for subsequent records.

Binlog is also an archive log, what is it used for? As the name suggests, its main role is archiving (and master-slave)! There are three modes:

statement: records every statement except the query.

row: Record the modification form of each line, that is, record which line has been changed and what has been changed! For example, if you update 100 records, it will record what has been changed in these 100 records (only available in version 5.1.5).

mixed: is a mixture of statement and row, mysql to determine which form of this statement to record! (Only available in version 5.1.8)

Binlog does not have a fixed size, each time an additional record does not overwrite the previous one.

Another point is that redolog is only available in InnoDB, which exists at the engine level, while binlog exists at the Server level. So if you are using MyISAM as a storage engine, then you have no redolog left!

Let's move on to two-paragraph submissions.

two-stage submission

That is, we first write this update to redolog, and set redolog to prepare state, then write binlog, write binlog, and then commit the transaction, and set redolog to commit state. That is to say, the relolog is split into two sections: prepare and commit!

Why would you do that?

In fact, redolog was added later, binlog was added before. First the storage engine was MyISAM, then InnoDB, then MyISAM had no transactions, no crash-safe capability. So InnoDB got a redolog. Then, to keep the two logs synchronized, there is a two-phase commit.

If you save the redolog first, then record the binlog. If redolog dies after writing it. OK, you seem to be OK, but your binlog is not recorded yet, so this record is missing! If you back up this binlog, you will lose this record forever!

What if I write binlog first and then redolog? Well, binlog is finished, your database is down, so does redolog mean that you haven't, haven't updated successfully before? But binlog has already been recorded. Anyway, it succeeded on its side, so the backup binlog is also wrong!

After reading the above, do you have a good understanding of Mysql logging module and what is the two-phase commit method? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report