(Star ImportNew to improve Java skills)
Atomicity: All operations in a transaction are indivisible in the database, either all done or none executed.
Consistency: Several transactions executed in parallel that must have a result consistent with the result of a sequence of serial executions.
Isolation: The execution of a transaction is not interfered with by other transactions, and the intermediate results of transaction execution must be transparent to other transactions.
Durability: For any committed transaction, the system must ensure that the transaction’s changes to the database are not lost, even if the database fails
When adding a new record, when creating the corresponding undo log, you only need to record the primary key value of the record, if you want to roll back the insertion operation, you only need to delete the record according to the corresponding primary key value.
When deleting a record, when creating the corresponding undo log, you need to record all the contents of this data, if you want to roll back the delete statement, you need to produce the corresponding insert statement for the recorded data content and insert it into the database.
When updating a record, if the primary key is not updated, when creating the corresponding undo log, if you want to roll back the update statement, you need to record the content before the change, if you want to roll back the update statement, you need to update the recorded data back according to the primary key.
When updating a record, if there is an update primary key, when creating the corresponding undo log, you need to record all the contents of the data, if you want to roll back the update statement, first delete the data after the change, and then execute the insert statement to insert the backup data into the database.
Transaction A id is 1 inserts a piece of data X, this data trx_id = 1 , roll_pointer is empty (the first insert).
Transaction B id is 2 This data is updated, this data trx_id = 2 , roll_pointer points to the undo log of transaction A.
The transaction C id is 3 and the data is updated, the data trx_id = 3, roll_pointer points to the undo log of transaction B.
m_ids: Represents a list of transaction IDs for read-write transactions that were active in the current system at the time the ReadView was built.
min_trx_id: Represents the smallest transaction id in the current system at the time the ReadView was built, that is, the smallest value in m_ids.
max_trx_id: Indicates the id value that should be assigned to the next transaction in the system when the ReadView is built.
creator_trx_id: Represents the transaction ID of the transaction that generated the ReadView.
If the trx_id property value of the accessed version is the same as the creator_trx_id value in the ReadView, it means that the current transaction is accessing its own modified records, so that version can be accessed by the current transaction.
If the value of the trx_id property of the accessed version is less than the min_trx_id value in the ReadView, the transaction that generated the version was committed before the current transaction generated the ReadView, so the version can be accessed by the current transaction.
If the value of the trx_id property of the accessed version is greater than the max_trx_id value in the ReadView, it means that the transaction that generated the version is not started until the current transaction generates the ReadView, so the version cannot be accessed by the current transaction.
If the value of the trx_id property of the accessed version is between the min_trx_id and max_trx_id of the ReadView, it is necessary to determine whether the value of the trx_id property is in the m_ids list, and if the transaction that generated the version is still active when the ReadView is created, the version cannot be accessed; If not, the transaction that generated the version when the ReadView was created has been committed and the version can be accessed.
If a version of the data is not visible to the current transaction, follow the version chain to find the next version of the data, continue to determine the visibility according to the steps above, and so on, until the last version in the version chain. If the last version is also not visible, it means that the record is completely invisible to the transaction, and the query results do not include the record.
Transferred from: OSCHINA
Link: https://my.oschina.net/u/4090830/blog/5580720
– EOF –
Dig three feet into the Redis and MySQL data consistency issues
Caching and database consistency issues, read this article is enough
Got a harvest after reading this article? Please forward and share it with more people
Follow “ImportNew” to improve your Java skills
Likes and looks are the biggest support ❤️