CN112954133A - Method, device, electronic device and storage medium for synchronizing node time - Google Patents
Method, device, electronic device and storage medium for synchronizing node time Download PDFInfo
- Publication number
- CN112954133A CN112954133A CN202110074360.6A CN202110074360A CN112954133A CN 112954133 A CN112954133 A CN 112954133A CN 202110074360 A CN202110074360 A CN 202110074360A CN 112954133 A CN112954133 A CN 112954133A
- Authority
- CN
- China
- Prior art keywords
- node
- main
- nodes
- master
- time
- 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
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N5/00—Details of television systems
- H04N5/04—Synchronising
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
- H04J3/0641—Change of the master or reference, e.g. take-over or failure of the master
Landscapes
- Engineering & Computer Science (AREA)
- Signal Processing (AREA)
- Multimedia (AREA)
- Computer Networks & Wireless Communication (AREA)
- Synchronisation In Digital Transmission Systems (AREA)
- Small-Scale Networks (AREA)
Abstract
The present application relates to a method, an apparatus, an electronic apparatus and a storage medium for synchronizing time nodes, wherein the method sets a master priority; all nodes in the control system synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority; under the condition that the main node is not inquired and the current inquiry frequency exceeds the preset frequency of inquiring the main node at regular time, declaring the node responsible for the current inquiry as the main node; and starting the heartbeat keep-alive service of the main node and providing the synchronous system time service for the system. The method and the system solve the problem that when the main node is abnormal, the time synchronization of the whole system is trapped in a paralyzed state, so that the stability of the system is poor, and the stability of the system is improved.
Description
Technical Field
The present application relates to the field of system time synchronization technologies, and in particular, to a method, an apparatus, an electronic apparatus, and a storage medium for synchronizing node time.
Background
Along with the application and popularization of the distributed television wall in scenes such as a monitoring center, a command center and the like, the application of the distributed television wall is more and more extensive. Among them, time consistency among the nodes constituting the distributed tv wall is very important, because it is the basis of the video cross-window synchronization scheme, and the high smoothness of the video must be solved.
In the related art, a master node is known, and each slave node performs time synchronization to the master node through an NTP component, and when the master node is abnormal, the time synchronization of the entire system falls into a paralyzed state. Therefore, a time synchronization method for automatically selecting the master node as the NTP component is provided to improve the stability of the system. For example, a node is manually configured in a cluster of distributed televisions to be configured as a master node, other nodes are configured as slave nodes, and a time synchronization address is configured for the master node according to the address of each slave node to perform time synchronization interaction.
At present, an effective solution is not provided for the problem that in the related art, when a master node is abnormal, the time synchronization of the whole system falls into a paralyzed state, which results in poor system stability.
Disclosure of Invention
The embodiment of the application provides a method, a device, an electronic device and a storage medium for synchronizing time nodes, so as to solve the problem that in the related art, when a master node is abnormal, the time synchronization of the whole system falls into a paralyzed state, which results in poor system stability.
In a first aspect, an embodiment of the present application provides a method for synchronizing time nodes, including:
setting a master selection priority;
all nodes in the control system synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority;
under the condition that the main node is not inquired and the current inquiry frequency exceeds the preset frequency of inquiring the main node at regular time, declaring the node responsible for the current inquiry as the main node;
and starting heartbeat keep-alive service of the main node and providing synchronous system time service for the system. In some embodiments, the declaring, when the master node is not queried and the current query number of times exceeds the preset number of times of querying the master node at regular time, the node responsible for the current query as the master node includes the following steps:
presetting the frequency of the timed query main node;
under the condition that the main node is not inquired, judging whether the current inquiry frequency exceeds the frequency of the timing inquiry main node or not;
if yes, the node responsible for the current query is declared to be the master node.
In some embodiments, in the case that the master node is not queried, after determining whether the current number of queries has exceeded the number of queries to the master node periodically, the method further includes:
if not, continuously controlling all nodes in the system to synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority.
In some embodiments, after all nodes in the control system synchronously broadcast and query the master node in the system according to the number of timed queries preset by the master priority, the method further includes:
if the main node is inquired, declaring that the node responsible for the current inquiry is a slave node;
and starting heartbeat keep-alive monitoring of the main node, and controlling the slave node to synchronize system time to the main node at regular time.
In some embodiments, the providing the synchronized system time service to the system comprises:
controlling the slave node to synchronize the system time to the master node by installing a network time protocol between the master node and the slave node.
In some of these embodiments, the method further comprises: and when the heartbeat keep-alive service of the main node fails, setting the current main node to be in an unknown state, and controlling all nodes in the system to synchronously broadcast and inquire the main node in the system according to the timing inquiry times preset by the main selection priority.
In some of these embodiments, the method further comprises: under the condition that n main nodes simultaneously appear in the system, the main node with the network abnormality is set as a slave node, wherein n is a natural number larger than 1;
and under the condition that no network abnormality occurs in the n main nodes, starting an arbitration mechanism, comparing the priorities among the n main nodes, and setting the lower priority as a slave node.
In a second aspect, an embodiment of the present application provides an apparatus for synchronizing time nodes, including: the system comprises a preference module, a query module, a judgment module and a service module;
the preferred module is used for setting the priority of the selected main;
the query module is used for controlling all nodes in the system to synchronously broadcast and query the main nodes in the system according to the timing query times preset by the main selection priority;
the judging module is used for declaring the node responsible for the current query as the main node under the condition that the main node is not queried and the current query frequency exceeds the preset frequency of the timed query of the main node;
and the service module is used for starting the heartbeat keep-alive service of the main node and providing the synchronous system time service for the system. In a third aspect, an embodiment of the present application provides an electronic device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor, when executing the computer program, implements a method for synchronizing time nodes according to the first aspect.
In a fourth aspect, the present application provides a storage medium, on which a computer program is stored, which when executed by a processor, implements a method for synchronizing time nodes as described in the first aspect above.
Compared with the related art, the method, the device, the electronic device and the storage medium for synchronizing the time nodes provided by the embodiment of the application have the advantages that the master selection priority is set, all nodes in the system are controlled to synchronously broadcast and inquire the master node in the system according to the preset timing inquiry times of the master selection priority, and the node responsible for the current inquiry is declared to be the master node under the condition that the master node is not inquired and the current inquiry times exceed the preset timing inquiry times of the master node; and starting the heartbeat keep-alive service of the main node and providing the synchronous system time service for the system. The problem of when the master node is abnormal, the time synchronization of the whole system falls into a paralyzed state, so that the system stability is poor is solved, and the system stability is improved.
The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below to provide a more thorough understanding of the application.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a block diagram of a hardware structure of a terminal of a method of synchronizing time nodes according to an embodiment of the present application;
FIG. 2 is a flow chart of a method of synchronizing time nodes according to an embodiment of the present application;
FIG. 3 is a schematic node arrangement diagram of a method for synchronizing time nodes according to an embodiment of the present application;
FIG. 4 is a flow chart of another method of synchronizing time nodes according to an embodiment of the present application;
FIG. 5 is a preferred flow diagram of a method of synchronizing time nodes according to an embodiment of the present application;
FIG. 6 is a schematic diagram of an apparatus for synchronizing time nodes according to an embodiment of the present application;
fig. 7 is a block diagram of a computer device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments provided in the present application without any inventive step are within the scope of protection of the present application. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the specification. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of ordinary skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments without conflict.
Unless defined otherwise, technical or scientific terms referred to herein shall have the ordinary meaning as understood by those of ordinary skill in the art to which this application belongs. Reference to "a," "an," "the," and similar words throughout this application are not to be construed as limiting in number, and may refer to the singular or the plural. The present application is directed to the use of the terms "including," "comprising," "having," and any variations thereof, which are intended to cover non-exclusive inclusions; for example, a process, method, system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or elements, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. Reference to "connected," "coupled," and the like in this application is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference herein to "a plurality" means greater than or equal to two. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. Reference herein to the terms "first," "second," "third," and the like, are merely to distinguish similar objects and do not denote a particular ordering for the objects.
The method provided by the embodiment can be executed in a terminal, a computer or a similar operation device. Taking the example of running on a terminal, fig. 1 is a hardware structure block diagram of an application terminal of a method for synchronizing time nodes according to an embodiment of the present invention. As shown in fig. 1, the terminal may include one or more processors 102 (only one is shown in fig. 1) (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, and optionally, a transmission device 106 for communication functions and an input-output device 108. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the terminal. For example, the terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used for storing computer programs, for example, software programs and modules of application software, such as a computer program corresponding to a method for synchronizing time nodes in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the above-mentioned method. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
The embodiment provides a method for synchronizing time nodes, which is mainly applied to synchronizing time of distributed television wall nodes, and fig. 2 is a flowchart of synchronizing time nodes according to the method for synchronizing time nodes of the embodiment of the present application, and as shown in fig. 2, the flowchart includes the following steps:
step S201, setting a master selection priority;
the master priority is selected, namely all nodes in the system keep the same configuration, and each node automatically updates and selects the master priority according to the layout rule of the nodes. In this step, the master election priority is set in preparation for subsequent broadcast query master nodes.
The setting of the master priority is illustrated below by taking a distributed tv wall as an example. For each node in the distributed television wall, firstly, the same television wall configuration rule is stored in each node forming the distributed television wall, and secondly, the master selection priority of the nodes is automatically updated from left to right and from top to bottom according to the television wall layout and the same television wall configuration rule. As shown in fig. 3, taking a 2X2 distributed tv wall system composed of four decoder nodes as an example, in the tv wall system, the master priorities of node 1, node 2, node 3, and node 4 are 1, 2, 3, and 4, respectively, and the master priority with a small value is high, that is, the master priority level: node 1> node 2> node 3> node 4.
Step S202, controlling all nodes in the system to synchronously broadcast and inquire the main nodes in the system according to the preset timing inquiry times of the main selection priority.
The master nodes which broadcast and inquire synchronously can be selected by controlling all the nodes in the system according to the timing inquiry times preset by the master selection priority, the master node in the current system can be selected, and the slave nodes are determined after the master node is determined.
Specifically, the device information of each node in the system can be queried through a broadcast protocol, and after receiving the broadcast, each node reports the device information of itself, wherein the device information contains a role mark. When the node role is in an unknown state, the mark is a logging node; when the node role is the main node, the mark is the mainNode; when the node role is slave node, the mark is subNode.
Step S203, declaring the node responsible for the current query as the master node when the master node is not queried and the current query frequency exceeds the preset frequency of querying the master node at regular time.
Wherein each node is independently operated, and the logic of the query is independently operated on each node. For example, the number of times of regularly querying the master nodes is set to 5, the master priority level is selected, and the time interval of each query is 1 second. If the first node does not inquire the main node for 5 times, the first node can be declared as the main node; and if the second node does not inquire the master node 10 times, the second node can be declared as the master node, and the like, and under the condition of determining the master node, other nodes can declare the self node as a slave node after finding the master node through inquiry. With reference to the above embodiments, the method for setting the number of timing queries can make the probability that each node becomes a master node different due to different master priorities, thereby reducing the probability that a plurality of master nodes appear at the same time.
Step S204, the heartbeat keep-alive service of the main node is started, and the synchronous broadcast inquiry system time service is provided for the system.
The heartbeat keep-alive service is to send a self-defined heartbeat packet at regular time to make the opposite side know the connection state of the opposite side so as to ensure the effectiveness of the connection.
Through the steps, all the master priorities are arranged in the system in advance, the master nodes in the system are synchronously broadcast and inquired by being associated with the timing inquiry time, the inquiry times with high priorities are less, the inquiry times with low priorities are more, then all the nodes in the system are controlled to inquire the master nodes in the system according to the preset timing inquiry times of the master priorities, the master nodes are inquired according to the master priority order, the simultaneous occurrence of a plurality of master nodes is avoided, under the condition that the master nodes are not inquired and the current inquiry times exceed the preset timing inquiry times of the master nodes, the node responsible for the current inquiry is declared to be the master node, the master node can be reconfirmed, the smooth operation of the system is ensured, then the node heartbeat keep-alive service is started, the keep-alive condition inquiry signaling of each slave node is received and fed back, and the system time is synchronously broadcast and inquired from the, the problem that the query time cannot be synchronously broadcasted due to the abnormal main node is solved, and the stability of the system is improved.
In some embodiments, when the master node is not queried and the current query frequency exceeds the preset frequency of querying the master node at regular time, declaring the node responsible for the current query as the master node, including the following steps: inquiring the times of the main node in preset time; under the condition that the main node is not inquired, judging whether the current inquiry frequency exceeds the frequency of the timing inquiry main node or not; if yes, declaring the node responsible for the current query as a main node; if not, other nodes in the system continue to be controlled to synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority.
If the number of times of inquiring the main node at regular time is exceeded and the main node is not inquired, the node which is responsible for inquiring at present is defined as the main node; if the number of times of inquiring the main node is not exceeded, the main node in the system is continuously inquired until the main node is inquired, the success rate of selecting the main node is ensured, and meanwhile, the stability of the system is ensured.
For example: suppose that two nodes, node 1 and node 2, run the master priority process at time t simultaneously, and get the master priority level of node 1> node 2. Node 1 inquires 5 times, if there is no master node in the system, it can declare the current node, i.e. node 1 is the master node, at this time, node 2 inquires 6 times, it finds that there is a master node in the system, so it declares node 2 to be the slave node. In another case, node 1 is not online, no broadcast query is performed, and node 2 queries that there is a master node in the system for 10 times, so that node 2 can be declared as the master node.
It should be noted that in reality, it cannot be guaranteed that the node devices are all started at the same time. In some embodiments, the method for starting the heartbeat keep-alive service of the main node and providing the synchronous system time service for the system comprises the following steps: and controlling the slave node to synchronize the system time with the master node by installing a network time protocol between the master node and the slave node.
Each node in the distributed television wall system is provided with an NTP (Network Time Protocol) component for Time synchronization between the nodes.
Specifically, a heartbeat keep-alive service is started, and a keep-alive condition query signaling of each slave node is received and fed back; then the NTP server program will automatically start after the system starts, and provide time synchronization service for the NTP client request. By installing the network time protocol, accurate and robust time service can be provided in an unordered Internet environment, and the time of the system is accurately synchronized from the slave node to the master node.
In some of these embodiments, the method further comprises: when the heartbeat keep-alive service of the main node fails, the current main node is set to be in an unknown state, all nodes in the system are controlled again to synchronously broadcast and inquire the main node in the system according to the timing inquiry times preset by the main selection priority.
When the heartbeat keep-alive of the main node fails, the current main node is possibly in an offline state, the current node is reset to be a node in an unknown state, all nodes in the control system are re-entered, and the main node in the system is synchronously queried in a broadcast mode according to the preset timing query times of the priority of the selected main node. The method and the system have the advantages that the condition that the master node and the slave node are interrupted due to abnormity is kept, the abnormal condition of heartbeat keep-alive service provided by the master node is saved, and the stability of providing synchronous system time service for the system by the master node is improved.
In some of these embodiments, the method further comprises: under the condition that n main nodes simultaneously appear in the system, the main node with the network abnormality is set as a slave node, wherein n is a natural number larger than 1; and under the condition that no network abnormality occurs in the n main nodes, starting an arbitration mechanism, comparing the priority among the n main nodes, and setting the lower priority as a slave node.
According to the method and the device, the arbitration mechanism is started when the network is abnormal, so that the abnormal condition that two or more main nodes exist in the system is solved. This embodiment also provides another method for synchronizing time nodes, which is mainly applied to a distributed tv wall node to synchronize time, fig. 4 is a flowchart of another method for synchronizing time nodes according to the embodiment of the present application, and as shown in fig. 4, the flowchart includes the following steps:
step S401, setting a master selection priority;
the master priority is selected, namely all nodes in the system keep the same configuration, and each node automatically updates and selects the master priority according to the layout rule of the nodes. The setting of the master priority is illustrated below by taking a distributed tv wall as an example. For each node in the distributed television wall, firstly, the same television wall configuration rule is stored in each node forming the distributed television wall, and secondly, the master selection priority of the nodes is automatically updated from left to right and from top to bottom according to the television wall layout and the same television wall configuration rule. As shown in fig. 3, taking a 2X2 distributed tv wall system composed of four decoder nodes as an example, in the tv wall system, the master priorities of node 1, node 2, node 3, and node 4 are 1, 2, 3, and 4, respectively, and the master priority with a small value is high, that is, the master priority level: node 1> node 2> node 3> node 4.
And step S402, controlling all nodes in the system to synchronously broadcast and query the main nodes in the system according to the preset timing query times of the main selection priority.
The master nodes synchronously broadcast and inquired by controlling all the nodes in the system according to the timing inquiry times preset by the master selection priority can select the master node in the current system, and the slave nodes are confirmed after the master node is determined.
Specifically, the device information of each node in the system can be queried through a broadcast protocol, and after receiving the broadcast, each node reports the device information of itself, wherein the device information contains a role mark. When the node role is in an unknown state, the mark is a logging node; when the node role is the main node, the mark is the mainNode; when the node role is slave node, the mark is subNode.
Step S403, under the condition that the main node is not inquired and the current inquiry frequency exceeds the preset frequency of regularly inquiring the main node, declaring the node responsible for the current inquiry as the main node;
wherein each node is independently operated, and the logic of the query is independently operated on each node. For example, the number of times of regularly querying the master nodes is set to 5, the master priority level is selected, and the interval of each query time is 1 second. If the first node does not inquire the main node for 5 times, the first node can be declared as the main node; and if the second node does not inquire the master node 10 times, the second node can be declared as the master node, and the like, and under the condition of determining the master node, other nodes can declare the self node as a slave node after finding the master node through inquiry.
With reference to the above embodiments, the method for setting the number of timing queries can make the probability that each node becomes a master node different due to different master priorities, thereby reducing the probability that a plurality of master nodes appear at the same time.
Step S404, the heartbeat keep-alive service of the main node is started, and the synchronous broadcast inquiry system time service is provided for the system.
The heartbeat keep-alive service is to send a self-defined heartbeat packet at regular time to make the opposite side know the connection state of the opposite side so as to ensure the effectiveness of the connection.
In step S405, if the master node is queried, it is declared that the node responsible for current query is a slave node.
Specifically, when a master node in the system is queried, it is proved that the master node has already been determined so that the current node is a slave node, so that the current node queried by the broadcast protocol is set as a slave node.
Step S406, starting the heartbeat keep-alive monitoring of the master node, and controlling the slave node to synchronously broadcast and inquire the system time to the master node at regular time.
In step S402, the device information such as the IP address of the master node can be known, and then in step S406, a socket connection is established between the slave node and the master node, and a keep-alive signaling is sent to the master node at regular time to confirm whether the master node is online, and if the master node is not online, an exception handling process is started. A timer is then started and the NTP client program is executed every 30 minutes to request the master node for synchronized system time.
Through the steps, all the master selection priorities are arranged in the system in advance, and the master selection priorities are associated with the timing query time, so that the conditions that the query times are low when the priorities are high and the query times are high when the priorities are low are ensured, then all the nodes in the system are controlled to query the master nodes in the system according to the preset timing query times of the master selection priorities in a synchronous broadcast mode, the master nodes can be queried according to the master selection priority sequence, the condition that when a plurality of master nodes are simultaneously used as the queried master nodes in the system, master node heartbeat monitoring is started, connection is established between the master nodes and slave nodes, the slave nodes are controlled to send keep-alive signals to the master nodes at regular time, and meanwhile, the master nodes are requested to synchronize the system time at regular time is solved, and the problem that.
Fig. 5 is a preferred flowchart of a method for synchronizing time nodes according to an embodiment of the present application, and as shown in fig. 5, the preferred method for synchronizing time nodes includes the following steps:
step S501, setting a master selection priority;
step S503, determine whether the existence of the master node is queried.
Step S504, if not, continuing to control all nodes in the system to synchronously broadcast and inquire the main nodes in the system according to the preset timing inquiry times of the main selection priority
Step S505, under the condition that the main node is not inquired and the current inquiry frequency exceeds the preset frequency of regularly inquiring the main node, declaring the node responsible for the current inquiry as the main node;
step S506, the heartbeat keep-alive service of the main node is started, and the synchronous broadcast inquiry system time service is provided for the system.
In step S507, if the master node is queried, it is declared that the node responsible for current query is a slave node.
And step S508, starting heartbeat keep-alive monitoring of the main node, and controlling the slave node to synchronize system time to the main node at regular time.
Through the steps, all master priorities are arranged in the system in advance, the master nodes in the system are synchronously broadcast and inquired according to the preset timing inquiry times of the master priorities by being associated with the timing inquiry time, the master nodes in the system are prevented from appearing simultaneously by inquiring the master nodes according to the master priority order, the master node responsible for the current inquiry can be declared as the master node under the condition that the master node is not inquired and the current inquiry times exceed the preset timing inquiry times of the master nodes, the master node can be reconfirmed, the smooth keep-alive operation of the system is ensured, then the node heartbeat service is started, the keep-alive condition inquiry signaling of each slave node is received and fed back, and the system time is synchronized from the slave node to the master node, the problem that the time cannot be synchronized due to the exception of the main node is solved, and the stability of the system is improved.
It should be noted that the steps illustrated in the above-described flow diagrams or in the flow diagrams of the figures may be performed in a computer system such as a set of computer-executable instructions, and that while a logical order is illustrated in the flow diagrams, in some cases, the steps illustrated or described may be performed in an order different than here.
The present embodiment further provides a device for synchronizing time nodes, where the device is used to implement the foregoing embodiments and preferred embodiments, and details are not repeated for what has been described. As used hereinafter, the terms "module," "unit," "subunit," and the like may implement a combination of software and/or hardware for a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 6 is a block diagram of an apparatus for synchronizing time nodes according to an embodiment of the present application, where the apparatus, as shown in fig. 6, includes: a setting module 61, a query module 62, a judgment module 63 and a service module 64;
the setting module 61 is used for setting the master selection priority;
the query module 62 is configured to control all nodes in the system to synchronously broadcast and query the master node in the system according to the number of timing queries preset by the master selection priority;
the judging module 63 is configured to declare a node responsible for current query as a master node when the master node is not queried and the current query frequency exceeds a preset frequency of querying the master node at a fixed time;
the service module 64 is configured to start a heartbeat keep-alive service of the master node and provide a synchronized system time service to the system.
In some embodiments, the determining module 63 is further configured to preset the number of times of querying the master node at regular time; under the condition that the main node is not inquired, judging whether the current inquiry frequency exceeds the frequency of the timing inquiry main node or not; if yes, the node responsible for the current query is declared to be the master node.
In some embodiments, the apparatus for synchronizing time nodes further comprises a broadcasting module for broadcasting
If not, continuously controlling all nodes in the system to synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority.
In some of these embodiments, the apparatus for synchronizing time nodes further comprises a monitoring module, configured to declare the node responsible for the current query as a slave node if the master node is queried; and starting heartbeat keep-alive monitoring of the master node, and controlling the slave node to synchronize system time to the master node at regular time.
In some of these embodiments, the service module 64 is also used to control the slave node to synchronize the system time to the master node by installing a network time protocol between the master node and the slave node.
In some embodiments, the apparatus for synchronizing time nodes further includes a resetting module, where the resetting module is configured to, when the heartbeat keep-alive service of the master node fails, set the current master node to an unknown state, and re-control all nodes in the system to synchronously broadcast and query the master nodes in the system according to the number of timed queries preset by the master selection priority.
In some embodiments, the apparatus for synchronizing time nodes further includes an arbitration module, configured to set, as a slave node, a master node where a network anomaly has occurred, in a case where two master nodes are present in the system at the same time; and under the condition that no network abnormality occurs in the two main nodes, starting an arbitration mechanism, comparing the priority between the two main nodes, and setting the lower priority as a slave node.
The above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
In an embodiment, a computer device is provided, fig. 7 is a block diagram of a computer device according to an embodiment of the present application, and fig. 7 shows a computer program stored thereon, where the computer program is executed by a processor to implement the steps in a method for synchronizing time nodes provided in the foregoing embodiments, and the steps are as follows:
step S1, setting a master selection priority;
step S2, controlling all nodes in the system to synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the priority of the selected main;
step S3, under the condition that the main node is not inquired and the current inquiry frequency exceeds the preset frequency of the main node, declaring the node responsible for the current inquiry as the main node;
step S4, the heartbeat keep-alive service of the master node is turned on, and the synchronized system time service is provided to the system.
Those skilled in the art will appreciate that the architecture shown in fig. 7 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to serve as a limitation on the computer-readable storage media to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.
Claims (10)
1. A method of synchronizing time nodes, comprising:
setting a master selection priority;
all nodes in the control system synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority;
under the condition that the main node is not inquired and the current inquiry frequency exceeds the preset frequency of inquiring the main node at regular time, declaring the node responsible for the current inquiry as the main node;
and starting heartbeat keep-alive service of the main node and providing synchronous system time service for the system.
2. The method of claim 1, wherein declaring a node responsible for the current query as the master node if the master node is not queried and the current query number exceeds a preset number of times of querying the master node at regular time, comprises:
presetting the frequency of the timed query main node;
under the condition that the main node is not inquired, judging whether the current inquiry frequency exceeds the frequency of the timing inquiry main node or not;
if yes, the node responsible for the current query is declared to be the master node.
3. The method of claim 2, wherein after determining whether the current number of queries has exceeded the number of queries to the primary node periodically without querying the primary node, the method further comprises:
if not, continuously controlling all nodes in the system to synchronously broadcast and inquire the main nodes in the system according to the timing inquiry times preset by the main selection priority.
4. The method of claim 1, wherein after all nodes in the control system synchronously broadcast queries the master node in the system according to the number of timed queries preset by the master priority, the method further comprises:
if the main node is inquired, declaring that the node responsible for the current inquiry is a slave node;
and starting heartbeat keep-alive monitoring of the main node, and controlling the slave node to synchronize system time to the main node at regular time.
5. The method of claim 4, wherein providing the synchronized system time service to the system comprises:
controlling the slave node to synchronize the system time to the master node by installing a network time protocol between the master node and the slave node.
6. The method of claim 5, further comprising:
and when the heartbeat keep-alive service of the main node fails, setting the current main node to be in an unknown state, and controlling all nodes in the system to synchronously broadcast and inquire the main node in the system according to the timing inquiry times preset by the main selection priority.
7. The method of claim 6, further comprising:
under the condition that n main nodes simultaneously appear in the system, the main node with the network abnormality is set as a slave node, wherein n is a natural number larger than 1;
and under the condition that no network abnormality occurs in the n main nodes, starting an arbitration mechanism, comparing the priorities among the n main nodes, and setting the lower priority as a slave node.
8. An apparatus for synchronizing time nodes, comprising: the system comprises a preference module, a query module, a judgment module and a service module;
the preferred module is used for setting the priority of the selected main;
the query module is used for controlling all nodes in the system to synchronously broadcast and query the main nodes in the system according to the timing query times preset by the main selection priority;
the judging module is used for declaring the node responsible for the current query as the main node under the condition that the main node is not queried and the current query frequency exceeds the preset frequency of the timed query of the main node;
and the service module is used for starting the heartbeat keep-alive service of the main node and providing the synchronous system time service for the system.
9. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, and wherein the processor is arranged to execute the computer program to perform the method of synchronizing node times of any of claims 1 to 7.
10. A storage medium, in which a computer program is stored, wherein the computer program is arranged to perform the method of synchronizing node times of any of claims 1 to 7 when executed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110074360.6A CN112954133B (en) | 2021-01-20 | 2021-01-20 | Method, device, electronic device and storage medium for synchronizing node time |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110074360.6A CN112954133B (en) | 2021-01-20 | 2021-01-20 | Method, device, electronic device and storage medium for synchronizing node time |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112954133A true CN112954133A (en) | 2021-06-11 |
CN112954133B CN112954133B (en) | 2023-03-14 |
Family
ID=76235652
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110074360.6A Active CN112954133B (en) | 2021-01-20 | 2021-01-20 | Method, device, electronic device and storage medium for synchronizing node time |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112954133B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117295148A (en) * | 2023-11-22 | 2023-12-26 | 泉州艾奇科技有限公司 | Time synchronization method, central control host and wireless device |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5708767A (en) * | 1995-02-03 | 1998-01-13 | The Trustees Of Princeton University | Method and apparatus for video browsing based on content and structure |
CN102098113A (en) * | 2011-02-25 | 2011-06-15 | 东南大学 | Method for realizing water sound sensor network MAC (Media Access Control) protocol based on ALOHA and TDMA (Time Division Multiple Access) |
CN102202425A (en) * | 2011-06-24 | 2011-09-28 | 中国人民解放军国防科学技术大学 | Satellite cluster self-organization networking method based on master-slave heterogeneous data transmission module |
CN104539055A (en) * | 2015-01-07 | 2015-04-22 | 山东鲁能智能技术有限公司 | Electric system key equipment actualizing-one-prepared method and system based on network |
CN109639640A (en) * | 2015-10-28 | 2019-04-16 | 杭州数梦工场科技有限公司 | Message method and device |
CN109977161A (en) * | 2019-03-28 | 2019-07-05 | 上海中通吉网络技术有限公司 | The monitoring system of presto cluster |
CN110622478A (en) * | 2018-04-08 | 2019-12-27 | 华为技术有限公司 | Method and device for data synchronous processing |
CN111641522A (en) * | 2020-05-25 | 2020-09-08 | 杭州安恒信息技术股份有限公司 | Method, system and computer equipment for node switching |
-
2021
- 2021-01-20 CN CN202110074360.6A patent/CN112954133B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5708767A (en) * | 1995-02-03 | 1998-01-13 | The Trustees Of Princeton University | Method and apparatus for video browsing based on content and structure |
CN102098113A (en) * | 2011-02-25 | 2011-06-15 | 东南大学 | Method for realizing water sound sensor network MAC (Media Access Control) protocol based on ALOHA and TDMA (Time Division Multiple Access) |
CN102202425A (en) * | 2011-06-24 | 2011-09-28 | 中国人民解放军国防科学技术大学 | Satellite cluster self-organization networking method based on master-slave heterogeneous data transmission module |
CN104539055A (en) * | 2015-01-07 | 2015-04-22 | 山东鲁能智能技术有限公司 | Electric system key equipment actualizing-one-prepared method and system based on network |
CN109639640A (en) * | 2015-10-28 | 2019-04-16 | 杭州数梦工场科技有限公司 | Message method and device |
CN110622478A (en) * | 2018-04-08 | 2019-12-27 | 华为技术有限公司 | Method and device for data synchronous processing |
CN109977161A (en) * | 2019-03-28 | 2019-07-05 | 上海中通吉网络技术有限公司 | The monitoring system of presto cluster |
CN111641522A (en) * | 2020-05-25 | 2020-09-08 | 杭州安恒信息技术股份有限公司 | Method, system and computer equipment for node switching |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117295148A (en) * | 2023-11-22 | 2023-12-26 | 泉州艾奇科技有限公司 | Time synchronization method, central control host and wireless device |
CN117295148B (en) * | 2023-11-22 | 2024-02-23 | 泉州艾奇科技有限公司 | Time synchronization method, central control host and wireless device |
Also Published As
Publication number | Publication date |
---|---|
CN112954133B (en) | 2023-03-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP2523422A1 (en) | Issuing method and system for configuration information | |
CN107295080B (en) | Data storage method applied to distributed server cluster and server | |
US11172023B2 (en) | Data synchronization method and system | |
CN111190736A (en) | Low-intrusion distributed timing task scheduling system and method based on microservice | |
US11271714B2 (en) | Time synchronization system, time master, management master, and time synchronization method | |
CN104184756A (en) | Data synchronization method, device and system | |
EP3764591A1 (en) | Network protocol method for mesh capability in narrow-band wireless networks | |
CN108055140B (en) | Cross-device communication method, device, storage medium and computer equipment thereof in networking | |
CN112799867B (en) | Election method based on distributed storage system and distributed storage system | |
CN109040184B (en) | Host node election method and server | |
CN112954133B (en) | Method, device, electronic device and storage medium for synchronizing node time | |
US20220264496A1 (en) | Method and system for synchronizing data | |
JP2022513769A (en) | How to process subscription messages, devices, computer devices and storage media | |
CN112911520B (en) | Method, device and storage medium for determining master node in ad hoc network | |
CN114338267B (en) | Maintenance method, device, equipment, bus network and medium for multiple management nodes | |
CN111083016B (en) | Polling table processing method and device, storage medium and equipment | |
CN107370647B (en) | Method for interconnecting local area internal controller systems and local area network system | |
CN106936940B (en) | Lease information backup method and system in a kind of Dynamic Host Configuration Protocol server | |
US10404534B2 (en) | Method and device for networking intelligent terminals | |
WO2021134766A1 (en) | Method, apparatus and device for determining device state, and storage medium | |
CN116938712A (en) | Device upgrade method, device upgrade apparatus, and computer-readable storage medium | |
US20230126682A1 (en) | Fault tolerance method and apparatus of network device system, computer device, and storage medium | |
CN113992295B (en) | Multi-NTP server timing realization method and system, computer equipment and storage medium | |
CN114531322B (en) | Method, system, device and medium for synchronizing multi-gateway data of Internet of things | |
CN112751907A (en) | Information processing method, information processing apparatus, storage medium, and electronic apparatus |
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 |