This is the seventh day of my participation in the August More text Challenge. For details, see:August is more challenging

The guide knowledge

Buffer Pool Buffer Pool

MySQL, as a storage system, has a Buffer Pool just like the operating system, which avoids disk I/O for each query. Buffer Pool The Buffer Pool is used to cache table data and index data and load data on disks to the Buffer Pool, avoiding disk I/O for each access and accelerating access.

Log Buffer Log Buffer

The Log Buffer is a memory storage area that stores the data of Log files to be written to disks. The contents of the Log Buffer are periodically flushed to disks. The log buffer size is defined by the innodb_log_buffer_size variable and the default size is 16MB.

Redo log Redo log

Redolog is a type of log unique to InnoDB’s storage engine that is used to recover data and to ensure the persistence of committed transactions. The redo log records changes that have been successfully committed, and the redo log is persisted to disk. In the event of a MySQL shutdown or other problems, the redo log can be read after MySQL restarts to restore the latest data.

Undo log Rolls back logs

Undo log is used to save a version of the data before the start of a transaction (can be regarded as a place to store backup data), when the transaction is abnormal, the undo log can be used to restore the data to the state before the start of the transaction. Thus, undo log implements atomicity of transactions. Unlike the Redo log, a rollback is performed only to restore the data logically to the state before the transaction began, not physically.

Innodb implements the transaction process

Innodb implements transactions through Buffer pool, redo log, undo log and log Buffer. With the understanding of the key issues above, we can briefly describe the simple process of Innodb to implement transactions (take an update statement as an example) :

  1. After receiving the update statement, Innodb will first find out the page of the data according to the condition, and then cache the data of this page into the Buffer Pool.

  2. Execute the update statement to modify the data cached in the Buffer Pool.

  3. Create a redo log for update statements and save the redo log to the log Buffer.

  4. The undo log is generated for the update statement to roll back transactions and ensure atomicity.

  5. If the transaction is committed, persist the redo log to disk to ensure the transaction’s persistence. After persisting the redo log, MySQl uses other mechanisms to persist the modified pages from the Buffer Pool to disk.

  6. If the transaction is rolled back, the undo log rollback log is used to roll back the transaction.

This is the simple process of Innodb transaction introduction, if there are mistakes, please also comment corrections, if you think this article is helpful to you then click 😋😋

Phase to recommend

  • With you easy to clarify the Java IO system ⏳
  • Class loader, parent delegate
  • The Spring transaction
  • ABA problem, AtomicStampReference
  • These three concurrency utility classes, you must be able to!
  • MySQL transaction