Method and apparatus for processing transaction in database system, and database system
By transmitting incremental transaction states within the CSN range between the read node and the target node, and utilizing the mapping relationship between CSN and xid for visibility determination, the problem of high performance overhead of read transactions in existing technologies is solved, and efficient read transaction processing is achieved.
Patent Information
- Application Number
- PCT/CN2025/083706
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-05-27
- Filing Date
- 2025-03-20
- Publication Date
- 2025-12-04
AI Technical Summary
Existing database systems require synchronizing the entire transaction state to the read nodes when processing read transactions, resulting in excessive performance overhead and failing to meet the RC or RR requirements for read transactions.
By transmitting incremental transaction states within the CSN range between the read node and the target node, and utilizing the mapping relationship between CSN and xid for visibility determination, the amount of data synchronized is reduced, thereby improving the performance of reading transactions.
It reduces the performance overhead of processing read transactions, improves the processing efficiency of read transactions, and meets the RC or RR requirements of read transactions.
Smart Images

Figure CN2025083706_04122025_PF_FP_ABST
Abstract
Description
Transaction processing method and device in database system and database system
[0001] The present application claims priority to the Chinese Patent Application No. 202410671886.6, filed on May 27, 2024, and entitled "Transaction processing method and device in database system and database system", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD
[0002] The present application relates to the technical field of database, in particular to a transaction processing method, device and database system in a database system. BACKGROUND
[0003] The data records stored in a database system usually have one or more versions, and different versions are marked by different transaction identifiers (xids). The transaction identifiers can include transaction identifiers (xmin) for inserting the records and transaction identifiers (xmax) for deleting the records.
[0004] Multiply version concurrence control (MVCC) is a mechanism for ensuring that a read transaction reads correct version data in a multi-transaction concurrent execution scenario. In a multi-transaction concurrent scenario, the data read by a read transaction needs to meet the requirements of read commit (RC) or repeatable read (RR). RC means that a read transaction reads only committed transaction data and does not read uncommitted transaction (transaction is being executed, execution fails or has been rolled back) modified data. RR means that a read transaction reads only committed transaction data, and for the same data, the read transaction reads the same version no matter how many times it reads.
[0005] In order to meet the above RC or RR requirements of the read transaction, the read node needs to first obtain the transaction state according to the transaction identifier when processing each read request, and then use the transaction state to make a visibility judgment for each data record. Only the data records visible to the read request can be returned to the client sending the read request. The current database system needs to synchronize the full transaction state to the read node when processing each read request, which causes a large performance overhead. SUMMARY
[0006] The present application provides a transaction processing method in a database system for reducing the performance overhead of processing read transactions and improving the performance of processing read transactions. The present application also provides corresponding devices, computer-readable storage medium computer program products and database systems, etc.
[0007] The first aspect of the present application provides a transaction processing method in a database system, comprising: a read node receiving a first read request and a corresponding first commit sequence number (CSN), the first CSN being a snapshot corresponding to the first read request; the read node pulling a first transaction state corresponding to a CSN in an interval between the first CSN and a second CSN from a target node, wherein the second CSN is a snapshot corresponding to a second read request, the second read request being adjacent to the first read request in terms of receiving time sequence or processing time sequence, and the second read request being prior to the first read request, the first transaction state comprising at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, a value is a transaction identifier (xid), a CSN in each first mapping relationship is greater than the second CSN and is not greater than the first CSN; the read node reading at least one first data record according to the first read request; the read node performing visibility judgment according to the first CSN, the at least one first mapping relationship and the first data record, and returning a query result corresponding to the first read request according to a result of the visibility judgment.
[0008] In the present application, the database system can be a distributed database system (DDBS). The database system can comprise one or more read nodes (read DN), one or more write nodes (write DN). The database system can further comprise one or two global transaction managers (GTM), if there are two GTMs, one is a primary GTM, and the other GTM is a standby GTM, the database system can further comprise a coordinator node (CN); or the database system can not comprise a GTM and a CN, but comprise a cluster caching facility / cluster facility (CF). Of course, the database system can further comprise other nodes, which are not limited in the present application.
[0009] In the present application, the target node refers to a node for storing a mapping relationship <CSN, xid> with a key of CSN and a value of xid. In a database system comprising a GTM, the target node is the GTM; in a database system not comprising a GTM, the <CSN, xid> is stored in a write node, and the target node is the write node; in a database system comprising a cluster caching facility / cluster facility (CF), the <CSN, xid> is stored in the CF, and the target node is the CF.
[0010] In the present application, the process in which the read node pulls the first transaction state corresponding to the CSN in the first CSN and second CSN interval from the target node can include: the read node sends a transaction state acquisition request to the target node, the transaction state acquisition request including the first CSN and the second CSN, and the read node receives the first transaction state from the target node.
[0011] In the present application, the first read request can be sent by the CN to the read node, and the first read request can be sent by the CN to the read node after the CN receives the read request (query statement) sent by the client, obtains the first CSN from the target node, and then adds the first CSN to the first read request. The second read request is a read request received or processed by the read node before the first read request. If the first read request is the Mth read request received or processed by the read node, the second read request is the (M-1)th read request processed by the read node, where M>1 and M is an integer.
[0012] In the present application, a transaction is a sequence of database operations, consisting of all operations executed between transaction begin and transaction commit. These operations are either all executed or all not executed, and are an indivisible unit of work. Transaction commit refers to the transaction being executed and saved in the data storage after the transaction is executed. When the transaction begins or is generated, the database system allocates a transaction identifier xid to the transaction. After the transaction is committed, a CSN is allocated to the transaction. The xid and CSN can be referred to as transaction state.
[0013] In the present application, a snapshot refers to the maximum CSN in the database system when the read request is received by the database system. The maximum CSN corresponding to the read request arriving at the database system at different times is usually different.
[0014] In the present application, the query result can be the first data record visible to the first read request. If there is no visible first data record, the query result that the first data record corresponding to the first read request does not exist can be returned.
[0015] In the above first aspect, when processing the read request, the read node can pull the first transaction state using the first CSN and the second CSN because the first transaction state stored in the target node is keyed by CSN and valued by xid. Moreover, the first transaction state pulled by the read node is the incremental transaction state with CSN greater than the second CSN and less than or equal to the first CSN. The target node does not need to synchronize the full transaction state to the read node, which reduces the data volume of synchronizing the transaction state, reduces the performance overhead of processing the read transaction, and improves the performance of processing the read transaction.
[0016] In a possible implementation, if the first CSN is the same as the second CSN, it indicates that the database system has no newly added transaction state, in this case, the read node receives prompt information from the target node, and the prompt information is used to indicate that there is no incremental transaction state in the target node, and then the read node can use the mapping relationship pulled before and the first CSN to perform visibility judgment on the first data record.
[0017] In a possible implementation, the step of performing, by the read node, visibility judgment according to the first CSN, the at least one first mapping relationship, and the first data record includes:
[0018] The read node converts each first mapping relationship into a key-value pair with xid as the key and CSN as the value.
[0019] The read node converts, according to the key-value pair of xid and CSN, a transaction identifier xmin representing an insertion transaction in the first data record into a commit sequence number xminCSN representing the insertion transaction, and converts a transaction identifier xmax representing a deletion transaction into a commit sequence number xmaxCSN representing the deletion transaction, and performs visibility judgment according to the first CSN, the xminCSN, and the xmaxCSN in the first data record.
[0020] In a possible implementation, the key-value pair <xid, CSN> in the read node is stored in a hash table.
[0021] In this possible implementation, because the first data record stores a transaction identifier (xmin) representing an insertion transaction and a transaction identifier (xmax) representing a deletion transaction, the key used in the visibility judgment is xid. Therefore, after obtaining the first mapping relationship, the read node stores the <CSN, xid> in the hash table in the format of the key-value pair <xid, CSN>. In the visibility judgment, the xmin and xmax in the first data record are combined with the <xid, CSN> in the hash table to convert the respective xminCSN and xmaxCSN, and then the xminCSN and the xmaxCSN are compared with the first CSN to determine the result of the visibility judgment. As can be seen, the read node flexibly adjusts the storage format of the first mapping relationship <CSN, xid> in the read node, and improves the speed of subsequent visibility judgment.
[0022] In a possible implementation, if xminCSN in the first data record is less than or equal to the first CSN, and xmaxCSN is greater than the first CSN, the first data record is visible.
[0023] In the possible implementation, xminCSN≤ the first CSN indicates that the transaction has been committed, and xmaxCSN> the first CSN indicates that the data record has not been deleted when the database system receives the read request, and therefore, the data record is visible to the read request. In this way, the visibility of the first data record is determined by simple comparison, which can improve the speed of visibility determination and improve the performance of read request processing.
[0024] In a possible implementation, the transaction processing method further includes: receiving a target xid from the write node, the target xid being used to indicate that data records with xmin no greater than the target xid in the data record of the write node are in a frozen state; and deleting, from the hash table, key-value pairs with xid no greater than the target xid.
[0025] In the possible implementation, the hash table is stored in the memory, and if there are too many data in the hash table, more memory will be occupied. However, the data records in the write node that are in the frozen state will not be read again. Therefore, the read node can delete, in a timely manner, the key-value pairs with xid no greater than the target xid in the hash table according to the state of the data records in the write node, to clean up data that will not be used, thereby reducing the occupation of the memory and improving the memory utilization.
[0026] In a possible implementation, the first transaction state further includes at least one second mapping relationship, where a key in each second mapping relationship is a rollback sequence number (RSN), and a value is a transaction identifier xid; and correspondingly, the hash table further includes a key-value pair with the key being the xid and the value being the RSN.
[0027] If the xmin in the target data record cannot be found from the key-value pair of xid and CSN, but the xmin corresponding to xminRSN can be found from the key-value pair of xid and RSN, the read node determines that the target data record is a rolled-back record, and the target data record is included in the at least one first data record.
[0028] In this application, <xid, RSN> can be stored separately from <xid, CSN> in different spaces, or different lengths are used to distinguish RSN and CSN.
[0029] In a possible implementation manner, the second mapping relationship <RSN, xid> is a processing manner for a rolled-back transaction, and if the transaction has been rolled back, the corresponding transaction commit sequence number cannot be found. Therefore, the read node can save <xid, RSN> in the hash table, and when performing the visibility judgment, if the xminCSN corresponding to the xmin cannot be found, the corresponding xminRSN can be found through <xid, RSN> to determine that the target data record is a rolled-back record, thereby achieving more comprehensive processing of the transaction.
[0030] In a possible implementation manner, the transaction processing method further includes that the read node sends a snapshot obtaining request to the target node, the snapshot obtaining request includes the first CSN, and the snapshot obtaining request is used to request a third CSN, the third CSN is a snapshot corresponding to the snapshot obtaining request, the first CSN and the third CSN are used for the target node to extract a second transaction state from the circular array, to accelerate synchronization of transaction states stored in the circular array to the read node, and the second transaction state includes at least one third mapping relationship, a CSN in each third mapping relationship is greater than the first CSN and is not greater than the third CSN; and the read node receives the second transaction state from the target node.
[0031] In a possible implementation manner, the circular array can be understood as a storage space, and the read node actively sends the snapshot obtaining request to the target node, which can accelerate the speed of the read node pulling the incremental data in the circular array. In this way, the read node can promote the space recycling of the circular array in the target node, which is conducive to storing the newly added transaction state in the circular array, and can also reduce the pulling amount of the incremental transaction state when a read request is received subsequently.
[0032] The second aspect of the present application provides a transaction processing method in a database system, including: receiving a transaction state obtaining request sent by a read node, the transaction state obtaining request including a first CSN and a second CSN, the first CSN being a snapshot corresponding to a first read request, and the second CSN being a snapshot corresponding to a second read request, the second read request being adjacent to the first read request in a receiving sequence or a processing sequence, and the second read request being before the first read request; obtaining a corresponding first transaction state according to the first CSN and the second CSN, the first transaction state including at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, a value is a transaction identifier xid, a CSN in each first mapping relationship is greater than the second CSN and is not greater than the first CSN; and sending the first transaction state to the read node, the first transaction state being used for the read node to perform a visibility judgment on at least one first data record corresponding to the first read request.
[0033] In the second aspect, the transaction processing method can be executed by a target node, and the target node can be a GTM, a write node or a CF.
[0034] In the present application, the first mapping relationship can be represented as <CSN, xid>, where CSN is the key and xid is the value.
[0035] In the above second aspect, because the first transaction state stored in the target node is keyed by CSN and valued by xid, the target node can read the incremental first transaction state using the first CSN and the second CSN and return it to the read node. The target node does not need to synchronize the full transaction state to the read node, which reduces the data volume of the synchronized transaction state, reduces the performance overhead of processing read transactions, and improves the performance of processing read transactions.
[0036] In a possible implementation, if the first CSN is the same as the second CSN, it indicates that the database system has no new transaction state, in which case the target node only needs to send a prompt message to the read node, and the prompt message is used to indicate that there is no incremental transaction state in the target node. Then the read node can use the mapping relationship pulled before and the first CSN to make a visibility judgment on the first data record.
[0037] In a possible implementation, the transaction processing method further includes: obtaining a commit sequence number CSN obtaining request initiated by the write node, the CSN obtaining request containing a first transaction identifier xid; assigning a target CSN to the CSN obtaining request, and writing a mapping relationship between the target CSN and the first xid into the circular array.
[0038] In this possible implementation, the target node can synchronize the mapping relationship between the target CSN and the first xid when assigning the CSN to the write node. In this way, when processing read transactions, the read node can directly obtain the mapping relationship between the target CSN and the first xid, which is used to process read transactions, thereby improving the performance of processing read transactions.
[0039] In a possible implementation, the transaction processing method further includes: receiving a snapshot obtaining request from the read node, the snapshot obtaining request containing a first CSN, the snapshot obtaining request being used to request a third CSN, the third CSN being a snapshot corresponding to the snapshot obtaining request; extracting a second transaction state from the circular array according to the first CSN and the third CSN, to accelerate synchronization of the transaction state stored in the circular array to the read node, the second transaction state including at least one third mapping relationship, the CSN in each third mapping relationship being greater than the first CSN and not greater than the third CSN; and sending the second transaction state to the read node.
[0040] In the possible implementation, the circular array can be understood as a storage space, and the read node actively sends a snapshot obtaining request to the target node, which can accelerate the speed of the read node pulling the incremental data in the circular array. In this way, the target node can speed up the space recycling of the circular array, which is conducive to the storage of new transaction states in the circular array, and can also reduce the pulling amount of the incremental transaction states corresponding to subsequent read requests.
[0041] In a possible implementation, the transaction processing method further includes: updating the transaction state in the circular array.
[0042] In the possible implementation, after the target node synchronizes the transaction state in the circular array to each read node, the original transaction state can be deleted to free the circular array for storing new transaction states, thereby improving the utilization rate of the circular array.
[0043] The third aspect of the present application provides a transaction processing apparatus, comprising:
[0044] The transceiver unit is configured to receive a first read request and a corresponding first commit sequence number CSN, and the first CSN is a snapshot corresponding to the first read request.
[0045] The transceiver unit is configured to pull, from the target node, a first transaction state corresponding to a CSN in an interval between the first CSN and a second CSN, wherein the second CSN is a snapshot corresponding to a second read request, the second read request is adjacent to the first read request in terms of receiving time sequence or processing time sequence, and the second read request is before the first read request, and the first transaction state includes at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, and a value is a transaction identifier xid, the CSN in each first mapping relationship is greater than the second CSN and is not greater than the first CSN.
[0046] The processing unit is configured to read at least one first data record according to the first read request, perform a visibility judgment according to the first CSN, the at least one first mapping relationship, and the first data record, and return a query result corresponding to the first read request according to a result of the visibility judgment.
[0047] In a possible implementation, the processing unit is configured to convert each first mapping relationship into a key-value pair with an xid as the key and a CSN as the value, convert a transaction identifier xmin representing an insertion transaction in the first data record into a commit sequence number xminCSN representing the insertion transaction according to the key-value pair with the xid and the CSN, and convert a transaction identifier xmax representing a deletion transaction in the first data record into a commit sequence number xmaxCSN representing the deletion transaction, and the read node performs a visibility judgment according to the first CSN, the xminCSN and the xmaxCSN in the first data record.
[0048] In a possible implementation, if xminCSN in the first data record is less than or equal to the first CSN and xmaxCSN is greater than the first CSN, the first data record is visible.
[0049] In a possible implementation, the transceiver is further configured to receive a target xid from the write node, where the target xid is used to indicate that data records with xmin greater than or equal to the target xid in the data records of the write node are in a frozen state, and delete, from the hash table, key-value pairs with xid greater than or equal to the target xid.
[0050] In a possible implementation, the processing unit is further configured to determine, when the first transaction state further includes at least one second mapping relationship, that a key in each second mapping relationship is a rollback sequence number RSN and a value is a transaction identifier xid, and correspondingly, the hash table further includes a key-value pair with the key being the xid and the value being the RSN, and determine, when xmin in the target data record is not found in the key-value pair with the xid and the CSN but xmin corresponding to the xminRSN is found in the key-value pair with the xid and the RSN, that the target data record is a rolled-back record, and the target data record is included in the at least one first data record.
[0051] In a possible implementation, the transceiver is further configured to send, to the target node, a snapshot acquisition request, where the snapshot acquisition request includes the first CSN, the snapshot acquisition request is used to request a third CSN, the third CSN is a snapshot corresponding to the snapshot acquisition request, the first CSN and the third CSN are used by the target node to extract a second transaction state from the circular array, to accelerate synchronization of the transaction state stored in the circular array to the read node, and the second transaction state includes at least one third mapping relationship, a CSN in each third mapping relationship is greater than the first CSN and less than or equal to the third CSN, and receive the second transaction state from the target node.
[0052] The fourth aspect of the present application provides a transaction processing apparatus, comprising:
[0053] The transceiver is configured to receive a transaction state acquisition request sent by the read node, where the transaction state acquisition request includes a first CSN and a second CSN, the first CSN is a snapshot corresponding to a first read request, the second CSN is a snapshot corresponding to a second read request, the second read request is adjacent to the first read request in terms of receiving sequence or processing sequence, and the second read request is before the first read request;
[0054] The processing unit is configured to acquire a corresponding first transaction state according to the first CSN and the second CSN, where the first transaction state includes at least one first mapping relationship, a key in each first mapping relationship is a CSN, and a value is a transaction identifier xid, a CSN in each first mapping relationship is greater than the second CSN and less than or equal to the first CSN.
[0055] The transceiver is further configured to send, to the read node, a first transaction state, the first transaction state being used by the read node to perform visibility judgment on at least one first data record corresponding to the first read request.
[0056] In a possible implementation, the processing unit is further configured to obtain a commit sequence number (CSN) obtaining request initiated by the write node, the CSN obtaining request containing a first transaction identifier (xid); assign a target CSN to the CSN obtaining request, and write a mapping relationship between the target CSN and the first xid into the circular array.
[0057] In a possible implementation, the transceiver is further configured to receive, from the read node, a snapshot obtaining request, the snapshot obtaining request containing a first CSN, the snapshot obtaining request being used to request a third CSN, the third CSN being a snapshot corresponding to the snapshot obtaining request.
[0058] The processing unit is further configured to extract, from the circular array, a second transaction state according to the first CSN and the third CSN, to accelerate synchronization of transaction states stored in the circular array to the read node, the second transaction state including at least one third mapping relationship, a CSN in each third mapping relationship being greater than the first CSN and not greater than the third CSN.
[0059] The transceiver is further configured to send, to the read node, a second transaction state.
[0060] In a possible implementation, the processing unit is further configured to update the transaction state in the circular array.
[0061] In a fifth aspect, the present application provides a transaction processing apparatus. The apparatus can include at least one processor, a memory, and a communication interface. The processor is coupled to the memory and the communication interface. The memory is configured to store instructions, the processor is configured to execute the instructions, and the communication interface is configured to communicate with other apparatuses under control of the processor. The instructions, when executed by the processor, cause the processor to perform the method in the first aspect or any possible implementation of the first aspect.
[0062] In a sixth aspect, the present application provides a transaction processing apparatus. The apparatus can include at least one processor, a memory, and a communication interface. The processor is coupled to the memory and the communication interface. The memory is configured to store instructions, the processor is configured to execute the instructions, and the communication interface is configured to communicate with other apparatuses under control of the processor. The instructions, when executed by the processor, cause the processor to perform the method in the second aspect or any possible implementation of the second aspect.
[0063] In a seventh aspect, the present application provides a computer-readable storage medium storing one or more computer-executable instructions that, when executed by a processor, cause the processor to perform the method in the first aspect or any possible implementation of the first aspect.
[0064] The eighth aspect of the present application provides a computer readable storage medium storing one or more computer-executable instructions that, when executed by a processor, cause the processor to perform the method according to the second aspect or any possible implementation of the second aspect.
[0065] The ninth aspect of the present application provides a computer program product storing one or more computer-executable instructions that, when executed by a processor, cause the processor to perform the method according to the first aspect or any possible implementation of the first aspect.
[0066] The tenth aspect of the present application provides a computer program product storing one or more computer-executable instructions that, when executed by a processor, cause the processor to perform the method according to the second aspect or any possible implementation of the second aspect.
[0067] The eleventh aspect of the present application provides a chip system, which includes a processor for supporting a computer device to implement the functions involved in the first aspect or any possible implementation of the first aspect. In a possible design, the chip system can further include a memory for storing necessary program instructions and data. The chip system can be composed of a chip, or can include the chip and other discrete devices.
[0068] The twelfth aspect of the present application provides a chip system, which includes a processor for supporting a computer device to implement the functions involved in the second aspect or any possible implementation of the second aspect. In a possible design, the chip system can further include a memory for storing necessary program instructions and data. The chip system can be composed of a chip, or can include the chip and other discrete devices.
[0069] The thirteenth aspect of the present application provides a database system, which includes a read node and a target node. The read node is configured to perform the method according to the first aspect or any possible implementation of the first aspect. The target node is configured to perform the method according to the second aspect or any possible implementation of the second aspect. The target node can be a GTM, a write node or a CF.
[0070] The technical effects brought by the third aspect or any possible implementation of the third aspect, the fifth aspect, the seventh aspect, the ninth aspect, the eleventh aspect or the thirteenth aspect can refer to the technical effects brought by the first aspect or any possible implementation of the first aspect, which will not be repeated here.
[0071] The technical effects brought by the fourth aspect or any possible implementation manner of the fourth aspect, the sixth aspect, the eighth aspect, the tenth aspect, the twelfth aspect, or the thirteenth aspect can refer to the technical effects brought by the second aspect or different possible implementation manners of the second aspect, which will not be described here. BRIEF DESCRIPTION OF DRAWINGS
[0072] FIG. 1A is a schematic diagram of an architecture of a database system;
[0073] FIG. 1B is another schematic diagram of an architecture of a database system provided by an embodiment of the present application;
[0074] FIG. 1C is another schematic diagram of an architecture of a database system provided by an embodiment of the present application;
[0075] FIG. 1D is another schematic diagram of an architecture of a database system provided by an embodiment of the present application;
[0076] FIG. 2 is a schematic diagram of an embodiment of a transaction processing method provided by an embodiment of the present application;
[0077] FIG. 3 is a schematic diagram of an example of a snapshot of a database system provided by an embodiment of the present application;
[0078] FIG. 4 is a schematic diagram of an example of a data record provided by an embodiment of the present application;
[0079] FIG. 5 is a schematic diagram of another embodiment of a transaction processing method provided by an embodiment of the present application;
[0080] FIG. 6 is a schematic diagram of another embodiment of a transaction processing method provided by an embodiment of the present application;
[0081] FIG. 7 is a schematic diagram of another embodiment of a transaction processing method provided by an embodiment of the present application;
[0082] FIG. 8 is a schematic diagram of another embodiment of a transaction processing method provided by an embodiment of the present application;
[0083] FIG. 9 is a schematic diagram of another embodiment of a transaction processing method provided by an embodiment of the present application;
[0084] FIG. 10 is a schematic diagram of a structure of a transaction processing apparatus provided by an embodiment of the present application;
[0085] FIG. 11 is a schematic diagram of another structure of a transaction processing apparatus provided by an embodiment of the present application;
[0086] FIG. 12 is a schematic diagram of another structure of a transaction processing apparatus provided by an embodiment of the present application;
[0087] FIG. 13 is a schematic diagram of another structure of a database system provided by an embodiment of the present application. DETAILED DESCRIPTION
[0088] The embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. As those skilled in the art will understand, with the development of technology and the emergence of new scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0089] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0090] This application provides a transaction processing method in a database system to reduce the performance overhead of processing read transactions and improve the performance of processing read transactions. This application also provides corresponding apparatus, computer-readable storage media, computer program products, and database systems. These will be described in detail below.
[0091] For ease of understanding, the technical terms involved in the embodiments of this application are briefly introduced below:
[0092] 1. Transaction: A transaction is a sequence of database operations, consisting of a batch of operations executed between the start and commit points of the transaction. These operations either all succeed or all fail; no intermediate states are allowed, and it is an indivisible unit of work. Specifically, transactions must satisfy the semantics of atomicity, consistency, isolation, and durability, also known as ACID semantics.
[0093] 2. Atomicity: Atomicity means that during the same business process, a transaction guarantees that modifications to multiple data will either succeed simultaneously or be rolled back simultaneously.
[0094] 3. Consistency: Consistency means that the database must be in the correct state before and after a transaction is executed, satisfying integrity constraints.
[0095] 4. Isolation: Isolation means that in different business processes, transactions ensure that the data being read and written by each business is independent and will not affect each other.
[0096] 5. Durability: Durability means that a transaction should ensure that all successfully committed data modifications are correctly persisted and that no data is lost.
[0097] 6. Transaction Commit: Transaction commit refers to the process of submitting a transaction to the data storage after it has been executed. When a transaction starts or is generated, the database system will assign a transaction identifier xid to the transaction. After the transaction is committed, a transaction commit sequence number (commitseqNo, CSN) will be assigned to the transaction. xid and CSN can be referred to as transaction status.
[0098] 7. Distributed Transaction: A distributed transaction refers to a transaction initiated by a user on a distributed data processing system (distributed database system).
[0099] 8. Distributed Transaction Processing System: A distributed system that provides database transaction processing capabilities and meets the ACID semantic requirements of transactions. Typical examples include: Online Transaction Processing (OLTP) database systems and Online Analytical Processing (OLAP) database systems.
[0100] 9. Database System: The database system may include one or more read datanodes (readDNs) and one or more write datanodes (writeDNs). The database system may also include one or two global transaction managers (GTMs). If there are two GTMs, one is the primary GTM and the other is the standby GTM. The database system may also include a coordinator node (CN); alternatively, the database system may not include GTMs and CNs, but instead include a cluster caching facility / cluster facility (CF). Of course, the database system may also include other nodes, which are not limited in this application.
[0101] 10. Write node: In a database system, the node responsible for handling write transactions (insert, delete, and modify operations on records).
[0102] 11. Read node: In a database system, the node responsible for handling read transactions (queries of records); read nodes and write nodes may be the same node or independent nodes. Read-write separation technology can be used to make write nodes handle write transactions and read nodes handle read transactions.
[0103] 12. Transaction state in a broad sense: Transaction state in a broad sense refers to the state of all transactions (completed transactions and transactions in progress) in the database system at a certain moment, including: active, failed, partially committed, committed, rolled back, and completed.
[0104] 13. Narrowly Defined Transaction State: In the context of Multi-Version Concurrency Control (MVCC), the narrow definition of transaction state refers to a simplified and customized version of the broader transaction state used in Multi-Version Concurrency Control (MVCC) technology. This version simplifies and customizes the broader concept of transaction state to determine the visibility of different versions of data records (tuples) generated by a transaction. This transaction state acts as the "eyes" for judging the visibility of each version of a record. For example, the mapping relationship between xid and CSN can be understood as a type of transaction state within this narrow definition. The transaction state in this application primarily refers to this narrow definition. The transaction state in this application is typically stored in the GTM (Generic Transaction Manager), but it may also be stored in the write node or the CF (Consciousness Provider).
[0105] 14. MVCC: MVCC is a transaction processing technique that sets multiple versions of data records and uses the transaction state as "eyes" to determine the visibility of each version of the data record when processing read transactions.
[0106] 15. Transaction state synchronization: When a database system processes a read transaction, in order to satisfy the Isolation semantics and level, it needs to obtain the transaction state to determine the visibility of the read data record, thus generating the need for transaction state synchronization, that is, to synchronize the transaction state from the GTM, write node or CF to the read node.
[0107] 16. Snapshot: A snapshot refers to the maximum CSN in the database system when a read request is received. The maximum CSN corresponding to read requests arriving at the database system at different times is usually different.
[0108] 17. Write request: This refers to writing the structured query language (SQL) corresponding to the transaction, which is used to request that the corresponding data be written to the database system.
[0109] 18. Read request: refers to the SQL corresponding to a read transaction, used to request and query the corresponding data in the database system.
[0110] The method provided in this application embodiment can be applied to a database system. Figure 1A shows a typical logical architecture of a database system. According to Figure 1A, the database system 100 includes a database 110 and a database management system (DBMS) 130.
[0111] Database 110 is an organized collection of data stored in data storage 120; that is, a related collection of data organized, stored, and used according to a specific data model. Depending on the data model used to organize the data, the data can be divided into various types, such as relational data, graph data, and time series data. Relational data is data modeled using a relational model, usually represented as a table, where rows represent a set of related values for an object or entity. Graph data, simply called a "graph," is used to represent relationships between objects or entities, such as social relationships. Time series data is a series of data columns recorded and indexed in chronological order, used to describe the state changes of an object over time.
[0112] The database management system 130 is the core of the database system, serving as system software for organizing, storing, and maintaining data. Clients 200 can access the database 110 through the database management system 130, and database administrators also use the database management system for database maintenance. The database management system 130 provides various functions for clients 200 to create, modify, and query the database; clients 200 can be applications or user devices. The functions provided by the database management system 130 may include, but are not limited to, the following: (1) Data definition function: The database management system 130 provides a data definition language (DDL) to define the structure of the database 110. The DDL is used to describe the database framework and can be stored in the data dictionary; (2) Data access function: The database management system 130 provides a data manipulation language (DML) to implement basic access operations on the database 110, such as retrieval, insertion, modification and deletion; (3) Database operation management function: The database management system 130 provides data control function to effectively control and manage the operation of the database 110 to ensure that the data is correct and valid; (4) Database creation and maintenance function: including loading the initial data of the database, database dumping, recovery, reorganization, system performance monitoring and analysis, etc.; (5) Database transmission: The database management system provides data transmission to realize communication between the client and the database management system, which is usually coordinated with the operating system.
[0113] Data storage 120 includes, but is not limited to, solid-state drives (SSDs), disk arrays, cloud storage, or other types of non-transient computer-readable storage media. Those skilled in the art will understand that a database system may include fewer or more components than those shown in FIG. 1A, or may include components different from those shown in FIG. 1A, which merely illustrates components more relevant to the implementation disclosed in the embodiments of the present invention.
[0114] The database system provided in this application embodiment can be a distributed database system (DDBS). In order to achieve concurrency control between transactions during transaction processing, DDBS typically uses a global transaction manager (GTM) to manage transactions. DDBS is described below with reference to Figure 1B.
[0115] Figure 1B is a schematic diagram of a distributed database system using a shared-storage architecture, including one or more coordinator nodes (CNs), multiple read nodes (readDNs), multiple write nodes (writeDNs), and one or more Group Managers (GTMs) (as shown in Figure 1B: the first GTM and the second GTM). The first GTM acts as the master GTM, and the second GTM is used to back up the data of the first GTM and take over the work of the first GTM when it fails, thus ensuring the high reliability of DDBS. The multiple read nodes and multiple write nodes can have a one-to-one relationship, a many-to-one relationship, or an M-to-N relationship (i.e., a many-to-many relationship). The CN communicates with the readDNs and writeDNs through a network channel. In one embodiment, this network channel can be composed of network devices such as switches, routers, and gateways. The CNs, readDNs, writeDNs, and GTMs together implement the functions of the database management system, providing clients with services such as database retrieval, insertion, modification, and deletion.
[0116] In one embodiment, a database management system is deployed on each CN, readDN, writeDN, and GTM. Shared memory and a shared data storage store data that can be shared by multiple readDNs and writeDNs. The readDNs and writeDNs can perform read and write operations on the data in the data storage via a network channel. The shared data storage can be a shared disk array. In the distributed database system, the CN, readDN, writeDN, first GTM, or second GTM can be physical machines, such as database servers, or virtual machines (VMs) or containers running on abstract hardware resources. In one embodiment, the CN, readDN, writeDN, first GTM, or second GTM are virtual machines or containers, and the network channel is a virtual switching network, which includes virtual switches. The database management system deployed in the CN, DN, first GTM, or second GTM is a DBMS instance, which can be a process or a thread. These DBMSs work together to complete the functions of a database relational system. In another embodiment, CN, readDN, writeDN, the first GTM or the second GTM are physical machines, and the network channel includes one or more switches, which are storage area network (SAN) switches, Ethernet switches, fiber optic switches or other physical switching devices.
[0117] In all embodiments of this application, the data storage of the database system includes, but is not limited to, solid-state drives (SSDs), disk arrays, or other types of non-transient computer-readable media. Although a database is not shown in Figure 1B, it should be understood that the database is stored in data storage. Those skilled in the art will understand that a database system may include fewer or more components than those shown in Figures 1A and 1B, or may include components different from those shown in Figures 1A and 1B, which merely show components more relevant to the implementation disclosed in the embodiments of this application. However, those skilled in the art will understand that a distributed database system may contain any number of CNs, readDNs, and writeDNs. The database management system functions of each CN, readDN, and writeDN can be implemented by appropriate combinations of software, hardware, and / or firmware running on each CN, readDN, and writeDN.
[0118] The distributed database system described in Figure 1B above includes multiple readDNs, multiple writeDNs, and multiple CNs. The functions of each readDN or each writeDN are basically the same, and the functions of each CN are also basically the same.
[0119] Additionally, it should be noted that if the write node can store a large amount of data, the shared data storage in Figure 1B above can be removed, and the write node can store the data records generated by the transaction.
[0120] Additionally, it should be noted that the solution provided in this application embodiment can also be applied to architectures excluding CN and GTM. As shown in Figure 1C, this database system may include read nodes, write nodes, shared memory, and shared storage. One write node can correspond to multiple read nodes, or multiple write nodes can correspond to multiple read nodes. Shared storage refers to storage resources other than shared memory. Read nodes and write nodes can read and write data in shared memory and shared storage through network channels.
[0121] The solution provided in this application embodiment can also be applied to the architecture shown in Figure 1D. As shown in Figure 1D, the database system may include read nodes, write nodes, a central functional component (CF), shared memory, and shared storage. The CF can coordinate requests between read nodes and write nodes, and the function of the CF is equivalent to CN+GTM. Read nodes and write nodes can read and write data in shared memory and shared storage through network channels.
[0122] Based on the aforementioned database system, referring to Figure 2, the transaction processing method provided in this embodiment includes:
[0123] 201. The read node receives the first read request and the corresponding first CSN. The first CSN is the snapshot corresponding to the first read request.
[0124] The snapshot of the first read request can be understood by referring to Figure 3. As shown in Figure 3, a transaction is assigned a transaction identifier (xid) when it is generated. For example, the xids of TX1, TX2, ..., TX8 are 1, 2, ..., 8, respectively. The CSN is the transaction commit sequence number, which is assigned when the transaction is committed. Because the execution time of transactions varies, transactions generated earlier are not necessarily committed earlier. In Figure 3, TX1 is the first transaction generated and the first transaction committed in the system, so its CSN is 1; TX2 is the second transaction generated but the fourth transaction committed, so its CSN is 4; TX3 is the third transaction generated but the second transaction committed, so its CSN is 2; TX5 is the fifth transaction generated but the third transaction committed, so its CSN is 3; and so on. From Figure 3, the CSNs of TX4, TX6, TX7, and TX8 can be determined. If the database system receives the first read request at the location of snapshot indicator line 301 in Figure 3, it can be determined that the first CSN = 3, which is the maximum CSN of committed transactions in the database system at this time.
[0125] 202. The read node sends a transaction status retrieval request to the target node. Correspondingly, the target node receives the transaction status retrieval request from the read node. The transaction status retrieval request includes the first CSN and the second CSN.
[0126] Here, the second CSN is the snapshot corresponding to the second read request. The second read request is adjacent to the first read request in terms of reception or processing timing, and the second read request precedes the first read request. If the first read request is the read request received or processed by the Mth read node, then the second read request is the read request processed by the (M-1)th read node, where M > 1 and M is an integer. If the first CSN is represented by reqCSN, the second CSN can be represented by last reqCSN.
[0127] In this application, the target node can be a GTM, a write node, or a CF.
[0128] 203. The target node obtains the corresponding first transaction status based on the first CSN and the second CSN.
[0129] The first transaction state includes at least one first mapping relationship, wherein the key in each first mapping relationship is CSN and the value is the transaction identifier xid. The CSN in each first mapping relationship is greater than the second CSN and not greater than the first CSN.
[0130] In this application, the first mapping relationship can be used<CSN,xid> Represented in the form of .
[0131] The fetch range (last reqCSN, reqCSN) can be determined by the first CSN and the second CSN. Then, using this fetch range, the saved data can be queried.<CSN,xid> A list, with each CSN in (last reqCSN, reqCSN) as the key, can be used to retrieve one or more CSNs corresponding to (last reqCSN, reqCSN) from the list.<CSN,xid> This refers to the first transaction state.
[0132] 204. The target node sends the first transaction status to the read node. Correspondingly, the read node receives the first transaction status from the target node.
[0133] Optionally, if the first CSN is the same as the second CSN, it means that there is no new transaction state in the database system. In this case, the read node receives a prompt message from the target node, which indicates that there is no incremental transaction state in the target node. Then the read node can use the previously pulled mapping relationship and the first CSN to make a visibility judgment on the first data record.
[0134] It should be noted that steps 202 and 204 above can also be understood as the process by which the read node pulls the first transaction state corresponding to the CSN in the interval between the first CSN and the second CSN from the target node.
[0135] 205. The read node reads at least one first data record based on the first read request.
[0136] In this application, at least one first data record may be a data record associated with some identifiers in the read request, such as a data record associated with a bank card number, or time information associated with the read request.
[0137] A single data record can have one or more versions. The database system can assign a version stamp to each version, and the same data (such as a single data record) in different versions are linked together by pointers, forming a version linked list. A read transaction can follow this linked list and read the required version of the data based on the transaction status data. Figure 4 can be used to understand the representation of the first data record and its different versions.
[0138] As shown in Figure 4, there are three data records, denoted by 1), 2), and 3). 1) is the first inserted data record; 2) is the data record updated once based on 1); and 3) is the data record updated based on 2). These three data records are described below:
[0139] 1) This indicates the format of a data record when it is first inserted. Here, xmin = 10 indicates that the transaction ID for inserting the data record is 10, xmax = 0 indicates that the data record has not been deleted, ctid = (0, 1) indicates that the record is the first data record on the page with page ID 0, and the data is value1.
[0140] 2) This indicates that the data record has been updated once, generating a new data record. This new data record has two versions.
[0141] In the first version, xmin = 10, indicating that the transaction ID for inserting the data record of this version is 10; xmax = 12, indicating that the transaction ID for deleting the data record of this version is 12; ctid = (0, 2) indicates that the data record of this version is the second data record on the page with page ID 0; and data = value1.
[0142] In the second version, xmin = 12, indicating that the transaction ID for inserting the data record in this version is 12; xmax = 0, indicating that the data record in this version has not been deleted; ctid = (0, 2), indicating that the data record in this version is the second data record on the page with page ID 0; and data = value2.
[0143] 3) indicates a data record that was updated based on 2). This new data record has three versions.
[0144] In the first version, xmin = 10, indicating that the transaction ID for inserting the data record of this version is 10; xmax = 12, indicating that the transaction ID for deleting the data record of this version is 12; ctid = (0, 2) indicates that the data record of this version is the second data record on the page with page ID 0; and data = value1.
[0145] In the second version, xmin=12 indicates that the transaction ID for inserting the data record of this version is 12, xmax=15 indicates that the transaction ID for deleting the data record of this version is 15, ctid is (1,1) indicates that the data record of this version is the first data record on the page with page ID 1, and data is value2.
[0146] In the second version, xmin=15 indicates that the transaction ID for inserting the data record in this version is 15, xmax=0 indicates that the data record in this version has not been deleted, ctid is (1,1) indicates that the data record in this version is the first data record on the page with page ID 1, and data is value3.
[0147] 206. The read node performs a visibility determination based on the first CSN, at least one first mapping relationship, and the first data record.
[0148] In this application, the read node can utilize<CSN,xid> Determine the CSN corresponding to xid(xmin, xmax) in the first data record, and then use the relationship between the corresponding CSN and the first CSN to determine whether each data record meets the visibility requirement. Visibility indicates data records that have been committed but not yet deleted.
[0149] 207. The read node returns the query result corresponding to the first read request based on the visibility determination result.
[0150] In this application, the query result can be the first data record that is visible to the first read request. If there is no visible first data record, the query result can be returned indicating that there is no first data record corresponding to the first read request.
[0151] The solution provided in this application embodiment allows the read node to retrieve the first transaction state using both the first and second CSNs when processing read requests, since the first transaction state stored in the target node is set to CSN as the key and xid as the value. Furthermore, the first transaction state of the read node is an incremental transaction state where CSN is greater than the second CSN and less than or equal to the first CSN. This eliminates the need for the target node to synchronize the full transaction state to the read node, reducing the amount of data to be synchronized, lowering the performance overhead of reading transactions, and improving the performance of reading transactions.
[0152] Optionally, step 206 above can be:
[0153] The read node saves each first mapping relationship into a hash table in the format of key-value pairs with key as xid and value as CSN; the read node converts the transaction identifier xmin representing the insertion transaction in the first data record to xminCSN, and the transaction identifier xmax representing the deletion transaction to xmaxCSN, based on the key-value pairs xid and CSN in the hash table.
[0154] The read node determines visibility based on the first CSN, xminCSN, and xmaxCSN in the first data record.
[0155] If xminCSN ≤ first CSN and xmaxCSN > first CSN in the first data record, then the first data record is visible; otherwise, the first data record is not visible.
[0156] In this embodiment, because the first data record stores the transaction identifier (xmin) for inserting the record and the transaction identifier (xmax) for deleting the record, the key used for visibility determination is xid. Therefore, after obtaining the first mapping relationship, the read node will...<CSN,xid> according to<xid,CSN> The key-value pair format is maintained in a hash table. When performing visibility checks, only the xmin and xmax values from the first data record need to be considered, combined with the values in the hash table.<xid,CSN> The corresponding xminCSN and xmaxCSN are then derived. These can be compared with the first CSN to determine the visibility assessment result. This demonstrates that the read node can flexibly adjust the first mapping relationship.<CSN,xid> The storage format in the read node improves the speed of subsequent visibility determination.
[0157] The transaction processing process provided by the embodiments of this application has been described above from the perspective of the read node and the target node. The transaction processing method provided by the embodiments of this application is described below based on database systems with different structures.
[0158] Based on the database system shown in 1B above, as shown in Figure 5, the write transaction processing process of the transaction processing method provided in this application embodiment includes:
[0159] 501.CN receives write requests from clients.
[0160] When a client starts a write transaction, it may initiate one or more write requests, each of which is a write SQL statement.
[0161] 502.CN assigns a write node to a write request. Correspondingly, the write node receives the write request.
[0162] CN can parse each SQL statement and determine the corresponding write node (writeDN) for each SQL statement, so that the write node can execute the write request.
[0163] 503. The write node assigns a transaction identifier to the write transaction corresponding to the write request.
[0164] In this embodiment of the application, the transaction identifier assigned to the write transaction is represented by xid1.
[0165] 504. The write node sends a CSN retrieval request to the GTM, which includes xid1. Correspondingly, the GTM receives the CSN retrieval request.
[0166] 505.GTM allocates CSN1 for this write transaction and...<CSN1,xid1> Write it to a circular array.
[0167] <CSN1,xid1>This represents a mapping relationship with CSN1 as the key and xid1 as the value.
[0168] 506.GTM returns CSN1 to the write node. Correspondingly, the write node receives CSN1.
[0169] 507. Write the node to commit the transaction.
[0170] In this embodiment of the application, GTM can synchronously store the mapping relationship between CSN1 and xid1 when allocating CSN to the write node. In this way, when processing read transactions, the read node can directly obtain the mapping relationship between CSN1 and xid1 to process the read transaction, thereby improving the performance of processing read transactions.
[0171] In the embodiment corresponding to Figure 5 above, the xid is allocated by the write node. In fact, the xid can also be allocated by the GTM. If the xid is also allocated by the GTM, then the write transaction processing procedure can be:
[0172] The client initiates a write transaction by sending a batch of write SQL statements to the CN. Before processing the write SQL statements, the CN sends an `xid getxid` request to the GTM to create an `xid` for the write transaction. This `xid` will be written to every record inserted or modified by the write transaction. For each write SQL statement, the CN parses and converts it into a write request, which is then sent to the corresponding `writeDN`. The `writeDN` executes the write request. If, after all write SQL statements have been processed, the client sends a transaction commit command to the CN, the write transaction commit process begins. The CN first sends a `prepare` command to each `writeDN` participating in the write transaction, pre-committing the write transaction on each `writeDN`. After all `writeDNs` have pre-committed the write transaction, the CN sends a `CSN getCSN` request to the GTM, including the `xid` in the request. Upon receiving the `CSN getCSN` request, the GTM allocates a new `CSN` for the write transaction (using `CSN++`) and establishes the mapping relationship between the newly allocated `CSN` and the `xid`.<CSN,Xid> The data is written to a circular array. After obtaining the CSN through the CSN acquisition request, the CN sends a transaction commit command to each WriteDN participating in the write transaction and performs the final commit operation.
[0173] In summary, regardless of the write transaction processing flow executed, GTM can establish...<CSN,Xid> The mapping relationship is used for subsequent read transaction processing. The read transaction processing flow of the database system based on Figure 1B is introduced below.
[0174] As shown in Figure 6, the transaction processing method provided in this embodiment includes:
[0175] 601.CN receives the first read request from the client.
[0176] The first read request is the read SQL corresponding to the read transaction. A read transaction can have one or more read SQL statements.
[0177] 602.CN sends a snapshot request to GTM to obtain the first CSN corresponding to the first read request.
[0178] The first CSN is the maximum CSN of the database system corresponding to the first read request. The first CSN can be represented by reqCSN.
[0179] 603.CN sends the first read request and the first CSN to the read node. Correspondingly, the read node receives the first read request and the first CSN.
[0180] The CN can first parse the first read request, determine the corresponding read node for the first read request, and then send the first read request to the read node. The first CSN can be sent in the first read request, or the first read request and the first CSN can be sent independently.
[0181] 604. The read node sends a transaction status retrieval request to the CTM. Correspondingly, the GTM receives the transaction status retrieval request from the read node. The transaction status retrieval request includes the first CSN and the second CSN.
[0182] The second CSN is the snapshot corresponding to the second read request, which is the read request preceding the first read request. The second CSN can be represented by last reqCSN. The first and second CSNs in the transaction status retrieval request can be represented as (second CSN, first CSN), which is (lastreqCSN, reqCSN).
[0183] 605.GTM pulls the first transaction state from the circular array based on (second CSN, first CSN).
[0184] The first transaction state<CSN,xid> The CSN in the first case is greater than the second CSN, i.e., greater than lastreqCSN, and not greater than (less than or equal to) the first CSN, i.e., reqCSN.
[0185] For example: if lastreqCSN = 2, reqCSN = 4, and the circular array includes five first mapping relationships, as shown in Table 1:
[0186] Table 1: Circular Arrays<CSN,xid>
[0187] As shown in Table 1, the first mapping relationship between CSN=3 and CSN=4 can be found by using the value range of CSN (2, 4], which are <3, 5> and <4, 1> respectively. That is, the first transaction state includes <3, 5> and <4, 1>.
[0188] 606.GTM sends the first transaction status to the read node. Correspondingly, the read node receives the first transaction status.
[0189] 607. Read node will<CSN,xid> Store the data in the hash table and read the first data record.
[0190] The structure of a hash table can also be represented by Table 2:
[0191] Table 2: Hash Table<xid,CSN>
[0192] There can be one or more first data records. This first data record can be retrieved by the read node from the write node or from the data storage based on a first read request.
[0193] 608. Read node based on hash table<xid,CSN> The transaction identifier xmin representing the insertion transaction in the first data record is converted to xminCSN, and the transaction identifier xmax representing the deletion transaction is converted to xmaxCSN.
[0194] The format of the first data record can be understood by referring to the example in Figure 3 above. Here, xmin represents the transaction identifier xid for inserting the first data record, and xmax represents the transaction identifier xid for deleting the first data record.
[0195] Using xmin as the key, the corresponding CSN can be found using Table 2. The CSN corresponding to xmin can be represented as xminCSN; using xmax as the key, the corresponding CSN can be found using Table 2. The CSN corresponding to xmax can be represented as xmaxCSN.
[0196] 609. The read node determines visibility based on the first CSN, xminCSN and xmaxCSN in the first data record.
[0197] If the first data record has two entries, where:
[0198] The first data record has xmin = 2 and xmax = 5; that is, this record was created by the write transaction with xid = 2 and deleted by the write transaction with xid = 5.
[0199] The second data record has xmin = 2 and xmax = 6; that is, this record was created by the write transaction with xid = 2 and deleted by the write transaction with xid = 6.
[0200] After converting the xmin and xmax values of the first and second data records into xminCSN and xmaxCSN, if:
[0201] The first data record: xminCSN is 1, xmaxCSN is 3, that is: based on xmin=2, the corresponding CSN=1 is determined, and based on xmax=5, the corresponding CSN=3 is determined.
[0202] The second data record shows that xminCSN is 1 and xmaxCSN is unknown. This means that the corresponding CSN is 1 based on xmin=2, but no corresponding CSN can be found for xmax=6. This indicates that the write transaction corresponding to xmax=6 is still in progress and has not been committed.
[0203] Given that the first CSN = 4, a visibility check is performed on the first data record. `xminCSN = 1 < 4`, meaning `xminCSN < first CSN`, indicating that the first data record has been committed. However, `xmaxCSN = 3 < 4`, meaning `xmaxCSN < first CSN`, indicating that the first data record was deleted when the first read request reached the database system. Therefore, the first data record is not visible.
[0204] Given that the first CSN = 4, we perform a visibility check on the second data record. xminCSN = 1 < 4, meaning xminCSN < the first CSN; this indicates that the second data record has been committed. Furthermore, xmaxCSN is unknown, indicating that the second data record has not been deleted. Therefore, the second data record is visible.
[0205] 610. The read node returns the query result corresponding to the first read request based on the visibility determination result.
[0206] In this application, the query result can be the second data record that is visible to the first read request, that is, the data corresponding to xmin=2 and xmax=6.
[0207] If no visible data record is identified through steps 602 to 609 above, a query result indicating that no first data record corresponding to the first read request exists can be returned.
[0208] As described above, the transaction processing method provided in this application embodiment can satisfy the three requirements of one-to-one synchronization, incremental synchronization, and synchronization only once, wherein:
[0209] One-to-one synchronization means that the read node only needs to retrieve the transaction status from the GTM.
[0210] Incremental synchronization refers to the fact that the read node only pulls the transaction state that is added between two read requests; the shorter the interval between two read requests, the less transaction state data is pulled, and the more efficient the transaction synchronization is.
[0211] One-time synchronization: This means that when processing a read transaction, the read node only needs to pull the transaction state once, which greatly improves the synchronization efficiency of the transaction state.
[0212] In addition, the transaction processing method provided in this application embodiment can also manage hash tables, identify rollback transactions, and manage circular arrays, which will be described below:
[0213] 1. Manage hash tables;
[0214] The management of hash tables by read nodes can be accomplished through collaboration between read and write nodes, as shown in Figure 7. This process may include:
[0215] 701. Write the node to determine the target xid.
[0216] To prevent transaction states from accumulating over time, write nodes select a target xid (oldestxid) during the vacuum operation and modify the xmin values of all data records whose xmin is less than or equal to the oldestxid to 2, or mark all data records whose xmin is less than or equal to the oldestxid with a freeze flag (xmin_FROZEN).
[0217] The target xid is used to indicate that data records in the write node whose xmin is not greater than (less than or equal to) the target xid are in a frozen state.
[0218] 702. The write node sends the target xid to the read node. Correspondingly, the read node receives the target xid from the write node.
[0219] 703. Read node deletes key-value pairs in the hash table whose xid is not greater than the target xid.
[0220] Taking target xid=3 as an example, if the hash table before processing is Table 2, then the hash table after processing can be understood by referring to Table 3.
[0221] Table 3: Hash Tables<xid,CSN>
[0222] A comparison of Tables 2 and 3 shows that when the target xid = 3, the two key-value pairs or correspondences in Table 2, <1, 4> for xid = 1 and <2, 1> for xid = 2, are deleted.
[0223] Of course, after deleting <1,4> and <2,1>, the positions of other key-value pairs in the hash table can be changed, or two columns that do not record data can be deleted. This application does not limit this.
[0224] In this embodiment, since the hash table is stored in memory, it will consume a lot of memory if there is too much data in the hash table. Data records in the write node that are in a frozen state will no longer be read. Therefore, the read node can promptly delete key-value pairs in the hash table that are not greater than the target xid based on the state of the data records in the write node, thereby cleaning up unused data, reducing memory consumption, and improving memory utilization.
[0225] 2. Identify rollback transactions;
[0226] In this embodiment of the application, the first transaction state described above may further include at least one second mapping relationship, wherein the key in each second mapping relationship is the rollback sequence number (RSN) and the value is the transaction identifier xid; correspondingly, the hash table also includes key-value pairs with the key xid and the value RSN;
[0227] If the xmin in the target data record cannot be found in the xid and CSN key-value pair with a corresponding xminCSN, but the xminRSN corresponding to xmin is found in the xid and RSN key-value pair with a corresponding xmin, then the read node determines that the target data record is a rolled-back record and that the target data record is contained in at least one first data record.
[0228] <xid,RSN> Can be with<xid,CSN> The RSN and CSN can be stored separately in different spaces, or different lengths can be used to distinguish them.
[0229] Therefore, the embodiments of this application not only provide a method for processing submitted transactions, but also use a second mapping relationship.<RSN,xid> It provides a way to handle rolled-back transactions; if a transaction has been rolled back, the corresponding transaction commit sequence number cannot be found. Therefore, read nodes can store it in a hash table.<xid,RSN> When performing visibility checks, if the xminCSN corresponding to xmin cannot be found, it can be done through...<xid,RSN> This allows us to find the corresponding xminRSN, thereby determining whether the target data record is a rollback record, thus enabling more comprehensive processing of transactions.
[0230] 3. Managing circular arrays;
[0231] The process of managing the circular array can be accomplished collaboratively by the read nodes and the GTM, as shown in Figure 8. This process includes:
[0232] 801. The read node sends a snapshot acquisition request to the GTM, the snapshot acquisition request containing the first CSN. Correspondingly, the GTM receives the snapshot acquisition request from the read node.
[0233] 802.GTM extracts the second transaction state from the circular array based on the first CSN and the third CSN to accelerate the synchronization of the transaction state stored in the circular array to the read nodes.
[0234] The second transaction state includes at least one third mapping relationship, where the CSN in each third mapping relationship is greater than the first CSN and not greater than the third CSN.
[0235] 803. GTM sends the second transaction status to the read node. Correspondingly, the read node receives the second transaction status from GTM.
[0236] 804.GTM updates the transaction status in the circular array.
[0237] After GTM synchronizes the transaction states of the first part of the circular array to each read node, it can delete those transaction states, freeing up space in the first part of the circular array to store new transaction states, thereby improving the utilization of the circular array.
[0238] For example, if the circular array is updated, you can refer to Table 4 for understanding.
[0239] Table 4: Circular Arrays<CSN,xid>
[0240] If the first CSN = 4 and the third CSN = 8, then the range to be pulled from the circular array is (4, 8]. The second transaction states then include <5, 3>, <6, 7>, <7, 6>, and <8, 9>. If each read node pulls the second transaction states from the circular array, the circular array can be updated, deleting the second transaction states from the array. After updating the circular array, only <9, 8> remains, freeing up considerable space to store new transactions.<CSN,xid> .
[0241] In this embodiment, the circular array can be understood as a storage space. The read node actively sends a snapshot retrieval request to the target node, which can accelerate the speed at which the read node pulls incremental data from the circular array. In this way, the read node can promote the reclamation of space in the circular array on the target node, which is beneficial for the circular array to store newly added transaction states. Furthermore, it can reduce the amount of incremental transaction states that need to be retrieved when subsequent read requests are received.
[0242] The above describes the transaction processing process in the database system based on Figure 1B. In the database system shown in Figure 1C, the GTM functions in Figures 2 to 8 can be integrated into the write nodes and executed by them. The differences in transaction processing between the database system architecture shown in Figure 1C and the scheme without this application, and the scheme using this application, can be understood by referring to Figure 9.
[0243] As shown in Figure 9, there are three main differences in transaction processing between the scheme not adopted in this application and the scheme adopted in this application, namely 901, 902 and 903.
[0244] Here, 901 represents the difference at the write node. Before adopting the scheme of this application, the write node was stored using an array.<xid,CSN> After adopting the scheme of this application, the write node uses a circular array to store the mapping relationship between CSN and xid.<CSN,xid> .
[0245] Here, 902 represents the difference at the read node. Before adopting the scheme of this application, the read node obtains the CSN from the write node based on the xid. After adopting the scheme of this application, the read node obtains the newly generated CSN between the two requests from the write node by querying the range (lastReqCSN, ReqCSN).<CSN,xid> Additionally, the read node will also receive the incremental data.<CSN,xid> Convert to<xid,CSN> The data is stored in a hash table in the form of [data type], and is used to perform the visibility determination process described earlier.
[0246] Here, 902 indicates a difference in data records. Before adopting the solution in this application, data records included both xid and CSN. This meant that whenever a user record without a CSN field was read, a request needed to be sent to the write node to retrieve the CSN, resulting in a large number of requests and significant latency. With the solution in this application, data records only need to include xid, simplifying the data storage structure.
[0247] In this embodiment, the user record may or may not have a CSN field. If the number of records modified by a transaction is small, the CSN will be written to the record upon transaction commit, resulting in a record with a CSN field. If the number of records modified by a transaction is large, for performance reasons during transaction commit, the CSN will not be written to the record, thus generating a user record without a CSN field.
[0248] Additionally, it should be noted that in the transaction processing process shown in Figure 1C above, the process originally executed by GTM is now executed by the write node. The steps executed by the read node can be understood by referring to the relevant content introduced in Figures 2 to 8 above.
[0249] In addition, under the architecture shown in Figure 1D, CF can perform the functions of GTM and CN as described in Figures 2 to 8. Therefore, the transaction processing based on Figure 1D can be understood by referring to the relevant content introduced in Figures 2 to 8, and will not be repeated here.
[0250] The above embodiments describe transaction processing methods in a database system. The transaction processing apparatus provided in the embodiments of this application is described below with reference to the accompanying drawings.
[0251] As shown in Figure 10, the transaction processing device 1000 provided in this embodiment can be the read node described above. The transaction processing device 1000 includes:
[0252] The transceiver unit 1001 is used to receive the first read request and the corresponding first commit sequence number (CSN), where the first CSN is the snapshot corresponding to the first read request.
[0253] The transceiver unit 1001 is used to pull the first transaction state corresponding to the CSN within the interval of the first CSN and the second CSN from the target node; wherein, the second CSN is a snapshot corresponding to the second read request, the second read request is adjacent to the first read request in the receiving time sequence or processing time sequence, and the second read request is before the first read request, the first transaction state includes at least one first mapping relationship, wherein the key in each first mapping relationship is CSN, the value is transaction identifier xid, and the CSN in each first mapping relationship is greater than the second CSN and not greater than the first CSN;
[0254] The processing unit 1002 is configured to read at least one first data record according to the first read request; and to perform a visibility determination based on the first CSN, at least one first mapping relationship and the first data record, and to return the query result corresponding to the first read request based on the result of the visibility determination.
[0255] The solution provided in this application embodiment allows the read node to retrieve the first transaction state using both the first and second CSNs when processing read requests, since the first transaction state stored in the target node is set to CSN as the key and xid as the value. Furthermore, the first transaction state of the read node is an incremental transaction state where CSN is greater than the second CSN and less than or equal to the first CSN. This eliminates the need for the target node to synchronize the full transaction state to the read node, reducing the amount of data to be synchronized, lowering the performance overhead of reading transactions, and improving the performance of reading transactions.
[0256] Optionally, the processing unit 1002 is used to convert each first mapping relationship into a key-value pair with an xid and a value of CSN; based on the key-value pair of xid and CSN, convert the transaction identifier xmin representing the insertion transaction in the first data record into xminCSN, and convert the transaction identifier xmax representing the deletion transaction into xmaxCSN; the read node performs visibility determination based on the first CSN, xminCSN and xmaxCSN in the first data record.
[0257] Optionally, if xminCSN ≤ first CSN and xmaxCSN > first CSN in the first data record, then the first data record is visible.
[0258] Optionally, the transceiver unit 1001 is also used to receive a target xid from the write node, the target xid being used to indicate that all data records in the write node whose xmin is not greater than the target xid are in a frozen state; and to delete key-value pairs in the hash table whose xid is not greater than the target xid.
[0259] Optionally, the processing unit 1002 is further configured to include at least one second mapping relationship in the first transaction state, wherein the key in each second mapping relationship is the rollback sequence number RSN and the value is the transaction identifier xid; correspondingly, the hash table also includes key-value pairs with the key xid and the value RSN; if the xmin in the target data record cannot find the corresponding xminCSN in the key-value pair of xid and CSN, but finds the xminRSN corresponding to xmin in the key-value pair of xid and RSN, it is determined that the target data record is a rollback record, and the target data record is contained in at least one first data record.
[0260] Optionally, the transceiver unit is further configured to send a snapshot acquisition request to the target node. The snapshot acquisition request includes a first CSN and is used to request a third CSN, where the third CSN is the snapshot corresponding to the snapshot acquisition request. The first CSN and the third CSN are used by the target node to extract a second transaction state from the circular array to accelerate the synchronization of the transaction state stored in the circular array to the read node. The second transaction state includes at least one third mapping relationship, where the CSN in each third mapping relationship is greater than the first CSN and not greater than the third CSN. The unit also receives the second transaction state from the target node.
[0261] The above-mentioned details regarding the transceiver unit 1001 and the processing unit 1002 of the transaction processing device 1000 can be understood by referring to the relevant content of the read node in the aforementioned method embodiment section, and will not be repeated here.
[0262] As shown in Figure 11, the transaction processing apparatus 1100 provided in this embodiment can be the target node (GTM, write node, or CF) described above. The transaction processing apparatus 1100 includes:
[0263] The transceiver unit 1101 is used to receive a transaction status acquisition request sent by the read node. The transaction status acquisition request includes a first CSN and a second CSN. The first CSN is a snapshot corresponding to the first read request, and the second CSN is a snapshot corresponding to the second read request. The second read request is adjacent to the first read request in the receiving time sequence or processing time sequence, and the second read request is before the first read request.
[0264] The processing unit 1102 is used to obtain the corresponding first transaction state based on the first CSN and the second CSN. The first transaction state includes at least one first mapping relationship, wherein the key in each first mapping relationship is CSN and the value is transaction identifier xid. The CSN in each first mapping relationship is greater than the second CSN and not greater than the first CSN.
[0265] The transceiver unit 1101 is also used to send a first transaction status to the read node. The first transaction status is used by the read node to make a visibility determination on at least one first data record corresponding to the first read request.
[0266] The solution provided in this application embodiment uses the first transaction state stored in the target node with CSN as the key and xid as the value. Therefore, the target node can use the first CSN and the second CSN to read the incremental first transaction state and return it to the read node. The target node does not need to synchronize the full transaction state to the read node, which reduces the amount of data to be synchronized, reduces the performance overhead of processing read transactions, and improves the performance of processing read transactions.
[0267] Optionally, the processing unit 1102 is further configured to obtain a commit sequence number (CSN) acquisition request initiated by the write node, wherein the CSN acquisition request includes a first transaction identifier (xid); allocate a target CSN for the CSN acquisition request, and write the mapping relationship between the target CSN and the first xid into a circular array.
[0268] Optionally, the transceiver unit 1101 is further configured to receive a snapshot acquisition request from the read node, the snapshot acquisition request including a first CSN, the snapshot acquisition request being used to request a third CSN, the third CSN being the snapshot corresponding to the snapshot acquisition request;
[0269] The processing unit 1102 is further configured to extract a second transaction state from the circular array based on the first CSN and the third CSN, so as to accelerate the synchronization of the transaction state stored in the circular array to the read node. The second transaction state includes at least one third mapping relationship, and the CSN in each third mapping relationship is greater than the first CSN and not greater than the third CSN.
[0270] The transceiver unit 1101 is also used to send the second transaction status to the read node.
[0271] Optionally, the processing unit 1102 is also used to update the transaction status in the circular array.
[0272] The above-mentioned contents of the transceiver unit 1101 and the processing unit 1102 of the transaction processing device 1100 can be understood by referring to the relevant contents of the target node (GTM, write node or CF) in the aforementioned method embodiment section, and will not be repeated here.
[0273] Figure 12 shows a possible logical structure diagram of the transaction processing device 1200 involved in the above embodiments provided by the present application. The transaction processing device 1200 includes: a processor 1201, a communication interface 1202, a memory 1203, and a bus 1204. The processor 1201, the communication interface 1202, and the memory 1203 are interconnected through the bus 1204. In the embodiments of the present application, the processor 1201 is used to control and manage the operation of the transaction processing device 1200. For example, the processor 1201 is used to execute the determination-related steps in Figures 2 to 9, such as steps 203, 205, 206, etc., the processing steps executed by the read node or target node. The communication interface 1202 is used to support the transaction processing device 1200 to communicate. For example, the communication interface 1202 can execute the receiving or sending-related steps in the above method embodiments. The communication interface 1202 can perform the functions of the transceiver unit 1001 and transceiver unit 1101 in Figures 10 and 11. The memory 1203 is used to store the program code and data of the database system 120.
[0274] The processor 1201 can be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, etc. The bus 1204 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one thick line is used in Figure 11, but this does not indicate that there is only one bus or one type of bus.
[0275] Referring to Figure 13, this embodiment of the application also provides a distributed database system, including: a hardware layer 1307 and a virtual machine monitor (VMM) 1301 running on the hardware layer 1307, and multiple virtual machines 1302. A virtual machine can serve as a read node or a write node in the distributed database system. Optionally, a virtual machine can also be designated as a coordinating node.
[0276] Specifically, Virtual Machine 1302 is a virtual computer simulated on public hardware resources using virtual machine software. Operating systems and applications can be installed on the virtual machine, and it can also access network resources. For applications running in the virtual machine, it's as if they are working on a real computer.
[0277] Hardware Layer 1307: The hardware platform running in the virtualized environment, which can be abstracted from the hardware resources of one or more physical hosts. The hardware layer may include various hardware components, such as a processor 1304 (e.g., CPU) and memory 1305, as well as a network interface card 1303 (e.g., RDMA network card), high-speed / low-speed input / output (I / O) devices, and other devices with specific processing functions.
[0278] Virtual machine 1302, based on the VMM and the hardware resources provided by hardware layer 1307, runs executable programs to implement some or all of the functions of the transaction processing device in the embodiments related to Figures 2 to 9. For the sake of brevity, further details are omitted here.
[0279] Furthermore, the distributed database system may also include a host: acting as a management layer to manage and allocate hardware resources; presenting a virtual hardware platform for virtual machines; and implementing virtual machine scheduling and isolation. The host may be a Virtual Machine Monitor (VMM); or it may be a combination of a VMM and a privileged virtual machine. The virtual hardware platform provides various hardware resources to the virtual machines running on it, such as virtual processors (e.g., VCPUs), virtual memory, virtual disks, virtual network cards, etc. The virtual disk may correspond to a file or a logical block device on the host. Virtual machines run on the virtual hardware platform prepared for them by the host, and one or more virtual machines run on the host. The VCPU of virtual machine 1302 executes an executable program stored in its corresponding virtual memory to implement or perform the method steps described in the above-described method embodiments of the present invention. For example, it implements some or all of the functions of transaction processing device 1000 or transaction processing device 1100 in the embodiments related to Figures 2 to 9.
[0280] In another embodiment of this application, a computer-readable storage medium is also provided, which stores computer-executable instructions. When at least one processor of the device executes the computer-executable instructions, the device executes the transaction processing method described in the embodiments of Figures 2 to 9 above.
[0281] In another embodiment of this application, a computer program product is also provided, the computer program product including computer execution instructions stored in a computer-readable storage medium; at least one processor of the device can read the computer execution instructions from the computer-readable storage medium, and the at least one processor executes the computer execution instructions to cause the device to perform the transaction processing method described in the embodiments of Figures 2 to 9 above.
[0282] In another embodiment of this application, a chip system is also provided, which includes a processor for supporting a transaction processing device in implementing the transaction processing methods described in the embodiments of Figures 2 to 9. In one possible design, the chip system may further include a memory for storing program instructions and data necessary for the transaction processing device. This chip system may be composed of chips or may include chips and other discrete devices.
[0283] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this application.
[0284] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0285] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0286] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0287] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0288] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this application, essentially, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A transaction processing method in a database system, characterized by, The method comprises: a read node receives a first read request and a corresponding first commit sequence number (CSN), the first CSN being a snapshot corresponding to the first read request; the read node pulls a first transaction state corresponding to a CSN in a first CSN and a second CSN interval from a target node, wherein the second CSN is a snapshot corresponding to a second read request, the second read request is adjacent to the first read request in a receiving time sequence or a processing time sequence, and the second read request is prior to the first read request, and the first transaction state comprises at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, and a value is a transaction identifier (xid), the CSN in each first mapping relationship is greater than the second CSN, and is not greater than the first CSN; the read node reads at least one first data record according to the first read request; the read node performs visibility judgment according to the first CSN, the at least one first mapping relationship and the first data record, and returns a query result corresponding to the first read request according to a result of the visibility judgment.
2. The method of claim 1, wherein, The read node performs visibility judgment according to the first CSN, the at least one first mapping relationship and the first data record, comprising: the read node converts each first mapping relationship into a key-value pair with an xid as a key and a CSN as a value; the read node converts a transaction identifier xmin representing an insertion transaction in the first data record into a commit sequence number xminCSN representing the insertion transaction according to the key-value pair of the xid and the CSN, and converts a transaction identifier xmax representing a deletion transaction into a commit sequence number xmaxCSN representing the deletion transaction; the read node performs visibility judgment according to the first CSN, the xminCSN and the xmaxCSN in the first data record.
3. The method of claim 2, wherein, If the xminCSN in the first data record is less than or equal to the first CSN, and the xmaxCSN is greater than the first CSN, the first data record is visible.
4. The method according to claim 2 or 3, characterized in that, The method further comprises: receiving a target xid from a write node, the target xid being used to indicate that data records with an xmin less than or equal to the target xid in a data record of the write node are in a frozen state; deleting a key-value pair with an xid less than or equal to the target xid in the hash table.
5. The method according to any one of claims 2-4, characterized in that, The first transaction state further comprises at least one second mapping relationship, wherein a key in each second mapping relationship is a rollback sequence number (RSN), and a value is a transaction identifier (xid); correspondingly, the hash table further comprises a key-value pair with an xid as a key and an RSN as a value; If an xmin in a target data record cannot be found from the key-value pair of the xid and the CSN, but the xmin corresponding to the xminRSN can be found from the key-value pair of the xid and the RSN, the read node determines that the target data record is a rolled-back record, and the target data record is included in the at least one first data record.
6. The method according to any one of claims 1-5, characterized in that, The method further comprises: The read node sends a snapshot acquisition request to the target node, the snapshot acquisition request containing the first CSN, the snapshot acquisition request being used to request a third CSN, the third CSN being a snapshot corresponding to the snapshot acquisition request, the first CSN and the third CSN being used for the target node to extract second transaction states from a circular array, the second transaction states including at least one third mapping relationship, a CSN in each third mapping relationship being greater than the first CSN and not greater than the third CSN, so as to accelerate synchronization of transaction states stored in the circular array to the read node; The read node receives second transaction states from the target node.
7. A transaction processing method in a database system, characterized by, Comprise: Receiving a transaction state acquisition request sent by a read node, the transaction state acquisition request including a first CSN and a second CSN, the first CSN being a snapshot corresponding to the first read request, the second CSN being a snapshot corresponding to a second read request, the second read request being adjacent to the first read request in receiving sequence or processing sequence, and the second read request being prior to the first read request; According to the first CSN and the second CSN, a corresponding first transaction state is acquired, the first transaction state including at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, and a value is a transaction identifier xid, the CSN in each first mapping relationship being greater than the second CSN and not greater than the first CSN; The first transaction state is sent to the read node, the first transaction state being used for the read node to perform visibility judgment on at least one first data record corresponding to the first read request.
8. The method of claim 7, wherein, The method further comprises: Acquiring a commit sequence number CSN acquisition request initiated by a write node, the CSN acquisition request containing a first transaction identifier xid; A target CSN is allocated for the CSN acquisition request, and a mapping relationship between the target CSN and the first xid is written into the circular array.
9. The method according to claim 7 or 8, characterized in that, The method further comprises: Receiving a snapshot acquisition request from the read node, the snapshot acquisition request containing the first CSN, the snapshot acquisition request being used to request a third CSN, the third CSN being a snapshot corresponding to the snapshot acquisition request; According to the first CSN and the third CSN, second transaction states are extracted from a circular array to accelerate synchronization of transaction states stored in the circular array to the read node, the second transaction states including at least one third mapping relationship, a CSN in each third mapping relationship being greater than the first CSN and not greater than the third CSN; The second transaction states are sent to the read node.
10. The method of claim 9, wherein, The method further comprises: Updating transaction states in a circular array.
11. A transaction processing apparatus, characterized by comprising: Comprise: A transceiver unit is configured to receive a first read request and a corresponding first commit sequence number CSN, the first CSN being a snapshot corresponding to the first read request; The transceiver unit is configured to pull, from the target node, a first transaction state corresponding to a CSN in the first CSN and the second CSN interval; the second CSN is a snapshot corresponding to a second read request, the second read request is adjacent to the first read request in terms of receiving time sequence or processing time sequence, and the second read request is prior to the first read request; the first transaction state includes at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, a value is a transaction identifier xid, the CSN in each first mapping relationship is greater than the second CSN, and is not greater than the first CSN; The processing unit is configured to read at least one first data record according to the first read request, and perform visibility judgment according to the first CSN, the at least one first mapping relationship and the first data record, and return a query result corresponding to the first read request according to a result of the visibility judgment.
12. A transaction processing apparatus, characterized by comprising: The transceiver unit is configured to receive a transaction state acquisition request sent by a read node, the transaction state acquisition request including a first CSN and a second CSN, the first CSN being a snapshot corresponding to the first read request, and the second CSN being a snapshot corresponding to a second read request, the second read request being adjacent to the first read request in terms of receiving time sequence or processing time sequence, and the second read request being prior to the first read request; The processing unit is configured to acquire a corresponding first transaction state according to the first CSN and the second CSN, the first transaction state including at least one first mapping relationship, wherein a key in each first mapping relationship is a CSN, a value is a transaction identifier xid, the CSN in each first mapping relationship is greater than the second CSN, and is not greater than the first CSN; The transceiver unit is further configured to send the first transaction state to the read node, the first transaction state being used for the read node to perform visibility judgment on at least one first data record corresponding to the first read request. The computer program is executed by the processor to implement the method of any one of claims 1-10.
13. A transaction processing apparatus, characterized by comprising: The computer program is executed by the processor to implement the method of any one of claims 1-10. The computer program product includes computer program code, when the computer program code is run on a computer device, so that the computer device executes the method of any one of claims 1-10.
14. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program product includes computer program code, when the computer program code is run on a computer device, so that the computer device executes the method of any one of claims 1-10.
15. A computer program product, characterised in that, The computer program product includes computer program code, when the computer program code is run on a computer device, so that the computer device executes the method of any one of claims 1-10.
16. A database system, characterized in that
Citation Information
Patent Citations
Distributed transaction consistency realization method and device
CN110196760A
Database system and transaction management method and device
CN113934737A
Method and system for processing database transactions in distributed online transactional processing (OLTP) database
CN117616411A
High-throughput distributed transaction management for globally consistent sharded OLTP system and method of implementing
US20190171763A1