当前位置:网站首页>Mvcc and bufferpool (VI)

Mvcc and bufferpool (VI)

2022-06-13 03:01:00 summer_ forty-five

Database notes

MVCC

MVCC = undo + read-view

Service for isolation

Definition :

MVCC: Multi version concurrency control mechanism , stay Read committed and repeatable At the isolation level MVCC Mechanism

characteristic :

Not through locking , To achieve isolation between transactions

Realization principle

undo Log version chain

Definition :

undo Log version means A row of data is modified by multiple transactions in turn , **MySQL The data before each operation will be retained .** And use trx_id Business id】 and roll_pointer rollback pointer 】 take undo Logs are concatenated , Form a historical version chain .

undo Log version chain

Special :

In case of deletion

  • The latest data in the version chain will be copied
  • And then trx_id Modify to delete trx_id
  • In this article In the recorded header information delete_flag The flag bit is set to true

characteristic :

  • For multiple transactions , There is only one log version chain
  • Business id And rollback pointer Are hidden fields

Consistency view read-view

Definition :

When the transaction is on , Execute any query SQL, Generates the of the current transaction Consistency view

form :

  • View array
    • from All current uncommitted transactions id form
  • Maximum transaction created id

{ [ Not submitted id1, Not submitted id2, Not submitted id3, Not submitted id4] max_id }

Be careful :

Business id stay == Execute the first DML When the sentence is , Generation ,== Not in begin/start transaction Generate .

Version chain alignment rules

 Example

readview:{ [200],300 }

The rules :

  1. Execute query statement
  2. The version chain is searched from top to bottom , If delete_flag == true, Don't return data . conversely :
    • If trx_id Fall in the The green part (trx_id < min_id), Indicates that the version is generated by a committed transaction , so
    • If trx_id Fall in the The red part (trx_id > max_id), Indicates that the version is generated by uncommitted transactions , invisible
    • If trx_id Fall in the yellow (min_id < trx_id < max_id)
      • If trx_id non-existent View array ([200]) in , Indicates that the version is generated by a committed transaction , so
      • If trx_id There is View array ([200]) in , Indicates that the version is generated by uncommitted transactions , invisible

MVCC Read submitted

Realized MVCC Mechanism

characteristic :

  • read-view The array changes dynamically with each query , Realized Sure Read committed transaction modifications Characteristics of

MVCC Repeatable

Realized MVCC Mechanism

characteristic :

  • ==read-view After the array is generated, it is fixed ,== Achieved isolation .

BufferPool

BufferPool stay Engine layer from InnoDB Realization , be based on LRU Algorithm

Why design BufferPool?

Because no BufferPool, One request requires one disk Random, speaking, reading and writing I/O Update disk data , Poor performance ;

Although design BufferPool, There will be reading and writing to log files , but The log file is Sequential reading and writing I/O, Performance is better than random read / write I/O Much higher

One sql Implementation ( Service layer )

One DMLsql Implementation ( Engine layer )

  1. From disk ibd Load cached data in the file
  2. Write the old value to undo Log files 【 Version chain 、 Transaction commit failed, rollback
  3. to update BufferPool Data in
  4. Write redo Log cache
  5. Write redo Log files 【 Transaction submitted successfully , Recover in case of system downtime BufferPool data
  6. Write bin-log Log files 【 Transaction submitted successfully , Recover disk data in case of system downtime
  7. Write commit Mark to redo Log files 【 Make sure redo and bin-log Uniformity
  8. Background thread Random take BufferPool Modified data In pages Write to disk ibd file
原网站

版权声明
本文为[summer_ forty-five]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280534510881.html