CN108363806B - Multi-version concurrency control method and device for database, server and storage medium - Google Patents

Multi-version concurrency control method and device for database, server and storage medium Download PDF

Info

Publication number
CN108363806B
CN108363806B CN201810171319.9A CN201810171319A CN108363806B CN 108363806 B CN108363806 B CN 108363806B CN 201810171319 A CN201810171319 A CN 201810171319A CN 108363806 B CN108363806 B CN 108363806B
Authority
CN
China
Prior art keywords
transaction
current
record
data page
target data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810171319.9A
Other languages
Chinese (zh)
Other versions
CN108363806A (en
Inventor
王海龙
韩朱忠
薛慧
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Dameng Database Co Ltd
Original Assignee
Shanghai Dameng Database Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Dameng Database Co Ltd filed Critical Shanghai Dameng Database Co Ltd
Priority to CN201810171319.9A priority Critical patent/CN108363806B/en
Publication of CN108363806A publication Critical patent/CN108363806A/en
Application granted granted Critical
Publication of CN108363806B publication Critical patent/CN108363806B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2315Optimistic concurrency control
    • G06F16/2329Optimistic concurrency control using versioning

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a multi-version concurrency control method, a device, a server and a storage medium of a database, wherein the method comprises the following steps: when the current affair is started, the affair number of the current affair is blocked in an exclusive lock mode; if the current operation of the current transaction is write operation, generating a transaction save point; searching a target data page corresponding to the write operation, and locking the target data page in an exclusive lock mode; and executing the current operation according to a preset rule. Through the blocking mechanism, the number of locks has no direct relation with the number of records of transaction modification, the number of locks can be greatly reduced, blocking conflicts and blocking resource consumption are reduced, and the concurrency efficiency of the database management system is improved.

Description

Multi-version concurrency control method and device for database, server and storage medium
Technical Field
The invention relates to the technical field of databases, in particular to a multi-version concurrency control method and device of a database, a server and a storage medium.
Background
At present, each mainstream database management system basically realizes an MVCC mechanism, but the MVCC realization mechanism of each product has obvious difference, for example, PostgreSQL L and SQ L Server realize the MVCC based on physical records and directly store the physical records of a plurality of versions, while Oracle, InnodB and Dadame database (DM7) realize the MVCC based on rollback records, and the system only stores the physical records of the latest Version and utilizes the rollback records to store the historical information of the data.
The basic idea of implementing MVCC based on rollback records is to judge whether the current record meets the requirement of consistency state, that is, whether the data is visible or not, if the current record is invisible, the historical data is backtracked by using a pointer pointing to the rollback record of the previous version, and finally the data meeting the requirement of consistency reading is constructed.
In the conventional concept, a transaction TrxA modifies a row of data before it has an exclusive row-level lock (X-lock) on the row of data, and if another transaction TrxB has previously blocked the row of data, the blocking system blocks the current transaction TrxA until TrxB releases the row-level lock.
In order to reduce the resource consumption of the lock object, each database product adopts a series of optimization measures, for example, the InnodB uses a BIT (BIT) to indicate a row of records on a certain data page, and compared with the direct use of a row identifier (ROWID) for indication, the resource consumption of the lock object can be greatly reduced. However, in general, the blocking overhead of a transaction is positively correlated with the number of records modified by the transaction, and the resource consumption of the lock object cannot be really reduced.
Disclosure of Invention
The invention provides a multi-version concurrency control method and device for a database, a server and a storage medium, which can reduce the number of locks, reduce blocking conflicts and blocking resource consumption and improve the concurrency efficiency of a database management system.
In a first aspect, an embodiment of the present invention provides a multi-version concurrency control method for a database, including:
when the current affair is started, the affair number of the current affair is blocked in an exclusive lock mode;
if the current operation of the current transaction is write operation, generating a transaction save point;
searching a target data page corresponding to the write operation, and locking the target data page in an exclusive lock mode;
and executing the current operation according to a preset rule.
Further, after blocking the transaction number of the current transaction in an exclusive lock mode, the method further includes:
if the transaction isolation level of the current transaction is serialized or repeatable read, collecting an active transaction view and an assigned maximum transaction number;
if the transaction isolation level of the current transaction is read commit, then after generating a transaction save point, collecting the active transaction view and the assigned maximum transaction number.
Further, if the current operation is an insertion, the executing the current operation according to a preset rule includes:
inserting data to be inserted into the target data page, writing the transaction number of the current transaction into a TID field of a record corresponding to the data to be inserted, and releasing the lock of the target data page.
Further, if the current operation is deleting or updating, the executing the current operation according to a preset rule includes:
reading a transaction number in a TID field of a record to be operated in the target data page;
judging the visibility of the record to be operated on the current transaction according to the transaction number in the TID field, the active transaction view and the allocated maximum transaction number;
and executing the current operation according to the visibility of the record to be operated on the current transaction.
Further, the executing the current operation according to the visibility of the record to be operated on the current transaction includes:
if the record to be operated is visible to the current transaction, deleting or updating data in the target data page, writing the transaction number of the current transaction into the TID field of the record to be operated, and releasing the lock of the target data page;
if the record to be operated is invisible to the current transaction, releasing the lock of the target data page, blocking the transaction number in the TID field in an exclusive lock mode, when the transaction corresponding to the transaction number in the TID field is submitted or rolled back, successfully blocking the transaction number in the TID field, and re-executing the steps of searching the target data page, locking the target data page and judging the visibility of the record; if the record to be operated is visible to the current transaction, executing the current operation and releasing the lock of the target data page; and if the record to be operated is invisible to the current transaction, executing corresponding operation according to the transaction isolation level of the current transaction.
Further, the executing the corresponding operation according to the transaction isolation level of the current transaction includes:
if the transaction isolation level of the current transaction is read commit, rolling back the current transaction to the transaction save point;
if the transaction isolation level of the current transaction is serialized or repeatedly readable, determining that the current operation fails, and outputting error information.
Further, after all operations of the current transaction are executed, the lock of the transaction number of the current transaction is released.
In a second aspect, an embodiment of the present invention further provides a multi-version concurrency control apparatus for a database, where the apparatus includes:
the transaction number blocking module is used for blocking the transaction number of the current transaction in an exclusive lock mode when the current transaction is started;
a save point generating module, configured to generate a transaction save point if the current operation of the current transaction is a write operation;
the data page locking module is used for searching a target data page corresponding to the write operation and locking the target data page in an exclusive lock mode;
and the operation execution module is used for executing the current operation according to a preset rule.
In a third aspect, an embodiment of the present invention further provides a server, where the server includes:
one or more processors;
storage means for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors implement the multi-version concurrency control method for the database according to any embodiment of the invention.
In a fourth aspect, the embodiments of the present invention further provide a server, a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a multi-version concurrency control method for a database as described in any embodiment of the present invention.
The invention provides a multi-version concurrency control method of a database, which blocks a transaction number of a current transaction in an exclusive lock mode when the current transaction is started, and prevents other transactions from blocking the current transaction and modifying data. If the current operation of the current transaction is a write operation, generating a transaction save point so that in the processing process of the transaction, a certain part of operation on the database can be cancelled by rolling back to a certain transaction save point; searching a target data page corresponding to the write operation, and locking the target data page in an exclusive lock mode, so that other transactions can not modify the same data during data modification operation; and after the current transaction number and the target data page are blocked, executing the operation of the transaction according to a preset rule. Through the blocking mechanism, the number of locks has no direct relation with the number of records of transaction modification, the number of locks and the consumption of blocking resources can be greatly reduced, and the concurrency efficiency of the database management system is improved.
Drawings
Fig. 1 is a flowchart of a multi-version concurrency control method for a database according to an embodiment of the present invention.
Fig. 2 is a flowchart of a multi-version concurrency control method for a database according to a second embodiment of the present invention.
Fig. 3 is a flowchart of another multi-version concurrency control method for a database according to a second embodiment of the present invention.
Fig. 4 is a schematic structural diagram of a multi-version concurrency control device for a database according to a third embodiment of the present invention.
Fig. 5 is a schematic structural diagram of a server in the fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a multi-version concurrency control method for a database according to an embodiment of the present invention, where this embodiment is applicable to a multi-version concurrency control situation of a database, and the method can be executed by a multi-version concurrency control device for a database, and specifically includes the following steps:
s110, when the current transaction is started, blocking the transaction number of the current transaction in an exclusive lock mode.
If the transaction is cancelled or rolled back due to an error, all SQ L statement operations of the transaction are cleared, and the database is restored to a state before the transaction is executed, an Exclusive lock, also called an Exclusive lock (X-lock) or a write lock, is a basic lock type, if the transaction T adds an X-lock to a data object M, only T is allowed to read and modify M, and any other transaction cannot add any lock to M until T releases the lock on M.
And S120, if the current operation of the current transaction is write operation, generating a transaction save point.
The transaction save point is a logical point in the transaction process, and can roll back the transaction to the point without rolling back the whole transaction, and is a mark for the application program to roll back partial transaction when encountering minor error.
S130, searching a target data page corresponding to the write operation, and locking the target data page in an exclusive lock mode.
The method comprises the steps of obtaining a target data page, locking the target data page by using an exclusive latch (L ATCH), wherein the latch is a lightweight level lock and is a concurrency control mechanism used for data page access in a database, and the latch obtaining and releasing speed is high.
And S140, executing the current operation according to a preset rule.
The preset rule refers to a preset policy for how to execute the current operation, and illustratively, the corresponding policy corresponding to the execution of the insert, delete and update operations may be preset according to the visibility principle of the transaction and different transaction isolation levels, so as to implement a database mechanism with high concurrency efficiency and low resource consumption.
Optionally, after all operations of the current transaction are executed, the lock of the transaction number of the current transaction is released, and after the lock is released, occupation of system resources can be reduced, operation efficiency of other transactions can be accelerated, and a database row-level blocking mechanism with high concurrency efficiency and low resource consumption is realized.
The invention provides a multi-version concurrency control method of a database, which blocks a transaction number of a current transaction in an exclusive lock mode when the current transaction is started, and prevents other transactions from blocking the current transaction and modifying data. If the current operation of the current transaction is a write operation, generating a transaction save point so that in the processing process of the transaction, a certain part of operation on the database can be cancelled by rolling back to a certain transaction save point; searching a target data page corresponding to the write operation, and locking the target data page in an exclusive lock mode, so that other transactions can not modify the same data during data modification operation; and executing the current operation according to a preset rule, and releasing the lock of the transaction number of the current transaction after the operation is completed. By the blocking mechanism, the number of locks has no direct relation with the number of records of transaction modification, and only when update conflict occurs, explicit blocking (namely, the current transaction number blocks the transaction number in the TID field) is needed, so that the number of line-level locks can be greatly reduced, blocking conflict and blocking resource consumption are reduced, and the concurrency efficiency of the database management system is improved.
Example two
Fig. 2 is a flowchart of a multi-version concurrency control method for a database according to a second embodiment of the present invention, where this embodiment provides an implementation manner that, when a current operation is an insertion, the current operation is executed according to a preset rule, and as shown in fig. 2, the method specifically includes:
s210, when the current transaction is started, blocking the transaction number of the current transaction in an exclusive lock mode.
And S220, if the current operation of the current transaction is write operation, generating a transaction save point.
S230, searching a target data page corresponding to the write operation (insertion), and locking the target data page in an exclusive lock mode.
S240, inserting data to be inserted into the target data page, writing the transaction number of the current transaction into a TID field of a record corresponding to the data to be inserted, and releasing the lock of the target data page.
When inserting operation is carried out, corresponding data is inserted into a locked target data page, the transaction number of the current transaction is written into the TID field of the corresponding insertion record, and after the lock of the target data page is released. When the transaction accesses and modifies the record each time, the transaction can read the TRX _ ID in the TID field on the record, and judge the visibility of the record to the current transaction according to the visibility principle of the record to further perform the current operation, thereby realizing the multi-version concurrent control of the data.
Fig. 3 is a flowchart of another multi-version concurrency control method for a database according to a second embodiment of the present invention, and optionally, on the basis of the foregoing embodiments, an implementation manner is provided in which, when a current operation is a deletion or an update, the current operation is executed according to a preset rule, and as shown in fig. 3, the method specifically includes:
s310, when the current transaction is started, the transaction number of the current transaction is blocked in an exclusive lock mode.
And S320, if the current operation of the current transaction is write operation, generating a transaction save point.
Optionally, the active transaction view and the allocated maximum transaction number may be collected according to the transaction isolation level of the current transaction, and used to determine the visibility of the record to be operated on the current transaction when executing the delete or update operation. The active transaction view comprises active transactions and transaction numbers TID corresponding to the active transactions, and the allocated maximum transaction number refers to the maximum transaction number which is already allocated to the transactions by the system at the moment of currently collecting the transaction numbers.
Specifically, if the transaction isolation level of the current transaction is serialized or repeatedly readable, the active transaction view and the allocated maximum transaction number are collected after the transaction number of the current transaction is blocked in an exclusive lock mode; if the transaction isolation level of the current transaction is read commit, then after generating a transaction save point, collecting the active transaction view and the assigned maximum transaction number.
S330, searching a target data page corresponding to the write operation (deletion or update), and locking the target data page in an exclusive lock mode.
S340, reading a transaction number in a TID field of a record to be operated in the target data page; and judging the visibility of the record to be operated on the current transaction according to the transaction number in the TID field, the active transaction view and the allocated maximum transaction number.
When the current operation is deletion or update, the transaction number in the TID field of the record to be operated is read, which may be a TRX _ ID, and corresponds to the transaction that has recently modified the record to be operated. That is to say, when a user accesses a record, the transaction number in the TID field of the record is read first, and then whether the record is visible to the current transaction is determined according to whether the transaction number in the TID field is in the collected active transaction view and whether the transaction number is greater than the maximum transaction number that has been allocated, so that the current operation can be further executed.
And S350, executing the current operation according to the visibility of the record to be operated on the current transaction.
Optionally, the determining, according to the transaction number in the TID field, the active transaction view, and the allocated maximum transaction number, the visibility of the record to be operated on the current transaction includes:
if one of the following conditions is met, determining that the record to be operated is invisible to the current transaction:
the transaction number in the TID field is one of the active transaction views;
the transaction number in the TID field is greater than the allocated maximum transaction number.
That is, when the transaction number TRX _ ID in the TID field is smaller than the allocated maximum transaction number and is not in the active transaction view, it can be determined that the record to be operated is visible for the current transaction, and the rest of the records are invisible. Since the transaction does not see any modifications to the same record by the uncommitted transaction, if the same record is visible to the current transaction, it is said that other transactions that modify this record must have committed. When the determination is visible, it may be determined that the transaction that most recently modified the pending record has committed before the current transaction started, and thus the record is visible. If the record is visible to the current transaction, it indicates that the transaction that modified the record has committed, and the record can be modified by the current transaction. If the record is not visible to the current transaction, it indicates that other transactions are concurrently modifying the record, and the current transaction may not modify the record.
Optionally, in S350, if the record to be operated is visible to the current transaction, deleting or updating data in the target data page, writing the transaction number of the current transaction into the TID field of the record to be operated, and releasing the lock of the target data page. That is, if it is visible, the delete or update operation can be directly performed, and the transaction number of the current transaction is written in the TID field of the corresponding modification record, and other transactions cannot modify the record until the current transaction releases the lock of the target data page.
Optionally, in S350, if the record to be operated is invisible to the current transaction, releasing the lock of the target data page, blocking the transaction number in the TID field in an exclusive lock manner, and when the transaction corresponding to the transaction number in the TID field is committed or rolled back, successfully blocking the transaction number in the TID field, re-performing the steps of searching for the target data page, locking the target data page, and determining the visibility of the record; if the record to be operated is visible to the current transaction, executing the current operation and releasing the lock of the target data page; and if the record to be operated is invisible to the current transaction, executing corresponding operation according to the transaction isolation level of the current transaction.
That is, if not visible, it indicates that the current transaction cannot directly perform the current update or delete operation, and the transaction number in the TID field can be blocked with an exclusive lock after the lock on the target data page is released. Because the transaction number in the TID field generates an exclusive lock at the time of transaction initiation, the block conflicts, the block for the current transaction may be blocked, and the block may be in a wait state. When the transaction corresponding to the transaction number in the TID field is committed or rolled back, the blocking is successful, and at this time, the current transaction is awakened to continue the current operation. And re-executing the steps of searching the target data page, locking the target data page and judging the visibility of the record (namely S330 and S340), and if the record is judged to be visible to the current transaction, indicating that the transaction of the modified record is rolled back, and continuing to execute the deleting or updating operation.
If the record is judged to be still invisible to the current transaction, releasing the lock of the target data page, and executing corresponding operation according to the transaction isolation level of the current transaction, wherein the method specifically comprises the following steps:
if the transaction isolation level of the current transaction is read commit, rolling back the current transaction to the transaction save point;
if the transaction isolation level of the current transaction is serialized or repeatedly readable, determining that the current operation fails, and outputting error information.
And according to the definition of the isolation level of the read-commit transaction, rolling back to the transaction storage point, recollecting the active transaction view and the allocated maximum transaction number, and re-executing deletion or update operation according to S330 to S350.
The technical solution of this embodiment provides a multi-version concurrency control method for a database, where a transaction number is written into a TID field of a record to be operated when an insertion, update, or deletion operation is performed on a transaction, and the record to be operated is implicitly blocked once. Since the transaction number remains the same after the transaction is started, the TID field values on these records are the same regardless of how many row records are modified by the transaction. By utilizing the TID field and the database latch on the record, a database row-level blocking mechanism with high concurrency efficiency and low resource consumption is realized, and the problem of write and write concurrency conflict is solved. In the case of no update conflicts, the row-level lock is eliminated completely, and no matter how many row records are modified by a transaction, no row-level lock object is generated. When a plurality of transactions modify the same line record concurrently and update conflict occurs, reading the TID field of the record, blocking the read TID, and converting the blocking aiming at the record line into blocking the transaction number. By adopting the blocking mechanism, the number of locks has no direct relation with the number of records of transaction modification, and explicit blocking is needed only when update conflicts occur, so that the number of locks can be greatly reduced, blocking conflicts and blocking resource consumption are reduced, and the concurrency efficiency of the database management system is improved.
EXAMPLE III
Fig. 4 is a schematic structural diagram of a multi-version concurrency control device for a database according to a third embodiment of the present invention, where this embodiment is applicable to a case of multi-version concurrency control for a database, and as shown in fig. 4, the multi-version concurrency control device for a database includes:
a transaction number blocking module 410, configured to block a transaction number of a current transaction in an exclusive lock manner when the current transaction is started;
a save point generating module 420, configured to generate a transaction save point if the current operation of the current transaction is a write operation;
a data page locking module 430, configured to search for a target data page corresponding to the write operation, and lock the target data page in an exclusive lock manner;
an operation executing module 440, configured to execute the current operation according to a preset rule.
Optionally, the apparatus further comprises:
the first transaction collection module is used for collecting an active transaction view and an allocated maximum transaction number if the transaction isolation level of the current transaction is serialized or repeatedly readable after the transaction number of the current transaction is blocked in an exclusive lock mode;
and the second transaction collection module is used for collecting the active transaction view and the allocated maximum transaction number after generating a transaction save point if the transaction isolation level of the current transaction is read commit.
Optionally, the operation executing module 440 includes:
a transaction number reading unit, configured to read a transaction number in a TID field of a record to be operated in the target data page if the current operation is deletion or update;
a visibility judging unit, configured to judge, according to the transaction number in the TID field, the active transaction view, and the allocated maximum transaction number, visibility of the record to be operated on the current transaction;
and the first operation execution unit is used for executing the current operation according to the visibility of the record to be operated on the current transaction.
Optionally, the first operation execution unit includes:
a first operation execution subunit, configured to delete or update data in the target data page if the record to be operated is visible to the current transaction, write the transaction number of the current transaction into the TID field of the record to be operated, and release the lock of the target data page;
a second operation execution subunit, configured to release the lock of the target data page and block the transaction number in the TID field in an exclusive lock manner if the record to be operated is invisible to the current transaction, and when a transaction corresponding to the transaction number in the TID field is committed or rolled back, block the transaction number in the TID field successfully, re-perform the steps of searching for the target data page, locking the target data page, and determining the visibility of the record; if the record to be operated is visible to the current transaction, executing the current operation and releasing the lock of the target data page; and if the record to be operated is still invisible to the current transaction, executing corresponding operation according to the transaction isolation level of the current transaction.
Optionally, the second operation execution subunit is specifically configured to: under the condition that the record to be operated is still invisible to the current transaction, if the transaction isolation level of the current transaction is read commit, rolling back the current transaction to the transaction save point; if the transaction isolation level of the current transaction is serialized or repeatedly readable, determining that the current operation fails, and outputting error information.
Optionally, the operation executing module 440 includes:
and the second operation execution unit is used for inserting data to be inserted into the target data page if the current operation is insertion, writing the transaction number of the current transaction into a TID field of a record corresponding to the data to be inserted, and releasing the lock of the target data page.
Optionally, the apparatus further comprises: and the lock releasing module is used for releasing the lock of the transaction number of the current transaction after all the operations of the current transaction are executed.
The device can execute the multi-version concurrency control method of the database provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the multi-version concurrency control method of the database.
It should be noted that, in the embodiment of the multi-version concurrency control device of the database, the modules included in the embodiment are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
Example four
An embodiment of the present invention provides a server, including: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement the multi-version concurrency control method for a database according to any embodiment of the present invention.
Fig. 5 is a schematic structural diagram of a server according to a fourth embodiment of the present invention, referring to fig. 5, where the server includes a processor 510 and a memory 520; the number of the processors 510 in the server may be one or more, and one processor 510 is taken as an example in fig. 5; the processor 510 and the memory 520 in the server may be connected by a bus or other means, and the bus connection is exemplified in fig. 5.
The memory 520 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the multi-version concurrency control method of the database in the embodiment of the present invention (for example, the transaction number blocking module 410, the save point generating module 420, the data page locking module 430, and the operation executing module 440 in the multi-version concurrency control device of the database). The processor 510 executes various functional applications of the server and data processing by executing software programs, instructions, and modules stored in the memory 520, that is, implements the multi-version concurrent control method of the database described above.
The memory 520 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 520 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 520 may further include memory located remotely from processor 510, which may be connected to a server over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The server provided by the embodiment of the present invention not only can execute and implement the multi-version concurrency control method for the database provided by any embodiment of the present invention, but also can execute other programs or methods according to specific requirements of services.
EXAMPLE five
The present embodiment provides a computer-readable storage medium on which a computer program is stored, which when executed by a processor implements a multi-version concurrency control method for a database according to any embodiment of the present invention.
The computer program stored in the computer-readable storage medium provided in this embodiment, except for being executed by the processor to implement the multi-version concurrency control method for the database in any embodiment of the present invention, may also include other programs to implement specific business requirements.
Based on the understanding that the technical solutions of the present invention can be embodied in the form of software products, such as floppy disks, Read-Only memories (ROMs), Random Access Memories (RAMs), flash memories (F L ASHs), hard disks or optical disks of a computer, etc., and include instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods according to the embodiments of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A multi-version concurrency control method of a database is characterized by comprising the following steps:
when the current affair is started, the affair number of the current affair is blocked in an exclusive lock mode;
if the current operation of the current transaction is write operation, generating a transaction save point;
searching a target data page corresponding to the write operation, and locking the target data page in an exclusive lock mode;
executing the current operation according to a preset rule; the preset rules comprise the step of presetting corresponding strategies corresponding to the execution of the insertion, deletion and updating operations according to the visibility principle of the transaction and different transaction isolation levels.
2. The method of claim 1, wherein after blocking the transaction number of the current transaction by an exclusive lock, further comprising:
if the transaction isolation level of the current transaction is serialized or repeatable read, collecting an active transaction view and an assigned maximum transaction number;
if the transaction isolation level of the current transaction is read commit, then after generating a transaction save point, collecting the active transaction view and the assigned maximum transaction number.
3. The method of claim 1, wherein if the current operation is an insert, the performing the current operation according to a predetermined rule comprises:
inserting data to be inserted into the target data page, writing the transaction number of the current transaction into a TID field of a record corresponding to the data to be inserted, and releasing the lock of the target data page.
4. The method of claim 2, wherein if the current operation is a delete or an update, the performing the current operation according to a predetermined rule comprises:
reading a transaction number of a transaction which most recently modifies the record to be operated in a TID field of the record to be operated in the target data page;
judging the visibility of the record to be operated on the current transaction according to the transaction number in the TID field, the active transaction view and the allocated maximum transaction number;
and executing the current operation according to the visibility of the record to be operated on the current transaction.
5. The method of claim 4, wherein performing the current operation according to the visibility of the to-be-operated record to the current transaction comprises:
if the record to be operated is visible to the current transaction, deleting or updating data in the target data page, writing the transaction number of the current transaction into the TID field of the record to be operated, and releasing the lock of the target data page;
if the record to be operated is invisible to the current transaction, releasing the lock of the target data page, blocking the transaction number in the TID field in an exclusive lock mode, when the transaction corresponding to the transaction number in the TID field is submitted or rolled back, successfully blocking the transaction number in the TID field, and re-executing the steps of searching the target data page, locking the target data page and judging the visibility of the record; if the record to be operated is visible to the current transaction, executing the current operation and releasing the lock of the target data page; and if the record to be operated is invisible to the current transaction, executing corresponding operation according to the transaction isolation level of the current transaction.
6. The method of claim 5, wherein performing the corresponding operation according to the transaction isolation level of the current transaction comprises:
if the transaction isolation level of the current transaction is read commit, rolling back the current transaction to the transaction save point;
if the transaction isolation level of the current transaction is serialized or repeatedly readable, determining that the current operation fails, and outputting error information.
7. The method of claim 1, further comprising:
and releasing the lock of the transaction number of the current transaction after all operations of the current transaction are executed.
8. A multi-version concurrency control apparatus for a database, comprising:
the transaction number blocking module is used for blocking the transaction number of the current transaction in an exclusive lock mode when the current transaction is started;
a save point generating module, configured to generate a transaction save point if the current operation of the current transaction is a write operation;
the data page locking module is used for searching a target data page corresponding to the write operation and locking the target data page in an exclusive lock mode;
the operation execution module is used for executing the current operation according to a preset rule; the preset rules comprise the step of presetting corresponding strategies corresponding to the execution of the insertion, deletion and updating operations according to the visibility principle of the transaction and different transaction isolation levels.
9. A server, characterized in that the server comprises:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a multi-version concurrency control method for a database in accordance with any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a multi-version concurrency control method for a database according to any one of claims 1 to 7.
CN201810171319.9A 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium Active CN108363806B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810171319.9A CN108363806B (en) 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810171319.9A CN108363806B (en) 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium

Publications (2)

Publication Number Publication Date
CN108363806A CN108363806A (en) 2018-08-03
CN108363806B true CN108363806B (en) 2020-07-31

Family

ID=63003078

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810171319.9A Active CN108363806B (en) 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium

Country Status (1)

Country Link
CN (1) CN108363806B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022271301A1 (en) * 2021-06-25 2022-12-29 Microsoft Technology Licensing, Llc Transaction identifier locking with data row locks

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109376026A (en) * 2018-09-14 2019-02-22 上海新炬网络信息技术股份有限公司 A kind of data synchronization check implementation method based on script
US11640383B2 (en) 2018-11-15 2023-05-02 Huawei Technologies Co., Ltd. Systems and methods for managing a shared database
CN109710629B (en) * 2019-01-08 2020-12-18 上海达梦数据库有限公司 Data access method, device, server and storage medium
CN109933606B (en) * 2019-03-19 2021-04-27 上海达梦数据库有限公司 Database modification method, device, equipment and storage medium
CN109976672B (en) * 2019-03-22 2022-02-22 深信服科技股份有限公司 Read-write conflict optimization method and device, electronic equipment and readable storage medium
CN110825752B (en) * 2019-10-16 2020-11-10 深圳巨杉数据库软件有限公司 Database multi-version concurrency control system based on fragment-free recovery
CN110990377B (en) * 2019-11-21 2023-08-22 上海达梦数据库有限公司 Data loading method, device, server and storage medium
CN111090663B (en) * 2019-12-25 2023-07-07 上海金仕达软件科技股份有限公司 Transaction concurrency control method, device, terminal equipment and medium
CN111259071B (en) * 2020-01-04 2022-08-05 浙江科技学院 Concurrent access control method in distributed database system
CN111240810B (en) * 2020-01-20 2024-02-06 上海达梦数据库有限公司 Transaction management method, device, equipment and storage medium
CN112883045B (en) * 2021-03-31 2024-05-17 中国工商银行股份有限公司 Database transaction splitting execution method and device
CN113746682A (en) * 2021-09-07 2021-12-03 迈普通信技术股份有限公司 Configuration guarantee method and device
CN114297217A (en) * 2021-12-31 2022-04-08 深圳市兆珑科技有限公司 Transaction concurrency control method and device, electronic equipment and readable storage medium
CN115543970B (en) * 2022-11-29 2023-03-03 本原数据(北京)信息技术有限公司 Data page processing method, data page processing device, electronic equipment and storage medium
CN116383209A (en) * 2023-03-30 2023-07-04 深圳计算科学研究院 Concurrency control method and concurrency control device for column-store database

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101364230A (en) * 2008-09-24 2009-02-11 金蝶软件(中国)有限公司 Concurrent access control method and device
CN101763390A (en) * 2008-12-24 2010-06-30 北京大学深圳研究生院 Database storing system and method based on Berkeley DB
WO2014026611A1 (en) * 2012-08-14 2014-02-20 Huawei Technologies Co., Ltd. Rollback method and apparatus of transaction, relational database management system
CN104793988A (en) * 2014-01-20 2015-07-22 阿里巴巴集团控股有限公司 Cross-database distributed transaction implementation method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104679881B (en) * 2015-03-13 2019-03-08 华为技术有限公司 A kind of concurrency control method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101364230A (en) * 2008-09-24 2009-02-11 金蝶软件(中国)有限公司 Concurrent access control method and device
CN101763390A (en) * 2008-12-24 2010-06-30 北京大学深圳研究生院 Database storing system and method based on Berkeley DB
WO2014026611A1 (en) * 2012-08-14 2014-02-20 Huawei Technologies Co., Ltd. Rollback method and apparatus of transaction, relational database management system
CN104793988A (en) * 2014-01-20 2015-07-22 阿里巴巴集团控股有限公司 Cross-database distributed transaction implementation method and device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022271301A1 (en) * 2021-06-25 2022-12-29 Microsoft Technology Licensing, Llc Transaction identifier locking with data row locks

Also Published As

Publication number Publication date
CN108363806A (en) 2018-08-03

Similar Documents

Publication Publication Date Title
CN108363806B (en) Multi-version concurrency control method and device for database, server and storage medium
EP3117348B1 (en) Systems and methods to optimize multi-version support in indexes
US6647510B1 (en) Method and apparatus for making available data that was locked by a dead transaction before rolling back the entire dead transaction
EP2378420B1 (en) Ownership reassignment in a shared-nothing database system
EP3467668B1 (en) Method for processing database transaction, client and server
US8429134B2 (en) Distributed database recovery
US7664799B2 (en) In-memory space management for database systems
KR100862661B1 (en) Method for deferred logging and apparatus thereof
US11442961B2 (en) Active transaction list synchronization method and apparatus
US7912821B2 (en) Apparatus and method for data management
US10769128B2 (en) Delegated key-level locking for a transactional multi-version key-value store
JP7101566B2 (en) Multiversion Concurrency Control (MVCC) in non-volatile memory
US20140040208A1 (en) Early release of transaction locks based on tags
CN113220490A (en) Transaction persistence method and system for asynchronous write-back persistent memory
CN113032292B (en) Storage space recovery method, data reading method and device
CN114691307A (en) Transaction processing method and computer system
US20080082533A1 (en) Persistent locks/resources for concurrency control
CN114328591A (en) Transaction execution method, device, equipment and storage medium
CN117076147B (en) Deadlock detection method, device, equipment and storage medium
CN117632888A (en) Transaction visibility checking method, device, equipment and medium
CN116860768A (en) Database transaction processing method, device, equipment and storage medium
CN117609246A (en) Data processing method and device for columnar storage of multiple bins

Legal Events

Date Code Title Description
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant