A method, device and storage medium for predicting a distributed transaction branch
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CITIC BANK CO LTD
- Filing Date
- 2022-12-07
- Publication Date
- 2026-06-23
AI Technical Summary
In current distributed transaction processing, the two-phase commit protocol results in a cumbersome process and poor high-interaction performance.
By predicting the resource manager set through the transaction coordinator, unnecessary branch transaction registrations are reduced, thereby improving the performance of distributed transaction processing.
By predicting the setup and propagation of resource manager sets, the state verification of the transaction coordinator is reduced, thus improving the performance of distributed transactions.
Smart Images

Figure CN116048736B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed systems, and in particular to a method, apparatus, device, and storage medium for predicting distributed transaction branches. Background Technology
[0002] Most current distributed transaction implementations employ a two-phase commit protocol. This protocol consists of two phases: a first phase of global transaction registration and branch registration, and a second phase of commit or rollback. These two phases are complex, involving significant interaction between the transaction coordinator (TC), resource manager (RM), and transaction manager (TM).
[0003] In the first phase, each call requires initiating a transaction branch registration with the transaction coordinator (TC). For each request to register a branch transaction, the TC needs to query the global transaction, verify the transaction status, and save the relationship between the branch information and the global transaction, resulting in poor performance of distributed transaction processing.
[0004] Therefore, there is an urgent need for a method to predict distributed transaction branches, which can improve the processing performance of distributed transactions. Summary of the Invention
[0005] The purpose of this embodiment is to provide a method, apparatus, device, and storage medium for predicting distributed transaction branches, so as to improve the processing performance of distributed transactions.
[0006] To achieve the above objectives, this embodiment provides a method for predicting distributed transaction branches, including:
[0007] The transaction manager of the target business service requests the transaction coordinator to start a global transaction with a unique identifier, wherein the unique identifier of the global transaction is used to characterize the category to which the global transaction belongs;
[0008] The transaction coordinator obtains a set of predicted resource managers based on the unique identifier of the global transaction. The set of predicted resource managers includes resource managers corresponding to the business services that are predicted to participate in the global transaction.
[0009] The transaction coordinator feeds back the predictive resource manager set to the transaction manager of the target business service;
[0010] The target service is designated as the current service, and the resource manager of the current service executes steps S1 to S5:
[0011] S1: Determine whether the resource manager of the current business service is in the predicted resource manager set;
[0012] S2: If so, the resource manager of the current business service does not need to register the branch transaction with the transaction coordinator;
[0013] S3: If not, the resource manager of the current business service registers the branch transaction with the transaction coordinator;
[0014] S4: Execute the branch transaction corresponding to the current business service, and call other business services according to the branch transaction corresponding to the current business service;
[0015] S5: The other business service is taken as the current business service, and the resource manager of the current business service executes S1 to S5;
[0016] Until all branch transactions corresponding to all business services participating in the global transaction have been completed, the transaction manager of the target business service initiates a commit or rollback of the global transaction to the transaction coordinator.
[0017] Preferably, the transaction coordinator, based on the unique identifier of the global transaction, further obtains the predicted resource manager set including:
[0018] The transaction coordinator obtains a set of historical resource managers based on the unique identifier of the global transaction. The set of historical resource managers includes resource managers corresponding to business services that have participated in the global transaction.
[0019] The transaction coordinator removes non-compliant resource managers from the historical resource manager set to obtain the predicted resource manager set.
[0020] Preferably, the transaction coordinator removes non-compliant resource managers from the historical resource manager set to obtain the predicted resource manager set, which further includes:
[0021] The transaction coordinator obtains the most recent participation time of the business service corresponding to each resource manager in the historical resource manager set in the global transaction;
[0022] Determine if the most recent engagement time of each resource manager is more than a set time from the current time;
[0023] If so, then remove that resource manager from the set of historical resource managers.
[0024] Preferably, the historical resource manager set records the identifier of each resource manager and the most recent participation time of the business service corresponding to each resource manager in the global transaction.
[0025] Preferably, after the resource manager of the current business service registers the branch transaction with the transaction coordinator, it further includes:
[0026] The transaction coordinator adds the resource manager of the current business service to the set of predicted resource managers.
[0027] Preferred options also include:
[0028] When a global transaction with a unique identifier is initiated for the next time, the transaction coordinator uses the set of predicted resource managers corresponding to the initiation of the current global transaction as the set of historical resource managers corresponding to the initiation of the next transaction.
[0029] Preferably, after executing the branch transaction corresponding to the current business service, the method further includes:
[0030] The resource manager of the current business service adds itself to the set of actual resource managers, which includes the resource managers corresponding to the business services that actually participate in the global transaction.
[0031] Preferably, after the transaction manager of the target business service initiates a commit or rollback to the transaction coordinator, the process further includes:
[0032] If the transaction manager of the target business service initiates a commit to the transaction coordinator, then the branch transaction of each resource manager in the actual resource manager set is committed.
[0033] If the transaction manager of the target business service initiates a rollback to the transaction coordinator, then the branch transactions of each resource manager in the predictive resource manager set are rolled back.
[0034] On the other hand, this embodiment provides a distributed transaction branch prediction device, the device comprising:
[0035] The enabling module is used by the transaction manager of the target business service to request the transaction coordinator to enable a global transaction with a unique identifier, wherein the unique identifier of the global transaction is used to characterize the category to which the global transaction belongs.
[0036] The prediction module is used by the transaction coordinator to obtain a set of predicted resource managers based on the unique identifier of the global transaction. The set of predicted resource managers includes the resource managers corresponding to the business services that are predicted to participate in the global transaction.
[0037] The feedback module is used by the transaction coordinator to feed back the set of predictive resource managers to the transaction manager of the target business service;
[0038] The execution module is used to select the target business service as the current business service, and the resource manager of the current business service executes S1 to S5:
[0039] S1: Determine whether the resource manager of the current business service is in the predicted resource manager set;
[0040] S2: If so, the resource manager of the current business service does not need to register the branch transaction with the transaction coordinator;
[0041] S3: If not, the resource manager of the current business service registers the branch transaction with the transaction coordinator;
[0042] S4: Execute the branch transaction corresponding to the current business service, and call other business services according to the branch transaction corresponding to the current business service;
[0043] S5: The other business service is taken as the current business service, and the resource manager of the current business service executes S1 to S5;
[0044] The commit or rollback module is used so that the transaction manager of the target business service initiates a commit or rollback of the global transaction to the transaction coordinator until all branch transactions corresponding to all business services participating in the global transaction have been executed.
[0045] In another aspect, embodiments of this document also provide a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the computer program, when executed by the processor, performs instructions of any of the methods described above.
[0046] In another aspect, the embodiments of this document also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor of a computer device, performs instructions for any of the methods described above.
[0047] As can be seen from the technical solutions provided in the embodiments above, the embodiments in this paper, by setting the predictive resource manager set and propagating the predictive resource manager set with the call of business services, do not need to register branch transactions for the resource managers of the current business services that exist in the predictive resource manager set. Thus, the transaction coordinator does not need to perform transaction status verification, thereby improving the processing performance of distributed transactions.
[0048] To make the above and other objects, features and advantages of this document more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0049] To more clearly illustrate the technical solutions in the embodiments or prior art described herein, the accompanying drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this article. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 A flowchart illustrating a method for predicting distributed transaction branches provided in an embodiment of this paper is shown.
[0051] Figure 2 This document illustrates a flowchart of the transaction coordinator's process for committing or rolling back branch transactions for each resource manager, as provided in the embodiments of this document.
[0052] Figure 3 This document illustrates a flowchart of a process for obtaining a predicted set of resource managers based on the unique identifier of the global transaction, as provided in an embodiment of the invention.
[0053] Figure 4 The diagram illustrates the process by which the transaction coordinator provided in this embodiment removes non-compliant resource managers from the historical resource manager set to obtain the predicted resource manager set.
[0054] Figure 5 A flowchart illustrating the distributed transaction branch prediction method according to a specific embodiment of this paper is shown.
[0055] Figure 6 This document illustrates a schematic diagram of the module structure of a distributed transaction branch prediction device provided in an embodiment of the invention.
[0056] Figure 7 A schematic diagram of the structure of the computer device provided in the embodiments of this article is shown.
[0057] Explanation of symbols in the attached drawings:
[0058] 100. Activate the module;
[0059] 200. Prediction module;
[0060] 300. Feedback module;
[0061] 400. Execution Module;
[0062] 500. Submit or rollback the module;
[0063] 702. Computer equipment;
[0064] 704, Processor;
[0065] 706. Memory;
[0066] 708. Drive mechanism;
[0067] 710. Input / Output Module;
[0068] 712. Input devices;
[0069] 714. Output devices;
[0070] 716. Presentation equipment;
[0071] 718. Graphical User Interface;
[0072] 720. Network interface;
[0073] 722. Communication link;
[0074] 724. Communication bus. Detailed Implementation
[0075] The technical solutions in the embodiments described below will be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments described herein, and not all of the embodiments. Based on the embodiments described herein, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this document.
[0076] Most current distributed transaction implementations employ a two-phase commit protocol. This protocol consists of two phases: a first phase of global transaction registration and branch registration, and a second phase of commit or rollback. These two phases are complex, involving significant interaction between the transaction coordinator (TC), resource manager (RM), and transaction manager (TM).
[0077] In the first phase, each call requires initiating a transaction branch registration with the transaction coordinator (TC). For each request to register a branch transaction, the TC needs to query the global transaction, verify the transaction status, and save the relationship between the branch information and the global transaction, resulting in poor performance of distributed transaction processing.
[0078] To address the aforementioned issues, this paper provides a method for predicting distributed transaction branches. Figure 1 This is a flowchart illustrating a distributed transaction branch prediction method provided in this embodiment. This specification provides the operational steps of the method described in the embodiments or flowchart, but based on conventional or non-inventive labor, more or fewer operational steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only possible execution order. In actual system or device products, the methods shown in the embodiments or accompanying drawings can be executed sequentially or in parallel.
[0079] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings herein are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0080] Reference Figure 1 This paper provides a method for predicting distributed transaction branches, including:
[0081] S101: The transaction manager of the target business service requests the transaction coordinator to start a global transaction with a unique identifier, wherein the unique identifier of the global transaction is used to characterize the category to which the global transaction belongs;
[0082] S102: The transaction coordinator obtains a set of predicted resource managers based on the unique identifier of the global transaction. The set of predicted resource managers includes the resource managers corresponding to the business services that are predicted to participate in the global transaction.
[0083] S103: The transaction coordinator feeds back the predictive resource manager set to the transaction manager of the target business service;
[0084] S104: The target service is set as the current service, and the resource manager of the current service executes S1 to S5:
[0085] S1: Determine whether the resource manager of the current business service is in the predicted resource manager set;
[0086] S2: If so, the resource manager of the current business service does not need to register the branch transaction with the transaction coordinator;
[0087] S3: If not, the resource manager of the current business service registers the branch transaction with the transaction coordinator;
[0088] S4: Execute the branch transaction corresponding to the current business service, and call other business services according to the branch transaction corresponding to the current business service;
[0089] S5: The other business service is taken as the current business service, and the resource manager of the current business service executes S1 to S5;
[0090] S105: Until all branch transactions corresponding to all business services participating in the global transaction have been completed, the transaction manager of the target business service initiates a global transaction commit or rollback to the transaction coordinator.
[0091] Distributed transactions generally consist of two phases: the preparation phase and the commit / rollback phase. Steps S101 to S104 belong to the first phase, and S105 belongs to the second phase. Generally, after step S105, the second phase includes the transaction coordinator committing or rolling back the branch transactions for each resource manager. (See [reference]). Figure 2 Specifically:
[0092] S201: If the transaction manager of the target business service initiates a commit to the transaction coordinator, then the branch transaction of each resource manager in the actual resource manager set is committed.
[0093] S202: If the transaction manager of the target business service initiates a rollback to the transaction coordinator, then the branch transactions of each resource manager in the prediction resource manager set are rolled back.
[0094] The actual resource manager set includes the resource managers corresponding to the business services that actually participate in the global transaction.
[0095] Distributed transactions are completed through the participation of multiple business services. For example, when a user makes an online purchase, an order payment transaction needs to be initiated, which includes order service A and payment service B. When a customer purchases a product, order service A will decrement the quantity of the product in the inventory by one. Order service A calls payment service B to make the payment. Only after the quantity of the product in the inventory is successfully decremented and the order payment is successful will the online purchase order be in the "pending shipment" state, which means it is successful. Otherwise, the online purchase order will fail.
[0096] Different categories of global transactions are represented by unique identifiers. For global transactions of the same category, the business services involved are largely the same. However, for specific global transactions within the same category, the business services differ. For example, when a user makes an online purchase, the order payment transaction includes order service A and payment service B. However, if the user buys clothing, the order payment transaction includes order service A1 and payment service B; if the user buys food, the order payment transaction includes order service A2 and payment service B. Order services A1 and A2 correspond to different database tables, namely the clothing inventory table and the food inventory table, respectively. Of course, order service A1 can be further subdivided, but this will not be discussed further in this article.
[0097] The global transaction manager is used to start, commit, or roll back global transactions. Each business service has a corresponding resource manager, which can be a database. The transaction coordinator is used to coordinate the resource managers of multiple business services to perform the first phase of global transactions and branch transaction registration, as well as the second phase of commit or rollback, etc.
[0098] The transaction coordinator can obtain the set of predictive resource managers based on the unique identifier of the global transaction, return the set of predictive resource managers to the transaction manager of the target business service, and start executing the steps S1 to S5 above.
[0099] During the execution of S1 to S5, it's important to note that the branch transaction corresponding to the current business service may need to call other business services. For example, in an order payment transaction, order service A calls payment service B to make a payment. Although a set of predictive resource managers is obtained, one or more resource managers in this set may not be needed in practice, or the required resource managers may not exist in the set. For each business service in the global transaction, it's necessary to determine whether its corresponding resource manager is in the set of predictive resource managers. If it is, there's no need to register the branch transaction; otherwise, the branch transaction needs to be registered with the transaction coordinator. As the branch transaction corresponding to the current business service calls other business services, the set of predictive resource managers is propagated to those other business services.
[0100] In this embodiment, by setting the predictive resource manager set and propagating the predictive resource manager set along with the business service calls, there is no need to register branch transactions for the resource manager of the current business service that exists in the predictive resource manager set. Thus, the transaction coordinator no longer needs to verify the transaction status, thereby improving the processing performance of distributed transactions.
[0101] In the embodiments described herein, reference is made to Figure 3 The transaction coordinator, based on the unique identifier of the global transaction, further obtains the predicted resource manager set, including:
[0102] S301: The transaction coordinator obtains a set of historical resource managers based on the unique identifier of the global transaction. The set of historical resource managers includes resource managers corresponding to business services that have participated in the global transaction.
[0103] S302: The transaction coordinator removes non-compliant resource managers from the historical resource manager set to obtain the predicted resource manager set.
[0104] It should be noted that the historical resource manager for this global transaction is obtained based on the previous (most recent) global transaction with the same unique identifier. The historical resource manager for this global transaction includes resource managers that actually participated in the previous global transaction, as well as resource managers that did not participate in the previous global transaction but participated in a global transaction with the same unique identifier.
[0105] For the historical resource manager set, non-compliant resource managers need to be removed in order to obtain the predicted resource manager set.
[0106] Specifically, refer to Figure 4 The transaction coordinator removes non-compliant resource managers from the historical resource manager set to obtain the predicted resource manager set, which further includes:
[0107] S401: The transaction coordinator obtains the most recent participation time of the business service corresponding to each resource manager in the historical resource manager set in the global transaction;
[0108] S402: Determine whether the most recent participation time of each resource manager is more than a set time away from the current time;
[0109] S403: If so, remove the resource manager from the set of historical resource managers;
[0110] S404: If not, then no removal is required.
[0111] The historical resource manager set records the identifier of each resource manager and the most recent participation time of the business service corresponding to each resource manager in the global transaction.
[0112] For resource managers in the historical resource manager set, those that did not participate in the last global transaction but did participate in a global transaction with the same unique identifier may have a longer recent participation time. A longer time means that the business service corresponding to the resource manager has not participated in the global transaction for a long time and needs to be removed. When making the removal judgment, the current time is the time of the current global transaction. The difference between the current time and the recent participation time of each resource manager is calculated and compared with a set time. If the difference is greater than the set time, the resource manager is removed.
[0113] In this embodiment, after the resource manager of the current business service registers the branch transaction with the transaction coordinator, the following steps are also included:
[0114] The transaction coordinator adds the resource manager of the current business service to the set of predicted resource managers.
[0115] During the execution of S101 to S105 above, S3 involves the current business service's resource manager registering a branch transaction with the transaction coordinator. This indicates that the current business service's resource manager does not exist in the predicted resource manager set. Therefore, after S3, the current business service's resource manager can be added to the predicted resource manager set to complete the set, and then S4 is executed. In a global transaction, any current business function may be called more than once. After the predicted resource manager set is completed, if the current business function is called multiple times, subsequent calls, except for the first one, do not need to register a branch transaction with the transaction coordinator, thereby improving the performance of distributed transactions.
[0116] In this embodiment, it also includes:
[0117] When a global transaction with a unique identifier is initiated for the next time, the transaction coordinator uses the set of predicted resource managers corresponding to the initiation of the current global transaction as the set of historical resource managers corresponding to the initiation of the next transaction.
[0118] Once the predicted resource manager set is improved, it can serve as the historical resource manager for the next global transaction with a unique identifier. The next historical resource manager set will include not only the resource manager corresponding to the business service that actually participated in the current global transaction, but also the resource manager corresponding to the business service that actually participated in the previous (relative to the current) global transaction.
[0119] When a global transaction is initiated next time, the historical resource manager set can be further removed to obtain the predicted resource manager set for the next global transaction.
[0120] In this embodiment, after S4: executing the branch transaction corresponding to the current business service, the following is also included:
[0121] The resource manager of the current business service adds itself to the set of actual resource managers, which includes the resource managers corresponding to the business services that actually participate in the global transaction.
[0122] When each global transaction begins, the initial set of actual resource managers is empty. In S4, the resource manager of the current business service adds itself to the set of actual resource managers. The set of actual resource managers can be propagated with the calls of the current business service to other business services. When other business services execute S1 to S5 after becoming the current business service, they add themselves to the set of actual resource managers during the execution of S4, thus obtaining the set of actual resource managers.
[0123] As described in S201 to S202 above, if the transaction manager of the target service initiates a commit to the transaction coordinator, it indicates that the global transaction has been successfully prepared. At this time, the branch transactions of each resource manager in the actual resource manager set are committed. If the transaction manager of the target service initiates a rollback to the transaction coordinator, it indicates that the global transaction preparation has failed. At this time, the branch transactions of each resource manager in the predicted resource manager set need to be rolled back. Here, the resource manager can be a database, and rolling back the resource manager can mean rolling back the database data to its original state.
[0124] It's important to explain that, due to the steps described above—the transaction coordinator adding the resource manager of the current business service to the predicted resource manager set—the predicted resource manager set is the parent set of the actual resource manager set. Therefore, when rolling back each resource manager in the predicted resource manager set, every resource manager in the actual resource manager set will necessarily be rolled back. This also includes some resource managers not in the actual resource manager set that are rolled back because the global transaction preparation failed, likely due to an incorrect call to another resource manager. Rolling back each resource manager in the predicted resource manager set effectively avoids this problem.
[0125] To more clearly illustrate the technical solution described in this paper, a specific embodiment is given below. For details, please refer to... Figure 5 Methods for predicting distributed transaction branches include:
[0126] Step 1.1: The transaction manager of business service A requests the transaction coordinator to start a global transaction;
[0127] Step 1.2: The transaction coordinator feeds back the predicted resource manager set to business service A;
[0128] Step 1.3: If business service A is not in the prediction resource manager set, register the branch transaction with the transaction coordinator;
[0129] Step 1.4: Business service A calls business service B;
[0130] Step 1.5: If business service B is not in the prediction resource manager set, register the branch transaction with the transaction coordinator;
[0131] Step 1.6: Return to the caller;
[0132] Step 1.7: The transaction manager of business service A initiates a global transaction commit or rollback to the transaction coordinator;
[0133] Step 1.8: Commit or rollback the branch transaction of business service A;
[0134] Step 1.9: The branch transaction of business service A is committed or rolled back.
[0135] Step 2.0: Commit or rollback the branch transaction of business service B;
[0136] Step 2.1: The branch transaction of business service B is committed or rolled back.
[0137] Step 2.2: Global transaction commit or rollback complete.
[0138] Based on the aforementioned method for predicting distributed transaction branches, this embodiment also provides a device for predicting distributed transaction branches. The device may include a system (including a distributed system), software (application), module, component, server, client, etc., using the method described in this embodiment, combined with necessary hardware implementation. Based on the same innovative concept, the devices in one or more embodiments provided in this embodiment are as described in the following embodiments. Since the implementation schemes and methods for solving the problem are similar, the implementation of the specific devices in this embodiment can refer to the implementation of the aforementioned method, and repeated details will not be elaborated further. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0139] Specifically, Figure 6 This is a schematic diagram of the module structure of one embodiment of a distributed transaction branch prediction device provided in this article, with reference to... Figure 6 As shown in the embodiments herein, a distributed transaction branch prediction device includes: an initiation module 100, a prediction module 200, a feedback module 300, an execution module 400, and a commit or rollback module 500.
[0140] The enabling module 100 is used by the transaction manager of the target business service to request the transaction coordinator to enable a global transaction with a unique identifier, wherein the unique identifier of the global transaction is used to characterize the category to which the global transaction belongs.
[0141] The prediction module 200 is used by the transaction coordinator to obtain a set of predicted resource managers based on the unique identifier of the global transaction. The set of predicted resource managers includes resource managers corresponding to the business services that are predicted to participate in the global transaction.
[0142] Feedback module 300 is used for the transaction coordinator to feed back the predictive resource manager set to the transaction manager of the target business service;
[0143] Execution module 400 is used to select the target business service as the current business service, and the resource manager of the current business service executes S1 to S5:
[0144] S1: Determine whether the resource manager of the current business service is in the predicted resource manager set;
[0145] S2: If so, the resource manager of the current business service does not need to register the branch transaction with the transaction coordinator;
[0146] S3: If not, the resource manager of the current business service registers the branch transaction with the transaction coordinator;
[0147] S4: Execute the branch transaction corresponding to the current business service, and call other business services according to the branch transaction corresponding to the current business service;
[0148] S5: The other business service is taken as the current business service, and the resource manager of the current business service executes S1 to S5;
[0149] The commit or rollback module 500 is used to initiate a commit or rollback of the global transaction to the transaction coordinator after all branch transactions corresponding to all business services participating in the global transaction have been executed.
[0150] Reference Figure 7As shown, based on the aforementioned method for predicting distributed transaction branches, one embodiment of this document also provides a computer device 702, wherein the above-described method operates on the computer device 702. The computer device 702 may include one or more processors 704, such as one or more central processing units (CPUs) or graphics processing units (GPUs), each of which may implement one or more hardware threads. The computer device 702 may also include any memory 706 for storing any kind of information such as code, settings, data, etc. In one specific embodiment, a computer program is stored on the memory 706 and can run on the processor 704. When the computer program is run by the processor 704, it can execute instructions according to the above-described method. Non-limitingly, for example, the memory 706 may include any type of RAM, any type of ROM, flash memory, hard disk, optical disk, etc. More generally, any memory can use any technology to store information. Further, any memory can provide volatile or non-volatile retention of information. Further, any memory may represent a fixed or removable component of the computer device 702. In one scenario, when processor 704 executes associated instructions stored in any memory or combination of memories, computer device 702 can perform any operation of the associated instructions. Computer device 702 also includes one or more drive mechanisms 708 for interacting with any memory, such as hard disk drive mechanisms, optical disk drive mechanisms, etc.
[0151] Computer device 702 may also include an input / output module 710 (I / O) for receiving various inputs (via input device 712) and providing various outputs (via output device 714). A specific output mechanism may include a presentation device 716 and an associated graphical user interface 718 (GUI). In other embodiments, the input / output module 710 (I / O), input device 712, and output device 714 may be omitted, and the device may function solely as a computer device within a network. Computer device 702 may also include one or more network interfaces 720 for exchanging data with other devices via one or more communication links 722. One or more communication buses 724 couple the components described above together.
[0152] Communication link 722 can be implemented in any way, such as via a local area network, a wide area network (e.g., the Internet), a point-to-point connection, or any combination thereof. Communication link 722 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.
[0153] Corresponding to Figures 1-4In addition to the methods described above, this embodiment also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the above-described methods.
[0154] This embodiment also provides a computer-readable instruction, wherein when a processor executes the instruction, the program therein causes the processor to perform the following: Figures 1 to 4 The method shown.
[0155] It should be understood that in the various embodiments of this document, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.
[0156] It should also be understood that, in the embodiments herein, the term "and / or" is merely a description of the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following associated objects have an "or" relationship.
[0157] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this document.
[0158] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0159] In the embodiments provided herein, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or units, or they may be electrical, mechanical, or other forms of connection.
[0160] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments described herein, depending on actual needs.
[0161] Furthermore, the functional units in the various embodiments of this document can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0162] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this paper, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this paper. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0163] This document uses specific embodiments to illustrate the principles and implementation methods of this document. The descriptions of the embodiments above are only for the purpose of helping to understand the methods and core ideas of this document. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this document. Therefore, the content of this specification should not be construed as a limitation of this document.
Claims
1. A method for predicting distributed transaction branches, characterized in that, include: The transaction manager of the target business service requests the transaction coordinator to start a global transaction with a unique identifier, wherein the unique identifier of the global transaction is used to characterize the category to which the global transaction belongs; The transaction coordinator obtains a set of predicted resource managers based on the unique identifier of the global transaction. The set of predicted resource managers includes resource managers corresponding to the business services that are predicted to participate in the global transaction. The transaction coordinator feeds back the predictive resource manager set to the transaction manager of the target business service; The target service is designated as the current service, and the resource manager of the current service executes steps S1 to S5: S1: Determine whether the resource manager of the current business service is in the predicted resource manager set; S2: If so, the resource manager of the current business service does not need to register the branch transaction with the transaction coordinator; S3: If not, the resource manager of the current business service registers the branch transaction with the transaction coordinator; S4: Execute the branch transaction corresponding to the current business service, and call other business services according to the branch transaction corresponding to the current business service; S5: The other business service is taken as the current business service, and the resource manager of the current business service executes S1 to S5; Until all branch transactions corresponding to all business services participating in the global transaction have been completed, the transaction manager of the target business service initiates a commit or rollback of the global transaction to the transaction coordinator.
2. The method for predicting distributed transaction branches according to claim 1, characterized in that, The transaction coordinator, based on the unique identifier of the global transaction, further obtains the predicted resource manager set, which includes: The transaction coordinator obtains a set of historical resource managers based on the unique identifier of the global transaction. The set of historical resource managers includes resource managers corresponding to business services that have participated in the global transaction. The transaction coordinator removes non-compliant resource managers from the historical resource manager set to obtain the predicted resource manager set.
3. The method for predicting distributed transaction branches according to claim 2, characterized in that, The transaction coordinator removes non-compliant resource managers from the historical resource manager set, resulting in a predicted resource manager set that further includes: The transaction coordinator obtains the most recent participation time of the business service corresponding to each resource manager in the historical resource manager set in the global transaction; Determine if the most recent engagement time of each resource manager is more than a set time from the current time; If so, then remove that resource manager from the set of historical resource managers.
4. The method for predicting distributed transaction branches according to claim 2, characterized in that, The historical resource manager set records the identifier of each resource manager and the most recent participation time of the business service corresponding to each resource manager in the global transaction.
5. The method for predicting distributed transaction branches according to claim 2, characterized in that, After the resource manager of the current business service registers the branch transaction with the transaction coordinator, it also includes: The transaction coordinator adds the resource manager of the current business service to the set of predicted resource managers.
6. The method for predicting distributed transaction branches according to claim 5, characterized in that, Also includes: When a global transaction with a unique identifier is initiated for the next time, the transaction coordinator uses the set of predicted resource managers corresponding to the initiation of the current global transaction as the set of historical resource managers corresponding to the initiation of the next transaction.
7. The method for predicting distributed transaction branches according to claim 6, characterized in that, After executing the branch transaction corresponding to the current business service, the process also includes: The resource manager of the current business service adds itself to the set of actual resource managers, which includes the resource managers corresponding to the business services that actually participate in the global transaction.
8. The method for predicting distributed transaction branches according to claim 7, characterized in that, After the transaction manager of the target business service initiates a commit or rollback to the transaction coordinator, the following steps are also included: If the transaction manager of the target business service initiates a commit to the transaction coordinator, then the branch transaction of each resource manager in the actual resource manager set is committed. If the transaction manager of the target business service initiates a rollback to the transaction coordinator, then the branch transactions of each resource manager in the predictive resource manager set are rolled back.
9. A distributed transaction branch prediction device, characterized in that, The device includes: The enabling module is used by the transaction manager of the target business service to request the transaction coordinator to enable a global transaction with a unique identifier, wherein the unique identifier of the global transaction is used to characterize the category to which the global transaction belongs. The prediction module is used by the transaction coordinator to obtain a set of predicted resource managers based on the unique identifier of the global transaction. The set of predicted resource managers includes the resource managers corresponding to the business services that are predicted to participate in the global transaction. The feedback module is used by the transaction coordinator to feed back the set of predictive resource managers to the transaction manager of the target business service; The execution module is used to select the target business service as the current business service, and the resource manager of the current business service executes S1 to S5: S1: Determine whether the resource manager of the current business service is in the predicted resource manager set; S2: If so, the resource manager of the current business service does not need to register the branch transaction with the transaction coordinator; S3: If not, the resource manager of the current business service registers the branch transaction with the transaction coordinator; S4: Execute the branch transaction corresponding to the current business service, and call other business services according to the branch transaction corresponding to the current business service; S5: The other business service is taken as the current business service, and the resource manager of the current business service executes S1 to S5; The commit or rollback module is used so that the transaction manager of the target business service initiates a commit or rollback of the global transaction to the transaction coordinator until all branch transactions corresponding to all business services participating in the global transaction have been executed.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, When the computer program is run by the processor, it executes the instructions of the method according to any one of claims 1-8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is run by the processor of the computer device, it executes the instructions of the method according to any one of claims 1-8.