Distributed transaction processing method, device, equipment, storage medium and program product
By introducing a preset delay mechanism in distributed transaction processing, delaying the execution time of read requests for hot data items and giving priority to write requests containing smaller timestamps solves the problem of high distributed transaction abort rate and improves the system's performance. Throughput and latency performance.
Patent Information
- Application Number
- CN202111617497.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2041-12-27
Smart Images

Figure CN114398157B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed transaction technology, and in particular to a distributed transaction processing method, device, equipment, storage medium and program product. Background Art
[0002] A transaction is a computing unit in which users concurrently access a database. This computing unit has the characteristics of atomicity, consistency, isolation, and persistence. As the amount of data in various applications increases, data must be divided into servers at different nodes. Transactions involving multiple servers are called distributed transactions. During the execution of a distributed transaction, a transaction often contains multiple requests, and some requests have dependencies. The dependencies between requests lead to a high transaction abort rate when the server nodes in the distributed transaction system access data, especially when accessing hot data, causing execution delays for individual transactions and reduced throughput of the entire distributed transaction system.
[0003] In the prior art, the processing of distributed transactions is implemented based on timestamps. There are two main ways to optimize the distributed transaction processing method based on timestamps: one is to optimize the scalability of distributed clocks. Although this improvement helps the distributed transaction system to increase scalability, it further reduces the accuracy and still causes distributed transactions to be frequently aborted on hot data; the other is to look for opportunities in the submission phase to save the originally aborted transaction, but conflicts often occur in the execution phase, and the abort in the submission phase is irreversible, and it is still impossible to effectively reduce the transaction abort rate. Summary of the invention
[0004] The present invention provides a distributed transaction processing method, device, equipment, storage medium and program product, which are used to solve the defect of high transaction abort rate in the distributed transaction processing process in the prior art and reduce the transaction abort rate in the distributed transaction processing process.
[0005] The present invention provides a distributed transaction processing method, which is applied to a transaction executor, and includes: receiving a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator; postponing the execution time of the first request through a preset postponement mechanism; when the first request is not executed, receiving a second request, wherein the second request includes a second timestamp, and the second timestamp is less than the first timestamp; executing the second request at the execution time indicated by the second timestamp; and executing the first request when the postponement mechanism ends.
[0006] According to a distributed transaction processing method provided by the present invention, postponing the execution time of the first request through a preset postponement mechanism includes: determining that the first request is a read request for a target data item; and postponing the execution time of the first request.
[0007] According to a distributed transaction processing method provided by the present invention, postponing the execution time of the first request includes: obtaining the request access volume of the target data item within a preset time length; when determining that the request access volume is greater than a preset access threshold, postponing the execution time of the first request.
[0008] According to a distributed transaction processing method provided by the present invention, the postponing of the execution time of the first request includes: postponing the execution time of the first request by a first preset time length; when the first preset time length is postponed, obtaining the request failure rate of the target data item; judging whether the request failure rate is less than a preset failure threshold, and if so, executing the first request; if not, postponing the execution time of the first request again by a second preset time length, and obtaining the request failure rate of the target data item with the second preset time length as a period until the request failure rate is less than the failure threshold.
[0009] According to a distributed transaction processing method provided by the present invention, before executing the first request, it also includes: determining that the first request contains dependency information, wherein the dependency information is used to indicate that the execution process of the third request depends on the execution result of the first request, and the third request includes the first timestamp; after executing the first request, it also includes: when the third request is not received, receiving a fourth request, wherein the fourth request contains a fourth timestamp, wherein the fourth timestamp is greater than the first timestamp; blocking the execution of the fourth request until the third request is received and executed, and then executing the fourth request so that the third request is executed before the fourth request.
[0010] According to a distributed transaction processing method provided by the present invention, when determining that the first request contains dependency information, it also includes: judging whether there is an environmental basis for the execution of the third request, and if not, generating request failure information for the first request, and transmitting the request failure information to the transaction coordinator; if so, generating pre-occupied place information for the third request, and when the first request is executed, generating first commit information, and transmitting the first commit information to the transaction coordinator; blocking the execution of the fourth request includes: blocking the execution of the fourth request according to the pre-occupied place information.
[0011] According to a distributed transaction processing method provided by the present invention, the first request is a read request for the target data item, and the third request is a write request for the target data item; blocking the execution of the fourth request includes: determining that the fourth request is a read request for the target data item; and blocking the execution of the fourth request.
[0012] According to a distributed transaction processing method provided by the present invention, the execution of the first request includes: based on a local processor clock, determining that when the local processor timing reaches the execution time indicated by the first timestamp, executing the first request; wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock.
[0013] The present invention provides a distributed transaction processing method, which is applied to a transaction coordinator, comprising: upon receiving a target transaction transmitted by an upper-layer application, generating a clock request execution and transmitting it to a local clock module; obtaining a first timestamp returned by the local clock module; generating the first request based on the first timestamp, and transmitting the first request to a transaction executor.
[0014] According to a distributed transaction processing method provided by the present invention, before generating the first request based on the first timestamp, it also includes: determining dependency information, wherein the dependency information is used to indicate that the execution process of the third request depends on the execution result of the first request; generating the first request based on the first timestamp includes: generating the first request based on the first timestamp and the dependency information.
[0015] According to a distributed transaction processing method provided by the present invention, after transmitting the first request to the transaction executor, the method further includes: obtaining request failure information transmitted by the transaction executor; generating transaction failure information of the target transaction, and transmitting the transaction failure information to the upper-layer application, wherein the request failure information indicates that the transaction executor does not have an environment basis for executing the third request; or, obtaining first commit information transmitted by the transaction executor, generating the third request, and transmitting the third request to the transaction executor.
[0016] According to a distributed transaction processing method provided by the present invention, the first request is a read request for a target data item, and the third request is a write request for the target data item; the obtaining of the first commit information transmitted by the transaction executor, generating the third request, and transmitting the third request to the transaction executor, includes: obtaining the first commit information transmitted by the transaction executor; calculating the latest data that needs to be written to the target data item based on the first commit information; generating the third request based on the latest data, and transmitting the third request to the transaction executor.
[0017] The present invention provides a distributed transaction processing method, which is applied to a local clock module, comprising: upon receiving a clock request instruction transmitted by a transaction coordinator, obtaining a first timestamp generated by a local processor clock, wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock; and returning the first timestamp to the transaction coordinator.
[0018] According to a distributed transaction processing method provided by the present invention, before receiving the clock request instruction transmitted by the transaction coordinator, it also includes: obtaining a first mapping relationship between the preset root network card clock and the local network card clock; adjusting the local network card clock according to the first mapping relationship so that the local network card clock and the preset root network card clock are synchronized; obtaining a second mapping relationship between the local network card clock and the local processor clock; adjusting the local processor clock according to the second mapping relationship so that the local processor clock and the local network card clock are synchronized.
[0019] According to a distributed transaction processing method provided by the present invention, the first mapping relationship between the preset root network card clock and the local network card clock is obtained, including: in at least one continuous time slice, performing at least one of the following processing respectively: in an unreliable service mode oriented to datagrams, the local network card sends a first data packet to the preset root network card, and obtains a first local network card timestamp corresponding to the local network card clock when the first data packet leaves the local network card; in a reliable service mode oriented to connection, the local network card sends a second data packet to the preset root network card, and obtains a second local network card timestamp corresponding to the local network card clock when the second data packet leaves the local network card; obtains the preset Assume a first root network card timestamp and a second network card timestamp transmitted by the root network card, wherein the first root network card timestamp is the timestamp corresponding to the preset root network card clock when the first data packet reaches the preset root network card, and the second root network card timestamp is the timestamp corresponding to the preset root network card clock when the second data packet reaches the preset root network card; according to the first local network card timestamp, the first root network card timestamp, the second local network card timestamp and the second root network card timestamp, obtain a first timestamp probe pair of the preset root network card clock and the local network card clock; according to at least one of the first timestamp probe pairs in at least one of the time slices, obtain the first mapping relationship.
[0020] According to a distributed transaction processing method provided by the present invention, the first mapping relationship is obtained according to at least one of the first timestamp probe pairs in at least one of the time slices, including: fitting the linear relationship between the preset root network card clock and the local network card clock according to the first timestamp probe pair in at least one of the time slices; obtaining the i-th midpoint function value of the linear relationship in the i-th time slice, and obtaining the i+1-th midpoint function value of the linear relationship in the i+1-th time slice, where i is an integer greater than or equal to 0; taking the intersection of the straight line formed by connecting the i-th midpoint function value and the i+1-th midpoint function value and the right endpoint of the i+3-th time slice as the i-th prediction point; connecting at least two of the prediction points in sequence to obtain the first mapping relationship.
[0021] According to a distributed transaction processing method provided by the present invention, the obtaining of the second mapping relationship between the local network card clock and the local processor clock includes: performing at least one of the following processing in at least one continuous time slice: obtaining the first processor timestamp of the local processor clock; obtaining the first network card timestamp generated by the local network card clock; obtaining the second processor timestamp generated by the local processor time; determining the central processor timestamp corresponding to the first network card timestamp based on the first processor timestamp, the second processor timestamp and a preset fitting coefficient; obtaining the second timestamp probe pair of the local network card clock and the local processor clock according to the central processor timestamp and the first network card timestamp; obtaining the second mapping relationship according to at least one of the second timestamp probe pairs in at least one of the time slices.
[0022] The present invention also provides a transaction executor device for distributed transaction processing, comprising: a first receiving module, used to receive a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator; a deferral module, used to defer the execution time of the first request through a preset deferral mechanism; a second receiving module, used to receive a second request when the first request is not executed, wherein the second request includes a second timestamp, and the second timestamp is less than the first timestamp; a first execution module, used to execute the second request at the execution time indicated by the second timestamp; and a second execution module, used to execute the first request when the deferral mechanism ends.
[0023] The present invention also provides a transaction coordinator device for distributed transaction processing, comprising: a third receiving module, which is used to generate a clock request execution when receiving a target transaction transmitted by an upper-layer application, and transmit it to a local clock module; an acquisition module, which is used to obtain a first timestamp returned by the local clock module; and a generation module, which is used to generate the first request based on the first timestamp, and transmit the first request to a transaction executor.
[0024] The present invention also provides a local clock module for distributed transaction processing, comprising: a receiving unit, used to obtain a first timestamp generated by a local processor clock when receiving a clock request instruction transmitted by a transaction coordinator, wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock; a returning unit, used to return the first timestamp to the transaction coordinator.
[0025] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the distributed transaction processing method with a transaction executor as the execution subject as described in any one of the above are implemented; or, when the processor executes the program, the steps of the distributed transaction processing method with a transaction coordinator as the execution subject as described in any one of the above are implemented; or, when the processor executes the program, the steps of the distributed transaction processing method with a local clock module as the execution subject as described in any one of the above are implemented.
[0026] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of a distributed transaction processing method with a transaction executor as the execution subject as described in any one of the above; or, when executed by a processor, implements the steps of a distributed transaction processing method with a transaction coordinator as the execution subject as described in any one of the above; or, when executed by a processor, implements the steps of a distributed transaction processing method with a local clock module as the execution subject as described in any one of the above.
[0027] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the steps of any of the above-mentioned distributed transaction processing methods with a transaction executor as the execution subject; or, when the computer program is executed by a processor, the computer program implements the steps of any of the above-mentioned distributed transaction processing methods with a transaction coordinator as the execution subject; or, when the computer program is executed by a processor, the computer program implements the steps of any of the above-mentioned distributed transaction processing methods with a local clock module as the execution subject.
[0028] The distributed transaction processing method, device, equipment, storage medium and program product provided by the present invention, the transaction executor receives the first request transmitted by the transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through the local clock module corresponding to the transaction coordinator; the execution time of the first request is postponed through a preset postponement mechanism; when the first request is not executed, a second request is received, wherein the second request includes a second timestamp, and the second timestamp is smaller than the first timestamp; at the execution time indicated by the second timestamp, the second request is executed; when the postponement mechanism ends, the first request is executed. In the prior art, when the first request reaches the transaction executor first, the transaction executor will execute the first request; however, since the second timestamp is smaller than the first timestamp, after the first request is executed, the second request will be unable to be executed, and the transaction corresponding to the second request will be terminated. In the present invention, after receiving the first request, the transaction executor will postpone the first request so that the second request including a smaller second timestamp is executed first, and then the first request is executed. In this way, the situation where the corresponding transaction is terminated due to the inability to execute the second request is avoided, and the overall transaction termination rate in the distributed transaction processing process is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 It is a flow chart of the distributed transaction processing method provided by the present invention implemented by a transaction executor;
[0031] Figure 2 It is a flow chart of the distributed transaction processing method provided by the present invention implemented by the transaction coordinator;
[0032] Figure 3 It is a flow chart of the distributed transaction processing method provided by the present invention implemented by the local clock module;
[0033] Figure 4 This is an example diagram of the process of network card clock synchronization provided by the present invention;
[0034] Figure 5 is an example diagram of a process for obtaining a first mapping function provided by the present invention;
[0035] Figure 6 is a structural example diagram of the distributed transaction system provided by the present invention;
[0036] Figure 7It is a flow chart of the distributed transaction processing method provided by the present invention implementing read-modify-write operations;
[0037] Figure 8 It is a structural schematic diagram of a transaction executor device for distributed transaction processing provided by the present invention;
[0038] Fig. 9 It is a structural diagram of a transaction coordinator device for distributed transaction processing provided by the present invention;
[0039] Fig.10 It is a structural diagram of a local clock module for distributed transaction processing provided by the present invention;
[0040] Fig.11 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] The inventor has analyzed the prior art and found that the process of distributed transaction processing is implemented in a distributed transaction system. The distributed transaction system includes at least one server, and each server is connected through a high-speed data center network (referred to as high-speed network), specifically, through a high-speed remote direct data access (RDMA) network. Each server includes a transaction coordinator, a transaction executor, a backup participant, a clock module and a memory. Different data items are stored in the memory of each server. The transaction coordinator, the transaction executor, the backup participant and the clock module are program modules inside the server, respectively, for implementing corresponding functions in the distributed transaction processing process.
[0043] The upper-layer application can interact with the distributed system for data. The upper-layer application generates a transaction as needed and transmits the transaction to a server. The transaction coordinator in the server distributes at least one request contained in the transaction to the transaction executors of each server in the distributed transaction system. The transaction executors of each server access the data items in the memory of the server according to the received request to complete the entire transaction.
[0044] For a server transaction executor, the received requests may be different requests contained in the same transaction or different requests contained in different transactions. Each request contains a timestamp indicating the execution time of the request. The transaction executor executes each request one by one in the time sequence indicated by the request timestamp.
[0045] The inventors analyzed the above-mentioned timestamp-based distributed transaction processing method and found that there are three main reasons affecting the transaction abort rate: first, the clocks of each server in the distributed transaction system are not accurate enough, there is a lack of synchronization between the clocks, and there are a lot of inconsistencies between the timestamps obtained by the transaction and the physical time; second, there is a delay difference between accessing local data and accessing data through the network, which leads to inconsistency between the order in which requests are served and the order of timestamps contained in the requests; third, dependent requests must go through dependent waiting, that is, they can only be sent and executed after the preceding request is executed, and the waiting causes the request execution to be out of order.
[0046] Based on the above analysis, the following Figure 1-Figure 7 The distributed transaction processing method of the present invention is described.
[0047] First, the distributed transaction processing method of the present invention is introduced with the transaction executor as the execution subject.
[0048] In one embodiment, if Figure 1 As shown, the process steps of the distributed transaction processing method implemented by the transaction executor are as follows:
[0049] Step 101: Receive a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator.
[0050] In this embodiment, the first request belongs to the target transaction, and the target transaction is transmitted to the transaction coordinator by the upper layer application. The transaction executor that receives the first request and the transaction coordinator that transmits the first request can be located on the same server or on different servers. In fact, the target transaction contains multiple requests. When the transaction coordinator distributes multiple requests of the target transaction to different transaction executors, it can be distributed to the transaction executors in the server where the transaction coordinator is located, or to the transaction executors in the server where the transaction coordinator is not located.
[0051] In this embodiment, the first request includes a first timestamp, which is obtained through a local clock module corresponding to the transaction coordinator. The first timestamp is used to indicate the execution time of the first request.
[0052] Step 102: Postponing the execution time of the first request through a preset postponement mechanism.
[0053] In this embodiment, the transaction executor does not postpone all received requests using the postponement mechanism, but rather screens the received requests according to some conditions and postpones the requests that meet the conditions.
[0054] In one embodiment, in a distributed transaction processing method based on timestamps, a read request will not fail, but a write request will fail due to a conflict with an already occurred read request with a smaller timestamp. Therefore, the execution time of the first request is postponed through a preset postponement mechanism, and the specific implementation process is as follows: determining that the first request is a read request for the target data item; and postponing the execution time of the first request.
[0055] In this embodiment, the read request is postponed to avoid the failure of the write request with a larger timestamp, thereby reducing the transaction abort rate.
[0056] In one embodiment, postponing the execution of all read requests in a transaction will dramatically increase the execution delay of the transaction. After determining that the first request is a read request for the target data item, the execution time of the first request is postponed. The specific implementation process is: obtaining the request access volume of the target data item within a preset time period; when determining that the request access volume is greater than a preset access threshold, the execution time of the first request is postponed.
[0057] In this embodiment, the preset access threshold is set to a specific value according to actual conditions and needs. When the number of requested accesses to the target data item within a preset time period is greater than the preset access threshold, for example, when the number of accesses to the target data item within 1 hour from the current moment is greater than the preset access threshold, it indicates that within the preset time period, the target data item is hot data. Since there are more requests on hot data, it is more likely to cause disordered requests, so the first request that occurs on the hot data is postponed. For read requests on non-hot data, that is, when the number of requested accesses to the target data item within the preset time period is less than or equal to the preset access threshold, since the cycle of request arrival on non-hot data is long, the benefit of postponing the read request is low. If it is postponed, not only will many late write requests not be successfully executed, but the execution delay of the read request will also be increased. Therefore, the read request on the non-hot data is not postponed, and is directly executed according to the timestamp contained in the read request.
[0058] In a specific embodiment, a dynamic hotspot monitoring mechanism is used to detect hotspot data in a distributed transaction system. The mechanism counts the number of requests for each data item within 10 milliseconds from the current time (also known as the request access volume), and determines whether the data is frequently accessed based on the request throughput on each data item. If a data item becomes hotspot data, the read request to access the data item is postponed; if it is found through monitoring that the memory access frequency of the data item decreases and it has become "cold data", that is, the frequency of accessing the data item decreases, the postponement mechanism is stopped for the data item.
[0059] In one embodiment, when the postponement mechanism is applied to postpone the first request, the postponement time of the request is heuristically determined. Specifically, the execution time of the first request is postponed, and the implementation process is as follows: postpone the execution time of the first request by a first preset time length; when the first preset time length is postponed, obtain the request failure rate of the target data item; determine whether the request failure rate is less than the preset failure threshold, and if so, execute the first request; if not, postpone the execution time of the first request again by a second preset time length, and obtain the request failure rate of the target data item with the second preset time length as a period, until the request failure rate is less than the failure threshold. Among them, the request failure rate refers to the ratio of the number of failed requests for the target data item to the total number of requests for the target data item in history.
[0060] In this embodiment, the first preset time length is less than the second preset time length. When the execution time of the first request is postponed for the first preset time length, if the second request or other write requests for the target data item are executed, the failure rate of the target data item will be reduced. If the failure rate is reduced to less than the preset failure threshold, the execution time of the first request will no longer be postponed; if the failure rate is still less than the failure threshold, the execution time of the first request will be postponed for the second preset time length, and the failure rate will be periodically observed to see if it is less than the failure threshold, until the failure rate is still less than the failure threshold.
[0061] In this embodiment, the transaction executor will first use a smaller postponement time (i.e., the first preset duration), and decide whether to increase the postponement time (i.e., the second preset duration) of the read request (i.e., the first request) according to the failure rate of the request on the data item, so as to tolerate more late write requests (e.g., the second request is a write request for the target data item) to be executed first. The postponement time of the request is determined heuristically, and when the failure rate drops below the failure threshold, the execution of the first request is stopped from being postponed, which can effectively reduce unnecessary postponements, and optimize the transaction execution delay under the premise of reducing the request failure rate and the transaction abort rate.
[0062] In one embodiment, when processing requests, the transaction executor may also postpone the local request that arrives first, and give priority to executing requests initiated from the remote end. Specifically, when the first request is a request generated by the server where the transaction executor is located, the request generated by the server where the transaction executor is located is postponed, and the request generated by the server other than the transaction executor is located is executed first, thereby avoiding the disorder of the arrival of requests due to network delay differences during the transmission process.
[0063] Step 103: When the first request is not executed, a second request is received, wherein the second request includes a second timestamp, and the second timestamp is smaller than the first timestamp.
[0064] In this embodiment, when a second request including a smaller second timestamp is received during the deferral of the first request, the second request may be executed preferentially.
[0065] Step 104: Execute the second request at the execution time indicated by the second timestamp.
[0066] In this embodiment, the second request is executed according to the execution time indicated by the second timestamp. When the second request is a write request for the target data item, the failure of the second request can be avoided, and the transaction corresponding to the second request can be avoided, thereby reducing the transaction abort rate of distributed transaction processing. When the second request is a read request, the confusion of the timestamp can be avoided, the request abort can be avoided, and the transaction abort rate can be further reduced.
[0067] Step 105, when the postponement mechanism ends, the first request is executed.
[0068] In this embodiment, given the condition for postponing the end of the first request, that is, when the postponement mechanism ends, the first request is executed to avoid the situation where the first request cannot be executed normally.
[0069] In one embodiment, the execution of the first request is based on the local processor clock. Specifically, the execution of the first request is implemented as follows: based on the local processor clock, it is determined that when the local processor timing reaches the execution time indicated by the first timestamp, the first request is executed; wherein the local processor clock is synchronized with the local network card clock, and the local network card clock is synchronized with the preset root network card clock.
[0070] In this embodiment, the execution process of the first request with the first timestamp is based on the local processor clock. The local processor clock is synchronized with the local network card clock, and the local network card clock is synchronized with the preset root network card clock, which ensures that the local processor clock is synchronized with the root network card clock. When the local processor clock of each server in the distributed transaction system is synchronized with the root network card clock, the clock consistency of the entire distributed transaction system is guaranteed, avoiding transaction aborts caused by asynchrony between clocks, and further reducing the transaction abort rate.
[0071] In this embodiment, the process of synchronizing the local processor clock with the local network card clock, and the process of synchronizing the local network card clock with the preset root network card clock can be implemented by the clock modules in each server.
[0072] In one embodiment, before executing a first request, it is determined that the first request contains dependency information, wherein the dependency information is used to indicate that the execution process of a third request depends on the execution result of the first request, and the third request includes a first timestamp; after executing the first request, when the third request is not received, a fourth request is received, wherein the fourth request contains a fourth timestamp, wherein the fourth timestamp is greater than the first timestamp; the execution of the fourth request is blocked until the third request is received and executed, and then the fourth request is executed so that the third request is executed before the fourth request.
[0073] In this embodiment, the transaction executor receives the fourth request, because the fourth timestamp included in the fourth request is greater than the first timestamp included in the third request. When the third request is not received, if the fourth request is received, the fourth request will be executed first. However, since the third request is a dependent request and the fourth timestamp is greater than the first timestamp, if the fourth request is executed first, the third request cannot be executed. Therefore, when the fourth request is received, the execution of the fourth request is blocked, so that the third request is executed before the fourth request, so that the third request and the fourth request can be executed normally, thereby reducing the transaction abort rate.
[0074] In this embodiment, a transaction includes multiple requests. Among the various requests of the transaction, the non-dependent request does not depend on other requests in the transaction, that is, the request can be directly transmitted to the transaction executor for execution; the dependent request depends on other requests in the transaction, that is, the execution process of the request depends on the execution result of another request (also known as the predecessor request). For non-dependent requests, the transaction coordinator sends each non-dependent request directly to the corresponding transaction executor, and the transaction executor directly executes the non-dependent request; for dependent requests, the transaction coordinator sends the existence information of the dependent request (that is, the dependency information) and the predecessor request to the transaction executor in advance, so that the transaction executor can perceive the existence of the dependent request in advance and "take up a place in advance", reduce the request execution failure rate, and thus reduce the transaction abort rate. Among them, the transaction abort rate refers to the ratio of transactions that have not been successfully executed in the history of the distributed transaction system divided by all transactions processed by the system.
[0075] In this embodiment, the first request and the third request in the target transaction have a dependency relationship, that is, the third request is a dependent request, and the first request is a pre-request of the third request. After receiving the first request, the transaction executor determines the existence of the third request based on the dependency information contained in the first request.
[0076] In one embodiment, the dependency information is a Boolean variable pre-set in the first request. When there is a third request that depends on the first request, when the transaction coordinator sends the first request, the Boolean variable in the first request is set to "1" to indicate the existence of the third request. When the transaction coordinator sends a non-dependency request, the Boolean variable in the non-dependency request is set to "0" to indicate that the non-dependency request has no dependency relationship. The transaction executor can determine whether the received request has a dependency relationship through the specific value set by the Boolean variable.
[0077] In this embodiment, the Boolean variable occupies a very small amount of data, and while being able to accurately represent the dependency relationship, has little impact on the data transmission burden.
[0078] In one embodiment, the execution of the first request is to complete the entire target transaction, so after determining that the first request contains dependency information of the third request, it can be pre-determined whether the transaction executor has an environmental basis for the execution of the third request. Specifically, when determining that the first request contains dependency information, it also includes: determining whether there is an environmental basis for the execution of the third request, if not, generating request failure information for the first request, and transmitting the request failure information to the transaction coordinator; if so, generating pre-placement information for the third request, and when the first request is executed, generating first commit information, and transmitting the first commit information to the transaction coordinator; blocking the execution of the fourth request, including: blocking the execution of the fourth request according to the pre-placement information.
[0079] In this embodiment, the transaction executor pre-determines whether there is an environmental basis for the execution of the third request. When it does not exist, the transaction executor directly generates request failure information and transmits the request failure information to the transaction coordinator. Since when any request included in the target transaction fails, the overall execution of the target transaction fails. Therefore, after the transaction coordinator receives the request failure information, it directly generates transaction failure information of the target transaction and informs the upper-layer application of the transaction failure information. The above process pre-determines the environmental basis for the execution of the third request before the third request is transmitted. When the environmental basis for the execution of the third request does not exist, the transaction coordinator will directly submit the transaction failure information, saving the processing resources occupied by transmitting the third request and further improving the transaction processing efficiency of the entire distributed transaction system.
[0080] In one embodiment, the first request is a read request for a target data item, the third request is a write request for the target data item, and the target data item is accessed by a transaction executor.
[0081] In timestamp-based distributed transaction processing, read requests will not fail, but write requests will fail due to conflicts with read requests that have already occurred. Specifically, if other read requests are executed after the first request is executed and before the third request is executed, the third request will fail. The main reason for the conflict is that the order of request execution is inconsistent with the order of timestamps marked by the requests. The main reasons for the inconsistency include the difference between local access delay and remote network access delay, and the asymmetry of network links.
[0082] Based on the above, the execution of the fourth request is blocked, and the specific implementation process is as follows: determine that the fourth request is a read request for the target data item; and block the execution of the fourth request.
[0083] After receiving the fourth request and determining that the fourth request is a read request for the target data item, the transaction executor will block the execution of the fourth request and give priority to the write request (i.e., the third request) that arrives during the postponement period and modifies the same target data item. In this way, the fourth request is scheduled to be executed after the third request, avoiding the occurrence of conflicts. At the same time, after receiving the fourth request, the transaction executor caches it for a period of time, that is, postpones the execution time of the fourth request. If other requests that may have a smaller timestamp arrive during the cache period of the fourth request, the request with the smaller timestamp can be executed first, effectively avoiding conflicts generated when the requests are executed.
[0084] Next, the distributed transaction processing method of the present invention is introduced with the transaction coordinator as the execution subject.
[0085] In one embodiment, if Figure 2 As shown, the distributed transaction processing method is implemented by the transaction coordinator in the following process steps:
[0086] Step 201, upon receiving a target transaction transmitted by an upper layer application, a clock request is generated for execution and transmitted to a local clock module;
[0087] Step 202, obtaining a first timestamp returned by a local clock module;
[0088] Step 203: Generate a first request based on the first timestamp, and transmit the first request to the transaction executor.
[0089] In this embodiment, the upper-layer application transmits the target transaction to a server in the distributed transaction system, and the transaction coordinator on the server receives the target transaction. The transaction coordinator generates various requests corresponding to the target transaction according to the specific content of the target transaction, and the various requests include a first request, and each request needs to be configured with a timestamp. Taking the first request as an example, the transaction coordinator requests the first timestamp from the local clock module. Specifically, the transaction coordinator requests the first timestamp from the local processor clock in the local clock module, and generates the first request according to the first timestamp and dependency information. Finally, the first request is transmitted to the transaction executor of the corresponding server so that the transaction executor executes the first request. Accordingly, the transaction coordinator needs to distribute the various requests contained in the target transaction to the corresponding transaction executors.
[0090] In one embodiment, after the transaction coordinator obtains the target transaction, it determines the dependency relationship between the requests according to the target transaction. Specifically, based on the first timestamp, before generating the first request, the dependency information is determined, wherein the dependency information is used to indicate that the execution process of the third request depends on the execution result of the first request; based on the first timestamp, the first request is generated, and the specific process is: based on the first timestamp and the dependency information, the first request is generated.
[0091] In one embodiment, the dependency information is a Boolean variable pre-set in the first request. When there is a third request that depends on the first request, the transaction coordinator sets the Boolean variable in the first request to "1" when sending the first request, indicating the existence of the third request. When the first request is a non-dependent request, the transaction coordinator sets the Boolean variable in the first request to "0", indicating that the first request has no dependency relationship.
[0092] In one embodiment, after transmitting the first request to the transaction executor, request failure information transmitted by the transaction executor is obtained; transaction failure information of the target transaction is generated, and the transaction failure information is transmitted to the upper-layer application, wherein the request failure information indicates that the transaction executor does not have an environmental basis for executing the third request; or, first commit information transmitted by the transaction executor is obtained, a third request is generated, and the third request is transmitted to the transaction executor.
[0093] In this embodiment, after the transaction coordinator transmits the first request to the transaction executor, the transaction executor sends a reply of the execution result of the first request to the transaction coordinator. If the transaction coordinator receives a failure to execute any request in the target transaction, including the failure of the first request and the failure of other requests in the target transaction, the transaction will be terminated; otherwise, after receiving the success information of all requests in the target transaction, the transaction coordinator believes that all requests of the target transaction have been successfully completed, and will notify all transaction executors to submit the transaction changes, send the transaction changes to the backup participants in each server for backup, and finally submit the transaction to the upper-layer application.
[0094] In this embodiment, when the third request is generated, the first timestamp obtained from the local processor clock in the clock module is also configured for the third request.
[0095] In one embodiment, the first request is a read request for the target data item, and the third request is a write request for the target data item. Specifically, the first commit information transmitted by the transaction executor is obtained, the third request is generated, and the third request is transmitted to the transaction executor. The implementation process is as follows: the first commit information transmitted by the transaction executor is obtained; according to the first commit information, the latest data to be written into the target data item is calculated; based on the latest data, the third request is generated, and the third request is transmitted to the transaction executor.
[0096] In this embodiment, after the transaction executor executes the first request (read request), it transmits the first commit information to the transaction coordinator, and the first commit information includes the data contained in the read target data item. The transaction coordinator calculates the latest data that needs to be written into the target data item based on the first commit information. Then, the write request (i.e., the third request) containing the latest data is transmitted to the transaction executor. After receiving the third request, the transaction executor does not need to perform further calculations and can directly write the latest data. In this way, the pressure on the transaction executor's processing resources can be reduced.
[0097] In one embodiment, the third request has modified the data in the target data item, and the fourth request actually needs to read the data before the modification by the third request. Therefore, the data items in the server memory include multiple historical versions of data items. Each historical version of the data item includes the generation timestamp of the version data item, the latest access timestamp, and the version status. When the transaction executor executes the fourth request, the corresponding historical version of the data item is read through the fourth timestamp included in the fourth request to ensure the correctness of the read data.
[0098] Next, the distributed transaction processing method of the present invention is introduced by taking the local clock module as the execution body.
[0099] In one embodiment, if Figure 3 As shown, the distributed transaction processing method is implemented by the local clock module in the following process steps:
[0100] Step 301, upon receiving a clock request instruction transmitted by a transaction coordinator, obtaining a first timestamp generated by a local processor clock, wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock;
[0101] Step 302: Return the first timestamp to the transaction coordinator.
[0102] In this embodiment, a local clock module of a server includes a local processor clock and a local network card clock. When the clock module receives a clock request instruction transmitted by the transaction coordinator, it obtains a first timestamp generated by the local processor clock and returns the first timestamp to the transaction coordinator.
[0103] In this embodiment, the clock module also needs to maintain synchronization between the local processor clock and the local network card clock, and between the local network card clock and the preset root network card clock.
[0104] In one embodiment, in order to synchronize the local processor clock with the local network card clock and the local network card clock with the preset root network card clock, before the local clock module receives the clock request instruction transmitted by the transaction coordinator, it obtains a first mapping relationship between the preset root network card clock and the local network card clock; according to the first mapping relationship, the local network card clock is adjusted to synchronize the local network card clock with the preset root network card clock; a second mapping relationship between the local network card clock and the local processor clock is obtained; according to the second mapping relationship, the local processor clock is adjusted to synchronize the local processor clock with the local network card clock.
[0105] In this embodiment, by maintaining the synchronization between the local processor clock and the local network card clock, and the synchronization between the local network card clock and the preset root network card clock, the synchronization between the local processor clock and the root network card clock is ensured. In a distributed transaction system, the local processor clock of each server is synchronized with the root network card clock, thereby achieving clock synchronization of the entire distributed transaction system.
[0106] In one embodiment, the first mapping relationship is obtained according to the timestamp. Specifically, the first mapping relationship between the preset root network card clock and the local network card clock is obtained, and the implementation process is as follows: in at least one continuous time slice, at least one of the following processes is performed respectively: in an unreliable service mode oriented to datagrams, the local network card sends a first data packet to the preset root network card, and obtains a first local network card timestamp corresponding to the local network card clock when the first data packet leaves the local network card; in a reliable service mode oriented to connection, the local network card sends a second data packet to the preset root network card, and obtains a second local network card timestamp corresponding to the local network card clock when the second data packet leaves the local network card. The timestamp of the first local network card is obtained; the first root network card timestamp and the second network card timestamp transmitted by the preset root network card are obtained, wherein the first root network card timestamp is the timestamp corresponding to the preset root network card clock when the first data packet reaches the preset root network card, and the second network card timestamp is the timestamp corresponding to the preset root network card clock when the second data packet reaches the preset root network card; according to the first local network card timestamp, the first network card timestamp, the second local network card timestamp and the second network card timestamp, obtain a first timestamp probe pair of the preset root network card clock and the local network card clock; according to at least one first timestamp probe pair in at least one time slice, obtain a first mapping relationship.
[0107] In this embodiment, the synchronization between the clocks of the network interface controller (also known as the network card, network interface controller, NIC) in the distributed transaction system, all NIC clocks and the root NIC clock establish a tree structure, and each NIC clock is indirectly synchronized with the root NIC clock through the NIC two-to-two synchronization. For the synchronization between the two NIC clocks, firstly, a batch of probe pairs are obtained. The acquisition of the probe pairs uses the interface ibv_cq_ex provided by the remote direct data access (RDMA) technology, as well as the datagram-oriented unreliable service (UD) mode and the connection-oriented reliable service (RC) mode. In this embodiment, RNIC B represents a preset root network card in a pre-established tree structure, and RNIC A represents a sub-network card associated with the preset root network card in a pre-established tree structure.
[0108] like Figure 4 As shown, the clock of the network card RNIC A is synchronized with the clock of the network card RNIC B. RNIC A uses the UD mode sending command to send (SEND) a data packet to RNIC B. The ibv_cq_ex structure will cache the timestamp of the data packet residing at both ends of the link. RNIC A will then use the RC mode sending command to send a data packet to RNIC B. Since the RC mode is a reliable transmission, the ibv_cq_ex structure will cache the timestamp of the confirmation message of the data packet residing at both ends of the link, thereby forming a round-trip probe message that only requires RNIC A to intervene. Finally, RNIC B only needs to asynchronously obtain the collected timestamps and transmit them in batches to RNIC A. Specifically, it can be achieved through the Acknowledge character (ACK), and RNIC A can obtain all probe pairs in the time slice to fit and generate a linear function. Through the method, the probe sending task can be flexibly assigned to any one of the two synchronization nodes without the intervention of both ends, reducing the central processing unit (CPU) occupancy introduced by the probe sending task.
[0109] In the above implementation process, when the subnet card RNIC A is not directly associated with the preset root network card, RNIC B may be an upper-level subnet card associated with RNIC A in a pre-established tree structure. In this case, the clock synchronization process is similar to the above process.
[0110] In one embodiment, a first mapping relationship is obtained based on at least one first timestamp probe pair in at least one time slice, and the specific implementation process is as follows: based on the first timestamp probe pair in at least one time slice, a linear relationship between a preset root network card clock and a local network card clock is fitted; the i-th midpoint function value of the linear relationship in the i-th time slice is obtained, and the i+1-th midpoint function value of the linear relationship in the i+1-th time slice is obtained, where i is an integer greater than or equal to 0; the intersection of the straight line formed by connecting the i-th midpoint function value and the i+1-th midpoint function value and the right endpoint of the i+3-th time slice is used as the i-th prediction point; at least two prediction points are connected in sequence to obtain the first mapping relationship.
[0111] Specifically, Figure 5 As shown in the figure, when the local NIC clock is RNIC A and the preset root NIC is RNIC B, clock A (clock A ) represents the clock of RNIC A, and clock B (clock B ) represents the clock of RNIC B, clock A 0 to 1 (including 1) on the axis represents a time slice, 1 to 2 (including 2) represents a time slice, and so on. The probe messages between the two clocks are counted in time slices, and a linear function is fitted to represent the linear relationship from clock A to clock B in this time slice; for this linear relationship, the function value of the midpoint Mi in the i-th time slice is calculated; the values of the midpoints Mi and Mi+1 of the adjacent time slices are connected to form a new linear function, which intersects at the right endpoint of the i+3th time slice to obtain the predicted point Ai; the adjacent predicted points Ai and Ai+1 are connected to obtain a continuous predicted linear function, which is used as the first mapping function from clock A to clock B in all time slices.
[0112] For example, the function value of the midpoint of the 0th time slice is M0, the function value of the midpoint of the 1st time slice is M1, the function value of the midpoint of the 2nd time slice is M2, and the function value of the midpoint of the 3rd time slice is M3. Connect the values of the midpoints M0 and M1 of the adjacent time slices to form a new linear function, which intersects at the right endpoint of the 3rd time slice to obtain the predicted point A0; connect the values of the midpoints M1 and M2 of the adjacent time slices to form a new linear function, which intersects at the right endpoint of the 4th time slice to obtain the predicted point A1; connect the values of the midpoints M2 and M3 of the adjacent time slices to form a new linear function, which intersects at the right endpoint of the 5th time slice to obtain the predicted point A2. The continuous predicted linear function formed by connecting A0, A1 and A2 is the first mapping function from clock A to clock B.
[0113] In the above implementation process, when subnet card RNIC A is not directly associated with the preset root network card, RNIC B may be an upper-level subnet card associated with RNIC A in a pre-established tree structure. In this case, the process of obtaining the first mapping function is similar to the above process.
[0114] In one embodiment, the second mapping relationship is obtained according to the timestamp. Specifically, the second mapping relationship between the local network card clock and the local processor clock is obtained, and the implementation process is as follows: in at least one continuous time slice, at least one of the following processing is performed respectively: obtain the first processor timestamp of the local processor clock; obtain the first network card timestamp generated by the local network card clock; obtain the second processor timestamp generated by the local processor time; based on the first processor timestamp, the second processor timestamp and the preset fitting coefficient, determine the central processor timestamp corresponding to the first network card timestamp; according to the central processor timestamp and the first network card timestamp, obtain the second timestamp probe pair of the local network card clock and the local processor clock; according to at least one second timestamp probe pair in at least one time slice, obtain the second mapping relationship.
[0115] In this embodiment, the local processor clock (also called CPU clock) and the local network card clock (also called NIC clock) in a single server are synchronized by obtaining probe pairs in batches to obtain the time of the CPU clock and the NIC clock at the same moment. First, obtain the timestamp C1 of the CPU clock, then obtain the timestamp N1 of the NIC clock, and finally obtain the timestamp C2 of the CPU clock. In order to determine the time of the CPU clock at the time point of obtaining N1, use the formula C01=a*C1+(1-a)*C2, where a represents the preset fitting coefficient, and a is determined in advance by offline fitting. After obtaining all probe pairs in a single time slice,<C0n,Nn> After that, where n is an integer greater than or equal to 1, the local clock module will filter the probe pairs with too long execution time, and use the linear regression method to fit the second linear relationship between the CPU clock and the NIC clock in the time slice.
[0116] In this embodiment, a second mapping relationship between the CPU clock and the NIC clock is obtained through a second linear relationship between the CPU clock and the NIC clock in at least one time slice.
[0117] Specifically, according to the second timestamp probe pair in at least one time slice, fit the second linear relationship between the local network card clock and the local processor clock; obtain the i-th midpoint function value of the second linear relationship in the i-th time slice, and obtain the i+1-th midpoint function value of the second linear relationship in the i+1-th time slice, where i is an integer greater than or equal to 0; take the intersection of the straight line formed by connecting the i-th midpoint function value and the i+1-th midpoint function value and the right endpoint of the i+3-th time slice as the i-th prediction point; connect at least one prediction point in sequence to obtain a second mapping relationship.
[0118] Next, the implementation process of the corresponding functions of the backup participants is introduced.
[0119] In one embodiment, the distributed transaction system uses a master-slave replica mechanism to tolerate the situation where the node server crashes during the distributed transaction processing, causing the transaction coordinator or transaction executor to crash. When the transaction coordinator decides to commit the transaction, it will first send the transaction update to the backup participants of each server for backup. After the transaction coordinator confirms that all backup participants have received the transaction update, it will notify the transaction executor to commit the transaction update and notify the upper-layer application that the transaction has been committed.
[0120] In one embodiment, when the transaction coordinator crashes, the backup participants can recover the transactions that have been submitted to the upper layer. After the server detects the crash of the transaction coordinator, it terminates the transaction being run by the transaction coordinator. Each server in the distributed transaction system first checks all transactions in the system. If a transaction has been backed up to all backup participants, it means that the transaction can be submitted to the upper layer. The distributed transaction system will resubmit the transaction to the upper layer and notify all transaction executors to submit all updates of the transaction; if a transaction has not been backed up to all backup participants, it means that the transaction has not yet been submitted to the upper layer and the completion progress of the transaction cannot be determined, so the distributed transaction system terminates the transaction and notifies all transaction executors to terminate all updates of the transaction.
[0121] In one embodiment, when a transaction executor crashes, after the server detects the crash, the distributed transaction system selects a backup participant from the backup participants corresponding to the transaction executor as a new transaction executor to replace the crashed transaction executor and continue to provide data access services. Since the transaction update (i.e., the update of the data item) is backed up to the backup participant before being submitted to the upper-layer application for execution, the new transaction executor saves the required data items.
[0122] In a specific embodiment, Figure 6As shown, the distributed transaction system includes at least one server. Each server includes a corresponding transaction coordinator, a transaction executor, a local clock module (referred to as clock), a backup participant and a memory. The servers are connected via a high-speed network. The local clock module includes a local processor clock and a local network card clock. In the distributed transaction system, the local network card clock of a server is selected as the preset root network card clock, and a tree structure of the network card clock is pre-established.
[0123] In this embodiment, the target transaction is transmitted to Figure 6 The transaction coordinator in the leftmost server distributes each request in the target transaction to the transaction executors of each server to implement the processing of the target transaction.
[0124] In an example, Figure 7 As shown, the distributed transaction processing method provided by the present invention is introduced by taking the read-modify-write operation as an example. The read-modify-write operation "X+=5" includes two operations, reading the value of X (read X) and writing a new value of X (write X=Xnew). Among them, X represents the target data item, "X+=5" means that the increment of X is 5, and Xnew represents the latest data that needs to be written to the target data item.
[0125] When sending read X, the transaction coordinator will set the Boolean variable representing the existence of the second write request of write X=Xnew to 1 in the first request (read request). After receiving the read X request, the transaction executor will first determine whether the subsequent write X=Xnew request can be successfully executed. If not, it can directly reply to the transaction coordinator that the request failed without executing the read X request, that is, return the request failure information, and the target transaction is terminated. If the third request (write request) of write X=Xnew can be executed, the transaction executor will first reserve a position for Xnew in the historical version of the X data item, that is, generate pre-occupied place information, realize "pre-occupied place" to avoid other requests intervening between the two read and write requests of X and causing the target transaction to be terminated. Afterwards, the transaction executor will execute the first request and return the read result to the transaction coordinator.
[0126] The transaction coordinator receives the return result of the first request and calculates the value of Xnew. The calculation indicates that the value of Xnew can be calculated and that the insertion of Xnew can be successful, and the write X=Xnew request will not fail. Therefore, when the transaction coordinator decides to send the third request, it sends the calculated value of Xnew together with the information submitted by the target transaction to the corresponding transaction executor. The transaction executor changes the version status corresponding to Xnew from the "pending submission" status to the "submitted" status, indicating that the data version can be read by other transactions and the modification of the data X by the transaction has been completely completed.
[0127] When all requests of the target transaction are submitted to the transaction coordinator for completion information, the transaction coordinator backs up all the submission information to the backup participants of each server, and then submits the completion information of the target transaction to the upper-level application.
[0128] The distributed transaction processing method provided by the present invention comprises: a transaction executor receives a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator; the execution time of the first request is postponed through a preset postponement mechanism; when the first request is not executed, a second request is received, wherein the second request includes a second timestamp, and the second timestamp is smaller than the first timestamp; the second request is executed at the execution time indicated by the second timestamp; and the first request is executed when the postponement mechanism ends. In the prior art, when the first request reaches the transaction executor first, the transaction executor will execute the first request; however, since the second timestamp is smaller than the first timestamp, the execution of the first request will cause the second request to be unable to be executed, and the transaction corresponding to the second request will be aborted. In the present invention, after receiving the first request, the transaction executor will postpone the first request so that the second request including a smaller second timestamp is executed first, and then the first request is executed. In this way, the situation where the corresponding transaction is aborted due to the inability to execute the second request is avoided, and the overall transaction abort rate in the distributed transaction processing process is reduced.
[0129] The following is a description of the transaction executor device for distributed transaction processing provided by the present invention. The transaction executor device for distributed transaction processing described below and the distributed transaction processing method implemented by the transaction executor as the execution subject described above can be referred to in correspondence with each other. Figure 8 As shown, the transaction executor device of the distributed transaction processing includes:
[0130] A first receiving module 801 is used to receive a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator;
[0131] A postponement module 802, configured to postpone the execution time of the first request through a preset postponement mechanism;
[0132] A second receiving module 803 is configured to receive a second request when the first request is not executed, wherein the second request includes a second timestamp, and the second timestamp is smaller than the first timestamp;
[0133] A first execution module 804, configured to execute the second request at an execution time indicated by a second timestamp;
[0134] The second execution module 805 is used to execute the first request when the postponement mechanism ends.
[0135] The following is a description of the transaction coordinator device for distributed transaction processing provided by the present invention. The transaction coordinator device for distributed transaction processing described below and the distributed transaction processing method implemented by the transaction coordinator as the execution subject described above can be referred to in correspondence with each other. Fig. 9 As shown, the transaction coordinator device for distributed transaction processing includes:
[0136] The third receiving module 901 is used to generate a clock request execution when receiving a target transaction transmitted by an upper layer application, and transmit it to the local clock module;
[0137] An acquisition module 902 is used to acquire a first timestamp returned by a local clock module;
[0138] The generating module 903 is configured to generate a first request based on the first timestamp, and transmit the first request to the transaction executor.
[0139] The local clock module of the distributed transaction processing provided by the present invention is described below. The local clock module of the distributed transaction processing described below and the distributed transaction processing method described above using the local clock module as the execution subject can be referred to each other. Fig.10 As shown, the local clock module of distributed transaction processing includes:
[0140] The receiving unit 1001 is used to obtain a first timestamp generated by a local processor clock when receiving a clock request instruction transmitted by a transaction coordinator, wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock;
[0141] The returning unit 1002 is used to return the first timestamp to the transaction coordinator.
[0142] Fig.11 An example of a physical structure diagram of an electronic device is shown in FIG. Fig.11As shown, the electronic device may include: a processor 1101, a communication interface 1102, a memory 1103 and a communication bus 1104, wherein the processor 1101, the communication interface 1102 and the memory 1103 complete mutual communication through the communication bus 1104. The processor 1101 may call the logic instructions in the memory 1103 to execute a distributed transaction processing method implemented by a transaction executor as an execution subject, the method comprising: receiving a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator; postponing the execution time of the first request through a preset postponement mechanism; when the first request is not executed, receiving a second request, wherein the second request includes a second timestamp, and the second timestamp is less than the first timestamp; executing the second request at the execution time indicated by the second timestamp; and executing the first request when the postponement mechanism ends.
[0143] Alternatively, the processor 1101 can call the logic instructions in the memory 1103 to execute a distributed transaction processing method implemented by the transaction coordinator as the execution subject, the method including: when receiving the target transaction transmitted by the upper-layer application, generating a clock request execution and transmitting it to the local clock module; obtaining the first timestamp returned by the local clock module; based on the first timestamp, generating a first request, and transmitting the first request to the transaction executor.
[0144] Alternatively, the processor 1101 can call the logic instructions in the memory 1103 to execute a distributed transaction processing method implemented by the local clock module as the execution subject, the method comprising: upon receiving a clock request instruction transmitted by the transaction coordinator, obtaining a first timestamp generated by the local processor clock, wherein the local processor clock is synchronized with the local network card clock, and the local network card clock is synchronized with the preset root network card clock; and returning the first timestamp to the transaction coordinator.
[0145] In addition, the logic instructions in the above-mentioned memory 1103 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0146] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the distributed transaction processing method implemented by the transaction executor as the execution subject provided in the above embodiments. The method includes: receiving a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator; postponing the execution time of the first request through a preset postponement mechanism; when the first request is not executed, receiving a second request, wherein the second request includes a second timestamp, and the second timestamp is less than the first timestamp; executing the second request at the execution time indicated by the second timestamp; when the postponement mechanism ends, executing the first request.
[0147] Alternatively, the computer can execute the distributed transaction processing method provided in the above embodiments with the transaction coordinator as the execution subject, the method comprising: upon receiving the target transaction transmitted by the upper-layer application, generating a clock request execution and transmitting it to the local clock module; obtaining the first timestamp returned by the local clock module; based on the first timestamp, generating a first request, and transmitting the first request to the transaction executor.
[0148] Alternatively, the computer can execute the distributed transaction processing method implemented by the local clock module provided in the above embodiments as the execution subject, the method comprising: upon receiving a clock request instruction transmitted by the transaction coordinator, obtaining a first timestamp generated by the local processor clock, wherein the local processor clock is synchronized with the local network card clock, and the local network card clock is synchronized with the preset root network card clock; and returning the first timestamp to the transaction coordinator.
[0149] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it implements a distributed transaction processing method implemented by the transaction executor provided in the above embodiments as the execution subject, the method comprising: receiving a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained by a local clock module corresponding to the transaction coordinator; postponing the execution time of the first request through a preset postponement mechanism; when the first request is not executed, receiving a second request, wherein the second request includes a second timestamp, and the second timestamp is less than the first timestamp; executing the second request at the execution time indicated by the second timestamp; and executing the first request when the postponement mechanism ends.
[0150] Alternatively, when the computer program is executed by the processor, a distributed transaction processing method is implemented with the transaction coordinator provided in the above embodiments as the execution subject, and the method includes: when receiving a target transaction transmitted by an upper-layer application, generating a clock request execution and transmitting it to a local clock module; obtaining a first timestamp returned by the local clock module; based on the first timestamp, generating a first request, and transmitting the first request to the transaction executor.
[0151] Alternatively, when the computer program is executed by the processor, a distributed transaction processing method is implemented by executing the local clock module provided by the above embodiments as the execution subject, the method comprising: upon receiving a clock request instruction transmitted by the transaction coordinator, obtaining a first timestamp generated by the local processor clock, wherein the local processor clock is synchronized with the local network card clock, and the local network card clock is synchronized with the preset root network card clock; and returning the first timestamp to the transaction coordinator.
[0152] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0153] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed transaction processing method, It is characterized in that Applicable to transaction executors, including: Receive a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained through a local clock module corresponding to the transaction coordinator; Postponing the execution time of the first request through a preset postponement mechanism; When the first request is not executed, a second request is received, wherein the second request includes a second timestamp, and the second timestamp is smaller than the first timestamp; At the execution time indicated by the second timestamp, executing the second request; When the postponement mechanism ends, executing the first request; The postponing the execution time of the first request by using a preset postponement mechanism includes: Determining that the first request is a read request for a target data item; Postponing the execution time of the first request; The postponing the execution time of the first request includes: Obtaining the requested access volume of the target data item within a preset time period; When it is determined that the requested access amount is greater than a preset access threshold, the execution time of the first request is postponed.
2. The distributed transaction processing method according to claim 1, It is characterized in that The postponing the execution time of the first request includes: Postponing the execution time of the first request by a first preset time period; When the first preset time period is postponed, obtaining the request failure rate of the target data item; Determine whether the request failure rate is less than a preset failure threshold. If so, execute the first request; if not, postpone the execution time of the first request again for a second preset time period, and use the second preset time period as a period to obtain the request failure rate of the target data item until the request failure rate is less than the failure threshold.
3. The distributed transaction processing method according to claim 1, It is characterized in that Before executing the first request, the method further includes: Determining that the first request includes dependency information, wherein the dependency information is used to indicate that an execution process of a third request depends on an execution result of the first request, and the third request includes the first timestamp; After executing the first request, the method further includes: When the third request is not received, a fourth request is received, wherein the fourth request includes a fourth timestamp, wherein the fourth timestamp is greater than the first timestamp; The execution of the fourth request is blocked until the third request is received and executed, and then the fourth request is executed, so that the third request is executed before the fourth request.
4. The distributed transaction processing method according to claim 3, It is characterized in that The determining that the first request includes dependency information further includes: Determine whether there is an environment basis for executing the third request, and if not, generate request failure information of the first request, and transmit the request failure information to the transaction coordinator; if so, generate pre-placement information of the third request, and when the first request is executed, generate first commit information, and transmit the first commit information to the transaction coordinator; The blocking the execution of the fourth request includes: According to the pre-occupied information, execution of the fourth request is blocked.
5. The distributed transaction processing method according to claim 3, It is characterized in that The first request is a read request for a target data item, and the third request is a write request for the target data item; The blocking the execution of the fourth request includes: Determining that the fourth request is a read request for the target data item; Blocking execution of the fourth request.
6. The distributed transaction processing method according to claim 1, It is characterized in that The executing the first request includes: determining, based on a local processor clock, that when the local processor timing reaches the execution time indicated by the first timestamp, executing the first request; The local processor clock is synchronized with the local network card clock, and the local network card clock is synchronized with the preset root network card clock.
7. A distributed transaction processing method, It is characterized in that The transaction coordinator as used in any one of claims 1 to 6 comprises: When receiving the target transaction transmitted by the upper-layer application, it generates a clock request execution and transmits it to the local clock module; Obtaining a first timestamp returned by the local clock module; Based on the first timestamp, the first request is generated and transmitted to a transaction executor.
8. The distributed transaction processing method according to claim 7, It is characterized in that Before generating the first request based on the first timestamp, the method further includes: Determining dependency information, wherein the dependency information is used to indicate that the execution process of the third request depends on the execution result of the first request; The generating the first request based on the first timestamp includes: Based on the first timestamp and the dependency information, the first request is generated.
9. The distributed transaction processing method according to claim 8, It is characterized in that After transmitting the first request to the transaction executor, the method further includes: Acquire request failure information transmitted by the transaction executor; generate transaction failure information of the target transaction, and transmit the transaction failure information to the upper layer application, wherein the request failure information indicates that the transaction executor does not have an environment basis for executing the third request; or, The first commit information transmitted by the transaction executor is obtained, the third request is generated, and the third request is transmitted to the transaction executor.
10. The distributed transaction processing method according to claim 8, It is characterized in that The first request is a read request for a target data item, and the third request is a write request for the target data item; The obtaining the first commit information transmitted by the transaction executor, generating the third request, and transmitting the third request to the transaction executor includes: Obtaining first submission information transmitted by the transaction executor; Calculate the latest data that needs to be written into the target data item according to the first submission information; Based on the latest data, the third request is generated and transmitted to the transaction executor.
11. A distributed transaction processing method, It is characterized in that The local clock module used in any one of claims 1 to 6 comprises: Upon receiving a clock request instruction transmitted by the transaction coordinator, obtaining a first timestamp generated by a local processor clock, wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock; The first timestamp is returned to the transaction coordinator.
12. The distributed transaction processing method according to claim 11, It is characterized in that Before receiving the clock request instruction transmitted by the transaction coordinator, the method further includes: Obtaining a first mapping relationship between the preset root network card clock and the local network card clock; According to the first mapping relationship, adjust the local network card clock so that the local network card clock is synchronized with the preset root network card clock; Acquire a second mapping relationship between the local network card clock and the local processor clock; According to the second mapping relationship, the local processor clock is adjusted to synchronize the local processor clock with the local network card clock.
13. The distributed transaction processing method according to claim 12, It is characterized in that The obtaining of a first mapping relationship between a preset root network card clock and a local network card clock includes: In at least one continuous time slice, perform the following processing at least once respectively: in an unreliable service mode oriented to datagrams, the local network card sends a first data packet to the preset root network card, and obtains a first local network card timestamp corresponding to the local network card clock when the first data packet leaves the local network card; in a reliable service mode oriented to connection, the local network card sends a second data packet to the preset root network card, and obtains a second local network card timestamp corresponding to the local network card clock when the second data packet leaves the local network card; obtains a first root network card timestamp and a second network card timestamp transmitted by the preset root network card, wherein the first root network card timestamp is a timestamp corresponding to the preset root network card clock when the first data packet reaches the preset root network card, and the second root network card timestamp is a timestamp corresponding to the preset root network card clock when the second data packet reaches the preset root network card; according to the first local network card timestamp, the first root network card timestamp, the second local network card timestamp and the second root network card timestamp, obtain a first timestamp probe pair of the preset root network card clock and the local network card clock; The first mapping relationship is acquired according to at least one first timestamp probe pair in at least one of the time slices.
14. The distributed transaction processing method according to claim 13, It is characterized in that The acquiring the first mapping relationship according to at least one first timestamp probe pair in at least one of the time slices includes: Fitting a linear relationship between the preset root network card clock and the local network card clock according to the first timestamp probe pair in at least one time slice; Obtaining the i-th midpoint function value of the linear relationship in the i-th time slice, and obtaining the i+1-th midpoint function value of the linear relationship in the i+1-th time slice, where i is an integer greater than or equal to 0; The intersection of the straight line formed by connecting the i-th midpoint function value and the i+1-th midpoint function value and the right endpoint of the i+3-th time slice is taken as the i-th prediction point; At least two of the prediction points are connected in sequence to obtain the first mapping relationship.
15. The distributed transaction processing method according to claim 12, It is characterized in that The obtaining of a second mapping relationship between the local network card clock and the local processor clock includes: In at least one continuous time slice, the following processing is performed at least once respectively: obtaining a first processor timestamp of the local processor clock; obtaining a first network card timestamp generated by the local network card clock; obtaining a second processor timestamp generated by the local processor clock; determining a central processor timestamp corresponding to the first network card timestamp based on the first processor timestamp, the second processor timestamp and a preset fitting coefficient; obtaining a second timestamp probe pair of the local network card clock and the local processor clock according to the central processor timestamp and the first network card timestamp; The second mapping relationship is acquired according to at least one second timestamp probe pair in at least one of the time slices.
16. A transaction executor device for distributed transaction processing, It is characterized in that include: A first receiving module, configured to receive a first request transmitted by a transaction coordinator, wherein the first request includes a first timestamp, and the first timestamp is obtained by a local clock module corresponding to the transaction coordinator; A deferral module, used to defer the execution time of the first request through a preset deferral mechanism; A second receiving module, configured to receive a second request when the first request is not executed, wherein the second request includes a second timestamp, and the second timestamp is smaller than the first timestamp; a first execution module, configured to execute the second request at an execution time indicated by the second timestamp; A second execution module, configured to execute the first request when the postponement mechanism ends; The postponing the execution time of the first request by using a preset postponement mechanism includes: Determining that the first request is a read request for a target data item; Postponing the execution time of the first request; The postponing the execution time of the first request includes: Obtaining the requested access volume of the target data item within a preset time period; When it is determined that the requested access amount is greater than a preset access threshold, the execution time of the first request is postponed.
17. A transaction coordinator device for distributed transaction processing, It is characterized in that The transaction coordinator as used in claim 16 comprises: A third receiving module is used to generate a clock request execution when receiving a target transaction transmitted by an upper layer application, and transmit it to a local clock module; An acquisition module, used for acquiring a first timestamp returned by the local clock module; A generating module is used to generate the first request based on the first timestamp, and transmit the first request to a transaction executor.
18. A local clock module for distributed transaction processing, It is characterized in that The local clock module used in claim 16 comprises: A receiving unit, configured to obtain a first timestamp generated by a local processor clock upon receiving a clock request instruction transmitted by a transaction coordinator, wherein the local processor clock is synchronized with a local network card clock, and the local network card clock is synchronized with a preset root network card clock; A returning unit is used to return the first timestamp to the transaction coordinator.
19. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the steps of the distributed transaction processing method according to any one of claims 1 to 6 are implemented; Alternatively, when the processor executes the program, the steps of the distributed transaction processing method according to any one of claims 7 to 10 are implemented; Alternatively, when the processor executes the program, the steps of the distributed transaction processing method as claimed in any one of claims 11 to 15 are implemented.
20. A non-transitory computer readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the distributed transaction processing method according to any one of claims 1 to 6 are implemented; Alternatively, when the processor executes the program, the steps of the distributed transaction processing method according to any one of claims 7 to 10 are implemented; Alternatively, when the processor executes the program, the steps of the distributed transaction processing method as claimed in any one of claims 11 to 15 are implemented.
21. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the distributed transaction processing method according to any one of claims 1 to 6 are implemented; Alternatively, when the processor executes the program, the steps of the distributed transaction processing method according to any one of claims 7 to 10 are implemented; Alternatively, when the processor executes the program, the steps of the distributed transaction processing method as claimed in any one of claims 11 to 15 are implemented.
Citation Information
Patent Citations
System for managing industry real-time data storage in distributed environment
CN103905537A
Transaction processing method and device, distributed database system and electronic equipment
CN113687921A
Distributed transaction processing in MPP databases
US20160299932A1
