Distributed transaction processing method and device, equipment and medium
By introducing the communication mechanism of preparation requests, pre-commit messages and operation instructions into the distributed database system, the efficiency and reliability problems of distributed transaction processing under the unitized architecture are solved, and efficient distributed transaction processing and recovery are achieved to ensure Data consistency and system availability.
Patent Information
- Application Number
- CN202411000761.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-10-15
AI Technical Summary
In a distributed database system with a modular architecture, how to achieve efficient and reliable distributed transaction processing is still an urgent problem to be solved. Especially in the face of network delays and node failures, existing technology cannot guarantee the atomicity of transactions. sex and consistency.
By defining the communication process of preparation requests, pre-commit messages and operation instructions between the transaction coordinator and transaction participants, it ensures that each transaction participant performs transaction operations and feedbacks the execution status, and the transaction coordinator decides to commit or abort the operation based on the feedback. This enables distributed transaction processing among various database objects.
It achieves efficient and reliable distributed transaction processing, ensures the atomicity and consistency of transactions, reduces communication and synchronization overhead between nodes, improves concurrency performance, and ensures data recovery and system availability in the event of a failure.
Smart Images

Figure CN118779069A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a method, apparatus, device, and medium for processing distributed transactions. Background Art
[0002] As a crucial database architecture in the database field, distributed database can store data on multiple nodes and allow multiple nodes to jointly process and manage data to achieve high availability, horizontal expansion and fault tolerance of the database to meet large-scale data processing and high concurrency requirements.
[0003] In a distributed database architecture, a database unitized architecture can be used to split the distributed database system into multiple independent units, each of which has independent computing and storage capabilities, to improve the scalability and concurrent processing capabilities of the distributed database and support larger-scale data storage and processing requirements. However, in a distributed database system with a unitized architecture, how to implement distributed transaction processing is still a problem that needs to be solved in related technologies. Summary of the invention
[0004] In view of this, one or more embodiments of this specification provide a distributed transaction processing method, device, equipment and medium.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a distributed transaction processing method is proposed, which is applied to a transaction coordinator in a distributed database with a unitized architecture. The method includes:
[0007] Sending a prepare request to multiple transaction participants based on the pending transaction, wherein for any transaction participant, the prepare request is used to instruct the transaction participant to perform a corresponding transaction operation;
[0008] Receiving pre-commit messages returned by the multiple transaction participants based on the prepare request, wherein for any transaction participant, the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant;
[0009] Based on the pre-commit messages returned by the multiple transaction participants, an operation instruction is sent to the multiple transaction participants. For any transaction participant, the operation instruction is used to instruct the transaction participant to process a first database object matching the executed transaction operation according to the executed transaction operation.
[0010] According to a second aspect of one or more embodiments of this specification, a distributed transaction processing method is proposed, which is applied to transaction participants in a distributed database with a unitized architecture, and the method includes:
[0011] In response to receiving a prepare request sent by the transaction coordinator based on the pending transaction, executing the transaction operation corresponding to the transaction participant based on the prepare request;
[0012] Based on the execution status of the transaction operation by the transaction participant, a pre-commit message is sent to the transaction coordinator, where the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant;
[0013] In response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, a first database object matching the executed transaction operation is processed based on the operation instruction.
[0014] According to a third aspect of one or more embodiments of this specification, a distributed transaction processing device is provided, which is applied to a transaction coordinator in a distributed database with a unitized architecture, and the device includes:
[0015] A sending module, configured to send a prepare request to multiple transaction participants based on the pending transaction, wherein for any transaction participant, the prepare request is used to instruct the transaction participant to perform a corresponding transaction operation;
[0016] A receiving module, configured to receive pre-commit messages returned by the multiple transaction participants based on the prepare request, wherein for any transaction participant, the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant;
[0017] The sending module is further used to send operation instructions to the multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants. For any transaction participant, the operation instruction is used to instruct the transaction participant to process a first database object that matches the executed transaction operation according to the executed transaction operation.
[0018] According to a fourth aspect of one or more embodiments of this specification, a distributed transaction processing device is provided, which is applied to a transaction participant in a distributed database of a unitized architecture, and the device includes:
[0019] A processing module, configured to, in response to receiving a prepare request sent by a transaction coordinator based on a pending transaction, execute a transaction operation corresponding to the transaction participant based on the prepare request;
[0020] A sending module, used for sending a pre-commit message to the transaction coordinator based on the execution status of the transaction operation by the transaction participant, wherein the pre-commit message is used for indicating the execution status of the transaction operation by the transaction participant;
[0021] The processing module is further configured to, in response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, process a first database object matching the executed transaction operation based on the operation instruction.
[0022] According to a fifth aspect of one or more embodiments of this specification, a computing device is provided, including:
[0023] processor;
[0024] a memory for storing processor-executable instructions;
[0025] The processor implements the method described in the first aspect or the second aspect by running the executable instructions.
[0026] According to a sixth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect or the second aspect are implemented.
[0027] In this specification, a transaction coordinator in a distributed database with a unitized architecture sends a prepare request to multiple transaction participants based on a pending transaction. Each transaction participant can perform a corresponding transaction operation based on the prepare request, and return a pre-commit message to the transaction coordinator based on the execution status of the transaction operation. The transaction coordinator can send an operation instruction to the multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants, so as to instruct each transaction participant to process a first database object matching the executed transaction operation according to the executed transaction operation through the operation instruction, thereby routing the transaction operation to be executed by each transaction participant to the corresponding first database object, so as to realize the processing of distributed transactions in each database object. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is a flowchart of a distributed transaction processing method provided by an exemplary embodiment.
[0029] Figure 2 The present invention is a flowchart of a distributed transaction processing method shown in an exemplary embodiment.
[0030] Figure 3 It is an interactive flow chart of a distributed transaction processing method shown by an exemplary embodiment.
[0031] Figure 4 It is a schematic structural diagram of a computing device provided by an exemplary embodiment.
[0032] Figure 5 It is a block diagram of a distributed transaction processing device provided by an exemplary embodiment.
[0033] Figure 6 It is a block diagram of a distributed transaction processing device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0034] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0035] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0036] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0037] In the related art, transaction operations across multiple nodes or services can be performed in a distributed database to achieve the processing of distributed transactions. However, due to the characteristics of distributed databases, network delays, node failures, etc. may occur, making the processing of distributed transactions more challenging.
[0038] Optionally, the distributed database can be split into multiple independent units through database unitization, each of which can have independent computing and storage capabilities to improve the scalability and concurrent processing capabilities of the distributed database and support larger-scale data storage and processing requirements.
[0039] In a distributed database unitized architecture, the database can be split horizontally into multiple shards through database sharding technology, so that each unit obtained by the database unitization process can be split into a group of shards. Each shard can contain a part of the database's data and computing resources, and can independently process read and write requests. Through database sharding, data and load can be distributed to different shards, thereby improving the scalability and performance of the database. In addition, through database sharding, the distributed database can have better horizontal expansion capabilities, so that shards can be dynamically added or deleted according to the load situation.
[0040] Optionally, each unit also has its own metadata service, which is responsible for managing metadata information for the database shard.
[0041] By unitizing the database, the distributed database can effectively distribute data and load, improve the concurrent processing capability and availability of the system. At the same time, the database unitized architecture can provide better horizontal expansion capabilities, allowing the database system to dynamically adjust the scale of computing and storage resources according to demand to meet the needs of large-scale data storage and processing.
[0042] However, in a distributed database system with a unitized architecture, how to implement the processing of distributed transactions is still a problem that needs to be further studied in related technologies.
[0043] In view of this, the present specification hopes to provide a distributed transaction processing method to implement distributed transaction processing in a distributed database system with a unitized architecture, thereby ensuring efficient and reliable distributed transaction processing and recovery.
[0044] It should be noted that in the processing of distributed transactions, there can be two roles: transaction coordinator and transaction participant. Among them, there is only one transaction coordinator, who is responsible for controlling the execution of distributed transactions. The transaction coordinator can also be called a transaction leader; there can be multiple transaction participants, who are responsible for executing specific transaction operations in distributed transactions.
[0045] See also Figure 1 , Figure 1 is a flowchart of a distributed transaction processing method provided by an exemplary embodiment, such as Figure 1 As shown, the method may be executed by a transaction coordinator in a distributed database of a unitized architecture, and may specifically include the following steps:
[0046] Step 101: Send a prepare request to multiple transaction participants based on the pending transaction. For any transaction participant, the prepare request is used to instruct the transaction participant to perform a corresponding transaction operation.
[0047] It should be noted that a pending transaction may include multiple pending transaction operations, and different transaction operations may be executed by different transaction participants to achieve processing of different data shards in a distributed database.
[0048] It should be noted that after receiving the prepare request sent by the transaction coordinator, each transaction participant can determine its corresponding transaction operation from multiple pending transaction operations included in the pending transaction based on the received prepare request, and then execute the corresponding transaction operation.
[0049] Step 102: Receive pre-commit messages returned by multiple transaction participants based on the prepare request. For any transaction participant, the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant.
[0050] It should be noted that regardless of whether the transaction operation is executed successfully or not, each transaction participant can send a pre-commit message to the transaction coordinator at the end of the transaction operation, so as to provide feedback to the transaction coordinator on the execution status of the transaction operation through the pre-commit message. The transaction coordinator can then execute subsequent processes based on the pre-commit messages fed back by each transaction participant.
[0051] Step 103: Based on the pre-commit messages returned by the multiple transaction participants, an operation instruction is sent to the multiple transaction participants. For any transaction participant, the operation instruction is used to instruct the transaction participant to process a first database object matching the executed transaction operation according to the executed transaction operation.
[0052] The database object may be used to indicate the database table to be processed and the location of the database table in the database.
[0053] It should be noted that during the execution of distributed transactions, the atomicity of the transaction needs to be maintained, that is, the transaction is an indivisible unit of work, which is either fully executed successfully or not executed at all, and there is no partial execution. Therefore, if all transaction participants report that the transaction operation is completed, the transaction coordinator can send an operation instruction to all transaction participants to indicate the commit operation; if any transaction participant reports that the transaction operation is not completed, the transaction coordinator can send an operation instruction to all transaction participants to indicate the abort operation.
[0054] After introducing the basic implementation process of this specification, the non-restrictive implementation method of this specification is introduced below.
[0055] In some embodiments, for step 101, when the transaction coordinator sends a prepare request to multiple transaction participants based on the pending transaction, the step can be implemented by the following steps:
[0056] Step 1011: In response to receiving a database operation request, generate a global pending transaction based on the database operation request.
[0057] Optionally, a database operation request may be triggered by an application or a client to read, write, delete, etc. data in the database through the database operation request.
[0058] In a possible implementation, upon receiving a database operation request, the transaction coordinator may generate a prepared version of the transaction based on the to-be-performed operation indicated by the database operation request as a to-be-processed transaction.
[0059] It should be noted that under the unitized architecture, distributed transactions can be initiated in the global zone (Global Zone, GZone) and the regional zone (Region Zone, RZone).
[0060] Among them, GZone can deploy inseparable data and services. There is only one group of GZones in the world, and only one copy of data. It can be used to deploy global services such as gateways, configurations, parameters, and routing. These data or services may be relied on by RZone. Each RZone can be self-contained, each RZone can have its own data, and can independently complete all business, and can be used to deploy core shardable businesses such as transactions, payments, and accounts.
[0061] It should be noted that transactions initiated in GZone will be written to a single table in the distributed database, while transactions initiated in RZone will route transaction logs to the appropriate target database and data table based on the identifier of the database shard.
[0062] Optionally, the transaction coordinator can initiate pending transactions in GZone to generate global pending transactions.
[0063] Optionally, the pending transaction may include a first timestamp, which may be a maximum value among a global timestamp (Global Timestamp, gts), a maximum readable timestamp (Max-Readable Timestamp, max_readable_ts), and a log timestamp (Log Timestamp, log_ts).
[0064] Among them, the global timestamp can be a timestamp used to mark the order in which events occur in a distributed database system to determine the causal relationship of events in the distributed system, which can be generated by a global clock (such as a global coordination clock). The maximum readable timestamp can be used to maintain the transaction isolation level in the database system. When a transaction starts to execute, the current maximum readable timestamp can be recorded. Transactions that have been submitted before this timestamp are visible to the node. The log timestamp refers to the timestamp used to record the order in which various operations occur during the transaction operation process in the database system. Each log entry can contain a timestamp to mark the time order in which the operations corresponding to the log entry occur.
[0065] By recording the maximum value of the global timestamp, the maximum readable timestamp, and the log timestamp, transaction management and concurrency control can be achieved.
[0066] Step 1012: Send a prepare request carrying the pending transaction to multiple transaction participants.
[0067] Optionally, after generating the pending transaction, the transaction coordinator may send a prepare request carrying the generated pending transaction to each of the multiple transaction participants.
[0068] It should be noted that after receiving the prepare request, the transaction participant can execute the transaction operation corresponding to himself among the multiple transaction operations included in the pending transaction, and save the operation result to the local transaction log.
[0069] Optionally, after executing the transaction operation, the transaction participant may also push up the first timestamp to obtain the second timestamp to ensure that other concurrent transactions cannot read the data modified by the transaction before the transaction is committed.
[0070] Optionally, the transaction participant may send a pre-commit message to the transaction coordinator to indicate the execution status of the transaction operation through the pre-commit message. Optionally, the pre-commit message may include a second timestamp.
[0071] In some embodiments, the transaction coordinator may receive pre-commit messages returned by multiple transaction participants based on the prepare request in step 102, and then send operation instructions to multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants in step 103.
[0072] Optionally, the transaction coordinator may send operation instructions to multiple transaction participants after receiving pre-commit messages returned by all transaction participants.
[0073] Optionally, the transaction coordinator may route the transaction log generated after executing the transaction operation on each transaction participant to the corresponding data shard, so that each transaction participant may perform corresponding processing based on the transaction log on the corresponding data shard.
[0074] It should be noted that for distributed transactions, only when all transaction participants have completed the transaction operation can the operation be committed, and as long as there are transaction participants who have not completed the transaction operation, the operation can only be aborted. Therefore, the operation instruction may include a first operation instruction and a second operation instruction, wherein the first operation instruction is used to instruct the transaction participant to commit the executed transaction operation in the first database object matching the executed transaction operation, and the second operation instruction is used to instruct the transaction participant to abort the executed transaction operation.
[0075] In some embodiments, for step 103, when sending operation instructions to multiple transaction participants based on the pre-commit messages returned by multiple transaction participants, it can be implemented in any of the following ways:
[0076] In a possible implementation, if the pre-commit messages returned by multiple transaction participants all indicate that the transaction participants have completed the execution of the transaction operation, a first operation instruction is sent to the multiple transaction participants.
[0077] Optionally, the transaction participant can perform a commit operation based on the first operation instruction sent by the transaction coordinator to persist the operation to the corresponding data shard, that is, the transaction participant can commit the executed transaction operation in the first database object that matches the executed transaction operation based on the first operation instruction sent by the transaction coordinator.
[0078] Optionally, the transaction participant may send a first response message to the transaction coordinator when executing a commit operation, where the first response message is used to indicate that the transaction participant has committed the executed transaction operation in a first database object that matches the executed transaction operation.
[0079] It should be noted that the transaction participant can send the first response message to the transaction coordinator after most logs are successfully copied.
[0080] In addition, transaction participants can also release row locks after most logs are copied successfully so that other transactions can continue to process data that was originally locked by the released row locks.
[0081] Optionally, the transaction coordinator may receive a first response message returned by the transaction participant based on the first operation instruction.
[0082] In another possible implementation, if at least one pre-commit message among the pre-commit messages returned by the multiple transaction participants indicates that the transaction participant has not completed the execution of the transaction operation, a second operation instruction is sent to the multiple transaction participants.
[0083] Optionally, the transaction participant can perform an abort operation based on the second operation instruction sent by the transaction coordinator to cancel the transaction operation based on the pending transaction, so as to roll back the database to the state before the transaction started, that is, abandon all modifications made based on the pending transaction. In other words, the transaction participant can abort the executed transaction operation based on the second operation instruction sent by the transaction coordinator.
[0084] Optionally, the transaction participant may send a second response message to the transaction coordinator when executing the abort operation, where the second response message is used to indicate that the transaction participant has aborted the executed transaction operation.
[0085] That is, transaction participants can directly respond to the transaction coordinator with an abort message when aborting the operation.
[0086] In some embodiments, after executing corresponding operations based on the operation instructions of the transaction coordinator, the transaction participants may release the transaction context and clean up related resources to complete the execution process of the distributed transaction.
[0087] In more possible implementations, a recovery task of a distributed transaction may also be executed. In the case of transaction recovery, the transaction coordinator may generate a global data recovery task in response to receiving a transaction recovery request; based on the data recovery task, determine the first database object corresponding to the unfinished transaction operation; and send a recovery execution instruction to the transaction participant corresponding to the unfinished transaction operation, the recovery execution instruction being used to indicate to the transaction participant the second database object used to execute the unfinished transaction operation.
[0088] Optionally, a transaction recovery request may be triggered by an application or a client to implement transaction recovery through the transaction recovery request.
[0089] Optionally, data recovery tasks can be performed in GZone. By performing data recovery tasks in GZone, data recovery tasks can not only observe single database tables in GZone, but also observe sharded databases and tables in RZone to ensure the integrity of data recovery. In addition, by performing recovery tasks in GZone, the recovery process of transactions can be centralized, improving the efficiency and reliability of the transaction recovery process.
[0090] Optionally, the transaction coordinator can analyze the shard information in the transaction log to determine the first database object corresponding to the unfinished transaction operation and determine the second database object to which the unfinished transaction operation should be routed, so that the transaction participants can implement transaction recovery in the second database object. By routing the transaction log to the appropriate target database and table, the correctness and consistency of the transaction are guaranteed.
[0091] Accordingly, the transaction participant may receive the recovery execution instruction sent by the transaction coordinator, and in response to receiving the recovery execution instruction sent by the transaction coordinator based on the global data recovery task, re-execute the transaction operation in the second database object indicated by the recovery execution instruction based on the recovery execution instruction.
[0092] Through the above transaction recovery method, efficient and reliable distributed transaction processing and recovery can be achieved to ensure data consistency and reliability.
[0093] See also Figure 2 , Figure 2 is a flowchart of a distributed transaction processing method shown in an exemplary embodiment. Figure 2 As shown, the method can be executed by a transaction participant in a distributed database with a unitized architecture, and specifically may include the following steps:
[0094] Step 201: In response to receiving a prepare request sent by a transaction coordinator based on a pending transaction, execute a transaction operation corresponding to a transaction participant based on the prepare request.
[0095] Optionally, after receiving the prepare request sent by the transaction coordinator, the transaction participant may determine the transaction operation corresponding to itself from the multiple transaction operations to be executed included in the pending transaction based on the received prepare request, and thereby execute the corresponding transaction operation.
[0096] Step 202: Based on the execution status of the transaction operation by the transaction participant, a pre-commit message is sent to the transaction coordinator, where the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant.
[0097] It should be noted that regardless of whether the transaction operation is executed successfully or not, the transaction participants can send a pre-commit message to the transaction coordinator at the end of the transaction operation, so as to provide feedback to the transaction coordinator on the execution status of the transaction operation through the pre-commit message, so that the transaction coordinator can execute subsequent processes based on the pre-commit messages fed back by each transaction participant.
[0098] Step 203: In response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, a first database object matching the executed transaction operation is processed based on the operation instruction.
[0099] It should be noted that during the execution of distributed transactions, the atomicity of transactions needs to be maintained, that is, transactions are an indivisible unit of work, which is either fully executed successfully or not executed at all, and there is no partial execution. Therefore, if all transaction participants report that the transaction operation is completed, the transaction coordinator can send an operation instruction to all transaction participants to indicate the commit operation; if any transaction participant reports that the transaction operation is not completed, the transaction coordinator can send an operation instruction to all transaction participants to indicate the abort operation. Accordingly, transaction participants can perform corresponding operations based on the received operation instructions.
[0100] After introducing the basic implementation process of this specification, the non-restrictive implementation method of this specification is introduced below.
[0101] In some embodiments, for step 201, when a transaction participant performs a transaction operation corresponding to the transaction participant based on the prepare request in response to receiving a prepare request sent by the transaction coordinator based on a pending transaction, the transaction participant can perform the transaction operation corresponding to itself after receiving the prepare request and save the operation result to a local transaction log.
[0102] Optionally, the pending transaction may be global, for example, the pending transaction may be initiated in a GZone.
[0103] Optionally, the transaction to be processed may include a first timestamp, which may be the maximum value among a global timestamp, a maximum readable timestamp and a log timestamp. For an introduction to the global timestamp, the maximum readable timestamp and the log timestamp, please refer to the above embodiments and will not be repeated here.
[0104] In some embodiments, for step 202, when the transaction participant sends a pre-commit message to the transaction coordinator based on the execution status of the transaction operation by the transaction participant, it can be implemented by the following steps:
[0105] Step 2021: Push up the first timestamp to obtain a second timestamp.
[0106] In a possible implementation, a transaction participant may push up the first timestamp after executing the transaction operation to obtain a second timestamp, so as to ensure that other concurrent transactions cannot read the data modified by the transaction before the transaction is committed.
[0107] Step 2022: Based on the execution status of the transaction operation by the transaction participants, a pre-commit message carrying a second timestamp is sent to the transaction coordinator.
[0108] Optionally, the transaction participants can send pre-commit information indicating the execution status of the transaction operations to the transaction coordinator based on their own execution status of the transaction operations, so that the transaction coordinator can determine the execution status of the transaction operations of each transaction participant based on the pre-commit information. In addition, the pre-commit message can also carry a second timestamp, so that the transaction coordinator can ensure that other concurrent transactions cannot read the data modified by the transaction before the transaction is committed based on the second timestamp.
[0109] Optionally, the transaction coordinator may implement sending of the operation instruction based on the pre-commit information fed back by each transaction participant. The specific process may refer to the above embodiment and will not be described in detail here.
[0110] It should be noted that, since the operation instruction sent by the transaction coordinator to the transaction participant can be the first operation instruction or the second operation instruction, the operation performed by the transaction participant based on the operation instruction can also be implemented in two ways.
[0111] In some embodiments, for step 203, in response to receiving the operation instruction sent by the transaction coordinator based on the pre-commit messages corresponding to the multiple transaction participants, the transaction participant processes the first database object matching the executed transaction operation based on the operation instruction, which can be implemented in the following manner:
[0112] In a possible implementation, in response to receiving the first operation instruction, the executed transaction operation may be committed in a first database object matching the executed transaction operation based on the first operation instruction.
[0113] The first operation instruction may be used to instruct the transaction participant to commit the executed transaction operation in the first database object matching the executed transaction operation.
[0114] Optionally, the transaction participant may perform a commit operation based on the first operation instruction sent by the transaction coordinator to persist the operation in the corresponding data shard.
[0115] Optionally, the transaction participant may send a first response message to the transaction coordinator when executing a commit operation, where the first response message is used to indicate that the transaction participant has committed the executed transaction operation in a first database object that matches the executed transaction operation.
[0116] It should be noted that the transaction participant can send the first response message to the transaction coordinator after most logs are successfully copied.
[0117] In addition, transaction participants can also release row locks after most logs are copied successfully so that other transactions can continue to process data that was originally locked by the released row locks.
[0118] That is, the transaction participant can release the row lock and send a first response message to the transaction coordinator after committing the executed transaction operation in the first database object matching the executed transaction operation based on the first operation instruction.
[0119] In another possible implementation, in response to receiving the second operation instruction, the executed transaction operation may be aborted based on the second operation instruction.
[0120] The second operation instruction may be used to instruct the transaction participant to terminate the executed transaction operation.
[0121] Optionally, the transaction participant may perform an abort operation based on the second operation instruction sent by the transaction coordinator to undo the transaction operation based on the pending transaction to roll back the database to the state before the transaction started, that is, abandon all modifications based on the pending transaction.
[0122] Optionally, the transaction participant may send a second response message to the transaction coordinator when executing the abort operation, where the second response message is used to indicate that the transaction participant has aborted the executed transaction operation.
[0123] That is, transaction participants can directly respond to the transaction coordinator with an abort message when aborting the operation.
[0124] In some embodiments, after executing corresponding operations based on the operation instructions of the transaction coordinator, the transaction participants may release the transaction context and clean up related resources to complete the execution process of the distributed transaction.
[0125] In more possible implementations, a recovery task of a distributed transaction may also be executed. In the case of transaction recovery, a transaction participant may respond to receiving a recovery execution instruction sent by a transaction coordinator based on a global data recovery task, and based on the recovery execution instruction, re-execute the transaction operation in the second database object indicated by the recovery execution instruction. The specific implementation process may refer to the above embodiment, which will not be described in detail here.
[0126] See also Figure 3 , Figure 3 is an interactive flow chart of a distributed transaction processing method shown in an exemplary embodiment. Figure 3 As shown, the method can be applied to a distributed database system with a unitized architecture. The distributed database system with a unitized architecture may include a transaction coordinator and multiple transaction participants. The method may include:
[0127] Step 301: In response to receiving a database operation request, the transaction coordinator generates a pending transaction based on the database operation request.
[0128] Step 302: The transaction coordinator sends a prepare request to multiple transaction participants.
[0129] The prepare request may be used to instruct a transaction participant to perform a corresponding transaction operation based on the pending transaction, and the pending transaction may carry a first timestamp.
[0130] Step 303: In response to receiving the prepare request sent by the transaction coordinator based on the pending transaction, the transaction participant executes the transaction operation corresponding to the prepare request based on the prepare request.
[0131] Step 304: After executing the transaction operation, the transaction participant pushes up the first timestamp included in the transaction to be processed to obtain a second timestamp.
[0132] Step 305: The transaction participant sends a pre-commit message carrying a second timestamp to the transaction coordinator.
[0133] Step 306: The transaction coordinator receives pre-commit messages returned by multiple transaction participants.
[0134] Step 307: The transaction coordinator sends operation instructions to the multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants.
[0135] Step 308: In response to receiving the operation instruction sent by the transaction coordinator based on the pre-commit messages corresponding to the multiple transaction participants, the transaction participant processes the first database object matching the executed transaction operation based on the operation instruction.
[0136] Step 309: The transaction participant releases the transaction context and cleans up related resources.
[0137] It should be noted that the above Figure 3 The specific implementation methods of each step can be found in Figure 1 and Figure 2 The corresponding embodiments will not be described in detail here.
[0138] In the unitized architecture, the database is divided into multiple units, each unit corresponds to a database object. Through the solution provided in this specification, the transaction log can be routed to the correct database and database table to ensure that the transaction operation can be executed in the right place, avoid data conflicts, and ensure data consistency. In addition, the transaction operation in each database object can be processed independently, reducing the communication and synchronization overhead between nodes, improving the concurrency performance of transaction processing, and achieving high efficiency and reliability of distributed transaction processing.
[0139] In addition, GZone is a global disaster recovery and recovery mechanism that manages the status of each target zone. By executing recovery tasks in GZone, data consistency and reliability can be ensured. When a target zone or database fails, transaction logs can be routed to other available target zones and databases, and recovery tasks can be executed in GZone to ensure system continuity and availability.
[0140] Corresponding to the aforementioned method embodiments, this specification also provides corresponding device embodiments.
[0141] Figure 4 is a schematic structural diagram of a computing device provided by an exemplary embodiment. Figure 4 At the hardware level, the computing device includes a processor 402, an internal bus 404, a network interface 406, a memory 408, and a non-volatile memory 410, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 402 reading the corresponding computer program from the non-volatile memory 410 into the memory 408 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0142] This specification also provides a distributed transaction processing device, please refer to Figure 5 , Figure 5 This is a block diagram of a distributed transaction processing device provided by an exemplary embodiment, which can be applied to a transaction coordinator in a distributed database of a unitized architecture to implement the technical solution of this specification. The distributed transaction processing device may include:
[0143] A sending module 501 is used to send a prepare request to multiple transaction participants based on the pending transaction. For any transaction participant, the prepare request is used to instruct the transaction participant to perform a corresponding transaction operation;
[0144] A receiving module 502 is used to receive pre-commit messages returned by multiple transaction participants based on the prepare request. For any transaction participant, the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant;
[0145] The sending module 501 is also used to send operation instructions to multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants. For any transaction participant, the operation instruction is used to instruct the transaction participant to process the first database object matching the executed transaction operation according to the executed transaction operation.
[0146] In some embodiments, the sending module 501, when used to send a prepare request to multiple transaction participants based on a pending transaction, is used to:
[0147] In response to receiving a database operation request, generating a global pending transaction based on the database operation request;
[0148] Sends prepare requests with pending transactions to multiple transaction participants.
[0149] In some embodiments, the pending transaction includes a first timestamp, which is a maximum value among a global timestamp, a maximum readable timestamp, and a log timestamp;
[0150] For any transaction participant, the first timestamp is used by the transaction participant to determine a second timestamp, and the pre-commit message includes the second timestamp.
[0151] In some embodiments, the operation instruction includes a first operation instruction and a second operation instruction, the first operation instruction is used to instruct the transaction participant to commit the executed transaction operation in the first database object matching the executed transaction operation, and the second operation instruction is used to instruct the transaction participant to abort the executed transaction operation;
[0152] The sending module 501, when used to send operation instructions to multiple transaction participants based on pre-commit messages returned by multiple transaction participants, is used for any of the following:
[0153] If the pre-commit messages returned by the multiple transaction participants all indicate that the transaction participants have completed the execution of the transaction operation, sending a first operation instruction to the multiple transaction participants;
[0154] If at least one pre-commit message among the pre-commit messages returned by the multiple transaction participants indicates that the transaction participant has not completed the execution of the transaction operation, a second operation instruction is sent to the multiple transaction participants.
[0155] In some embodiments, the receiving module 502 is further used for any of the following:
[0156] For any transaction participant, receiving a first response message returned by the transaction participant based on the first operation instruction, where the first response message is used to indicate that the transaction participant has submitted the executed transaction operation in a first database object matching the executed transaction operation;
[0157] A second response message returned by the transaction participant based on the second operation instruction is received, where the second response message is used to indicate that the transaction participant has aborted the executed transaction operation.
[0158] In some embodiments, the apparatus further comprises:
[0159] A generating module, configured to generate a global data recovery task in response to receiving a transaction recovery request;
[0160] A determination module, configured to determine, based on the data recovery task, a first database object corresponding to the unfinished transaction operation;
[0161] The sending module 501 is further used to send a resume execution instruction to the transaction participant corresponding to the unfinished transaction operation, where the resume execution instruction is used to indicate to the transaction participant the second database object used to execute the unfinished transaction operation.
[0162] Please refer to Figure 6 , Figure 6 This is a block diagram of a distributed transaction processing device provided by an exemplary embodiment, which can be applied to transaction participants in a distributed database of a unitized architecture to implement the technical solution of this specification. The distributed transaction processing device may include:
[0163] A processing module 601 is configured to, in response to receiving a prepare request sent by a transaction coordinator based on a pending transaction, execute a transaction operation corresponding to a transaction participant based on the prepare request;
[0164] A sending module 602 is used to send a pre-commit message to the transaction coordinator based on the execution status of the transaction operation by the transaction participant, where the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant;
[0165] The processing module 601 is further configured to, in response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, process a first database object matching the executed transaction operation based on the operation instruction.
[0166] In some embodiments, the pending transaction is global, and the pending transaction includes a first timestamp, which is a maximum value among a global timestamp, a maximum readable timestamp, and a log timestamp;
[0167] The sending module 602, when used to send a pre-commit message to the transaction coordinator based on the execution status of the transaction operation by the transaction participants, is used to:
[0168] Push up the first timestamp to get the second timestamp;
[0169] Based on the execution status of the transaction operation by the transaction participants, a pre-commit message carrying the second timestamp is sent to the transaction coordinator.
[0170] In some embodiments, the operation instruction includes a first operation instruction and a second operation instruction;
[0171] The processing module 601, when used to process a first database object matching the executed transaction operation based on the operation instruction in response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, is used for any of the following:
[0172] In response to receiving the first operation instruction, based on the first operation instruction, committing the executed transaction operation in a first database object matching the executed transaction operation;
[0173] In response to receiving the second operation instruction, the executed transaction operation is aborted based on the second operation instruction.
[0174] In some embodiments, the apparatus further comprises:
[0175] Release module, used to release row lock;
[0176] The sending module 602 is further used to send a first response message to the transaction coordinator, where the first response message is used to indicate that the transaction participant has submitted the executed transaction operation in the first database object matching the executed transaction operation;
[0177] The sending module 602 is further used to send a second response message to the transaction coordinator, where the second response message is used to indicate that the transaction participant has terminated the executed transaction operation.
[0178] In some embodiments, the processing module 601 is further used to respond to receiving a recovery execution instruction sent by the transaction coordinator based on a global data recovery task, and re-execute the transaction operation in the second database object indicated by the recovery execution instruction based on the recovery execution instruction.
[0179] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0180] In a typical configuration, a computer includes one or more processors (Central Processing Unit, CPU), input / output interface, network interface and memory.
[0181] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0182] Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0183] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0184] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0185] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0186] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0187] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A distributed transaction processing method, applied to a transaction coordinator in a distributed database with a unitized architecture, the method comprising: Sending a prepare request to multiple transaction participants based on the pending transaction, wherein for any transaction participant, the prepare request is used to instruct the transaction participant to perform a corresponding transaction operation; Receiving pre-commit messages returned by the multiple transaction participants based on the prepare request, wherein for any transaction participant, the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant; Based on the pre-commit messages returned by the multiple transaction participants, an operation instruction is sent to the multiple transaction participants. For any transaction participant, the operation instruction is used to instruct the transaction participant to process a first database object matching the executed transaction operation according to the executed transaction operation.
2. The method according to claim 1, wherein sending a prepare request to multiple transaction participants based on the pending transaction comprises: In response to receiving a database operation request, generating the global pending transaction based on the database operation request; Sending a prepare request carrying the pending transaction to the multiple transaction participants.
3. The method according to claim 1, wherein the to-be-processed transaction includes a first timestamp, and the first timestamp is a maximum value among a global timestamp, a maximum readable timestamp, and a log timestamp; For any transaction participant, the first timestamp is used by the transaction participant to determine a second timestamp, and the pre-commit message includes the second timestamp.
4. The method according to claim 1, wherein the operation instruction comprises a first operation instruction and a second operation instruction, wherein the first operation instruction is used to instruct the transaction participant to commit the executed transaction operation in the first database object matching the executed transaction operation, and the second operation instruction is used to instruct the transaction participant to abort the executed transaction operation; The sending operation instructions to the multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants includes any one of the following: If the pre-commit messages returned by the multiple transaction participants all indicate that the transaction participants have completed the execution of the transaction operation, sending the first operation instruction to the multiple transaction participants; If at least one pre-commit message among the pre-commit messages returned by the multiple transaction participants indicates that the transaction participant has not completed the execution of the transaction operation, the second operation instruction is sent to the multiple transaction participants.
5. The method according to claim 4, after sending operation instructions to the multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants, the method further comprises any one of the following: For any transaction participant, receiving a first response message returned by the transaction participant based on the first operation instruction, wherein the first response message is used to indicate that the transaction participant has submitted the executed transaction operation in a first database object matching the executed transaction operation; A second response message returned by the transaction participant based on the second operation instruction is received, where the second response message is used to indicate that the transaction participant has aborted the executed transaction operation.
6. The method according to claim 1, further comprising: In response to receiving a transaction recovery request, generating a global data recovery task; Based on the data recovery task, determining a first database object corresponding to the unfinished transaction operation; A resume execution instruction is sent to a transaction participant corresponding to the unfinished transaction operation, wherein the resume execution instruction is used to indicate to the transaction participant a second database object for executing the unfinished transaction operation.
7. A method for processing distributed transactions, applied to transaction participants in a distributed database with a unitized architecture, the method comprising: In response to receiving a prepare request sent by the transaction coordinator based on the pending transaction, executing the transaction operation corresponding to the transaction participant based on the prepare request; Based on the execution status of the transaction operation by the transaction participant, a pre-commit message is sent to the transaction coordinator, where the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant; In response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, a first database object matching the executed transaction operation is processed based on the operation instruction.
8. The method according to claim 7, wherein the pending transaction is global, and the pending transaction includes a first timestamp, and the first timestamp is a maximum value among a global timestamp, a maximum readable timestamp, and a log timestamp; The sending of a pre-commit message to the transaction coordinator based on the execution status of the transaction operation by the transaction participant includes: Pushing up the first timestamp to obtain a second timestamp; Based on the execution status of the transaction operation by the transaction participant, a pre-commit message carrying the second timestamp is sent to the transaction coordinator.
9. The method according to claim 7, wherein the operation instruction comprises a first operation instruction and a second operation instruction; In response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, processing a first database object matching the executed transaction operation based on the operation instruction includes any of the following: In response to receiving the first operation instruction, based on the first operation instruction, committing the executed transaction operation in a first database object matching the executed transaction operation; In response to receiving the second operation instruction, the executed transaction operation is aborted based on the second operation instruction.
10. The method according to claim 9, wherein in response to receiving the first operation instruction, after committing the executed transaction operation in the first database object matching the executed transaction operation based on the first operation instruction, the method further comprises: releasing the row lock, and sending a first response message to the transaction coordinator, wherein the first response message is used to indicate that the transaction participant has committed the executed transaction operation in a first database object matching the executed transaction operation; After the executed transaction operation is aborted based on the second operation instruction in response to receiving the second operation instruction, the method further includes: A second response message is sent to the transaction coordinator, where the second response message is used to indicate that the transaction participant has aborted the executed transaction operation.
11. The method according to claim 7, further comprising: In response to receiving a recovery execution instruction sent by the transaction coordinator based on a global data recovery task, based on the recovery execution instruction, the transaction operation is re-executed in the second database object indicated by the recovery execution instruction.
12. A distributed transaction processing device, applied to a transaction coordinator in a distributed database with a unitized architecture, the device comprising: A sending module, configured to send a prepare request to multiple transaction participants based on the pending transaction, wherein for any transaction participant, the prepare request is used to instruct the transaction participant to perform a corresponding transaction operation; A receiving module, configured to receive pre-commit messages returned by the multiple transaction participants based on the prepare request, wherein for any transaction participant, the pre-commit message is used to indicate the execution status of the transaction operation by the transaction participant; The sending module is further used to send operation instructions to the multiple transaction participants based on the pre-commit messages returned by the multiple transaction participants. For any transaction participant, the operation instruction is used to instruct the transaction participant to process a first database object that matches the executed transaction operation according to the executed transaction operation.
13. A distributed transaction processing device, applied to a transaction participant in a distributed database of a unitized architecture, the device comprising: A processing module, configured to, in response to receiving a prepare request sent by a transaction coordinator based on a pending transaction, execute a transaction operation corresponding to the transaction participant based on the prepare request; A sending module, used for sending a pre-commit message to the transaction coordinator based on the execution status of the transaction operation by the transaction participant, wherein the pre-commit message is used for indicating the execution status of the transaction operation by the transaction participant; The processing module is further configured to, in response to receiving an operation instruction sent by the transaction coordinator based on pre-commit messages corresponding to multiple transaction participants, process a first database object matching the executed transaction operation based on the operation instruction.
14. A computing device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method as described in any one of claims 1-6 or 7-11 by running the executable instructions.
15. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method as claimed in any one of claims 1 to 6 or 7 to 11.
Citation Information
Cited By
Medical data final consistency synchronization method and device for end-to-end data alignment
CN119652908A
