A method and device for executing a timed snapshot task
By using a single queue and residual value judgment in scheduled snapshot tasks, the problem of simultaneous execution of scheduled snapshot tasks is solved, serial execution of tasks and performance improvement are achieved, and the complexity of queue maintenance is reduced.
Patent Information
- Application Number
- CN202210167289.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-23
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-02-23
AI Technical Summary
The existing technology is prone to problems of simultaneous execution in scheduled snapshot tasks, and maintaining multiple queues requires extra work and may lead to memory overflow.
Using a single queue solution, the relationship between the ID number of the task and the number of threads is used, and the residual value is used to determine which thread executes the task, ensuring that the same task is executed at different times, and idle threads are used to check the queue in turn to prevent repeated execution.
It achieves serial execution of the same task at different times, reduces the difficulty of queue maintenance, and improves performance.
Smart Images

Figure CN114564291B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network data storage, and in particular to a method and system for executing a timed snapshot task. Background Art
[0002] In data centers, laboratories, or local area networks of all sizes, storage devices are usually used by multiple servers or hosts at the same time. As an important disaster recovery measure, scheduled snapshots are an indispensable part, but different applications deployed on different servers and hosts have different requirements for scheduled cycles. Currently, the common practice is to use the following two solutions.
[0003] Solution 1: Build a dedicated timing server to edit the timing snapshot task. When executing the timing snapshot task, the tasks will be entered into a queue or other types of data structures in sequence, and then multi-threading or multi-process will be used to obtain the tasks from the queue in sequence for execution. This solution will lead to a problem, that is, if the timing period of the same server is less than the time when the snapshot is generated, then two snapshots will be generated at the same time.
[0004] Solution 2: Create different queues for different servers or hosts. This solution can avoid the problem of two snapshots at the same time in Solution 1, but maintaining multiple queues requires more extra work and may cause memory overflow.
[0005] Therefore, how to design a timed snapshot task that does not cause the problem of simultaneous snapshots and does not require the maintenance of additional queues is a technical problem that needs to be solved at present. Summary of the invention
[0006] In order to solve the above problems, the present invention provides a method and device for executing a timed snapshot task. Specifically, the embodiments of the present invention provide the following technical solutions:
[0007] In a first aspect, an embodiment of the present invention provides a method for executing a timed snapshot task, including:
[0008] Set the timing period of the scheduled snapshot task, and assign a self-increasing ID number to each of the scheduled snapshot tasks;
[0009] Detect all the scheduled snapshot tasks, select the scheduled snapshot tasks that hit the scheduled period and put them into the created queue;
[0010] An idle thread is selected from multiple threads to check whether there is a task in the queue, and the ID number of the task is taken out from the corresponding position of the task in the queue. According to the relationship between the ID number and the number of threads, the same task is selected to be executed by only one idle thread that meets the preset rules at a certain moment.
[0011] Further, according to the relationship between the ID number and the number of threads, selecting at a certain moment that the same task is executed by only one idle thread that complies with the rule includes:
[0012] Calculate the remainder value after dividing the ID number by the number of threads. If the remainder value is equal to the thread number of the idle thread, remove the task from the queue and execute it by the idle thread. If the remainder value is not equal to the thread number of the idle thread, put the task back to the original corresponding position and move one position to continue checking and calculating.
[0013] Furthermore, the queue is a single queue, and the idle thread is controlled to start detecting from the head task in the queue first.
[0014] Further, detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into the created queue includes:
[0015] When the timing cycle is reached, all snapshot tasks that need to be executed are placed in the queue in order, and the position of the queue is marked. Each time a task is stored, the position in the queue moves backward and the mark value increases by 1.
[0016] Further, when there are multiple free threads, the multiple free threads take turns to check and calculate the remainder value after dividing the ID number by the number of threads.
[0017] Furthermore, the timing period is an interval time period or a fixed time point.
[0018] Furthermore, all the timed snapshot tasks are detected in each interval time period, and the time period is one minute.
[0019] In a second aspect, the present invention further provides a device for executing a timed snapshot task, comprising:
[0020] A task setting module, used to set the timing period of the scheduled snapshot task and assign a self-increasing ID number to each of the scheduled snapshot tasks;
[0021] A task detection module, used to detect all the timed snapshot tasks, select the timed snapshot tasks that hit the timing period and put them into the created queue;
[0022] The task execution module is used to select an idle thread from multiple threads to check whether there is a task in the queue, and take out the ID number of the task from the corresponding position of the task in the queue. According to the relationship between the ID number and the number of threads, the same task is selected at a certain moment to be executed by only one idle thread that meets the rules.
[0023] In a third aspect, the present invention further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method for executing a timed snapshot task as described in the first aspect are implemented.
[0024] In a fourth aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for executing a timed snapshot task as described in the first aspect are implemented.
[0025] It can be seen from the above technical solution that the execution method-level device of a timed snapshot task provided by the present invention only uses a single queue to save the pending execution status of the timed task at different times, and each execution thread determines whether to take out the task for execution by comparing the task ID with its own thread number. Through this multi-task timed snapshot single-queue method, the execution of the same task at different times can be serialized to prevent simultaneous execution, and concurrent processing between different tasks ensures performance while reducing the difficulty of queue maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0027] Figure 1 A flowchart of a method for executing a timed snapshot task provided by an embodiment of the present invention.
[0028] Figure 2 A schematic diagram of task execution in a single queue provided for one embodiment of the present invention.
[0029] Figure 3 Another schematic diagram of task execution in a single queue provided by an embodiment of the present invention.
[0030] Figure 4 A schematic diagram of the structure of a device for executing a timed snapshot task provided by an embodiment of the present invention.
[0031] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0032] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.
[0033] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0034] This application proposes a multi-task timed snapshot single queue concurrent execution solution, which puts multiple timed snapshot tasks into a single queue, and decides whether to execute based on a judgment function before the thread executes the task to ensure that the problem of simultaneous snapshots will not occur and there is no need to maintain additional queues.
[0035] Figure 1 FIG. 1 is a flow chart showing a method for executing a timing snapshot task provided by an embodiment of the present invention. Figure 1 As shown, the method for executing a timed snapshot task provided by an embodiment of the present invention includes the following steps:
[0036] Step S1: Set the timing period of the timing snapshot task and generate a self-incrementing ID for each timing snapshot task.
[0037] Specifically, the timing period of the scheduled snapshot task can be set as a fixed time period or one or more fixed time points. For example, the timing period can be set to every minute, every thirty minutes, 08:00, 12:00 every day, etc. An ID number is also set for each task. The ID number is marked with increasing numbers to indicate a uniquely identified task. For example, there are a total of 4 tasks, numbered 1, 2, 3, and 4 respectively.
[0038] Timing snapshots are also known as automatic snapshots. They are snapshots that are automatically created based on a set timing policy. Users can customize the number of snapshots created, and up to 128 timing snapshots can be created for each file system. Snapshots are automatically created based on the timing policy set by the system administrator, and multiple recovery points are generated flexibly and frequently for the data on the storage device, making it easy to quickly recover data. When users have high security requirements for business system data and need to quickly recover data at a specified time point in the event of file damage or loss, they can choose to create a timing snapshot.
[0039] Step S2: Create a single queue.
[0040] Specifically, the queue is a single queue, that is, all tasks to be executed are stored in one queue. X is used to represent the queue index, X represents the position of the task in the current queue, and the initial value can be set to 0, which represents the initial position of the queue. X always points to the position of the last task in the queue.
[0041] Step S3: Check all tasks, select the tasks that hit the timing cycle and put them into the created single queue.
[0042] Specifically, all tasks are checked at intervals of one minute or five minutes, and tasks that hit the timing period are selected and put into the queue. Assume that at 14:00, among the four tasks, tasks 1 and 2 are hit and need to be executed, then tasks 1 and 2 need to be put into the queue.
[0043] For example, first put task 1 at the initial position of the queue, then add 1 to position X, that is, move one position backward, and then put task 2 into the queue, and use the current position as the new position X value. Each time a task is stored, the position in the queue moves backward and the tag value increases by 1. If there is no task that hits the timing cycle, continue to detect at the set interval time period.
[0044] Step S4, generate n threads, and number each thread from 1 to n in sequence. If the mth thread (1≤m≤n) among the n threads is idle and available, then the mth thread is used to check whether there is a task put into the queue in step S3. A virtual position Y can be created, and position Y corresponds to the changed position X, that is, Y=X is set to check whether there is a task at position Y. If so, proceed to the next step S5. If it is detected that there is no task in the queue, continue to check at intervals until there is a task in the queue. Among them, the idle thread is controlled to start checking from the head task in the queue first.
[0045] When there are multiple free threads, the multiple free threads take turns to check and calculate the remainder value after dividing the ID number by the number of threads. That is, if there are two free threads No. 1 and No. 2, thread No. 1 will check and calculate. If it is not executed by No. 1, thread No. 2 will check and calculate. If it is not executed by No. 2 either, it will move to other positions in the queue.
[0046] Step S5, when there is a task, the mth thread takes out the ID of the task from the X position of the queue corresponding to the Y position, compares the relationship between the ID number and the total number of threads n, and selects only one idle thread that meets the preset rules to execute the same task at a certain time, so as to ensure that the same task in the same queue will not be executed repeatedly at different times.
[0047] Specifically, calculate the remainder of the result after dividing the ID number by n, that is, calculate k=MOD(ID / n). If k=m, it means that the task can be executed by the mth thread. Remove the task from the queue and execute it by the mth thread, and then go to step S4 to see if there are other idle threads available to execute the task. If k≠m, it means that the task cannot be executed by the mth thread. Put the task back to Y, and Y=Y-1, that is, move the original X position to the left. If y<0, it means that the queue has been checked and no tasks to be executed are found. Then the mth idle thread repeats this step to continue checking whether there are new tasks. After each task is hit in the timing cycle, the task is assigned to the idle thread for execution by steps S5~S6.
[0048] like Figure 2 As shown, suppose there are two tasks, namely, task 1 and task 2 are hit and placed in a single queue. First, task 1 is placed at the initial position of the queue, then moved to the right, and then task 2 is placed in the queue. At this time, the X position points to task 2. If there are two threads, thread 1 and thread 0, thread 1 is busy, and thread 0 is idle and can execute tasks. Thread 0 takes task 2 from position X. Since the total number of threads is 2, the remainder of 2 is 0, which is exactly equal to the thread number. Then thread 0 takes out the queue and executes task 2. Then the X position moves left, that is, to the position of task 1. Figure 3 As shown. Assume that the positions of task 1 and task 2 in the single queue are swapped, task 2 is on the left, and task 1 is at the corresponding latest X. Similarly, if thread 0 is idle, the remainder of 1 to 2 is 1, which is not equal to thread number 0, then task 2 is checked to the left, the remainder of 2 to 2 is 0, and task 2 is taken out for execution. Since the leftmost task 2 is taken out for execution, task 1 becomes the front one.
[0049] This application sets up this multi-task timed snapshot single queue mode. Each execution thread determines whether to take out the task for execution by comparing the task ID with its own thread number. This can serialize the execution of the same task at different times to prevent simultaneous execution. At the same time, concurrent processing between different tasks ensures performance while reducing the difficulty of queue maintenance.
[0050] Corresponding to the above embodiment, another embodiment of the present invention further provides an execution device for a timed snapshot task. In this embodiment, for the contents that are the same or corresponding to the above embodiment, please refer to the above introduction and will not be repeated later.
[0051] like Figure 4 As shown, an execution device of a timed snapshot task disclosed in an embodiment of the present invention includes:
[0052] The task setting module 301 is used to set the timing period of the timing snapshot task and assign a self-increasing ID number to each of the timing snapshot tasks;
[0053] The task detection module 302 is used to detect all the timed snapshot tasks, select the timed snapshot tasks that hit the timing period and put them into the created queue;
[0054] The task execution module 303 is used to select an idle thread from multiple threads to check whether there is a task in the queue, and take out the ID number of the task from the corresponding position of the task in the queue, and select only one idle thread that meets the preset rules to execute the same task at a certain time according to the relationship between the ID number and the number of threads, so as to ensure that the same task will not be executed at different times at the same time.
[0055] Since the execution device of the timing snapshot task provided in the embodiment of the present invention can be used to execute the execution method of the timing snapshot task described in the above embodiment, its working principle and beneficial effects are similar, so they are not described in detail here. For specific contents, please refer to the introduction of the above embodiment.
[0056] Based on the same inventive concept, another embodiment of the present invention provides an electronic device, see Figure 5 , the electronic device specifically includes the following contents: a processor, a memory, a communication interface and a communication bus; wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the processor is used to call the computer program in the memory, and the processor implements all the steps of the above method when executing the computer program, for example, the processor implements the following process when executing the computer program: setting the timing period of the timed snapshot task, and assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into the created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and selecting the same task to be executed by only one idle thread that meets the preset rules at a certain moment according to the relationship between the ID number and the number of threads.
[0057] It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.
[0058] Based on the same inventive concept, another embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, all the steps of the above method are implemented. For example, when the processor executes the computer program, the following process is implemented: setting a timing period of a timed snapshot task, and assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into the created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and according to the relationship between the ID number and the number of threads, selecting the same task to be executed by only one of the idle threads that meets the preset rules at a certain moment.
[0059] It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.
[0060] Based on the same inventive concept, another embodiment of the present invention provides a computer program product, which includes a computer program. When the computer program is executed by a processor, all the steps of the above method are implemented. For example, when the processor executes the computer program, the following process is implemented: setting a timing period of a timed snapshot task, and assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into a created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and selecting, according to the relationship between the ID number and the number of threads, to execute the same task at a certain moment only by one of the idle threads that meets the preset rules.
[0061] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0062] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present invention. Those of ordinary skill in the art may understand and implement them without creative effort.
[0063] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the traffic audit method described in each embodiment or some parts of the embodiment.
[0064] In addition, in the present invention, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0065] In addition, in the present invention, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0066] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for executing a timed snapshot task, characterized in that: include: Set the timing period of the scheduled snapshot task, and assign a self-increasing ID number to each of the scheduled snapshot tasks; Detect all the scheduled snapshot tasks, select the scheduled snapshot tasks that hit the scheduled period and put them into the created queue; Selecting an idle thread from a plurality of threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and selecting, based on the relationship between the ID number and the number of threads, to execute the same task at a certain moment only by the idle thread that meets the preset rule, and selecting, based on the relationship between the ID number and the number of threads, to execute the same task at a certain moment only by the idle thread that meets the preset rule comprises: Calculate the remainder value after dividing the ID number by the number of threads. If the remainder value is equal to the thread number of the idle thread, remove the task from the queue and execute it by the idle thread. If the remainder value is not equal to the thread number of the idle thread, put the task back to the original corresponding position and move one position to continue checking and calculating.
2. The method for executing a scheduled snapshot task according to claim 1, characterized in that: The queue is a single queue, and the idle thread is controlled to start detecting from the head task in the queue first.
3. The method for executing a scheduled snapshot task according to claim 1, characterized in that: Detecting all the scheduled snapshot tasks, selecting the scheduled snapshot tasks that hit the scheduled period and putting them into the created queue includes: When the timing cycle is reached, all snapshot tasks that need to be executed are placed in the queue in sequence, and the position of the queue is marked. Each time a task is stored, the position in the queue moves backward and the mark value increases by 1.
4. The method for executing a scheduled snapshot task according to claim 2, characterized in that: When there are multiple free threads, the multiple free threads check and calculate the remainder value after dividing the ID number by the number of threads in turn.
5. The method for executing a scheduled snapshot task according to claim 1, characterized in that: The timing cycle is an interval time period or a fixed time point.
6. The method for executing a scheduled snapshot task according to claim 1, characterized in that: All the timed snapshot tasks are detected in each interval time period, and the time period is one minute.
7. A device for executing a timed snapshot task, characterized in that: The device comprises: A task setting module, used to set the timing period of the scheduled snapshot task and assign a self-increasing ID number to each of the scheduled snapshot tasks; A task detection module, used to detect all the timed snapshot tasks, select the timed snapshot tasks that hit the timing period and put them into the created queue; The task execution module is used to select an idle thread from multiple threads to check whether there is a task in the queue, and take out the ID number of the task from the corresponding position of the task in the queue, and select only one idle thread that meets the preset rules to execute the same task at a certain time according to the relationship between the ID number and the number of threads; According to the relationship between the ID number and the number of threads, selecting at a certain moment that the same task is executed by only one of the idle threads that meets the preset rules includes: Calculate the remainder value after dividing the ID number by the number of threads. If the remainder value is equal to the thread number of the idle thread, remove the task from the queue and execute it by the idle thread. If the remainder value is not equal to the thread number of the idle thread, put the task back to the original corresponding position and move one position to continue checking and calculating.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the method for executing a timed snapshot task as described in any one of claims 1 to 6 are implemented.
9. A non-transitory 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 for executing a timed snapshot task as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Thread pool unified scheduling monitoring method and system
CN111984402A
Task processing method, system and device
CN113687931A
Methods and systems for concurrently taking snapshots of a plurality of virtual machines
US20160103738A1
Mechanism for stability within automatic reserve management artificial intelligence
US20220028002A1
