InnoDB storage engine to achieve the principle of MVCC

Simple Background

MySQL

MySQL is now the most popular choice relational database (RDB), in order to provide application functionality reliability data storage, and other matters. In recent years the Internet has become the first choice for the company. In version 5.5, the default use InnoDB storage engine.

MySQL architecture

The top level is the access layer, to achieve access for different languages, access layer is responsible for checking privileges, the thread pool management, thread management. Next is the MySQL service layer, there are SQL parser, SQL optimization, data buffer cache. The next is the storage engine. Finally, the file system layer.

InnoDB and MVCC

Properties in MySQL InnoDB storage engine has, the default level of Repeatable Read, row-level locking to achieve MVCC, Consistent nonlocking read (read default unlocked, consistent non-locking read), Insert Buffer, Adaptive Hash Index , Double Write , Cluster Index.
The above cited so many examples of how InnoDB has many features, and soon.
InnoDB is implemented in multiple versions of data through the Undo Log, and concurrency control is achieved through the lock.
Undo Log In addition to achieving the MVCC, but also provides a rollback function.

Redo log,Undo log, Bin log

MySQL InnoDB have a lot of logs, in addition to error logs, query logs and many log related to persisted.
log bin : MySQL log generated by the service layer, generally used for data recovery, database replication. Such as the common master-slave mode is achieved by binlog, but also to achieve additional binlog mysql replication to other data sources, such as: ElasticSearch.
log redo : record the data to modify, MySQL uses a lot into the cache at the physical level, when the inconsistent data in the cache and disk data, which is data in memory called dirty pages (dirty page). To ensure the security of data, transactions continue to produce redo log, when the transaction will be submitted to a flush operation, save to disk, redolog is written order, much larger than the random read and write performance. When MySQL Recovery will load the data in the redo log, redo log if there is a transaction is committed, then submit it to modify the data. This ensures consistency, atomicity, durability of transactions.
undo log : In addition to redo log records, the will undo log record, reverse undo log data recording operation, such as modifying the delete operation, the recording data is a value before the modification, for rollback and the version backtracking. You can be found in a particular version of a value according to undo log, thus achieving MVCC.
redo log and bin log to be consistent in order to achieve consistency, MySQL uses a two-phase commit protocol.

MVCC to achieve

undo log is divided into two kinds Insert and Update, Delete operation is also seen as a special Update, mark on the record is deleted.
For the Insert operation, when inserted into the generated Insert undo log, the transaction is committed, you can delete the undo log, because there are no other matters that need to undo log.
Update operation is performed when, generates a new undo log, the current record db_roll_ptr point to the new undo log.
The first snapshot after the start of the transaction read when the currently active transaction id will be recorded under RR level, recorded in the read view.

Released six original articles · won praise 0 · Views 29

Guess you like

Origin blog.csdn.net/qq_26375325/article/details/105059715