CN111538763B - Method for determining master node in cluster, electronic equipment and storage medium - Google Patents

Method for determining master node in cluster, electronic equipment and storage medium Download PDF

Info

Publication number
CN111538763B
CN111538763B CN202010335432.3A CN202010335432A CN111538763B CN 111538763 B CN111538763 B CN 111538763B CN 202010335432 A CN202010335432 A CN 202010335432A CN 111538763 B CN111538763 B CN 111538763B
Authority
CN
China
Prior art keywords
node
master
information
cluster
database
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.)
Active
Application number
CN202010335432.3A
Other languages
Chinese (zh)
Other versions
CN111538763A (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.)
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
MIGU Culture 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 China Mobile Communications Group Co Ltd, MIGU Culture Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202010335432.3A priority Critical patent/CN111538763B/en
Publication of CN111538763A publication Critical patent/CN111538763A/en
Application granted granted Critical
Publication of CN111538763B publication Critical patent/CN111538763B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Probability & Statistics with Applications (AREA)
  • Fuzzy Systems (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a method, electronic equipment and storage medium for determining a master node in a cluster, wherein any target node in the cluster interacts with a database, whether the target node is used as the master node is determined from node information corresponding to each node in the database, and if so, first information for marking the target node as the master node is sent to the database. And when the master node does not exist, the master node is determined according to the node information every time, so that the existence of multiple master nodes is avoided, and the disorder of service order and the waste of resources are avoided. Meanwhile, node information is stored through the database, and special hardware equipment is not needed to be newly added in the determining process of the master node.

Description

Method for determining master node in cluster, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method for determining a master node in a cluster, an electronic device, and a storage medium.
Background
With the development of the internet, the user volume is huge, and a common single-machine application cannot meet the requirement of high-concurrency application, but in order to solve the high-concurrency and high-availability scene, the common application uses a cluster to provide services to the outside. However, a master host is typically selected from the cluster to perform specific tasks.
Existing methods are generally based on a third party with a weight level of zookeeper or use a host-standby machine to realize master election in a traditional way. In the manner of the master-slave machine, the master machine acts as a master to complete processing of various services, while the standby node (slave machine) periodically sends Ping packets to the current master node, and after receiving the Ping packets, the master node sends response ack messages to the standby node, and when the standby node receives the response, the master machine is considered to be still alive and to continue to provide services, otherwise, the master machine is considered to hang up and to start to exercise the role of the master node and act as the master.
However, the following hidden danger exists mainly for the traditional master-slave mode: when the network of the host and the standby has a problem, the standby can not receive the ack reply message of the host, the standby can consider that the host node is hung up, and then the standby can automatically start the master instance. This results in 2 master nodes in the system, i.e., a dual master, and thus the entire service is cluttered. Meanwhile, the traditional 2 machine nodes, namely the slave node is generally used as a standby machine, namely the slave node does not provide service, and only when the host machine is down, the slave node receives the service, so that the waste of system resources is caused, and one machine is idle.
The addition of the zookeeper cluster for the traditional application is equivalent to adding a piece of heavy equipment, and meanwhile, the zookeeper cluster is also subjected to maintenance monitoring. And the master election is realized basically by relying on the minimum sequence numbers of preemption and registration, and the elected host has randomness and poor controllability.
Therefore, the existing master node determining process has the hidden trouble of a plurality of master nodes, so that the service order is disordered and the resources are wasted, or corresponding hardware equipment is required to be added.
Disclosure of Invention
The embodiment of the application provides a method for determining master nodes in a cluster, electronic equipment and a storage medium, which are used for solving the problems that the existing master node determination process has hidden danger of a plurality of master nodes, causes disorder of service order and waste of resources, or needs to add corresponding hardware equipment.
In view of the above technical problems, in a first aspect, an embodiment of the present application provides a method for determining a master node in a cluster, including:
if any target node in the cluster judges that the master node does not exist currently, determining whether the target node is used as the master node according to node information corresponding to each node of the cluster stored in a database;
and if the target node is used as a master node, transmitting first information for marking the target node as the master node to the database.
In a second aspect, an embodiment of the present application provides a method for determining a master node in a cluster, including:
and if the first information of marking the target node in the cluster as the main node is received, adding the mark of the main node into the node information of the target node.
In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the method for determining a master node in a cluster described above when the program is executed by the processor.
In a fourth aspect, embodiments of the present application provide a non-transitory readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of determining a master node in a cluster as described in any of the preceding claims.
The embodiment of the application provides a method, electronic equipment and storage medium for determining a master node in a cluster, wherein any target node in the cluster interacts with a database, whether the target node is used as the master node is determined from node information corresponding to each node in the database, and if so, first information for marking the target node as the master node is sent to the database. And when the master node does not exist, the master node is determined according to the node information every time, so that the existence of multiple master nodes is avoided, and the disorder of service order and the waste of resources are avoided. Meanwhile, node information is stored through the database, and special hardware equipment is not needed to be newly added in the determining process of the master node.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the present application, and other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of an election process of a master/slave election master provided by an embodiment of the present application;
FIG. 2 is a flowchart of a method for determining a master node in a cluster, which is applicable to any host in the cluster according to another embodiment of the present application;
FIG. 3 is a schematic diagram illustrating an implementation process of a queue inserting mechanism in a master node election process according to another embodiment of the present application;
FIG. 4 is a schematic flow chart of a master node election provided by another embodiment of the present application;
FIG. 5 is a flowchart illustrating a method for determining master nodes in a cluster for a database according to another embodiment of the present application;
FIG. 6 is a block diagram of an apparatus for determining a master node in a cluster corresponding to any node in the cluster according to another embodiment of the application;
FIG. 7 is a block diagram of an apparatus for determining a master node in a cluster corresponding to a database according to another embodiment of the present application;
fig. 8 is a schematic physical structure of an electronic device according to another embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The embodiment provides a method for determining a master node in a cluster, which is realized by any host and database configuration of the cluster. Fig. 2 is a flow chart of a method for determining a master node in a cluster, which is applicable to any host in the cluster, and referring to fig. 2, the method includes:
step 201: if any target node in the cluster does not exist at present, determining whether the target node is used as a master node according to node information corresponding to each node of the cluster stored in a database.
A cluster is a network composed of a plurality of nodes, each of which is a host, a server, or a computer, which is not particularly limited in this embodiment.
The node information comprises a time point when each node executes a preset instruction and basic information of the node; the basic information of the node comprises the machine IP, the machine name, a primary key, the type of an operating system, the installation time of the operating system, the refreshing update time and the like of the node. The preset instruction includes an instruction that the node performs a certain function, for example, the preset instruction includes storing node information corresponding to the node into the database (i.e. registering in the database), initializing the node, starting a certain application program by the node, sending a certain message by the node, and the embodiment is not limited in this way.
The database is an arbitrary relational database, for example, mysql, sqlserver, oracle and the like. The data is conveniently read and stored through the relational database, and the storage function of the relational database is only required to be applied to the technical scheme of the application, and other hardware devices are not required to be additionally arranged.
Step 202: and if the target node is used as a master node, transmitting first information for marking the target node as the master node to the database.
Wherein, still include: and executing a setting task through the master node or coordinating each node in the cluster.
The embodiment provides a method for determining a master node in a cluster, any target node in the cluster interacts with a database, whether the target node is used as the master node is determined according to node information corresponding to each node in the cluster in the database, and if so, first information for marking the target node as the master node is sent to the database. And when the master node does not exist, the master node is determined according to the node information every time, so that the existence of multiple master nodes is avoided, and the disorder of service order and the waste of resources are avoided. Meanwhile, node information is stored through the database, and special hardware equipment is not needed to be newly added in the determining process of the master node.
Further, on the basis of the foregoing embodiment, the determining, according to node information corresponding to each node of the cluster stored in the database, whether to use the target node as a master node includes:
determining election time points corresponding to the nodes according to the node information, and determining target election time points according to first time intervals between the election time points and the current time points;
if the node corresponding to the target election time point is the target node, the target node is used as a main node;
the election time point is a time point when the node executes a preset instruction, and the preset instruction comprises storing node information corresponding to the node into the database or initializing the node.
The election time point is determined from a plurality of time points stored in the node information, and is used for performing the election of the master node. After the election time point is determined for each node, the master node can be determined according to the election time point corresponding to each node. The time point when the node executes a certain same preset instruction (for example, the time point when the node is initialized is used as the election time point) can be taken as the election time point after judging that the master node does not exist at present each time, or the time point when the node executes different preset instructions (for example, when judging that the master node does not exist at present for the first time or the first time, the time point when storing the node information corresponding to the node into the database is taken as the election time point, and when judging that the master node does not exist at present after not the first time or the first time, the time point when initializing the node is taken as the election time point).
The method for determining the target election time point according to the first time interval between each election time point and the current time point comprises the following steps:
acquiring the longest first time length or the shortest first time length corresponding to the election time point as a target election time point according to the first time length between each election time point and the current time point;
if a plurality of election time points exist in the longest first time or the shortest first time, randomly selecting one election time point from the plurality of election time points as a target election time point.
According to the embodiment, after judging that the master node does not exist currently, the master node is elected according to the elected time point determined by the node information. The election of the master node is uniquely determined according to the election time point of each node, thereby avoiding the generation of multiple master nodes and improving the rationality of the election of the master node.
In this embodiment, each time a node executes a different preset instruction is taken as an election time point, further, on the basis of the foregoing embodiments, the determining, according to the node information, an election time point corresponding to each node, and determining, according to a first time interval between each election time point and a current time point, a target election time point includes:
determining a preset instruction corresponding to the number of times that the main node does not exist at present according to the preset corresponding relation, and taking the preset instruction as a target preset instruction;
and determining a target election time point according to the target preset instruction and the node information, and the election time point corresponding to each node according to the first time interval between each election time point and the current time point.
The preset corresponding relation is a preset instruction which is stored in advance and corresponds to the number of times that the main node does not exist at present. The preset correspondence may be set as needed, for example, a time point when it is determined for the first time that the master node does not exist at present is set as an election time point to execute a preset instruction of "store node information corresponding to a node to the database". When the primary node is not judged to exist currently for the first time, the time point for executing the preset instruction of initializing the node is taken as the election time point.
Specifically, when the fact that a master node does not exist currently is judged for the first time, acquiring time points of each node for storing node information into the database according to the node information, taking the time points as election time points, and determining target election time points according to first time intervals between each election time point and the current time point;
and when the fact that the master node does not exist currently is not judged for the first time, acquiring time points of each node for initializing the nodes according to the node information, taking the time points as election time points, and determining target election time points according to first time intervals between each election time point and the current time point.
According to the method and the device, according to the preset instructions corresponding to the times that the main node does not exist in the current judgment, the election time point is determined from the node information, the determination of the election time point can be set through the preset corresponding relation, and the election activity of the main node is improved.
In some scenarios, it is required to cause a specific certain node to be elected as a master node, i.e. implement "queuing" of nodes, and further, based on the above embodiments, further include:
generating a time modification instruction, wherein the time modification instruction is used for modifying an election time point corresponding to a node in the database;
and sending the time modification instruction to the database so that the database modifies the election time point corresponding to the node according to the time modification instruction.
And after receiving a modification request for modifying the election time point corresponding to the node in the cluster, the target node generates the time modification instruction. The modification request may be a request input to the target node by the user through the interactive interface, which is not particularly limited in this embodiment.
The time modification instruction generated by the target node is used for requesting to modify an election time point corresponding to the target node or requesting to modify an election time point corresponding to a node except the target node in the cluster nodes.
For example, when it is required to make the target node be selected as the master node, a time modification instruction may be sent to the database, and the election time point corresponding to the target node is modified, so that the target node can be determined as the master node according to the first duration of the election time point and the current time point. For example, when the node corresponding to the shortest first time length needs to be selected as the master node, the election time point of a certain node can be modified by the time modification instruction, so that the first time length corresponding to the target node after modification is shortest, and the target node can be elected as the master node.
According to the embodiment, the time point of election of each node of the cluster is modified through the time modification instruction, so that a specific node is subjected to 'queue' in the election process of the master node, and the specific node is elected as the master node. The "dequeue" mechanism increases the controllability of master node election.
Specifically, the embodiment records node information through the database, and uses the election time point (the election time point is the time point of executing the preset instruction or the time point of setting the node according to the time setting instruction) and adds a reasonably ordered 'queue' mechanism (i.e. the election time point is modified by the time modification instruction) to ensure that the master is acted as a reasonable host, so that the whole mechanism is optimized, the master is not randomly or orderly changed any more, and the priority can be configured according to each host.
Fig. 3 is a schematic diagram of an implementation process of a "dequeue" mechanism in a master node election process provided in this embodiment, and referring to fig. 3, the implementation process of the "dequeue" mechanism includes the following contents:
(1) The operating system initialization time of the machine is obtained.
(2) After judging that the master host is down, deleting the recorded information of the original master.
(3) According to the value of init_time (i.e., the operating system initialization time, i.e., the time for initializing the node) of the server_info table, the latest machine modification registration time is selected as the minimum registration time for all machines.
(4) The system will reselect the host and determine the machine with the minimum registration time as master.
Further, on the basis of the above embodiments, the method further includes:
judging whether an abnormal node exists according to the heartbeat time points periodically reported by all the nodes in the database, wherein the abnormal node is a node with a second time length longer than a preset time length between the latest reported heartbeat time point and the current time point;
and if the abnormal node exists, sending second information for deleting the node information of the abnormal node to the database.
Wherein the preset time period is 1 minute.
Each node reports the current time point every 30 seconds as a heartbeat time point.
According to the embodiment, whether the hosts are down or not is identified through the heartbeat time point, so that the down nodes can be timely eliminated from participating in the election of the main nodes, and the situation of multiple main nodes is effectively avoided.
Further, on the basis of the above embodiments, the method further includes:
judging whether node information marked as a master node exists according to the node information of each node currently stored in the database, and if not, judging that the master node does not exist in each node of the cluster currently.
If it is determined that node information marked as a master node exists, election of the master node is not required.
The embodiment realizes the judgment of whether the master node exists in the cluster currently or not through the marking of the master node.
Fig. 4 is a schematic flow chart of master node election provided in this embodiment, referring to fig. 4, the flow chart specifically includes the following contents:
(1) Each host starts, acquires own service IP, writes the IP into a database table server_master, and the register_time is the current software start time, the refresh time is the same as the registration time, and the is_master field is marked as no.
(2) Each machine simultaneously checks the initialization installation time of the operating system when starting, and can detect according to the modification time of the system file and simultaneously acquire the type and the machine name of the operating system. These information are written into the server_info host information table.
(3) Every host updates the refresh_time field of the server_master table of the database at 30 seconds intervals, indicating the heartbeat of the host.
(4) When each host updates the heartbeat for the first time, judging whether the host can become a master or not; traversing all records of a server_master table, acquiring a record of a machine with earliest registration time register_time, checking whether the IP of the record is matched with the IP of the machine of the record, if so, identifying the record as a master role, and updating an is_master field in the record as true.
(5) The machine that acquires master rights then performs the task belonging to the master.
(6) Subsequent heartbeat detection if there is a host whose refresh_time minus the current time is greater than 1 minute that has not been updated, the record is deleted, indicating that the host has been disconnected. If the master role is down, the authority of the master can be released when the heartbeat fails, and the corresponding master task can be released.
(7) After the master host is released, the system needs to reselect the master, at this time, each host reads the information of the server_info, determines the using time of the machine according to the init_time (the system installation initialization time), if the init_time is shortest from the current time, the host is the latest, and the machine which is the same as the own IP will take the registration time (modified according to the IP) of updating the server_master table, and updates the registration time to the smallest of all the registration times.
(8) In the subsequent heartbeat, when all machines detect the registration time, the machine with the smallest registration time, i.e. the machine which is the latest, is successfully elected as the master host.
Fig. 5 is a flowchart of a method for determining a master node in a cluster suitable for a database according to the present embodiment, and referring to fig. 5, the method includes:
step 501: and if the first information of marking the target node in the cluster as the main node is received, adding the mark of the main node into the node information of the target node.
The first information is information sent by any node (e.g., target node) in the cluster, which is used to indicate that the target node is marked as a master node.
The embodiment provides a method for determining a master node in a cluster, any target node in the cluster interacts with a database, whether the target node is used as the master node is determined according to node information corresponding to each node in the cluster in the database, and if so, first information for marking the target node as the master node is sent to the database. And when the master node does not exist, the master node is determined according to the node information every time, so that the existence of multiple master nodes is avoided, and the disorder of service order and the waste of resources are avoided. Meanwhile, node information is stored through the database, and special hardware equipment is not needed to be newly added in the determining process of the master node.
Further, on the basis of the above embodiment, the method further includes:
and if the time modification instruction is received, modifying the election time point corresponding to the node according to the time modification instruction.
Wherein, still include;
if node information sent by the nodes and/or heartbeat time points periodically reported by the nodes are received, storing the received node information and/or the heartbeat time points;
and if the second information for deleting the node information of the abnormal node is received, deleting the node information of the abnormal node.
It should be noted that, in the method provided in this embodiment, for each node of the cluster in the database, one list is used to access node information of each node, and the other Zhang Liebiao is used to access a heartbeat time point of the node. Two tables are created in a database, wherein one table accesses basic information and election time points of each node, the election time points corresponding to each node are included in a list of maintaining node information, and when a time modification instruction for modifying the election time point of a certain node is received by the database, the election time point corresponding to the node is modified.
According to the method for determining the master node in the cluster, the relational database is used for storing the networking information of the host, the master is elected according to the registration time and the installation initialization time of the operating system, and the installation initialization time of the operating system can be modified, so that the queue can be inserted in the elected, and the controllability of the elected is improved. Has the following advantages: compared with the traditional master-slave mode, the hidden danger of double masters is eliminated. Registration information is performed by utilizing a database, and zookeeper heavyweight software does not need to be installed. The master election of various conditions is fully considered, such as time sequence election, and the time mechanism is adjusted to perform the queue election.
In the method provided in the above embodiments, the database is used to store node information and a heartbeat time point sent by the node, and send information needed by the node to the node. The process is carried out by the nodes, the nodes read the node information from the database, the master node is elected, and the time modification instruction is sent to the database, so that the database does not actively participate in the election process of the master node and the active modification process of the election time point. Therefore, the developer only needs to develop on the node side for the process, and directly call the access function of the database. However, in practice, for some databases that are convenient for developers to develop, the election of the master node may also be implemented by the following procedure:
and the database judges whether a node marked as a master node exists currently, if not, the master node is determined according to the election time point corresponding to each node, and the node identification corresponding to the determined master node is sent to each node of the cluster.
Further comprises: and after receiving a modification request for modifying the election time point corresponding to the target node, modifying the election time point corresponding to the target node according to the modification request.
Further comprises: and receiving heartbeat time points periodically reported by all nodes of the cluster, and storing the heartbeat time points corresponding to the nodes.
Further comprises: judging whether abnormal nodes exist according to the heartbeat time points corresponding to the nodes, and if so, deleting node information corresponding to the abnormal nodes.
The abnormal node is a node with a second time length longer than a preset time length between the latest reported heartbeat time point and the current time point.
Fig. 6 is a block diagram of an apparatus for determining a master node in a cluster, corresponding to any node in a cluster, provided in this embodiment, and referring to fig. 6, the apparatus for determining a master node in a cluster includes a determining module 601 and a sending module 602, where,
a determining module 601, configured to determine whether to use the target node as a master node according to node information corresponding to each node of the cluster stored in the database if it is determined that the master node does not exist currently;
and the sending module 602 is configured to send, if the target node is used as a master node, first information for marking the target node as the master node to the database.
The device for determining the master node in the cluster provided in this embodiment is applicable to the method for determining the master node in the cluster corresponding to any node in the cluster provided in the foregoing embodiments, and will not be described herein.
The embodiment of the application provides a device for determining a master node in a cluster, wherein any target node in the cluster interacts with a database, whether the target node is taken as the master node or not is determined according to node information corresponding to each node in the database, and if so, first information for marking the target node as the master node is sent to the database. And when the master node does not exist, the master node is determined according to the node information every time, so that the existence of multiple master nodes is avoided, and the disorder of service order and the waste of resources are avoided. Meanwhile, node information is stored through the database, and special hardware equipment is not needed to be newly added in the determining process of the master node.
Optionally, the determining whether to use the target node as the master node according to node information corresponding to each node of the cluster stored in the database includes:
determining election time points corresponding to the nodes according to the node information, and determining target election time points according to first time intervals between the election time points and the current time points;
if the node corresponding to the target election time point is the target node, the target node is used as a main node;
the election time point is a time point when the node executes a preset instruction, and the preset instruction comprises storing node information corresponding to the node into the database or initializing the node.
Optionally, the method further comprises:
generating a time modification instruction, wherein the time modification instruction is used for modifying an election time point corresponding to a node in the database;
and sending the time modification instruction to the database so that the database modifies the election time point corresponding to the node according to the time modification instruction.
Optionally, the method further comprises:
judging whether an abnormal node exists according to the heartbeat time points periodically reported by all the nodes in the database, wherein the abnormal node is a node with a second time length longer than a preset time length between the latest reported heartbeat time point and the current time point;
and if the abnormal node exists, sending second information for deleting the node information of the abnormal node to the database.
Optionally, the method further comprises:
judging whether node information marked as a master node exists according to the node information of each node currently stored in the database, and if not, judging that the master node does not exist in each node of the cluster currently.
Optionally, the determining, according to the node information, an election time point corresponding to each node, and determining, according to a first time interval between each election time point and a current time point, a target election time point includes:
determining a preset instruction corresponding to the number of times that the main node does not exist at present according to the preset corresponding relation, and taking the preset instruction as a target preset instruction;
and determining a target election time point according to the target preset instruction and the node information, and the election time point corresponding to each node according to the first time interval between each election time point and the current time point.
Fig. 7 is a block diagram of an apparatus for determining a master node in a cluster corresponding to a database according to the present embodiment, and referring to fig. 7, the apparatus for determining a master node in a cluster includes a marking module 701, where,
the marking module 701 is configured to add a mark of a master node to node information of a target node in a cluster if first information of marking the target node as the master node is received.
The device for determining the master node in the cluster provided in this embodiment is applicable to the method for determining the master node in the cluster corresponding to the database provided in each embodiment, and is not described herein.
The embodiment of the application provides a device for determining a master node in a cluster, wherein any target node in the cluster interacts with a database, whether the target node is taken as the master node or not is determined according to node information corresponding to each node in the database, and if so, first information for marking the target node as the master node is sent to the database. And when the master node does not exist, the master node is determined according to the node information every time, so that the existence of multiple master nodes is avoided, and the disorder of service order and the waste of resources are avoided. Meanwhile, node information is stored through the database, and special hardware equipment is not needed to be newly added in the determining process of the master node.
Optionally, the method further comprises:
and if the time modification instruction is received, modifying the election time point corresponding to the node according to the time modification instruction.
Fig. 8 illustrates a physical structure diagram of an electronic device, as shown in fig. 8, which may include: a processor 801, a communication interface (Communications Interface) 802, a memory 803, and a communication bus 804, wherein the processor 801, the communication interface 802, and the memory 803 communicate with each other through the communication bus 804. The processor 801 may call logic instructions in the memory 803 to perform the following method: if any target node in the cluster judges that the master node does not exist currently, determining whether the target node is used as the master node according to node information corresponding to each node of the cluster stored in a database; and if the target node is used as a main node, sending first information for marking the target node as the main node to the database, or if the first information for marking the target node in the cluster as the main node is received, adding the mark of the main node into the node information of the target node.
Further, the logic instructions in the memory 803 described above may be implemented in the form of software functional units and may be stored in a computer readable storage medium when sold or used as a stand alone product. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Further, embodiments of the present application disclose a computer program product comprising a computer program stored on a non-transitory readable storage medium, the computer program comprising program instructions which, when executed by a computer, are capable of performing the methods provided by the above-described method embodiments, for example comprising: if any target node in the cluster judges that the master node does not exist currently, determining whether the target node is used as the master node according to node information corresponding to each node of the cluster stored in a database; and if the target node is used as a main node, sending first information for marking the target node as the main node to the database, or if the first information for marking the target node in the cluster as the main node is received, adding the mark of the main node into the node information of the target node.
In another aspect, an embodiment of the present application further provides a non-transitory readable storage medium having stored thereon a computer program that is implemented when executed by a processor to perform the transmission method provided in the above embodiments, for example, including: if any target node in the cluster judges that the master node does not exist currently, determining whether the target node is used as the master node according to node information corresponding to each node of the cluster stored in a database; and if the target node is used as a main node, sending first information for marking the target node as the main node to the database, or if the first information for marking the target node in the cluster as the main node is received, adding the mark of the main node into the node information of the target node.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present application without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a readable storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (9)

1. A method for determining master nodes in a cluster, comprising:
if any target node in the cluster judges that the master node does not exist currently, determining whether the target node is used as the master node according to node information corresponding to each node of the cluster stored in a database; the database is used for storing node information and heartbeat time points sent by the nodes and sending information needed by the nodes to the nodes;
if the target node is used as a main node, first information for marking the target node as the main node is sent to the database;
judging whether an abnormal node exists according to the heartbeat time points periodically reported by all the nodes in the database, wherein the abnormal node is a node with a second time length longer than a preset time length between the latest reported heartbeat time point and the current time point;
and if the abnormal node exists, sending second information for deleting the node information of the abnormal node to the database.
2. The method for determining a master node in a cluster according to claim 1, wherein determining whether to use the target node as the master node according to node information corresponding to each node of the cluster stored in a database includes:
determining election time points corresponding to the nodes according to the node information, and determining target election time points according to first time intervals between the election time points and the current time points;
if the node corresponding to the target election time point is the target node, the target node is used as a main node;
the election time point is a time point when the node executes a preset instruction, and the preset instruction comprises storing node information corresponding to the node into the database or initializing the node.
3. The method of determining a master node in a cluster of claim 2, further comprising:
generating a time modification instruction, wherein the time modification instruction is used for modifying an election time point corresponding to a node in the database;
and sending the time modification instruction to the database so that the database modifies the election time point corresponding to the node according to the time modification instruction.
4. The method of determining a master node in a cluster of claim 1, further comprising:
judging whether node information marked as a master node exists according to the node information of each node currently stored in the database, and if not, judging that the master node does not exist in each node of the cluster currently.
5. The method for determining a master node in a cluster according to claim 2, wherein determining an election time point corresponding to each node according to the node information, and determining a target election time point according to a first time interval between each election time point and a current time point, includes:
determining a preset instruction corresponding to the number of times that the main node does not exist at present according to the preset corresponding relation, and taking the preset instruction as a target preset instruction;
and determining a target election time point according to the target preset instruction and the node information, and the election time point corresponding to each node according to the first time interval between each election time point and the current time point.
6. A method for determining master nodes in a cluster, comprising:
the database is used for storing node information and heartbeat time points sent by the nodes and sending information needed by the nodes to the nodes;
if first information of marking a target node in a cluster as a main node is received, adding the mark of the main node into the node information of the target node;
if node information sent by the nodes and/or heartbeat time points periodically reported by the nodes are received, storing the received node information and/or the heartbeat time points;
and if the second information for deleting the node information of the abnormal node is received, deleting the node information of the abnormal node.
7. The method of determining master nodes in a cluster of claim 6, further comprising:
and if the time modification instruction is received, modifying the election time point corresponding to the node according to the time modification instruction.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method of determining master nodes in a cluster according to any of claims 1 to 7 when the program is executed.
9. A non-transitory readable storage medium having stored thereon a computer program, which when executed by a processor, implements the steps of the method of determining master nodes in a cluster according to any of claims 1 to 7.
CN202010335432.3A 2020-04-24 2020-04-24 Method for determining master node in cluster, electronic equipment and storage medium Active CN111538763B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010335432.3A CN111538763B (en) 2020-04-24 2020-04-24 Method for determining master node in cluster, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010335432.3A CN111538763B (en) 2020-04-24 2020-04-24 Method for determining master node in cluster, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111538763A CN111538763A (en) 2020-08-14
CN111538763B true CN111538763B (en) 2023-08-15

Family

ID=71967566

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010335432.3A Active CN111538763B (en) 2020-04-24 2020-04-24 Method for determining master node in cluster, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111538763B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112003755B (en) * 2020-08-25 2022-12-23 北京浪潮数据技术有限公司 Method, device, equipment and medium for selecting cluster master nodes
CN112035326A (en) * 2020-09-03 2020-12-04 中国银行股份有限公司 Abnormal node task processing method and device based on cluster node mutual detection
CN112286738B (en) * 2020-11-19 2024-01-26 政采云有限公司 Method, system, equipment and readable storage medium for accessing database
CN113220464A (en) * 2021-05-31 2021-08-06 平安科技(深圳)有限公司 Distributed application method and device, computer equipment and storage medium
CN113922988B (en) * 2021-09-16 2023-07-18 苏州浪潮智能科技有限公司 Network-based host security policy detection method and system
CN114422521B (en) * 2022-01-12 2024-04-05 北京京东振世信息技术有限公司 Method and device for determining master node, electronic equipment and storage medium
CN115499447A (en) * 2022-09-15 2022-12-20 北京天融信网络安全技术有限公司 Cluster master node confirmation method and device, electronic equipment and storage medium
CN115329151B (en) * 2022-10-17 2023-03-14 北方健康医疗大数据科技有限公司 Graph database optimization method and device, electronic equipment and storage medium
CN115811520B (en) * 2023-02-08 2023-04-07 天翼云科技有限公司 Method and device for electing master node in distributed system and electronic equipment

Citations (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6199169B1 (en) * 1998-03-31 2001-03-06 Compaq Computer Corporation System and method for synchronizing time across a computer cluster
CN101754271A (en) * 2008-12-09 2010-06-23 华为终端有限公司 Method and device for negotiation of master node
CN102904752A (en) * 2012-09-25 2013-01-30 新浪网技术(中国)有限公司 Node selection method, node equipment and node system
CN104679796A (en) * 2013-12-03 2015-06-03 方正信息产业控股有限公司 Selecting method, selecting device and database mirror image cluster node
CN104933132A (en) * 2015-06-12 2015-09-23 广州巨杉软件开发有限公司 Distributed database weighted voting method based on operating sequence number
CN106911524A (en) * 2017-04-27 2017-06-30 紫光华山信息技术有限公司 A kind of HA implementation methods and device
CN107257332A (en) * 2011-12-13 2017-10-17 迈克菲公司 Time control in large-scale firewall cluster
CN107800737A (en) * 2016-09-05 2018-03-13 中国移动通信有限公司研究院 The determination method, apparatus and server cluster of host node in a kind of server cluster
CN108780346A (en) * 2015-11-16 2018-11-09 东芝存储器株式会社 Host equipment and expanding unit
CN109379238A (en) * 2018-12-14 2019-02-22 郑州云海信息技术有限公司 A kind of CTDB host node electoral machinery of distributed type assemblies, apparatus and system
CN109951331A (en) * 2019-03-15 2019-06-28 北京百度网讯科技有限公司 For sending the method, apparatus and computing cluster of information
CN109995835A (en) * 2017-12-29 2019-07-09 浙江宇视科技有限公司 Host node electoral machinery, device and distributed memory system
CN110062027A (en) * 2019-03-18 2019-07-26 中科恒运股份有限公司 Load-balancing method, central server and terminal device
CN110300023A (en) * 2019-06-28 2019-10-01 上海智臻智能网络科技股份有限公司 A kind of state switching method, device, node, node group and storage medium
CN110431533A (en) * 2016-12-30 2019-11-08 华为技术有限公司 The method, apparatus and system of fault recovery

Patent Citations (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6199169B1 (en) * 1998-03-31 2001-03-06 Compaq Computer Corporation System and method for synchronizing time across a computer cluster
CN101754271A (en) * 2008-12-09 2010-06-23 华为终端有限公司 Method and device for negotiation of master node
CN107257332A (en) * 2011-12-13 2017-10-17 迈克菲公司 Time control in large-scale firewall cluster
CN102904752A (en) * 2012-09-25 2013-01-30 新浪网技术(中国)有限公司 Node selection method, node equipment and node system
CN104679796A (en) * 2013-12-03 2015-06-03 方正信息产业控股有限公司 Selecting method, selecting device and database mirror image cluster node
CN104933132A (en) * 2015-06-12 2015-09-23 广州巨杉软件开发有限公司 Distributed database weighted voting method based on operating sequence number
CN108780346A (en) * 2015-11-16 2018-11-09 东芝存储器株式会社 Host equipment and expanding unit
CN107800737A (en) * 2016-09-05 2018-03-13 中国移动通信有限公司研究院 The determination method, apparatus and server cluster of host node in a kind of server cluster
CN110431533A (en) * 2016-12-30 2019-11-08 华为技术有限公司 The method, apparatus and system of fault recovery
CN106911524A (en) * 2017-04-27 2017-06-30 紫光华山信息技术有限公司 A kind of HA implementation methods and device
CN109995835A (en) * 2017-12-29 2019-07-09 浙江宇视科技有限公司 Host node electoral machinery, device and distributed memory system
CN109379238A (en) * 2018-12-14 2019-02-22 郑州云海信息技术有限公司 A kind of CTDB host node electoral machinery of distributed type assemblies, apparatus and system
CN109951331A (en) * 2019-03-15 2019-06-28 北京百度网讯科技有限公司 For sending the method, apparatus and computing cluster of information
CN110062027A (en) * 2019-03-18 2019-07-26 中科恒运股份有限公司 Load-balancing method, central server and terminal device
CN110300023A (en) * 2019-06-28 2019-10-01 上海智臻智能网络科技股份有限公司 A kind of state switching method, device, node, node group and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Effect of network topology on the controllability of voter model dynamics using biased nodes;Aravinda R. Srinivasan;《2014 American Control Conference》;全文 *

Also Published As

Publication number Publication date
CN111538763A (en) 2020-08-14

Similar Documents

Publication Publication Date Title
CN111538763B (en) Method for determining master node in cluster, electronic equipment and storage medium
US10657119B1 (en) Fleet node management system
US10491632B1 (en) Methods for reducing compliance violations in mobile application management environments and devices thereof
US9367261B2 (en) Computer system, data management method and data management program
US20050108385A1 (en) Method and system for managing a discovery-related process in a network
CN106506490B (en) A kind of distributed computing control method and distributed computing system
CN105162879B (en) Realize the method, apparatus and system of multimachine room data consistency
RU2015106840A (en) METHOD (OPTIONS) AND SYSTEM (OPTIONS) OF PREVENTING AN UNAUTHORIZED ACCESS CONTAINING A LOT OF SERVER NODES
JP2015535970A5 (en)
JP3554471B2 (en) Group event management method and apparatus in a distributed computer environment
JPH10224395A (en) Electronic conference system
US9449041B2 (en) Database system lock operation method and device
CN104301990B (en) A kind of method and device of data syn-chronization
US11397632B2 (en) Safely recovering workloads within a finite timeframe from unhealthy cluster nodes
JP2012146083A (en) Session management system, session management apparatus, server device and session management method
US11687381B2 (en) Multi-phase distributed task coordination
CN110233774B (en) Detection method, distributed detection method and system for Socks proxy server
Billiau et al. SBDO: A new robust approach to dynamic distributed constraint optimisation
CN103023704A (en) Method and system for accessing virtual network service equipment
KR102567900B1 (en) Method and Apparatus for Ensuring Continuous Device Operational Stability in Cloud Degraded Mode
US10185735B2 (en) Distributed database system and a non-transitory computer readable medium
CN111092956A (en) Resource synchronization method, device, storage medium and equipment
CN102752144A (en) Method and device for processing topology change in soft restart in-service software upgrade process
CN111367921A (en) Data object refreshing method and device
Vasconcelos et al. Dynamic and coordinated software reconfiguration in distributed data stream systems

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