CN-121979620-A - Database transaction management method, device, equipment, storage medium and program product
Abstract
The present application relates to a method, apparatus, device, storage medium and program product for managing database transactions. The method comprises the steps of traversing a rollback file in a memory when a need of cutting-off operation on a transaction commit log is detected, searching a target transaction identifier in the rollback file, wherein the identifier value of the target transaction identifier is the minimum value of a transaction identifier to be recovered in the rollback file, the target transaction identifier corresponds to a transaction in a rollback state, a rollback state or a committed state, the rollback file comprises a plurality of transaction identifiers, states of all the transactions and information storage addresses of all the transactions, the transaction identifier adopts 64 bits to encode, and cutting-off operation is carried out on all the transactions smaller than the target transaction identifier in the transaction commit log. By setting the rollback file in the memory to store the transaction information, the target transaction identification can be rapidly determined when the transaction commit log is truncated, and the transaction smaller than the target transaction identification is directly judged and visible, so that the fluctuation of the performance of the database is avoided.
Inventors
- WU QI
Assignees
- 天翼云科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251222
Claims (10)
- 1. A method of managing database transactions, the method comprising: When detecting that a transaction commit log needs to be truncated, traversing a rollback file in a memory to find a target transaction identifier in the rollback file, wherein the identifier value of the target transaction identifier is the minimum value of a transaction identifier to be recovered in the rollback file, and the transaction corresponding to the target transaction identifier is in a rollback state or a rollback state; and performing a truncation operation on all the transactions smaller than the target transaction identification in the transaction commit log.
- 2. The method of claim 1, wherein the method of determining the target transaction identification comprises: determining a transaction identifier of a transaction to be recycled in the rollback file, wherein the transaction to be recycled is in a rolled back state, a submitted state and an operating state; and taking the transaction identifier with the smallest identifier value in the transaction identifiers of all the transactions to be recycled as a target transaction identifier.
- 3. The method according to claim 1 or 2, characterized in that the method further comprises: When a first transaction is detected, a first log space and a first rollback file are allocated for the first transaction, wherein the first transaction corresponds to the data inserting operation or the data updating operation; recording old data of the first transaction to the first log space; updating new data of the first transaction to a data page; And recording the transaction identification of the first transaction and the address information of the first log space into the first rollback file, and identifying the state of the first transaction, wherein the state comprises a recovered state, a rolled back state, a state to be rolled back, a submitted state and an operating state.
- 4. The method of claim 3, wherein the first transaction corresponds to an operation to insert data, the method further comprising: An index of the first transaction is added to an index page.
- 5. The method according to claim 4, wherein the method further comprises: When a second transaction is detected, old data corresponding to the second transaction is obtained from a first log space corresponding to the second transaction, and the old data is updated to the data page; Deleting new data corresponding to the second transaction on the data page; and updating the state of the second transaction in the first rollback file corresponding to the second transaction to be the rolled back state.
- 6. The method of claim 5, wherein the type of rollback data is insert data, the method further comprising: and deleting index information corresponding to the second transaction on the index page.
- 7. A database transaction management device, the device comprising: The query module is used for traversing the rollback file in the memory to find out a target transaction identifier in the rollback file when the need of cutting-off operation on the transaction commit log is detected, wherein the identifier value of the target transaction identifier is the minimum value of the transaction identifier to be recovered in the rollback file, and the transaction corresponding to the target transaction identifier is in a rollback state or a rollback state; And the cut-off module is used for cutting off all the transactions smaller than the target transaction identification in the transaction commit log.
- 8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any one of claims 1 to 6 when the computer program is executed.
- 9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any one of claims 1 to 6.
- 10. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
Description
Database transaction management method, device, equipment, storage medium and program product Technical Field The present application relates to the field of data processing technologies, and in particular, to a method, an apparatus, a device, a storage medium, and a program product for managing database transactions. Background In the database management system, a transaction identifier (xid) is written into a tuple header and is used for comparing with a transaction snapshot so as to judge the visibility of the tuple, and meanwhile, a transaction Commit Log (CLOG) is set and is used for recording the state before data modification so as to quickly judge whether the transaction is committed or not, and whether the tuple is valid or not is judged according to whether the transaction is committed or not in the visibility judgment. When the conventional method judges whether the tuple is visible through the rollback operation, due to the fact that the transaction commit log cannot be infinitely increased and the transaction identifier rollback, when the data table garbage is recycled (vacuum), the database firstly obtains the freezing limit (freeze_limit) according to the parameters and the minimum currently visible transaction (oldest _xmin), traverses the tuple in each block of the data table, and sets the freezing transaction identifier (frozen _xid) for all the tuples smaller than the freezing limit, so that the tuple is directly judged to be visible according to the freezing identifier when the visibility is judged. And finally, after the garbage collection of the data table is completed, acquiring the minimum freezing limit value of all tables of the database to truncate the transaction commit log. However, since the truncation of the transaction commit log requires scanning all tuples to perform a freeze operation, the freeze operation relies on garbage collection operations that sweep the table, greatly affecting the performance of the database system. Disclosure of Invention In view of the foregoing, it is desirable to provide a method, apparatus, device, storage medium, and program product for managing database transactions that can avoid significant performance fluctuations of a database. In a first aspect, the present application provides a method for managing database transactions, including: When detecting that a transaction commit log needs to be truncated, traversing a rollback file in a memory to find a target transaction identifier in the rollback file, wherein the identifier value of the target transaction identifier is the minimum value of a transaction identifier to be recovered in the rollback file, and the transaction corresponding to the target transaction identifier is in a rollback state or a rollback state; and performing a truncation operation on all the transactions smaller than the target transaction identification in the transaction commit log. In one embodiment, the method for determining the target transaction identification includes: determining a transaction identifier of a transaction to be recycled in the rollback file, wherein the transaction to be recycled is in a rolled back state, a submitted state and an operating state; and taking the transaction identifier with the smallest identifier value in the transaction identifiers of all the transactions to be recycled as a target transaction identifier. In one embodiment, the method further comprises: When a first transaction is detected, a first log space and a first rollback file are allocated for the first transaction, wherein the first transaction corresponds to the data inserting operation or the data updating operation; recording old data of the first transaction to the first log space; updating new data of the first transaction to a data page; And recording the transaction identification of the first transaction and the address information of the first log space into the first rollback file, and identifying the state of the first transaction, wherein the state comprises a recovered state, a rolled back state, a state to be rolled back, a submitted state and an operating state. In one embodiment, the first transaction corresponds to an operation of inserting data, and the method further comprises: An index of the first transaction is added to an index page. In one embodiment, the method further comprises: When a second transaction is detected, old data corresponding to the second transaction is obtained from a first log space corresponding to the second transaction, and the old data is updated to the data page; Deleting new data corresponding to the second transaction on the data page; and updating the state of the second transaction in the first rollback file corresponding to the second transaction to be the rolled back state. In one embodiment, the type of rollback data is insert data, and the method further includes: and deleting index information corresponding to the second transaction on the index page. In a secon