Transaction processing method, apparatus, device, and medium
By assigning global and sub-transaction numbers to global transactions that are associated across connections and recording their relationships in the transaction association table, and controlling the results of sub-transactions to be invisible until the global transaction is committed and confirmed, the problems of low synchronization efficiency and high resource consumption are solved, and data consistency and resource optimization are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JINZHUAN INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-09-22
- Publication Date
- 2026-07-03
AI Technical Summary
Existing technologies suffer from low synchronization efficiency and high resource consumption when handling global transactions across connections, leading to inconsistencies in data read by downstream databases.
By assigning a global transaction number and a sub-transaction number to sub-transaction requests and writing their association in the transaction association table, the results of sub-transaction processing are controlled to be invisible to the outside world until the global transaction commit instruction confirms that all sub-transactions are successful, at which point they become visible to the outside world.
It improves synchronization efficiency, reduces resource consumption, ensures data consistency for downstream databases at any time, and provides waiting time to ensure that all sub-transactions in the global transaction are completed.
Smart Images

Figure CN115421880B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of data processing technology, and in particular to a transaction processing method, apparatus, device and medium. Background Technology
[0002] Currently, when processing global transactions that are linked across connections, global inconsistencies often occur when querying data.
[0003] In existing technologies, to address the aforementioned problems, global transactions are ordered sequentially and a single connection is established with the downstream database. This means that multiple sub-transactions of the same global transaction are replayed together in the downstream database. However, this method suffers from low synchronization efficiency and high resource consumption. Summary of the Invention
[0004] This invention provides a transaction processing method, apparatus, device, and medium to improve synchronization efficiency and reduce resource consumption.
[0005] According to one aspect of the present invention, a transaction processing method is provided, comprising:
[0006] Extract the global transaction number from the obtained sub-transaction request, and assign a sub-transaction number to the sub-transaction request;
[0007] Write the association relationship between the global transaction number and the sub-transaction number into the transaction association table;
[0008] The sub-transaction is processed to obtain the sub-transaction processing result, and the sub-transaction processing result is persisted and controlled to be invisible to the outside world;
[0009] In response to a commit command for a global transaction, at least two associated sub-transaction numbers are determined based on the transaction association table, and the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers are switched to an externally visible state.
[0010] According to another aspect of the present invention, a transaction processing apparatus is provided, comprising:
[0011] The sub-transaction number allocation module is used to extract the global transaction number from the acquired sub-transaction request and allocate a sub-transaction number to the sub-transaction request;
[0012] The transaction association table determination module is used to write the association relationship between the global transaction number and the sub-transaction number into the transaction association table;
[0013] The invisible state control module is used to process the sub-transaction to obtain the sub-transaction processing result, persist the sub-transaction processing result, and control the sub-transaction processing result to be in an invisible state.
[0014] The externally visible state switching module is used to respond to the commit command of the global transaction, determine at least two associated sub-transaction numbers according to the transaction association table, and switch the sub-transaction processing results corresponding to the at least two sub-transaction numbers to an externally visible state.
[0015] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0016] At least one processor; and
[0017] A memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the transaction processing method according to any embodiment of the present invention.
[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the transaction processing method described in any embodiment of the present invention.
[0020] This invention provides a transaction processing scheme that adds a global transaction number to a global transaction requiring cross-connection association. Based on sub-transaction requests, the global transaction number is obtained and assigned a sub-transaction number. A transaction association table records the association between global transaction numbers and sub-transaction numbers. In response to the global transaction commit command, all sub-transaction numbers corresponding to the global transaction number are found in the transaction association table, and the processing results of the sub-transactions corresponding to those sub-transaction numbers are made visible externally. This scheme enables parallel data synchronization, exhibits superior concurrency performance, improves synchronization efficiency, and ensures data consistency for downstream databases at any given time. Furthermore, the internal processing mechanism of this scheme is simple and consumes few resources. Additionally, this scheme provides a state where the sub-transaction processing results are not visible externally, providing waiting time for processing cross-connection global transactions and ensuring that all sub-transactions within the global transaction are completed.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a flowchart of a transaction processing method provided in Embodiment 1 of the present invention;
[0024] Figure 2A This is a flowchart of a transaction processing method provided in Embodiment 2 of the present invention;
[0025] Figure 2B This is a data synchronization scenario diagram provided in Embodiment 2 of the present invention;
[0026] Figure 2C This is a scenario diagram of a modular application architecture provided in Embodiment 2 of the present invention;
[0027] Figure 3 This is a schematic diagram of the structure of a transaction processing device provided in Embodiment 3 of the present invention;
[0028] Figure 4 This is a schematic diagram of the structure of an electronic device that implements a transaction processing method according to Embodiment 4 of the present invention. Detailed Implementation
[0029] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.
[0030] To better understand the technical solutions of the embodiments of the present invention, the global inconsistencies will first be explained.
[0031] Global inconsistency refers to a situation in cross-connection transaction mechanisms where sub-transactions within a global transaction commit asynchronously. This means that when querying the results of sub-transactions in the downstream database, at least some parts are missing. The following explanation uses a distributed database as an example.
[0032] Based on a distributed database, this system handles cross-connection global transactions. The distributed database includes a first data shard and a second data shard. When data is modified simultaneously on both shards, sub-transaction A is generated on the first shard, and sub-transaction B is generated on the second shard. A synchronization tool starts two synchronization processes: process 1 synchronizes the first data shard and parses and replays the logs of sub-transaction A; process 2 synchronizes the second data shard and parses and replays the logs of sub-transaction B, synchronizing the data to the downstream database. Because the two processes lack transaction control, sub-transaction A is replayed to the downstream database, but sub-transaction B is not. This results in the downstream database reading data that only contains updates from sub-transaction A, excluding updates from sub-transaction B, leading to inconsistencies—a global inconsistency. This global inconsistency problem becomes more pronounced as the synchronization progress of the two shards widens.
[0033] Example 1
[0034] Figure 1 This is a flowchart of a transaction processing method provided in Embodiment 1 of the present invention. This embodiment is applicable to situations involving transaction processing. The transaction processing device can be implemented in hardware and / or software and can be integrated into an electronic device that carries transaction processing functions.
[0035] S110. Extract the global transaction number from the obtained sub-transaction request and assign a sub-transaction number to the sub-transaction request.
[0036] A sub-transaction request refers to a portion of a transaction request initiated to achieve a specific function. Specifically, a transaction request to achieve a function may involve multiple parts that work to implement that function. To ensure the function is implemented more accurately, the transaction request is divided into sub-transaction requests based on the function of each part. For any sub-transaction request, the function of the corresponding part can be displayed. For example, if the transaction request is for A to transfer 'a' yuan to B, then the first sub-transaction request is for A to spend 'a' yuan, and the second sub-transaction request is for B to receive 'a' yuan.
[0037] The global transaction number (Global_trans) refers to the number in each sub-transaction request that proves the relationship between the sub-transaction requests. Specifically, for any given transaction request, the transaction request has a unique global transaction number, and each sub-transaction request constituting the transaction request also has the same global transaction number, indicating that there is a relationship between the sub-transaction requests in the transaction request. The global transaction number can be displayed in at least one way, such as numbers and letters, and this embodiment of the invention does not limit this. Continuing the previous example, if the first sub-transaction request is A spending a yuan, and the second sub-transaction request is B receiving a yuan, both of which are part of the transaction request A transferring a yuan to B, then the global transaction numbers in the first and second transaction requests are consistent and the same as the global transaction number in the transaction request. That is, if Global_trans=10001 in the transaction request, then Global_trans=10001 in both the first and second transaction requests.
[0038] In this context, the sub-transaction number (Tid) can be understood as a unique identifier for a sub-transaction request. Specifically, while all sub-transaction requests share the same global transaction number, different sub-transaction numbers are assigned to distinguish them. The sub-transaction number can be displayed using at least one of numbers and letters, and this embodiment of the invention does not impose any limitations on this. Continuing the previous example, the sub-transaction number corresponding to the first sub-transaction request can be the first sub-transaction number, and the sub-transaction number corresponding to the second sub-transaction request can be the second sub-transaction number. The first and second sub-transaction numbers are different; for example, the first sub-transaction number is Tid1, and the second sub-transaction number is Tid2. It should be noted that the sub-transaction number can be set by technical personnel as needed.
[0039] Specifically, the process involves obtaining sub-transaction requests, extracting the global transaction number from the sub-transaction requests, and assigning different sub-transaction numbers to sub-transaction requests that have the same global transaction number.
[0040] S120. Write the association between the global transaction number and the sub-transaction number into the transaction association table.
[0041] The transaction association table records the global transaction number and the sub-transaction number in any sub-transaction request.
[0042] Specifically, for any sub-transaction request, the transaction association table can record the global transaction number of that sub-transaction request and the corresponding sub-transaction number for subsequent processing.
[0043] S130. Process the sub-transaction to obtain the sub-transaction processing result, persist the sub-transaction processing result, and control the sub-transaction processing result to be invisible to the outside world.
[0044] Here, the sub-transaction processing result refers to the processing result obtained by processing the sub-transaction according to the sub-transaction request. Persistence refers to saving the sub-transaction processing result. Externally invisible state means that the sub-transaction processing result is not visible to the outside world.
[0045] Specifically, based on the sub-transaction request, the sub-transaction is processed to obtain the sub-transaction processing result, which is then saved and kept in a non-publicly visible state.
[0046] S140. In response to the commit instruction for the global transaction, determine at least two associated sub-transaction numbers according to the transaction association table, and switch the sub-transaction processing results corresponding to the at least two sub-transaction numbers to an externally visible state.
[0047] The commit instruction (such as `commit`) for a global transaction is used to indicate that the results of sub-transactions within the global transaction are visible to the outside world. Specifically, the commit instruction for a global transaction is generated if at least two associated sub-transactions succeed. That is, if the global transaction includes at least two associated sub-transactions, the commit instruction for the global transaction is generated when both of these sub-transactions succeed. If any one of the at least two associated sub-transactions fails, the global transaction fails, and the commit instruction for the global transaction cannot be generated.
[0048] Understandably, generating a global transaction commit instruction only when at least two associated sub-transactions are successfully completed can prevent situations where the generated commit instruction cannot accurately reflect the sub-transaction results if any sub-transaction fails, thus avoiding missing or incorrect sub-transaction results visible to the outside world and improving the accuracy of the generated commit instruction.
[0049] The externally visible state refers to the fact that the results of the sub-transaction processing are visible to the outside world.
[0050] Specifically, if at least two sub-transactions within the global transaction succeed, a commit instruction for the global transaction is generated. The sub-transaction numbers corresponding to the at least two sub-transactions within the global transaction are determined from the transaction association table, and the processing results of the sub-transactions corresponding to these at least two sub-transaction numbers are switched from an externally invisible state to an externally visible state. If any one of the at least two sub-transactions within the global transaction fails during processing, then the at least two sub-transactions within the global transaction are reprocessed.
[0051] In one optional embodiment, reprocessing at least two sub-transactions within a global transaction can be achieved by: in response to a rollback instruction for the global transaction, determining the numbers of at least two associated sub-transactions based on a transaction association table, and rolling back the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers; wherein, the rollback instruction for the global transaction (e.g., rollback) is used to reprocess at least two sub-transactions within the global transaction. The rollback instruction is generated if any of the associated sub-transactions fails.
[0052] Specifically, for at least two sub-transactions within a global transaction, if any sub-transaction fails, a rollback instruction for the global transaction can be generated. Based on the transaction association table, at least two related sub-transaction numbers are identified, and the processing results of the sub-transactions corresponding to these at least two sub-transaction numbers are rolled back. This means the sub-transactions are processed again to obtain new sub-transaction processing results, which are then recorded in the transaction association table. Optionally, when recording new sub-transaction processing results, the transaction association table can overwrite the atomic transaction processing results corresponding to the sub-transaction numbers; alternatively, it can mark the new sub-transaction processing results and their corresponding sub-transaction numbers as a new version for subsequent use.
[0053] Understandably, by introducing rollback instructions, the results of any associated sub-transaction are rolled back when the sub-transaction fails, thus achieving atomicity of sub-transactions within the global transaction, preventing errors in the externally visible sub-transaction results, and improving the accuracy of sub-transaction results.
[0054] This invention provides a transaction processing scheme that adds a global transaction number to a global transaction requiring cross-connection association. Based on sub-transaction requests, the global transaction number is obtained and assigned a sub-transaction number. A transaction association table records the association between global transaction numbers and sub-transaction numbers. In response to the global transaction commit command, all sub-transaction numbers corresponding to the global transaction number are found in the transaction association table, and the processing results of the sub-transactions corresponding to those sub-transaction numbers are made visible externally. This scheme enables parallel data synchronization, exhibits superior concurrency performance, improves synchronization efficiency, and ensures data consistency for downstream databases at any given time. Furthermore, the internal processing mechanism of this scheme is simple and consumes few resources. Additionally, this scheme provides a state where the sub-transaction processing results are not visible externally, providing waiting time for processing cross-connection global transactions and ensuring that all sub-transactions within the global transaction are completed.
[0055] In this embodiment of the invention, in order to ensure that the commit instruction is generated when all sub-transactions in the global transaction have completed processing, a synchronous negotiation process can be added. That is, after the first sub-transaction in the global transaction completes processing, it will send queries to the other sub-transactions in the global transaction to inquire whether the other sub-transactions have completed processing. If all receive positive replies, the commit instruction of the global transaction is generated.
[0056] Example 2
[0057] Figure 2A This is a flowchart of a transaction processing method provided in Embodiment 2 of the present invention. Based on the above embodiments, this embodiment further refines the operation of "writing the association relationship between the global transaction number and the sub-transaction number into the transaction association table" to "if the transaction association table includes the global transaction number, then obtain the global internal number associated with the global transaction number from the transaction association table, and write the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table; otherwise, use the sub-transaction number as the global internal number associated with the global transaction number, and write the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table," thereby improving the mechanism for determining the transaction association table. It should be noted that for parts not detailed in this embodiment, please refer to the descriptions in other embodiments.
[0058] See Figure 2A The transaction processing methods shown include:
[0059] S210. Extract the global transaction number from the obtained sub-transaction request and assign a sub-transaction number to the sub-transaction request.
[0060] S220. If the transaction association table includes the global transaction number, then obtain the global internal number associated with the global transaction number from the transaction association table, and write the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table.
[0061] The global internal ID (Global_tid) serves the same purpose as the global transaction ID, identifying the relationships between sub-transaction requests. The global internal ID is determined based on the sub-transaction ID corresponding to the first sub-transaction in the global transaction. For example, if the sub-transaction ID corresponding to the first sub-transaction in the global transaction is Tid1, then the global internal ID is Tid1. The advantage of setting a global internal ID is that when the global transaction ID is long, a shorter global internal ID can be used, reducing resource usage during transaction processing. It should be noted that the global internal ID is not mandatory; its existence can be determined based on the specific circumstances.
[0062] Specifically, if the global transaction number is found in the transaction association table, the global internal number associated with the global transaction number is obtained from the transaction association table, and based on the global transaction number, the global internal number and the sub-transaction number are written into the position corresponding to the global transaction number in the transaction association table.
[0063] S230. Otherwise, use the sub-transaction number as the global internal number associated with the global transaction number, and write the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table.
[0064] Specifically, if the global transaction number is not found in the transaction association table, a preset number of records are inserted, writing the global transaction number, the global internal number, and the sub-transaction number into the transaction association table. The preset number of records is determined based on the number of sub-transactions included in the global transaction, which refers to a global transaction whose global transaction number is not found in the transaction association table.
[0065] For example, consider a first and second sub-transaction that are related. If the global transaction number of the first and second sub-transactions is 10001, the internal sub-transaction number of the first sub-transaction is Tid1, and the internal sub-transaction number of the second sub-transaction is Tid2, then if no record with a global transaction number of 10001 is found in the transaction association table, two records are inserted into the transaction association table, as shown in Table 1.
[0066] In Table 1, Global_trans represents the global transaction number, and 10001 is the specific value of the global transaction number; Global_tid represents the global internal number, and Tid1 is the specific value of the global internal number, which is determined by the first sub-transaction number; Tid represents the sub-transaction number, with Tid1 being the first sub-transaction number and Tid2 being the second sub-transaction number.
[0067] Table 1. Inserted Records in the Transaction Association Table
[0068]
[0069] S240. Process the sub-transaction to obtain the sub-transaction processing result, persist the sub-transaction processing result, and control the sub-transaction processing result to be invisible to the outside world.
[0070] In one optional embodiment, processing a sub-transaction to obtain a sub-transaction processing result, persisting the sub-transaction processing result, and controlling the sub-transaction processing result to be in an externally invisible state includes: processing a sub-transaction to obtain a sub-transaction processing result and writing the sub-transaction processing result into memory; in response to a pre-commit instruction for a sub-transaction, persisting the sub-transaction processing result and controlling the sub-transaction processing result to be in an externally invisible state.
[0071] Among them, pre-commit instructions (such as precommit and subcommit) are instructions that control the result of a sub-transaction to be in a pending-commit state.
[0072] Specifically, based on the sub-transaction request, the sub-transaction is processed to obtain the sub-transaction processing result, which is then written into memory. When at least some sub-transactions have not been completed, based on the pre-commit instruction, the obtained sub-transaction processing results are persisted and controlled to be in an invisible state to the outside world.
[0073] Understandably, by introducing the pre-commit instruction to persist the results of sub-transactions and control the results of sub-transactions to be invisible to the outside world, the isolation of each sub-transaction in the global transaction is achieved. This can avoid the situation where the results of sub-transactions are missing when they are visible to the outside world, and improve the integrity of the results of sub-transactions when they are visible to the outside world.
[0074] S250. In response to the commit instruction for the global transaction, determine at least two associated sub-transaction numbers according to the transaction association table, and switch the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers to an externally visible state.
[0075] This invention provides a transaction processing scheme that, if the transaction association table includes a global transaction number, retrieves the global internal number associated with the global transaction number from the transaction association table and writes the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table; otherwise, uses the sub-transaction number as the global internal number associated with the global transaction number and writes the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table. This achieves the goal of adding content to the transaction association table while fully considering its contents, thereby improving the comprehensiveness of the content in the transaction association table and providing a foundation for subsequent processing based on the transaction association table.
[0076] In this embodiment of the invention, no limitations are placed on the application scenarios of the transaction processing method. Optionally, the transaction processing method is applied in data synchronization scenarios, or optionally, it is applied in unitized application architecture scenarios.
[0077] In one optional embodiment, the transaction processing method is applied to a data synchronization scenario. When the upstream database in the data synchronization scenario is a distributed database, sub-transaction requests are generated by each synchronization node based on the data to be synchronized in the corresponding data shard; the data to be synchronized are interconnected. The distributed database, as an online transaction processing (OLTP) system, needs to synchronize data to the downstream database in real time for further processing. Data shards are part of the distributed database. Synchronization nodes can be used to process sub-transactions. The data to be synchronized refers to the data in the distributed database.
[0078] Specifically, because there are multiple data shards in a distributed database, concurrent data synchronization between data shards has high performance. However, when multiple data shards synchronize data to downstream databases, the data between data shards is submitted asynchronously in the downstream databases, which leads to a global inconsistency problem when the application queries data in the downstream databases.
[0079] To address the global inconsistency issue that arises when downstream databases query data in a distributed database environment, Figure 2B The following diagram illustrates a data synchronization scenario. In this scenario, there are an upstream distributed database, a data synchronization tool, and a downstream database. The upstream distributed database includes compute nodes and a global transaction manager; the data synchronization tool includes a first synchronization node and a second synchronization node, and these two nodes are interconnected.
[0080] Continuing the previous example, if the first synchronization node starts the first sub-transaction and the second synchronization node starts the second sub-transaction, and the global transaction number extracted from the first and / or second sub-transaction requests is 10001, then the global transaction number for both the first and second sub-transactions is 10001. The downstream database generates Tid1 as the first sub-transaction number and Tid2 as the second sub-transaction number, and writes the association between the global transaction number 10001 and the first sub-transaction number Tid1 into the transaction association table. Similarly, the association between the global transaction number 10001 and the second sub-transaction number Tid2 is written into the transaction association table. Since the first and second sub-transactions have the same global transaction number, the downstream database associates the first and second sub-transactions and processes them as a single global transaction.
[0081] Continuing the previous example, data operations are used to replay the first transaction processing result obtained by the first synchronization node and the second transaction processing result obtained by the second synchronization node back into the transaction association table in the downstream database. For example, data operations can include at least one of the statements UPDATE, DELETE, and INSERT. It should be noted that when the first synchronization node completes the first sub-transaction, it initiates a pre-commit instruction to persist the first transaction processing result in the transaction association table of the downstream database and makes the first transaction processing result invisible; similarly, when the second synchronization node completes the second sub-transaction, it initiates a pre-commit instruction to persist the second transaction processing result and makes the second transaction processing result invisible. When both the first and second synchronization nodes have completed their sub-transactions, the first synchronization node initiates a commit instruction to make both the first and second processing results visible.
[0082] Continuing the previous example, when the upstream distributed database commits a global transaction, the compute nodes mark the first data shard g1 and the second data shard g2 involved in the global transaction at the commit time, and pass this to the first data shard via the "commit on g1,g2" statement. Upon receiving the "commit on g1,g2" request, the first data shard writes "commit on g1,g2" to the binlog (binary log) and simultaneously writes the global transaction number of the global transaction to the binlog. When the first synchronization node parses the binlog, it performs synchronization negotiation. The synchronization negotiation process is as follows: the first synchronization node queries the second synchronization node to inquire whether the second synchronization node has completed the second sub-transaction and written the result of the second transaction to the transaction association table. If the second synchronization node has completed the aforementioned operations, it sends an affirmative statement back to the first synchronization node. Upon receiving the affirmative statement from the second synchronization node, the first synchronization node generates a commit command. The benefit of performing synchronization negotiation is that it ensures that both the first and second sub-transactions in the global transaction have been completed.
[0083] In another alternative embodiment, when the transaction processing method is applied to a unitized application architecture scenario, the transaction request is generated by each application unit according to the corresponding application function; the application functions are interconnected.
[0084] Among them, the modular application architecture refers to using an upper-layer application system to break down the complete functionality of an application into multiple application units. Each application unit executes a part of the functionality, and multiple application units collaborate to form a complete application.
[0085] See Figure 2CThe illustrated modular application architecture scenario diagram is exemplified as follows: if the scenario diagram is a money transfer application, the first application unit is responsible for the deduction function (such as deducting 'a' yuan from account A), and the second application unit is responsible for the addition function (such as depositing 'a' yuan into account B). The first and second application units complete a global transaction of a money transfer, and the first and second application units respectively initiate independent connections with the database. Specifically, if the first application unit starts a transaction to deduct 'a' yuan from account A, and the second application unit starts a transaction to add 'a' yuan to account B, the global transaction number extracted from the transaction requests for deducting 'a' yuan from account A and / or adding 'a' yuan to account B is 10002. Therefore, the global transaction number for both the transaction deducting 'a' yuan from account A and adding 'a' yuan to account B is 10002. The downstream database generates Tid11 as the transaction number for deducting 'a' yuan from account A and Tid22 as the transaction number for adding 'a' yuan to account B, and writes the association between the global transaction number 10002 and the transaction number Tid11 for deducting 'a' yuan from account A into the transaction association table. Similarly, the association between the global transaction number 10002 and the transaction number Tid22 for adding 'a' yuan to account B is written into the transaction association table. Since the global transaction numbers for deducting 'a' yuan from account A and adding 'a' yuan to account B are the same, the downstream database associates these two transactions and processes them as a single global transaction.
[0086] Continuing the previous example, the first application unit initiates a data update, receiving the result that account A has been deducted 'a' yuan; the second application unit initiates a data update, receiving the result that account B has been topped up with 'a' yuan. It should be noted that when the first application unit completes the transaction of deducting 'a' yuan from account A, it initiates a pre-commit instruction. The downstream database persists the result of the deduction of 'a' yuan from account A and controls the result of the deduction to be invisible to the outside world. Similarly, when the second application unit completes the transaction of topping up 'a' yuan from account B, it initiates a pre-commit instruction. The downstream database persists the result of the topping up 'a' yuan from account B and controls the result of the topping up 'a' yuan from account B and the result of the topping up 'a' yuan from account B. When the first application unit completes the transaction of deducting 'a' yuan from account A and the second application unit completes the transaction of topping up 'a' yuan from account B, the first application unit initiates a commit instruction, controlling the results of the sub-transactions of the first and second application units to be visible to the outside world.
[0087] Continuing from the previous example, if the first application unit and / or the second application unit fail to process a sub-transaction, either of the two application units will initiate a rollback instruction. This rollback instruction will control the two application units to roll back the corresponding sub-transactions simultaneously, so as to achieve the atomicity of the two sub-transactions.
[0088] This invention provides two methods for generating sub-transaction requests, which in turn provide two application scenarios for transaction processing, illustrating part of the application scope of this invention, so as to better apply the transaction processing methods provided by this invention.
[0089] Example 3
[0090] Figure 3 This is a schematic diagram of a transaction processing device provided in Embodiment 3 of the present invention. This embodiment is applicable to situations involving transaction processing. The transaction processing device can be implemented in hardware and / or software and can be integrated into an electronic device that carries transaction processing functionality. Figure 3 As shown, the transaction processing apparatus of this embodiment includes: a sub-transaction number allocation module 310, a transaction association table determination module 320, an invisible state control module 330, and an externally visible state switching module 340. Among them,
[0091] The sub-transaction number allocation module 310 is used to extract the global transaction number from the obtained sub-transaction request and allocate a sub-transaction number to the sub-transaction request;
[0092] The transaction association table determination module 320 is used to write the association relationship between the global transaction number and the sub-transaction number into the transaction association table;
[0093] The invisible state control module 330 is used to process sub-transactions to obtain sub-transaction processing results, persist the sub-transaction processing results, and control the sub-transaction processing results to be in an invisible state.
[0094] The externally visible state switching module 340 is used to respond to the commit command of the global transaction, determine the numbers of at least two associated sub-transactions according to the transaction association table, and switch the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers to an externally visible state.
[0095] This invention provides a transaction processing scheme. A sub-transaction number allocation module extracts the global transaction number from the acquired sub-transaction requests and assigns a sub-transaction number to each request. A transaction association table determination module writes the association between the global transaction number and the sub-transaction number into the transaction association table. An invisible state control module processes the sub-transactions to obtain the sub-transaction processing results, persists these results, and controls them to be invisible to the outside world. An externally visible state switching module responds to the commit command of the global transaction, determines at least two associated sub-transaction numbers based on the transaction association table, and switches the sub-transaction processing results corresponding to these numbers to an externally visible state. This scheme enables parallel data synchronization, exhibits superior concurrency performance, improves synchronization efficiency, and ensures data consistency for downstream databases at any given time. Furthermore, the internal processing mechanism is simple and consumes few resources. Additionally, the scheme provides an externally invisible state for sub-transaction processing results, allowing waiting time for processing cross-connection global transactions and ensuring that all sub-transactions within the global transaction are completed.
[0096] Optionally, the transaction association table determination module 320 includes:
[0097] The first transaction association table determination unit is used to obtain the global internal number associated with the global transaction number from the transaction association table if the transaction association table includes the global transaction number, and write the association relationship between the global transaction number, the global internal number and the sub-transaction number into the transaction association table.
[0098] The second transaction association table determination unit is used otherwise to treat the sub-transaction number as the global internal number associated with the global transaction number, and to write the association relationship between the global transaction number, the global internal number, and the sub-transaction number into the transaction association table.
[0099] Optional, invisible state control module 330, including:
[0100] The sub-transaction processing result determination unit is used to process the sub-transaction to obtain the sub-transaction processing result and write the sub-transaction processing result into memory;
[0101] The externally invisible state control unit is used to persist the sub-transaction processing results in response to the pre-commit instruction for the sub-transaction and control the sub-transaction processing results to be in an externally invisible state.
[0102] Optionally, in this device, the commit instruction for the global transaction is generated if at least two associated sub-transactions are successfully processed.
[0103] Optionally, the device may also include:
[0104] The rollback module is used to respond to rollback instructions for global transactions. It determines at least two associated sub-transaction numbers based on the transaction association table and rolls back the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers. The rollback instruction is generated if any associated sub-transaction fails.
[0105] Optionally, in this device, sub-transaction requests are generated by each synchronization node based on the data to be synchronized in the corresponding data shard; the data to be synchronized are interconnected.
[0106] Optionally, in this device, sub-transaction requests are generated by each application unit according to the corresponding application function; the application functions are interconnected.
[0107] The transaction processing apparatus provided in the embodiments of the present invention can execute the transaction processing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing each transaction processing method.
[0108] In the technical solution of this invention, the collection, storage, use, processing, transmission, provision and disclosure of sub-transaction requests and sub-transaction processing results all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0109] Example 4
[0110] Figure 4 This is a schematic diagram of the structure of an electronic device 10 implementing a transaction processing method according to Embodiment 4 of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0111] like Figure 4As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0112] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0113] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as transaction processing methods.
[0114] In some embodiments, the transaction processing method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the transaction processing method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the transaction processing method by any other suitable means (e.g., by means of firmware).
[0115] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0116] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0117] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0118] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0119] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0120] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0121] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0122] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A transaction processing method, characterized by, include: Extract the global transaction number from the obtained sub-transaction request, and assign a sub-transaction number to the sub-transaction request; Write the association relationship between the global transaction number and the sub-transaction number into the transaction association table; The sub-transaction is processed to obtain the sub-transaction processing result, and the sub-transaction processing result is persisted and controlled to be invisible to the outside world; In response to the commit command for the global transaction, at least two associated sub-transaction numbers are determined according to the transaction association table, and the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers are switched to an externally visible state. The step of writing the association relationship between the global transaction number and the sub-transaction number into the transaction association table includes: If the transaction association table includes the global transaction number, then the global internal number associated with the global transaction number is obtained from the transaction association table, and the association relationship between the global transaction number, the global internal number and the sub-transaction number is written into the transaction association table; Otherwise, the sub-transaction number is used as the global internal number associated with the global transaction number, and the association relationship between the global transaction number, the global internal number, and the sub-transaction number is written into the transaction association table; Wherein, the step of using the sub-transaction number as the global internal number associated with the global transaction number includes: The subtransaction number corresponding to the first subtransaction in the global transaction is used as the global internal number.
2. The method of claim 1, wherein, The process of processing the sub-transaction to obtain the sub-transaction processing result, persisting the sub-transaction processing result, and controlling the sub-transaction processing result to be invisible to the outside world includes: The sub-transaction is processed to obtain the sub-transaction processing result, and the sub-transaction processing result is written into memory; In response to a pre-commit instruction for a sub-transaction, the result of the sub-transaction is persisted and controlled to be invisible to the outside world.
3. The method according to claim 1, characterized in that, A commit instruction for a global transaction is generated only if at least two associated sub-transactions are successfully completed.
4. The method according to claim 1, characterized in that, Also includes: In response to a rollback instruction for a global transaction, at least two associated sub-transaction numbers are determined according to the transaction association table, and the processing results of the sub-transactions corresponding to the at least two sub-transaction numbers are rolled back; the rollback instruction is generated if any associated sub-transaction fails.
5. The method according to claim 1, wherein, The sub-transaction requests are generated by each synchronization node based on the data to be synchronized in the corresponding data shard; the data to be synchronized are interconnected.
6. The method according to claim 1, wherein, The sub-transaction requests are generated by each application unit according to the corresponding application function; the application functions are interconnected.
7. A transaction processing apparatus, characterized in that, include: The sub-transaction number allocation module is used to extract the global transaction number from the acquired sub-transaction request and allocate a sub-transaction number to the sub-transaction request; The transaction association table determination module is used to write the association relationship between the global transaction number and the sub-transaction number into the transaction association table; The invisible state control module is used to process the sub-transaction to obtain the sub-transaction processing result, persist the sub-transaction processing result, and control the sub-transaction processing result to be in an invisible state. The externally visible state switching module is used to respond to the commit command of the global transaction, determine at least two associated sub-transaction numbers according to the transaction association table, and switch the sub-transaction processing results corresponding to the at least two sub-transaction numbers to an externally visible state. The transaction association table determination module includes: The first transaction association table determination unit is used to obtain the global internal number associated with the global transaction number from the transaction association table if the global transaction number is included in the transaction association table, and write the association relationship between the global transaction number, the global internal number and the sub-transaction number into the transaction association table; The second transaction association table determination unit is used to, otherwise, use the sub-transaction number as the global internal number associated with the global transaction number, and write the association relationship between the global transaction number, the global internal number and the sub-transaction number into the transaction association table; The second transaction association table determination unit is specifically used for: The subtransaction number corresponding to the first subtransaction in the global transaction is used as the global internal number.
8. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement a transaction processing method as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements a transaction processing method as described in any one of claims 1-6.