Transaction processing method and device, processor and electronic device
By dynamically selecting backup nodes and implementing circuit breaker control in a distributed system, the transaction processing problem when the server fails is solved, improving the system's stability and efficiency while reducing costs.
Patent Information
- Application Number
- CN202210873591.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-22
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-07-22
AI Technical Summary
When a server that processes transactions in a distributed system malfunctions, it affects the efficiency of the distributed system in processing transactions, and existing technologies have not been able to effectively solve this problem.
By obtaining the processing results of multiple transactions in a distributed system, identifying the target transactions that have failed, and processing these failed transactions through the target nodes, dynamically selecting backup nodes, implementing circuit breaker control and service degradation, the efficiency and reliability of transaction processing are ensured.
It improves the transaction processing efficiency of distributed systems in the event of server failure, enhances system stability and availability, reduces transaction redundancy time, and lowers hardware and maintenance costs.
Smart Images

Figure CN114998020B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of financial technology, and more specifically, to a transaction processing method and apparatus, processor, and electronic device. Background Technology
[0002] When a large-scale distributed system provides online transactions, the system must possess a certain level of stability, high availability, and timely response. Furthermore, Figure 1 This is a schematic diagram illustrating how a distributed system in existing technology provides online transactions, such as... Figure 1 As shown:
[0003] Cluster A is a load-balanced cluster where each node has the same function and can provide the same service. Each node in cluster A depends on service B provided by cluster B. Therefore, it can be seen that the availability and stability of service B play a crucial role in transactions; the entire transaction chain depends on service B. However, when using... Figure 1 When the distributed system shown provides online transactions, the following three situations may occur:
[0004] (1) When cluster B experiences network slowdown or excessive access pressure, it will cause service B to respond slowly, resulting in excessive time consumption of the entire transaction chain, excessive time consumption of client access, and unfriendly user experience.
[0005] (2) When the network where cluster B is located experiences a regional network outage, making it impossible for cluster A and cluster B to communicate normally, or when cluster B experiences an internal processing error, cluster A will experience call error and other abnormal information, and the client will receive some error codes.
[0006] (3) When cluster B has an error in its internal program logic, the returned result will be inaccurate, and the result information obtained by the client from cluster A will be incorrect, resulting in dirty business data.
[0007] In related technologies, the following methods are used to solve the above problems:
[0008] To address the above situations, a common and simple approach is to modify the way cluster A calls service B, i.e., to use an asynchronous method, or to rate-limit service B. The asynchronous method means that the system immediately returns a friendly notification to the customer, and then returns the actual result after service B has finished processing. The advantage of this approach is that it prevents transaction blocking in cluster A and excessive user waiting time when the response time of service B increases. However, the disadvantage is that asynchronous calls cannot be applied to online transactions. This is because a business scenario requires a customer to receive the result immediately after making a transaction, rather than waiting for a period of time. For example, a typical scenario is when a customer needs to check their bank account balance; they want to see the balance amount immediately after initiating the query, not a pop-up message indicating to check again in a few minutes. Rate limiting service B, i.e., limiting QPS (Queries Per Second), can prevent excessive resource consumption, transaction blocking, and slow response times caused by high call volume. However, the disadvantage is also obvious: calls exceeding the QPS will directly return abnormal results. This approach has a certain impact on the business experience in a service-oriented application system, significantly reducing the system's external service capacity. Therefore, to improve this situation and add a mechanism for handling such exceptions, another technical solution is service degradation. We can build a fallback service, called service C, within the system to temporarily replace service B. When a server node in cluster A encounters an anomaly while accessing service B for various reasons, it can then access service C as a fallback solution for transactions. However, this solution also has many areas for improvement and optimization. For example, adding cluster C to a distributed system inevitably increases the system's hardware and maintenance costs, while also reducing the stability and availability of the distributed system. Furthermore, when cluster A's access to service B is slow or service B is faulty, the transaction chain must first access service B each time. Only after service B returns an anomaly does cluster A access the fallback service C, which then processes the transaction. This process involves transaction redundancy and time consumption, leading to lower efficiency in the distributed system's transaction processing.
[0009] There is currently no effective solution to the problem that the efficiency of transaction processing in a distributed system is affected when the server processing the transaction fails. Summary of the Invention
[0010] The main objective of this application is to provide a transaction processing method, apparatus, processor, and electronic device to solve the problem in the related art where the transaction processing server in a distributed system malfunctions, affecting the transaction processing performance of the distributed system.
[0011] To achieve the above objectives, according to one aspect of this application, a transaction processing method is provided. The method is applied to a target server, wherein the target server is a server in a first cluster of a distributed system, and the distributed system further includes a second cluster, wherein the second cluster includes at least a target node. The method includes: acquiring a plurality of first transactions, wherein the first transactions are transactions to be processed in the distributed system; processing each of the plurality of first transactions to obtain a plurality of target processing results; determining, based on each of the plurality of target processing results, whether there is at least one target transaction that has failed among the plurality of first transactions; and if there is a target transaction that has failed among the plurality of first transactions, processing the target transaction through the target node.
[0012] Furthermore, the distributed system also includes a first server, and the second cluster also includes multiple first nodes. The first server is used to store a first information table, which represents the attribute information of each first node. If there is a target transaction that has failed among the multiple first transactions, the method further includes, before processing the target transaction through the target node, obtaining the first information table from the first server and determining the target node from the multiple first nodes based on the first information table.
[0013] Furthermore, if there is a failed target transaction among the plurality of first transactions, after processing the target transaction through the target node, the method further includes: obtaining a first processing result of the target node processing the target transaction; determining whether the target transaction is successful based on the first processing result; if the target transaction fails, deleting the attribute information of the target node from the first information table to obtain a second information table; determining a second node based on the second information table, and processing the target transaction through the second node.
[0014] Furthermore, after processing the target transaction through the target node, or after processing the target transaction through the second node, the method further includes: obtaining a first quantity and a second quantity, wherein the first quantity is used to represent the number of nodes processing the target transaction within a preset time, and the second quantity is used to represent the number of nodes in the second cluster; and determining whether to perform circuit breaker processing on the nodes in the second cluster based on the first quantity and the second quantity.
[0015] Furthermore, after determining whether to perform circuit breaker processing on nodes in the second cluster based on the first quantity and the second quantity, the method further includes: if it is determined that circuit breaker processing should be performed on nodes in the second cluster, then the second cluster is in a circuit breaker state; after the second cluster is in the circuit breaker state, a plurality of second transactions are obtained, wherein the second transactions are transactions to be processed in the distributed system after the second cluster is in the circuit breaker state; and each of the plurality of second transactions is processed by the target node.
[0016] Furthermore, after the second cluster is in the circuit breaker state, the method further includes: determining whether any one of the plurality of second transactions has been successfully processed; if it is determined that any one of the plurality of second transactions has been successfully processed, then obtaining a third quantity and a second quantity, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within the preset time period; and determining whether to switch the second cluster to a non-circuit breaker state based on the third quantity and the second quantity.
[0017] Further, obtaining the first quantity includes: obtaining attribute information of each node processing the target transaction and the time when each node receives the target transaction; and determining the first quantity based on the attribute information of each node and the time when each node receives the target transaction.
[0018] To achieve the above objectives, according to another aspect of this application, a transaction processing apparatus is provided. This apparatus is applied in a target server, wherein the target server is a server in a first cluster of a distributed system, and the distributed system further includes a second cluster, wherein the second cluster includes at least a target node. The apparatus includes: a first acquisition unit, configured to acquire a plurality of first transactions, wherein the first transactions are transactions to be processed in the distributed system; a first processing unit, configured to process each of the plurality of first transactions to obtain a plurality of target processing results; a first judgment unit, configured to determine, based on each of the plurality of target processing results, whether there is at least one failed target transaction among the plurality of first transactions; and a second processing unit, configured to process the target transaction through the target node if there is a failed target transaction among the plurality of first transactions.
[0019] Furthermore, the distributed system further includes a first server, and the second cluster further includes multiple first nodes. The first server is used to store a first information table, which represents the attribute information of each first node. The device further includes: a second acquisition unit, used to acquire the first information table from the first server before processing the target transaction through the target node if there is a failed target transaction among the multiple first transactions; and a first determination unit, used to determine the target node from the multiple first nodes based on the first information table.
[0020] Furthermore, the device further includes: a third acquisition unit, configured to, if there is a failed target transaction among the plurality of first transactions, acquire a first processing result of the target node processing the target transaction after processing the target transaction through the target node; a second determination unit, configured to determine whether the target transaction is successful based on the first processing result; a first deletion unit, configured to, if the target transaction fails, delete the attribute information of the target node from the first information table to obtain a second information table; and a third processing unit, configured to, based on the second information table, determine a second node and process the target transaction through the second node.
[0021] Furthermore, the device further includes: a fourth acquisition unit, configured to acquire a first quantity and a second quantity after the target transaction is processed by the target node or after the target transaction is processed by the second node, wherein the first quantity represents the number of nodes that process the target transaction within a preset time period, and the second quantity represents the number of nodes in the second cluster; and a third determination unit, configured to determine whether to perform circuit breaker processing on the nodes in the second cluster based on the first quantity and the second quantity.
[0022] Furthermore, the apparatus further includes: a fourth processing unit, configured to, after determining whether to perform circuit breaker processing on nodes in the second cluster based on the first quantity and the second quantity, if it is determined that circuit breaker processing should be performed on nodes in the second cluster, then the second cluster is in a circuit breaker state; a fifth acquisition unit, configured to acquire multiple second transactions after the second cluster is in the circuit breaker state, wherein the second transactions are transactions to be processed in the distributed system after the second cluster is in the circuit breaker state; and a fifth processing unit, configured to process each of the multiple second transactions through the target node.
[0023] Furthermore, the device further includes: a second judging unit, configured to judge whether any one of the plurality of second transactions has been successfully processed after the second cluster is in the circuit breaker state; a sixth obtaining unit, configured to obtain a third quantity and a second quantity if it is determined that any one of the plurality of second transactions has been successfully processed, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within the preset time period; and a fourth determining unit, configured to determine whether to switch the second cluster to a non-circuit breaker state based on the third quantity and the second quantity.
[0024] Furthermore, the fourth acquisition unit includes: a first acquisition module, used to acquire attribute information of each node processing the target transaction and the time when each node receives the target transaction; and a first determination module, used to determine the first quantity based on the attribute information of each node and the time when each node receives the target transaction.
[0025] To achieve the above objectives, according to another aspect of this application, a processor is provided for running a program, wherein the program, when running, executes the transaction processing method described in any of the above-described embodiments.
[0026] To achieve the above objectives, according to another aspect of this application, an electronic device is provided, the electronic device including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the transaction processing method described in any one of the above.
[0027] This application can be applied to a target server in a first cluster of a distributed system, which also includes a second cluster, wherein the second cluster includes at least a target node. The application employs the following steps: acquiring multiple first transactions, where each first transaction is a transaction to be processed in the distributed system; processing each of the multiple first transactions to obtain multiple target processing results; determining, based on each target processing result, whether there is at least one failed target transaction among the multiple first transactions; and if there is a failed target transaction among the multiple first transactions, processing the target transaction through the target node. This solves the problem in related technologies where the server processing transactions in the distributed system is abnormal, affecting the efficiency of transaction processing in the distributed system. By having the server in the first cluster process each of the acquired multiple transactions and, based on the processing results, determining whether there is at least one failed transaction among the multiple transactions, and if so, processing the failed transaction through a node in the second cluster, the efficiency of transaction processing in the distributed system can be improved when the server processing transactions in the distributed system is abnormal. Attached Figure Description
[0028] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0029] Figure 1 This is a schematic diagram illustrating how a distributed system in existing technology provides online transactions.
[0030] Figure 2 This is a schematic diagram illustrating the provision of online transactions by a distributed system according to an embodiment of this application;
[0031] Figure 3 This is a flowchart of a transaction processing method provided according to an embodiment of this application;
[0032] Figure 4 This is a flowchart of a single degradation process for each node in cluster A in this application embodiment;
[0033] Figure 5 This is a flowchart illustrating the process of circuit breaking and returning to a non-circuit-broken state in an embodiment of this application.
[0034] Figure 6 This is a schematic diagram of a transaction processing apparatus provided according to an embodiment of this application;
[0035] Figure 7 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0036] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0037] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0038] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application 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 for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus 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 apparatus.
[0039] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are information and data authorized by the user or fully authorized by all parties. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain the relevant information after receiving consent information from the aforementioned user or organization.
[0040] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0041] Distributed services: Distributed refers to distributed computing, a research area in computer science that studies how to break down a problem requiring enormous computing power into many smaller parts, distribute these parts among multiple computers for processing, and finally combine the results to obtain the final outcome. Similarly, distributed services refer to decoupling a service that originally required a large amount of overall computation into several smaller services, deploying them on different machines to alleviate service pressure.
[0042] Load balancing clusters offer an effective solution to capacity issues for enterprise needs. Furthermore, load balancing clusters distribute the workload as evenly as possible across the computer cluster. Additionally, the load typically includes application processing load and network traffic load, with each node capable of handling a certain amount of processing load, and the load can be dynamically distributed among the nodes to achieve load balancing.
[0043] Service degradation: In distributed services, when a service call to a normal service encounters an exception (including exceptions in the called service, service processing timeouts, network timeouts, etc.), in order to ensure that the process is not interrupted, stuck, or made to wait by the client, a degraded service needs to be called to continue the entire call process. This process is called service degradation.
[0044] Service circuit breaking: If a service crashes or experiences too many service failures within a given time period (i.e., too many service degradations), then a service circuit breaker is triggered. After a circuit breaker is triggered, the normal methods are skipped, and the fallback (contingency plan) method is called directly, meaning the service becomes unavailable after a circuit breaker. Similar to a home fuse, when the maximum service access limit is reached, access is denied, the power is cut off, and then the service degradation fallback method is called, returning a user-friendly message.
[0045] This invention can be applied to, for example Figure 2 The first cluster in the distributed system shown (corresponding to) Figure 2 The target server in cluster B (corresponding to) Figure 2 In the distributed system, a second cluster (corresponding to the servers in cluster B) can also be included. Figure 2 Cluster A in the second cluster includes at least the target node (corresponding to...). Figure 2 The master node in cluster A (i.e., the cluster control node) is mentioned below in conjunction with preferred implementation steps. Figure 3 This is a flowchart of a transaction processing method provided according to an embodiment of this application, such as... Figure 3 As shown, the method includes the following steps:
[0046] Step S301: Obtain multiple first transactions, where the first transactions are transactions to be processed in the distributed system.
[0047] For example, Figure 2 The target server in cluster B retrieves multiple transactions to be processed in the distributed system.
[0048] Step S302: Process each of the multiple first transactions to obtain multiple target processing results.
[0049] For example, Figure 2 The target servers in cluster B process the multiple transactions to be processed in the distributed system.
[0050] Step S303: Based on each target processing result among the multiple target processing results, determine whether there is a target transaction among the multiple first transactions where at least one transaction failed.
[0051] For example, Figure 2 The target server in cluster B can determine whether there are any failed transactions based on the processing results of multiple transactions pending in the distributed system processed by the servers in cluster B. In other words, after multiple transactions pending in the distributed system are processed by the servers in cluster B, are there any failed transactions?
[0052] Step S304: If there is a failed target transaction among the multiple first transactions, then the target transaction is processed through the target node.
[0053] For example, in a distributed system, if multiple transactions awaiting processing are processed by servers in cluster B, and some transactions fail, then... Figure 2 The target server in cluster B can be accessed through Figure 2 The master node in cluster A processes failed transactions.
[0054] Through the above steps S301 to S304, each of the multiple transactions obtained is processed by the servers in the first cluster, and based on the processing results, it is determined whether there is at least one failed transaction among the multiple transactions. If there is a failed transaction among the multiple transactions, the failed transaction is processed by the nodes in the second cluster. In this way, the transaction processing efficiency of the distributed system can be improved when the server processing transactions in the distributed system is abnormal.
[0055] Determining the target node is crucial for this application. Therefore, in the transaction processing method provided in this application embodiment, the following steps are used to determine the target node: the distributed system also includes a first server, and the second cluster also includes multiple first nodes. The first server is used to store a first information table, which represents the attribute information of each first node. If there is a target transaction that has failed among the multiple first transactions, the first information table is obtained from the first server before processing the target transaction through the target node. Based on the first information table, the target node is determined from the multiple first nodes.
[0056] For example, the first server mentioned above can be Figure 2 In the DB database server, the aforementioned multiple first nodes can be... Figure 2 In cluster A, there are multiple slave nodes (replica nodes corresponding to the master node, the cluster control node). First, maintain an information table in the database server containing all nodes in cluster A (including the master node and multiple slave nodes); and after each node in cluster A starts, Figure 2 The target server in cluster B will periodically pull information about all nodes in cluster A from the DB database server and record it in memory, and refresh the cluster information in memory periodically; then each node will select the node with the largest IP as the master node (the target node mentioned above) based on the cluster information in memory.
[0057] The above method can quickly and accurately identify the nodes in the cluster that need to process transactions.
[0058] To ensure high availability of the cluster, in the transaction processing method provided in this application embodiment, if there is a failed target transaction among multiple first transactions, after the target transaction is processed by the target node, the transaction can be processed through the following steps: obtaining the first processing result of the target node processing the target transaction; determining whether the target transaction is successful based on the first processing result; if the target transaction fails, deleting the attribute information of the target node from the first information table to obtain a second information table; determining the second node based on the second information table, and processing the target transaction through the second node.
[0059] For example, when an anomaly is detected in the master node, we only need to modify the cluster information in the database, that is, remove the information record corresponding to the master node from the cluster information table. Since each node periodically pulls cluster information and re-selects the node with the highest IP address as the master node, therefore... Figure 2 The target server in cluster B can re-select a working master node and process transactions through the re-selected master node.
[0060] In summary, by equipping all important nodes in the cluster with backup nodes and adopting a dynamic master node selection method—that is, when a master node in the cluster fails, the cluster can automatically select another master node as the circuit breaker control node by modifying the database table—it can prevent the entire cluster from becoming unavailable due to the failure of a single important node, thus ensuring the high availability of the cluster.
[0061] To accurately determine whether to apply circuit breaker processing to nodes in the cluster, in the transaction processing method provided in this application embodiment, after processing the target transaction through the target node, or after processing the target transaction through the second node, the following steps can be used to determine whether to apply circuit breaker processing to nodes in the cluster: obtaining a first quantity and a second quantity, wherein the first quantity is used to represent the number of nodes processing the target transaction within a preset time, and the second quantity is used to represent the number of nodes in the second cluster; and determining whether to apply circuit breaker processing to nodes in the second cluster based on the first quantity and the second quantity.
[0062] For example, Figure 4 This is a flowchart of a single degradation process for each node in cluster A in this application embodiment, as shown below. Figure 4As shown, each node in cluster A has three modules: a transaction module, a circuit breaker control module, and a degradation service module. The transaction module handles client requests normally and depends on service B. The circuit breaker control module is only enabled when a node detects itself as the master node; otherwise, it is disabled. This module records node information, including abnormal transaction information and node recovery information during circuit breaker states. The degradation service module is also only enabled on the master node. This module provides degradation services. When a node in the cluster experiences an abnormal access to service B, it sends a transaction request to the master node. The transaction is completed through the degradation service provided by the master node, and the result is returned to the client.
[0063] For example, Figure 5 This is a flowchart illustrating the process of circuit breaking and returning to a non-circuit-breaker state in an embodiment of this application, as shown below. Figure 5 As shown, the circuit breaker status control module on the master node can maintain two HashMap data structures. One, `brokenMap`, stores the latest request time record of the failed node. It can be stored in key-value pair format, where the key can be the IP address of the corresponding requesting node, and the value can be the time of the most recent failed request. The other, `recoveryMap`, stores the latest request time record of the recovered node after the cluster circuit breaker is triggered and the detection thread detects service recovery. It can also be stored in key-value pair format, where the key can be the IP address of the corresponding requesting node, and the value can be the time of the most recent failed request. Furthermore, Figure 5 The core logic lies in the circuit breaker control module starting two timed scanning threads. The circuit breaker thread can scan the `brokenMap`, which records anomaly information, even when the number of abnormal node IPs (the first number) within the current unit of time (the preset time mentioned above) exceeds half of the cluster (the second number mentioned above). At this point, it indicates that more than half of the cluster is experiencing an anomaly. Figure 2 The target server in cluster B can notify all nodes to initiate a circuit breaker.
[0064] In summary, deploying a degraded service on the master node allows slave nodes in the cluster to access the degraded service through the master node when they encounter anomalies while accessing external services. The master node can also record abnormal access information for each node in the cluster without requiring additional communication transactions to collect information on abnormal nodes. Furthermore, the master node's assessment of the overall cluster anomaly situation when deciding whether to initiate circuit breaking makes the judgment more accurate. And when an external dependent service is determined to be abnormal, notifying the entire cluster to initiate circuit breaking ensures that the circuit breaker status of each node in the cluster remains consistent.
[0065] In order to accurately obtain the first quantity, the transaction processing method provided in this application embodiment can also obtain the first quantity through the following steps: obtaining the attribute information of each node processing the target transaction and the time when each node receives the target transaction; determining the first quantity based on the attribute information of each node and the time when each node receives the target transaction.
[0066] For example, Figure 2 The target server in cluster B stores the following information in the circuit breaker status control module of the master node: the key (keyword) corresponding to the IP of the requesting node (the attribute information of each node mentioned above) and the value (attribute value) the time of the most recent abnormal request (the time when each node received the target transaction mentioned above). The number of abnormal node IPs per unit time can be calculated.
[0067] The above method can quickly and accurately calculate the number of abnormal node IPs per unit time.
[0068] How to handle transactions sent by clients after a cluster circuit breaker is crucial to this application. Therefore, the transaction processing method provided in this application uses the following steps to process transactions sent by clients after a cluster circuit breaker: After determining whether to apply circuit breaker processing to nodes in the second cluster based on a first quantity and a second quantity, if it is determined that circuit breaker processing should be applied to nodes in the second cluster, then the second cluster is in a circuit breaker state; after the second cluster is in a circuit breaker state, multiple second transactions are obtained, wherein the second transactions are transactions to be processed in the distributed system after the second cluster is in a circuit breaker state; each of the multiple second transactions is processed by the target node.
[0069] For example, Figure 2 After the target server in cluster B notifies all nodes to initiate circuit breaking, the cluster will switch to the circuit-breaking state. At this time, transaction requests received from clients will directly access the degraded service of the master node and will no longer access the abnormal service.
[0070] With the above solution, when the cluster is in a circuit breaker state, transactions sent by clients can be processed through the degraded service of the nodes.
[0071] To accurately determine whether to switch the second cluster to a non-circuit-breaker state, the transaction processing method provided in this application embodiment can also determine whether to switch the second cluster to a non-circuit-breaker state through the following steps: after the second cluster is in a circuit-breaker state, determine whether the target server has successfully processed any one of the multiple second transactions; if the target server has successfully processed any one of the multiple second transactions, obtain a third quantity and a second quantity, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within a preset time; based on the third quantity and the second quantity, determine whether to switch the second cluster to a non-circuit-breaker state.
[0072] For example, Figure 2 After the target server in cluster B notifies all nodes to initiate circuit breaking, the cluster will switch to the circuit-breaking state. Locally, a scheduled service probe will be initiated. When the service is detected to be normal, the master node will be notified that the node has recovered. At this time, another scheduled recovery scan thread in the circuit breaker control module of the master node scans the recovery map. When it detects that more than half of the cluster nodes can access the service normally within the most recent unit of time, it notifies all nodes to close the circuit breaker state, and all nodes resume normal access to service B.
[0073] By using the above solution, when it is determined that the external dependent service has returned to normal, the cluster is notified to close the circuit breaker, which can keep the circuit breaker status of each node in the entire cluster consistent.
[0074] The method provided in this application embodiment allows for the processing of pending transactions in a distributed system when service anomalies occur. This can be achieved through the following steps: dynamically selecting the cluster master node, single-event degradation and overall circuit breaking, and normal rollback. Specifically, multiple backup nodes are configured for critical nodes in the cluster, and these nodes can all perform service degradation. Therefore, when a service anomaly occurs in the distributed system, the node with the largest IP address can be selected first to process the pending transactions. If this node fails, other backup nodes are dynamically selected to process multiple pending transactions. If the circuit breaking thread determines that the number of requesting nodes for processing transactions within a unit of time exceeds half the number of nodes in the cluster, all nodes are notified, and the cluster is switched to a circuit-breaking state. Finally, the recovery thread determines whether the number of recovering nodes within a unit of time exceeds half the number of nodes in the cluster. If the number of recovering nodes within a unit of time exceeds half the number of nodes in the cluster, all nodes are notified, and the cluster is switched back to a non-circuit-breaking state.
[0075] In summary, this application can be applied to a target server in a first cluster of a distributed system. The distributed system also includes a second cluster, which contains at least a target node. The transaction processing method provided in this application involves acquiring multiple first transactions, where each first transaction is a transaction to be processed in the distributed system; processing each of the multiple first transactions by the target server to obtain multiple target processing results; determining, based on each target processing result, whether there is at least one failed target transaction among the multiple first transactions; and if there is a failed target transaction among the multiple first transactions, processing the target transaction by the target node. This solves the problem in related technologies where the effectiveness of transaction processing in a distributed system is affected when the server processing transactions in the distributed system is abnormal. By having the server in the first cluster process each of the acquired multiple transactions and determining, based on the processing results, whether there is at least one failed transaction among the multiple transactions, and if there is a failed transaction, processing the failed transaction by a node in the second cluster, the effectiveness of transaction processing in a distributed system can be improved when the server processing transactions in the distributed system is abnormal.
[0076] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0077] This application also provides a transaction processing apparatus. It should be noted that the transaction processing apparatus of this application can be used to execute the transaction processing method provided in this application. The transaction processing apparatus provided in this application will be described below.
[0078] Figure 6 This is a schematic diagram of a transaction processing apparatus according to an embodiment of this application. Figure 6 As shown, the device includes: a first acquisition unit 601, a first processing unit 602, a first judgment unit 603, and a second processing unit 604.
[0079] Specifically, the first acquisition unit 601 is used to acquire multiple first transactions, wherein the first transactions are transactions to be processed in the distributed system;
[0080] The first processing unit 602 is used to process each of the multiple first transactions to obtain multiple target processing results;
[0081] The first judgment unit 603 is used to determine, based on each of the multiple target processing results, whether there is a target transaction that has failed in at least one of the multiple first transactions;
[0082] The second processing unit 604 is used to process the target transaction through the target node if there is a target transaction that has failed among the multiple first transactions.
[0083] In summary, the transaction processing apparatus provided in this application embodiment acquires multiple first transactions through a first acquisition unit 601, wherein the first transactions are transactions to be processed in a distributed system; a first processing unit 602 processes each of the multiple first transactions to obtain multiple target processing results; a first judgment unit 603 determines, based on each target processing result, whether there is at least one failed target transaction among the multiple first transactions; and a second processing unit 604 processes the target transaction through a target node if there is a failed target transaction among the multiple first transactions. This solves the problem in related technologies where the server processing transactions in a distributed system is abnormal, affecting the effectiveness of transaction processing in the distributed system. By having servers in a first cluster process each of the acquired multiple transactions and determine, based on the processing results, whether there is at least one failed transaction among the multiple transactions, and if there is a failed transaction, processing the failed transaction through a node in a second cluster, the effectiveness of transaction processing in the distributed system can be improved when the server processing transactions in the distributed system is abnormal.
[0084] Optionally, in the transaction processing apparatus provided in this application embodiment, the distributed system further includes a first server, and the second cluster further includes multiple first nodes. The first server is used to store a first information table, which represents the attribute information of each first node. The apparatus further includes: a second acquisition unit, used to acquire the first information table from the first server before processing the target transaction through the target node if there is a target transaction that has failed among the multiple first transactions; and a first determination unit, used to determine the target node from the multiple first nodes based on the first information table.
[0085] Optionally, in the transaction processing apparatus provided in the embodiments of this application, the apparatus further includes: a third acquisition unit, configured to, if there is a target transaction that has failed among a plurality of first transactions, acquire a first processing result of the target node processing the target transaction after processing the target transaction through the target node; a second determination unit, configured to determine whether the target transaction is successful based on the first processing result; a first deletion unit, configured to, if the target transaction fails, delete the attribute information of the target node from the first information table to obtain a second information table; and a third processing unit, configured to, based on the second information table, determine a second node and process the target transaction through the second node.
[0086] Optionally, in the transaction processing apparatus provided in the embodiments of this application, the apparatus further includes: a fourth acquisition unit, configured to acquire a first quantity and a second quantity after processing the target transaction through the target node, or after processing the target transaction through the second node, wherein the first quantity is used to represent the number of nodes processing the target transaction within a preset time, and the second quantity is used to represent the number of nodes in the second cluster; and a third determination unit, configured to determine whether to perform circuit breaker processing on the nodes in the second cluster based on the first quantity and the second quantity.
[0087] Optionally, in the transaction processing apparatus provided in the embodiments of this application, the apparatus further includes: a fourth processing unit, configured to, after determining whether to perform circuit breaking processing on nodes in the second cluster based on a first quantity and a second quantity, if it is determined that circuit breaking processing should be performed on nodes in the second cluster, then the second cluster is in a circuit-breaking state; a fifth acquisition unit, configured to acquire multiple second transactions after the second cluster is in a circuit-breaking state, wherein the second transactions are transactions to be processed in the distributed system after the second cluster is in a circuit-breaking state; and a fifth processing unit, configured to process each of the multiple second transactions through a target node.
[0088] Optionally, in the transaction processing apparatus provided in the embodiments of this application, the apparatus further includes: a second judgment unit, configured to determine whether any one of the multiple second transactions has been successfully processed after the second cluster is in a circuit breaker state; a sixth acquisition unit, configured to acquire a third quantity and a second quantity if it is determined that any one of the multiple second transactions has been successfully processed, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within a preset time; and a fourth determination unit, configured to determine whether to switch the second cluster to a non-circuit breaker state based on the third quantity and the second quantity.
[0089] Optionally, in the transaction processing apparatus provided in this application embodiment, the fourth acquisition unit includes: a first acquisition module, used to acquire the attribute information of each node processing the target transaction and the time when each node receives the target transaction; and a first determination module, used to determine a first quantity based on the attribute information of each node and the time when each node receives the target transaction.
[0090] The transaction processing device includes a processor and a memory. The first acquisition unit 601, the first processing unit 602, the first judgment unit 603, and the second processing unit 604 are all stored in the memory as program units. The processor executes the program units stored in the memory to realize the corresponding functions.
[0091] A processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can improve the efficiency of transaction processing in a distributed system.
[0092] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0093] This invention provides a processor for running a program, wherein the program executes a transaction processing method during runtime.
[0094] like Figure 7 As shown, an embodiment of the present invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: acquiring a plurality of first transactions, wherein the first transactions are transactions to be processed in the distributed system; processing each of the plurality of first transactions to obtain a plurality of target processing results; determining, based on each of the plurality of target processing results, whether there is at least one target transaction that has failed among the plurality of first transactions; and if there is a target transaction that has failed among the plurality of first transactions, processing the target transaction through the target node.
[0095] When the processor executes the program, it also performs the following steps: the distributed system further includes a first server, and the second cluster further includes multiple first nodes, wherein the first server is used to store a first information table, the first information table is used to represent the attribute information of each first node, and if there is a target transaction that has failed among the multiple first transactions, before processing the target transaction through the target node, the method further includes: obtaining the first information table from the first server; and determining the target node from the multiple first nodes based on the first information table.
[0096] When the processor executes the program, it also implements the following steps: if there is a failed target transaction among the plurality of first transactions, after processing the target transaction through the target node, the method further includes: obtaining a first processing result of the target node processing the target transaction; determining whether the target transaction is successful based on the first processing result; if the target transaction fails, deleting the attribute information of the target node from the first information table to obtain a second information table; determining a second node based on the second information table, and processing the target transaction through the second node.
[0097] When the processor executes the program, it also performs the following steps: after processing the target transaction through the target node, or after processing the target transaction through the second node, the method further includes: obtaining a first quantity and a second quantity, wherein the first quantity is used to represent the number of nodes that process the target transaction within a preset time, and the second quantity is used to represent the number of nodes in the second cluster; and determining whether to perform circuit breaker processing on the nodes in the second cluster based on the first quantity and the second quantity.
[0098] When the processor executes the program, it also implements the following steps: after determining whether to perform circuit breaking on the nodes in the second cluster based on the first quantity and the second quantity, the method further includes: if it is determined that to perform circuit breaking on the nodes in the second cluster, the second cluster is in a circuit-breaking state; after the second cluster is in the circuit-breaking state, a plurality of second transactions are obtained, wherein the second transactions are transactions to be processed in the distributed system after the second cluster is in the circuit-breaking state; and each of the plurality of second transactions is processed by the target node.
[0099] When the processor executes the program, it also performs the following steps: after the second cluster is in the circuit breaker state, the method further includes: determining whether any one of the plurality of second transactions has been successfully processed; if it is determined that any one of the plurality of second transactions has been successfully processed, then obtaining a third quantity and a second quantity, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within the preset time; and determining whether to switch the second cluster to a non-circuit breaker state based on the third quantity and the second quantity.
[0100] When the processor executes the program, it also performs the following steps: obtaining the first quantity includes: obtaining the attribute information of each node that processes the target transaction and the time when each node receives the target transaction; determining the first quantity based on the attribute information of each node and the time when each node receives the target transaction.
[0101] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0102] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: obtaining a plurality of first transactions, wherein the first transactions are transactions to be processed in the distributed system; processing each of the plurality of first transactions to obtain a plurality of target processing results; determining, based on each of the plurality of target processing results, whether there is at least one target transaction that has failed among the plurality of first transactions; and if there is a target transaction that has failed among the plurality of first transactions, processing the target transaction through the target node.
[0103] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: the distributed system further includes a first server, and the second cluster further includes multiple first nodes, wherein the first server is used to store a first information table, the first information table is used to represent the attribute information of each first node, and if there is a failed target transaction among the multiple first transactions, before processing the target transaction through the target node, the method further includes: obtaining the first information table from the first server; and determining the target node from the multiple first nodes based on the first information table.
[0104] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: if there is a failed target transaction among the plurality of first transactions, after processing the target transaction through the target node, the method further includes: obtaining a first processing result of the target node processing the target transaction; determining whether the target transaction is successful based on the first processing result; if the target transaction fails, deleting the attribute information of the target node from the first information table to obtain a second information table; determining a second node based on the second information table, and processing the target transaction through the second node.
[0105] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: after processing the target transaction through the target node, or after processing the target transaction through the second node, the method further includes: obtaining a first quantity and a second quantity, wherein the first quantity is used to represent the number of nodes processing the target transaction within a preset time, and the second quantity is used to represent the number of nodes in the second cluster; and determining whether to perform circuit breaker processing on the nodes in the second cluster based on the first quantity and the second quantity.
[0106] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: after determining whether to perform circuit breaking processing on nodes in the second cluster based on the first quantity and the second quantity, the method further includes: if it is determined that circuit breaking processing should be performed on nodes in the second cluster, then the second cluster is in a circuit-breaking state; after the second cluster is in the circuit-breaking state, acquiring a plurality of second transactions, wherein the second transactions are transactions to be processed in the distributed system after the second cluster is in the circuit-breaking state; and processing each of the plurality of second transactions through the target node.
[0107] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: after the second cluster is in the circuit breaker state, the method further includes: determining whether any one of the plurality of second transactions has been successfully processed; if it is determined that any one of the plurality of second transactions has been successfully processed, then obtaining a third quantity and a second quantity, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within the preset time; and determining whether to switch the second cluster to a non-circuit breaker state based on the third quantity and the second quantity.
[0108] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: obtaining a first quantity includes: obtaining attribute information of each node processing the target transaction and the time when each node receives the target transaction; determining the first quantity based on the attribute information of each node and the time when each node receives the target transaction.
[0109] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0110] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0111] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0112] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0113] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0114] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0115] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0116] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0117] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0118] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for processing transactions, characterized in that, The method is applied to a target server, wherein the target server is a server in a first cluster of a distributed system, and the distributed system further includes a second cluster and a first server, wherein the second cluster includes at least a target node and multiple first nodes, and the first server is used to store a first information table, the first information table being used to represent the attribute information of each first node, and the method includes: Obtain multiple first transactions, wherein the first transactions are transactions to be processed in the distributed system; Each of the plurality of first transactions is processed separately to obtain multiple target processing results; Based on each of the multiple target processing results, determine whether there is at least one target transaction that failed among the multiple first transactions; If the target transaction fails among the plurality of first transactions, the first information table is obtained from the first server; based on the first information table, the target node is determined from the plurality of first nodes, and the target transaction is processed through the target node; Obtain the first processing result of the target node in processing the target transaction; determine whether the target transaction is successful based on the first processing result; if the target transaction fails, delete the attribute information of the target node from the first information table to obtain a second information table; determine a second node based on the second information table, and process the target transaction through the second node; wherein, the second node is a new target node; After the target transaction is processed through the target node, or after the target transaction is processed through the second node: obtain a first quantity and a second quantity, wherein the first quantity is used to represent the number of nodes that process the target transaction within a preset time, and the second quantity is used to represent the number of nodes in the second cluster; based on the first quantity and the second quantity, determine whether to perform circuit breaker processing on the nodes in the second cluster; if it is determined to perform circuit breaker processing on the nodes in the second cluster, then the second cluster is in a circuit breaker state; wherein, when the second cluster is in a circuit breaker state, the transaction sent by the client is processed through the degraded service of the target node.
2. The method according to claim 1, characterized in that, The method further includes: After the second cluster is in the circuit breaker state, multiple second transactions are obtained, wherein the second transactions are the transactions to be processed in the distributed system after the second cluster is in the circuit breaker state; Each of the plurality of second transactions is processed by the target node.
3. The method according to claim 2, characterized in that, After the second cluster is in the circuit breaker state, the method further includes: Determine whether any one of the plurality of second transactions has been successfully processed; If it is determined that any one of the plurality of second transactions has been successfully processed, then a third quantity and the second quantity are obtained, wherein the third quantity is used to represent the number of nodes that have successfully processed the second transaction within the preset time period; Based on the third quantity and the second quantity, determine whether to switch the second cluster to a non-circuit breaker state.
4. The method according to claim 1, characterized in that, Obtaining the first quantity includes: Obtain the attribute information of each node that processes the target transaction and the time when each node receives the target transaction; The first quantity is determined based on the attribute information of each node and the time when each node receives the target transaction.
5. A transaction processing apparatus, characterized in that, The device is applied in a target server, wherein the target server is a server in a first cluster of a distributed system, and the distributed system further includes a second cluster and a first server, wherein the second cluster includes at least a target node and multiple first nodes, and the first server is used to store a first information table, the first information table being used to represent the attribute information of each first node, and the device includes: The first acquisition unit is used to acquire multiple first transactions, wherein the first transactions are transactions to be processed in the distributed system; The first processing unit is used to process each of the plurality of first transactions respectively to obtain a plurality of target processing results; The first judgment unit is used to determine, based on each of the multiple target processing results, whether there is at least one target transaction that has failed among the multiple first transactions; The second processing unit is used to process the target transaction through the target node if there is a failed target transaction among the plurality of first transactions; The second acquisition unit is configured to acquire the first information table from the first server before processing the target transaction through the target node if there is a failed target transaction among the plurality of first transactions; the first determination unit is configured to determine the target node from the plurality of first nodes based on the first information table; The third acquisition unit is used to, if there is a failed target transaction among the plurality of first transactions, acquire a first processing result of the target node processing the target transaction after processing the target transaction through the target node; the second determination unit is used to determine whether the target transaction is successful based on the first processing result; the first deletion unit is used to, if the target transaction fails, delete the attribute information of the target node from the first information table to obtain a second information table; the third processing unit is used to, based on the second information table, determine a second node and process the target transaction through the second node; wherein, the second node is a new target node; The fourth acquisition unit is configured to acquire a first quantity and a second quantity after processing the target transaction through the target node or after processing the target transaction through the second node, wherein the first quantity represents the number of nodes that processed the target transaction within a preset time period, and the second quantity represents the number of nodes in the second cluster; the third determination unit is configured to determine whether to perform circuit breaker processing on the nodes in the second cluster based on the first quantity and the second quantity. The fourth processing unit is configured to determine whether to perform circuit breaking processing on the nodes in the second cluster based on the first quantity and the second quantity. If it is determined that circuit breaking processing should be performed on the nodes in the second cluster, then the second cluster is in a circuit breaking state. When the second cluster is in a circuit breaking state, the transactions sent by the client are processed through the degradation service of the target node.
6. A processor, characterized in that, The processor is used to run a program, wherein the program executes the transaction processing method according to any one of claims 1 to 4 when it runs.
7. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the transaction processing method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Intelligent transaction routing method, device and apparatus and storage medium
CN110390529A