Method, device and related multi-server system for coordinating single-task master-slave programs

By preempting execution rights on the master-slave coordination server and registering the slave program as the new master program, the problem of coordination of the master-slave program on multiple servers is solved, and the smooth execution of tasks and data security is achieved.

CN114090211BActive Publication Date: 2025-02-18BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111397836.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-23
Publication Date
2025-02-18
Estimated Expiration
2041-11-23

AI Technical Summary

Technical Problem

The prior art is difficult to effectively coordinate a single-task master-slave program on multiple servers, resulting in problems such as data duplication and data conflict.

Method used

By preempting execution rights on the preset master-slave coordination server, obtaining information of the original master program, connecting and stopping the operation of the original master program, and deploying the slave program to register as the new master program to continue executing tasks.

Benefits of technology

It realizes fair seizing execution rights of single task master-slave programs on multiple servers, avoids data duplication and conflicts, and ensures smooth execution of tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090211B_ABST
    Figure CN114090211B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and related multi-server system for coordinating single-task master-slave programs, belonging to automatic program design. The method includes: seizing the execution right on a preset master-slave coordination server; if the execution right is successfully seized, the information of the original master program of the single task is obtained from the master-slave coordination server, and according to the information of the original master program obtained, the original master program is connected and the operation of the original master program is stopped; the slave program of the single task deployed locally registers its own information on the master-slave coordination server, and runs as a new master program to continue executing the single task. The present invention provides a master-slave backup solution for deploying a single task on multiple task servers, and well avoids a series of problems such as data duplication and data conflict caused by the single task program running on multiple servers at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for coordinating single-task master-slave programs and a related multi-server system. Background Art

[0002] When a single task is deployed on a single server, if the machine fails, the single task will not be executed normally and the corresponding task will not be completed.

[0003] The existing technology adopts a master-slave backup method to solve the above problems. A single task is deployed on two servers, and an additional task detection thread is added on the two servers where the single task is deployed. A polling method is used to check whether the task thread survives normally. When the check program on the server where the slave program (manually set when the program starts) is located fails to detect the status of the main program or is unresponsive for multiple times, the slave program is started on the server to take over the main program and continue to execute the corresponding task.

[0004] This method is often suitable for deploying a single task on two servers. When deployed on multiple servers, there is a lack of corresponding solutions. In addition, deployment on multiple servers can easily cause a single task program to run on multiple servers at the same time, leading to a series of problems such as data duplication and data conflict, which also need to be solved urgently. Summary of the invention

[0005] An embodiment of the present invention provides a method for coordinating a single-task master-slave program, comprising:

[0006] Seize the execution right on the preset master-slave coordination server;

[0007] If the execution right is seized successfully, the information of the original main program of the single task is obtained from the master-slave coordination server, and according to the obtained information of the original main program, the original main program is connected and the operation of the original main program is stopped;

[0008] The slave program of the single task deployed locally registers its own information on the master-slave coordination server and runs as a new master program to continue executing the single task.

[0009] In one embodiment, the method further includes: if the execution right is not seized successfully, monitoring the state of the original main program on the master-slave coordination server, and when the state of the original main program changes, executing the operation of seizing the execution right from the master-slave coordination server again.

[0010] In one embodiment, the seizing the execution right on the preset master-slave coordination server includes:

[0011] Creating a temporary node on the master-slave coordination server;

[0012] If the creation is successful, the preemption of execution rights is successful. If the creation fails, the preemption of execution rights fails.

[0013] In one embodiment, before creating a temporary node on the master-slave coordination server, the method further includes:

[0014] Check whether the node corresponding to the original master program exists on the master-slave coordination server;

[0015] If it does not exist, the process proceeds to execute the step of creating a temporary node on the master-slave coordination server.

[0016] In one embodiment, the acquiring the information of the original main program of the single task from the master-slave coordination server, and connecting to the original main program and stopping the running of the original main program according to the acquired information of the original main program, comprises:

[0017] Obtaining information of a node corresponding to the original master program from the master-slave coordination server, the information including: an IP address, a port number and status information of the original master program;

[0018] When it is determined that the status information of the original main program is a non-end status, a socket connection is established with the original main program according to the IP address and the port number;

[0019] A stop command is sent to the original main program through the socket connection to stop the running of the original main program.

[0020] In one embodiment, when it is determined that the status information of the original main program is in the end state, the operation of the single-task slave program deployed locally is directly ended.

[0021] In one embodiment, the single-task slave program deployed locally registers its own information on the master-slave coordination server, including:

[0022] The single-task slave program deployed locally registers its own IP address, port number and status information on the master-slave coordination server.

[0023] In one embodiment, the method for coordinating a single-task master-slave program further includes:

[0024] When the execution of the new main program ends, the state information of the corresponding node on the master-slave coordination server is modified to the end state.

[0025] The embodiment of the present invention further provides a device for coordinating a single-task master-slave program, comprising:

[0026] The execution right seizure module is used to seize the execution right on the preset master-slave coordination server;

[0027] An acquisition module, used for acquiring information of the original main program of the single task from the master-slave coordination server if the execution right is successfully seized;

[0028] A connection module, used to connect to the original main program and stop the operation of the original main program according to the information of the original main program obtained;

[0029] The registration module is used to register the information of the slave program of the single task deployed locally on the master-slave coordination server and run it as a new master program to continue executing the single task.

[0030] An embodiment of the present invention further provides a task server, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the aforementioned method for coordinating single-task master-slave programs when executing the computer program.

[0031] The embodiment of the present invention also provides a multi-server system for executing a single task, comprising a master-slave coordination server and a plurality of task servers as described above connected to the master-slave coordination server;

[0032] At the same time, one of the multiple task servers runs the main program of the single task, and the other task servers run the slave programs of the single task.

[0033] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for coordinating single-task master-slave programs as described above is implemented.

[0034] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method for coordinating single-task master-slave programs as described above is implemented.

[0035] The above-mentioned method, device and related multi-server system for coordinating single-task master-slave programs provided by the embodiment of the present invention, relative to the prior art, fairly seizes the execution right through the programs on multiple task servers deployed by a single task, re-elects a new master program, and the others serve as new slave programs, and the new master program will actively connect to the original master program to terminate the original master program before running, and the new slave program continues to monitor the status of the new master program to wait for the next opportunity to seize the execution right. The embodiment of the present invention not only provides a solution for master-slave backup of a single task deployed on multiple task servers, but also, at the same time, only one program runs as the master program, and the other slave programs are in a waiting state and do not run, which can well avoid a single task running on multiple servers at the same time, leading to a series of problems such as data duplication and data conflict. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0037] Figure 1 A flowchart of a method for coordinating a single-task master-slave program in an embodiment of the present invention;

[0038] Figure 2 A flowchart of the steps of obtaining information of the original main program and connecting to the original main program to stop the running of the original main program in an embodiment of the present invention;

[0039] Figure 3 A flowchart of a specific example in an embodiment of the present invention;

[0040] Figure 4 is a structural block diagram of a device for coordinating single-task master-slave programs in an embodiment of the present invention;

[0041] Figure 5 4 is a structural block diagram of a multi-server system executing a single task in an embodiment of the present invention. DETAILED DESCRIPTION

[0042] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0043] The present invention belongs to automatic programming technology. In order to distinguish servers with different functions, in the embodiments of the present invention, the server responsible for coordinating the operation of the master and slave programs on multiple servers deployed with a single task is called a master-slave coordination server, and the server where the master program or slave program specifically responsible for executing a single task is located is called a task server.

[0044] The embodiment of the present invention provides a method for coordinating a single-task master-slave program, which is applicable to deploying a single task on any server among multiple task servers, referring to Figure 1 As shown, the method comprises the following steps:

[0045] S11, seize the execution right on the preset master-slave coordination server;

[0046] S12, if the execution right is seized successfully, obtaining the information of the original main program of the single task from the master-slave coordination server;

[0047] S13, according to the information of the original main program obtained, connecting to the original main program and stopping the operation of the original main program;

[0048] S14. The single-task slave program deployed locally registers its own information on the master-slave coordination server and runs as a new master program to continue executing the single task.

[0049] The execution subject of the above steps S11-S14 may be, for example, a slave program of a single task deployed on the task server.

[0050] There are many execution opportunities for the above step S11. For example, the slave program of a single task will monitor the status of the current master program on the master-slave coordination server. When the status of the master program changes, a new round of execution right preemption process can be triggered, that is, from the master and slave programs of the same single task running on multiple servers, each program competes fairly, preempts the execution right, and re-elects one as the new master program and the others as new slave programs. For another example, when multiple task servers deployed with the same single task are started, the operation of preempting the execution right will also be triggered.

[0051] In one embodiment, in the method for coordinating single-task master-slave programs, if the preemption of execution rights fails, the status of the original master program on the master-slave coordination server is monitored. When the status of the original master program changes, the operation of preempting execution rights from the master-slave coordination server is executed again.

[0052] The above S11 can be implemented by seizing the execution right from the preset master-slave coordination server in the following manner:

[0053] Creating a temporary node on the master-slave coordination server;

[0054] If the creation is successful, the preemption of execution rights is successful. If the creation fails, the preemption of execution rights fails.

[0055] In one embodiment, the master-slave coordination server can be, for example, a Zookeeper (ZK) server. ZooKeeper is a distributed, open source distributed application coordination service. It is a software that provides consistency services for distributed applications, and the functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc. The goal of ZooKeeper is to encapsulate complex and error-prone key services and provide users with simple and easy-to-use interfaces and efficient and stable systems. In the Zookeeper server, a node, i.e., a znode, is a node similar to a Unix file system path, and data can be stored or retrieved at this node.

[0056] The execution right (that is, the qualification to become the new master program) can be seized by creating a temporary node on the ZK server. After the session ends, the new master program is elected and registered, and the temporary node can be deleted.

[0057] In one embodiment, before creating a temporary node on the aforementioned master-slave coordination server, the method for coordinating single-task master-slave programs can also check whether the node corresponding to the original master program on the master-slave coordination server exists; if not, then turn to executing the step of creating a temporary node on the master-slave coordination server.

[0058] If there is a node corresponding to the original master program, and the slave program of the single task deployed locally has successfully seized the execution right, the step of obtaining the information of the original master program of the single task from the master-slave coordination server will be executed.

[0059] In one embodiment, the above steps S12 and S13 are specifically implemented with reference to Figure 2 As shown, this can be achieved through the following process:

[0060] S21, obtaining information of a node corresponding to the original master program from the master-slave coordination server, where the node information includes at least the following information: an IP address, a port number and status information of the original master program;

[0061] S22, judging the status information of the original main program, if the status information is a non-end state, executing the subordinate step S23; if the status information is an end state, executing step S25;

[0062] S23, establishing a socket connection with the original main program according to the IP address and port number information;

[0063] S24, sending a stop command to the original main program through the socket connection to stop the operation of the original main program;

[0064] S25, directly ending the operation of the single-task slave program deployed locally.

[0065] In one embodiment, registering the self information to the master-slave coordination server includes:

[0066] The single-task slave program deployed locally registers its own IP address, port number and status information on the master-slave coordination server.

[0067] When the execution of the new main program ends, in the embodiment of the present invention, the new main program also needs to modify the state information of the corresponding node on the master-slave coordination server to the end state.

[0068] In order to better illustrate the method for coordinating single-task master-slave programs provided by an embodiment of the present invention, the above method is further illustrated by an example. In this example, a master program (referred to as the original master program here) is running on multiple servers deployed with a single task, and the others are running slave programs. The master program executes the single task, and the other slave programs monitor the status of the master program. When the status changes, the process of electing a new master program and a new slave program is initiated.

[0069] Reference Figure 3 As shown, the process includes:

[0070] S31. Create a temporary node / task / service on the ZK server. If the temporary node creation fails, execute step S40. If the creation succeeds, execute the following step S32.

[0071] S32. Check whether the ZK server node / task / status exists. If not, execute S33; if it exists, execute S34.

[0072] S33. Create a ZK server node / task / status on the ZK server.

[0073] S34. Obtain the node data, obtain the IP address, port number and status of the original main program, and then execute the following step S35.

[0074] S35. Use the obtained IP address and port number to create a Socket connection and check the original main program status; if the original main program status is finish, execute the following step S36, otherwise, execute the following step S37.

[0075] S36. Directly terminate the execution of this slave program and go to step S41.

[0076] S37. Send a stop command to stop the running of the original main program, and then execute step S38.

[0077] S38. The single task program registers the IP address, port number and status start of the task program in the ZK node.

[0078] S39. Run the single-task business part program and update the state of the ZK node to finish when it is finished. Then end the running of this main program and execute step S41.

[0079] S40. Create a monitoring event and callback method for temporary node changes. When the callback method is triggered, continue to execute step S31 to seize the execution right.

[0080] S41. The process ends.

[0081] Based on the same inventive concept, an embodiment of the present invention also provides a device for coordinating single-task master-slave programs and a multi-server system for executing a single task. Since the principles of the problems solved by these devices and systems are similar to the aforementioned methods for implementing the coordination of single-task master-slave programs, the implementation of the devices, systems, etc. can refer to the implementation of the aforementioned methods, and the repeated parts will not be repeated.

[0082] An embodiment of the present invention provides a device for coordinating a single-task master-slave program, referring to Figure 4 As shown, including:

[0083] The execution right seizure module 41 is used to seize the execution right on the preset master-slave coordination server;

[0084] An acquisition module 42 is used to acquire the information of the original main program of the single task from the master-slave coordination server if the execution right is seized successfully;

[0085] A connection module 43, used to connect to the original main program and stop the operation of the original main program according to the acquired information of the original main program;

[0086] The registration module 44 is used to register the information of the slave program of the single task deployed locally on the master-slave coordination server and run it as a new master program to continue executing the single task.

[0087] An embodiment of the present invention provides a task server, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for coordinating a single-task master-slave program as described above is implemented.

[0088] An embodiment of the present invention provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the method for coordinating a single-task master-slave program as described above is implemented.

[0089] An embodiment of the present invention provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method for coordinating single-task master-slave programs as described above is implemented.

[0090] Reference Figure 5 As shown, an embodiment of the present invention provides a multi-server system for executing a single task, including a master-slave coordination server 51 and a plurality of task servers 52 as described above connected to the master-slave coordination server;

[0091] At the same time, one of the multiple task servers runs the main program of the single task, and the other task servers run the slave programs of the single task.

[0092] The above-mentioned method, device and related multi-server system for coordinating single-task master-slave programs provided by the embodiment of the present invention, relative to the prior art, fairly seizes the execution right through the programs on multiple task servers deployed by a single task, re-elects a new master program, and the others serve as new slave programs, and the new master program will actively connect to the original master program to terminate the original master program before running, and the new slave program continues to monitor the status of the new master program to wait for the next opportunity to seize the execution right. The embodiment of the present invention not only provides a solution for master-slave backup of a single task deployed on multiple task servers, but also, at the same time, only one program runs as the master program, and the other slave programs are in a waiting state and do not run, which can well avoid a single task running on multiple servers at the same time, leading to a series of problems such as data duplication and data conflict.

[0093] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0094] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0095] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0096] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0097] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for coordinating a single-task master-slave program, characterized in that: The method comprises: Seize the execution right on the preset master-slave coordination server; If the execution right is seized successfully, the information of the original main program of the single task is obtained from the master-slave coordination server, and according to the obtained information of the original main program, the original main program is connected and the operation of the original main program is stopped; The slave program of the single task deployed locally registers its own information on the master-slave coordination server and runs as a new master program to continue executing the single task; Seize the execution right on the preset master-slave coordination server, including: The slave program of a single task will monitor the status of the current master program on the master-slave coordination server. When the status of the master program changes, a new round of preemptive execution rights will be triggered. That is, among the master and slave programs of the same single task running on multiple servers, each program will compete fairly, preempt execution rights, and re-elect one as the new master program, and the others as new slave programs. Acquiring information of the original main program of the single task from the master-slave coordination server, and connecting to the original main program and stopping the running of the original main program according to the acquired information of the original main program, including: Obtaining information of a node corresponding to the original master program from the master-slave coordination server, the node information including at least the following information: an IP address, a port number and status information of the original master program; Determine the status information of the original main program, and if the status information is a non-end status, establish a socket connection with the original main program according to the IP address and port number information; send a stop command to the original main program through the socket connection to stop the operation of the original main program; If the status information is the end status, the operation of the slave program of the single task deployed locally is directly ended.

2. The method according to claim 1, characterized in that The method further includes: if the execution right is not seized successfully, monitoring the state of the original master program on the master-slave coordination server, and when the state of the original master program changes, executing the operation of seizing the execution right from the master-slave coordination server again.

3. The method according to claim 1, characterized in that Seizing the execution right on the preset master-slave coordination server includes: Creating a temporary node on the master-slave coordination server; If the creation is successful, the preemption of execution rights is successful. If the creation fails, the preemption of execution rights fails.

4. The method according to claim 3, characterized in that Before creating a temporary node on the master-slave coordination server, the method further includes: Check whether the node corresponding to the original master program exists on the master-slave coordination server; If it does not exist, the process proceeds to execute the step of creating a temporary node on the master-slave coordination server.

5. The method according to claim 1, characterized in that The single-task slave program deployed locally registers its own information on the master-slave coordination server, including: The single-task slave program deployed locally registers its own IP address, port number and status information on the master-slave coordination server.

6. The method according to claim 5, characterized in that Also includes: When the execution of the new main program ends, the state information of the corresponding node on the master-slave coordination server is modified to the end state.

7. A device for coordinating a single-task master-slave program, characterized in that: include: The execution right seizure module is used to seize the execution right on the preset master-slave coordination server; An acquisition module, used for acquiring information of the original main program of the single task from the master-slave coordination server if the execution right is successfully seized; A connection module, used to connect to the original main program and stop the operation of the original main program according to the information of the original main program obtained; A registration module, used to register the information of the slave program of the single task deployed locally on the master-slave coordination server, and run it as a new master program to continue executing the single task; The execution right seizure module is specifically used for the slave program of a single task. It will monitor the status of the current master program on the master-slave coordination server. When the status of the master program changes, a new round of execution right seizure process is triggered. That is, among the master and slave programs of the same single task running on multiple servers, each program competes fairly, seizes the execution right, and re-elects one as the new master program, and the others as new slave programs. The acquisition module is specifically used to obtain the information of the node corresponding to the original master program from the master-slave coordination server, and the node information at least includes the following information: the IP address, port number and status information of the original master program; The connection module is specifically used to determine the status information of the original main program. If the status information is a non-end status, a socket connection is established with the original main program according to the IP address and port number information; a stop command is sent to the original main program through the socket connection to stop the operation of the original main program; if the status information is an end status, the operation of the single-task slave program deployed locally is directly ended.

8. A task server, 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 method for coordinating single-task master-slave programs described in any one of claims 1 to 6 is implemented.

9. A multi-server system for executing a single task, characterized in that: comprising a master-slave coordination server and a plurality of task servers as claimed in claim 8 connected to the master-slave coordination server; At the same time, one of the multiple task servers runs the main program of the single task, and the other task servers run the slave programs of the single task.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for coordinating single-task master-slave programs according to any one of claims 1 to 6 is implemented.

11. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method for coordinating single-task master-slave programs according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Switching method of master node in distributed master-slave system, master node equipment and storage medium

    CN112860787A

  • Method and system for realizing high availability of distributed cluster and computer readable medium

    CN112887367A