Method and apparatus for processing transaction in database system, and database system
By transmitting the mapping relationship between CSN and xid between the read node and the target node, the read node only pulls the incremental transaction status within the CSN range for visibility judgment, which solves the performance overhead problem caused by full synchronization and improves the processing efficiency and memory utilization of read transactions.
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
- 2026-01-29
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 impacting processing efficiency.
By transmitting the mapping relationship between commit sequence number (CSN) and transaction identifier (xid) between the read node and the target node, the read node only pulls the incremental transaction status within the CSN range for visibility judgment, reducing full synchronization and improving processing efficiency.
It reduces the amount of data synchronized for transaction states, improves the processing performance of read transactions, reduces memory usage, and increases the system's processing speed.
Smart Images

Figure CN2025083706_29012026_PF_FP_ABST
Abstract
Description
Transaction processing method and device in database system and database system
[0001] The present application claims priority from 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 whole content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] The present application relates to the technical field of database, in particular to a transaction processing method and device in database system and database system. BACKGROUND
[0003] The data records stored in the 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 reads the same version of the same data regardless of the number of times the read transaction reads the data.
[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 on 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 of the record and a transaction identifier (xmax) representing a deletion transaction of the record, when performing visibility judgment, the key used is xid. Therefore, after obtaining the first mapping relationship, the read node stores <CSN, xid> in the hash table in the format of <xid, CSN> key-value pair. When performing visibility judgment, only the xmin and xmax in the first data record and the <xid, CSN> in the hash table need to be combined to convert the respective xminCSN and xmaxCSN, and then the xminCSN and the xmaxCSN can be 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 new transaction states in the circular array, and can also reduce the amount of incremental transaction states pulled when a read request is subsequently received.
[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 a receiving sequence or a 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] With reference to the drawings, embodiments of the present application will be described below. Obviously, the described embodiments are only a part but not all of the embodiments of the present application. Based on the description of the embodiments, those skilled in the art can further understand the technical solutions provided by the present application.
[0089] The terms "first", "second", and the like in the description and claims of the present application and the above drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "comprise" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device comprising a series of steps or units does not necessarily limit to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to the process, method, product or device.
[0090] The embodiments of the present application provide a transaction processing method in a database system, which is used to reduce the performance overhead of processing read transactions and improve the performance of processing read transactions. The present application also provides corresponding devices, computer readable storage media, computer program products and database systems, etc. The following are described in detail respectively.
[0091] For ease of understanding, the technical terms related to the embodiments of the present application are briefly introduced as follows:
[0092] 1. Transaction: A transaction is a sequence of database operations, which is composed of a batch of operations executed between transaction begin and transaction commit. The batch of operations are either all successful or all failed, and there is no intermediate state, which is an indivisible unit of work. Specifically, a transaction needs to meet the atomicity, consistency, isolation and durability semantics, also known as ACID semantics.
[0093] 2. Atomicity: Atomicity refers to the fact that in the same business process, the transaction guarantees the modification of multiple data, which is either successful at the same time or revoked at the same time.
[0094] 3. Consistency: Consistency refers to the fact that a transaction must be in a correct state before and after execution, and meet the integrity constraints.
[0095] 4. Isolation: Isolation refers to the fact that in different business processes, the transaction guarantees that the data being read and written by each business is independent of each other and will not affect each other.
[0096] 5. Durability: Durability refers to the fact that a transaction should guarantee that all successfully committed data modifications are correctly persisted without data loss.
[0097] 6. Transaction commit: Transaction commit refers to the fact that a transaction is executed and then committed to the data storage for persistence. When a transaction is started or generated, the database system allocates a transaction identifier xid to the transaction. After the transaction is committed, the database system allocates a transaction commit sequence number (CSN) to the transaction. The xid and the CSN can be referred to as the transaction state.
[0098] 7. Distributed transaction: 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 requirements of transaction ACID semantics. Examples include an online transaction processing (OLTP) database system and an on-line analytical processing (OLAP) database system.
[0100] 9. Database system: A database system can include one or more read data nodes (read DN), one or more write data nodes (write DN), one or more global transaction managers (GTM), and one or more coordinator nodes (CN). If there are two GTMs, one is the primary GTM and the other is the standby GTM. The database system can also include a cluster caching facility (CF) instead of a GTM and a CN. Of course, the database system can also include other nodes, which are not limited in this application.
[0101] 10. Write node: In a database system, a node responsible for processing write transactions (addition, deletion, and modification operations on records).
[0102] 11. Read node: In a database system, a node responsible for processing read transactions (queries on records). The read node and the write node can be the same node or independent nodes. Write nodes can be used to process write transactions and read nodes can be used to process read transactions through read-write separation technology.
[0103] 12. General transaction state: The general transaction state refers to the state of all transactions (ended transactions and executing transactions) in the database system at a certain moment, including: active, failed, partially committed, committed, rolled back, ended, etc.
[0104] 13. Narrow transaction state: The narrow transaction state refers to the state of the transaction in the multi-version concurrency control (MVCC) technology, which is a simplified and customized version of the general transaction state to achieve visibility judgment of each version of the data record (tuple) generated by the transaction. The transaction state is more efficient for storage and synchronization. With this transaction state as "glasses", the visibility of each version of the record can be judged, such as the mapping relationship between xid and CSN. The transaction state in this application is mainly the narrow transaction state. The transaction state in this application is usually stored in GTM, of course, it can also be stored in the write node, or in the CF.
[0105] 14. MVCC: MVCC is a transaction processing technology that sets multiple versions of data records and uses transaction state as "glasses" to judge the visibility of each version of the data record when processing read transactions.
[0106] 15. Transaction state synchronization: In order to meet the Isolation semantic level, the database system needs to obtain the transaction state to judge the visibility of the read data record when processing the read transaction, thus generating the synchronization demand of the transaction state, that is, synchronizing the transaction state from GTM, write node or CF to the read node.
[0107] 16. Snapshot: Snapshot refers to the maximum CSN in the database system when the database system receives a read request. The maximum CSN corresponding to the read request arriving at the database system at different times is usually different.
[0108] 17. Write request: refers to the structured query language (SQL) corresponding to the write transaction, which is used to request to write the corresponding data into the database system.
[0109] 18. Read request: refers to the SQL corresponding to the read transaction, which is used to request to query the corresponding data in the database system.
[0110] The method provided by the embodiments of the present application can be applied to a database system. FIG. 1A shows a typical logical architecture of a database system. According to FIG. 1A, the database system 100 includes a database 110 and a database management system (DBMS) 130.
[0111] The database 110 is a collection of organized data stored in a data storage 120, that is, a collection of associated data organized, stored and used according to a specific data model. According to different data models used to organize data, data can be divided into various types, such as relational data, graph data, time series data, etc. Relational data is data modeled using a relational model, usually represented as a table, and rows in the table represent a collection of related values of an object or entity. Graph data, simply referred to as "graph", is used to represent the relationship between objects or entities, such as social relationships. Time series data, simply referred to as time series data, is a data column recorded and indexed in chronological order, used to describe the state change information of an object in the time dimension.
[0112] The database management system 130 is the core of the database system, and is a system software for organizing, storing, and maintaining data. The client 200 can access the database 110 through the database management system 130, and the database administrator also performs maintenance work of the database through the database management system. The database management system 130 provides various functions for the client 200 to establish, modify, and query the database, where the client 200 can be an application program or a user device. The functions provided by the database management system 130 can 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 saved in a 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 a data control function to effectively control and manage the operation of the database 110, to ensure that the data is correct and effective; (4) database establishment and maintenance function, including loading of initial data of the database, dumping, restoring, reorganizing of the database, system performance monitoring, analysis, and other functions; (5) database transmission, the database management system provides processing of data transmission to realize communication between the client and the database management system, which is usually coordinated with the operating system.
[0113] The data storage 120 includes but is not limited to a solid state drive (SSD), a disk array, cloud storage, or other types of non-transitory computer readable storage media. Those skilled in the art can understand that a database system can include fewer or more components than those shown in FIG. 1A, or include different components from those shown in FIG. 1A, and FIG. 1A only shows components more relevant to the implementation disclosed in the embodiments of the present application.
[0114] The database system provided by the embodiments of the present application can be a distributed database system (DDBS). In the process of transaction processing, in order to realize concurrency control between transactions, the DDBS usually adopts a global transaction manager (GTM) to manage transactions. The DDBS will be introduced below in combination with FIG. 1B.
[0115] Figure 1B is a schematic diagram of a distributed database system employing a shared-storage architecture, including one or more coordinator nodes (CNs), a plurality of read nodes (readDNs), a plurality of write nodes (writeDNs), and one or more GTMs (e.g., a first GTM and a second GTM in Figure 1B). The first GTM serves as a primary GTM, and the second GTM serves as a backup for the first GTM, taking over the work of the first GTM in case of failure of the first GTM, thus ensuring high reliability of the DDBS. The plurality of read nodes and the plurality of 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 CNs and the readDNs, writeDNs communicate through network channels. In one embodiment, the network channels can be composed of network devices such as switches, routers, and gateways. The CNs, readDNs, writeDNs, and GTMs collectively implement the functions of a database management system, providing services such as retrieval, insertion, modification, and deletion of databases for clients.
[0116] In one embodiment, each of the CNs, readDNs, writeDNs, and GTMs has a database management system deployed thereon. A shared memory and a shared data store store data that is shared by the plurality of readDNs and the plurality of writeDNs, and the readDNs and writeDNs can perform read and write operations on the data in the data store through the network channels. The shared data store can be a shared disk array. The CNs, readDNs, writeDNs, first GTM, or second GTM in the distributed database system can be physical machines such as database servers, or virtual machines (VMs) or containers running on abstracted hardware resources. In one embodiment, the CNs, readDNs, writeDNs, first GTM, or second GTM are virtual machines or containers, and the network channels are virtual switching networks that include virtual switches. The database management systems deployed in the CNs, DN, first GTM, or second GTM are DBMS instances, which can be processes or threads, and these DBMS instances collectively implement the functions of a database relational system. In another embodiment, the CNs, readDNs, writeDNs, first GTM, or second GTM are physical machines, and the network channels include one or more switches, which can be storage area network (SAN) switches, Ethernet switches, fiber switches, or other physical switching devices.
[0117] In all embodiments of the present application, the data storage of the database system includes, but is not limited to, solid state drives (SSD), disk arrays or other types of non-transitory computer readable media. Although the database is not shown in FIG. IB, it should be understood that the database is stored in the data storage. Those skilled in the art can understand that a database system can include fewer or more components than those shown in FIG. 1A and FIG. IB, or include different components from those shown in FIG. 1A and FIG. IB, and FIG. 1A and FIG. IB only show components more relevant to the implementation disclosed in the embodiments of the present application. However, those skilled in the art can understand that a distributed database system can include any number of CNs, readDNs and writeDNs. The database management system functions of each CN, readDN and writeDN can be respectively implemented by a suitable combination of software, hardware and / or firmware running on each CN, readDN and writeDN.
[0118] The distributed database system described in FIG. IB above includes a plurality of readDNs, a plurality of writeDNs and a plurality of CNs, wherein the functions of each readDN or each writeDN are substantially the same, and the functions of each CN are also substantially the same.
[0119] In addition, it should be noted that if the write node can store more data, the shared data storage in FIG. IB above can be removed, and the write node can store the data records generated by the transaction.
[0120] In addition, it should be noted that the scheme provided by the embodiments of the present application can also be applied to an architecture that does not include CN and GTM, as shown in FIG. 1C. The database system can include read nodes, write nodes, shared memory and shared storage, wherein one write node can correspond to a plurality of read nodes, and of course, a plurality of write nodes can also correspond to a plurality of read nodes. The shared storage refers to storage resources other than the shared memory. The read nodes and the write nodes can read and write data in the shared memory and the shared storage through network channels.
[0121] The scheme provided by the embodiments of the present application can also be applied to an architecture as shown in FIG. 1D. As shown in FIG. 1D, the database system can include read nodes, write nodes, a central function component CF, shared memory and shared storage. The CF can coordinate requests between the read nodes and the write nodes, and the function of the CF is equivalent to CN+GTM. The read nodes and the write nodes can read and write data in the shared memory and the shared storage through network channels.
[0122] Based on the above database system, referring to FIG. 2, the transaction processing method provided by the embodiments of the present application includes:
[0123] 201. The read node receives a first read request and a corresponding first CSN, the first CSN being a snapshot corresponding to the first read request.
[0124] The snapshot corresponding to the first read request can be understood with reference to FIG. 3, as shown in FIG. 3: a transaction is assigned a transaction identifier xid when generated, such as xid of TX1, TX2, … TX8 being 1, 2, … 8 respectively. A CSN is a transaction commit sequence number, which is assigned when the transaction is committed. Because the duration of transaction execution is different, a transaction generated earlier does not necessarily commit earlier. In FIG. 3, TX1 is the first transaction generated in the system and also the first transaction committed, so the CSN of TX1 is 1; TX2 is the second transaction generated in the system, but the fourth transaction committed, so the CSN of TX2 is 4; TX3 is the third transaction generated in the system, but the second transaction committed, so the CSN of TX3 is 2; TX5 is the fifth transaction generated in the system, but the third transaction committed, so the CSN of TX3 is 3; and so on. From FIG. 3, the CSN of TX4, TX6, TX7 and TX8 can be determined. If the database system receives a first read request at the position of the snapshot indication line 301 in FIG. 3, it can be determined that the first CSN = 3, that is, the maximum CSN of the committed transaction in the database system at this time.
[0125] 202. The read node sends a transaction state acquisition request to the target node, and correspondingly, the target node receives the transaction state acquisition request from the read node, the transaction state acquisition request including the first CSN and the second CSN.
[0126] 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 sequence or processing sequence, and the second read request being prior to 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. If the first CSN is denoted as reqCSN, the second CSN can be denoted as last reqCSN.
[0127] In this application, the target node can be a GTM, a write node or a CF.
[0128] 203. The target node acquires a corresponding first transaction state according to the first CSN and the second CSN.
[0129] The first transaction state includes at least one first mapping relationship, where the key in each first mapping relationship is a CSN, and the value is a 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 the present application, the first mapping relationship can be expressed in the form of <CSN, xid>.
[0131] The pull range (last reqCSN, reqCSN] can be determined by the first CSN and the second CSN, and then the list storing <CSN, xid> can be queried using the pull range. With each CSN in (last reqCSN, reqCSN] as a key, one or more <CSN, xid> corresponding to (last reqCSN, reqCSN] can be queried from the list, i.e., the first transaction state.
[0132] 204. The target node sends the first transaction state to the read node. Correspondingly, the read node receives the first transaction state from the target node.
[0133] Optionally, if the first CSN is the same as the second CSN, it indicates that the database system has no new transaction state. In this case, the read node receives a prompt from the target node, and the prompt is used to indicate 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 the above steps 202 and 204 can also be understood as a process in which the read node pulls the first transaction state corresponding to the CSN in the interval of the first CSN and the second CSN from the target node.
[0135] 205. The read node reads at least one first data record according to the first read request.
[0136] In the present application, the at least one first data record can be a data record associated with some identifier in the read request, such as a data record associated with a certain bank card number, or time information associated in the read request.
[0137] There can be one or more versions in a first data record, and the database system can stamp a version stamp on each version. The same data (such as a first data record) between different versions are associated with each other by pointers, forming a version chain table. A read transaction can read the data of the required version along the chain table according to the transaction state data. The manifestation of the first data record and different versions can be understood with reference to FIG. 4.
[0138] As shown in FIG. 4, there are three data records, which are represented by 1), 2), and 3), respectively. Among them, 1) is a first inserted data record; 2) is a data record updated once based on 1); and 3) is a data record updated based on 2). The three data records will be introduced as follows.
[0139] 1) represents the first time a data record is inserted, the data record is represented by xmin = 10, which indicates that the transaction identifier of the inserted data record is 10, xmax = 0, which indicates that the data record has not been deleted, and ctid is (0, 1), which indicates that the data record is the first data record on the page with the page identifier 0, and data is value 1.
[0140] 2) represents that the data record is updated once to generate a new data record, and the new data record has two versions.
[0141] The first version has xmin = 10, which indicates that the transaction identifier of the inserted data record is 10, xmax = 12, which indicates that the transaction identifier of the deleted data record is 12, ctid is (0, 2), which indicates that the data record is the second data record on the page with the page identifier 0, and data is value 1.
[0142] The second version has xmin = 12, which indicates that the transaction identifier of the inserted data record is 12, xmax = 0, which indicates that the data record has not been deleted, ctid is (0, 2), which indicates that the data record is the second data record on the page with the page identifier 0, and data is value 2.
[0143] 3) represents the data record updated based on 2), and the new data record has three versions.
[0144] The first version has xmin = 10, which indicates that the transaction identifier of the inserted data record is 10, xmax = 12, which indicates that the transaction identifier of the deleted data record is 12, ctid is (0, 2), which indicates that the data record is the second data record on the page with the page identifier 0, and data is value 1.
[0145] The second version has xmin = 12, which indicates that the transaction identifier of the inserted data record is 12, xmax = 15, which indicates that the transaction identifier of the deleted data record is 15, ctid is (1, 1), which indicates that the data record is the first data record on the page with the page identifier 1, and data is value 2.
[0146] The second version has xmin = 15, which indicates that the transaction identifier of the inserted data record is 15, xmax = 0, which indicates that the data record has not been deleted, ctid is (1, 1), which indicates that the data record is the first data record on the page with the page identifier 1, and data is value 3.
[0147] 206. The read node determines visibility according to the first CSN, the at least one first mapping relationship, and the first data record.
[0148] In this application, the read node can determine the CSN corresponding to the xid (xmin, xmax) in the first data record by using <CSN, xid>, and then determine whether each data record meets the visibility by using the relationship between the corresponding CSN and the first CSN. The visibility indicates the data record that has been committed but not deleted.
[0149] 207. The read node returns the query result corresponding to the first read request according to the result of the visibility determination.
[0150] In this 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 indicating that there is no first data record corresponding to the first read request can be returned.
[0151] The scheme provided by the embodiments of the present application can be used in the following way. When processing the read request, the read node can pull the first transaction state by 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 read node first transaction state is the incremental transaction state whose CSN is greater than the second CSN and less than or equal to the first CSN, so the target node does not need to synchronize the full transaction state to the read node, which reduces the data amount of the synchronized transaction state, reduces the performance overhead of processing the read transaction, and improves the performance of processing the read transaction.
[0152] Optionally, the step 206 can be:
[0153] The read node saves each first mapping relationship in the hash table in the format of the key-value pair with xid as the key and CSN as the value. The read node converts the transaction identifier xmin representing the insertion transaction in the first data record into xminCSN and converts the transaction identifier xmax representing the deletion transaction into xmaxCSN according to the key-value pair of xid and CSN in the hash table.
[0154] The read node determines visibility according to the first CSN, xminCSN, and xmaxCSN in the first data record.
[0155] 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. If the condition is not met, the first data record is not visible.
[0156] In the embodiment of the present application, because the first data record stores the transaction identifier (xmin) of the transaction that inserts the record and the transaction identifier (xmax) of the transaction that deletes the record, when making the visibility judgment, the key used is xid. Therefore, after the read node obtains the first mapping relationship, it keeps <CSN, xid> in the hash table in the format of <xid, CSN> key-value pair. When making the visibility judgment, only the xmin and xmax in the first data record and the <xid, CSN> in the hash table are needed to convert the respective corresponding xminCSN and xmaxCSN, and then the xminCSN and xmaxCSN can be 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.
[0157] The transaction processing process provided by the embodiment of the present application is introduced from the perspective of the read node and the target node, and the transaction processing method provided by the embodiment of the present application is introduced based on a database system of different structures.
[0158] Based on the database system shown in 1B, the write transaction processing process of the transaction processing method provided by the embodiment of the present application includes the following steps, as shown in FIG. 5.
[0159] 501. The CN receives a write request from the client.
[0160] When starting a write transaction, the client can initiate one or more write requests, and each write request is a write SQL.
[0161] 502. The CN allocates a write node for the write request. Correspondingly, the write node receives the write request.
[0162] The CN can parse each SQL and determine the corresponding write node writeDN for each SQL, so that the write node can execute the write request.
[0163] 503. The write node allocates a transaction identifier for the write transaction corresponding to the write request.
[0164] In the embodiment of the present application, the transaction identifier allocated for the write transaction is denoted as xid1.
[0165] 504. The write node sends a CSN acquisition request to the GTM, and the CSN acquisition request contains xid1. Correspondingly, the GTM receives the CSN acquisition request.
[0166] 505. The GTM allocates CSN1 for the write transaction and writes <CSN1, xid1> into the circular array.
[0167] <CSN1, xid1> represents a set of mapping relations with CSN1 as a key and xid1 as a value.
[0168] 506. The GTM returns the CSN1 to the write node. Correspondingly, the write node receives the CSN1.
[0169] 507. The write node performs transaction commit.
[0170] In the embodiment, the GTM can store the mapping relation between CSN1 and xid1 when allocating the CSN for the write node, so that the read node can directly obtain the mapping relation between CSN1 and xid1 when processing the read transaction, and use the mapping relation to process the read transaction, thereby improving the performance of processing the read transaction.
[0171] The xid in the above-mentioned Figure 5 corresponds to the embodiment of the write node, and actually, the xid can also be allocated by the GTM. If the xid is also allocated by the GTM, the process of the write transaction processing can be as follows:
[0172] The client starts a write transaction and sends a batch of write SQLs to the CN; before processing the write SQLs, the CN initiates an xid obtaining (getxid) request to the GTM to create an xid for the write transaction, which will be written into each record inserted or modified by the write transaction. For each write SQL, the CN will parse and convert into a write request to send to the corresponding write DN, and the write DN will execute the write request; if all the write SQLs are processed, the client sends a transaction commit (commit) command to the CN to start the write transaction commit process; the CN first sends a prepare command to each write DN participating in the write transaction processing to pre-commit the write transaction (prepare) on each write DN. After the pre-commit of the write transaction on all the write DNs is completed, the CN initiates a CSN obtaining (GetCSN) request to the GTM, and the xid is carried in the CSN obtaining request. After receiving the CSN obtaining request, the GTM allocates a latest CSN (by means of CSN++) for the write transaction, and writes the mapping relation between the latest allocated CSN and the xid, i.e., <CSN, Xid>, into a circular array. After obtaining the CSN through the CSN obtaining request, the CN sends a transaction commit command to each write DN participating in the write transaction to perform the final commit operation.
[0173] In the above, no matter which write transaction processing flow is executed, the GTM can establish the mapping relation between <CSN, Xid> for subsequent read transaction processing flow, which will be introduced below in combination with the read transaction processing flow of the database system based on Figure 1B.
[0174] As shown in Figure 6, the method for transaction processing provided in the embodiment includes:
[0175] 601. The CN receives a first read request from the client.
[0176] The first read request is a read SQL corresponding to a read transaction, and one read transaction can have one or more read SQLs.
[0177] 602. The CN sends a snapshot request to the GTM to obtain a 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 denoted as reqCSN.
[0179] 603. The 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, wherein 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 state acquisition request to the GTM, and correspondingly, the GTM receives the transaction state acquisition request from the read node, wherein the transaction state acquisition request includes the first CSN and a second CSN.
[0182] The second CSN is a snapshot corresponding to a second read request, and the second read request is a previous read request of the first read request. The second CSN can be denoted as lastreqCSN. The first CSN and the second CSN in the transaction state acquisition request can be denoted as (second CSN, first CSN], that is, (lastreqCSN, reqCSN].
[0183] 605. The GTM pulls a first transaction state from the circular array according to (second CSN, first CSN].
[0184] The CSN in the first transaction state <CSN, xid> is greater than the second CSN, that is, greater than lastreqCSN, and is not greater than (less than or equal to) the first CSN, that is, reqCSN.
[0185] For example, if lastreqCSN = 2 and reqCSN = 4, and the circular array includes five first mapping relationships, which are denoted as Table 1:
[0186] Table 1: Circular array <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 xmin and xmax of the first data record and the second data record into xminCSN and xmaxCSN, if:
[0201] The first data record: xminCSN is 1, and xmaxCSN is 3, that is, according to xmin=2, the corresponding CSM is determined to be 1, and according to xmax=5, the corresponding CSM is determined to be 3.
[0202] The second data record: xminCSN is 1, and xmaxCSN is unknown, that is, according to xmin=2, the corresponding CSM is determined to be 1, and according to xmax=6, the corresponding CSM cannot be found, which indicates that xmax=6 corresponds to a write transaction that is still being executed and has not been committed.
[0203] In combination with the first CSM=4, the visibility of the first data record is determined, xminCSN=1<4, that is, xminCSN<first CSM; it is indicated that the first data record has been committed. But xmaxCSN=3<4, that is, xmaxCSN<first CSM; it is indicated that the first data record has been deleted when the first read request reaches the database system. Therefore, the first data record is invisible.
[0204] In combination with the first CSM=4, the visibility of the second data record is determined, xminCSN=1<4, that is, xminCSN<first CSM; it is indicated that the second data record has been committed, and xmaxCSN is unknown, which indicates 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 according to the result of the visibility determination.
[0206] In the present application, the query result can be the second data record visible to the first read request, that is, the data corresponding to xmin=2 and xmax=6.
[0207] If no visible data record is determined through the above steps 602 to 609, the query result that the first data record corresponding to the first read request does not exist can be returned.
[0208] In the embodiments of the present application, as known from the above introduction, the transaction processing method provided by the embodiments of the present application can meet the one-to-one synchronization, incremental synchronization, and synchronization of three points at a time requirements, wherein:
[0209] One-to-one synchronization means that the read node only needs to pull the transaction state from the GTM.
[0210] Incremental synchronization: refers to that the read node only pulls the transaction state added between two read requests; the shorter the interval between the two read requests, the less the amount of transaction state data pulled, and the more efficient the transaction synchronization.
[0211] One-time synchronization: refers to processing a read transaction, and the read node only needs to pull the transaction state once, greatly improving the synchronization efficiency of the transaction state.
[0212] In addition, the transaction processing method provided by the embodiments of the present application can also manage a hash table, identify a rollback transaction, and manage a circular array, which will be introduced as follows:
[0213] 1. Managing a hash table;
[0214] Regarding the read node managing the hash table, it can be completed through the cooperation of the read node and the write node, as shown in FIG. 7, and the process can include:
[0215] 701. The write node determines a target xid.
[0216] In order to prevent the transaction state from accumulating over time, the write node selects an oldest xid when performing a vacuum operation, and modifies the xmin value of the data record whose xmin is less than or equal to the oldest xid to 2 or marks the data record whose xmin is less than or equal to the oldest xid with a frozen mark (xmin_FROZEN).
[0217] The target xid is used to indicate that the data record whose xmin is not greater than (less than or equal to) the target xid in the data record of the write node is 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. The read node deletes the key-value pair whose xid is not greater than the target xid in the hash table.
[0220] Taking the target xid = 3 as an example, if the hash table before processing is taken as Table 2, the hash table after processing can be understood by referring to Table 3.
[0221] Table 3: Hash table <xid, CSN>
[0222] As can be known from the comparison between Table 2 and Table 3, when the target xid = 3, the <1, 4> of xid = 1 and the <2, 1> of xid = 2 in Table 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 also be deleted, or two columns in which no data is recorded are deleted, which is not limited in the application.
[0224] In the embodiment of the application, since the hash table is saved in the memory, if there are too many data in the hash table, more memory will be occupied. The data records in the write node are in a frozen state and will not be read again. Therefore, the read node can delete the key-value pairs in the hash table that are not greater than the target xid according to the state of the data records in the write node, to clean up the data that will not be used, thereby reducing the occupation of the memory and improving the memory utilization.
[0225] 2. Identify a rollback transaction;
[0226] In the embodiment of the application, the first transaction state introduced above can further include at least one second mapping relationship, wherein the key in each second mapping relationship is a rollback sequence number (RSN), and the value is a transaction identifier xid; correspondingly, the hash table further includes a key-value pair with the key xid and the value RSN.
[0227] If the xmin in the target data record cannot be found from the xid and CSN key-value pair, but the xmin corresponding xminRSN can be found from the xid and RSN key-value pair, the read node determines that the target data record is an already-rolled-back record, and the target data record is included in at least one first data record.
[0228] The <xid, RSN> can be stored separately from the <xid, CSN> in different spaces, or different lengths are used to distinguish the RSN and the CSN.
[0229] As can be seen, the embodiment of the application not only provides a processing manner for a committed transaction, but also provides a processing manner for a rollback transaction using the second mapping relationship <RSN, xid>. If a transaction has been rolled back, the corresponding transaction commit sequence number cannot be found. Therefore, the read node can save the <xid, RSN> in the hash table, and when making the visibility judgment, if the xmin corresponding xminCSN cannot be found, the xminRSN corresponding to the xmin can be found through the <xid, RSN> to determine that the target data record is an already-rolled-back record, thereby achieving more comprehensive processing of the transaction.
[0230] 3. Manage a circular array;
[0231] The process of managing the circular array can be completed by the read node and the GTM in cooperation, as shown in FIG. 8, and the process includes:
[0232] 801. The read node sends a snapshot acquisition request to the GTM, and the snapshot acquisition request contains the first CSN. Correspondingly, the GTM receives the snapshot acquisition request from the read node.
[0233] 802. The GTM extracts the second transaction state from the circular array according to 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.
[0234] 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.
[0235] 803. The GTM sends the second transaction state to the read node. Correspondingly, the read node receives the second transaction state from the GTM.
[0236] 804. The GTM updates the transaction state in the circular array.
[0237] After the GTM synchronizes the front part of the transaction state in the circular array to each read node, the GTM can delete the part of the transaction state, so as to free the space in the front part of the circular array for storing new transaction state, thereby improving the utilization of the circular array.
[0238] For example, if the circular array can refer to Table 4 before being updated.
[0239] Table 4: Circular array <CSN, xid>
[0240] If the first CSN = 4 and the third CSN = 8, the pull range in the circular array is (4, 8], and the second transaction state includes <5, 3>, <6, 7>, <7, 6> and <8, 9>. If each read node pulls the second transaction state from the circular array, the circular array can be updated, and the second transaction state in the array can be deleted. After the circular array is updated, only <9, 8> is left in the circular array, and more space is freed for storing new <CSN, xid>.
[0241] In the embodiments of the present application, the circular array can be understood as a storage space, and the read node actively sends a snapshot acquisition 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 the circular array storing new transaction state, and can also reduce the amount of pulling of incremental transaction state when receiving a read request subsequently.
[0242] The above is the process of transaction processing in the database system based on FIG. 1B. If in the database system shown in FIG. 1C, the functions of GTM in FIGS. 2-8 can be integrated on the write node and executed by the write node. Under the database system architecture shown in FIG. 1C, the differences between the transaction processing before and after using the scheme of the present application can be understood with reference to FIG. 9.
[0243] As shown in FIG. 9, the differences between the transaction processing before and after using the scheme of the present application mainly include three parts, which are 901, 902 and 903.
[0244] 901 represents the difference at the write node. Before using the scheme of the present application, the array is used to save <xid, CSN> in the write node. After using the scheme of the present application, the circular array is used to save the mapping relationship <CSN, xid> of CSN and xid in the write node.
[0245] 902 represents the difference at the read node. Before using the scheme of the present application, the read node acquires CSN from the write node according to xid. After using the scheme of the present application, the read node acquires the newly generated <CSN, xid> between two requests from the write node by querying the range (lastReqCSN, ReqCSN]. In addition, the read node also converts the acquired incremental <CSN, xid> into the form of <xid, CSN> and stores it in the hash table, which is used to execute the process of visibility judgment introduced above.
[0246] 902 represents the difference of data records. Before using the scheme of the present application, the data records include both xid and CSN. In this way, when a user record without the CSN field is read, a request needs to be sent to the write node to pull the CSN, and the number of requests is large, and the time delay is large. After using the scheme of the present application, only xid is included in the data record, which simplifies the data storage structure.
[0247] In the embodiment of the present application, the user record can have a CSN field or can not have a CSN field. If the number of records modified by the transaction is small, the CSN will be written into the record when the transaction is committed, and the record with the CSN field is generated. If the number of records modified by the transaction is large, the CSN will not be written into the record for the consideration of the performance of the transaction, and the user record without the CSN field is generated.
[0248] In addition, it should be noted that in the transaction processing process under the architecture shown in FIG. 1C, the process originally executed by the GTM is changed to be executed by the write node, and the steps executed by the read node can be understood with reference to the corresponding contents introduced in the foregoing FIGS. 2-8.
[0249] In addition, under the architecture shown in FIG. 1D, the CF can perform the functions of the GTM and the CN in the foregoing section G of FIGS. 2-8, and thus the transaction processing procedure based on FIG. 1D can be understood by referring to the corresponding content described in the foregoing section G of FIGS. 2-8, which will not be repeated here.
[0250] The above embodiments describe a transaction processing method in a database system. The transaction processing apparatus provided by the embodiments of the present application is described below in conjunction with the accompanying drawings.
[0251] As shown in FIG. 10, the transaction processing apparatus 1000 provided by the embodiments of the present application can be the read node described above, and the transaction processing apparatus 1000 includes:
[0252] The transceiver unit 1001 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.
[0253] The transceiver unit 1001 is configured to pull, from the target node, a first transaction state corresponding to the CSN in the 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 prior to the first read request, and the first transaction state includes at least one first mapping relationship, wherein the key in each first mapping relationship is a CSN, and the 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.
[0254] The processing unit 1002 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 the result of the visibility judgment.
[0255] According to the scheme provided by the embodiments of the present application, when processing a 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 of the read node is an incremental transaction state with a CSN greater than the second CSN and less than or equal to the first CSN, and the target node does not need to synchronize the full transaction state to the read node, thereby reducing the data volume of the synchronized transaction state, reducing the performance overhead of processing read transactions, and improving the performance of processing read transactions.
[0256] Optionally, the processing unit 1002 is configured to convert each first mapping relationship into a key-value pair with xid and CSN as the key and the value respectively; convert xmin in the first data record representing a transaction identifier of an insertion transaction into xminCSN and convert xmax in the first data record representing a transaction identifier of a deletion transaction into xmaxCSN according to the key-value pair with xid and CSN; and the read node performs visibility judgment according to the first CSN, xminCSN and xmaxCSN in the first data record.
[0257] Optionally, 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.
[0258] Optionally, the transceiver 1001 is further configured to receive a target xid from the write node, the target xid being used to indicate that data records with xmin less than or equal to the target xid in the data record of the write node are in a frozen state; and delete the key-value pairs with xid less than or equal to the target xid in the hash table.
[0259] Optionally, the processing unit 1002 is further configured to, if the first transaction state further includes at least one second mapping relationship, each second mapping relationship has a rollback sequence number RSN as the key and a transaction identifier xid as the value; correspondingly, the hash table further includes a key-value pair with xid as the key and RSN as the value; if xmin in the target data record cannot be found from the key-value pair with xid and CSN, but xminRSN corresponding to xmin can be found from the key-value pair with xid and RSN, it is determined 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.
[0260] Optionally, the transceiver is further configured to send a snapshot acquisition request to the target node, the snapshot acquisition request including 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 by the target node to extract a second transaction state from the circular array, so as 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, each third mapping relationship having a CSN greater than the first CSN and not greater than the third CSN; and receive the second transaction state from the target node.
[0261] The transceiver 1001 and the processing unit 1002 of the transaction processing apparatus 1000 can be understood with reference to the related content of the read node in the foregoing method embodiment, which will not be repeated here.
[0262] As shown in FIG. 11, the transaction processing apparatus 1100 provided by the embodiments of the present application can be the target node (GTM, write node or CF) introduced above, and the transaction processing apparatus 1100 comprises:
[0263] The transceiver 1101 is configured to receive a transaction state acquisition request sent by the read node, the transaction state acquisition request comprising 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 terms of receiving sequence or processing sequence, and the second read request being prior to the first read request;
[0264] The processing unit 1102 is configured to acquire a first transaction state corresponding to the first CSN and the second CSN according to the first CSN and the second CSN, the first transaction state comprising at least one first mapping relationship, wherein the key in each first mapping relationship is a CSN, and the 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;
[0265] The transceiver 1101 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.
[0266] According to the scheme provided by the embodiments of the present application, 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, thereby reducing the data volume of the synchronized transaction state, reducing the performance overhead of processing the read transaction, and improving the performance of processing the read transaction.
[0267] Optionally, the processing unit 1102 is further configured to acquire a commit sequence number CSN acquisition request initiated by the write node, the CSN acquisition request containing a first transaction identifier xid; allocate a target CSN for the CSN acquisition request, and write a mapping relationship between the target CSN and the first xid into the circular array.
[0268] Optionally, the transceiver 1101 is further configured to receive a snapshot acquisition request from the read node, the snapshot acquisition request containing a 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;
[0269] The processing unit 1102 is further configured to extract a second transaction state from the circular array according to the first CSN and the third CSN, so as to accelerate synchronization of the transaction state stored in the circular array to the read node, the second transaction state comprising 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;
[0270] The transceiver 1101 is further configured to send the second transaction state to the read node.
[0271] Optionally, the processing unit 1102 is further configured to update the transaction state in the circular array.
[0272] The transceiver 1101 and the processing unit 1102 of the transaction processing device 1100 can be understood in the manner of the related content of the target node (GTM, write node or CF) in the foregoing method embodiments, which will not be repeated here.
[0273] FIG. 12 shows a possible logical structure of the transaction processing device 1200 involved in the foregoing embodiments according to an embodiment of 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 connected to each other through the bus 1204. In an embodiment of the present application, the processor 1201 is configured to control and manage the actions of the transaction processing device 1200, for example, the processor 1201 is configured to perform the steps related to determination in FIGS. 2-9, such as the processing steps performed by the read node or the target node in the foregoing steps 203, 205, 206, etc. The communication interface 1202 is configured to support the transaction processing device 1200 to communicate, for example, the communication interface 1202 can perform the steps related to receiving or sending in the foregoing method embodiments. The communication interface 1202 can perform the functions of the transceiver 1001 and the transceiver 1101 in FIGS. 10 and 11. The memory 1203 is configured 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, a field programmable gate array, or other programmable logic device, transistor logic, hardware components, or any combination thereof. It can implement or execute the various exemplary logical blocks, modules and circuits described in connection with the disclosure. The processor can also be a combination of implementing computing 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. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is shown in FIG. 11, but it does not mean that there is only one bus or only one type of bus.
[0275] Referring to FIG. 13, the embodiment of the present application further provides a distributed database system, comprising: a hardware layer 1307 and a virtual machine monitor (VMM) 1301 running on the hardware layer 1307, and a plurality of virtual machines 1302. One virtual machine can serve as a read node or a write node of the distributed database system. Optionally, a virtual machine can also be designated as a coordination node.
[0276] Specifically, the virtual machine 1302 is a virtual computer simulated on a common hardware resource by a virtual machine software, and the virtual machine can install an operating system and an application program, and can also access network resources. For an application program running in the virtual machine, the virtual machine is like working in a real computer.
[0277] The hardware layer 1307: a hardware platform on which a virtualization environment runs, and can be abstracted from hardware resources of one or more physical hosts. The hardware layer can include various hardware, such as a processor 1304 (for example, a CPU) and a memory 1305, and can also include a network card 1303 (for example, an RDMA network card), a high-speed / low-speed input / output (I / O, Input / Output) device, and other devices with specific processing functions.
[0278] The virtual machine 1302 runs an executable program based on the VMM and the hardware resources provided by the hardware layer 1307, to realize part or all of the functions of the transaction processing apparatus in the embodiments related to FIGS. 2 to 9. For brevity, details are not repeated here.
[0279] Further, the distributed database system can further include a host (Host): as a management layer, to complete the management and allocation of hardware resources, to present a virtual hardware platform for the virtual machine, and to realize the scheduling and isolation of the virtual machine. The Host can be a virtual machine monitor (VMM), or can be a combination of the VMM and a privileged virtual machine. The virtual hardware platform provides various hardware resources for each virtual machine running thereon, such as a virtual processor (for example, a VCPU), a virtual memory, a virtual disk, a virtual network card, and the like. The virtual disk can correspond to a file or a logical block device of the Host. The virtual machine runs on the virtual hardware platform prepared by the Host for it, and the Host runs one or more virtual machines. The VCPU of the virtual machine 1302 realizes or executes the method steps described in the above method embodiments of the present application by executing an executable program stored in its corresponding virtual memory. For example, the VCPU realizes part or all of the functions of the transaction processing apparatus 1000 or the transaction processing apparatus 1100 and in the embodiments related to FIGS. 2 to 9.
[0280] In another embodiment of the present application, a computer readable storage medium is also provided, and the computer readable storage medium stores computer-executable instructions. When at least one processor of the device executes the computer-executable instructions, the device performs the transaction processing method described in the foregoing method embodiments of FIG. 2 to FIG. 9.
[0281] In another embodiment of the present application, a computer program product is also provided, and the computer program product includes computer-executable instructions stored in a computer readable storage medium. At least one processor of the device can read the computer-executable instructions from the computer readable storage medium, and the at least one processor executes the computer-executable instructions to cause the device to perform the transaction processing method described in the foregoing method embodiments of FIG. 2 to FIG. 9.
[0282] In another embodiment of the present application, a chip system is also provided, and the chip system includes a processor. The processor is configured to support the transaction processing device to perform the transaction processing method described in the foregoing method embodiments of FIG. 2 to FIG. 9. In a possible design, the chip system can further include a memory. The memory is configured to store necessary program instructions and data for the transaction processing device. The chip system can be composed of a chip, or can include the chip and other discrete devices.
[0283] Those skilled in the art can clearly understand that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software manner depends on the specific application and design constraints of the technical solutions. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of the present application.
[0284] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.
[0285] In the several embodiments of the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic. The division of the units is only a logical function division. There can be another division manner for actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be electrical, mechanical or in other forms.
[0286] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0287] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0288] If the function is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical scheme of the embodiments of the present application or the part that essentially contributes to the prior art or the part of the technical scheme can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of each embodiment of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, and various media that can store program codes.
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 to 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