Dynamic routing method and device, equipment, storage medium and program product
By utilizing hash algorithms and a second modulo mechanism in a distributed system to dynamically adjust routing paths, the problem of mapping relationship failure caused by changes in the number of service nodes is solved, achieving efficient and reliable request processing in online document collaborative editing scenarios.
Patent Information
- Application Number
- CN202511076728.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-01
- Publication Date
- 2025-11-04
AI Technical Summary
In online document collaborative editing scenarios, when the number of service nodes changes dynamically, the original mapping relationship between resources and instances becomes invalid, making it difficult for subsequent requests to match historical routing rules, leading to service interruptions or data inconsistencies.
When a client request is received, the resource identifier is extracted for initial route allocation. A hash algorithm is used to map the request to the first target service unit. If the first target service unit is unavailable, a second modulo operation is performed based on the number of currently available service units to reroute the request to the second target service unit, thus ensuring the normal processing of the request.
When the number of service units changes dynamically, local adjustments to routes are made to prevent global mapping failures, ensuring normal route access even when the number of nodes decreases, thereby improving system availability and data consistency.
Smart Images

Figure CN120896896A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data transmission, and particularly relates to a dynamic routing method and device, equipment, a storage medium and a program product. BACKGROUND
[0002] In online document collaborative editing and the like scenarios, message middleware is widely applied to asynchronous communication between multiple instances to guarantee the collaborative consistency of document data. In a typical architecture, each set of microservices independently deploys a message middleware instance, and routing binding of a resource ID and a service instance is implemented through a hash algorithm to ensure that the same resource ID always accesses the same microservice instance, thereby supporting the growth demand of traffic in a high concurrency scenario.
[0003] However, the number of service nodes is not fixed, and when the number of service nodes dynamically changes (such as expansion or contraction), the original mapping relationship between resources and instances will completely fail, which easily leads to the difficulty of matching historical routing rules for subsequent requests, and causes the problems of service interruption or data inconsistency. SUMMARY
[0004] The main purpose of the present application is to provide a dynamic routing method, device, equipment, a storage medium and a program product, aiming at solving the technical problem that in online document collaborative editing and the like scenarios, when the number of service nodes expands or contracts, the original mapping relationship between resources and instances fails, subsequent requests are difficult to match historical routing rules, and service interruption is caused.
[0005] To achieve the above purpose, the present application provides a dynamic routing method, which is applied to a gateway device of a distributed system, and the method comprises the following steps:
[0006] In the case of receiving a client request, extracting a resource identifier carried by the client request;
[0007] According to the resource identifier, the client request is routed and distributed to obtain an initial routing distribution value, and the initial routing distribution value is mapped to a first target service unit;
[0008] In the case that the first target service unit is in an unavailable state, the initial routing distribution value is subjected to secondary modulo operation according to the number of currently available service units to obtain a current service unit index, and the current service unit index is mapped to a second target service unit;
[0009] According to the current service unit index, the client request is routed to the second target service unit.
[0010] In an embodiment, the step of routing and distributing the client request according to the resource identifier to obtain an initial routing distribution value comprises:
[0011] convert the resource identifier into a fixed-length identifier hash value;
[0012] map the identifier hash value to each service unit of the distributed system to determine a first target service unit corresponding to the identifier hash value;
[0013] obtain a first routing path of the first target service unit;
[0014] distribute the identifier hash value and the first routing path as an initial routing allocation value.
[0015] In an embodiment, the step of performing secondary modulo operation on the initial routing allocation value according to a number of currently available service units to obtain a current service unit index in the case that the first target service unit is in an unavailable state comprises:
[0016] detect a target unit state of the first target service unit based on the routing path;
[0017] trigger a secondary modulo instruction in the case that the target unit state is an unavailable state;
[0018] determine a number of currently available service units based on the secondary modulo instruction;
[0019] perform modulo operation on the identifier hash value according to the number of currently available service units to obtain a current service unit index.
[0020] In an embodiment, the step of performing modulo operation on the identifier hash value according to the number of currently available service units to obtain a current service unit index comprises:
[0021] perform modulo operation on the identifier hash value with the number of currently available service units as a modulo number to obtain a new hash value;
[0022] map the new hash value to a currently available service unit to determine a second target service unit;
[0023] obtain a second routing path of the second target service unit;
[0024] distribute the second routing path as the current service unit index.
[0025] In an embodiment, the step of detecting a target unit state of the first target service unit based on the routing path comprises:
[0026] pull a latest routing group configuration of the gateway device at a preset time interval based on the routing path;
[0027] comparing the latest routing group configuration with the routing group in memory to determine a change of the latest routing group configuration;
[0028] determining a target unit state of the first target service unit according to the change, wherein the target unit state is an unavailable state in a case that the routing group of the first target service unit is closed.
[0029] In an embodiment, the distributed system further comprises a message middleware connected with the service unit, and the service unit is connected with the gateway device, and after the step of routing the client request to the second target service unit according to the current service unit index, the method further comprises:
[0030] determining an abnormal service unit according to the alarm signal in a case that the alarm signal uploaded on the message middleware is received;
[0031] obtaining an abnormal routing path of the abnormal service unit, and isolating the abnormal routing path;
[0032] updating a service unit state of the abnormal service unit to the unavailable state, and returning to perform the step of performing secondary modulo operation on the initial routing allocation value according to a number of currently available service units to obtain the current service unit index in a case that the first target service unit is in the unavailable state, until the client request is re-routed to a healthy service unit.
[0033] In addition, to achieve the above object, the application further provides a dynamic routing device, which is applied to a gateway device of a distributed system, and the device comprises:
[0034] a resource identification module configured to extract a resource identification carried by the client request in a case that the client request is received;
[0035] a routing allocation module configured to perform routing allocation on the client request according to the resource identification to obtain an initial routing allocation value, wherein the initial routing allocation value is mapped to a first target service unit;
[0036] a secondary modulo module configured to perform secondary modulo operation on the initial routing allocation value according to a number of currently available service units to obtain a current service unit index in a case that the first target service unit is in an unavailable state, wherein the current service unit index is mapped to a second target service unit;
[0037] a request routing module configured to route the client request to the second target service unit according to the current service unit index.
[0038] In addition, to achieve the above object, the application further provides a gateway device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the dynamic routing method.
[0039] In addition, to achieve the above object, the application further provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the dynamic routing method.
[0040] In addition, to achieve the above object, the application further provides a computer program product, which comprises a computer program, and the computer program is executed by a processor to implement the steps of the dynamic routing method.
[0041] The one or more technical solutions provided by the application have at least the following technical effects: the dynamic routing method comprises the following steps: in the case of receiving a client request, extracting a resource identifier carried by the client request; according to the resource identifier, performing routing allocation on the client request to obtain an initial routing allocation value, the initial routing allocation value is mapped to a first target service unit; in the case that the first target service unit is in an unavailable state, performing secondary modulo operation on the initial routing allocation value according to the number of currently available service units to obtain a current service unit index, the current service unit index is mapped to a second target service unit; according to the current service unit index, routing the client request to the second target service unit.
[0042] Since the application first performs initial routing allocation to obtain an initial routing allocation value in the case of receiving a client request, and then performs secondary modulo operation according to the number of currently available service units when it is detected that the first target service unit corresponding to the initial routing allocation value is unavailable, only the local routing is adjusted when the number of service units changes dynamically, which can avoid global mapping failure, ensure normal routing access when the number of nodes is reduced, and improve system availability and data consistency. BRIEF DESCRIPTION OF DRAWINGS
[0043] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the application and, together with the specification, serve to explain the principles of the application.
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0045] Figure 1 A flowchart provided by the dynamic routing method embodiment one of the present application;
[0046] Figure 2 A structural connection diagram of the distributed system in the cooperative scenario provided by the embodiment one of the present application;
[0047] Figure 3 A division diagram of the service instance provided by the embodiment one of the present application;
[0048] Figure 4 An update diagram of the routing group configuration provided by the embodiment one of the present application;
[0049] Figure 5 A whole flowchart of the dynamic routing provided by the embodiment one of the present application;
[0050] Figure 6 A flowchart provided by the dynamic routing method embodiment two of the present application;
[0051] Figure 7 An exception isolation diagram provided by the embodiment two of the present application;
[0052] Figure 8 A module structure diagram of the dynamic routing device of the embodiment of the present application;
[0053] Figure 9 A device structure diagram of the hardware running environment involved by the dynamic routing method in the embodiment of the present application.
[0054] The implementation, functional features and advantages of the present application will be further explained with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0055] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application, and are not used to limit the present application.
[0056] In order to better understand the technical solutions of the present application, the following will be described in detail in combination with the drawings of the specification and the specific embodiments.
[0057] It should be noted that the execution subject of the present embodiment can be an electronic device with routing allocation, secondary modulo and dynamic routing functions, a dynamic routing device (such as a gateway device) executing the dynamic routing method of the present application, etc., and the present embodiment does not limit this. The following will take the gateway device as an example to describe the present embodiment and each of the following embodiments.
[0058] Based on this, the embodiment one of the present application is proposed. The present embodiment provides a dynamic routing method, which is described in detail with reference to Figure 1 , Figure 1A flowchart provided by the dynamic routing method of the first embodiment of the application.
[0059] In this embodiment, the method is applied to a gateway device of a distributed system, and the dynamic routing method comprises steps S10-S40.
[0060] It should be noted that a distributed system is a system composed of multiple interconnected computing nodes (such as computers, servers, etc.), which communicate and cooperate through a network to complete specific tasks. In a distributed system, data and computing tasks are distributed across different nodes, and client requests are dispersed to servers in multiple data centers through a gateway device for processing. The gateway device is a key device in the network, which is located between different networks and plays a role in connection and conversion.
[0061] For example, to facilitate understanding of the application scenario of the dynamic routing method of this embodiment, reference is made to Figure 2 , Figure 2 A structure connection diagram of a distributed system in a collaborative scenario is provided for the first embodiment of the application. In the collaborative scenario, the distributed system is divided into multiple clusters (such as cluster 1, cluster 2, and cluster 3), each cluster contains multiple service units (such as service unit 1, service unit 2, and service unit 3, which contain multiple instances P), and each service unit is connected to an independent message middleware for reading and writing. Routing and forwarding are performed through a gateway to ensure that client requests can be correctly routed to the corresponding service unit. Specifically, as shown in Figure 3 , Figure 3 A division diagram of service instances is provided for the first embodiment of the application. Multiple smallest manageable computing containers (such as pod1, pod2, pod3, and pod4) can be deployed in the service unit, each service unit is bound to a fixed message middleware (such as message middleware 1 and message middleware 2), and each service unit is responsible for processing collaborative editing requests in a specific area, and communication between multiple instances is achieved through the message middleware.
[0062] Step S10: In the case of receiving a client request, extracting a resource identifier carried by the client request.
[0063] It should be noted that a client request is a request message sent by a client (such as a browser used by a user, a mobile application, etc.) to a server or a service unit. For example, when a user enters a website address in a browser and presses the enter key, the browser will generate a client request, which may contain the identifier of the web resource to be accessed, some identity information of the user, etc., and then send the request to the gateway device of the distributed system in the network to obtain the corresponding web content.
[0064] It can be understood that the resource identifier is a symbol for uniquely identifying a client request. The client request usually carries a resource identifier (such as a document ID), and the gateway device can accurately route to the corresponding processing unit according to the resource identifier. For example, in a web server, each web page can have a specific URL (Uniform Resource Locator) as a resource identifier, which contains the address of the server, the directory where the web page is located, and the file name, etc. When the client request carries this URL, the gateway device can find and return the corresponding web page resource according to it.
[0065] Step S20: routing and distributing the client request according to the resource identifier, to obtain an initial routing and distribution value, which is mapped to a first target service unit.
[0066] It should be noted that the initial routing and distribution value is a preliminary result obtained when routing and distributing the client request according to the resource identifier carried by the client request, and corresponds to the initially determined target service unit, i.e. the first target service unit. For example, in a distributed cloud computing system, there are multiple computing service units, and the initial routing and distribution value calculated according to the resource identifier of the client request points to one of the computing service units, which is the first target service unit and has the ability to process the business logic related to the request.
[0067] It can be understood that routing and distribution is a process in a distributed system for indicating which service unit the client request should be sent to first, and determines which service unit the client request should be sent to for processing, which can improve the transmission efficiency of the network.
[0068] In a specific implementation, when the gateway device receives a client request, it parses the client request and extracts a resource identifier such as a URL. Then, the resource identifier is input into a preset routing and distribution algorithm, such as a hash algorithm, and after hash calculation on the resource identifier, the obtained numerical value is taken as the initial routing and distribution value, which corresponds to the first target service unit in the distributed system, to determine the service unit to which the client request is initially routed.
[0069] In a feasible implementation, the step S20 of the embodiment can include the steps of: converting the resource identifier into a fixed-length identifier hash value; mapping the identifier hash value to each service unit of the distributed system to determine the first target service unit corresponding to the identifier hash value; obtaining a first routing path of the first target service unit; and taking the identifier hash value and the first routing path as the initial routing and distribution value.
[0070] It should be noted that the identification hash value is a fixed length value obtained by converting the resource identification through a hash function. The identification hash value has uniqueness, and its fixed length feature facilitates subsequent processing.
[0071] It can be understood that the first routing path refers to the path through which the client request reaches the first target service unit. In a distributed system, due to the existence of multiple service units and complex network topology, data needs to follow a specific path during transmission from the client to the target service unit. The first routing path contains information of intermediate devices such as network nodes and gateways, ensuring that the client request can accurately reach the first target service unit.
[0072] In this embodiment, in the initial routing allocation, the gateway device converts the resource identification into a fixed length identification hash value using a hash algorithm, and uses its discrete and unique characteristics to ensure that the hash values generated by different identifications have good distinguishability. Then in the distributed system, a mapping relationship between the identification hash value and each service unit is established, and the first target service unit corresponding to the identification hash value is determined through comparison or lookup operation. Then the routing table or network topology information of the system is queried to obtain the first routing path of the first target service unit. Finally, the obtained identification hash value and first routing path are combined as the initial routing allocation value, so as to accurately guide the client request to the target service unit in the subsequent process. By converting the resource identification into a hash value for service unit mapping, efficient and uniform request routing allocation can be achieved.
[0073] Step S30: In the case that the first target service unit is in an unavailable state, performing secondary modulo operation on the initial routing allocation value according to the number of currently available service units to obtain a current service unit index, the current service unit index being mapped to a second target service unit.
[0074] It should be noted that the unavailable state means that the first target service unit cannot work normally or provide services. For example, hardware failure (such as server hard disk damage, memory failure, etc.), software failure (such as service program crash, deadlock, etc.), network connection problem (such as network interruption, insufficient network bandwidth, etc.) can cause the first target service unit to be in an unavailable state, unable to receive and process client requests.
[0075] It can be understood that the number of currently available service units refers to the number of service units that can currently work normally and provide services in the distributed system. For example, in a distributed system composed of 10 service units, if 2 service units fail, the number of currently available service units is 8.
[0076] Since the initial route allocation is calculated based on 10 service units, when the first target service unit is in an unavailable state, the initial route allocation value can be recalculated by secondary modulo operation. The initial route allocation value is modulo operated by the current available service unit quantity as the divisor to readjust the route allocation, so that the client request can be routed to other available service units (i.e. the second target service unit). For example, if the initial route allocation value is 7 and the current available service unit quantity is 5, the secondary modulo operation based on 5 is used to determine a new service unit index (i.e. the current service unit index), and the service unit (i.e. the second target service unit) that should receive the client request can be accurately found through the current service unit index.
[0077] It should be understood that the second target service unit is the service unit to which the client request should be finally routed, which is determined by the secondary modulo operation and the current service unit index when the first target service unit is unavailable. It should be noted that the first and second are only used to distinguish the first target service unit and the second target service unit, and do not represent advantages or disadvantages or precedence.
[0078] In a specific implementation, if the first target service unit is in an unavailable state, the initial route allocation value can be secondary modulo operated by modulo operation (e.g. hash value % N, N is the current available service unit quantity) to uniformly distribute the client request to the target unit, so as to realize preliminary load balancing. Thus, the processing unit can be quickly located, the load can be balanced, and the overall processing efficiency can be improved.
[0079] In a feasible implementation, the step S30 can include the steps of: detecting a target unit state of the first target service unit based on the route path; triggering a secondary modulo instruction in a case where the target unit state is an unavailable state; determining a current available service unit quantity based on the secondary modulo instruction; and performing modulo operation on the identification hash value according to the current available service unit quantity to obtain a current service unit index.
[0080] It should be noted that the target unit state refers to the current running state of the first target service unit, which can be divided into an available state and an unavailable state. The available state means that the first target service unit can normally receive requests, process tasks and return results; the unavailable state means that the first target service unit cannot normally work due to various reasons such as hardware failure, software crash or network connection interruption.
[0081] Specifically, in another possible implementation, the step of detecting the target unit state of the first target service unit based on the routing path includes: pulling a latest routing group configuration of the gateway device at a preset time interval based on the routing path; comparing the latest routing group configuration with a routing group in memory to determine a change of the latest routing group configuration; and determining the target unit state of the first target service unit according to the change, wherein the target unit state is an unavailable state when a routing group of the first target service unit is closed.
[0082] It should be noted that the preset time interval is a timing time for pulling the latest routing group configuration of the gateway device, for example, every ten minutes or half an hour, and the embodiment is not limited thereto. The latest routing group configuration is the latest setting of the gateway device about the routing group, and is a collection of a series of settings about how a routing-related device (such as a router, a gateway, etc.) forwards a data packet, including a combination of network address, subnet mask, next-hop address, etc.
[0083] For example, in order to facilitate understanding of the above routing configuration updating process, reference is made to Figure 4 , Figure 4 The updating of the routing group configuration provided by the embodiment one of the application is shown in the figure. The gateway device is responsible for routing forwarding, and ensures that a client request can be correctly routed to a corresponding service unit. It is assumed that in an initial state, there are currently three routing groups (for example, routing group 1, routing group 2 and routing group 3). When the gateway closes a certain routing group (i.e., routing group 2 is abnormally closed). The timing task pulls the latest routing group configuration (for example, routing group 1 and routing group 3 are normal), and compares it with the routing group in memory, so as to determine which routing groups have been closed. Thus, the state of the routing is dynamically managed, and it is ensured that the request can be correctly routed to an available service unit.
[0084] In the embodiment, the network stability can be ensured by updating the latest routing group configuration at a timing.
[0085] It can be understood that the secondary modulo instruction is an instruction of performing a modulo operation again when it is found that the first target service unit is unavailable, and the purpose is to determine an available service unit again to process the client request.
[0086] Specifically, in another possible implementation, the step of performing modulo operation on the identification hash value according to the number of currently available service units to obtain a current service unit index includes: performing modulo operation on the identification hash value with the number of currently available service units as a modulo number to obtain a new hash value; mapping the new hash value to a currently available service unit to determine a second target service unit; and obtaining a second routing path of the second target service unit; and taking the second routing path as the current service unit index.
[0087] It should be noted that the new hash value is obtained by performing modulo operation on the identification hash value with the number of currently available service units as a modulo number, and can be used to determine the service unit to be used next. The second routing path is a data transmission route specially determined for the second target service unit, which contains network connection information, gateway information and the like from the source to the second target service unit, so as to ensure that the data can accurately reach the second target service unit. Among them, the first and the second are only distinguished, and do not represent the advantages and disadvantages between the first routing path and the second routing path.
[0088] In this embodiment, when it is found that the first target service unit is unavailable, a secondary modulo process is triggered, so that the faulty node is automatically avoided without manual intervention, and the normal processing of the client request in a complex environment is ensured.
[0089] Step S40: routing the client request to the second target service unit according to the current service unit index.
[0090] For example, in order to facilitate understanding of the above dynamic routing process, reference is made to Figure 5 , Figure 5 The overall flowchart of the dynamic routing provided by Embodiment One of the present application is shown in FIG. 1. The gateway device serves as a request entrance, and when receiving a client request, first intercepts the resource identification carried by the client request. Then, a hash calculation is performed on the resource identification to obtain a hash value, and the hash value is taken modulo 3 (for example, hash value % 3 = x) to obtain a result x. At this time, the x of the hash value can be judged according to the routing group configuration, if x = 0, the client request is routed to service unit A, if x = 1, the client request is routed to service unit C, and if x = 2, the client request is routed to service unit B. At this time, the routing group configuration (for example, routing group 1, routing group 2, routing group 3) is read through the resource identification, and the target unit state of the target service unit is detected in real time, and if it is found that service unit B is abnormal, a secondary modulo process is triggered for secondary judgment. At this time, the number of available service units is 2, and the identification hash value is recalculated with 2 as a new modulo number (for example, hash value % 2 = x), and the request is dynamically redirected to the available service unit. Through the double-layer mechanism of hash algorithm and dynamic routing adjustment, the efficiency and fault tolerance are taken into account, and the efficiency and reliability of routing allocation are improved.
[0091] In the technical solution provided in the embodiment, when the gateway device receives a client request, the gateway device parses the client request and extracts a resource identifier in the form of a URL or the like from the client request. Then, the gateway device inputs the resource identifier into a preset routing allocation algorithm, such as a hash algorithm, performs hash calculation on the resource identifier, and obtains a numerical value as an initial routing allocation value corresponding to a first target service unit in the distributed system to determine a service unit to which the client request is initially routed. If the first target service unit is in an unavailable state, the initial routing allocation value is subjected to secondary modulo operation (for example, hash value % N, N being the number of currently available service units) to uniformly route the client request to a second target service unit. Thus, efficient routing is ensured by the initial hash allocation, and the reliability of request processing is guaranteed by the secondary dynamic adjustment, so that even local failure can be handled calmly, and in the case of node reduction, large-scale routing mapping failure is avoided, thereby providing a highly available routing solution for the distributed system.
[0092] Based on the above-mentioned embodiment one of the present application, the second embodiment of the present application is proposed. In the second embodiment of the present application, the same or similar contents as the above-mentioned embodiment one can be referred to the above introduction, and will not be described hereinafter. On this basis, please refer to Figure 6 , Figure 6 The flowchart provided for the second embodiment of the dynamic routing method of the present application is shown in FIG. 4.
[0093] After the step S40 of the present example, the dynamic routing method further includes steps S51-S53:
[0094] Step S51: In the case where an alarm signal uploaded by the message middleware is received, an abnormal service unit is determined according to the alarm signal.
[0095] It should be noted that the abnormal service unit is a service unit that is faulty or does not meet the normal operation requirements in the system, for example, may be unable to normally provide services due to hardware damage, software vulnerabilities, resource depletion, or the like.
[0096] Step S52: An abnormal routing path of the abnormal service unit is obtained, and the abnormal routing path is isolated.
[0097] It should be noted that the abnormal routing path is a connection track of a series of network nodes through which data is transmitted to the abnormal service unit in the network. The abnormal routing path may be affected due to the failure of the abnormal service unit, for example, may cause data transmission failure, error, or performance degradation, or the like.
[0098] Step S53: updating the service unit state of the abnormal service unit to an unavailable state, and returning to performing the step of performing secondary modulo operation on the initial routing allocation value according to the number of currently available service units to obtain a current service unit index in the case that the first target service unit is in an unavailable state, until the client request is re-routed to a healthy service unit.
[0099] For example, in order to facilitate understanding of the above process, reference is made to Figure 2 and Figure 7 , Figure 7 The abnormal isolation diagram provided by the second embodiment of the present application. When the middleware alarm is detected (for example, message middleware 1 and 2 are normal, and message middleware 3 is faulty), the gateway device will automatically isolate the abnormal routing path of the abnormal service unit, and then intelligently schedule to real-time re-redirect the client request to a healthy node (i.e. a healthy service unit), so as to guarantee that the system quickly recovers the service in the abnormal scenario and shortens the business interruption time, and significantly improves the overall availability and fault response efficiency.
[0100] In the technical solution provided by the present embodiment, when the service unit is abnormal, the possible request may be incorrectly routed to an unavailable node, resulting in unavailable service or request timeout. The present embodiment can monitor the service state in real time, automatically exclude the abnormal service unit and redirect the request, so as to avoid service interruption and request timeout. In the online document collaboration high-concurrency scenario, it can ensure that the routing is normal when the number of nodes is reduced, and improve the system availability and data consistency.
[0101] It should be noted that the above examples are only used for understanding the present application, and do not constitute a limitation on the dynamic routing method of the present application. More forms of simple transformation based on this technical concept are within the protection scope of the present application.
[0102] The present application also provides a dynamic routing device, please refer to Figure 8 , Figure 8 The module structure diagram of the dynamic routing device of the present application embodiment; the device is applied to a gateway device of a distributed system, and the dynamic routing device comprises:
[0103] A resource identification module 801 is configured to extract a resource identification carried by a client request in the case that the client request is received;
[0104] A routing allocation module 802 is configured to perform routing allocation on the client request according to the resource identification, so as to obtain an initial routing allocation value, and the initial routing allocation value is mapped to a first target service unit;
[0105] The secondary modulo module 803 is configured to, in the case that the first target service unit is in an unavailable state, perform secondary modulo operation on the initial routing allocation value according to a current available service unit quantity, to obtain a current service unit index, the current service unit index being mapped to a second target service unit.
[0106] The request routing module 804 is configured to route the client request to the second target service unit according to the current service unit index.
[0107] As an implementation form, the routing allocation module 802 is further configured to convert the resource identifier into an identification hash value of fixed length, map the identification hash value to each service unit of the distributed system to determine a first target service unit corresponding to the identification hash value, acquire a first routing path of the first target service unit, and take the identification hash value and the first routing path as an initial routing allocation value.
[0108] As an implementation form, the secondary modulo module 803 is further configured to detect a target unit state of the first target service unit based on the routing path, trigger a secondary modulo instruction in the case that the target unit state is an unavailable state, determine a current available service unit quantity based on the secondary modulo instruction, and perform modulo operation on the identification hash value according to the current available service unit quantity to obtain a current service unit index.
[0109] As an implementation form, the secondary modulo module 803 is further configured to perform modulo operation on the identification hash value with the current available service unit quantity as a modulo number to obtain a new hash value, map the new hash value to a current available service unit to determine a second target service unit, acquire a second routing path of the second target service unit, and take the second routing path as the current service unit index.
[0110] As an implementation form, the secondary modulo module 803 is further configured to pull a latest routing group configuration of the gateway device at a preset time interval based on the routing path, compare the latest routing group configuration with a routing group in the memory to determine a change condition of the latest routing group configuration, and determine a target unit state of the first target service unit according to the change condition, wherein the target unit state is an unavailable state in the case that a routing group of the first target service unit is closed.
[0111] As an implementation form, the dynamic routing apparatus is further configured to, in a case where an alarm signal uploaded on the message middleware is received, determine an abnormal service unit according to the alarm signal; acquire an abnormal routing path of the abnormal service unit, and isolate the abnormal routing path; update a service unit state of the abnormal service unit to an unavailable state, and return to perform the operation of performing secondary modulo operation on the initial routing distribution value according to a current available service unit quantity to obtain a current service unit index until the client request is rerouted to a healthy service unit in a case where the first target service unit is in the unavailable state.
[0112] Other embodiments or specific implementations of the dynamic routing apparatus provided in the present application can refer to the above-mentioned method embodiments, and will not be described here again.
[0113] The dynamic routing apparatus provided in the present application adopts the dynamic routing method in the above-mentioned embodiments, and can solve the technical problem that in scenarios such as online document collaborative editing, when the number of service nodes is expanded or shrunk, the mapping relationship between original resources and instances is invalid, subsequent requests are difficult to match historical routing rules, and service interruption is caused. Compared with the prior art, the dynamic routing apparatus provided in the present application has the same beneficial effects as the dynamic routing method provided in the above-mentioned embodiments, and other technical features in the dynamic routing apparatus are the same as the features disclosed in the above-mentioned embodiment methods, and will not be described here again.
[0114] The present application provides a gateway device, which comprises at least one processor and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the dynamic routing method in the above-mentioned embodiment one.
[0115] The following refers to Figure 9 , Figure 9 The device structure diagram of a hardware running environment related to the dynamic routing method in the embodiments of the present application is shown, which shows a structure diagram of a gateway device suitable for implementing the embodiments of the present application. The gateway device in the embodiments of the present application can include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistant), PADs (Portable Application Description), PMPs (Portable Media Player), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 9The gateway device shown is merely an example and should not impose any limitation on the functions and use range of the embodiments of the present application.
[0116] As shown in Figure 9 The gateway device can include a processing device 1001 (for example, a central processor, a graphics processor, etc.) that can perform various appropriate actions and processes according to programs stored in a read-only memory 1002 or loaded from a storage device 1003 into a random access memory 1004. Various programs and data required for the operation of the gateway device are also stored in the random access memory 1004. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other through a bus 1005. An input / output interface 1006 is also connected to the bus. Generally, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; the storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the gateway device to communicate with other devices wirelessly or by wire to exchange data. Although the gateway device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be alternatively implemented or provided.
[0117] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program codes for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through the communication device, or installed from the storage device 1003, or installed from the read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are performed.
[0118] The gateway device provided in the present application adopts the dynamic routing method in the above-mentioned embodiments, and can solve the technical problem that when the number of service nodes is expanded or reduced in scenarios such as online document collaborative editing, the mapping relationship between original resources and instances is invalid, subsequent requests are difficult to match historical routing rules, and service is interrupted. Compared with the prior art, the gateway device provided in the present application has the same beneficial effects as the dynamic routing method provided in the above-mentioned embodiments, and other technical features in the gateway device are the same as the features disclosed in the previous embodiment method, which will not be repeated here.
[0119] It should be understood that portions of the application disclosed can be implemented in hardware, software, firmware, or combinations thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0120] The above description is merely illustrative of the application and is not intended to limit the scope of the application. Any variations and modifications that can be made by any person skilled in the art within the spirit and scope of the application are intended to be encompassed by the application. Therefore, the scope of the application should be determined by the appended claims.
[0121] The application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e., computer programs) for performing the dynamic routing method in the above embodiments.
[0122] The computer readable storage medium provided by the application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared or semiconductor system or device, or any combination thereof. More specific examples of the computer readable storage medium can include, but are not limited to, an electric connection having one or more conductive wires, a portable computer disk, a hard disk, a random access memory (RAM), a read only memory (ROM), an erasable programmable read only memory (EPROM or flash memory), an optical fiber, a portable compact disk read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the embodiments, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer readable storage medium can be transmitted by any suitable medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency) cable, etc., or any suitable combination thereof.
[0123] The above computer readable storage medium can be contained in a gateway device or can exist separately without being assembled into the gateway device.
[0124] The computer readable storage medium described above carries one or more programs, when the one or more programs are executed by the gateway device, cause the gateway device to: in a case where a client request is received, extract a resource identifier carried by the client request; according to the resource identifier, perform routing allocation on the client request to obtain an initial routing allocation value, the initial routing allocation value being mapped to a first target service unit; in a case where the first target service unit is in an unavailable state, perform secondary modulo operation on the initial routing allocation value according to a current available service unit quantity to obtain a current service unit index, the current service unit index being mapped to a second target service unit; according to the current service unit index, route the client request to the second target service unit.
[0125] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0126] The computer readable storage medium described above carries one or more programs, when the one or more programs are executed by the gateway device, cause the gateway device to: in a case where a client request is received, extract a resource identifier carried by the client request; according to the resource identifier, perform routing allocation on the client request to obtain an initial routing allocation value, the initial routing allocation value being mapped to a first target service unit; in a case where the first target service unit is in an unavailable state, perform secondary modulo operation on the initial routing allocation value according to a current available service unit quantity to obtain a current service unit index, the current service unit index being mapped to a second target service unit; according to the current service unit index, route the client request to the second target service unit.
[0127] The modules described in the embodiments of the present application can be implemented in the form of software or in the form of hardware. In some cases, the name of the module does not constitute a limitation on the module itself.
[0128] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e., a computer program) for executing the dynamic routing method described above, and can solve the technical problem that in the online document collaborative editing scenario, when the number of service nodes is expanded or reduced, the mapping relationship between the original resources and instances is invalid, subsequent requests are difficult to match historical routing rules, and service interruption occurs. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the dynamic routing method provided by the above-mentioned embodiments, and will not be repeated here.
[0129] The present application also provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the dynamic routing method as described above.
[0130] The computer program product provided by the present application can solve the technical problem that in the online document collaborative editing scenario, when the number of service nodes is expanded or reduced, the mapping relationship between the original resources and instances is invalid, subsequent requests are difficult to match historical routing rules, and service interruption occurs. Compared with the prior art, the computer program product provided by the present application has the same beneficial effects as the dynamic routing method provided by the above-mentioned embodiments, and will not be repeated here.
[0131] The above only describes some embodiments of the present application, and does not limit the protection scope of the present application, and any equivalent structural transformation made by using the content of the present application specification and drawings, or direct / indirect application in other related technical fields is included in the protection scope of the present application.
Claims
1. A dynamic routing method, characterized in that, The method is applied to a gateway device in a distributed system, and the method includes: Upon receiving a client request, extract the resource identifier carried in the client request; Based on the resource identifier, the client request is routed to obtain an initial route allocation value, which is mapped to the first target service unit; If the first target service unit is unavailable, the initial route allocation value is moduloed twice based on the number of currently available service units to obtain the current service unit index, which is mapped to the second target service unit. The client request is routed to the second target service unit based on the current service unit index.
2. The method as described in claim 1, characterized in that, The step of routing the client request according to the resource identifier to obtain an initial route allocation value includes: Convert the resource identifier into a fixed-length identifier hash value; The identifier hash value is mapped to each service unit of the distributed system to determine the first target service unit corresponding to the identifier hash value; Obtain the first routing path of the first target service unit; Use the identifier hash value and the first route path as the initial route assignment value.
3. The method as described in claim 2, characterized in that, The step of obtaining the current service unit index by performing a second modulo operation on the initial route allocation value based on the number of currently available service units when the first target service unit is unavailable includes: Based on the routing path, detect the target unit status of the first target service unit; If the target unit is in an unavailable state, a second modulo instruction is triggered. Based on the secondary modulo instruction, the number of currently available service units is determined; The current service unit index is obtained by performing a modulo operation on the identifier hash value based on the number of currently available service units.
4. The method as described in claim 3, characterized in that, The step of performing a modulo operation on the identifier hash value based on the number of currently available service units to obtain the current service unit index includes: Using the number of currently available service units as the modulo, perform a modulo operation on the identifier hash value to obtain a new hash value; Map the new hash value to the currently available service units to determine the second target service unit; Obtain the second routing path of the second target service unit; Use the second routing path as the index of the current service unit.
5. The method as described in claim 3, characterized in that, The step of detecting the target unit status of the first target service unit based on the routing path includes: Based on the routing path, the latest routing group configuration of the gateway device is retrieved at preset time intervals; The latest routing group configuration is compared with the routing group in memory to determine the changes in the latest routing group configuration; Based on the changes, the target unit status of the first target service unit is determined, wherein the target unit status is unavailable when the routing group of the first target service unit is closed.
6. The method according to any one of claims 1 to 5, characterized in that, The distributed system further includes a message middleware, which is connected to a service unit. The service unit is connected to a gateway device. After the step of routing the client request to the second target service unit according to the current service unit index, the system includes: Upon receiving an alarm signal uploaded by the message middleware, the abnormal service unit is determined based on the alarm signal; Obtain the abnormal routing path of the abnormal service unit and isolate the abnormal routing path; The service unit status of the abnormal service unit is updated to unavailable, and the process returns to the step of performing a second modulo operation on the initial route allocation value based on the number of currently available service units to obtain the current service unit index when the first target service unit is unavailable, until the client request is rerouted to a healthy service unit.
7. A dynamic routing device, characterized in that, The device is used as a gateway device in a distributed system, and the device includes: The resource identification module is used to extract the resource identifier carried in the client request when a client request is received. The routing allocation module is used to allocate routes to the client request based on the resource identifier to obtain an initial route allocation value, which is mapped to the first target service unit. The secondary modulo module is used to perform a secondary modulo operation on the initial route allocation value based on the number of currently available service units when the first target service unit is unavailable, to obtain the current service unit index, and the current service unit index is mapped to the second target service unit. The request routing module is used to route the client request to the second target service unit according to the current service unit index.
8. A gateway device, characterized in that, The gateway device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the dynamic routing method as described in any one of claims 1 to 6.
9. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the dynamic routing method as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the dynamic routing method as described in any one of claims 1 to 6.