Transaction processing method and system in distributed database
By introducing global transaction modules and data visibility modules into distributed databases, the problem of high response latency in the existing technology is solved, simplifying the process and reducing latency, and is suitable for high-demand scenarios.
Patent Information
- Application Number
- CN202010268665.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-08
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2040-04-08
AI Technical Summary
When handling distributed transactions, existing distributed databases have high response latency. In particular, Percolator and Spanner models rely on lock information writing and high-precision timestamp services, resulting in high data update cost and limited scope of application. Meet scenarios with high requirements for transaction response delay.
By introducing global transaction modules and data visibility modules in distributed transaction processing, receiving and serializing transaction requests, generating global transaction status information, and deciding whether to perform transaction snapshot requests based on isolation levels, simplifying processing flow, reducing network interactions, and reducing Response delay.
It simplifies the distributed transaction processing process, reduces transaction response delay, and improves snapshot request speed, which is suitable for scenarios with high response delay requirements.
Smart Images

Figure CN113495872B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed databases, and in particular to a distributed transaction processing method and system in a distributed database. Background Art
[0002] With the promotion of mobile Internet, various data are growing exponentially. Traditional stand-alone databases can no longer meet the storage needs of today's growing data volume. Distributed database systems are slowly beginning to replace stand-alone systems.
[0003] Existing distributed databases solve the problem of data consistency in distributed transactions, including models such as Percolator and Spanner. The Percolator model was invented by Google and applied to its internal BigTable system to provide a solution for cross-row distributed transactions. The Percolator model adds two new columns to each row of user data, the lock column and the write column. The lock column is used to lock before writing data, and the write column is used to indicate transaction submission. The written value records the timestamp of this write. Since the Percolator model needs to write lock information to user data, and at the same time, it needs to obtain the submission timestamp from a single-point timestamp server when submitting, and then update the written data, the cost of data update is very high, and user data needs to be written repeatedly, which is not suitable for scenarios with high requirements for transaction response delay. The Spanner model was invented by Google and is a distributed transaction solution based on the True Time API. It proposes the concept of external consistency. True Time is based on atomic clocks and GPS, and provides a timestamp service with an error of 1-7 milliseconds worldwide, which is used to provide submission timestamps for distributed transactions. Since the Spanner model is highly dependent on high-precision, low-error timestamp services, its scope of application is very limited. In addition, since there is still an error in clock accuracy, the submission of a transaction needs to wait for the end of the clock error. At the same time, there is also a waiting situation between reading and writing, which makes it impossible for distributed transactions to achieve low latency. This is not suitable for scenarios with high requirements for transaction response latency. Summary of the invention
[0004] This summary is provided to introduce a set of concepts that will be further described in the following detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
[0005] In order to achieve the above-mentioned purpose, the present specification provides a distributed transaction processing method and system. The present application discloses a method for processing distributed transactions, the method comprising: receiving distributed transaction requests from each transaction participant; sending the distributed transaction request to a global transaction module; receiving a globally serialized transaction request from the global transaction module; generating global transaction status information locally according to the globally serialized transaction request at the transaction participant; and executing SQL statements according to the global transaction status information.
[0006] In some examples, the distributed transaction request includes one or more of the following: a transaction start request, a transaction commit request, a transaction rollback request, a transaction snapshot request, and wherein the global transaction state information includes one or more of the following: a current maximum global transaction identifier, a set of transaction identifiers that are currently active.
[0007] In addition, before each transaction participant submits the distributed transaction request, the method further includes: generating a corresponding global transaction request according to different transaction request types.
[0008] In some examples, generating the corresponding global transaction request further includes:
[0009] If the transaction request type is a transaction start request, the global transaction request includes a transaction participant global identifier and a local transaction identifier generated independently by the transaction participant;
[0010] If the transaction request type is a transaction commit request, the global transaction request includes a transaction participant global identifier and the obtained global transaction identifier;
[0011] If the transaction request type is a transaction rollback request, the global transaction request includes a transaction participant global identifier and the obtained global transaction identifier; and
[0012] If the transaction request type is a transaction snapshot request, it does not need to be converted into a global transaction request, but a request response is directly made locally to obtain global transaction status information.
[0013] In some examples, the globally serialized transaction request further includes: a transaction request obtained by adding a globally incremented sequential ID to the distributed transaction request.
[0014] In addition, generating the global transaction status information further includes:
[0015] If the distributed transaction request is a transaction start request, compare the local transaction identifier contained in the distributed transaction request with the current maximum global transaction identifier in the global transaction state information, and update the local transaction identifier according to the comparison result, wherein if the local transaction identifier is greater than the current maximum global transaction identifier, update the current maximum global transaction identifier to the local transaction identifier, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; if the local transaction identifier is less than or equal to the current maximum global transaction identifier, update the current maximum global transaction identifier to the current maximum global transaction identifier plus one, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state;
[0016] If the distributed transaction request is a transaction commit request or a transaction rollback request, then according to the global transaction identifier included in the distributed transaction request, clear it from the set of currently active transaction identifiers in the global transaction state information; and
[0017] If the distributed transaction request is a transaction snapshot request, snapshot information of the current global transaction state information is obtained.
[0018] In addition, before executing the SQL statement according to the global transaction status information, the method further includes: determining whether it is necessary to perform a transaction snapshot request before executing the SQL statement according to the isolation level set by the transaction participant, wherein the global transaction identifier contained in the data in the database is generated according to the global transaction identifier of the transaction participant, and the data in the database of the transaction participant contains transaction identifier information; and if a transaction snapshot request is performed, determining the visibility of the data according to the obtained transaction snapshot information in combination with the transaction identifier information in the data.
[0019] In some examples, making a transaction snapshot request further includes: if the isolation level is a read committed isolation level, a transaction snapshot request needs to be made before each SQL statement in the distributed transaction is executed; and if the isolation level is a snapshot isolation level, a transaction snapshot request only needs to be made before the first SQL statement in the distributed transaction is executed.
[0020] In some examples, determining visibility of data further includes:
[0021] If the global transaction identifier in the data is consistent with the global transaction identifier of the transaction participant, the data is considered visible;
[0022] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is in the active transaction identifier of the snapshot information, the data is judged to be invisible;
[0023] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifiers in the snapshot information, and the global transaction identifier in the data is less than or equal to the maximum global transaction identifier in the snapshot information, then the data is determined to be visible; and
[0024] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier of the snapshot information, and the global transaction identifier in the data is greater than the maximum global transaction identifier in the snapshot information, the data is judged to be invisible.
[0025] In order to achieve the above-mentioned purpose, the present application discloses a system for processing distributed transactions, which includes: a local transaction module, which is used to receive distributed transaction requests from various transaction participants; send the distributed transaction requests to a global transaction module; receive globally serialized transaction requests from the global transaction module; generate global transaction status information according to the globally serialized transaction requests; and a data visibility module, which is used to execute SQL statements according to the global transaction status information.
[0026] In some examples, the distributed transaction request includes: a transaction start request, a transaction commit request, a transaction rollback request, a transaction snapshot request, and wherein the global transaction status information includes: a current maximum global transaction identifier, and an identifier of a currently active transaction.
[0027] In addition, the local transaction module is further used to generate a global transaction request according to different transaction request types, wherein: if the transaction request type is a transaction start request, the global transaction request includes a transaction participant global identifier and a local transaction identifier generated independently by the transaction participant; if the transaction request type is a transaction commit request, the global transaction request includes a transaction participant global identifier and an obtained global transaction identifier; if the transaction request type is a transaction rollback request, the global transaction request includes a transaction participant global identifier and an obtained global transaction identifier; and if the transaction request type is a transaction snapshot request, it does not need to be converted into a global transaction request, but a request response is directly performed locally to obtain global transaction status information.
[0028] In some examples, the local transaction module generates the global transaction state information by:
[0029] If the distributed transaction request is a transaction start request, compare the local transaction identifier contained in the distributed transaction request with the current maximum global transaction identifier in the global transaction state information, and update the local transaction identifier according to the comparison result, wherein if the local transaction identifier is greater than the current maximum global transaction identifier, update the current maximum global transaction identifier to the local transaction identifier, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; if the local transaction identifier is less than or equal to the current maximum global transaction identifier, update the current maximum global transaction identifier to the current maximum global transaction identifier plus one, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state;
[0030] If the distributed transaction request is a transaction commit request or a transaction rollback request, then according to the global transaction identifier included in the distributed transaction request, clear it from the set of currently active transaction identifiers in the global transaction state information; and
[0031] If the distributed transaction request is a transaction snapshot request, snapshot information of the current global transaction state information is obtained.
[0032] In some examples, the globally serialized transaction request further includes: a transaction request obtained by adding a globally incremented sequential ID to the distributed transaction request.
[0033] In addition, the data visibility module is further used to: before executing the SQL statement, determine whether it is necessary to perform a transaction snapshot request before executing the SQL statement according to the isolation level set by the transaction participant, wherein the global transaction identifier contained in the data in the database is generated according to the global transaction identifier of the transaction participant, and the data in the database of the transaction participant contains transaction identifier information, and if a transaction snapshot request is performed, the visibility of the data is determined based on the obtained transaction snapshot information in combination with the transaction identifier information in the data.
[0034] In some examples, the data visibility module performs a transaction snapshot request by performing the following operations: if the isolation level is a read committed isolation level, a transaction snapshot request needs to be performed before each SQL statement in the distributed transaction is executed; and if the isolation level is a snapshot isolation level, a transaction snapshot request only needs to be performed before the first SQL statement in the distributed transaction is executed.
[0035] In addition, the data visibility module determines the visibility of the data by:
[0036] If the global transaction identifier in the data is consistent with the global transaction identifier of the transaction participant, the data is considered visible;
[0037] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is in the active transaction identifier of the snapshot information, the data is judged to be invisible;
[0038] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifiers in the snapshot information, and the global transaction identifier in the data is less than or equal to the maximum global transaction identifier in the snapshot information, then the data is determined to be visible; and
[0039] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier of the snapshot information, and the global transaction identifier in the data is greater than the maximum global transaction identifier in the snapshot information, the data is judged to be invisible.
[0040] According to an embodiment of the present invention, an apparatus for processing distributed transactions includes: a processor; and a memory for storing executable instructions, wherein the executable instructions, when executed, enable the processor to execute the aforementioned method.
[0041] According to a machine-readable medium of an embodiment of the present invention, executable instructions are stored thereon, wherein when the executable instructions are executed, the machine executes the aforementioned method.
[0042] Compared with the prior art, the technical effects that can be obtained by this application include:
[0043] (1) Only transaction requests are globally serialized, and there is no need to respond to each transaction request separately, which simplifies the processing flow of distributed transaction processing;
[0044] (2) Transaction snapshot requests are localized, eliminating the need for global transaction requests, reducing network interactions and significantly increasing the speed of snapshot requests;
[0045] (3) Transaction requests are all memory and network operations, and do not require synchronous disk operations, which reduces the response delay of distributed transactions.
[0046] It should be noted that one or more of the above aspects include the features described in detail below and specifically pointed out in the claims. The following description and drawings set forth in detail certain illustrative features of the one or more aspects. These features are merely indicative of the various ways in which the principles of various aspects may be implemented, and the present disclosure is intended to include all such aspects and their equivalents. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The disclosed aspects will be described below in conjunction with the accompanying drawings, which are provided to illustrate rather than limit the disclosed aspects.
[0048] Figure 1 A schematic diagram of a process for processing a distributed transaction according to an embodiment of the present application is shown;
[0049] Figure 2 A schematic flow chart of another method for processing distributed transactions according to an embodiment of the present application is shown;
[0050] Figure 3 A schematic flow chart of another method for processing distributed transactions according to an embodiment of the present application is shown;
[0051] Figure 4 A schematic diagram of the structure of a system for processing distributed transactions according to an embodiment of the present application is shown;
[0052] Figure 5 A schematic diagram of an apparatus for processing distributed transactions according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0053] The present disclosure will now be discussed with reference to various exemplary embodiments. It should be understood that the discussion of these embodiments is only for enabling those skilled in the art to better understand and thereby implement examples of the present disclosure, and does not teach any limitation on the scope of the present disclosure.
[0054] Various embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0055] The implementation of the method of the present application is further described below with reference to the first embodiment. Figure 1 A schematic flow chart of a method 100 for processing distributed transactions according to an embodiment of the present application is shown.
[0056] The method 100 includes: at step S102, a transaction participant sends a distributed transaction request to a global transaction module through a local transaction module. In some examples, the distributed transaction request is received by the local transaction module from each transaction participant, and includes but is not limited to one or more of the following: a transaction start request, a transaction commit request, a transaction rollback request, a transaction snapshot request, etc.
[0057] In step S104, the transaction participant receives a globally serialized distributed transaction request from the global transaction module through the local transaction module, wherein the globally serialized distributed transaction request is obtained by the global transaction module by performing a global serialization operation on the distributed transaction request.
[0058] In step S106, global transaction status information is generated at the transaction participant through the local transaction module according to the globally serialized distributed transaction request. In this article, the global transaction status information includes but is not limited to one or more of the following: the current maximum global transaction identifier, the transaction identifier currently in an active state, etc., wherein the global transaction identifier represents a globally unique identifier (ID) for the transaction, the current maximum global transaction identifier represents the maximum value of the global transaction identifier allocated for the latest global transaction start request, and the transaction identifier currently in an active state indicates a transaction generated according to the global transaction start request but has not yet made a transaction commit or transaction rollback request, wherein an active transaction is generated when a global transaction start request is received, and the active transaction is terminated when a global transaction commit or transaction rollback request is received.
[0059] In step S106, the transaction participant executes a specific structured query language (SQL) statement according to the generated global transaction status information through the local transaction module, for example, to determine the visibility of data.
[0060] The implementation of the method of the present application is further described below with reference to the second embodiment. Figure 2 A schematic flow chart of another method 200 for processing distributed transactions according to an embodiment of the present application is shown. In this embodiment, a global transaction start request processing process in the method for processing distributed transactions is described in detail.
[0061] The method includes: at step S202, the local transaction module receives a distributed transaction start request from a transaction participant.
[0062] In step S204, the local transaction module constructs a global transaction start request based on the distributed transaction start request. In this article, the global transaction start request includes but is not limited to one or more of the following: a transaction participant's globally unique identifier, a local transaction identifier generated independently by a transaction participant, etc. In this article, the transaction participant's globally unique identifier is composed of a local transaction module unique identifier and a transaction participant identifier. For example, if the local transaction module's unique identifier is 0x1 and the transaction participant identifier is 0x2, then the transaction participant's globally unique identifier is 0x0000000100000002. In some examples, the local transaction identifier is generated by a local transaction module and includes a physical clock and a logical clock, wherein the physical clock represents the number of milliseconds from the current time to 1970, and the logical clock is used to resolve time conflicts caused by physical clock rollback or the same clock. In some examples, if there are two or more concurrent transaction requests from two or more transaction participants at the same time indicated by the physical clock, these concurrent transaction requests cannot be distinguished by the same physical clock. In this case, different logical clocks can be assigned to different transaction participants, such as logical clock 1 for transaction participant 1, logical clock 2 for transaction participant 2, and so on, so that different transaction participants can be distinguished by combining the physical clock and the logical clock. For example, the currently assigned physical clock is 1578486304711, and the corresponding local transaction identifier is 1578486304711<<16. If this identifier is smaller than the last assigned local transaction identifier, the last assigned local transaction identifier plus one is selected as the current local transaction identifier. It should be understood that here, adding one to the last assigned local transaction identifier as the current local transaction identifier is only an example. In actual applications, any appropriate method can be used to generate the current local transaction identifier based on the last assigned local transaction identifier.
[0063] In step S206, the local transaction module sends a global transaction start request to the global transaction module.
[0064] In step S208, the local transaction module receives a serialized global transaction start request from the global transaction module, wherein the serialized global transaction start request is obtained by the global transaction module performing a serialization operation on the global transaction start request, for example, adding a globally incremented continuous ID to the global transaction start request.
[0065] In step S210, the local transaction module generates global transaction status information by processing the serialized global transaction start request, wherein the global transaction status information includes but is not limited to one or more of the following: the current maximum global transaction identifier and the currently active transaction identifier.
[0066] In some examples, the global transaction status information can be further generated according to the following steps: comparing the local transaction identifier included in the global transaction start request with the current maximum global transaction identifier in the global transaction status information; if the local transaction identifier is greater than the current maximum global transaction identifier, updating the current maximum global transaction identifier to the local transaction identifier, and using it as the new current maximum global transaction identifier of the corresponding participant, and placing the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; if the local transaction identifier is less than or equal to the current maximum global transaction identifier, updating the current maximum global transaction identifier to the current maximum global transaction identifier plus one, and using it as the global transaction identifier of the corresponding participant, and placing the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state.
[0067] The implementation of the method of the present application is further described below with reference to the third embodiment. Figure 3 A schematic flow chart of another method 300 for processing distributed transactions according to an embodiment of the present application is shown. In this embodiment, a data visibility judgment process in a method for processing distributed transactions is described in detail. Specifically, this embodiment describes how to perform visibility judgment on data involved in the process of executing SQL statements according to global transaction state information generated by a local transaction module.
[0068] The method 300 includes: in step S302, if the global transaction identifier in the data is consistent with the global transaction identifier of the transaction participant, then proceeding to step S310, where the data is determined to be visible; otherwise, proceeding to step S304.
[0069] In step S304, if the global transaction identifier in the data is in the active transaction identifier set of the snapshot information of the global transaction state information, the process proceeds to step S308, where the data is determined to be invisible; otherwise, the process proceeds to step S306.
[0070] In step S306, if the global transaction identifier in the data is less than or equal to the maximum global transaction identifier in the snapshot information, the process proceeds to step S310, where the data is determined to be visible; otherwise, the process proceeds to step S308, where the data is determined to be invisible.
[0071] The implementation of the system of the present application is further described below with another embodiment. Figure 4 A schematic structural diagram of a system 400 for processing distributed transactions according to an embodiment of the present application is shown. In some examples, the system 400 may include a local transaction module 402 , a global transaction module 404 , and a data visibility module 406 .
[0072] In some examples, the local transaction module 402 is used to receive a distributed transaction request from a transaction participant, and generate a corresponding global transaction request according to different distributed transaction request types. In other examples, a global transaction request corresponding to the transaction participant can be generated based on the distributed transaction request from the transaction requester according to local information associated with the transaction participant. In some examples, the distributed transaction request type includes one or more of the following: a transaction start request, a transaction commit request, a transaction rollback request, a transaction snapshot request, etc.
[0073] The global transaction module 404 receives the distributed transaction requests of each transaction participant from the local transaction module 402, globally serializes the distributed transaction requests, and sends the globally serialized transaction requests to each transaction participant.
[0074] The local transaction module 402 receives the globally serialized transaction request from the global transaction module 404, and generates global transaction status information according to the globally serialized transaction request. In some examples, the global transaction status information includes one or more of the following: the current maximum global transaction identifier, the currently active transaction identifier, etc.
[0075] The data visibility module 406 executes a specific SQL statement according to the global transaction status information generated by the local transaction module 402, for example, to determine the visibility of the data.
[0076] In addition, the local transaction module 402 may generate global transaction status information in the following manner: if the distributed transaction request is a transaction start request, the global transaction request includes a transaction participant global identifier and a local transaction identifier generated independently by the transaction participant; if the distributed transaction request is a transaction commit request, the global transaction request includes a transaction participant global identifier and an obtained global transaction identifier of the transaction participant; if the distributed transaction request is a transaction rollback request, the global transaction request includes a transaction participant global identifier and an obtained global transaction identifier of the transaction participant; if the distributed transaction request is a transaction snapshot request, it does not need to be converted into a global transaction request, and a request response may be directly performed locally to obtain global transaction status information.
[0077] In addition, the local transaction module 402 may also generate global transaction status information in the following manner:
[0078] If the distributed transaction request is a transaction start request, the local transaction identifier included in the distributed transaction request is compared with the current maximum global transaction identifier in the global transaction status information: if the local transaction identifier is greater than the current maximum global transaction identifier, the current maximum global transaction identifier is updated to the local transaction identifier, and is used as the global transaction identifier of the corresponding participant, and the updated current maximum global transaction identifier is placed in the transaction identifier set that is currently in an active state; and if the local transaction identifier is less than or equal to the current maximum global transaction identifier, the current maximum global transaction identifier is updated to the current maximum global transaction identifier plus one, and is used as the global transaction identifier of the corresponding participant, and the updated current maximum global transaction identifier is placed in the transaction identifier set that is currently in an active state;
[0079] If the distributed transaction request is a transaction commit request or a transaction rollback request, then according to the global transaction identifier included in the distributed transaction request, clear it from the set of currently active transaction identifiers in the global transaction status information; and
[0080] If the distributed transaction request is a transaction snapshot request, snapshot information of the current global transaction state information is obtained.
[0081] In addition, the global transaction module 404 may add globally incremented continuous IDs to the distributed transaction requests.
[0082] In addition, before executing a specific SQL statement, the data visibility module determines whether it is necessary to make a transaction snapshot request before executing the SQL statement based on the isolation level set by the transaction participant. In this article, the global transaction identifier contained in the data in the database is generated based on the global transaction identifier of the transaction participant. If it is determined that it is necessary to make a transaction snapshot request before executing the SQL statement, the visibility of the data is determined based on the transaction snapshot information obtained when making the transaction snapshot request, combined with the comparison of the global transaction identifier in the data with the global transaction identifier of the transaction participant.
[0083] In addition, the data visibility module 406 uses the following method to make a transaction snapshot request: if the transaction participant sets the read committed isolation level, a transaction snapshot request needs to be made before each SQL statement in the transaction is executed; if the transaction participant sets the snapshot isolation level, a transaction snapshot request only needs to be made before the first SQL statement in the transaction is executed.
[0084] In addition, the data visibility module 406 uses the following method to determine the visibility of data in the database:
[0085] If the global transaction identifier in the data is consistent with the global transaction identifier of the transaction participant, the data is considered visible;
[0086] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is in the active transaction identifier set of the snapshot information, the data is judged to be invisible;
[0087] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier set of the snapshot information, and the global transaction identifier in the data is less than or equal to the maximum global transaction identifier in the snapshot information, then the data is judged to be visible;
[0088] If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier set of the snapshot information, and the global transaction identifier in the data is greater than the maximum global transaction identifier in the snapshot information, the data is judged to be invisible.
[0089] Figure 5 A schematic diagram of an apparatus 500 for processing distributed transactions according to an embodiment of the present invention is shown.
[0090] like Figure 5 As shown, the apparatus 500 may include a processor 502 and a memory 504, wherein the memory 504 is used to store executable instructions, and when the executable instructions are executed, the processor 502 executes the method described above.
[0091] An embodiment of the present invention further provides a machine-readable medium on which executable instructions are stored. When the executable instructions are executed, the machine executes the above method.
[0092] It should be understood that all operations in the method described above are merely exemplary, and the present disclosure is not limited to any operation in the method or the order of these operations, but should cover all other equivalent transformations under the same or similar concept.
[0093] It should also be understood that all modules in the above-described device can be implemented in various ways. These modules can be implemented as hardware, software, or a combination thereof. In addition, any module in these modules can be further divided into submodules or combined together functionally. The above-mentioned method, device, and machine-readable medium for processing distributed transactions can all be implemented by a distributed database product GreatDB Cluster.
[0094] The above description shows and describes several preferred embodiments of the present application, but as mentioned above, it should be understood that the present application is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the invention concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art do not depart from the spirit and scope of the present application, and should be within the scope of protection of the claims attached to the present application.
Claims
1. A method for processing distributed transactions, comprising: Receive distributed transaction requests from various transaction participants; Sending the distributed transaction request to a global transaction module; receiving a globally serialized transaction request from the global transaction module; Generate global transaction status information locally at the transaction participant according to the globally serialized transaction request; as well as Execute SQL statements according to the global transaction status information; The distributed transaction request includes one or more of the following: a transaction start request, a transaction commit request, a transaction rollback request, and a transaction snapshot request, and the global transaction status information includes one or more of the following: a current maximum global transaction identifier and a set of transaction identifiers that are currently active.
2. The method according to claim 1, characterized in that: Before each transaction participant submits the distributed transaction request, the method further includes: generating a corresponding global transaction request according to different transaction request types; Wherein, generating the corresponding global transaction request further includes: If the transaction request type is a transaction start request, the global transaction request includes a transaction participant global identifier and a local transaction identifier generated independently by the transaction participant; If the transaction request type is a transaction commit request, the global transaction request includes a transaction participant global identifier and the obtained global transaction identifier; If the transaction request type is a transaction rollback request, the global transaction request includes a transaction participant global identifier and the obtained global transaction identifier; and If the transaction request type is a transaction snapshot request, it does not need to be converted into a global transaction request, but a request response is directly made locally to obtain global transaction status information.
3. The method according to claim 1, characterized in that in, The globally serialized transaction request further includes: a transaction request obtained by adding globally incremented consecutive IDs to the distributed transaction request.
4. The method according to claim 1, characterized in that: Generating the global transaction status information further includes: If the distributed transaction request is a transaction start request, compare the local transaction identifier contained in the distributed transaction request with the current maximum global transaction identifier in the global transaction state information, and update the local transaction identifier according to the comparison result, wherein if the local transaction identifier is greater than the current maximum global transaction identifier, update the current maximum global transaction identifier to the local transaction identifier, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; if the local transaction identifier is less than or equal to the current maximum global transaction identifier, update the current maximum global transaction identifier to the current maximum global transaction identifier plus one, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; If the distributed transaction request is a transaction commit request or a transaction rollback request, then according to the global transaction identifier included in the distributed transaction request, clear it from the set of currently active transaction identifiers in the global transaction state information; and If the distributed transaction request is a transaction snapshot request, snapshot information of the current global transaction state information is obtained.
5. The method according to claim 1, characterized in that Before executing the SQL statement according to the global transaction status information, the method further includes: Determining whether it is necessary to perform a transaction snapshot request before executing the SQL statement according to the isolation level set by the transaction participant, wherein the global transaction identifier included in the data in the database is generated according to the global transaction identifier of the transaction participant, and the data in the database of the transaction participant includes transaction identifier information; and If a transaction snapshot request is made, the visibility of the data is determined based on the obtained transaction snapshot information combined with the transaction identification information in the data.
6. The method according to claim 5, characterized in that Making a transaction snapshot request further includes: If the isolation level is the read committed isolation level, a transaction snapshot request needs to be made before each SQL statement in the distributed transaction is executed; and If the isolation level is a snapshot isolation level, a transaction snapshot request only needs to be made before the first SQL statement in the distributed transaction is executed.
7. The method according to claim 5, characterized in that Determining data visibility further includes: If the global transaction identifier in the data is consistent with the global transaction identifier of the transaction participant, the data is considered visible; If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is in the active transaction identifier of the snapshot information, the data is judged to be invisible; If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier of the snapshot information, and the global transaction identifier in the data is less than or equal to the maximum global transaction identifier in the snapshot information, then the data is considered visible; If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier of the snapshot information, and the global transaction identifier in the data is greater than the maximum global transaction identifier in the snapshot information, the data is judged to be invisible.
8. A system for processing distributed transactions, comprising: Local transaction module for: Receive distributed transaction requests from various transaction participants; Sending the distributed transaction request to a global transaction module; receiving a globally serialized transaction request from the global transaction module; Generate global transaction state information according to the globally serialized transaction request; as well as A data visibility module, used for executing SQL statements according to the global transaction status information; The distributed transaction request includes: a transaction start request, a transaction commit request, a transaction rollback request, and a transaction snapshot request, and the global transaction status information includes: the current maximum global transaction identifier and the identifier of the transaction currently in an active state.
9. The system according to claim 8, characterized in that The local transaction module is also used to generate a global transaction request according to different transaction request types, wherein: If the transaction request type is a transaction start request, the global transaction request includes a transaction participant global identifier and a local transaction identifier generated independently by the transaction participant; If the transaction request type is a transaction commit request, the global transaction request includes a transaction participant global identifier and the obtained global transaction identifier; If the transaction request type is a transaction rollback request, the global transaction request includes a transaction participant global identifier and the obtained global transaction identifier; and If the transaction request type is a transaction snapshot request, it does not need to be converted into a global transaction request, but a request response is directly made locally to obtain global transaction status information.
10. The system according to claim 8, characterized in that The local transaction module generates the global transaction status information by the following operations: If the distributed transaction request is a transaction start request, compare the local transaction identifier contained in the distributed transaction request with the current maximum global transaction identifier in the global transaction state information, and update the local transaction identifier according to the comparison result, wherein if the local transaction identifier is greater than the current maximum global transaction identifier, update the current maximum global transaction identifier to the local transaction identifier, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; if the local transaction identifier is less than or equal to the current maximum global transaction identifier, update the current maximum global transaction identifier to the current maximum global transaction identifier plus one, and use it as the global transaction identifier of the corresponding participant, and put the updated current maximum global transaction identifier into the transaction identifier set that is currently in an active state; If the distributed transaction request is a transaction commit request or a transaction rollback request, then according to the global transaction identifier included in the distributed transaction request, clear it from the set of currently active transaction identifiers in the global transaction state information; and If the distributed transaction request is a transaction snapshot request, snapshot information of the current global transaction state information is obtained.
11. The system according to claim 8, characterized in that The globally serialized transaction request further includes: a transaction request obtained by adding globally incremented consecutive IDs to the distributed transaction request.
12. The system according to claim 8, characterized in that The data visibility module is further used to: before executing the SQL statement, determine whether it is necessary to perform a transaction snapshot request according to the isolation level set by the transaction participant, wherein the global transaction identifier contained in the data in the database is generated according to the global transaction identifier of the transaction participant, and the data in the database of the transaction participant contains transaction identifier information, and If a transaction snapshot request is made, the visibility of the data is determined based on the obtained transaction snapshot information combined with the transaction identification information in the data.
13. The system according to claim 12, characterized in that The data visibility module performs the transaction snapshot request by: If the isolation level is the read committed isolation level, a transaction snapshot request needs to be made before each SQL statement in the distributed transaction is executed; as well as If the isolation level is a snapshot isolation level, a transaction snapshot request only needs to be made before the first SQL statement in the distributed transaction is executed.
14. The system according to claim 12, characterized in that The data visibility module determines the visibility of data by: If the global transaction identifier in the data is consistent with the global transaction identifier of the transaction participant, the data is considered visible; If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is in the active transaction identifier of the snapshot information, the data is judged to be invisible; If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier of the snapshot information, and the global transaction identifier in the data is less than or equal to the maximum global transaction identifier in the snapshot information, then the data is considered visible; as well as If the global transaction identifier in the data is inconsistent with the global transaction identifier of the transaction participant, and the global transaction identifier in the data is not in the active transaction identifier of the snapshot information, and the global transaction identifier in the data is greater than the maximum global transaction identifier in the snapshot information, the data is judged to be invisible.
15. An apparatus for processing distributed transactions, comprising: processor; as well as A memory for storing executable instructions, wherein the executable instructions, when executed, cause the processor to perform the method of claims 1-7.
16. A machine-readable medium having executable instructions stored thereon, wherein: When the executable instructions are executed, the machine performs the method of claims 1-7.
