CN112865992A - Method and device for switching master nodes in distributed master-slave system and computer equipment - Google Patents

Method and device for switching master nodes in distributed master-slave system and computer equipment Download PDF

Info

Publication number
CN112865992A
CN112865992A CN201911183863.6A CN201911183863A CN112865992A CN 112865992 A CN112865992 A CN 112865992A CN 201911183863 A CN201911183863 A CN 201911183863A CN 112865992 A CN112865992 A CN 112865992A
Authority
CN
China
Prior art keywords
task
election
state
master
nodes
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911183863.6A
Other languages
Chinese (zh)
Other versions
CN112865992B (en
Inventor
韩志华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Bilibili Technology Co Ltd
Original Assignee
Shanghai Bilibili Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Bilibili Technology Co Ltd filed Critical Shanghai Bilibili Technology Co Ltd
Priority to CN201911183863.6A priority Critical patent/CN112865992B/en
Publication of CN112865992A publication Critical patent/CN112865992A/en
Application granted granted Critical
Publication of CN112865992B publication Critical patent/CN112865992B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0663Performing the actions predefined by failover planning, e.g. switching to standby network elements

Abstract

The invention provides a method and a device for switching master nodes in a distributed master-slave system and computer equipment. The system comprises a plurality of slave nodes and a plurality of main nodes, the main node in the working state sends heartbeat information to the main node in the rest state at preset time intervals, and the switching method comprises the following steps: when monitoring that heartbeat information is overtime, entering an election state from a rest state and sending an election request; when the number of the received election votes is larger than a first threshold value, entering a working state from an election state; receiving a task request sent by a client, and establishing a corresponding task item to write in a local log; distributing tasks corresponding to uncompleted task entries in the local log to the slave nodes, and updating corresponding task states according to execution progress returned by the slave nodes; when the local log is modified, the modification information is carried to the heartbeat information. According to the invention, the fault perception accuracy is prevented from being reduced by depending on a third party.

Description

Method and device for switching master nodes in distributed master-slave system and computer equipment
Technical Field
The present invention relates to the field of distributed system technologies, and in particular, to a method and an apparatus for switching master nodes in a distributed master-slave system, a computer device, and a computer-readable storage medium.
Background
The distributed master-slave system comprises a master node and a plurality of slave nodes, and after a user submits tasks to the distributed master-slave system through an interface, the master node receives the tasks and distributes the tasks to the slave nodes for execution.
However, when a master node fails, the distributed master-slave system cannot properly receive and distribute tasks to slave nodes. In the related technology, a third-party server is arranged in a distributed master-slave system, a master node communicates with the third-party server, and when a working master node in a working state fails, the third-party server informs other master nodes after sensing the failure, so that the other master nodes can replace the failed working master node in time to become a new working master node, and sensing and switching of the failed master node are realized.
However, the solution needs to introduce a third-party server, which increases the complexity of physical deployment of the distributed master-slave system, and meanwhile, the reliability of the master node in the distributed master-slave system needs to depend on the reliability of communication between the working master node and the third-party server, which is highly dependent on the third-party server, and a normal working node can be determined as a fault due to a communication fault between the working master node and the third-party server, thereby reducing the accuracy of fault sensing.
Disclosure of Invention
The invention aims to provide a method and a device for switching a main node in a distributed master-slave system and computer equipment, which are used for solving the technical problem that the fault perception accuracy is reduced due to the dependence on a third party when the fault perception and switching of the main node are depended on in the prior art.
On one hand, in order to achieve the above object, the present invention provides a method for switching master nodes in a distributed master-slave system.
The distributed master-slave system comprises a plurality of slave nodes and a plurality of master nodes, the states of the master nodes comprise a working state, a rest state and an election state, wherein the master nodes in the working state send heartbeat information to the master nodes in the rest state at preset time intervals, and the switching method comprises the following steps: when the heartbeat information is monitored to be out of time, entering an election state from a rest state, and sending an election request, wherein a main node receiving the election request is used for returning an election vote; when the number of the received election votes is larger than a first threshold value, entering a working state from an election state; receiving a task request sent by a client; establishing a task item corresponding to the task request, wherein the task item comprises a task identifier and a task state; writing the task entries into a local log; distributing tasks corresponding to uncompleted task entries in the local log to the slave nodes, and updating corresponding task states according to execution progress returned by the slave nodes; and when the local log is modified, carrying the modification information to the heartbeat information, wherein the master node receiving the modification information is used for modifying the log of the master node according to the modification information.
Further, after entering the election state from the rest state, and before sending the election request, the switching method further includes: taking a task identifier in the latest task entry in the local log as a detection identifier and carrying the detection identifier to the election request; and the master node receiving the election request is also used for comparing the detection identifier with the task identifier in the self log, and returning the election vote when the self log does not comprise the detection identifier or the task identifier in the latest task entry in the self log is the same as the detection identifier.
Further, each master node maintains its own cycle number, and the switching method further includes: after entering the election state from the rest state and before sending an election request, updating the cycle sequence number of the master node, taking the updated cycle sequence number as a detection sequence number to carry the detection sequence number to the election request, wherein the master node receiving the election request is used for comparing the detection sequence number with the cycle sequence number of the master node, and returning to the election voting when the cycle sequence number of the master node is not newer than the detection sequence number; and carrying the elected information to heartbeat information after the elected state enters a working state, wherein the main node receiving the elected information updates the cycle sequence number of the main node.
Further, the states of the master node further include a pre-election state, and the step of entering the election state from the rest state includes: entering a pre-election state from a rest state, and sending a pre-election request, wherein a main node receiving the pre-election request judges whether a main node in a working state and normal exists at present, and if the main node in the working state and normal does not exist, returning to pre-election voting; and when the number of the received pre-election votes is larger than a second threshold value, entering an election state from a pre-election state.
Further, the master node that receives the election request is also configured to send the election vote only once within one cycle sequence number, and when two or more election requests are received, return the election vote to the master node that sent the election request first.
Further, after receiving the task request sent by the client, the switching method further includes: writing task data corresponding to the task request into a database, wherein the task data comprises a task identifier, a task command and task parameters; the task entries in the local log are arranged in sequence, and the step of distributing the tasks corresponding to the unfinished task entries in the local log to the slave nodes comprises the following steps: inquiring incomplete task entries in a local log; acquiring task identifiers in a plurality of uncompleted task items; reading task data in a database in batches according to the obtained task identifiers; and distributing the tasks to the slave nodes according to the acquired task data.
Further, the step of allocating tasks to slave nodes according to the acquired task data includes: and distributing the tasks with the same task command to the same slave node.
In another aspect, the present invention provides a device for switching master nodes in a distributed master-slave system.
The distributed master-slave system comprises a plurality of slave nodes and a plurality of master nodes, the states of the master nodes comprise a working state, a rest state and an election state, wherein the master nodes in the working state send heartbeat information to the master nodes in the rest state at preset intervals, and the switching device comprises: the first state switching module is used for entering an election state from a rest state when monitoring that heartbeat information is overtime; the system comprises an election request sending module, a voting module and a voting module, wherein the election request sending module is used for sending an election request, and a main node receiving the election request is used for feeding back election voting; the second state switching module is used for entering a working state from the election state when the number of the received election votes meets a first preset condition; the task request receiving module is used for receiving a task request sent by a client; the task item newly-establishing module is used for establishing a task item corresponding to the task request, wherein the task item comprises a task identifier and a task state; the log updating module is used for writing the task entries into the local log; the task distribution module is used for distributing tasks corresponding to unfinished task entries in the local log to the slave nodes, and the log updating module is also used for updating corresponding task states according to the execution progress returned by the slave nodes; and the heartbeat information processing module is used for carrying the modification information to the heartbeat information when the local log is modified, wherein the master node receiving the modification information is used for modifying the own log according to the modification information.
To achieve the above object, the present invention also provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the above method when executing the computer program.
To achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the above method.
The master node has a working state, a rest state and an election state, the master node in the working state is used as a working master node, heartbeat information is sent to the master node in the rest state at intervals of a preset time, the master node in the rest state is used as a redundant master node, and whether the working master node fails or not is monitored by monitoring the heartbeat information; meanwhile, the work master node receives a task request sent by the client in the working process, and establishes a corresponding task item to write in the local log. When the tasks are distributed, the tasks corresponding to the unfinished task entries in the local logs are distributed to the slave nodes, the corresponding task states are updated according to the execution progress returned by the slave nodes, when the local logs are modified, the modification information is carried to the heartbeat information, and through the heartbeat information, the redundant master node can modify the own logs according to the modification information, namely, the logs of the synchronous working master node. When the heartbeat information is monitored by the redundant main node to be out of time, the current working main node is in failure, the redundant main node enters an election state from a rest state, the redundant main node requests to be elected as a new working main node by sending an election request, when the number of the received election votes is larger than a first threshold value, the redundant main node can be elected as the new working main node, and at the moment, the electing state enters the working state to become the new working main node, so that the switching of the working main nodes is realized. The new work master node may also receive a task request sent by the client, and when allocating a task, allocate the task corresponding to the unfinished task entry in the local log to the slave node, where the local log of the new work master node includes a log of a previous work master node, that is, a replaced fault master node, that is, when the work master node fails, not only is the switching of the work master nodes achieved, but also the logs of the work master nodes can be synchronized. Moreover, it can be seen that in the monitoring and switching of the fault main node and the synchronization process of the log, monitoring and feedback are not required to be carried out through a third party server, so that the influence of third party dependence on the sensing accuracy of the fault main node is avoided.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a flowchart illustrating steps of a method for switching master nodes in a distributed master-slave system according to an embodiment of the present invention;
fig. 2 is a block diagram of a switching device for master nodes in a distributed master-slave system according to a second embodiment of the present invention;
fig. 3 is a hardware structure diagram of a computer device according to a third embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention provides a method and a device for switching master nodes in a distributed master-slave system, computer equipment and a computer readable storage medium, wherein the distributed master-slave system comprises a plurality of master nodes and a plurality of slave nodes, the states of the master nodes comprise a working state, a rest state and an election state, wherein when the master nodes are in the working state, the master nodes are also called as working master nodes and can receive task requests of a client, distribute tasks to the slave nodes for execution, receive execution results and feed back the execution results to the client; when the main node is in a rest state, the main node is used as a redundant main node; when the work main nodes need to be switched, the main nodes enter an election state from a rest state, a new work main node is generated in the election state by election, the main node selected as the work main node enters a work state from the election state, other main nodes not selected as the work main nodes keep the rest state or return to the rest state from the election state, wherein the main node in the work state sends heartbeat information to the main node in the rest state at preset time intervals, namely the work main node sends the heartbeat information to the redundant main node at preset time intervals, based on the method, in the switching method of the main nodes in the distributed main and slave system, in a normal state, the work main node sends the heartbeat information to the redundant main node at preset time intervals, the redundant main node monitors the heartbeat information, when one redundant main node monitors that the heartbeat information is overtime, that is, when the heartbeat information can not be received within the preset time length, it indicates that the working master node is in failure, a new working master node needs to be generated, at this time, the master node enters an election state from a rest state, and sends an election request to other master nodes in the distributed master-slave system, for the master node receiving the election request, an election vote can be returned to the master node sending the election request, when the number of the received election votes is more than a certain number, the master node is elected as the new working master node, the working state is entered from the election state, after the working state is accessed, the task request sent by the client is received, a task entry corresponding to the task request is established, the task entry is written into a local log, meanwhile, the corresponding task is distributed to the slave nodes aiming at the task entries which are not completed in the local log, correspondingly, the corresponding task state is updated according to the execution progress returned by the, in the above process, when the local log is modified, including writing a new task entry and modifying the task state in the task entry, the modified information is carried to the heartbeat information, the heartbeat information is sent to other master nodes, the modification is synchronized to other master nodes, the master node receiving the modified information modifies its own log according to the modified information, so that the redundant master node can synchronize the task distribution progress of the work master nodes and the task execution state, therefore, when one work master node fails and is replaced, the local log of the re-elected work master node is synchronized with the local log of the failed master node, if the local log of the failed master node includes an unfinished task entry, the unfinished task entry is retained in the local log of the re-elected work master node, and therefore, when the new work master node allocates tasks for the unfinished task entries in the local log, the new work master node can continue to allocate the tasks to the failed master node, that is, the unfinished task entry on the previous work master node. It can be seen that when a working master node in a working state fails, other master nodes can sense the failure and generate a new working master node in time, so that the replacement of the failed master node is realized, meanwhile, the continuity of task information on the working master node can be ensured, and the reliability of tasks of the working master node is improved.
The embodiments of the method, the apparatus, the computer device, and the computer-readable storage medium for switching master nodes in a distributed master-slave system according to the present invention will be described in detail below.
Example one
The embodiment of the invention provides a method for switching master nodes in a distributed master-slave system, wherein the distributed master-slave system comprises a plurality of master nodes and a plurality of slave nodes, the states of the master nodes comprise a working state, a rest state and an election state, and one master node can be switched among the three states. By the switching method of the master nodes in the distributed master-slave system provided by the embodiment, when the master node in the working state sends a fault, the master node in the rest state can sense the fault in time, and enters the election state from the rest state, and enters the working state from the election state after being elected as a working node, namely, the failed main node is replaced, when the main node in the distributed master-slave system fails, the fault main node is automatically switched to the normal main node, and the reliability of the task on the main node is ensured, meanwhile, the influence of the dependence of a third party on the perception accuracy of a fault main node is avoided without monitoring and feedback through a third party server, and particularly, fig. 1 is a flowchart illustrating steps of a method for switching master nodes in a distributed master-slave system according to an embodiment of the present invention, as shown in fig. 1, the method for switching master nodes in a distributed master-slave system provided by this embodiment includes steps S101 to S107 as follows.
Step S101: and when monitoring that the heartbeat information is overtime, entering an election state from a rest state and sending an election request.
The main node in the working state (namely, the working main node) can send heartbeat information to the main node in the rest state (namely, the redundant main node) at preset intervals, and when the working main node fails, the redundant main node cannot receive the heartbeat information on time or cannot receive the heartbeat information, so that whether the working main node fails or not can be monitored by monitoring whether the heartbeat information is overtime or not for the redundant main node. When a redundant main node monitors that heartbeat information is over time, the main node enters an election state from a rest state.
Optionally, when the system is started, all the master nodes are in a rest state, no master node in the system is in a working state, that is, no working master node is generated in the system, each master node is configured to randomly determine a time length as a preset time length within a certain time length range, and when a certain master node does not monitor heartbeat information within the preset time length, that is, when the heartbeat information is monitored to be over time, the master node firstly enters an election state from the rest state.
Optionally, in a normal operation process of the system, some of the master nodes are in a rest state and are redundant master nodes, and a master node in the system is in an operating state and is an operating master node, when the operating master node fails, the redundant master node may monitor that heartbeat information is out of time, and when a master node does not monitor heartbeat information within a preset time period, that is, when the heartbeat information is out of time, the master node enters an election state from the rest state.
After entering the election state, the master node sends an election request, and the election request can be sent to other master nodes in the distributed master-slave system or to the master node, wherein the election request is used for requesting election voting, optionally, the master node receiving the election request is used for returning the election voting, further optionally, a voting rule can be set, the master node receiving the election request judges the voting rule, the election voting is returned when the voting rule is satisfied, and the election voting is not returned when the voting rule is not satisfied.
Step S102: and when the number of the received election votes is larger than a first threshold value, entering a working state from an election state.
After the main nodes in the election state send election requests, the main nodes can receive election votes sent by each main node, and when the number of the received election votes reaches a preset number, namely is larger than a first threshold value, the main nodes are elected as working main nodes, so that the main nodes enter the working state from the election state. Alternatively, the first threshold may be half of the number of master nodes in the distributed master-slave system, and when the number of election votes received by one master node is half, that is, when the number of election votes received by one master node reaches half of the total number of master nodes in the distributed master-slave system, the master node is elected as a working master node.
Step S103: and receiving a task request sent by a client.
After the master node enters a working state and becomes a working master node, a task request sent by a client can be received, wherein the task request can comprise information such as a task identifier, a task parameter, a task command and the like.
Step S104: and establishing a task item corresponding to the task request.
The task item comprises a task identifier and a task state.
After receiving the task request, establishing task items corresponding to the task request, wherein one task request can correspond to one task item, and the task items comprise task identifiers and task states.
Step S105: the task entry is written to the local log.
Wherein, each main node maintains a log in the local. And after the task item corresponding to the task request is established, writing the task item into a local log, wherein the local log is also equal to a state machine, and maintaining the task state.
Step S106: and distributing the tasks corresponding to the incomplete task entries in the local log to the slave nodes, and updating the corresponding task states according to the execution progress returned by the slave nodes.
When the work main node distributes the tasks corresponding to the unfinished task items in the local log to the slave nodes, the slave nodes execute the tasks after receiving the distributed tasks, the execution progress and the execution result are fed back to the work main node so that the work main node can update the corresponding task state, and the execution result is returned to the client side when needed so as to respond to the task request.
Step S107: when the local log is modified, the modification information is carried to the heartbeat information.
And the master node receiving the modification information is used for modifying the own log according to the modification information.
When the local log is modified, the modification information is carried to the heartbeat information and sent to the redundant main node. The redundant main node can analyze the modification information after receiving the heartbeat information, and then can modify the log of the redundant main node according to the modification information and synchronize the log of the working main node to the redundant main node.
Based on this, in step S106, the unfinished task entry in the local log on the current work master node includes not only the task entry established by the work master node according to the received task request, but also the task entry synchronized by the previous work master node, that is, when the work master node switches, the continuity of the task information on the work master node can be ensured.
By adopting the switching method of the master nodes in the distributed master-slave system provided by the embodiment, the master nodes have a working state, a rest state and a election state, the master nodes in the working state are used as the working master nodes, heartbeat information is sent to the master nodes in the rest state at preset intervals, the master nodes in the rest state are used as redundant master nodes, and whether the working master nodes are in failure or not is monitored by monitoring the heartbeat information; meanwhile, the work master node receives a task request sent by the client in the working process, and establishes a corresponding task item to write in the local log. When the tasks are distributed, the tasks corresponding to the unfinished task entries in the local logs are distributed to the slave nodes, the corresponding task states are updated according to the execution progress returned by the slave nodes, when the local logs are modified, the modification information is carried to the heartbeat information, and through the heartbeat information, the redundant master node can modify the own logs according to the modification information, namely, the logs of the synchronous working master node. When the heartbeat information is monitored by the redundant main node to be out of time, the current working main node is in failure, the redundant main node enters an election state from a rest state, the redundant main node requests to be elected as a new working main node by sending an election request, when the number of the received election votes is larger than a first threshold value, the redundant main node can be elected as the new working main node, and at the moment, the electing state enters the working state to become the new working main node, so that the switching of the working main nodes is realized. The new work master node may also receive a task request sent by the client, and when allocating a task, allocate the task corresponding to the unfinished task entry in the local log to the slave node, where the local log of the new work master node includes a log of a previous work master node, that is, a replaced fault master node, that is, when the work master node fails, not only is the switching of the work master nodes achieved, but also the logs of the work master nodes can be synchronized. Moreover, it can be seen that in the monitoring and switching of the fault main node and the synchronization process of the log, monitoring and feedback are not required to be carried out through a third party server, so that the influence of third party dependence on the sensing accuracy of the fault main node is avoided.
Optionally, in an embodiment, after entering the election state from the rest state, before sending the election request, the switching method further includes: and taking the task identifier in the latest task entry in the local log as a detection identifier to be carried to the election request, wherein the master node receiving the election request is also used for comparing the detection identifier with the task identifier in the self log, and returning the election vote when the self log does not comprise the detection identifier or the task identifier in the latest task entry in the self log is the same as the detection identifier.
Specifically, after the redundant master node enters the election state from the rest state, a task identifier of a latest task entry in a local log is inquired, the task identifier is taken as a detection identifier and carried to an election request, the master node receiving the election request compares the detection identifier with the task identifier in the master node itself, and if the master node itself does not include the detection identifier, the updating condition of the local log of the master node sending the election request is shown to be earlier than the updating condition of the master node receiving the election request; if the task identifier in the latest task entry in the self log is the same as the detection identifier, the updating condition of the local log of the main node sending the election request is consistent with the updating condition of the main node receiving the election request; if the task identifier in the non-latest task entry in the self log is the same as the detection identifier, the update condition of the local log of the master node sending the election request lags behind the update condition of the master node receiving the election request, in summary, the master node receiving the election request can determine the relationship between the update condition of the local log of the master node sending the election request and the update condition of the self log by comparing the detection identifier with the task identifier in the self log, and the detection identifier is not included in the self log, or the task identifier in the latest task entry in the self log is the same as the detection identifier, and then the election vote is returned, namely the election vote is prevented from being returned to the master node whose local log update condition lags behind the update condition of the self log.
By adopting the method for switching master nodes in the distributed master-slave system provided by the embodiment, the master node in the election state takes the task identifier of the latest task entry in the local log as the detection identifier to be carried to the election request, so that the master node receiving the election request can judge the updating condition of the own log and the updating condition of the local log of the master node sending the election request to determine whether to return the election vote or not, and the situation that the local log on the new selected working master node lags behind the log information of the master node casting the election vote is avoided.
Optionally, in an embodiment, each master node respectively maintains its own cycle number, and the switching method further includes: after entering the election state from the rest state and before sending an election request, updating the cycle sequence number of the master node, taking the updated cycle sequence number as a detection sequence number to carry the detection sequence number to the election request, wherein the master node receiving the election request is used for comparing the detection sequence number with the cycle sequence number of the master node, and returning to the election voting when the cycle sequence number of the master node is not newer than the detection sequence number; and carrying the elected information to heartbeat information after the elected state enters a working state, wherein the main node receiving the elected information updates the cycle sequence number of the main node.
Specifically, the period when the master nodes are in the election state and the working state is taken as a period, each master node maintains a period sequence number, when the master node enters the election state from the rest state, the period sequence number of the master node is updated before the election request is sent, for example, when the period sequence number is a number, the period sequence number can be updated by increasing the number. After the cycle sequence number is updated, the updated cycle sequence number is taken as a detection sequence number and is carried to the election request, so that the main node receiving the election request can obtain the detection sequence number at the same time, and further can judge whether to return the election voting or not by detecting the sequence number. When the number of the election votes received by the main node in the election state is larger than a first threshold value, the main node is elected as a work main node, at the moment, the election state enters the work state, elected information is carried to heartbeat information, other main nodes are informed, a new work main node is generated, the main node receiving the elected information learns that a new work main node appears, at the moment, the cycle sequence number of the main node is updated, and the main node uniformly enters a new cycle.
By adopting the method for switching master nodes in the distributed master-slave system provided by the embodiment, the master node in the election state updates the cycle sequence number of the master node at first, and carries the updated cycle sequence number as a detection sequence number to the election request, so that the master node receiving the election request can judge the sequence of the cycle sequence number of the master node and the cycle sequence number of the master node sending the election request to determine whether to return the election vote or not, and the cycle sequence number of the master node casting the election vote is prevented from lagging behind the cycle sequence number of the master node casting the election vote when the cycle sequence number of a new working master node is. For the cycle sequence number of the master node, the master node enters the election state by itself or other master nodes are elected as new working master nodes, and the update of the cycle sequence number is triggered, so that the sequence of the cycle sequence number can represent the activity of the master node, the cycle sequence number of the elected new working master node is prevented from lagging the cycle sequence number of the master node casting the election vote, and the master node with low activity is also prevented from being elected as the working master node. In addition, the main node receiving the election request judges whether to return the election vote or not through the detection serial number and the detection identifier, and the probability that two or more working main nodes are elected simultaneously in the system can be reduced.
Optionally, in an embodiment, the state of the master node further includes a pre-election state, and the step of entering the election state from the rest state includes: entering a pre-election state from a rest state, and sending a pre-election request, wherein a main node receiving the pre-election request judges whether a main node in a working state and normal exists at present, and if the main node in the working state and normal does not exist, returning to pre-election voting; and when the number of the received pre-election votes is larger than a second threshold value, entering an election state from a pre-election state.
Specifically, when a master node entering the election state has a network partition problem and cannot normally communicate with other master nodes, the master node repeatedly enters the election state, and further causes the maintained periodic sequence number to be repeatedly updated, at this time, when the master node normally communicates with other master nodes at a certain moment, after an election request carrying a detection sequence number is sent to a redundant master node, the periodic sequence number of the redundant master node is not new to the detection sequence number at a high probability, so that election voting can be returned, and at this time, a new working master node is substantially the master node with the network problem. In order to avoid the situation, the states of the main nodes also include a preselection state, when the main nodes enter the election state from the rest state, the main nodes first enter the preselection state from the rest state, and send a preselection request, for the main nodes receiving the preselection request, whether the main nodes in the working state and normal currently exist is judged, for example, the judgment is carried out by monitoring heartbeat information, if the heartbeat information is normal, the main nodes in the working state and normal currently exist, at the moment, preselection voting is not returned, if the main nodes in the working state and normal do not exist, preselection voting is returned, when the number of the received preselection voting is larger than a certain number, namely, the number is larger than a second threshold value, the preselection state enters the election state, and then the election request is sent. Wherein the second threshold may be half the number of master nodes in the distributed master-slave system.
By adopting the switching method of the master nodes in the distributed master-slave system provided by the embodiment, when the master node in the rest state enters the election state, the pre-election request is sent firstly through the pre-election state, the master node receiving the pre-election request judges whether the master node which normally works exists at present, if yes, the master node sending the pre-election request has problems, at the moment, the pre-election voting is not returned, only the master node which normally works does not exist, the pre-election voting is returned, and when the number of the received pre-election voting meets the requirement, the master node enters the election state from the pre-election state, so that the probability that the redundant master node initiates new elections due to the problems of the master node is.
Optionally, in an embodiment, the master node that receives the election request is further configured to send the election vote only once within one cycle number, and when two or more election requests are received, return the election vote to the master node that sent the election request first.
Specifically, the master node receiving the election request follows the principle of only casting once and casting first in one cycle when determining whether to return the election vote, wherein the priority of each principle can be configured.
By adopting the method for switching the master nodes in the distributed master-slave system provided by the embodiment, the probability that two or more master nodes are elected as working master nodes can be reduced through the voting principle.
Optionally, in an embodiment, after receiving the task request sent by the client, the switching method further includes: writing task data corresponding to the task request into a database, wherein the task data comprises a task identifier, a task command and task parameters; the task entries in the local log are arranged in sequence, and the step of distributing the tasks corresponding to the unfinished task entries in the local log to the slave nodes comprises the following steps: inquiring incomplete task entries in a local log; acquiring task identifiers in a plurality of uncompleted task items; reading task data in a database in batches according to the obtained task identifiers; and distributing the tasks to the slave nodes according to the acquired task data.
Specifically, after a task request is received, task data is written into a database, task identifiers and task states are set in task entries of local logs, and task commands, task parameters and the like are not set, so that modification of the task commands, the task parameters and the like is not required when the local logs are modified by a working master node, the data size of modified information is reduced, and the modified information can be synchronized to other redundant master nodes. The task entries in the local log of the work master node are arranged in sequence, when tasks corresponding to unfinished task entries in the local log are distributed to the slave nodes, firstly, unfinished tasks are determined according to task states in the task entries in the local log, then task identifiers of the unfinished tasks are obtained in batches, corresponding task data are obtained in a database according to the task identifiers, and finally, the tasks are distributed to the slave nodes in batches according to the obtained task data.
By adopting the switching method of the master nodes in the distributed master-slave system, on one hand, task data such as task commands and task parameters are written into the database and are not arranged in the local log, so that the data volume of the working master nodes for synchronously modifying information to the redundant master nodes can be reduced, on the other hand, the task data are arranged in the database, the task distribution efficiency is improved through batch acquisition and batch distribution, and the pressure for accessing the database interface is reduced.
Optionally, in an embodiment, the step of allocating the task to the slave node according to the obtained task data includes: and distributing the tasks with the same task command to the same slave node.
By adopting the switching method of the master node in the distributed master-slave system provided by the embodiment, the tasks with the same task command are distributed to the same slave node, so that the slave nodes can execute the same task command in batch, and the speed of executing the tasks by the slave nodes is improved.
Example two
Corresponding to the first embodiment, a second embodiment of the present invention provides a switching device for master nodes in a distributed master-slave system, where the distributed master-slave system includes a plurality of slave nodes and a plurality of master nodes, and the states of the master nodes include a working state, a rest state, and an election state, where the master node in the working state sends heartbeat information to the master node in the rest state at preset time intervals, and related technical features and corresponding technical effects may refer to the first embodiment, and are not described herein again. Specifically, fig. 2 is a block diagram of a switching device for a master node in a distributed master-slave system according to a second embodiment of the present invention, and as shown in fig. 2, the switching device includes: a first state switching module 201, an election request sending module 202, a second state switching module 203, a task request receiving module 204, a task entry new building module 205, a log updating module 206, a task allocation module 207, and a heartbeat information processing module 208.
The first state switching module 201 is configured to enter an election state from a rest state when it is monitored that heartbeat information is out of time; an election request sending module 202, configured to send an election request, where a master node that receives the election request is used to feed back an election vote; the second state switching module 203 is configured to enter a working state from an election state when the number of the received election votes meets a first preset condition; a task request receiving module 204, configured to receive a task request sent by a client; the task item creating module 205 is configured to create a task item corresponding to the task request, where the task item includes a task identifier and a task state; a log update module 206, configured to write the task entry into the local log; the task allocation module 207 is configured to allocate the tasks corresponding to the incomplete task entries in the local log to the slave nodes, and the log update module 206 is further configured to update the corresponding task states according to the execution progress returned by the slave nodes; and the heartbeat information processing module 208 is configured to carry the modification information to the heartbeat information when the local log is modified, where the master node that receives the modification information is configured to modify its own log according to the modification information.
Optionally, in an embodiment, the election request sending module 202 is further configured to, after entering the election state from the rest state, before sending the election request, take a task identifier in a latest task entry in the local log as a detection identifier to be carried to the election request; and the master node receiving the election request is also used for comparing the detection identifier with the task identifier in the self log, and returning the election vote when the self log does not comprise the detection identifier or the task identifier in the latest task entry in the self log is the same as the detection identifier.
Optionally, in an embodiment, each master node maintains its own cycle sequence number, and the election request sending module 202 is further configured to update its own cycle sequence number after entering the election state from the rest state and before sending the election request, and carry the updated cycle sequence number as the detection sequence number to the election request, where the master node that receives the election request is configured to compare the detection sequence number with its own cycle sequence number, and return the election vote when its own cycle sequence number is not newer than the detection sequence number; the heartbeat information processing module 208 is further configured to carry the elected information to the heartbeat information after the election state enters the working state, where the master node that receives the elected information updates its own cycle sequence number.
Optionally, in an embodiment, the states of the master node further include a pre-election state, and when the first state switching module 201 enters the election state from the rest state, the specifically executed steps include: entering a pre-election state from a rest state, and sending a pre-election request, wherein a main node receiving the pre-election request judges whether a main node in a working state and normal exists at present, and if the main node in the working state and normal does not exist, returning to pre-election voting; and when the number of the received pre-election votes is larger than a second threshold value, entering an election state from a pre-election state.
Optionally, in an embodiment, the master node that receives the election request is further configured to send the election vote only once within one cycle number, and when two or more election requests are received, return the election vote to the master node that sent the election request first.
Optionally, in an embodiment, the switching device further includes a database writing module, configured to write task data corresponding to the task request into the database after the task request receiving module 204 receives the task request sent by the client, where the task data includes a task identifier, a task command, and a task parameter; the task entries in the local log are arranged in sequence, and when the task allocation module 207 allocates the tasks corresponding to the uncompleted task entries in the local log to the slave nodes, the specific steps executed include: inquiring incomplete task entries in a local log; acquiring task identifiers in a plurality of uncompleted task items; reading task data in a database in batches according to the obtained task identifiers; and distributing the tasks to the slave nodes according to the acquired task data.
Optionally, in an embodiment, when allocating a task to a slave node according to the acquired task data, the task allocation module 207 allocates a task with the same task command to the same slave node.
EXAMPLE III
The embodiment also provides a computer device, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server or a rack server (including an independent server or a server cluster composed of a plurality of servers) capable of executing programs, and the like. As shown in fig. 3, the computer device 01 of the present embodiment at least includes but is not limited to: a memory 011 and a processor 012, which are communicatively connected to each other via a system bus, as shown in fig. 3. It is noted that fig. 3 only shows the computer device 01 having the component memory 011 and the processor 012, but it is to be understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead.
In this embodiment, the memory 011 (i.e., a readable storage medium) includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the storage 011 can be an internal storage unit of the computer device 01, such as a hard disk or a memory of the computer device 01. In other embodiments, the memory 011 can also be an external storage device of the computer device 01, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. provided on the computer device 01. Of course, the memory 011 can also include both internal and external memory units of the computer device 01. In this embodiment, the memory 011 is generally used for storing an operating system installed in the computer device 01 and various application software, such as program codes of the switching device of the master node in the distributed master-slave system in the second embodiment. Further, the memory 011 can also be used to temporarily store various kinds of data that have been output or are to be output.
The processor 012 may be a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor, or other data Processing chip in some embodiments. The processor 012 is generally used to control the overall operation of the computer device 01. In this embodiment, the processor 012 is configured to run a program code stored in the memory 011 or process data, such as a master node switching method in a distributed master-slave system.
Example four
The present embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application mall, etc., on which a computer program is stored, which when executed by a processor implements corresponding functions. The computer-readable storage medium of this embodiment is used to store a switching apparatus for master nodes in a distributed master-slave system, and when executed by a processor, the switching apparatus implements the method for switching master nodes in a distributed master-slave system according to the first embodiment.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for switching master nodes in a distributed master-slave system is characterized in that the distributed master-slave system comprises a plurality of slave nodes and a plurality of master nodes, the states of the master nodes comprise a working state, a rest state and an election state, wherein the master nodes in the working state send heartbeat information to the master nodes in the rest state at preset intervals, and the switching method comprises the following steps:
when the heartbeat information is monitored to be out of time, the rest state enters the election state, and an election request is sent, wherein the main node receiving the election request is used for returning election voting;
when the number of the received election votes is larger than a first threshold value, entering the working state from the election state;
receiving a task request sent by a client;
establishing a task item corresponding to the task request, wherein the task item comprises a task identifier and a task state;
writing the task entry to the local log;
distributing the tasks corresponding to the uncompleted task entries in the local log to the slave nodes, and updating the corresponding task states according to the execution progress returned by the slave nodes;
and when the local log is modified, carrying modification information to the heartbeat information, wherein the master node receiving the modification information is used for modifying the log of the master node according to the modification information.
2. The method for switching master nodes in a distributed master-slave system according to claim 1, wherein after entering the election state from the rest state and before sending an election request, the method further comprises:
taking a task identifier in the latest task entry in the local log as a detection identifier and carrying the detection identifier to the election request;
and the master node receiving the election request is also used for comparing the detection identifier with the task identifier in the self log, and returning the election vote when the self log does not comprise the detection identifier or the task identifier in the latest task entry in the self log is the same as the detection identifier.
3. The method for switching master nodes in a distributed master-slave system according to claim 1, wherein each master node maintains its own cycle number, and the method further comprises:
after the rest state enters the election state and before an election request is sent, updating a cycle sequence number of the main node, taking the updated cycle sequence number as a detection sequence number to be carried to the election request, wherein the main node receiving the election request is used for comparing the detection sequence number with the cycle sequence number of the main node, and returning the election voting when the cycle sequence number of the main node is not new to the detection sequence number; and
and after the election state enters the working state, carrying elected information to the heartbeat information, wherein the main node receiving the elected information updates the cycle sequence number of the main node.
4. The method for switching master nodes in a distributed master-slave system according to claim 3, wherein the states of the master nodes further include a pre-election state, and the step of entering the election state from the rest state comprises:
entering the pre-election state from the rest state, and sending a pre-election request, wherein the main node receiving the pre-election request judges whether a main node in the working state and normal exists at present, and if the main node in the working state and normal does not exist, returning a pre-election vote;
and when the received number of the pre-election votes is larger than a second threshold value, entering the election state from the pre-election state.
5. The method as claimed in claim 3, wherein the master node receiving the election request is further configured to send the election vote only once within one of the cycle numbers, and when two or more election requests are received, return the election vote to the master node that sent the election request first.
6. The method for master node handover in a distributed master-slave system according to claim 1,
after receiving the task request sent by the client, the switching method further comprises the following steps: writing task data corresponding to the task request into a database, wherein the task data comprises the task identifier, a task command and task parameters;
the task entries in the local log are arranged in sequence, and the step of distributing the tasks corresponding to the task entries which are not completed in the local log to the slave nodes comprises the following steps: querying the incomplete task entry in the local log; acquiring task identifiers in a plurality of uncompleted task items; reading task data in the database in batches according to the obtained task identifiers; and distributing tasks to the slave nodes according to the acquired task data.
7. The method according to claim 6, wherein the step of allocating the task to the slave node according to the acquired task data comprises:
and distributing the tasks with the same task command to the same slave node.
8. A switching device of master nodes in a distributed master-slave system is characterized in that the distributed master-slave system comprises a plurality of slave nodes and a plurality of master nodes, the states of the master nodes comprise a working state, a rest state and an election state, wherein the master nodes in the working state send heartbeat information to the master nodes in the rest state at preset intervals, and the switching device comprises:
the first state switching module is used for entering the election state from the rest state when the heartbeat information is monitored to be out of time;
an election request sending module, configured to send an election request, where the master node that receives the election request is configured to feed back an election vote;
the second state switching module is used for entering the working state from the election state when the number of the received election votes meets a first preset condition;
the task request receiving module is used for receiving a task request sent by a client;
the task item newly-establishing module is used for establishing a task item corresponding to the task request, wherein the task item comprises a task identifier and a task state;
the log updating module is used for writing the task entries into the local log;
the task distribution module is used for distributing tasks corresponding to the task entries which are not completed in the local log to the slave nodes, and the log updating module is further used for updating the corresponding task states according to the execution progress returned by the slave nodes;
and the heartbeat information processing module is used for carrying modification information to the heartbeat information when the local log is modified, wherein the master node receiving the modification information is used for modifying the log of the master node according to the modification information.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 7 are implemented by the processor when executing the computer program.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that: the computer program when executed by a processor implements the steps of the method of any one of claims 1 to 7.
CN201911183863.6A 2019-11-27 2019-11-27 Method and device for switching master nodes in distributed master-slave system and computer equipment Active CN112865992B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911183863.6A CN112865992B (en) 2019-11-27 2019-11-27 Method and device for switching master nodes in distributed master-slave system and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911183863.6A CN112865992B (en) 2019-11-27 2019-11-27 Method and device for switching master nodes in distributed master-slave system and computer equipment

Publications (2)

Publication Number Publication Date
CN112865992A true CN112865992A (en) 2021-05-28
CN112865992B CN112865992B (en) 2022-10-14

Family

ID=75984913

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911183863.6A Active CN112865992B (en) 2019-11-27 2019-11-27 Method and device for switching master nodes in distributed master-slave system and computer equipment

Country Status (1)

Country Link
CN (1) CN112865992B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113325689A (en) * 2021-08-02 2021-08-31 中国人民解放军海军工程大学 Full-time domain hot standby method of control system based on data synchronization
CN113923222A (en) * 2021-12-13 2022-01-11 云和恩墨(北京)信息技术有限公司 Data processing method and device
CN114363350A (en) * 2021-12-14 2022-04-15 中科曙光南京研究院有限公司 Service management system and method
CN115102839A (en) * 2022-06-17 2022-09-23 济南浪潮数据技术有限公司 Master-slave node election method, device, equipment and medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104933132A (en) * 2015-06-12 2015-09-23 广州巨杉软件开发有限公司 Distributed database weighted voting method based on operating sequence number
CN105554142A (en) * 2015-12-24 2016-05-04 北京奇虎科技有限公司 Method, apparatus and system for pushing messages
CN106789197A (en) * 2016-12-07 2017-05-31 高新兴科技集团股份有限公司 A kind of cluster election method and system
CN107124305A (en) * 2017-04-20 2017-09-01 腾讯科技(深圳)有限公司 node device operation method and node device
US20170270176A1 (en) * 2010-12-23 2017-09-21 Eliot Horowitz System and method for determining consensus within a distributed database
CN108810100A (en) * 2018-05-22 2018-11-13 郑州云海信息技术有限公司 A kind of electoral machinery of host node, device and equipment
CN108989391A (en) * 2018-06-19 2018-12-11 北京百悟科技有限公司 A kind of method and device of consistency treatment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170270176A1 (en) * 2010-12-23 2017-09-21 Eliot Horowitz System and method for determining consensus within a distributed database
CN104933132A (en) * 2015-06-12 2015-09-23 广州巨杉软件开发有限公司 Distributed database weighted voting method based on operating sequence number
CN105554142A (en) * 2015-12-24 2016-05-04 北京奇虎科技有限公司 Method, apparatus and system for pushing messages
CN106789197A (en) * 2016-12-07 2017-05-31 高新兴科技集团股份有限公司 A kind of cluster election method and system
CN107124305A (en) * 2017-04-20 2017-09-01 腾讯科技(深圳)有限公司 node device operation method and node device
CN108810100A (en) * 2018-05-22 2018-11-13 郑州云海信息技术有限公司 A kind of electoral machinery of host node, device and equipment
CN108989391A (en) * 2018-06-19 2018-12-11 北京百悟科技有限公司 A kind of method and device of consistency treatment

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113325689A (en) * 2021-08-02 2021-08-31 中国人民解放军海军工程大学 Full-time domain hot standby method of control system based on data synchronization
CN113325689B (en) * 2021-08-02 2021-12-28 中国人民解放军海军工程大学 Full-time domain hot standby method of control system based on data synchronization
CN113923222A (en) * 2021-12-13 2022-01-11 云和恩墨(北京)信息技术有限公司 Data processing method and device
CN113923222B (en) * 2021-12-13 2022-05-31 云和恩墨(北京)信息技术有限公司 Data processing method and device
CN114363350A (en) * 2021-12-14 2022-04-15 中科曙光南京研究院有限公司 Service management system and method
CN114363350B (en) * 2021-12-14 2024-04-16 中科曙光南京研究院有限公司 Service management system and method
CN115102839A (en) * 2022-06-17 2022-09-23 济南浪潮数据技术有限公司 Master-slave node election method, device, equipment and medium
CN115102839B (en) * 2022-06-17 2024-02-09 济南浪潮数据技术有限公司 Master-slave node election method, device, equipment and medium

Also Published As

Publication number Publication date
CN112865992B (en) 2022-10-14

Similar Documents

Publication Publication Date Title
CN112865992B (en) Method and device for switching master nodes in distributed master-slave system and computer equipment
CN106789362B (en) Equipment management method and network management system
US11888933B2 (en) Cloud service processing method and device, cloud server, cloud service system and storage medium
CN107844343B (en) Upgrading system and method for complex server application system
CN102567438A (en) Method for providing access to data items from a distributed storage system
CN111314479A (en) Data processing method and equipment
CN112558997A (en) Method and device for deploying applications
CN107819556B (en) Service state switching method and device
CN110704172B (en) Cluster system timing task scheduling method and cluster system
CN111884834A (en) Zookeeper-based distributed system upgrading method and system and computer equipment
CN106533751B (en) SDN controller cluster merging method and device
CN112860787A (en) Method for switching master nodes in distributed master-slave system, master node device and storage medium
CN112865995B (en) Distributed master-slave system
CN113946427A (en) Task processing method, processor and storage medium for multi-operating system
CN110737670A (en) cluster data consistency guarantee method, device and system
CN112865993A (en) Method and device for switching slave nodes in distributed master-slave system
CN112416542A (en) Distributed task system, management method and device and computer equipment
CN113608831B (en) Plug-in instance management method, system, storage medium and equipment
CN112866314B (en) Method for switching slave nodes in distributed master-slave system, master node device and storage medium
CN110650059B (en) Fault cluster detection method, device, computer equipment and storage medium
CN110489208B (en) Virtual machine configuration parameter checking method, system, computer equipment and storage medium
CN111414242B (en) Method, device, server, system and storage medium for operating state machine
CN112631727B (en) Monitoring method and device for pod group pod
CN115905271B (en) Virus library updating method and device and multi-engine detection system
CN115202901A (en) Method and device for determining microservice instance identifier, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant