当前位置:网站首页>Transaction recovery and processing of "inside database system"
Transaction recovery and processing of "inside database system"
2022-07-20 07:23:00 【_ Su Mu】
《 Inside the database system 》
Chapter five
The fifth chapter is an important chapter in this book , There are three sections . It is some advanced component problems behind the storage structure , Including buffer management 、 Lock management and recovery . In order to understand database transactions more conveniently .
Buffer management
Page caching
For a two-tier storage system , The access speed of disk is slow , So in order to reduce access to disk , Pages are cached in memory .
When the data on the disk has not been modified , You can reuse cached pages in memory , Called virtual disk . But when the memory copy is full , Will access the disk , The above is called page caching .
When the storage engine requests pages , First, check whether there is a cached version in memory , If so, visit directly , If not, go to the disk , Convert logical address and page number to physical address , Load into memory , Then give the cached version of the storage engine .
Dirty page : The dirty flag bit on the page indicates that the content is out of sync with the disk , You must brush to disk to ensure persistence .
Recycling
It is better to keep the page cache full .
Persistence maintenance : You need to pre write the log (WAL) And page caching . Because if the database crashes, the unwritten data will be lost , So set the log , The log records are discarded only after the brush is completed .
Prewrite log 、 Page caching ( Cache page swiping completed )-> Log records are discarded -> Dirty page swap out cache
Lock page
according to b The data structure of the tree , It can be understood that he is “ Short and fat ” The shape of the , It can be considered that high-level nodes will hit in most reads . At the same time, it is often hit in the split and merge operation . So for these pages with high frequency, you can “ Fix ”.
Page replacement strategy : Same as os Replacement strategy in .
FIFO: Attention will produce belady abnormal .
LRU: Not used for the longest time , If you maintain one queue at a time , When changing a page , It is expensive to re reference and link nodes .
CLOCK/CLOCK-sweep:( Clock page replacement algorithm )
LFU: Minimum frequency algorithm .tinyLFU Is a frequency based page replacement strategy , It's not an element that you choose to swap out , The selected elements to be retained form a protection queue , Elements with relatively high access frequency are kept in the queue for a long time . A frequency histogram is used to maintain a compact cache access history .
There are three queues in this strategy :
Enter the queue ---- Investigation queue ---- Protection queue
recovery
Through the pre write log, which is an additional auxiliary disk data structure , Ensure that the database system has persistence semantics .
WAL Save separate operation records , And save the record of transaction completion .
In order to ensure the normal operation of the system during rollback or recovery , The compensation log record will be recorded and stored in the log when the operation is undone .
checkpoint
Checkpoints are used to mark that previous logging is no longer needed , Reduced workload . The process of forcing all dirty pages to be written to disk is called synchronization checkpoint .
Because it's unrealistic to brush it all , So most databases choose fuzzy checkpoints .
Log header with last——checkpoint The pointer records the last successful checkpoint information . Fuzzy checkpoints start from begin-checkpoint Record start to end-checkpoint end .
steal and force Strategy ( I don't quite understand , Look back )
To determine when to brush memory changes to disk , Defined strategies .
steal The policy is to allow the page modified by the transaction to be written before the transaction is committed .
no-sreal The policy does not allow uncommitted transaction content to be written to disk .
force The policy requires that all the pages modified by the transaction be written to disk before the transaction is committed .
no-force Policy even if the page modified by the transaction has not been written to disk , You can also submit .
Now? DBMS What is commonly used is steal/no-force Strategy , Therefore, it is generally necessary to record redo log and undo log. This allows faster runtime performance , The price is in database recovery (recovery) You need to do a lot of things when you're in trouble , It increases the time of system restart .
The recovery process of restarting after database crash is divided into three stages :
analysis phase : Identify dirty pages in the page cache and transactions that occur when they crash .
Redo phase : Replay the history until the crash point .
The cancellation phase : Rollback all outstanding transactions , Restore to consistent state . Prevent another crash , The undo transaction operation will also be recorded in the log .
concurrency control
This chapter studies the local concurrency control technology .
Optimistic concurrency control :
Allow multiple transactions to read and write concurrently , Transactions do not block each other , Instead, keep records , And check whether these history records conflict before submitting , If there is a conflict, terminate a conflict transaction .
Multi version concurrency control mvcc:
Allow multiple timestamp versions of a piece of data at the same time , In this way, transactions read a consistent view of a certain time in the past . Subsequent operations are carried out for one version of data ( The translation here is very confusing ).
Pessimistic Concurrency :
The locked version will require the maintenance of locks on database records . The implementation without locking is scheduled according to incomplete transactions , Maintain a list of read and write operations .
abnormal
Read and write exceptions will occur during concurrent transaction execution : Dirty reading 、 It can't be read repeatedly 、 Fantasy reading ; Dirty write 、 Lost update 、 Write slant .
Dirty reading : Uncommitted data read , For example, rollback after updating the previous transaction , Later transactions read uncommitted data .
Don't reread : The same transaction is executed twice , The data read is inconsistent ,t1 Read a line ,t2 Revise and submit ,t1 Read the data again and change .
Fantasy reading : It means that the row sets obtained by two range reads are different .Lost update : Two transactions update a value at the same time , Jidu commit, Then the submitted later overwrites the submitted earlier .
Dirty write : It is modified in case of dirty reading .
Write slant : A single transaction satisfies some constraints , Combining transactions violates .
Several methods to deal with database deadlock :
1. Introduce a timeout mechanism and terminate long-running transactions .
2. conservative 2PL( Two stage lock ).
Databases often use wait charts (waits-for graph Realization ) To detect or avoid deadlocks :
边栏推荐
- 数据库系统概论总结复习
- 在通达信开户安全么
- 2022-07-18: what is the output of the following go language code? A:Groutine; B:Main; C:Goroutine; D:GoroutineMain。 package main import ( “f
- 企业数字化转型:三个关键点!
- fiddler5+雷电模拟器4.0对app抓包设置
- Low flow conversion of independent stations? Low customer repurchase rate? Look here
- 超时放弃订单怎么实现(几种方案)
- 对TableView的优化
- 三、品达通用权限系统__pd-tools-swagger2
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 1, sign in question Gadi
猜你喜欢
Silicon Valley class lesson 9 - integration gateway and order and marketing module
Microservice 2-nacos registry
Sql语句中IN和exists的区别及应用
[wechat applet] curriculum case -- 0 basic version
Enterprise digital transformation: three key points!
硅谷课堂-公众号云点播 硅谷课堂微服务项目实战笔记
【DA9739】基于射频DAC9739的任意波形产生的性能研究
STL之string学习
SoC第一个工程hello_world
Electron渲染进程向主进程发送消息
随机推荐
Low flow conversion of independent stations? Low customer repurchase rate? Look here
《数据库系统内 幕》存储引擎
Mysql_Note1
做好这四个阶段,实施MES系统将更简单
三、品达通用权限系统__pd-tools-swagger2
go操作excel库excelize使用
实验1:电影分析
2022-07-18: what is the output of the following go language code? A:Groutine; B:Main; C:Goroutine; D:GoroutineMain。 package main import ( “f
Why is there an unsafe prompt on the website when SSL certificate is installed?
小样本学习-入门
Numpy learning
对TableView的优化
企业数字化转型:三个关键点!
2022 Guangdong provincial network security competition code penetration test WP
MIT-6874-Deep Learning in the Life Sciences Week 8
初等变换 矩阵的秩
股票开户免费办理佣金最低的券商,网上开户安全吗
Experiment 1: film analysis
How to carry out engineering implementation of DDD Domain Driven Design
Dharma hall proposes a new time series prediction model | Lingyun Express