CN113505114A - Multi-version concurrency control method of database and database system - Google Patents

Multi-version concurrency control method of database and database system Download PDF

Info

Publication number
CN113505114A
CN113505114A CN202110728250.7A CN202110728250A CN113505114A CN 113505114 A CN113505114 A CN 113505114A CN 202110728250 A CN202110728250 A CN 202110728250A CN 113505114 A CN113505114 A CN 113505114A
Authority
CN
China
Prior art keywords
version
transaction
target
snapshot
data record
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.)
Pending
Application number
CN202110728250.7A
Other languages
Chinese (zh)
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.)
Tsinghua University
Original Assignee
Tsinghua University
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 Tsinghua University filed Critical Tsinghua University
Priority to CN202110728250.7A priority Critical patent/CN113505114A/en
Publication of CN113505114A publication Critical patent/CN113505114A/en
Pending legal-status Critical Current

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/21Design, administration or maintenance of databases
    • G06F16/219Managing data history or versioning

Landscapes

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

Abstract

The embodiment of the application provides a multi-version concurrency control method of a database and a database system, and relates to the technical field of databases. The method comprises the following steps: when a target transaction is started, generating a transaction ID for the target transaction, wherein the transaction ID comprises a thread number of a working thread for starting the target transaction and a current local count value of the working thread; acquiring a logic snapshot of a database, and searching a target visible version of a target transaction on a version chain corresponding to a target data record to be operated according to the logic snapshot; and performing reading or updating operation of the data record on the version chain of the target data record based on the target visible version. The technical scheme can provide the isolation level of snapshot isolation and improve the operation efficiency of transactions. Compared with the existing method, the concurrency control method has lower overhead, can remarkably increase the transaction processing capacity of the database, and can reach the speed-up ratio of 4.24 times.

Description

Multi-version concurrency control method of database and database system
Technical Field
The present application relates to the field of database technologies, and in particular, to a multi-version concurrency control method for a database and a database system.
Background
Database systems are one of the important software upon which modern computer applications depend. The database system has a transaction processing interface, and when a transaction is operated, a certain isolation guarantee needs to be provided by means of a concurrency control algorithm. The design of the concurrency control algorithm can greatly influence the transaction processing performance of the database system.
Traditional databases use a two-tier storage architecture based on memory-disk, where memory is used to provide runtime access to data and disk is used to ensure data persistence. Non-volatile memory (NVM) is a new type of storage medium that can both support byte addressing like memory and store data persistently like a disk. A new generation of databases with single-layer storage structures can be implemented with NVM. However, because the access speed of NVM is faster than that of magnetic disk, magnetic disk is no longer a performance bottleneck factor of NVM single-layer database system, and therefore, more efficient concurrent control algorithm is needed to fully utilize the performance of NVM.
The multi-version concurrency control algorithm is a common method for improving the transaction processing performance of the database, and the multi-version concurrency control can provide an isolation level of snapshot isolation and increase the concurrency degree of transaction processing. However, a traditional concurrency control algorithm supporting snapshot isolation usually uses a global counter to allocate a transaction ID to a transaction, and each working thread needs to operate the global counter when starting the transaction, which becomes a performance bottleneck factor of a database system and affects the performance of the database, and particularly when the number of the working threads is large, the processing efficiency of the transaction is rather reduced.
Disclosure of Invention
The embodiment of the application provides a multi-version concurrency control method for a database and a database system, so as to solve the technical problem.
In a first aspect, an embodiment of the present application provides a multi-version concurrency control method for a database, including: when a target transaction is started, generating a transaction ID for the target transaction, wherein the transaction ID comprises a thread number of a working thread for starting the target transaction and a current local count value of the working thread, and after the transaction ID is generated, the local count value of the working thread is incremented by i which is a positive integer not less than 1; acquiring a logic snapshot of a database, and searching a target visible version of a target transaction on a version chain corresponding to a target data record to be operated according to the logic snapshot; the logical snapshot comprises a transaction ID of a latest completed transaction corresponding to each working thread running in the database, and the version chain comprises a plurality of versions of a target data record; and performing reading or updating operation of the data record on the version chain of the target data record through the target transaction based on the target visible version.
In a second aspect, an embodiment of the present application provides a database system, including: the system comprises a transaction ID distribution module, a transaction ID generation module and a transaction ID processing module, wherein the transaction ID distribution module is used for generating a transaction ID for a target transaction when the target transaction is started, the transaction ID comprises a thread number of a working thread for starting the target transaction and a current local count value of the working thread, after the transaction ID is generated, the local count value of the working thread is increased by i, and i is a positive integer not less than 1; the logical snapshot acquisition module is used for acquiring a logical snapshot of the database; the logical snapshot comprises a transaction ID of a latest completed transaction corresponding to each working thread running in the database, and the version chain comprises a plurality of versions of a target data record; and the data record operation module is used for searching a target visible version of the target transaction on a version chain corresponding to the target data record to be operated according to the logic snapshot and performing reading or updating operation on the data record on the version chain of the target data record through the target transaction based on the target visible version.
The invention provides a multi-version concurrency control method supporting snapshot isolation. Compared with the existing concurrency control method supporting snapshot isolation, the method provided by the invention does not need to maintain a global counter, and each working thread only needs to operate a corresponding local counter, so that resource competition is reduced, the transaction processing efficiency can be effectively improved, and the transaction throughput can be well expanded along with the increase of the number of threads.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a flowchart illustrating a multi-version concurrency control method provided by an embodiment of the present application;
FIG. 2 is a flow chart illustrating transactions at various stages in a multi-version concurrency control method provided by an embodiment of the present application;
FIG. 3 is a diagram showing a specific implementation of a transaction ID in the embodiment of the present application;
FIG. 4 is a schematic diagram illustrating a specific implementation of a logical snapshot in an embodiment of the present application;
fig. 5 is a flowchart illustrating the step S12 of acquiring a logical snapshot in the embodiment of the present application;
FIG. 6 is a diagram showing a structure of a version chain in the embodiment of the present application;
FIG. 7 shows a flow diagram of a transaction reading data records on a version chain during a transaction execution phase;
FIG. 8 shows a flow diagram of a transaction updating data records on a version chain during a transaction execution phase;
FIG. 9 is a schematic diagram of a database system provided by an embodiment of the present application;
FIG. 10 is another schematic diagram of a database system provided by an embodiment of the present application;
FIG. 11 is a graph showing experimental results obtained by comparing the N2DB-M system with the N2DB system in the examples of the present application;
FIG. 12 shows a comparison of the results of another experiment comparing the N2DB-M system with the N2DB system in the examples of the present application.
Detailed Description
The following detailed description of exemplary embodiments of the present application, taken in conjunction with the accompanying drawings, makes it apparent that the described embodiments are only some embodiments of the application, and are not exhaustive of all embodiments. It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict.
The embodiment of the application provides a multi-version concurrency control method for a database, and fig. 1 shows a flow chart of the multi-version concurrency control method, wherein the flow chart comprises the following steps:
s100, when the target transaction is started, generating a transaction ID for the target transaction.
S200, acquiring a logic snapshot of the database, wherein the logic snapshot comprises a transaction ID of a latest completed transaction corresponding to each working thread running in the database.
S300, searching a target visible version of the target transaction on a version chain corresponding to the target data record to be operated according to the acquired logic snapshot. The database comprises a plurality of data records, the data record to be operated at this time of the target transaction is the target data record, and a plurality of versions of the same data record form a version chain.
And S400, reading or updating the data record on the version chain of the target data record through the target transaction based on the target visible version.
In a particular embodiment, the life cycle of a transaction includes three phases, start, execute, and end. As shown in fig. 2, in the multi-version concurrency control method, the specific implementation of each stage includes:
s1, a transaction starting phase.
A plurality of working threads run in the database, and the working threads enter a transaction starting stage when a transaction is started. Taking the starting of a certain target transaction as an example, the execution step of the transaction starting phase includes:
s11, when the target transaction starts, a transaction ID is generated for the target transaction. The transaction ID comprises a thread number of a working thread for starting a target transaction and a current local count value of the working thread, and the local count value of the working thread is increased by i after the transaction ID is generated; i is a positive integer not less than 1. Optionally, i is 1.
The transaction ID of the target transaction has global uniqueness, and fig. 3 shows a specific implementation diagram of the transaction ID, as shown in fig. 3, the length of the transaction ID is 64 bits, wherein the upper 8 bits are the thread number of the worker thread, and the lower 56 bits are the value of the local counter of the worker thread, and the local counter of the worker thread is incremented by 1 after one transaction ID is allocated.
And S12, acquiring a logic snapshot of the database, wherein the logic snapshot comprises the transaction ID of the latest completed transaction of each working thread running in the database.
In the present embodiment, the logical snapshot is represented by a vector clock, which is generally considered as a set of clock values Vi [1 ] from different nodes]、Vi[2]、…、Vi[n]The method is used to represent logical snapshots. The logical snapshot includes the transaction ID of the latest completed transaction of each worker thread running in the database, and can represent the range of completed transactions in the database system when the snapshot is generated. Fig. 4 shows a specific implementation diagram of a logical snapshot, where S ═ 3,2,7,5]A vector clock representation of a logical snapshot, which represents: all 4 worker threads in the database have the transaction ID of the latest completed transaction. As shown in FIG. 4, the transaction ID of the latest completed transaction of thread 0 is T (0,3), wherein 0 represents "thread number", 3 represents "local count value", the transaction ID of the latest completed transaction of thread 1 is T (1,2), the transaction ID of the latest completed transaction of thread 2 is T (2,7), the transaction ID of the latest completed transaction of thread 3 is T (3,5), ts isiIndicating the "local count value" in the transaction ID of the last completed transaction for worker thread i.
In one embodiment, when the number of the worker threads in the database is fixed, the thread number of each worker thread is continuous, the logical snapshot may be represented by an array with a fixed length, each value in the array represents a local count value in the transaction ID, and the thread number in the transaction ID is implicit in the position relationship of each array, for example, if the value of the first position in the array is 3, the corresponding transaction ID is thread number "0" + local count value "3". In other embodiments, when the number of the work threads in the database is variable, the thread numbers among the work threads are not necessarily continuous, and the snapshot can be represented in the form of a hash table.
Fig. 5 shows a flowchart for acquiring the logical snapshot in step S12. As shown in fig. 5, S12 includes:
s121, judging whether a non-target transaction is generating a logic snapshot or not; if not, go to S122, and if yes, go to S124.
And S122, generating a new logic snapshot according to the transaction ID of the latest completed transaction of each working thread running in the database.
And S123, writing the newly generated logic snapshot into a snapshot buffer area.
And S124, taking the latest snapshot in the snapshot buffer area as the logic snapshot acquired at this time.
In the above steps S121-S124, it is necessary to first determine whether there are other transactions generating the logical snapshot, and determine how to obtain the logical snapshot according to the determination result, so as to ensure the correctness of snapshot isolation. As previously mentioned, a snapshot actually describes the scope of completed transactions in the entire database system, and for two different snapshots A and B, the scope of completed transactions they describe needs to satisfy an inclusion relationship, i.e., either
Figure BDA0003138333560000051
Or either
Figure BDA0003138333560000052
In this embodiment, snapshots are not allowed to be generated concurrently (that is, when a certain transaction generates a snapshot, other transactions cannot generate snapshots), so as to ensure that any two snapshots satisfy the inclusion relationship described above, thereby ensuring correctness of snapshot isolation.
S2, transaction execution phase.
The transaction enters the execution phase after completing all the above operations. If the transaction is a read transaction, the transaction will read the data record in the database, and if the transaction is a write transaction, the transaction will update the data record in the database. In any database, when a transaction reads/writes data, the database defines an isolation level that describes which data the transaction can see (especially, whether/when data written by other concurrent transactions can be seen). Snapshot isolation is one of the isolation levels. In this embodiment, the result of the operation of transaction reading/updating data records is consistent with the requirement of snapshot isolation.
In this embodiment, a single linked list formed by multiple versions of the same data record is a version chain of the data record, and a structure diagram of the version chain is shown in fig. 6. The version chain includes a header node including the ID of the target data record and a pointer to the latest version (latest version), and a plurality of version nodes including the transaction ID of the version creator, payload data of the version, and a pointer to the previous version (prev version).
In S2, the operation of the transaction execution phase is further divided into a transaction read data record (S21) and a transaction update data record (S22). When a transaction reads a certain target data record in the database, the transaction finds a target visible version in the multi-version storage along the version chain of the target data record based on a certain visibility rule according to the held logical snapshot, and reads the content in the target visible version. Referring to fig. 7, the specific process of the transaction reading the data record on the version chain includes:
s211, acquiring a version chain of the target data record in the database according to the ID of the target data record to be operated.
S212, setting the latest version in the version chain as the currently considered target version.
S213, acquiring the transaction ID of the creator of the target version.
In S213, the transaction ID corresponding to the version node of the target version is obtained from the version chain.
S214, according to the thread number in the transaction ID of the creator, determining a local count value corresponding to the corresponding thread number from the transaction IDs in the acquired logic snapshot.
And extracting the thread number and the local count value from the acquired transaction ID, finding the local count value corresponding to the thread number from the logic snapshot according to the thread number, and comparing the two local count values.
S215, judging whether the local count value in the transaction ID of the creator is not greater than the local count value determined according to the logic snapshot; if the value is larger than the predetermined value, the process goes to S216, and if the value is not larger than the predetermined value, the process goes to S217.
In S215, the size relationship between the transaction ID of the creator of the target version and the transaction ID of the latest completed transaction of the corresponding thread in the acquired snapshot is compared, so as to determine whether the target version was created before the logical snapshot is generated.
S216, setting the previous version of the current target version as a new target version, and then jumping to S213.
S217, judging whether the submission state of the creator is submitted; if it is committed, the process jumps to S218, and if it is not committed, the process jumps to S216.
In this embodiment, each work thread in the database maintains its own commit log, the commit logs of each work thread are decoupled, and each commit log records the commit status (including running, committed, and rolled back) of all transactions on the corresponding thread. In S217, a query is made on the commit log of the corresponding thread using the transaction ID of the creator of the target version to acquire the commit status of the creator.
And S218, determining the current target version as the target visible version.
And S219, reading the load data of the target visible version from the version chain by the target transaction.
During the process of searching along the version chain, the transaction selects the version which is created before the snapshot is generated and the creator of the version is in the committed state as the version visible to the transaction itself, namely the target visible version. If there is no such version, the read operation will fail. For example, after a target version is examined, if the examined version does not meet the requirement, the target version is set to be a previous version pointed by the pointer of the current target version, the previous version may exist (the prev _ version pointer is not null), or may not exist (the prev _ version pointer is a null pointer), and when the target version does not exist, it indicates that the visible version cannot be found, and this reading operation fails.
And after the target transaction determines the target visible version, reading the load data of the target visible version from the version chain, and finishing the data record reading operation.
Furthermore, when the transaction updates a certain target data record in the database, it needs to lock the data record and perform conflict detection according to the held logical snapshot, and after the conflict detection is passed, the data record update operation is performed. Referring to fig. 8, the specific process of the transaction updating the data record on the version chain includes:
s221, adding a record lock for the version chain of the target data record; if the locking is successful, jumping to S222, if the locking is failed, jumping to S225.
Firstly, adding a record lock to a version chain of a target data record to be updated, if the locking fails, indicating that a concurrent transaction is modifying the same data record, and if the updating operation of the current target transaction fails, entering a rollback flow.
S222, searching a target visible version of the target transaction on the version chain according to the logic snapshot.
S223, detecting whether a version which is newer than the target visible version of the target transaction exists on the version chain or not, and the submission state of a creator of the newer version is submitted or running; if not, go to S224, and if so, go to S226.
In S222-223, collision detection is performed. Before updating the data records, it is necessary to determine whether the current target data record has been updated by a concurrent transaction to prevent write conflicts. In the foregoing steps S212-218, a method for determining the visible version of the transaction in the version chain has been provided, and in S222, the same method is adopted to determine the target visible version of the target transaction according to the logical snapshot held by the target transaction, and in S223, conflict detection is performed based on the target visible version. The principle of collision detection is: there cannot be a version on the version chain that is newer than the version visible to the current transaction and that is in commit or running. If such a version exists, the visible version has been modified by the concurrent transaction, conflict detection fails, the current transaction cannot continue updating the data record, it will release the record lock, and a rollback flow is performed.
And S224, performing updating operation of the data record on the version chain by the target transaction.
After the conflict detection is passed, the target transaction may continue to update the data record, and the specific process is as follows:
1) creating a new version node for the target data record in a storage layer of the database;
2) writing the ID and the load data of the target transaction on the newly created version node;
3) maintaining a version chain pointer, enabling the pointer of the newly created version node to point to the latest version in the current version chain, and enabling the pointer of the head node of the current version chain to point to the newly created version node;
4) releasing the record lock on the version chain.
And S225, executing a rollback flow on the target transaction.
S226, releasing the record lock on the version chain, and executing a rollback flow on the target transaction.
And the target transaction enters a transaction ending flow after the read/write operation of the data record is completed in the transaction execution stage.
S3, transaction end phase.
The transaction end includes two cases, namely commit and rollback, and the concurrency control method in this embodiment performs unified processing on the two cases. The transaction ending step is as follows:
s31, in the commit log of the work thread starting the target transaction, updating the commit state of the target transaction, and recording that the commit state of the target transaction is committed or rolled back.
And S32, updating the transaction ID of the latest completed transaction corresponding to the working thread into the transaction ID of the target transaction for the subsequent snapshot generation process.
Based on the foregoing embodiments, the present application further provides a database system, which may be a database system based on a non-volatile memory (NVM), or a database system based on a conventional disk or a conventional memory. In the multi-version concurrency control method in this embodiment, a storage layer of a database is required to adopt multi-version storage, as shown in fig. 9, the database system includes:
(1) and submitting the log. In this embodiment, each work thread in the database maintains its own commit log, the commit logs of each work thread are decoupled, and each commit log records the commit status (including running, committed, and rolled back) of all transactions on the corresponding thread.
(2) A snapshot buffer. The snapshot buffer is used to store logical snapshots of the database that have been generated over the last period of time.
(3) A version linked list storage area. The version chain storage area stores a plurality of version chains, each version chain corresponds to a plurality of versions of a data record, wherein each version chain comprises a head node and a plurality of version nodes, the head node comprises an ID of a target data record and a pointer pointing to the latest version, and the version nodes comprise a transaction ID of a version creator, load data of the version and a pointer pointing to the previous version.
As shown in fig. 10, the database system provided in the embodiment of the present application includes the following modules:
a transaction ID allocating module 410, configured to generate a transaction ID for a target transaction when the target transaction is started, where the transaction ID includes a thread number of a work thread that starts the target transaction and a current local count value of the work thread, and after the transaction ID is generated, the local count value of the work thread is incremented by i; i is a positive integer not less than 1;
a logic snapshot obtaining module 420, configured to obtain a logic snapshot of a database, where the logic snapshot includes a transaction ID of a latest completed transaction of each worker thread running in the database, and the version chain includes multiple versions of a target data record;
the data record operation module 430 is configured to search a target visible version of the target transaction on a version chain corresponding to a target data record to be operated according to the logical snapshot; and based on the target visible version, performing reading or updating operation of the data record on the version chain of the target data record through the target transaction.
It can be understood that, in the database system in this embodiment, the implementation principle and the generated technical effect are already introduced in the foregoing method embodiment, and for the sake of brief description, corresponding descriptions in the foregoing method embodiment may be referred to for what is not mentioned in the database system, and are not repeated herein.
In order to verify the actual use effect of the multi-version concurrency control method provided by the invention, an NVM database system using the multi-version concurrency control method provided by the embodiment of the invention is denoted as "N2 DB-M", an NVM system using the PostgreSQL concurrency control method is denoted as "N2 DB", and the performances of N2DB-M and N2DB are compared. The experimental environment was a single machine equipped with 18 core CPUs and 6 Optane non-volatile memory (NVM). The transaction throughputs of the two systems are measured under different working thread numbers, and the obtained experimental results are shown in fig. 11 and fig. 12, wherein fig. 11 shows the transaction throughputs of the two systems under different thread numbers under the condition of carrying out experiments by using loads a, B and C, and fig. 12 shows the transaction throughputs of the two systems under different thread numbers under the condition of using TPC-C loads and having TPC-C load parameters of "warehouse number" equal to 1, equal to 4 and equal to thread numbers. Under the load experiments, N2DB-M achieves higher maximum transaction throughput than N2DB, and nearly three times of acceleration ratio can be obtained at most.
The multi-version concurrency control method provided by the invention has the advantage that the performance of transaction processing can be expanded when the number of the working threads is increased. From the experimental results, it can be seen that, due to the PostgreSQL concurrency control method adopted by N2DB, a global counter is used to assign a timestamp to a transaction, and the global counter needs to be locked when a snapshot is generated, so that when the number of working threads is large, the transaction throughput is rather reduced due to the global lock. While the transaction throughput of N2DB-M can scale well as the number of work threads increases.
In summary, the present invention designs a multi-version concurrency control method supporting snapshot isolation, in which a local counter of a working thread is used to assign a transaction ID to a transaction, an original global counter is removed, and a local counter of each thread is used to replace the global counter, and further, based on "replacing the global counter with multiple counters", the present invention designs a transaction operation flow, thereby correctly implementing the isolation level of snapshot isolation. In the prior art, in order to ensure the correctness of the snapshot, a global counter is usually required to be locked, so that a bottleneck exists in the performance of the global counter. In addition, the submission logs of the working threads in the technical scheme are decoupled, so that write competition cannot occur on the submission logs, and the performance is better compared with a scheme using a global submission log.
It should be noted that the concurrency control algorithm provided by the present invention has universality, and is not only suitable for NVM databases, but also suitable for traditional disk or memory databases.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (12)

1. A multi-version concurrency control method of a database is characterized by comprising the following steps:
when a target transaction is started, generating a transaction ID for the target transaction, wherein the transaction ID comprises a thread number of a working thread for starting the target transaction and a current local count value of the working thread, and after the transaction ID is generated, the local count value of the working thread is incremented by i which is a positive integer not less than 1;
acquiring a logic snapshot of a database, and searching a target visible version of a target transaction on a version chain corresponding to a target data record to be operated according to the logic snapshot; the logical snapshot comprises a transaction ID of a latest completed transaction corresponding to each working thread running in the database, and the version chain comprises a plurality of versions of a target data record;
and performing reading or updating operation of the data record on the version chain of the target data record through the target transaction based on the target visible version.
2. The method of claim 1, wherein taking the logical snapshot of the database comprises:
judging whether a non-target transaction is generating a logic snapshot or not;
if no non-target transaction is generating a logic snapshot, generating a new logic snapshot according to the transaction ID of the latest completed transaction of each working thread running in the database;
writing the newly generated logic snapshot into a snapshot buffer;
and acquiring the latest snapshot in the snapshot buffer area as the logical snapshot of the database.
3. The method of claim 2, wherein after determining whether a non-target transaction is generating a logical snapshot, the method further comprises: and if a non-target transaction is generating a logic snapshot, acquiring the latest snapshot in the snapshot buffer area as the logic snapshot of the database.
4. The method of claim 1, wherein the version chain comprises a head node and a plurality of version nodes, the head node comprises an ID of a target data record and a pointer to a latest version, the version nodes comprise a transaction ID of a version creator, payload data of the version and a pointer to a previous version, and the finding a target visible version of the target transaction on the version chain corresponding to the target data record to be operated according to the logical snapshot comprises:
acquiring a version chain of a target data record in a database according to the ID of the target data record to be operated;
setting the latest version in the version chain as a currently investigated target version;
acquiring a transaction ID of a creator of the target version;
according to the thread number in the transaction ID of the creator, determining a local count value corresponding to the corresponding thread number from each acquired transaction ID in the logic snapshot;
judging whether a local count value in the transaction ID of the creator is not greater than the local count value determined according to the logic snapshot;
if not, judging whether the submission state of the creator is submitted;
and if the current target version is submitted, determining the current target version as the target visible version.
5. The method of claim 4, further comprising:
if the local count value in the transaction ID of the creator is larger than the local count value determined according to the logic snapshot, or the commit state of the creator is not committed, setting the previous version of the current target version as a new target version, and then jumping to the transaction ID of the creator for acquiring the target version.
6. The method of claim 4, wherein performing a read or update operation on a version chain of a target data record by the target transaction based on the target visible version comprises: and if the target transaction is a read transaction, reading the load data of the target visible version from the version chain through the target transaction.
7. The method of claim 4, wherein performing a read or update operation on a version chain of a target data record by the target transaction based on the target visible version comprises:
if the target transaction is a write transaction, adding a record lock for the version chain of the target data record through the target transaction;
detecting whether a version which is newer than the target visible version exists on the version chain and the submission state of a creator of the newer version is submitted or running;
and if the version chain does not have the version meeting the conditions, updating the data record on the version chain through the target transaction.
8. The method of claim 7, wherein the performing the update operation of the data record on the version chain by the target transaction comprises:
creating a new version node for the target data record in a storage layer of the database;
writing the ID and the load data of the target transaction on the newly created version node;
maintaining a version chain pointer, enabling the pointer of a newly created version node to point to the latest version in a current version chain, and enabling the pointer of a head node of the current version chain to point to the newly created version node;
releasing the record lock on the version chain.
9. The method according to claim 7 or 8, characterized in that the method further comprises:
and if the addition of the record lock to the version chain of the target data record fails, executing a rollback flow on the target transaction.
10. The method according to claim 7 or 8, wherein after detecting whether a newer version than the target visible version exists on the version chain and the commit status of the creator of the newer version is committed or running, the method further comprises:
and if the version meeting the conditions exists in the version chain, releasing the record lock on the version chain and executing a rollback process on the target transaction.
11. The method of claim 1, wherein after performing a read or update operation of a data record on a version chain of a target data record by the target transaction based on the target visible version, the method further comprises:
and updating the commit state of the target transaction in a commit log of the working thread which starts the target transaction, and updating the transaction ID of the latest completed transaction corresponding to the working thread to be the transaction ID of the target transaction.
12. A database system, comprising:
the system comprises a transaction ID distribution module, a transaction ID generation module and a transaction ID processing module, wherein the transaction ID distribution module is used for generating a transaction ID for a target transaction when the target transaction is started, the transaction ID comprises a thread number of a working thread for starting the target transaction and a current local count value of the working thread, after the transaction ID is generated, the local count value of the working thread is increased by i, and i is a positive integer not less than 1;
the logical snapshot acquisition module is used for acquiring a logical snapshot of the database; the logical snapshot comprises a transaction ID of a latest completed transaction corresponding to each working thread running in the database, and the version chain comprises a plurality of versions of a target data record;
and the data record operation module is used for searching a target visible version of the target transaction on a version chain corresponding to the target data record to be operated according to the logic snapshot and performing reading or updating operation on the data record on the version chain of the target data record through the target transaction based on the target visible version.
CN202110728250.7A 2021-06-29 2021-06-29 Multi-version concurrency control method of database and database system Pending CN113505114A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110728250.7A CN113505114A (en) 2021-06-29 2021-06-29 Multi-version concurrency control method of database and database system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110728250.7A CN113505114A (en) 2021-06-29 2021-06-29 Multi-version concurrency control method of database and database system

Publications (1)

Publication Number Publication Date
CN113505114A true CN113505114A (en) 2021-10-15

Family

ID=78009518

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110728250.7A Pending CN113505114A (en) 2021-06-29 2021-06-29 Multi-version concurrency control method of database and database system

Country Status (1)

Country Link
CN (1) CN113505114A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114691307A (en) * 2022-03-16 2022-07-01 阿里巴巴(中国)有限公司 Transaction processing method and computer system
CN116401262A (en) * 2023-03-06 2023-07-07 安芯网盾(北京)科技有限公司 Database upgrading method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114691307A (en) * 2022-03-16 2022-07-01 阿里巴巴(中国)有限公司 Transaction processing method and computer system
CN116401262A (en) * 2023-03-06 2023-07-07 安芯网盾(北京)科技有限公司 Database upgrading method and device
CN116401262B (en) * 2023-03-06 2024-02-02 安芯网盾(北京)科技有限公司 Database upgrading method and device

Similar Documents

Publication Publication Date Title
US11386065B2 (en) Database concurrency control through hash-bucket latching
US7890472B2 (en) Parallel nested transactions in transactional memory
US8271464B2 (en) Parallel nested transactions in transactional memory
US7962456B2 (en) Parallel nested transactions in transactional memory
US8364909B2 (en) Determining a conflict in accessing shared resources using a reduced number of cycles
EP3346401A1 (en) Distributed, transactional key-value store
CN113505114A (en) Multi-version concurrency control method of database and database system
EP3396560B1 (en) Database operating method and device
CN107665219B (en) Log management method and device
US20100058344A1 (en) Accelerating a quiescence process of transactional memory
EP3396542B1 (en) Database operating method and device
CN110515705B (en) Extensible persistent transactional memory and working method thereof
CN113515501B (en) Nonvolatile memory database management system recovery method and device and electronic equipment
US20170235780A1 (en) Providing lock-based access to nodes in a concurrent linked list
WO2022206398A1 (en) Method and apparatus for reading data maintained in tree data structures
CN115080670A (en) Deterministic transaction concurrency control method based on GPU acceleration
CN113253932B (en) Read-write control method and system for distributed storage system
US10671427B2 (en) Snapshot isolation in graphical processing unit hardware transactional memory
CN110515707B (en) Deterministic concurrency control method and system based on advanced transaction processing
CN110825734B (en) Concurrent updating method of balance tree and read-write system
CN112100188A (en) Concurrent control method and system based on machine learning
CN111444214A (en) Method and device for processing large-scale data and industrial monitoring memory database
US11625386B2 (en) Fast skip list purge
CN115422182A (en) Read-write performance optimization method based on persistent memory B + tree index
CN111400333A (en) Data parallel writing method, system and computer readable medium

Legal Events

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