Implement Transaction Management in simpledb (3)

Source: Internet
Author: User

We have already talked about the concurrency management and crash recovery management of transactions, leaving the last point:

1. Manage the transaction's own buffer

2. Transaction manage data read/write

> Transaction Buffer Management

A bufferlist is maintained in transaction, and this bufferlist maintains the buffer of the transaction currently pin.

Figure 1 bufferlist class diagram

Maintain a dictionary <block, buffer> Object buffers, and save the buffer associated with the current transaction. A list <block> Object pins stores the disk blocks involved in the current transaction; the buffer manager buffermgr uses the static objects of the system.

Figure 2 Relationship Between Transaction bufferlist and system bufferpool

Bufferlist is the buffer associated with the manager's current transaction. It provides available buffer when reading and writing data, and releases buffer in batches when the transaction is committed.

> Transaction

Figure 3 transaction class diagram

Transaction provides transaction management to ensure that all transactions can be serialized and recovered, basically meeting the acid characteristics.

    • Concurrency ensures consistency and isolation
    • Recovery ensures atomicity and Durability

The following describes how to read and write data under TX management:

1. Read data

A) Use concurrencymgr to add slock to the data block

B) obtain the buffer through the bufferlist object for reading data.

C) read data through Buffer

2. Write Data

A) Add xlock to the data block through concurrencymgr

B) obtain the buffer through the bufferlist object to write data.

C) Write logs first, write logs through recoverymgr, and save the old data stored in the data location

D) write new data through Buffer

The following figure shows the relationship between the read and write data and recoverymgr and concurrencymgr:

Figure 4 association between read/write data and recoverymgr and concurrencymgr

 

Finally, from the transaction perspective, check the transaction commit, rollback, and recovery)

1. Commit

When a transaction is committed, all the modified data and the corresponding operation log records must be persistently written to the disk, written to and persisted to a commit log record on the disk, and finally the Left and Right locks should be released, release all associated buffer

A) Submit recoverymgr and modify data and log records persistently.

B) concurrencymgr releases the lock held by the current transaction

C) The bufferlist object releases the buffer associated with all the current transactions.

2. rollback

Roll back the current transaction, reverse all actions of the current transaction, reset the modified data, release the lock held, and release all associated buffer.

A) recoverymgr roll back and reverse the action of the current firm

B) concurrencymgr releases the lock held by the current transaction

C) The bufferlist object releases the buffer associated with all the current transactions.

Figure 4 recoverymgr rollback method

3. Recovery

When the transaction is restored, the data in all the buffer (the buffer of the system, not the buffers of the transaction) is first persisted, and then the transaction is restored through recoverymgr.

A) persist all the data in the buffer.

B) Resume transactions through recoverymgr

 

The transaction management module ends.

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.