Distributed cluster task management method and device, computer equipment and storage medium

By selecting the source node as the clock source in a distributed cluster and using a balanced binary tree to manage timing tasks, the problem of difficulty in time synchronization among nodes in the cluster is solved, the consistency of task execution time sequence is achieved, and the reliability and scalability of the system is improved.

CN120104360APending Publication Date: 2025-06-06INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510123071.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-26
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

The time of each node in a distributed cluster is difficult to synchronize, resulting in inconsistent task execution time order, affecting the high reliability and scalability of the system.

Method used

The source nodes in the cluster are obtained through the election module, and the source nodes are used as the clock source to send clock beats. Each node updates the system time according to the received clock beats, and manages timing tasks through balanced binary trees to ensure that each node performs target tasks synchronously.

Benefits of technology

Time synchronization of each node in the cluster is realized, ensuring the consistent time sequence of tasks execution, and improving the high reliability and scalability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120104360A_ABST
    Figure CN120104360A_ABST
Patent Text Reader

Abstract

The invention relates to a distributed cluster task management method and device, computer equipment and a storage medium. The method comprises the following steps: acquiring current nodes in a cluster, and electing a source node from the current nodes; in response to the received first clock beat sent by the source node, acquiring the local time of the source node and taking the local time as the current system time; obtaining a timed task, and setting the execution time of the timed task according to the current system time; in response to the received second clock beat sent by the source node, acquiring the local time of the current source node and updating the current system time, and taking the current system time before updating as historical system time; and determining a target period according to a time range between the updated historical system time and the current system time, and finding out the timed task of which the execution time is within the target period and taking the timed task as a target task, so that each node in the cluster synchronously executes the target task. By adopting the method, the consistency of timing services of each node in the cluster can be ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of distributed cluster technology, and in particular to a distributed cluster task management method, apparatus, computer equipment and storage medium. Background Art

[0002] Distributed storage systems connect multiple servers through the network to form a cluster to achieve high reliability, scalability and performance of data. Since the servers in the cluster are different in terms of region and model, the local time may not be the same, and the system clocks of different models may also be inconsistent, so it is difficult to synchronize the time of each node in the cluster. However, distributed clusters have high requirements for the time order of task execution. Many tasks require each node to execute strictly in the same order, so the consistency of cluster time is very important.

[0003] At present, the methods commonly used in the industry include using dedicated time calibration servers for time synchronization and using atomic clocks or satellite signals for time synchronization. Although these methods can improve time accuracy to a certain extent, they often rely on external facilities, making it difficult to fully guarantee the consistency of time for all nodes, and the implementation cost is relatively high. Summary of the invention

[0004] Based on this, it is necessary to provide a distributed cluster task management method, apparatus, computer equipment and storage medium that can enable each node in the cluster to execute tasks periodically and simultaneously in response to the above technical problems.

[0005] On the one hand, a distributed cluster task management method is provided, the method comprising:

[0006] Obtain the current nodes in the cluster, and select a source node from the current nodes;

[0007] In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time;

[0008] Obtain a scheduled task and set the execution time of the scheduled task according to the current system time;

[0009] In response to receiving the second clock beat sent by the source node, obtaining the current local time of the source node and updating the current system time, and taking the current system time before the update as the historical system time;

[0010] The target period is determined according to the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster executes the target tasks synchronously.

[0011] In one embodiment, obtaining a current node in the cluster and selecting a source node from the current node includes:

[0012] When creating a cluster, the first online node that joins the cluster is used as the source node, and the value of the source node is saved in the cluster memory;

[0013] In response to a new node joining the cluster, checking whether the value of the source node is valid;

[0014] In response to the value of the source node being invalid, a new source node is determined by re-electing the current node.

[0015] In one embodiment, in response to the value of the source node being invalid, re-electing the current node to determine a new source node includes:

[0016] In response to the value of the source node being invalid, obtaining hardware information of the current node;

[0017] Determine the priority of each node in the current node according to the hard disk information, and determine a new source node based on the priority;

[0018] In response to the hardware information of the current nodes being the same, a master node in the cluster is elected as a new source node.

[0019] In one embodiment, in response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time includes:

[0020] The source node is used as a clock source for cluster time synchronization, and the source node is used to start a periodic timer and send a clock beat to the cluster end and other nodes in the form of an event when the timer reaches a trigger time;

[0021] In response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before updating is used as the historical system time.

[0022] In one embodiment, the acquiring of the scheduled task and setting the execution time of the scheduled task according to the current system time includes:

[0023] Set up a scheduled task and specify the callback function of the scheduled task;

[0024] Set the interval time for executing the callback function next time, add the interval time and the current system time to obtain the execution time of the scheduled task, and activate the scheduled task.

[0025] In one embodiment, determining the target period according to the time range between the updated historical system time and the current system time, finding the scheduled task whose execution time is within the target period and using it as the target task, so that each node in the cluster synchronously executes the target task, includes:

[0026] Inserting the activated scheduled task into a balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task;

[0027] Subscribe to the clock beat of the source node through a publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated;

[0028] In response to receiving the second clock beat, searching the balanced binary tree for a scheduled task whose execution time is within the target period as a target task, and obtaining a callback function and an execution mode of the target task;

[0029] In response to the target task being executed in a single execution mode, after the callback function of the target task is executed, the target task is deleted from the balanced binary tree;

[0030] In response to the target task being executed in a loop, after the callback function of the target task is executed, the execution time of the target task is updated according to the current system time and the interval time of the callback function, and the target task is reinserted into the balanced binary tree.

[0031] In one embodiment, the method further comprises:

[0032] In response to a node failure in the cluster, determining whether the failed node is a source node;

[0033] In response to the faulty node being a source node, a new source node is determined by re-electing the current node.

[0034] In another aspect, a distributed cluster task management device is provided, the device comprising:

[0035] An election module, used to obtain the current nodes in the cluster and elect a source node from the current nodes;

[0036] A first updating module, configured to, in response to receiving a first clock beat sent by the source node, obtain the local time of the source node and use it as the current system time;

[0037] A setting module, used to obtain a scheduled task and set the execution time of the scheduled task according to the current system time;

[0038] A second updating module is used for obtaining the local time of the current source node and updating the current system time in response to receiving the second clock beat sent by the source node, and taking the current system time before the update as the historical system time;

[0039] The execution module is used to determine the target period according to the time range between the updated historical system time and the current system time, find out the scheduled tasks whose execution time is within the target period and use them as the target tasks, so that each node in the cluster can synchronously execute the target tasks.

[0040] In another aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are implemented:

[0041] Obtain the current nodes in the cluster, and select a source node from the current nodes;

[0042] In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time;

[0043] Obtain a scheduled task and set the execution time of the scheduled task according to the current system time;

[0044] In response to receiving the second clock beat sent by the source node, obtaining the current local time of the source node and updating the current system time, and taking the current system time before the update as the historical system time;

[0045] The target period is determined according to the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster executes the target tasks synchronously.

[0046] In another aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0047] Obtain the current nodes in the cluster, and select a source node from the current nodes;

[0048] In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time;

[0049] Obtain a scheduled task and set the execution time of the scheduled task according to the current system time;

[0050] In response to receiving the second clock beat sent by the source node, obtaining the current local time of the source node and updating the current system time, and taking the current system time before the update as the historical system time;

[0051] The target period is determined according to the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster executes the target tasks synchronously.

[0052] The above-mentioned distributed cluster task management method, device, computer equipment and storage medium select a suitable source node as the clock source for cluster time synchronization through node election, ensure that all nodes can update the current system time according to a unified time standard, and find out the expired target tasks based on the historical system time at the time of the last update and the current system time, so that each node in the cluster can be executed simultaneously at a unified time, ensuring the consistency of the timing services of each node. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 A schematic diagram of the structure of a cluster consistency transaction processing framework in one embodiment;

[0054] Figure 2 A schematic diagram of a process flow of a distributed cluster task management method in one embodiment;

[0055] Figure 3 A schematic diagram of a process of a distributed cluster task management method implemented based on a cluster time management module in one embodiment;

[0056] Figure 4 It is a structural block diagram of a distributed cluster task management device in one embodiment;

[0057] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0058] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0059] As described in the background technology, the complexity of distributed clusters doubles with the increase in the number of nodes. When executing some periodic tasks, some tasks require each node to execute simultaneously or in a certain order, so time synchronization is required between the nodes of the system. However, each node is an independent device (such as a computer or server) in physical structure, with its own time. Even if various means are used to synchronize the time of each node, in theory, the time of each node is still different, and the consistency of event execution on each node cannot be guaranteed.

[0060] Therefore, this application does not synchronize time on each node, but adopts a cluster consistency transaction processing framework based on the RAFT algorithm, and builds a time management module (UTTM) on this basis, and puts the tasks that need to be executed simultaneously or need to be strictly ordered on each node under this time management module for execution, such as Figure 1 shown.

[0061] Among them, the RAFT algorithm (Raft algorithm, consensus algorithm) is a consistency algorithm for managing replicated logs, which aims to solve the problem of data consistency between multiple nodes in a distributed system. It elects a leader to manage and coordinate log replication to ensure data consistency among all nodes.

[0062] In one embodiment, Figure 2 As shown, a distributed cluster task management method is provided, which is applied to the cluster side and includes the following steps:

[0063] Step S1, obtain the current nodes in the cluster, and select the source node from the current nodes.

[0064] It should be noted that under the cluster consistency transaction processing framework based on the RAFT algorithm, each node in the cluster needs to run the cluster-side and node-side programs at the same time. The cluster-side program is the code that all nodes must execute, while the node-side program determines whether to execute based on the node itself.

[0065] In an optional implementation, a current node in the cluster is obtained, and a source node is selected from the current node, including: when creating a cluster, the first online node that joins the cluster is used as the source node, and the value of the source node is saved in the cluster memory; in response to a new node joining the cluster, checking whether the value of the source node is valid; in response to the value of the source node being invalid, re-electing the current node to determine a new source node.

[0066] Each node can join the cluster after it is started and ready. By managing the status information of each node in the cluster, it is possible to know which nodes exist in the cluster and select a node from all nodes as the source of the clock, namely the source node (Focal Point).

[0067] Specifically, when creating a cluster, the focal point is initialized to an invalid value, indicating that no node is currently the source node. The system automatically elects the first online node to join the cluster as the source node and saves its identification information (such as node ID) in the cluster memory, so that time synchronization can be achieved after the cluster is created. Re-election of nodes when adding new nodes can ensure the reliability of time synchronization.

[0068] In an optional embodiment, in response to the value of the source node being invalid, the current node is re-elected to determine a new source node, including: in response to the value of the source node being invalid, obtaining the hardware information of the current node; determining the priority of each node in the current node according to the hard disk information, and determining a new source node based on the priority; in response to the hardware information of the current nodes being the same, electing the master node in the cluster as the new source node.

[0069] For example, the hardware information of all online nodes in the cluster can be collected, including CPU performance, memory capacity, disk I / O speed, etc. Based on the collected hardware information, the system will evaluate the priority of each node. For example, a high-performance CPU may get a higher priority, and then the node with the highest priority will be elected as the new source node. In the case of the same hardware information, the master node (or leader node) in the cluster can be elected as the source node. Based on this election rule, a node with better performance can be selected more intelligently as the new source node, which improves the accuracy of time synchronization and the overall performance of the system.

[0070] In an optional implementation, in response to a node failure in the cluster, it is determined whether the failed node is a source node; in response to the failed node being a source node, a new source node is determined by re-electing the current node.

[0071] Step S2: in response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time.

[0072] In an optional embodiment, in response to receiving the first clock beat sent by the source node, the local time of the source node is obtained and used as the current system time, including: using the source node as a clock source for cluster time synchronization, the source node is used to start a periodic timer, and when the timer reaches the trigger time, the clock beat is sent to the cluster end and other nodes in the form of an event; in response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before the update is used as the historical system time.

[0073] Specifically, the source node election process is executed on the cluster side. After the election is completed, the cluster calls the corresponding interface to notify the successfully elected source node. On the node side, the elected source node starts a periodic timer. Whenever the timer reaches the trigger time, the source node generates a clock tick in its expiration processing function and sends it to the time management module on the cluster side in the form of an event. In this way, the system time update is triggered only when the clock tick event is subscribed, so that each node in the cluster can arrange and execute tasks according to a unified timestamp. The period of the timer determines the accuracy of the cluster time management module, so that the entire cluster can maintain high-precision time synchronization.

[0074] The message processing of the time management module is based on the publish-subscribe mechanism, that is, the subscriber perceives the changes of the information by subscribing to the information of interest, and a task can also actively publish to make other subscribers perceive its changes. The variable that applies the publish-subscribe mechanism is called an object variable. In this embodiment, the source node acts as a publisher and the time management module acts as a subscriber. When the time management module receives the clock beat of the source node, it records the new system time and the old system time as local_time object variable and last_time object variable respectively.

[0075] In an optional implementation, the time interval of the timer can be adjusted dynamically. Specifically, the time interval length, redundant counter and suppression counter of the timer are initialized; the selection interval of the random time constant is determined according to the current time interval length to determine the time limit of the timer, and the task execution status of other nodes in the cluster is monitored; in response to the consistency of the acquired task execution status, the redundant counter value is increased; in response to the inconsistency of the acquired task execution status, the initialization is returned after the waiting time interval ends; when the time limit is reached, if the current value of the redundant counter is greater than the redundant constant, the suppression counter value is increased, otherwise the task execution status of the current node is sent; when the time interval ends, the redundant counter and the suppression counter values ​​are both set to 0, and the current time interval length is doubled. If the increased time interval length exceeds the maximum time interval, the maximum time interval is used as the next time interval length; if it does not exceed the maximum time interval, the increased time interval length is used as the next time interval length.

[0076] Based on the above steps, redundant counters and suppression counters are used to monitor and adjust the timer interval to ensure that the task can be triggered on time. By listening to the task execution status of other nodes in the cluster, the timer interval is dynamically adjusted according to the state consistency of each node to ensure that all nodes can execute tasks synchronously based on a unified time reference, reduce unnecessary clock beat events under low load conditions, shorten the timer interval during high load or critical tasks, and ensure that tasks can be discovered and executed in a timely manner.

[0077] Step S3, obtaining a scheduled task and setting the execution time of the scheduled task according to the current system time.

[0078] In an optional implementation, a scheduled task is obtained, and the execution time of the scheduled task is set according to the current system time, including: setting the scheduled task and specifying a callback function for the scheduled task; setting the interval time for the next execution of the callback function, adding the interval time and the current system time to obtain the execution time of the scheduled task, and activating the scheduled task.

[0079] Among them, all time-related businesses in the cluster need to register a scheduled task instance of the time management module. The content of each instance is shown in Table 1:

[0080] Table 1 Scheduled task registration example

[0081]

[0082] Specifically, when creating a new scheduled task, call the interface to register a task instance and specify a callback function. The callback function is the operation that needs to be performed after the time expires. At this time, the state of the instance is set to UTTM_STATE_INACTIVE, indicating that the task has not yet been activated. When the scheduled task needs to be executed, call the uttm_schedule() function to activate the task. At this time, the instance state of the task instance is set to UTTM_STATE_PRIMED. Assign a value to Next_time according to the interval time when the callback function needs to be executed next time, and then add Next_time and the current system time Local_time to get the first execution time of the scheduled task to update the value of Next_time. At this time, the instance state State is UTTM_STATE_ACTIVE, indicating that the scheduled task is ready to execute.

[0083] Based on the above steps, the execution time of the scheduled task is set based on the unified clock source in the cluster. There is no need to synchronize the time on each node, and the tasks on all nodes can be triggered at the same time.

[0084] Step S4, in response to receiving the second clock beat sent by the source node, the local time of the current source node is obtained and the current system time is updated, and the current system time before the update is used as the historical system time.

[0085] Step S5, determining the target period according to the time range between the updated historical system time and the current system time, finding out the scheduled tasks whose execution time is within the target period and taking them as the target tasks, so that each node in the cluster executes the target tasks synchronously.

[0086] In an optional implementation, a target period is determined based on a time range between an updated historical system time and a current system time, and a scheduled task whose execution time is within the target period is found and used as a target task, so that each node in the cluster executes the target task synchronously, including: inserting the activated scheduled task into a balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task; subscribing to the clock beat of the source node through a publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated; in response to receiving a second clock beat, finding a scheduled task whose execution time is within the target period in the balanced binary tree as a target task, and obtaining a callback function and an execution mode of the target task; in response to the execution mode of the target task being a single execution, deleting the target task from the balanced binary tree after the callback function of the target task is executed; in response to the execution mode of the target task being a loop execution, updating the execution time of the target task according to the current system time and the interval time of the callback function after the callback function of the target task is executed, and reinserting the target task into the balanced binary tree.

[0087] Specifically, when the state of the task instance becomes UTTM_STATE_ACTIVE, it is inserted into a balanced binary tree according to the value of its Next_time. A balanced binary tree is a data structure used to efficiently manage and schedule scheduled tasks. It ensures that the time complexity of search, insertion, and deletion operations is close to optimal by keeping the height of the tree as small as possible. Each node in the tree is sorted according to its Next time value, ensuring that all tasks are arranged in order according to the expected execution time. In this embodiment, the search time complexity of the balanced binary tree can be set to O(log n), where n is the number of nodes in the tree, that is, when it is necessary to find a task whose execution time falls within a certain time range, it can be completed in O(log n) time.

[0088] For example, assuming that the trigger time of the timer is set to 5ms, the source node sends a new clock beat every 5ms, and the cluster end and all nodes update local_time and last_time once. When the object variables of local_time and last_time are updated, the subscription function time_process() is triggered. This function first reads the values ​​of local_time and last_time, and then searches the balanced binary tree for instances whose Next_time values ​​fall between [last_time, local_time]. These instances are the instances that should be executed when they expire. It can be understood that the system will batch process a batch of expired scheduled tasks every 5ms to ensure that tasks on all nodes can be executed synchronously within a unified time frame.

[0089] Based on the above steps, a balanced binary tree is used to store and manage scheduled tasks, which improves the efficiency of task search. Since the time management module runs on the cluster side, all nodes in the cluster will execute it. Whenever the source node time is updated, all nodes will execute the same process because they subscribe to the time, thereby achieving synchronous execution of each node.

[0090] like Figure 3 As shown in the figure, the time management module provides the business module with a timer registration interface, applies for memory, runs the state machine, inserts the registered instance into the balanced binary tree, and converts the clock tick sent by the source node through the processing function to two object variables, local_tim and last_time. Then, every time the variable changes, it searches for the instance that meets the conditions in the balanced binary tree and calls the callback function of the instance.

[0091] It should be understood that although Figure 2-3 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-3 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0092] In one embodiment, Figure 4 As shown, a distributed cluster task management device is provided, including: an election module, a first update module, a setting module, a second update module and an execution module, wherein:

[0093] The election module is used to obtain the current node in the cluster and elect the source node from the current node;

[0094] A first updating module, configured to, in response to receiving a first clock beat sent by a source node, obtain a local time of the source node and use the local time as the current system time;

[0095] The setting module is used to obtain the scheduled tasks and set the execution time of the scheduled tasks according to the current system time;

[0096] A second updating module is used for obtaining the local time of the current source node and updating the current system time in response to receiving the second clock beat sent by the source node, and taking the current system time before the update as the historical system time;

[0097] The execution module is used to determine the target period according to the time range between the updated historical system time and the current system time, find out the scheduled tasks whose execution time is within the target period and use them as the target tasks, so that each node in the cluster can execute the target tasks synchronously.

[0098] In one embodiment, the election module is also used to, when creating a cluster, use the first online node that joins the cluster as the source node and save the value of the source node in the cluster memory; in response to a new node joining the cluster, check whether the value of the source node is valid; in response to the value of the source node being invalid, re-elect the current node to determine a new source node.

[0099] In one embodiment, the election module is also used to obtain the hardware information of the current node in response to the value of the source node being invalid; determine the priority of each node in the current node according to the hard disk information, and determine the new source node based on the priority; in response to the hardware information of the current nodes being the same, elect the master node in the cluster as the new source node.

[0100] In one embodiment, the first update module is also used to use the source node as a clock source for cluster time synchronization. The source node is used to start a periodic timer and send clock beats to the cluster end and other nodes in the form of events when the timer reaches the trigger time; in response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before the update is used as the historical system time.

[0101] In one embodiment, the setting module is also used to set the scheduled task and specify the callback function of the scheduled task; set the interval time for the next execution of the callback function, add the interval time and the current system time to obtain the execution time of the scheduled task, and activate the scheduled task.

[0102] In one embodiment, the execution module is also used to insert the activated scheduled task into the balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task; subscribe to the clock beat of the source node through the publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated; in response to receiving the second clock beat, find the scheduled task whose execution time is within the target period in the balanced binary tree as the target task, and obtain the callback function and execution mode of the target task; in response to the execution mode of the target task being a single execution, delete the target task from the balanced binary tree after the callback function of the target task is executed; in response to the execution mode of the target task being a cyclic execution, after the callback function of the target task is executed, update the execution time of the target task according to the current system time and the interval time of the callback function, and reinsert the target task into the balanced binary tree.

[0103] In one embodiment, the election module is further used to, in response to a node failure in the cluster, determine whether the failed node is a source node; in response to the failed node being a source node, re-elect the current node to determine a new source node.

[0104] For the specific definition of the distributed cluster task management device, please refer to the definition of the distributed cluster task management method above, which will not be repeated here. Each module in the above-mentioned distributed cluster task management device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0105] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store scheduled task data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a distributed cluster task management method is implemented.

[0106] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0107] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:

[0108] Get the current node in the cluster and select the source node from the current node;

[0109] In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time;

[0110] Get the scheduled task and set the execution time of the scheduled task according to the current system time;

[0111] In response to receiving the second clock beat sent by the source node, obtaining the local time of the current source node and updating the current system time, and taking the current system time before the update as the historical system time;

[0112] The target period is determined based on the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster can execute the target tasks synchronously.

[0113] In one embodiment, the processor further implements the following steps when executing the computer program: when creating a cluster, taking the first online node that joins the cluster as the source node, and saving the value of the source node in the cluster memory; in response to a new node joining the cluster, checking whether the value of the source node is valid; in response to the value of the source node being invalid, re-electing the current node to determine a new source node.

[0114] In one embodiment, the processor also implements the following steps when executing the computer program: in response to the value of the source node being invalid, obtaining the hardware information of the current node; determining the priority of each node in the current node according to the hard disk information, and determining a new source node based on the priority; in response to the hardware information of the current nodes being the same, electing the master node in the cluster as the new source node.

[0115] In one embodiment, the processor also implements the following steps when executing the computer program: using the source node as a clock source for cluster time synchronization, the source node is used to start a periodic timer, and when the timer reaches the trigger time, the clock beat is sent to the cluster end and other nodes in the form of an event; in response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before the update is used as the historical system time.

[0116] In one embodiment, when the processor executes the computer program, it also implements the following steps: setting a scheduled task and specifying a callback function for the scheduled task; setting the interval time for the next execution of the callback function, adding the interval time and the current system time to obtain the execution time of the scheduled task, and activating the scheduled task.

[0117] In one embodiment, the processor further implements the following steps when executing the computer program: inserting the activated scheduled task into a balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task; subscribing to the clock beat of the source node through a publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated; in response to receiving a second clock beat, finding a scheduled task whose execution time is within a target period in the balanced binary tree as a target task, and obtaining a callback function and an execution mode of the target task; in response to the execution mode of the target task being a single execution, deleting the target task from the balanced binary tree after the callback function of the target task is executed; in response to the execution mode of the target task being a cyclic execution, after the callback function of the target task is executed, updating the execution time of the target task according to the current system time and the interval time of the callback function, and reinserting the target task into the balanced binary tree.

[0118] In one embodiment, the processor further implements the following steps when executing the computer program: in response to a node failure in the cluster, determining whether the failed node is a source node; in response to the failed node being a source node, re-electing the current node to determine a new source node.

[0119] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0120] Get the current node in the cluster and select the source node from the current node;

[0121] In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time;

[0122] Get the scheduled task and set the execution time of the scheduled task according to the current system time;

[0123] In response to receiving the second clock beat sent by the source node, obtaining the local time of the current source node and updating the current system time, and taking the current system time before the update as the historical system time;

[0124] The target period is determined based on the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster can execute the target tasks synchronously.

[0125] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when creating a cluster, the first online node that joins the cluster is used as the source node, and the value of the source node is saved in the cluster memory; in response to a new node joining the cluster, checking whether the value of the source node is valid; in response to the value of the source node being invalid, re-electing the current node to determine a new source node.

[0126] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: in response to the value of the source node being invalid, obtaining the hardware information of the current node; determining the priority of each node in the current node according to the hard disk information, and determining a new source node based on the priority; in response to the hardware information of the current nodes being the same, electing the master node in the cluster as the new source node.

[0127] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: the source node is used as the clock source for cluster time synchronization, the source node is used to start a periodic timer, and when the timer reaches the trigger time, the clock beat is sent to the cluster end and other nodes in the form of an event; in response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before the update is used as the historical system time.

[0128] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: setting a scheduled task and specifying a callback function for the scheduled task; setting the interval time for the next execution of the callback function, adding the interval time and the current system time to obtain the execution time of the scheduled task, and activating the scheduled task.

[0129] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: inserting the activated scheduled task into a balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task; subscribing to the clock beat of the source node through a publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated; in response to receiving a second clock beat, finding a scheduled task whose execution time is within a target period in the balanced binary tree as a target task, and obtaining a callback function and an execution mode of the target task; in response to the execution mode of the target task being a single execution, deleting the target task from the balanced binary tree after the callback function of the target task is executed; in response to the execution mode of the target task being a cyclic execution, after the callback function of the target task is executed, updating the execution time of the target task according to the current system time and the interval time of the callback function, and reinserting the target task into the balanced binary tree.

[0130] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: in response to a node failure in the cluster, determining whether the failed node is a source node; in response to the failed node being a source node, re-electing the current node to determine a new source node.

[0131] In one embodiment, a computer product is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0132] Get the current node in the cluster and select the source node from the current node;

[0133] In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time;

[0134] Get the scheduled task and set the execution time of the scheduled task according to the current system time;

[0135] In response to receiving the second clock beat sent by the source node, obtaining the local time of the current source node and updating the current system time, and taking the current system time before the update as the historical system time;

[0136] The target period is determined based on the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster can execute the target tasks synchronously.

[0137] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when creating a cluster, the first online node that joins the cluster is used as the source node, and the value of the source node is saved in the cluster memory; in response to a new node joining the cluster, checking whether the value of the source node is valid; in response to the value of the source node being invalid, re-electing the current node to determine a new source node.

[0138] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: in response to the value of the source node being invalid, obtaining the hardware information of the current node; determining the priority of each node in the current node according to the hard disk information, and determining a new source node based on the priority; in response to the hardware information of the current nodes being the same, electing the master node in the cluster as the new source node.

[0139] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: the source node is used as the clock source for cluster time synchronization, the source node is used to start a periodic timer, and when the timer reaches the trigger time, the clock beat is sent to the cluster end and other nodes in the form of an event; in response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before the update is used as the historical system time.

[0140] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: setting a scheduled task and specifying a callback function for the scheduled task; setting the interval time for the next execution of the callback function, adding the interval time and the current system time to obtain the execution time of the scheduled task, and activating the scheduled task.

[0141] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: inserting the activated scheduled task into a balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task; subscribing to the clock beat of the source node through a publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated; in response to receiving a second clock beat, finding a scheduled task whose execution time is within a target period in the balanced binary tree as a target task, and obtaining a callback function and an execution mode of the target task; in response to the execution mode of the target task being a single execution, deleting the target task from the balanced binary tree after the callback function of the target task is executed; in response to the execution mode of the target task being a cyclic execution, after the callback function of the target task is executed, updating the execution time of the target task according to the current system time and the interval time of the callback function, and reinserting the target task into the balanced binary tree.

[0142] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: in response to a node failure in the cluster, determining whether the failed node is a source node; in response to the failed node being a source node, re-electing the current node to determine a new source node.

[0143] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0144] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0145] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A distributed cluster task management method, characterized in that: include: Obtain the current node in the cluster, and select a source node from the current node; In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time; Obtain a scheduled task and set the execution time of the scheduled task according to the current system time; In response to receiving the second clock beat sent by the source node, obtaining the current local time of the source node and updating the current system time, and taking the current system time before the update as the historical system time; The target period is determined according to the time range between the updated historical system time and the current system time, and the scheduled tasks whose execution time is within the target period are found and used as the target tasks, so that each node in the cluster executes the target tasks synchronously.

2. The distributed cluster task management method according to claim 1, characterized in that: The obtaining of the current node in the cluster and selecting the source node from the current node includes: When creating a cluster, the first online node that joins the cluster is used as the source node, and the value of the source node is saved in the cluster memory; In response to a new node joining the cluster, checking whether the value of the source node is valid; In response to the value of the source node being invalid, a new source node is determined by re-electing the current node.

3. The distributed cluster task management method according to claim 2, characterized in that: In response to the value of the source node being invalid, re-electing the current node to determine a new source node includes: In response to the value of the source node being invalid, obtaining hardware information of the current node; Determine the priority of each node in the current node according to the hard disk information, and determine a new source node based on the priority; In response to the hardware information of the current nodes being the same, a master node in the cluster is elected as a new source node.

4. The distributed cluster task management method according to claim 1, characterized in that: In response to receiving the first clock beat sent by the source node, obtaining the local time of the source node and using it as the current system time includes: The source node is used as a clock source for cluster time synchronization, and the source node is used to start a periodic timer and send a clock beat to the cluster end and other nodes in the form of an event when the timer reaches a trigger time; In response to receiving the first clock beat, the local time of the source node is recorded as the current system time, and the current system time before updating is used as the historical system time.

5. The distributed cluster task management method according to claim 1, characterized in that: The acquiring of the scheduled task and setting the execution time of the scheduled task according to the current system time includes: Set up a scheduled task and specify the callback function of the scheduled task; Set the interval time for executing the callback function next time, add the interval time and the current system time to obtain the execution time of the scheduled task, and activate the scheduled task.

6. The distributed cluster task management method according to claim 5, characterized in that: The step of determining a target period according to a time range between the updated historical system time and the current system time, finding a scheduled task whose execution time is within the target period and taking it as a target task, so that each node in the cluster synchronously executes the target task, includes: Inserting the activated scheduled task into a balanced binary tree, wherein the position of the scheduled task in the balanced binary tree is determined according to the execution time of the scheduled task; Subscribe to the clock beat of the source node through a publish-subscribe mechanism to monitor whether the current system time and the historical system time are updated; In response to receiving the second clock beat, searching the balanced binary tree for a scheduled task whose execution time is within the target period as a target task, and obtaining a callback function and an execution mode of the target task; In response to the target task being executed in a single execution mode, after the callback function of the target task is executed, the target task is deleted from the balanced binary tree; In response to the target task being executed in a loop, after the callback function of the target task is executed, the execution time of the target task is updated according to the current system time and the interval time of the callback function, and the target task is reinserted into the balanced binary tree.

7. The distributed cluster task management method according to claim 1, characterized in that: The method further comprises: In response to a node failure in the cluster, determining whether the failed node is a source node; In response to the faulty node being a source node, a new source node is determined by re-electing the current node.

8. A distributed cluster task management device, characterized in that: The device comprises: An election module, used to obtain the current nodes in the cluster and elect a source node from the current nodes; A first updating module, configured to, in response to receiving a first clock beat sent by the source node, obtain the local time of the source node and use it as the current system time; A setting module, used to obtain a scheduled task and set the execution time of the scheduled task according to the current system time; A second updating module is used for obtaining the local time of the current source node and updating the current system time in response to receiving the second clock beat sent by the source node, and taking the current system time before the update as the historical system time; The execution module is used to determine the target period according to the time range between the updated historical system time and the current system time, find out the scheduled tasks whose execution time is within the target period and use them as the target tasks, so that each node in the cluster can synchronously execute the target tasks.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

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 steps of the method according to any one of claims 1 to 7 are implemented.