Four characteristics of Dark horse day11 affairs

Source: Internet
Author: User

1. Four characteristics of a transaction: the most basic characteristic of a transaction, a well-designed database can guarantee the four characteristics.
1.1 atomicity: Atomicity means that a transaction is an inseparable unit of work, and the operations in the transaction either occur or do not occur.
1.2 Consistency: If the database is a state of integrity before the transaction is executed, the database remains an integrity state after the transaction finishes regardless of whether the transaction succeeds.
Integrity State of the database: when all the data in a database conforms to all the constraints defined in the database, it can be said that the database is an integrity state.
1.3 Isolation: Transaction isolation is when multiple users concurrently access the database, one user's transaction can not be disturbed by other users ' transactions, multiple concurrent transactions between transactions to be isolated
1.4 Persistence: Persistence refers to the fact that once a transaction is committed, it changes the data in the database to be permanent, and then it should not have any effect even if the database fails.
2. Isolation:
The design of the database as a single-threaded database prevents all thread-safety problems and naturally ensures isolation. But if the database is designed like this, then efficiency can be extremely low.
If two threads are modified concurrently, they will be disruptive to each other, and the lock mechanism must be used to prevent concurrent modification of multiple threads.
If two threads are queried concurrently, there is no thread safety issue
If two threads a modification, a query ...
Dirty reads: One transaction reads uncommitted data to another transaction

Non-REPEATABLE READ: Reads a row of data from a table within a transaction, multiple read results are different-row level issues
Dirty Read
Transaction 1: Zhang San to John Doe transfer 100 Yuan
Transaction 2: John Doe View your account

? T1: Transaction 1: Start transaction
? T2: Transaction 1: Zhang San to John Doe transfer 100 Yuan
? T3: Transaction 2: Start transaction
? T4: Transaction 2: John Doe View your account, see the account more than 100 yuan (dirty Read)
? T5: Transaction 2: Committing a transaction
? T6: Transaction 1: ROLLBACK TRANSACTION, back to the state before the transfer
Non-REPEATABLE READ
Transaction 1: Hotel View two times Room No. 1048th status
Transaction 2: Book Room number 1048th

? T1: Transaction 1: Start transaction
? T2: Transaction 1: View number 1048th room status is idle (first time query)
? T3: Transaction 2: Start transaction
? T4: Transaction 2: Booking room 1048th
? T5: Transaction 2: Committing a transaction
? T6: Transaction 1: Check room 1048th again for use (second query)
? T7: Transaction 1: Committing a transaction
Two query results for the same record are inconsistent!

Phantom reading
Transaction 1: Two statistics on hotel room reservation records
Transaction 2: Add a booking room record

? T1: Transaction 1: Start transaction
? T2: Transaction 1: Statistical booking records 100
? T3: Transaction 2: Start transaction
? T4: Transaction 2: Add a booking room record
? T5: Transaction 2: Committing a transaction
? T6: Transaction 1: Re-counting the booking record to 101 records
? T7: Transaction 1: Commit
Inconsistent with two queries on the same table!

The difference between non-repeatable reads and Phantom reads:
? Non-repeatable reads are updates to another transaction;
? A phantom read is an insert that reads to another transaction (it cannot be tested into a phantom read in MySQL);

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Four characteristics of Dark horse day11 affairs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.