A task executor switching method and device, electronic equipment and storage medium
By detecting and determining the switching conditions and information of the task executor, the timeliness and integrity issues of scheduled tasks switching in the primary and backup application service architecture are resolved, enabling smooth task switching between primary and backup servers and improving the system's reliability and real-time performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- AGRICULTURAL BANK OF CHINA
- Filing Date
- 2023-02-28
- Publication Date
- 2026-07-31
AI Technical Summary
In the core business systems of the financial industry, when scheduled tasks switch between primary and backup application service architectures, task processing may be untimely, missed, or duplicated, affecting system reliability and real-time performance.
By detecting the switching conditions of the task executor, the switching field information is determined, including the execution mode, switching mode and task identifier. Based on this information, the target executor and switching mode of the task to be executed are determined, and the task is switched from the current executor to the target executor, ensuring a smooth task switching in the primary and backup service architecture system.
It enables timely processing of tasks during primary/standby server switching, avoiding omissions or duplications, improving system reliability and real-time performance, and ensuring data integrity of scheduled tasks during the switching process.
Smart Images

Figure CN116225652B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for switching task executors. Background Technology
[0002] The core business systems of the financial industry perform functions such as sending and receiving messages, scheduled capital injections, and synchronizing data with related systems through scheduled tasks. To improve the availability of information systems, system application services are often deployed on multiple application servers, forming a primary and backup application service architecture. These services perform certain business processes through scheduled tasks, and each scheduled task must be executed on only one of the primary or backup application service servers at any given time. Duplicate capital injections or missed message processing can lead to serious consequences.
[0003] Therefore, reliability and real-time performance are particularly important for core business systems. When switching servers between primary and backup servers, how to handle the switching of scheduled tasks, and how to switch the execution of scheduled tasks from one server to another, to ensure that scheduled tasks process business in a timely manner, without omissions or duplication, is a technical problem that urgently needs to be solved. Summary of the Invention
[0004] This invention provides a method, apparatus, electronic device, and storage medium for switching task executors, so as to realize the switching of execution servers for scheduled tasks.
[0005] According to one aspect of the present invention, a method for switching task executors is provided, comprising:
[0006] When the switching conditions for the task executor are met, the switching field information corresponding to the executor switching instruction is determined; wherein, the switching field information includes an execution mode field, a switching mode field, and a task identifier field;
[0007] Based on the switching field information, the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed, are determined; wherein, the switching mode is determined based on the switching mode field;
[0008] Based on the switching mode, the current executor of the task to be executed is switched to the target executor, so that the target executor executes the task to be executed. The executor and the target executor are servers in the master-slave service architecture system.
[0009] According to another aspect of the present invention, a switching device for a task executor is provided, comprising:
[0010] The field information determination module is used to determine the switching field information corresponding to the switching instruction of the task executor when the switching conditions of the task executor are detected to be met; wherein, the switching field information includes an execution mode field, a switching mode field, and a task identifier field;
[0011] A switching mode determination module is used to determine, based on the switching field information, the task to be executed corresponding to the executor switching instruction, the target executor of the task to be executed, and the switching mode; wherein, the switching mode is determined based on the switching mode field.
[0012] The pending task switching module switches the current executor of the pending task to the target executor based on the switching mode, so that the target executor executes the pending task. The executor and the target executor are servers in the master-slave service architecture system.
[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0014] At least one processor; and
[0015] A memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the task executor switching method according to any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the task executor switching method described in any embodiment of the present invention.
[0018] The technical solution of this invention, when detecting that the switching conditions for the task executor are met, determines the switching field information corresponding to the executor switching instruction; based on the switching field information, it determines the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed; based on the switching mode, it switches the current executor of the task to be executed to the target executor, so that the target executor after the switch executes the task to be executed. The executor and the target executor are servers in a primary / backup service architecture system. The technical solution of this invention solves the problem that when the target switches between primary and backup servers, the tasks on the server cannot be switched simultaneously, leading to untimely, missed, or duplicate task processing, and realizes the switching of the task executor from one server to another.
[0019] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 A flowchart of a task executor switching method provided in Embodiment 1 of the present invention;
[0022] Figure 2 This is an architecture diagram of a task executor switching method provided in Embodiment 2 of the present invention;
[0023] Figure 3 This is a flowchart illustrating the processing flow of the Kafka messaging system provided in Embodiment 2 of the present invention.
[0024] Figure 4 This is a flowchart of a consumer consuming messages during the processing of a Kafka message system, provided in Embodiment 2 of the present invention.
[0025] Figure 5 This is a schematic diagram of the structure of a task executor switching device provided in Embodiment 3 of the present invention;
[0026] Figure 6 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. Detailed Implementation
[0027] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0029] Example 1
[0030] Figure 1 This is a flowchart of a task executor switching method provided in Embodiment 1 of the present invention. This embodiment is applicable to a primary / backup application service architecture, where, during primary / backup server switching, it is necessary to switch tasks from one server to another. This method can be executed by a device, which can be implemented in hardware and / or software and can be configured in the server. Figure 1 As shown, the method includes:
[0031] S110. When the switching conditions of the task executor are met, determine the switching field information corresponding to the executor switching instruction.
[0032] In this context, the task executor can be understood as the server used to execute tasks in a primary / backup application service architecture. In a primary / backup application service architecture, sometimes it is necessary to switch between primary and backup servers, which means that the task executor needs to be switched. The executor switching command is used to control the primary / backup application service architecture to switch a task on one server to another server, and execute the task through the other server. The corresponding switching field information refers to the field values of each field contained in the executor switching command.
[0033] Specifically, when the switching conditions for the task executor are met, a corresponding executor switching instruction can be generated. This instruction can be automatically generated or sent by operations personnel; for example, when a primary / standby application service architecture is detected to be preparing for a primary / standby server switch, a corresponding switching instruction can be automatically generated to instruct the unexecuted tasks to be switched from one server to another. Furthermore, the corresponding switching field information is determined based on the executor switching instruction.
[0034] Based on the above technical solution, the step of receiving an execution party switching instruction and determining the switching field information corresponding to the execution party switching instruction when the switching conditions of the task execution party are detected includes: when the execution party switching instruction is received, storing the execution party switching instruction in the form of a log file in the message processing system; and parsing the execution party switching instruction in the log file based on the message processing system to obtain the switching field information.
[0035] In this context, the message processing system refers to a system specifically designed for storing and processing executor switching instructions; for example, a Kafka messaging system. After receiving an executor switching instruction, it can be stored in the message processing system for further processing.
[0036] In this embodiment, each time the message processing system receives an executor switching instruction, it appends the instruction to the end of the log file in the message processing system. Each instruction has its own corresponding offset, thereby achieving data persistence. The message processing system can parse the executor switching instruction to determine the field information contained in the instruction, that is, the switching field information.
[0037] S120. Based on the switching field information, determine the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed.
[0038] The task to be executed can be a scheduled task, which means that the executor of the task to be executed needs to be switched. The target executor refers to the server that will execute the task to be executed after the switch. The switching mode refers to the switching mode of the executor.
[0039] Specifically, the switching field information can determine the task to be executed corresponding to that field information, that is, determine which task's executor needs to be switched, as well as the switching mode and which server to switch the executor of the task to be executed to.
[0040] Based on the above technical solution, the step of determining the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed, based on the switching field information, includes: determining the task to be executed corresponding to the executor switching instruction based on the field information of the task identifier field; determining the target executor corresponding to the task to be executed based on the field information of the execution mode field; and determining the switching mode corresponding to the task to be executed based on the field information of the switching mode field.
[0041] The switching modes include partial switching mode and full switching mode. Partial switching refers to switching the executor of the task to be executed corresponding to a specific executor switching instruction, for example, switching the executor of task A. Full switching refers to switching the executor of the tasks to be executed corresponding to all executor switching instructions.
[0042] Specifically, the task identifier field in the executor switching command can be parsed to determine the field information. Based on this field information, it can be determined which executor of the task to be switched. The switching mode field in the executor switching command can be parsed to determine the method of switching the executor. The execution mode field in the executor switching command can also be parsed to determine the target executor, that is, the server that will execute the task after the switch.
[0043] S130. Based on the switching mode, the current executor of the task to be executed is switched to the target executor, so that the target executor after the switch can execute the task to be executed. The executor and the target executor are servers in the master-slave service architecture system.
[0044] Specifically, after determining the switching mode, the current executor of the task to be executed can be switched to the target executor according to the switching mode. This switches the task to be executed from one server to another so that the target executor can process the task. This achieves the switching of the task to be executed simultaneously after the primary and backup servers are switched, and the task to be executed will not be lost due to the switching of the primary server.
[0045] Based on the above technical solution, determining the target executor corresponding to the task to be executed based on the field information of the execution mode field includes: if the field information of the execution mode field is consistent with the first mode field information, then the master server in the master-slave service architecture system is determined as the current executor, and the backup server is determined as the target executor; if the field information of the execution mode field is consistent with the second mode field information, then the backup server in the master-slave service architecture system is determined as the current executor, and the master server is determined as the target executor.
[0046] The primary / backup service architecture system includes a primary server and a backup server. The first mode field information indicates that the task to be executed is to be performed on the backup server, and the second mode field information indicates that the task to be executed is to be performed on the primary server.
[0047] Specifically, if the field information of the execution mode matches the field information of the first mode, then the primary server is determined as the current executor, and the backup server is determined as the target executor. If the field information of the execution mode matches the field information of the second mode, then the backup server is determined as the current executor, and the primary server is determined as the target executor. Of course, the above is only an example of execution modes and is not limited to the above modes. Other possible modes include: first stopping all or part of the scheduled tasks on the primary application service, and then starting all or part of the scheduled tasks on the backup application service; or first stopping all or part of the scheduled tasks on the backup application service, and then starting all or part of the scheduled tasks on the primary application service; or starting all or part of the scheduled tasks on the primary application service; or stopping all or part of the scheduled tasks on the primary application service; or starting all or part of the scheduled tasks on the backup application service; or stopping all or part of the scheduled tasks on the backup application service.
[0048] Based on the above technical solution, the step of switching the current executor of the task to be executed to the target executor based on the switching mode includes: if the switching mode is a full switching mode, then the current executor of each task to be executed received within a preset time period is switched to the target executor; if the switching mode is a partial switching mode, then the current executor of the task to be executed corresponding to the task identifier field is switched to the target executor.
[0049] The preset time can be a pre-defined time period. Correspondingly, if the switching mode is full switching, the executor of all tasks received within the preset time period will be switched from the current executor to the target executor. If the switching mode is partial switching, the specific executor of the task to be switched needs to be determined based on the task identifier field, and then the executor of that task will be switched. The advantage of this is that it allows for different switching methods, improving the accuracy and efficiency of the switching process.
[0050] Based on the above technical solution, the step of switching the current executor of the task to be executed to the target executor based on the switching mode, so that the target executor executes the task to be executed, includes: controlling the current executor to stop processing the task to be executed, and processing the task to be executed based on the target executor.
[0051] Specifically, during the switching process, the current executor can be controlled to stop processing the pending tasks. For example, the pending tasks can be deleted from the current executor's system. This can prevent the repeated execution of the pending tasks and ensure that the target executor executes the pending tasks.
[0052] Based on the above technical solution, the method further includes: determining the execution status information corresponding to the executor switching instruction based on the log file in the message processing system, and synchronizing the execution status information to each server in the primary and backup service architecture system.
[0053] Understandably, if a data recovery requirement arises between the primary and backup services, logs for the corresponding time period can be extracted from the database logs based on the records in the log file to perform data recovery, thus mitigating the risk of data loss that may occur during scheduled task execution when switching between primary and backup application services. By extracting scheduled task instructions and their timestamps from the log file corresponding to the Kafka messaging system, and combining this with the actual execution status of scheduled tasks in the primary and backup databases, the execution status of scheduled tasks can be monitored.
[0054] The technical solution of this invention, when detecting that the switching conditions for the task executor are met, determines the switching field information corresponding to the executor switching instruction; based on the switching field information, it determines the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed; based on the switching mode, it switches the current executor of the task to be executed to the target executor, so that the target executor after the switch executes the task to be executed. The executor and the target executor are servers in a primary / backup service architecture system. The technical solution of this invention solves the problem that when the target switches between primary and backup servers, the tasks on the server cannot be switched simultaneously, leading to untimely, missed, or duplicate task processing, and realizes the switching of the task executor from one server to another.
[0055] Example 2
[0056] Figure 2 This is an architectural diagram of a task executor switching method provided in Embodiment 2 of the present invention. This embodiment is a preferred embodiment of the above embodiments, and its specific implementation can be found in the technical solution of this embodiment. Technical terms that are the same as or corresponding to those in the above embodiments will not be repeated here.
[0057] The technical solution of this invention involves three parts:
[0058] 1) The overall architecture and workflow of the Quartz scheduled task scheduling method based on Kafka master and standby application services provide ordered and asynchronous processing of scheduled task message events between master and standby application services. It avoids the risk of data loss that may occur during scheduled task execution when master and standby application services switch through data persistence. It also monitors the scheduling and execution of scheduled tasks between master and standby application services.
[0059] 2) Interface layer design for Kafka message system to handle scheduled tasks;
[0060] 3) The process of consumers executing Quartz scheduled tasks in the Kafka messaging system allows for independent modification or extension of the scheduling method of Quartz scheduled tasks between primary and backup application services.
[0061] Overall architecture and workflow of embodiments of the present invention
[0062] This invention provides a Quartz scheduled task method for primary and secondary application services based on Kafka, which provides ordered and asynchronous processing of scheduled task message events between primary and secondary application services. The overall architecture is as follows: Figure 2 As shown.
[0063] Among them, the Consumer is an application service deployed on the primary and backup machines. The system's operations and maintenance personnel can send two types of commands:
[0064] The first type of instruction is a complete switchover of primary and standby services. This instruction is first sent by the system's operations and maintenance personnel to the application service, which then sends a complete switchover instruction for the scheduled tasks to the Kafka messaging system. This instruction can be considered as a producer-sent instruction, which is consumed by the consumer to achieve a complete switchover of Quartz scheduled tasks between the primary and standby application services. The primary / standby application service switchover can be achieved through methods such as updating the system's domain name resolution address. The complete switchover of Quartz scheduled tasks can be achieved through the Quartz open-source component's scheduled task scheduler interfaces, such as `schedulerFactoryBean.start()` and `schedulerFactoryBean.stop()`. After the instruction is sent to the Kafka messaging system, both can be executed simultaneously, thus achieving asynchronous processing.
[0065] The second type of instruction is a partial switching of scheduled tasks. This instruction is sent directly to the Kafka messaging system by the system's operations and maintenance personnel. This instruction can be directly regarded as an instruction sent by the producer, and the consumer consumes this instruction to achieve partial switching of Quartz scheduled tasks between the primary and backup application services. Partial switching of Quartz scheduled tasks can be achieved through the scheduled task scheduler interfaces of the Quartz open-source component, such as scheduler.pauseJob(jobKey) and scheduler.resumeJob(jobKey). Here, jobKey is a unique identifier for each scheduled task, consisting of the task name jobName and the task group jobGroup.
[0066] The processing procedure of the Kafka messaging system is as follows: Figure 3 As shown.
[0067] Each producer command is continuously appended to the end of the corresponding partition's log file, and each command has its own corresponding offset. The commands contain detailed information such as the scheduled task action, scheduled task mode, scheduled task identifier, and timestamp, which are recorded in the log file to achieve data persistence. If there is a need to restore data between the primary and standby services, logs for the corresponding time period can be extracted from the database logs based on the records in the log file for data recovery, mitigating the risk of data loss that may occur during scheduled task execution when switching between primary and standby application services. By extracting scheduled task commands and their timestamps from the log file corresponding to the Kafka message system partition, and combining this with the actual execution status of scheduled tasks in the primary and standby databases, the execution status of scheduled tasks can be monitored.
[0068] The interface layer design for handling scheduled tasks in the Kafka messaging system according to this invention.
[0069] This invention provides a Quartz timed task scheduling method based on Kafka master-slave application service. The parameters required for the interface receiving producer instructions during the Kafka message system processing are shown in Table 1.
[0070] Table 1
[0071]
[0072] The action field is required for scheduled tasks and can have six possible values:
[0073] 1) MS indicates that the scheduled task has switched from the primary application service to the standby application service;
[0074] 2) SM indicates that the scheduled task has switched from the standby application service to the primary application service;
[0075] 3) MO indicates that scheduled tasks are enabled only for the host application service;
[0076] 4) MC indicates that scheduled tasks are stopped only on the host application service;
[0077] 5) SO indicates that scheduled tasks are enabled only for standby application services;
[0078] 6) SC indicates that scheduled tasks are stopped only when the standby application service is running.
[0079] The mode field is required for scheduled tasks and can have two values:
[0080] 1) A indicates a complete switch of scheduled tasks. When mode is A, the jobKey scheduled task identifier is empty.
[0081] 2) P indicates the switching of the scheduled task. When mode is P, the jobKey scheduled task identifier cannot be empty. It consists of the scheduled task name jobName (10 characters) and the scheduled task group jobGroup (6 characters).
[0082] The time stamp for scheduled tasks consists of a date (8 bits) and a time (6 bits), used to record the specific time of the scheduled task.
[0083] The process of consumer execution of Quartz scheduled tasks in the Kafka messaging system in this embodiment of the invention
[0084] In the Kafka messaging system, the consumer's message consumption process is as follows: Figure 4 As shown.
[0085] 1) First, read the action field to obtain the scheduled task action. If the value of this field is not among the six specified values, return failure.
[0086] 2) Read the mode field to obtain the scheduled task mode. If the value of this field is not among the two specified values, return failure.
[0087] 3) Then, determine if the mode field is P. Read the jobKey timer task identifier. If the jobKey timer task identifier is empty or does not meet the 16-character string format, return failure. If the mode field is A, there is no need to read the jobKey timer task identifier. If the mode field is neither P nor A, return failure.
[0088] 4) Next, based on the six possible values of the `action` field, send commands to the primary or standby application service, as follows:
[0089] 4-1)MS: First, stop all or part of the scheduled tasks in the main application service according to the mode, and then start all or part of the scheduled tasks in the standby application service according to the mode.
[0090] 4-2)SM: First, stop all or part of the scheduled tasks in the standby application service according to the mode, and then start all or part of the scheduled tasks in the master application service according to the mode.
[0091] 4-3) MO: The host application service starts a whole or part of the scheduled task according to the mode;
[0092] 4-4) MC: The host application service stops all or part of the scheduled tasks according to the mode;
[0093] 4-5) SO: The standby application service starts all or part of the scheduled tasks according to the mode;
[0094] 4-6)SC: Stop all or part of the scheduled tasks in the standby application service according to the mode.
[0095] 5) When the primary or backup application service switches between all or part of the scheduled tasks based on the mode, if mode is A, the Quartz open-source component's scheduled task scheduler interface `schedulerFactoryBean.start()` and `schedulerFactoryBean.stop()` are used to start or stop the overall scheduled task; if mode is P, the Quartz open-source component's scheduled task scheduler interface `scheduler.pauseJob(jobKey)` and `scheduler.resumeJob(jobKey)` are used. For producers and consumers, as long as the interface parameters for sending and receiving messages meet the above requirements, producers and consumers can be modified or extended independently to flexibly meet the system's module requirements for scheduling Quartz scheduled tasks between primary and backup application services, while also decoupling the primary / backup application service switching from scheduled task scheduling to scheduled task scheduling.
[0096] The technical solution of this invention provides a method for switching task executors, namely, an event manager that can uniformly manage and monitor the scheduled task relationships between primary and backup application services. This decouples the switching of primary and backup application services from the scheduling of scheduled tasks, ensuring reliable, scalable, and recoverable scheduling and execution of scheduled tasks between primary and backup application services. It reduces system modifications when adding new scheduled task business requirements, processes messages about scheduling scheduled tasks between primary and backup application services in real time, and provides unified monitoring and management. The scheduling method for scheduled tasks between primary and backup application services implemented in this invention has low complexity and is easily scalable. Only four parameters required by the message interface need to be passed to meet the requirement that the same scheduled task can only be executed on one server in the primary or backup application service at any given time. When new requirements for scheduled task switching arise, value selection can be added to the `action` scheduled task scheduling method or `mode` scheduled task scheduling mode, and processing of this method or mode can be added to the consumer interface, resulting in high scalability. It also possesses reliability and recoverability. During primary / standby server failover, the Kafka messaging system allows consumers to perform scheduled task switching in an orderly manner, ensuring that scheduled tasks process business logic without omissions or duplication. Each instruction is persistently recorded and can be recovered via log files and database logs. It offers high real-time performance. Whether performing primary / standby server failover or receiving scheduled task switchover instructions directly from operations personnel, the Kafka messaging system can process these instructions in real time, ensuring timely completion of business tasks. This paper utilizes the Kafka messaging system to centrally manage the relationships between scheduled tasks in primary and backup application services. It designs an interface layer for the Kafka messaging system to handle scheduled task scheduling, decoupling the switching between primary and backup application services and scheduled task scheduling. This allows for independent modification or extension of the scheduling method for Quartz scheduled tasks between primary and backup application services. The paper also designs the process for consumers in the Kafka messaging system to execute Quartz scheduled tasks, ensuring reliable, scalable, and recoverable scheduling and execution of scheduled tasks between primary and backup application services. Data persistence is used to mitigate the risk of data loss during scheduled task execution during primary and backup application service switching, and integrated logging is used to monitor the scheduling and execution of scheduled tasks between primary and backup application services.
[0097] Example 3
[0098] Figure 5 This is a schematic diagram of a task executor switching device provided in Embodiment 3 of the present invention. Figure 5 As shown, the device includes:
[0099] The field information determination module 310 is used to determine the switching field information corresponding to the switching instruction of the task executor when the switching conditions of the task executor are detected to be met; wherein, the switching field information includes an execution mode field, a switching mode field, and a task identifier field;
[0100] The switching mode determination module 320 is used to determine, based on the switching field information, the task to be executed corresponding to the executor switching instruction, the target executor of the task to be executed, and the switching mode; wherein, the switching mode is determined based on the switching mode field.
[0101] The task switching module 330 switches the current executor of the task to the target executor based on the switching mode, so that the target executor executes the task. The executor and the target executor are servers in the master-slave service architecture system.
[0102] The technical solution of this invention, when detecting that the switching conditions for the task executor are met, determines the switching field information corresponding to the executor switching instruction; based on the switching field information, it determines the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed; based on the switching mode, it switches the current executor of the task to be executed to the target executor, so that the target executor after the switch executes the task to be executed. The executor and the target executor are servers in a primary / backup service architecture system. The technical solution of this invention solves the problem that when the target switches between primary and backup servers, the tasks on the server cannot be switched simultaneously, leading to untimely, missed, or duplicate task processing, and realizes the switching of the task executor from one server to another.
[0103] Optionally, the field information determination module 310 includes:
[0104] The storage module is used to store the executor switching instruction in the form of a log file in the message processing system when the executor switching instruction is received;
[0105] The parsing module is used to parse the executor switching instruction in the log file based on the message processing system to obtain the switching field information.
[0106] Optionally, the switching mode determination module 320 includes:
[0107] The task determination module is used to determine the task to be executed corresponding to the executor switching instruction based on the field information of the task identifier field;
[0108] An executor determination module is used to determine the target executor corresponding to the task to be executed based on the field information of the execution mode field;
[0109] The mode determination module is used to determine the switching mode corresponding to the task to be executed based on the field information of the switching mode field, wherein the switching mode includes a partial switching mode and a complete switching mode.
[0110] Optionally, the executor determination module includes:
[0111] If the field information of the execution mode field is consistent with the field information of the first mode field, then the master server in the master-slave service architecture system is determined as the current executor, and the backup server is determined as the target executor.
[0112] If the field information of the execution mode field is consistent with the field information of the second mode field, then the backup server in the master-slave service architecture system is determined as the current executor, and the master server is determined as the target executor.
[0113] The primary and backup service architecture system includes the primary server and the backup server.
[0114] Optionally, the task switching module 330 includes:
[0115] If the switching mode is the full switching mode, then the current executor of each task to be executed received within the preset time period will be switched to the target executor;
[0116] If the switching mode is a partial switching mode, then the current executor of the task to be executed corresponding to the task identifier field will be switched to the target executor.
[0117] Optionally, the task switching module 330 is specifically used for:
[0118] The current executor is controlled to stop processing the task to be executed, and the task to be executed is processed based on the target executor.
[0119] Optionally, the switching device for the task executor further includes:
[0120] Based on the log files in the message processing system, determine the execution status information corresponding to the executor switching instruction, and synchronize the execution status information to each server in the primary and backup service architecture system.
[0121] The task executor switching device provided in the embodiments of the present invention can execute the task executor switching method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0122] Example 4
[0123] Figure 6 This is a schematic diagram of an electronic device according to Embodiment 4 of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0124] like Figure 6 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0125] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0126] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the task executor switching methods.
[0127] In some embodiments, the task executor switching method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the task executor switching method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the task executor switching method by any other suitable means (e.g., by means of firmware).
[0128] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0129] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0130] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0131] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0132] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0133] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0134] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0135] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A task performer switching method, characterized by, include: When the switching conditions for the task executor are met, the switching field information corresponding to the executor switching instruction is determined; wherein, the switching field information includes an execution mode field, a switching mode field, and a task identifier field; Based on the switching field information, the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed, are determined; wherein, the switching mode is determined based on the switching mode field; Based on the switching mode, the current executor of the task to be executed is switched to the target executor, so that the target executor executes the task to be executed. The executor and the target executor are servers in the master-slave service architecture system. When the switching conditions for the task executor are detected to be met, the step of receiving the executor switching instruction and determining the switching field information corresponding to the executor switching instruction includes: Upon receiving the executor switching instruction, the executor switching instruction is stored in the message processing system as a log file; The switching field information is obtained by parsing the executor switching instruction in the log file based on the message processing system. The step of determining the task to be executed corresponding to the executor switching instruction, as well as the target executor and switching mode of the task to be executed, based on the switching field information, includes: The task to be executed corresponding to the executor switching instruction is determined based on the field information of the task identifier field; The target executor corresponding to the task to be executed is determined based on the field information of the execution mode field; The switching mode corresponding to the task to be executed is determined based on the field information of the switching mode field, wherein the switching mode includes partial switching mode and full switching mode; Among them, the executor switching instructions are stored in the Kafka message processing system in the form of log files. The Kafka message processing system continuously appends the executor switching instructions to the end of the log file corresponding to the partition. Each instruction has a corresponding offset to achieve data persistence. The step of determining the target executor corresponding to the task to be executed based on the field information of the execution mode field includes: If the field information of the execution mode field is consistent with the field information of the first mode field, then the master server in the master-slave service architecture system is determined as the current executor, and the backup server is determined as the target executor. If the field information of the execution mode field is consistent with the field information of the second mode field, then the backup server in the master-slave service architecture system is determined as the current executor, and the master server is determined as the target executor. The primary and backup service architecture system includes the primary server and the backup server. The step of switching the current executor of the task to be executed to the target executor based on the switching mode includes: If the switching mode is the full switching mode, then the current executor of each task to be executed received within the preset time period will be switched to the target executor; If the switching mode is a partial switching mode, then the current executor of the task to be executed corresponding to the task identifier field will be switched to the target executor; The step of switching the current executor of the task to be executed to the target executor based on the switching mode, so that the target executor executes the task to be executed, includes: The current executor is controlled to stop processing the task to be executed, and the task to be executed is processed based on the target executor; The interface for switching instructions includes four fixed fields: action (timed task scheduling action), mode (timed task scheduling mode), jobKey (timed task identifier), and time (time stamp). The action field has six possible values: MS, SM, MO, MC, SO, and SC, while the mode field has two possible values: A and P.
2. The method of claim 1, wherein, Also includes: Based on the log files in the message processing system, determine the execution status information corresponding to the executor switching instruction, and synchronize the execution status information to each server in the primary and backup service architecture system.
3. A task performer handover apparatus, characterized by comprising: The apparatus for implementing the method for switching task executors as described in any one of claims 1-2, the apparatus comprising: The field information determination module is used to determine the switching field information corresponding to the switching instruction of the task executor when the switching conditions of the task executor are detected to be met; wherein, the switching field information includes an execution mode field, a switching mode field, and a task identifier field; A switching mode determination module is used to determine, based on the switching field information, the task to be executed corresponding to the executor switching instruction, the target executor of the task to be executed, and the switching mode; wherein, the switching mode is determined based on the switching mode field. The pending task switching module, based on the switching mode, switches the current executor of the pending task to the target executor, so that the target executor executes the pending task. The executor and the target executor are servers in the master-slave service architecture system. The field information determination module includes: The storage module is used to store the executor switching instruction in the form of a log file in the message processing system when the executor switching instruction is received; The parsing module is used to parse the executor switching instruction in the log file based on the message processing system to obtain the switching field information; The switching mode determination module includes: The task determination module is used to determine the task to be executed corresponding to the executor switching instruction based on the field information of the task identifier field; An executor determination module is used to determine the target executor corresponding to the task to be executed based on the field information of the execution mode field; The mode determination module is used to determine the switching mode corresponding to the task to be executed based on the field information of the switching mode field, wherein the switching mode includes partial switching mode and full switching mode; The executor switching instructions are stored in the Kafka message processing system as log files. The Kafka message processing system continuously appends the executor switching instructions to the end of the log file corresponding to the partition, with each instruction carrying a corresponding offset to achieve data persistence.
4. An electronic device, comprising: The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the task executor switching method according to any one of claims 1-2.
5. A computer readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the task executor switching method as described in any one of claims 1-2.