A transaction (transcation)
What is a transaction: the basic unit of execution of database, the database is a logical unit of work
Several questions affairs:
- Concurrent operation
- Data inconsistency
ACID properties of the transaction
Atomicity Atomicity or did not do, or do it all himself
Consistency Consistency isolation transaction execution time to ensure consistency
Isolation Isolation concurrent execution of multiple transactions pairwise influence
After persistent Durability transaction is complete, the impact on the system is permanent
State of affairs
Active active
Partially commited partial commit
Failed failed state
Aborted give up state
Committed submission status
Terminated end state
Data recovery--
- The establishment of redundant data
method:
- Data dump, the log file level
Common Recovery Technology
- Transaction failure: undo
- System failure: undo + redo
- Media failure: Backup and restore back to a consistent state + redo
Improve the recovery efficiency of technology
- Checkpoint technology
- Mirroring
Second, concurrency control
1 three kinds of concurrency conflicts
- When both transactions to the database changes: Write Conflict
- Write conflict: two consecutive read operations because of other transactions in which the transaction and to show inconsistency
- Write Read conflict: a transaction which finished rolled back, then read another transaction before it is rolled back ...
When a series of transactions executed concurrently isolation can easily be destroyed
Concurrency control is a series of mechanisms to implement the order of transactions can be controlled, so that one concurrent transaction execution result is equivalent to walking through the implementation of the results of
1 lock mode. Divided into exclusive locks and shared locks. Exclusive lock, only to get an exclusive lock on the X's affairs before they can operate. Get shared lock can only be read but not write S.
Controlled by a concurrent lock. They also have compatibility. S lock and the lock is only compatible with the S, X is not compatible with any lock locks. In other words, there is an X lock when the transaction should be something if and only if X lock it only when he is released, and the other lock can have X or S lock lock this thing.
Interlock mechanism like this is also the problem of deadlock. To avoid this problem, the introduction of a two-phase control protocol. The first phase of growth phase lock transaction allows application data items, but not allowed to release the lock data items. The second phase allows the transaction to release the lock, all locks are not allowed to apply. Sometimes 2PL can not avoid thinking
Three locking protocol - in order to overcome the problem of inconsistent data in the database
- A: prevent loss modification
- Class 2: In addition to preventing the loss of modification may also prevent dirty data read
- Three: In addition to modifications and prevent loss prevention dirty data read, also prevents the non-repeatable read