Transaction processing method and apparatus, electronic device, and storage medium

CN115712488BActive Publication Date: 2026-08-07JINZHUAN INFORMATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
JINZHUAN INFORMATION TECHNOLOGY CO LTD
Filing Date
2022-11-18
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0004]本申请提供了一种事务处理方法、装置、电子设备及存储介质,以解决现有技术中当事务内存在一条语句执行失败,通常是将整个事务进行回退,导致事务的执行效率较低的问题

Benefits of technology

[0045]在本申请实施例中,通过接收客户端发送的目标语句,所述目标语句为目标事务内的任一语句;对所述目标语句进行语法解析,得到至少一个可执行子语句;将预先定义的所述目标语句对应的保存点携带于所述可执行子语句中,并发送给数据节点,以供所述数据节点基于所述目标语句对应的保存点,保存各所述可执行子语句对应分片的初始数据,并执行各所述可执行子语句,得到各所述可执行子语句对应的处理结果;接收所述数据节点返回的所述处理结果;在所述处理结果指示目标分片的可执行子语句执行失败的情况下,向所述数据节点发送回退指令,以供所述数据节点将除所述目标分片之外的其他分片的数据回退至各自对应的初始数据,并生成回退成功响应,所述目标分片为各所述可执行子语句对应分片中的任一分片;接收所述数据节点返回的所述回退成功响应,并基于所述回退成功响应向所述客户端发送所述目标语句的执行结果。通过上述方式,在执行目标事务内的目标语句时,如果目标分片的可执行子语句执行失败,则可以将除目标分片之外的其他分片的数据回退至各自对应的初始数据,从而保证了事务的一致性;同时,由于只需要将目标语句进行回退,而无需将整个目标事务进行回退,有效提高了目标事务的执行效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115712488B_ABST
    Figure CN115712488B_ABST
Patent Text Reader

Abstract

The application relates to a transaction processing method and device, electronic equipment and a storage medium. The method comprises the following steps: receiving a target statement sent by a client; performing syntax analysis on the target statement to obtain at least one executable sub-statement; carrying a pre-defined save point corresponding to the target statement in the executable sub-statement and sending the executable sub-statement to a data node; receiving a processing result returned by the data node; in the case that the processing result indicates that the executable sub-statement of a target shard fails to execute, sending a rollback instruction to the data node, so that the data node rolls back the data of shards other than the target shard to the initial data corresponding to the respective shards, and generates a rollback success response; receiving the rollback success response returned by the data node, and sending an execution result of the target statement to the client based on the rollback success response. In this way, the consistency of the transaction can be ensured, and the execution efficiency of the target transaction can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of distributed transaction processing technology, and in particular to a transaction processing method, apparatus, electronic device and storage medium. Background Technology

[0002] With the rapid development of computer technology and the national economy, the amount of data and the scale of users in the financial industry have experienced explosive growth. Traditional centralized databases can no longer meet the current needs for storing and processing massive amounts of data. Therefore, distributed databases have emerged, and the consistency problem of distributed transactions is one of the current research hotspots.

[0003] In distributed databases, for ease of scalability and load balancing, appropriate distribution rules are often adopted to distribute data reasonably and evenly across different shards. Thus, a single statement within a transaction may involve accessing and modifying data on multiple nodes. Consequently, when executing a distributed transaction, if a statement within the transaction fails, the failed shard will automatically roll back to its state before the statement's execution, while the successful shard will retain the results of the statement's execution. This results in some shards failing and others succeeding, thus compromising transaction consistency. However, to ensure transaction consistency, current technologies typically roll back the entire transaction, leading to low execution efficiency. Therefore, how to simultaneously achieve both high efficiency and consistency in transactions has become a pressing technical problem. Summary of the Invention

[0004] This application provides a transaction processing method, apparatus, electronic device, and storage medium to solve the problem in the prior art that when a statement within a transaction fails to execute, the entire transaction is usually rolled back, resulting in low transaction execution efficiency.

[0005] In a first aspect, this application provides a transaction processing method applied to a computing node, the method comprising:

[0006] Receive the target statement sent by the client, where the target statement is any statement within the target transaction;

[0007] The target statement is parsed to obtain at least one executable substatement;

[0008] The predefined save point corresponding to the target statement is carried in the executable sub-statement and sent to the data node, so that the data node can save the initial data of the corresponding fragment of each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement.

[0009] Receive the processing result returned by the data node;

[0010] If the processing result indicates that the executable sub-statement of the target fragment has failed to execute, a rollback instruction is sent to the data node so that the data node rolls back the data of other fragments except the target fragment to their respective initial data and generates a rollback success response. The target fragment is any fragment among the fragments corresponding to each executable sub-statement.

[0011] The system receives the rollback success response returned by the data node and sends the execution result of the target statement to the client based on the rollback success response.

[0012] Optionally, the step of carrying the predefined savepoint corresponding to the target statement in the executable sub-statement and sending it to the data node includes:

[0013] The savepoint corresponding to the target statement is appended to the executable substatement as a comment and sent to the data node.

[0014] Optionally, the step of carrying the predefined savepoint corresponding to the target statement in the executable sub-statement and sending it to the data node further includes:

[0015] If there are multiple executable sub-statements, and at least two of the multiple executable sub-statements correspond to the same fragment on the data node, the save point corresponding to the target statement is carried in the first of the at least two executable sub-statements and sent to the data node.

[0016] Optionally, after receiving the processing result returned by the data node, the method further includes:

[0017] If the processing result indicates that each of the executable sub-statements was executed successfully, the execution result of the target statement is sent directly to the client.

[0018] Secondly, this application also provides a transaction processing method applied to data nodes, the method comprising:

[0019] The system receives at least one executable sub-statement sent by the computing node and parses it to obtain the save point corresponding to the target statement carried in each executable sub-statement. The save point corresponding to the target statement is predefined. The executable sub-statement is obtained by the computing node through syntax parsing of the target statement. The target statement is any statement in the target transaction sent by the client to the computing node.

[0020] Based on the save point corresponding to the target statement, the initial data of the slice corresponding to each executable sub-statement is saved, and each executable sub-statement is executed to obtain the processing result corresponding to each executable sub-statement;

[0021] The processing result is sent to the computing node;

[0022] Upon receiving a rollback instruction from the computing node, the data of all fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated. The target fragment is any fragment among the fragments corresponding to each executable sub-statement. The rollback instruction is generated by the computing node when the processing result indicates that the executable sub-statement of the target fragment has failed to execute.

[0023] The rollback success response is sent to the computing node, so that the computing node can send the execution result of the target statement to the client based on the rollback success response.

[0024] Optionally, upon receiving a rollback instruction from the computing node, the data of all fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated, including:

[0025] Upon receiving a rollback instruction from the computing node, the savepoint corresponding to the target statement carried in the rollback instruction is parsed and obtained.

[0026] Based on the save point corresponding to the target statement, determine the initial data corresponding to other fragments besides the target fragment;

[0027] The data of all other fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated.

[0028] Thirdly, this application also provides a transaction processing apparatus applied to a computing node, the apparatus comprising:

[0029] The first receiving module is used to receive the target statement sent by the client, wherein the target statement is any statement within the target transaction;

[0030] The syntax parsing module is used to perform syntax parsing on the target statement to obtain at least one executable substatement;

[0031] The first sending module is used to carry the predefined save point corresponding to the target statement in the executable sub-statement and send it to the data node, so that the data node can save the initial data of the corresponding fragment of each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement.

[0032] The second receiving module is used to receive the processing result returned by the data node;

[0033] The second sending module is used to send a rollback instruction to the data node when the processing result indicates that the executable sub-statement of the target segment has failed to execute, so that the data node can roll back the data of other segments except the target segment to their respective initial data and generate a rollback success response. The target segment is any segment among the segments corresponding to each executable sub-statement.

[0034] The third sending module is used to receive the rollback success response returned by the data node, and send the execution result of the target statement to the client based on the rollback success response.

[0035] Fourthly, this application also provides a transaction processing apparatus applied to a data node, the apparatus comprising:

[0036] The third receiving module is used to receive at least one executable sub-statement sent by the computing node, and parse it to obtain the save point corresponding to the target statement carried in each executable sub-statement. The save point corresponding to the target statement is predefined. The executable sub-statement is obtained by the computing node through syntax parsing of the target statement. The target statement is any statement in the target transaction sent by the client to the computing node.

[0037] The save and execute module is used to save the initial data of the slice corresponding to each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement;

[0038] The fifth sending module is used to send the processing result to the computing node;

[0039] The generation module is used to roll back the data of other fragments except the target fragment to their respective initial data when a rollback instruction is received from the computing node, and generate a rollback success response. The target fragment is any fragment among the fragments corresponding to each executable sub-statement. The rollback instruction is generated by the computing node when the processing result indicates that the executable sub-statement of the target fragment has failed to execute.

[0040] The sixth sending module is used to send the rollback success response to the computing node, so that the computing node can send the execution result of the target statement to the client based on the rollback success response.

[0041] Fifthly, this application also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0042] Memory, used to store computer programs;

[0043] When a processor executes a program stored in memory, it implements the steps of the transaction processing method described in any embodiment of the first aspect, or the steps of the transaction processing method described in any embodiment of the second aspect.

[0044] Sixthly, this application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the transaction processing method described in any embodiment of the first aspect, or implements the steps of the transaction processing method described in any embodiment of the second aspect.

[0045] In this embodiment, a target statement is received from a client, where the target statement is any statement within a target transaction. The target statement is then parsed to obtain at least one executable sub-statement. A predefined savepoint corresponding to the target statement is carried within the executable sub-statement and sent to a data node. The data node saves the initial data of each shard corresponding to the executable sub-statement based on the savepoint, executes each executable sub-statement, and obtains the processing result corresponding to each executable sub-statement. The processing result returned by the data node is received. If the processing result indicates that the executable sub-statement of the target shard has failed to execute, a rollback instruction is sent to the data node. This allows the data node to roll back the data of other shards (excluding the target shard) to their respective initial data and generate a rollback success response. The target shard is any shard among the shards corresponding to each executable sub-statement. The rollback success response returned by the data node is received, and the execution result of the target statement is sent to the client based on the rollback success response. In this way, when executing the target statement within the target transaction, if the executable sub-statement of the target shard fails, the data of other shards besides the target shard can be rolled back to their respective initial data, thus ensuring the consistency of the transaction. At the same time, since only the target statement needs to be rolled back, instead of the entire target transaction, the execution efficiency of the target transaction is effectively improved. Attached Figure Description

[0046] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0048] Figure 1 A flowchart illustrating a transaction processing method provided in an embodiment of this application;

[0049] Figure 2 A schematic diagram illustrating a method for splicing the storage points corresponding to a target statement, provided in an embodiment of this application;

[0050] Figure 3 A flowchart illustrating another transaction processing method provided in an embodiment of this application;

[0051] Figure 4 A flowchart illustrating another transaction processing method provided in an embodiment of this application;

[0052] Figure 5 This is a schematic diagram of the structure of a transaction processing device provided in an embodiment of this application;

[0053] Figure 6 This is a schematic diagram of another transaction processing apparatus provided in an embodiment of this application;

[0054] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0056] It should be noted that the transaction processing method provided in this application embodiment can be applied to a distributed database. When processing distributed transactions in this distributed database, it typically involves compute nodes (CNs) and data nodes (DNs). The compute node mainly includes execution threads, routing threads, and worker threads. The execution thread is mainly used to process Structured Query Language (SQL) statements sent by the client, including parsing the SQL statements to obtain executable sub-statements. The routing thread is mainly responsible for sending the executable sub-statements to the data nodes. The worker thread is mainly used to process and listen to the executable sub-statements sent to the data nodes and the processing results. The data node is mainly used to store data and can include multiple shards. The data corresponding to each executable sub-statement can be distributed across one shard or multiple shards. The existing transaction processing flow is as follows: After receiving the raw SQL statement sent by the client, the compute node performs syntax parsing on the raw SQL statement through the execution thread in the compute node, generating one or more executable substatements. These executable substatements are then distributed to different shards of the data node via the routing thread in the compute node. The listening thread in the compute node then listens for the processing results returned by the data node. After the data node completes processing, it sends the processing result back to the compute node, where it is sent to the execution thread via the listening thread and routing thread for result aggregation. Finally, the execution result of the raw SQL statement is sent to the client. At this point, shards on the data node that fail to execute the executable substatements automatically roll back, while shards that successfully execute the executable substatements retain the data after execution, leading to transaction inconsistency issues. The transaction processing method provided in this application, however, employs a single-statement rollback technique within the transaction based on compute nodes and data nodes. This ensures the correctness and consistency of the transaction while minimizing the impact on statement execution efficiency.

[0057] See Figure 1 , Figure 1 This is a flowchart illustrating a transaction processing method provided in an embodiment of this application. Figure 1 As shown, this transaction processing method is applied to compute nodes, and the method may specifically include the following steps:

[0058] Step 101: Receive the target statement sent by the client. The target statement is any statement within the target transaction.

[0059] Specifically, the aforementioned client can be any terminal device such as a smartphone, tablet, personal computer, or wearable device. The aforementioned target statement can be any statement within the target transaction, such as any native SQL statement within the target transaction sent by the client. The target transaction here can be any transaction based on a distributed database, and this target transaction can include multiple SQL statements.

[0060] Step 102: Perform syntax parsing on the target statement to obtain at least one executable substatement.

[0061] In this step, after receiving the target statement sent by the client, the compute node can perform syntax parsing on the target statement to obtain one or more executable sub-statements. Each executable sub-statement, when executed, needs to access or modify data in one or more shards within the data node.

[0062] Step 103: Carry the save point corresponding to the predefined target statement in the executable sub-statement and send it to the data node, so that the data node can save the initial data of the corresponding fragment of each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement.

[0063] In this step, after parsing at least one executable sub-statement, the compute node can include the savepoint corresponding to the target statement within the executable sub-statement and then send it to the data node. Thus, upon receiving each executable sub-statement, the data node can save the initial data of the corresponding slice based on the savepoint of the target statement, and then execute each executable sub-statement to obtain the processing result.

[0064] It should be noted that the savepoint corresponding to the target statement here is predefined. Different target statements can have different predefined savepoints, and multiple different executable sub-statements within the same target statement all carry the savepoint corresponding to that target statement. That is, multiple different executable sub-statements within the same target statement carry the same savepoint. Specifically, the way executable sub-statements carry savepoints can be by appending them as comments to the executable sub-statements, or by carrying the savepoint as a parameter or identifier within the executable sub-statements. This application does not impose specific limitations on this embodiment.

[0065] Step 104: Receive the processing results returned by the data node.

[0066] In this step, after executing each executable sub-statement, the data node returns the processing result of each executable sub-statement to the compute node. The compute node then receives and summarizes these results to determine if all executable sub-statements were executed successfully. If all executable sub-statements execute successfully, the target statement is considered executed successfully, and the execution result can be returned to the client. If any executable sub-statement fails, the target statement fails, and step 105 needs to be executed.

[0067] Step 105: If the processing result indicates that the executable sub-statement of the target fragment has failed to execute, a rollback instruction is sent to the data node so that the data node can roll back the data of other fragments except the target fragment to their respective initial data and generate a rollback success response. The target fragment is any fragment in the fragments corresponding to each executable sub-statement.

[0068] In this step, when the processing result indicates that the executable substatement of the target shard has failed to execute, the compute node can send a rollback instruction to the data node. In this way, the data node can roll back the data of other shards except the target shard to their respective initial data, generate a rollback success response, and then return the rollback success response to the compute node.

[0069] It should be noted that the target shard is any shard within the shards corresponding to each executable sub-statement. In other words, if the executable sub-statement of the target shard fails to execute, data from other shards where the sub-statement executed successfully can be rolled back, thus ensuring transaction consistency.

[0070] Step 106: Receive the rollback success response returned by the data node, and send the execution result of the target statement to the client based on the rollback success response.

[0071] In this step, when the compute node receives a rollback success response from the data node, it can send the execution result of the target statement to the client based on the rollback success response.

[0072] In this embodiment, when executing the target statement within the target transaction, if the executable sub-statement of the target shard fails to execute, the data of other shards besides the target shard can be rolled back to their respective initial data, thereby ensuring the consistency of the transaction. At the same time, since only the target statement needs to be rolled back, and the entire target transaction does not need to be rolled back, the execution efficiency of the target transaction is effectively improved.

[0073] Further, step 103 above, which involves carrying the savepoint corresponding to the predefined target statement in the executable sub-statement and sending it to the data node, includes:

[0074] The savepoint corresponding to the target statement is appended to the executable substatement as a comment and sent to the data node.

[0075] In one embodiment, when carrying the savepoint corresponding to the target statement in the executable sub-statement, it can be implemented by concatenating it with comments. Specifically, it can be implemented by concatenating it with hint comments. For example, suppose a raw SQL statement is parsed by a compute node and internally split into two executable sub-statements, SQL1 and SQL2. Due to the sharding issue, SQL1 needs to be split into SQL1_1 and SQL1_2, and SQL2 into SQL2_1 and SQL2_2; among which, SQL1 needs to be distributed to shards G1 and G2, and SQL2 needs to be distributed to shards G2 and G3. Then, when distributing SQL1 to the data nodes corresponding to shards G1 and G2, a slash ( / ) can be concatenated before SQL1. * +SP= * The slash ( / ) is used to carry the save point corresponding to the target statement, and then the concatenated SQL1 is sent out. When sending SQL2 to the data nodes corresponding to the G2 and G3 shards, a slash ( / ) can be added before SQL2. * +SP= * The ' / ' operator is used to carry the save point corresponding to the target statement, and then the concatenated SQL2 is sent out.

[0076] It should be noted that the above-mentioned G1 shard, G2 shard, and G3 shard can represent three different shards in the same data node, or they can represent shards in different data nodes. This application embodiment does not make specific limitations.

[0077] In this embodiment, the savepoint corresponding to the target statement can be appended to the executable sub-statement as a comment and then sent to the data node. This achieves the carrying of the savepoint without changing the original statement format of the executable sub-statement.

[0078] Furthermore, step 103 above, which involves carrying the savepoint corresponding to the predefined target statement in the executable sub-statement and sending it to the corresponding fragment on the data node, also includes:

[0079] If there are multiple executable sub-statements, and at least two of the multiple executable sub-statements correspond to the same shard, the save point corresponding to the target statement is carried only in the first of the at least two executable sub-statements and sent to the corresponding shard on the data node.

[0080] In one embodiment, when there are multiple executable sub-statements, and at least two of these sub-statements correspond to the same shard, it is sufficient to include the savepoint corresponding to the target statement in the first of the at least two executable sub-statements. Other executable sub-statements do not need to include the savepoint. For example, continuing from the above example, since both executable sub-statements SQL1 and SQL2 correspond to the G2 shard, when the compute node sends SQL1 and SQL2 to the data node corresponding to the G2 shard, only SQL1 needs to include the savepoint corresponding to the target statement; SQL2 does not need to include it. Figure 2 As shown. This reduces unnecessary hint splicing, thereby improving the overall performance of the computing nodes.

[0081] Furthermore, after step 104 above, receiving the processing result returned by the data node, the method further includes:

[0082] If the execution results of the executable sub-statements returned by the corresponding shards on the data nodes all indicate that the executable sub-statements were executed successfully, the execution result of the target statement is sent directly to the client.

[0083] In one embodiment, after receiving the processing results of the executable sub-statements, the computing node can summarize the processing results of the executable sub-statements and determine whether each executable sub-statement has been executed successfully. If each executable sub-statement has been executed successfully, it means that the target statement has been executed successfully, and the execution result of the target statement can be directly returned to the client.

[0084] See Figure 3 , Figure 3 A flowchart illustrating another transaction processing method provided in an embodiment of this application. For example... Figure 3 As shown, this transaction processing method is applied to data nodes, and the method may specifically include the following steps:

[0085] Step 301: Receive at least one executable sub-statement sent by the compute node, and parse the savepoint corresponding to the target statement carried in each executable sub-statement. The savepoint corresponding to the target statement is predefined. The executable sub-statement is obtained by the compute node through syntax parsing of the target statement. The target statement is any statement within the target transaction sent by the client to the compute node.

[0086] Specifically, the aforementioned client can be any terminal device such as a smartphone, tablet, personal computer, or wearable device. The aforementioned target statement can be any statement within the target transaction, such as any native SQL statement within the target transaction sent by the client. The target transaction here can be any transaction based on a distributed database, and this target transaction can include multiple SQL statements.

[0087] In this step, after receiving the target statement sent by the client, the compute node can perform syntax parsing on the target statement to obtain one or more executable sub-statements. Then, it carries the predefined savepoint corresponding to the target statement within the executable sub-statement and sends it to the data node. In this way, the data node can receive at least one executable sub-statement sent by the compute node and parse it to obtain the savepoint corresponding to the target statement carried in each executable sub-statement.

[0088] It should be noted that the savepoint corresponding to the target statement here is predefined. Different target statements can have different predefined savepoints, and multiple different executable sub-statements within the same target statement all carry the savepoint corresponding to that target statement. That is, multiple different executable sub-statements within the same target statement carry the same savepoint. Specifically, the way executable sub-statements carry savepoints can be by appending them as comments to the executable sub-statements, or by carrying the savepoint as a parameter or identifier within the executable sub-statements. This application does not impose specific limitations on this embodiment.

[0089] Step 302: Based on the save point corresponding to the target statement, save the initial data of the slice corresponding to each executable sub-statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement.

[0090] In this step, the data node can save the initial data of the slice corresponding to each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement.

[0091] Step 303: Send the processing results to the computing node.

[0092] In this step, after executing each executable sub-statement, the data node returns the processing result of each executable sub-statement to the compute node. The compute node then receives and summarizes these results to determine if all executable sub-statements were executed successfully. If all executable sub-statements execute successfully, the target statement is considered executed successfully, and the execution result can be returned to the client. If any executable sub-statement fails, the target statement fails, and step 304 needs to be executed.

[0093] Step 304: Upon receiving a rollback instruction from the compute node, roll back the data of all fragments except the target fragment to their respective initial data and generate a rollback success response. The target fragment is any fragment among the fragments corresponding to each executable sub-statement. The rollback instruction is generated by the compute node when the processing result indicates that the executable sub-statement of the target fragment has failed to execute.

[0094] In this step, when the processing result indicates that the executable substatement of the target shard has failed to execute, the compute node can send a rollback instruction to the data node. After receiving the rollback instruction from the compute node, the data node can roll back the data of other shards except the target shard to their respective initial data and generate a rollback success response.

[0095] It should be noted that the target shard is any shard within the shards corresponding to each executable sub-statement. In other words, if the executable sub-statement of the target shard fails to execute, data from other shards where the sub-statement executed successfully can be rolled back, thus ensuring transaction consistency.

[0096] Step 305: Send the rollback success response to the compute node so that the compute node can send the execution result of the target statement to the client based on the rollback success response.

[0097] In this step, after generating a rollback success response, the data node can send the rollback success response to the compute node. In this way, the compute node can send the execution result of the target statement to the client based on the rollback success response.

[0098] In this embodiment, when executing the target statement within the target transaction, if the executable sub-statement of the target shard fails to execute, the data of other shards besides the target shard can be rolled back to their respective initial data, thereby ensuring the consistency of the transaction. At the same time, since only the target statement needs to be rolled back, and the entire target transaction does not need to be rolled back, the execution efficiency of the target transaction is effectively improved.

[0099] Further, in step 304 above, upon receiving a rollback instruction from the compute node, the data of all fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated, including:

[0100] Upon receiving a rollback command from a compute node, the savepoint corresponding to the target statement carried in the rollback command is parsed and obtained.

[0101] Based on the save point corresponding to the target statement, determine the initial data corresponding to other fragments besides the target fragment;

[0102] The data of all fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated.

[0103] In one embodiment, when a data node receives a rollback command from a compute node, it can parse and obtain the savepoint corresponding to the target statement carried in the rollback command. Then, based on the savepoint corresponding to the target statement, it determines the initial data corresponding to other shards besides the target shard. Finally, it rolls back the data of the other shards to their respective initial data and generates a rollback success response. In this way, the data node can save the corresponding initial data based on the savepoint corresponding to any statement in the target transaction, facilitating rollback of any statement in the target transaction if execution fails, thereby improving overall business efficiency.

[0104] In one example, the transaction processing method provided in this application embodiment can be as follows: after a compute node receives a raw SQL statement and enters the compute node, the execution thread in the compute node performs syntax parsing to generate an executable substatement. Then, the savepoint of the generated SQL statement is concatenated in the form of a hint comment before the executable substatement and saved locally. Then, the routing thread in the compute node sends these executable substatements carrying savepoints to different shards of the data node. Finally, the listening thread in the compute node listens to the processing results returned by the data node. When a data node receives an executable sub-statement carrying a savepoint, it first parses the hint comment preceding the sub-statement to obtain the savepoint, saving the initial data state before the sub-statement's execution. After the sub-statement finishes execution, the processing result is sent to the compute node for result aggregation by the execution thread. If one executable sub-statement fails while the others succeed, a rollback command (e.g., a rollback to savepoint statement) is sent to the data nodes of the successfully executed shards. This savepoint is a previously recorded savepoint. Upon receiving this statement, the data node locates the savepoint record and performs the rollback, restoring the successfully executed shards to their initial data state. Once the compute node receives successful rollback responses from all data nodes, it returns the execution result of the original SQL statement to the client, such as... Figure 4 As shown.

[0105] Compared with existing technologies, the transaction processing method provided in this application can achieve the following effects:

[0106] First, it solves the problem of distributed inconsistency caused by errors in the execution of a single statement in a distributed transaction scenario, thus ensuring the distributed atomicity and consistency of statements.

[0107] Secondly, it avoids the phenomenon of the entire transaction being rolled back after the failure of a distributed super-large transaction, effectively improving the overall business efficiency.

[0108] See Figure 5 , Figure 5 This is a schematic diagram of the structure of a transaction processing device provided in an embodiment of this application. Figure 5 As shown, the transaction processing device 500 is applied to a computing node, and the device 500 includes:

[0109] The first receiving module 501 is used to receive the target statement sent by the client, where the target statement is any statement within the target transaction.

[0110] The syntax parsing module 502 is used to perform syntax parsing on the target statement to obtain at least one executable substatement;

[0111] The first sending module 503 is used to carry the save point corresponding to the predefined target statement in the executable sub-statement and send it to the data node, so that the data node can save the initial data of the corresponding fragment of each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement.

[0112] The second receiving module 504 is used to receive the processing results returned by the data node;

[0113] The second sending module 505 is used to send a rollback instruction to the data node when the processing result indicates that the executable sub-statement of the target segment has failed to execute. This instruction allows the data node to roll back the data of other segments except the target segment to their respective initial data and generate a rollback success response. The target segment is any segment in the segment corresponding to each executable sub-statement.

[0114] The third sending module 506 is used to receive the rollback success response returned by the data node and send the execution result of the target statement to the client based on the rollback success response.

[0115] Furthermore, the first transmitting module 503 includes:

[0116] The first sending submodule is used to append the savepoint corresponding to the target statement to the executable substatement as a comment and send it to the data node.

[0117] Furthermore, the first transmitting module 503 also includes:

[0118] The second sending submodule is used to send the save point corresponding to the target statement only in the first of the at least two executable sub-statements, and send it to the data node when there are multiple executable sub-statements and at least two of the executable sub-statements correspond to the same fragment on the data node.

[0119] Furthermore, the device 500 also includes:

[0120] The fourth sending module is used to directly send the execution result of the target statement to the client when the processing result indicates that each executable substatement has been executed successfully.

[0121] It should be noted that the device 500 can achieve the above-mentioned... Figure 1 Any step in the transaction processing method embodiment shown can achieve the same technical effect, and will not be described in detail here.

[0122] See Figure 6 , Figure 6 This is a schematic diagram of another transaction processing apparatus provided in an embodiment of this application. Figure 6 As shown, the transaction processing apparatus 600 is applied to a data node, and the apparatus 600 includes:

[0123] The third receiving module 601 is used to receive at least one executable sub-statement sent by the computing node, and parse the save point corresponding to the target statement carried in each executable sub-statement. The save point corresponding to the target statement is predefined. The executable sub-statement is obtained by the computing node through syntax parsing of the target statement. The target statement is any statement in the target transaction sent by the client to the computing node.

[0124] The save and execute module 602 is used to save the initial data of the slice corresponding to each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement;

[0125] The fifth sending module 603 is used to send the processing results to the computing node;

[0126] The generation module 604 is used to roll back the data of other fragments except the target fragment to their respective initial data when a rollback instruction is received from the computing node, and generate a rollback success response. The target fragment is any fragment in the fragments corresponding to each executable sub-statement. The rollback instruction is generated by the computing node when the processing result indicates that the executable sub-statement of the target fragment has failed to execute.

[0127] The sixth sending module 605 is used to send the rollback success response to the computing node, so that the computing node can send the execution result of the target statement to the client based on the rollback success response.

[0128] Furthermore, the generation module 604 includes:

[0129] The parsing submodule is used to parse and obtain the save point corresponding to the target statement carried in the rollback instruction when a rollback instruction is received from the computing node.

[0130] The determination submodule is used to determine the initial data corresponding to other fragments besides the target fragment based on the save point corresponding to the target statement;

[0131] The generation submodule is used to roll back the data of other shards (excluding the target shard) to their respective initial data and generate a rollback success response.

[0132] It should be noted that the device 600 can achieve the above-mentioned... Figure 3 Any step in the transaction processing method embodiment shown can achieve the same technical effect, and will not be described in detail here.

[0133] like Figure 7 As shown in the illustration, this application also provides an electronic device, including a processor 711, a communication interface 712, a memory 713, and a communication bus 714, wherein the processor 711, the communication interface 712, and the memory 713 communicate with each other via the communication bus 714.

[0134] Memory 713 is used to store computer programs;

[0135] In one embodiment of this application, when the processor 711 executes the program stored in the memory 713, it implements the above-described... Figure 1 Any step in the transaction processing method embodiment shown, or implementing the above Figure 3 Any step in the transaction processing method embodiment shown.

[0136] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described functionality. Figure 1 Any step in the transaction processing method embodiment shown, or implementing the above Figure 3 Any step in the transaction processing method embodiment shown.

[0137] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0138] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A transaction processing method, characterized in that, Applied to a computing node, the method includes: Receive the target statement sent by the client, where the target statement is any statement within the target transaction; The target statement is parsed to obtain at least one executable substatement; The predefined save point corresponding to the target statement is carried in the executable sub-statement and sent to the data node, so that the data node can save the initial data of the corresponding fragment of each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement. Receive the processing result returned by the data node; If the processing result indicates that the executable sub-statement of the target fragment has failed to execute, a rollback instruction is sent to the data node so that the data node rolls back the data of other fragments except the target fragment to their respective initial data and generates a rollback success response. The target fragment is any fragment among the fragments corresponding to each executable sub-statement. The system receives the rollback success response returned by the data node and sends the execution result of the target statement to the client based on the rollback success response.

2. The method according to claim 1, characterized in that, The step of carrying the savepoint corresponding to the predefined target statement in the executable sub-statement and sending it to the data node includes: The savepoint corresponding to the target statement is appended to the executable substatement as a comment and sent to the data node.

3. The method according to claim 2, characterized in that, The step of carrying the save point corresponding to the predefined target statement in the executable sub-statement and sending it to the data node further includes: If there are multiple executable sub-statements, and at least two of the multiple executable sub-statements correspond to the same fragment on the data node, the save point corresponding to the target statement is carried in the first of the at least two executable sub-statements and sent to the data node.

4. The method according to claim 1, characterized in that, After receiving the processing result returned by the data node, the method further includes: If the processing result indicates that each of the executable sub-statements was executed successfully, the execution result of the target statement is sent directly to the client.

5. A transaction processing method, characterized in that, Applied to data nodes, the method includes: The system receives at least one executable sub-statement sent by the computing node and parses it to obtain the save point corresponding to the target statement carried in each executable sub-statement. The save point corresponding to the target statement is predefined. The executable sub-statement is obtained by the computing node through syntax parsing of the target statement. The target statement is any statement within the target transaction sent by the client to the computing node. Based on the save point corresponding to the target statement, the initial data of the slice corresponding to each executable sub-statement is saved, and each executable sub-statement is executed to obtain the processing result corresponding to each executable sub-statement; The processing result is sent to the computing node; Upon receiving a rollback instruction from the computing node, the data of all fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated. The target fragment is any fragment among the fragments corresponding to each executable sub-statement. The rollback instruction is generated by the computing node when the processing result indicates that the executable sub-statement of the target fragment has failed to execute. The rollback success response is sent to the computing node, so that the computing node can send the execution result of the target statement to the client based on the rollback success response.

6. The method according to claim 5, characterized in that, Upon receiving a rollback instruction from the computing node, the data of all fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated, including: Upon receiving a rollback instruction from the computing node, the savepoint corresponding to the target statement carried in the rollback instruction is parsed and obtained. Based on the save point corresponding to the target statement, determine the initial data corresponding to other fragments besides the target fragment; The data of all other fragments except the target fragment are rolled back to their respective initial data, and a rollback success response is generated.

7. A transaction processing apparatus, characterized in that, Applied to a computing node, the device includes: The first receiving module is used to receive the target statement sent by the client, wherein the target statement is any statement within the target transaction; The syntax parsing module is used to perform syntax parsing on the target statement to obtain at least one executable substatement; The first sending module is used to carry the predefined save point corresponding to the target statement in the executable sub-statement and send it to the data node, so that the data node can save the initial data of the corresponding fragment of each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement. The second receiving module is used to receive the processing result returned by the data node; The second sending module is used to send a rollback instruction to the data node when the processing result indicates that the executable sub-statement of the target segment has failed to execute, so that the data node can roll back the data of other segments except the target segment to their respective initial data and generate a rollback success response. The target segment is any segment among the segments corresponding to each executable sub-statement. The third sending module is used to receive the rollback success response returned by the data node, and send the execution result of the target statement to the client based on the rollback success response.

8. A transaction processing apparatus, characterized in that, Applied to data nodes, the device includes: The third receiving module is used to receive at least one executable sub-statement sent by the computing node, and parse it to obtain the save point corresponding to the target statement carried in each executable sub-statement. The save point corresponding to the target statement is predefined. The executable sub-statement is obtained by the computing node through syntax parsing of the target statement. The target statement is any statement in the target transaction sent by the client to the computing node. The save and execute module is used to save the initial data of the slice corresponding to each executable sub-statement based on the save point corresponding to the target statement, and execute each executable sub-statement to obtain the processing result corresponding to each executable sub-statement; The fifth sending module is used to send the processing result to the computing node; The generation module is used to roll back the data of other fragments except the target fragment to their respective initial data when a rollback instruction is received from the computing node, and generate a rollback success response. The target fragment is any fragment among the fragments corresponding to each executable sub-statement. The rollback instruction is generated by the computing node when the processing result indicates that the executable sub-statement of the target fragment has failed to execute. The sixth sending module is used to send the rollback success response to the computing node, so that the computing node can send the execution result of the target statement to the client based on the rollback success response.

9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; When a processor executes a program stored in memory, it implements the steps of the transaction processing method according to any one of claims 1-4, or the steps of the transaction processing method according to any one of claims 5-8.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the transaction processing method according to any one of claims 1-4, or the steps of the transaction processing method according to any one of claims 5-8.

Citation Information

Patent Citations

  • Transaction processing method and device of distributed database system

    CN105608086A

  • Data processing method and device, electronic equipment and storage medium

    CN114647659A