Task execution method and device, electronic equipment and computer readable storage medium

By updating the hash ring and task allocation in a distributed system, the task execution efficiency and interruption caused by changes in the number of nodes is solved, and more efficient task allocation and execution are achieved.

CN119690624APending Publication Date: 2025-03-25MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411825182.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-11
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

In distributed systems, when the number of nodes changes, hash ring updates and task allocation processing efficiency are inefficient, which may cause task execution interruptions.

Method used

By responding to changes in the number of nodes, the hash ring is updated according to the node number and registration time, and tasks are allocated and executed according to the updated hash ring.

Benefits of technology

It accelerates the perception of the number of nodes by distributed systems, improves the accuracy and execution efficiency of task allocation, and reduces the risk of task execution interruption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690624A_ABST
    Figure CN119690624A_ABST
Patent Text Reader

Abstract

The invention provides a task execution method and device, electronic equipment and a computer readable storage medium, and the method comprises the steps: responding to the change of the number of nodes of a distributed system, updating a hash ring of the distributed system according to the node number and registration time of the changed nodes, and obtaining an updated hash ring; according to the updated Hash ring, tasks are allocated, task allocation information is obtained, and the task allocation information is used for indicating the corresponding relation between each task and the node number and registration time in the updated Hash ring; and executing the corresponding task through the changed node according to the task allocation information. According to the embodiment of the invention, the task execution efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a task execution method and device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In the related art, the task allocation of distributed systems usually adopts the consistent hashing algorithm. When the number of nodes in the distributed system changes, the hash ring is usually updated. However, the task acquisition and allocation based on the hash ring usually adopts the timed polling method, which not only affects the efficiency of task execution, but also may cause the tasks originally assigned to the offline nodes to be interrupted in a short time. Summary of the invention

[0003] The present invention provides a task execution method and device, an electronic device, and a computer-readable storage medium.

[0004] In a first aspect, the present disclosure provides a task execution method, the method comprising: in response to a change in the number of nodes in a distributed system, updating the hash ring of the distributed system according to the node numbers and registration times of the changed nodes to obtain an updated hash ring; according to the updated hash ring, assigning tasks to obtain task assignment information, the task assignment information being used to indicate the correspondence between each task and the node numbers and registration times in the updated hash ring; and according to the task assignment information, executing the corresponding tasks through the changed nodes.

[0005] In a second aspect, the present disclosure provides a task execution device, which includes: an update module, which is used to respond to a change in the number of nodes in a distributed system, and update the hash ring of the distributed system according to the node number and registration time of the changed node to obtain an updated hash ring; an allocation module, which is used to allocate tasks according to the updated hash ring to obtain task allocation information, wherein the task allocation information is used to indicate the correspondence between each task and the node number and registration time in the updated hash ring; and an execution module, which is used to execute the corresponding task through the changed node according to the task allocation information.

[0006] In a third aspect, the present disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can perform the above-mentioned task execution method.

[0007] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned task execution method when executed by a processor.

[0008] The task allocation method provided by the embodiment of the present disclosure, in response to the change in the number of nodes of the distributed system, can update the hash ring of the distributed system according to the node number and registration time of the changed node to obtain an updated hash ring; then, according to the updated hash ring, the task is allocated to obtain task allocation information, and according to the task allocation information, the corresponding task is executed by the changed node, so that after the number of nodes of the distributed system changes, the hash ring can be updated immediately, and after the hash ring is updated, the task is allocated and executed immediately according to the updated hash ring, which accelerates the distributed system's perception of the change in the number of nodes, which can not only improve the accuracy of task allocation and the efficiency of task execution, but also reduce the risk of interruption of task execution. In addition, the task execution method of the embodiment of the present application uses the node number and registration time as the node identifier, which can be applicable to the scenario where the service of the distributed system is put online by adding and deleting nodes first.

[0009] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings, in which:

[0011] Figure 1 A flowchart of a task execution method provided by an embodiment of the present disclosure;

[0012] Figure 2 A schematic diagram of a processing process of a task execution method provided by an embodiment of the present disclosure;

[0013] Figure 3 A block diagram of a task execution device provided by an embodiment of the present disclosure;

[0014] Figure 4 A block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0015] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0016] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.

[0017] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.

[0018] The terms used herein are only used to describe specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.

[0019] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined as such herein.

[0020] A distributed system is a computing system in which multiple independent computers connected through a network work together to complete a specific task. It aims to eliminate the bottleneck or central failure point of the system and improve the reliability and scalability of the system through resource sharing, parallel processing and fault tolerance.

[0021] The task allocation of distributed systems usually adopts the consistent hashing algorithm. The consistent hashing algorithm maps data to a ring space (i.e., a hash ring), and each node in the distributed system corresponds to a position on the hash ring. By dividing the positions on the hash ring, the data is distributed to different nodes.

[0022] In the related art, when the number of nodes in a distributed system changes, the hash ring is usually updated. However, the processing of task acquisition and allocation based on the hash ring usually adopts a timed polling method. That is to say, after the hash ring is updated, task acquisition and allocation usually need to wait for a certain time (for example, 5 seconds) before execution, which makes the distributed system perceive the change in the number of nodes more slowly, which not only affects the efficiency of task execution, but also may cause the execution of tasks originally assigned to the offline nodes to be interrupted in a short time.

[0023] In addition, distributed systems usually use IP (Internet Protocol) addresses as node identifiers. However, when the distributed system service is launched by adding nodes first and then deleting them, the IP address of the node may change. Therefore, using IP addresses as node identifiers is not suitable for the scenario where nodes in the distributed system are added first and then deleted.

[0024] In order to solve the above technical problems, an embodiment of the present disclosure provides a task execution method, which includes: in response to a change in the number of nodes in a distributed system, updating the hash ring of the distributed system according to the node number and registration time of the changed node to obtain an updated hash ring; according to the updated hash ring, assigning tasks to obtain task assignment information, wherein the task assignment information is used to indicate the correspondence between each task and the node number and registration time in the updated hash ring; according to the task assignment information, executing the corresponding task through the changed node.

[0025] The task execution method of the disclosed embodiment, in response to the change in the number of nodes of the distributed system, can update the hash ring of the distributed system according to the node number and registration time of the changed node to obtain an updated hash ring; then, according to the updated hash ring, the task is assigned to obtain task assignment information, and according to the task assignment information, the corresponding task is executed by the changed node, so that after the number of nodes of the distributed system changes, the hash ring can be updated immediately, and after the hash ring is updated, the task is assigned and executed immediately according to the updated hash ring, which accelerates the distributed system's perception of the change in the number of nodes, which can not only improve the accuracy of task assignment and the efficiency of task execution, but also reduce the risk of task execution interruption. In addition, the task execution method of the embodiment of the present application uses the node number and registration time as the node identifier, which can be applicable to the scenario where the services of the distributed system are put online by adding nodes first and then deleting them.

[0026] The task execution method of the embodiment of the present disclosure is applied to a distributed system, which includes multiple nodes connected through a network, and each node can be an independent computer. The task execution method of the embodiment of the present disclosure can be implemented by a processor calling a computer-readable program instruction stored in a memory.

[0027] Figure 1 A flowchart of a task execution method provided by an embodiment of the present disclosure. Figure 1 , the method comprising:

[0028] Step S11, in response to a change in the number of nodes in the distributed system, the hash ring of the distributed system is updated according to the node numbers and registration times of the changed nodes to obtain an updated hash ring.

[0029] A distributed system includes multiple nodes, each of which is used to perform tasks of the distributed system. The number of nodes in a distributed system will change as the nodes go online or offline. In response to a change in the number of nodes in a distributed system, the node number and registration time of the changed node can be obtained. In an embodiment of the present disclosure, the node number and registration time of the node are used as node identifiers. That is, a node is uniquely identified by the method of "node number + registration time". Among them, the node number refers to the number of the node in the distributed system, for example, the node number is node 1 or node 2, etc. The registration time of the node refers to the time point when the node goes online.

[0030] The node number and registration time of the changed node can be obtained from the application, service or list that maintains the node information of the distributed system (including node number, registration time, IP address and other information). For example, in the case where the distributed system uses a heartbeat table to maintain the node information, the node number and registration time of the changed node can be obtained from the heartbeat table. For another example, in the case where the distributed system uses a registration center to maintain the node information, the node number and registration time of the changed node can be obtained from the registration center. The present disclosure does not limit the maintenance method of the node information.

[0031] Then, the hash ring of the distributed system can be updated according to the node number and registration time of the changed node to obtain an updated hash ring. The number of nodes in the hash ring is consistent with the number of nodes in the distributed system. The node number and registration time of each node are saved in the hash ring. For example, assuming that the number of nodes in the distributed system is 16, then the node numbers and registration times of these 16 nodes are saved in the hash ring, that is, 16 "node numbers + registration times" are saved in the hash ring.

[0032] In some possible implementations, updating the hash ring of the distributed system may be to update some nodes in the hash ring or to reinitialize the hash ring. Those skilled in the art may set the update method of the hash ring according to actual conditions, and the present disclosure does not limit this.

[0033] Step S12, assigning tasks according to the updated hash ring to obtain task assignment information, wherein the task assignment information is used to indicate the corresponding relationship between each task and the node number and registration time in the updated hash ring.

[0034] After obtaining the updated hash ring, immediately obtain the task from the task list, and assign the task according to the updated hash ring to obtain task assignment information. The task assignment information can be used to indicate the corresponding relationship between each task and the node number and registration time in the updated hash ring.

[0035] For example, assuming that the task list includes four tasks, Task A, Task B, Task C, and Task D, the updated hash ring includes the node numbers and registration times of the two nodes, Node 1 and Node 2, where the node number and registration time of Node 1 are: Node number Dp1, registration time "2024-06-08 12:00:05", and the node number and registration time of Node 2 are: Node number Dp2, registration time "2024-06-08 12:00:14".

[0036] According to the updated hash ring, task A, task B, task C, and task D can be allocated through the consistent hashing algorithm to obtain the task allocation information: the node number and registration time corresponding to task A are: node number Dp1, registration time "2024-06-08 12:00:05"; the node number and registration time corresponding to task B are: node number Dp1, registration time "2024-06-08 12:00:05"; the node number and registration time corresponding to task C are: node number Dp2, registration time "2024-06-08 12:00:14"; the node number and registration time corresponding to task D are: node number Dp2, registration time "2024-06-08 12:00:14".

[0037] Step S13: executing the corresponding task through the changed node according to the task allocation information.

[0038] After obtaining the task allocation information, the corresponding task can be executed through the changed node according to the task allocation information. From the perspective of the task, for any task, the node number and registration time corresponding to the task can be determined from the task allocation information, and then the task can be executed through the node indicated by the node number and registration time corresponding to the task.

[0039] From the perspective of the node, for any node (referred to as this node in the following embodiments), a task can be obtained from the task allocation information, and it is judged whether the node number and registration time corresponding to the task are consistent with the node number and registration time of this node. If the node number and registration time corresponding to the task are consistent with the node number and registration time of this node, it is considered that the task is assigned to this node for execution, and this node executes the task. If the node number and registration time corresponding to the task are inconsistent with the node number and registration time of this node, it is considered that the task is assigned to other nodes for execution, and this node does not execute the task, and then the next task can be obtained from the task allocation information, and the above judgment is re-executed. In this way, it is possible to obtain the task assigned to this node from the task allocation information and execute it.

[0040] According to an embodiment of the present disclosure, in response to a change in the number of nodes in a distributed system, the hash ring of the distributed system can be updated according to the node number and registration time of the changed node to obtain an updated hash ring; then, tasks are assigned according to the updated hash ring to obtain task assignment information, and according to the task assignment information, corresponding tasks are executed by the changed node, so that the hash ring can be updated immediately after the number of nodes in the distributed system changes, and after the hash ring is updated, tasks are assigned and executed immediately according to the updated hash ring, which accelerates the distributed system's perception of changes in the number of nodes, not only improving the accuracy of task assignment and the efficiency of task execution, but also reducing the risk of task execution interruption. In addition, the task execution method of the embodiment of the present application uses the node number and registration time as the node identifier, which can be applicable to the scenario where the services of the distributed system are put online by adding and deleting nodes first.

[0041] In some possible implementations, the change in the number of nodes includes a node going online, and the method further includes: in response to detecting a first node going online, writing the node number, registration time and current heartbeat timestamp of the first node into a heartbeat table, the heartbeat table including the node number, registration time and heartbeat timestamp of the node of the distributed system, and the heartbeat timestamp is used to indicate the update time of the node's heartbeat information.

[0042] The change in the number of nodes in the distributed system includes the node going online, that is, the increase in the number of nodes. In response to detecting the first node going online, the node number, registration time and the heartbeat timestamp of the first node can be written into the heartbeat table. This process can also be called registering the first node into the heartbeat table.

[0043] Among them, the heartbeat table is used to maintain the node number, registration time, heartbeat timestamp and other information of the nodes of the distributed system (including all online nodes). For any node, its heartbeat timestamp is used to indicate the update time of the heartbeat information of the node. The node number and registration time in the heartbeat table can be used to identify the node. The heartbeat timestamp in the heartbeat table can be used to determine whether the operation of the node is normal. For example, when the heartbeat timestamp of a node has not been updated for more than a preset time (for example, 15 seconds), it can be considered that the operation of the node is abnormal, and the node offline related processing is performed. The following Table 1 exemplarily shows the heartbeat table of a distributed system:

[0044] Table 1 Heartbeat table

[0045] Node Number Registration Time Heartbeat timestamp Dp1 2024-06-08 12:00:05 2024-06-08 12:00:05 Dp3 2024-06-08 12:00:06 2024-06-08 12:00:09 Dp2 2024-06-08 12:00:10 2024-06-08 12:00:14

[0046] As shown in Table 1 above, the heartbeat table includes the node numbers, registration times and heartbeat timestamps of the three nodes, namely, node Dp1, node Dp2 and node Dp3.

[0047] In an embodiment of the present disclosure, changes in the number of nodes include nodes going online. In response to detecting the first node going online, the node number, registration time and current heartbeat timestamp of the first node are written into the heartbeat table, so that the node number, registration time and current heartbeat timestamp of the online node can be written into the heartbeat table, so that the node information can be maintained through the heartbeat table.

[0048] In some possible implementations, each node in the distributed system periodically sends heartbeat information. The heartbeat information includes the node number, registration time and the timestamp of the current heartbeat. The method further includes: in response to receiving the heartbeat information, determining the target node to be updated in the heartbeat table according to the node number and registration time in the heartbeat information; and using the heartbeat timestamp in the heartbeat information as the latest heartbeat timestamp of the target node, and updating it to the heartbeat table.

[0049] In response to receiving the heartbeat information, the node number and registration time can be obtained from the heartbeat information, and the target node whose heartbeat timestamp is to be updated in the heartbeat table is determined according to the node number and registration time. Then, the heartbeat timestamp in the heartbeat information is used as the latest heartbeat timestamp of the target node and updated to the heartbeat table.

[0050] For example, the received heartbeat information is: node number Dp1, registration time 2024-06-08 12:00:05, and current heartbeat timestamp 2024-06-08 12:00:10; according to the node number and registration time in the heartbeat information, the target node to be updated in the heartbeat table is determined to be: the node with node number Dp1 and registration time 2024-06-08 12:00:05; then the heartbeat timestamp 2024-06-08 12:00:10 in the heartbeat information is used as the latest heartbeat timestamp of the target node and updated to the heartbeat table.

[0051] In an embodiment of the present disclosure, in response to receiving heartbeat information, the target node to be updated in the heartbeat table can be determined based on the node number and registration time in the heartbeat information, and the heartbeat timestamp in the heartbeat information is used as the latest heartbeat timestamp of the target node and updated to the heartbeat table, so that when updating the heartbeat timestamp, the target node can be determined based on the node number and registration time.

[0052] In some possible implementations, the change in the number of nodes also includes a node going offline, and the method further includes: in response to the node going offline, deleting the node number, registration time and heartbeat timestamp of the offline node from the heartbeat table.

[0053] Node offline means that the node is disconnected from the distributed system, which can also be considered as the node being deleted or destroyed from the distributed system. Node offline will result in a decrease in the number of nodes. For any node in the distributed system, when the node goes offline, it can actively delete its own node number, registration time and heartbeat timestamp from the heartbeat table. For example, when node Dp1 goes offline, it can actively delete its own node number, registration time and heartbeat timestamp from the heartbeat table by executing shutdownHook.

[0054] In the embodiments of the present disclosure, when a node goes offline, it can actively delete its own node number, registration time and heartbeat timestamp from the heartbeat table, thereby accelerating the distributed system's perception of changes in the number of nodes, thereby improving the efficiency and accuracy of task allocation and task execution.

[0055] In some possible implementations, the method further includes: periodically detecting the number of combinations of node numbers and registration times in the heartbeat table; and in response to detecting a change in the number of combinations, determining that the number of nodes corresponding to the combination has changed.

[0056] The distributed system may periodically detect the number of combinations of node numbers and registration times in the heartbeat table, and the detection period may be, for example, 3 seconds, 5 seconds, etc. Those skilled in the art may set the detection period according to actual conditions, and the present disclosure does not limit this. Since the node number and registration time are used as identifiers of the nodes, when the number of combinations of node numbers and registration times is detected to have changed, it can be determined that the number of nodes has changed.

[0057] For example, assuming that the number of combinations of node numbers and registration times detected last time was 10, if the number of combinations of node numbers and registration times detected this time is also 10, it can be determined that the number of nodes has not changed; if the number of combinations of node numbers and registration times detected this time is 12, it can be determined that the number of nodes has changed and the hash ring needs to be updated.

[0058] In an embodiment of the present disclosure, it is possible to periodically detect the number of combinations of node numbers and registration times in the heartbeat table, and when a change in the number of combinations of node numbers and registration times is detected, it is determined that the number of nodes has changed, thereby being able to determine whether the number of nodes has changed by periodically detecting the number of combinations of node numbers and registration times in the heartbeat table.

[0059] In some possible implementations, the distributed system may further include a registration center, and the method may further include: detecting nodes in the distributed system through the registration center to determine whether the number of nodes has changed.

[0060] A registration center may be set up on the distributed system. When the first node that is online is detected, the first node may be registered in the registration center according to the node number and registration time of the first node. The registration center may be, for example, nacos. The present disclosure does not limit the specific type of the registration center.

[0061] During the operation of the distributed system, the nodes can be detected through the registration center. When the registration center detects the registration of a new node or the disconnection of a connected node, it can be determined that the number of nodes has changed.

[0062] In the embodiments of the present disclosure, the nodes in the distributed system are detected by a registration center to determine whether the number of nodes has changed, so that the distributed system can perceive the change in the number of nodes more timely.

[0063] Figure 2 A schematic diagram of a processing process of a task execution method provided by an embodiment of the present disclosure. Figure 2 , the process of the task execution method can be exemplified as follows:

[0064] Step 1: When it is detected that node A, node B, and node C are online, their node numbers, registration time, and the timestamp of this heartbeat are written into the heartbeat table; then a hash ring is generated according to the node numbers and registration time in the heartbeat table, and task allocation information is obtained according to the hash ring; according to the task allocation information, the task is executed by node A, node B, and node C;

[0065] Step 2: during the operation of the distributed system, periodically detecting the number of combinations of node numbers and registration times in the heartbeat table, and in response to detecting a change in the number of combinations of node numbers and registration times in the heartbeat table, determining that the number of nodes has changed;

[0066] Step 3, in response to a change in the number of nodes in the distributed system, updating the hash ring of the distributed system according to the node number and registration time of the changed node to obtain an updated hash ring;

[0067] Step 4: Allocate tasks according to the updated hash ring to obtain new task allocation information;

[0068] Step 5: According to the new task allocation information, the corresponding tasks are executed through the changed nodes.

[0069] In related technologies, the service launch of distributed systems usually adopts a rolling release method, which will cause nodes to go offline and online again in a short period of time, resulting in continuous reallocation of tasks in a short period of time, causing unstable task execution and affecting the availability of the distributed system.

[0070] For the launch of services in a distributed system, an embodiment of the present disclosure provides a method of adding nodes first and then deleting them. Based on this, the task execution method of the embodiment of the present disclosure also includes: in response to the existence of a second node to be updated, launching a third node with the same node number as the second node and assigned a service, the registration time of the third node being later than the registration time of the second node; in response to the third node being verified, taking the second node offline and updating the third node to the second node.

[0071] When the service of a distributed system goes online, each node can be updated in turn. Any node to be updated can be regarded as a second node. In response to the existence of a second node to be updated, a third node with the same node number as the second node and assigned a service can be put online. The registration time of the third node is later than the registration time of the second node. That is, the third node is a node with the same node number as the second node but a different registration time. Since the registration time of the third node is later than the registration time of the second node, the second node can be regarded as an old node, and the third node can be regarded as a new node, and the third node is used to replace the second node.

[0072] After the third node goes online, the node number, registration time and the timestamp of the heartbeat of the third node can be written into the heartbeat table. Then the third node is verified. The third node can be verified by executing a preset number of tasks. If the preset number of tasks are all executed successfully, the third node is considered to have passed the verification. Otherwise, the third node is considered to have failed the verification.

[0073] In response to the third node passing the verification, the second node can be offline, and the third node can be updated to the second node. When the second node is offline, its own node number, registration time and heartbeat timestamp can be deleted from the heartbeat table.

[0074] In response to the third node failing the verification, a rollback is performed, that is, the third node is offline. When the third node is offline, its node number, registration time and heartbeat timestamp can be deleted from the heartbeat table without affecting the normal operation of the second node.

[0075] In an embodiment of the present disclosure, in response to the existence of a second node to be updated, a third node with the same node number as the second node and assigned services is brought online, and the registration time of the third node is later than the registration time of the second node; in response to the third node being verified successfully, the second node is taken offline and the third node is updated to the second node, so that the services of the distributed system can be brought online by first adding and then deleting nodes.

[0076] In some possible implementations, when using the method of adding nodes first and then deleting them, step S11 may include: in response to the node number and registration time of the second node and the node number and registration time of the third node existing in the heartbeat table at the same time, using the node number and registration time of the third node to update the hash ring of the distributed system.

[0077] When updating the hash ring of a distributed system, it is possible to determine whether the node number and registration time of the second node and the node number and registration time of the third node exist in the heartbeat table at the same time, that is, to determine whether there are nodes with the same node number but different registration times in the heartbeat table. If so, the node number and registration time of the third node are used to update the hash ring of the distributed system. That is, when the node numbers are the same, the node number and registration time with the latest registration time are selected to update the hash ring.

[0078] For example, assume that there are four combinations of node numbers and registration times in the heartbeat table, namely: node number Dp4, registration time "2024-06-10 10:00:10"; node number Dp5, registration time "2024-06-10 10:00:25"; node number Dp6, registration time "2024-06-10 10:00:30"; node number Dp5, registration time "2024-06-1020:00:10".

[0079] When updating the hash ring, determine whether the node number and registration time of the second node and the node number and registration time of the third node exist in the heartbeat table at the same time. After determination, the node number and registration time of the second node and the node number and registration time of the third node exist in the heartbeat table at the same time. The node number and registration time of the second node are: node number Dp5, registration time "2024-06-10 10:00:25", and the node number and registration time of the third node are: node number Dp5, registration time "2024-06-10 20:00:10". The node number and registration time of the third node as the new node (node ​​number Dp5, registration time "2024-06-10 20:00:10") can be selected from the node number and registration time of the second node and the node number and registration time of the third node to update the hash ring, without using the node number and registration time of the second node as the old node.

[0080] That is to say, when the hash ring is updated, the following three node numbers and registration times are used: node number Dp4, registration time "2024-06-10 10:00:10"; node number Dp6, registration time "2024-06-10 10:00:30"; node number Dp5, registration time "2024-06-10 20:00:10".

[0081] In an embodiment of the present disclosure, in response to the simultaneous existence of the node number and registration time of the second node and the node number and registration time of the third node in the heartbeat table, the hash ring of the distributed system is updated using the node number and registration time of the third node, so that when the node is first added and then deleted, the number of nodes in the hash ring can be kept unchanged, so that the tasks of the distributed system can be executed continuously during the service launch, thereby improving the stability and availability of the distributed system during the service launch.

[0082] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.

[0083] In addition, the present disclosure also provides a task execution device, an electronic device, and a computer-readable storage medium, all of which can be used to implement any task execution method provided by the present disclosure. The corresponding technical solutions and descriptions are referred to the corresponding records in the method part and will not be repeated here.

[0084] Figure 3 A block diagram of a task execution device provided in an embodiment of the present disclosure.

[0085] Reference Figure 3 The embodiment of the present disclosure provides a task execution device, which is applied to a distributed system. The distributed system includes a plurality of nodes. The task execution device 30 includes:

[0086] An updating module 31, configured to update the hash ring of the distributed system according to the node number and registration time of the changed node in response to a change in the number of nodes of the distributed system, to obtain an updated hash ring;

[0087] An allocation module 32, configured to allocate tasks according to the updated hash ring to obtain task allocation information, wherein the task allocation information is used to indicate a corresponding relationship between each task and a node number and a registration time in the updated hash ring;

[0088] The execution module 33 is used to execute the corresponding task through the changed node according to the task allocation information.

[0089] In some possible implementations, the change in the number of nodes includes a node going online, and the device also includes: a first online module, which, in response to detecting a first node going online, writes the node number, registration time and corresponding heartbeat timestamp of the first node into a heartbeat table, the heartbeat table including the node number, registration time and heartbeat timestamp of the node of the distributed system, and the heartbeat timestamp is used to indicate the update time of the heartbeat information of the node.

[0090] In some possible implementations, the device also includes: a target node determination module, which, in response to receiving heartbeat information, determines the target node to be updated in the heartbeat table based on the node number and registration time in the heartbeat information; and a timestamp update module, which is used to update the heartbeat table using the heartbeat timestamp in the heartbeat information as the latest heartbeat timestamp of the target node.

[0091] In some possible implementations, the change in the number of nodes also includes a node going offline, and the device further includes: an offline module, which deletes the node number, registration time and heartbeat timestamp of the offline node from the heartbeat table in response to the node going offline.

[0092] In some possible implementations, the device also includes: a first detection module, used to periodically detect the number of combinations of node numbers and registration times in the heartbeat table; and a determination module, in response to detecting a change in the number of combinations, determining a change in the number of nodes corresponding to the combination.

[0093] In some possible implementations, the device also includes: a second online module, which, in response to the existence of a second node to be updated, brings online a third node that has the same node number as the second node and has been assigned a service, and a registration time of the third node is later than a registration time of the second node; and a node update module, which, in response to the third node being verified successfully, takes the second node offline and updates the third node to the second node.

[0094] In some possible implementations, the update module includes: selecting a sub-module, in response to the node number and registration time of the second node and the node number and registration time of the third node existing in the heartbeat table, using the node number and registration time of the third node to update the hash ring of the distributed system.

[0095] Each module in the above task execution device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module.

[0096] Figure 4 A block diagram of an electronic device provided in an embodiment of the present disclosure.

[0097] Reference Figure 4 An embodiment of the present disclosure provides an electronic device, which includes: at least one processor 701; at least one memory 702, and one or more I / O interfaces 703, connected between the processor 701 and the memory 702; wherein the memory 702 stores one or more computer programs that can be executed by the at least one processor 701, and the one or more computer programs are executed by the at least one processor 701 so that the at least one processor 701 can perform the above-mentioned task execution method.

[0098] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0099] The present disclosure also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the above-mentioned task execution method when executed by a processor / processing core. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.

[0100] The embodiment of the present disclosure also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned task execution method.

[0101] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).

[0102] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.

[0103] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0104] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0105] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.

[0106] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0107] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0108] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0109] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0110] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present disclosure as set forth in the appended claims.

Claims

1. A task execution method, characterized in that: The method comprises: In response to a change in the number of nodes of a distributed system, a hash ring of the distributed system is updated according to the node numbers and registration times of the changed nodes to obtain an updated hash ring; According to the updated hash ring, tasks are assigned to obtain task assignment information, where the task assignment information is used to indicate the corresponding relationship between each task and the node number and registration time in the updated hash ring; According to the task allocation information, the corresponding task is executed by the changed node.

2. The method according to claim 1, characterized in that The change in the number of nodes includes a node going online, and the method further includes: In response to detecting the first node coming online, the node number, registration time and corresponding heartbeat timestamp of the first node are written into a heartbeat table. The heartbeat table includes the node number, registration time and heartbeat timestamp of the node of the distributed system. The heartbeat timestamp is used to indicate the update time of the node's heartbeat information.

3. The method according to claim 2, characterized in that The method further comprises: In response to receiving the heartbeat information, determining the target node to be updated in the heartbeat table according to the node number and registration time in the heartbeat information; The heartbeat timestamp in the heartbeat information is used as the latest heartbeat timestamp of the target node and updated into the heartbeat table.

4. The method according to claim 2, characterized in that: The change in the number of nodes also includes a node going offline, and the method further includes: In response to a node going offline, the node number, registration time and heartbeat timestamp of the offline node are deleted from the heartbeat table.

5. The method according to claim 2, characterized in that: The method further comprises: Periodically detect the number of combinations of node numbers and registration times in the heartbeat table; In response to detecting a change in the number of the combinations, a change in the number of nodes corresponding to the combinations is determined.

6. The method according to claim 2, characterized in that The method further comprises: In response to the existence of a second node to be updated, going online a third node which has the same node number as the second node and has been assigned a service, wherein the registration time of the third node is later than the registration time of the second node; In response to the third node passing verification, the second node is taken offline, and the third node is updated to the second node.

7. The method according to claim 6, characterized in that The method of updating the hash ring of the distributed system according to the node number and registration time of the changed node to obtain an updated hash ring includes: In response to the node number and registration time of the second node and the node number and registration time of the third node existing in the heartbeat table at the same time, the hash ring of the distributed system is updated using the node number and registration time of the third node.

8. A task execution device, characterized in that: Applied to a distributed system, the distributed system includes a plurality of nodes, and the device includes: An updating module, configured to update the hash ring of the distributed system in response to a change in the number of nodes of the distributed system, according to the node numbers and registration times of the changed nodes, to obtain an updated hash ring; An allocation module, used to allocate tasks according to the updated hash ring to obtain task allocation information, wherein the task allocation information is used to indicate the corresponding relationship between each task and the node number and registration time in the updated hash ring; An execution module is used to execute the corresponding task through the changed node according to the task allocation information.

9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs that can be executed by the at least one processor, and the one or more computer programs are executed by the at least one processor to enable the at least one processor to perform the task execution method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the task execution method according to any one of claims 1 to 7.