Data synchronization method, device and system, storage medium and terminal
By monitoring data packets in real time between multiple terminals, and matching and synchronous data packets with heartbeat data packets and synchronous data packets are used for matching and synchronization operations, real-time data synchronization and hot switching between multiple terminals are achieved, solving the problems of difficulty in data interoperability, flexible resource occupation control, and multi-functional data synchronization services in the prior art.
Patent Information
- Application Number
- CN202411842952.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-04-18
AI Technical Summary
It is difficult for the prior art to realize real-time data synchronization and hot switching between multiple terminals, especially in multi-machine and multi-control scenarios, where data interoperability is difficult, configuration and deployment complex, low degree of freedom and data consistency are problems.
By monitoring data packets in real time between multiple terminals, using heartbeat data packets and synchronous data packets for matching and synchronization operations, ensuring the effectiveness and synchronization order of data packets, realizing a decentralized data synchronization system.
Real-time data synchronization and hot switching between multiple terminals are realized, solving the problems of difficulty in data interoperability, flexible resource occupation control and multi-function data synchronization services, and adapting to the demand trend of multi-machine and multi-control of mixing station business.
Smart Images

Figure CN119854315A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data synchronization method, device, system, storage medium and terminal. Background Art
[0002] The basic form of the traditional mixing station control system is one station line and one terminal, that is, one-to-one independent control. The station line database is installed on the corresponding industrial computer terminal, and the stations and lines are managed independently without affecting each other. With the development and changes of the industry, higher requirements are put forward for mixing station control solutions, such as single machine dual control (one industrial computer controls two mixing stations at the same time), dual machine single control (two industrial computers control the same mixing station at the same time), dual machine dual control (two industrial computers control two mixing stations at will), etc., and it is developing in the direction of multi-machine multi-control. This involves a technical problem, that is, how to achieve data intercommunication between different stations and lines. In the existing technology, it is usually through the synchronization solution provided by the database service provider, such as the mainstream relational database has sqlserver subscription and publishing, and MySQL master-slave synchronization. However, this method is relatively more difficult to use, requires additional configuration and deployment overhead, and has low freedom, small customization space, and certain limitations. Another way is to select a central database and regularly back up the emergency database. However, in a multi-line scenario, once a problem occurs in the central database, all lines cannot be used normally. In addition, the timeliness of its scheduled backup strategy is not high, and the integrity of the emergency database data cannot be guaranteed. For data interaction between multiple terminals, it is necessary to determine the occurrence time of database operations of different terminals through time processing to determine the order of their occurrence to synchronize data, otherwise conflicts will occur. Therefore, it is currently impossible to solve the technical problem of real-time data synchronization or hot switching between multiple terminals in various scenarios. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a data synchronization method, device, system, storage medium and terminal to solve the technical problem of real-time data synchronization between multiple terminals in the prior art.
[0004] In order to achieve the above-mentioned object, the first aspect of the present application provides a data synchronization method, which is applied to a data synchronization system, the data synchronization system includes multiple terminals, and the method includes:
[0005] When any terminal among the multiple terminals is online, any terminal confirms whether it has received first timestamp information sent by another terminal among the multiple terminals;
[0006] When any terminal receives the first timestamp information, calibrate the timestamp of the any terminal according to the first timestamp information;
[0007] When any terminal starts the data synchronization service, it monitors the received data packets in real time;
[0008] When the data packet received by any terminal is a heartbeat data packet, the terminal verifies whether the terminal matches the terminal sending the heartbeat data packet according to the pairing code carried in the heartbeat data packet;
[0009] When any terminal successfully verifies, it adds the first sender ID carried in the heartbeat data packet to the target queue;
[0010] When any terminal receives a synchronous data packet, it determines whether there is a second sending end ID carried by the synchronous data packet in the target queue;
[0011] When any terminal has the second sender ID in the target queue, the synchronization data packet is synchronized to the database of the any terminal.
[0012] In an embodiment of the present application, it also includes: when any terminal is successfully verified, the sleepiness degree corresponding to each third sender ID included in the target queue is updated according to the first sender ID carried by the heartbeat data packet; any terminal removes the third sender ID whose sleepiness degree is greater than the preset sleepiness threshold from the target queue.
[0013] In an embodiment of the present application, when any terminal is successfully verified, the sleepiness degree corresponding to each third sender ID included in the target queue is updated according to the first sender ID carried by the heartbeat data packet, including: when any terminal is successfully verified and there is a third sender ID identical to the first sender ID in the target queue, the sleepiness degree corresponding to the third sender ID is updated to zero, and the sleepiness degree corresponding to the third sender ID in the target queue that is not the same as the first sender ID is incremented.
[0014] In an embodiment of the present application, when any terminal has a second sender ID in the target queue, the synchronization data packet is synchronized to the database of any terminal, including: when any terminal has a second sender ID in the target queue, determining whether the synchronization data packet is valid based on the second timestamp information carried by the synchronization data packet; when any terminal determines that the synchronization data packet is valid, the synchronization data packet is synchronized to the database of the terminal; when any terminal determines that the synchronization data packet is invalid, the invalidation information of the synchronization data packet is sent to other terminals.
[0015] In an embodiment of the present application, it also includes: when any terminal fails to receive the first timestamp information within a first preset time period, it sends a notification to other terminals among multiple terminals that it has become a time synchronization terminal; when any terminal fails to receive the first timestamp information within a second preset time period after sending the notification, it sends third timestamp information to other terminals and starts a data synchronization service; when any terminal receives the first timestamp information within the second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information has been received.
[0016] In an embodiment of the present application, it also includes: any terminal detects in real time whether the first timestamp information is received when starting to send the third timestamp information; when any terminal receives the first timestamp information after sending the third timestamp information, it stops sending the third timestamp information, suspends the data synchronization service, and reconfirms whether the first timestamp information is received again.
[0017] In an embodiment of the present application, when any terminal receives the first timestamp information within the second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information is received, including: when any terminal receives the first timestamp information within the second preset time period, determining the number of conflicts in which a timing conflict event occurs at any terminal, a timing conflict event means that any terminal does not receive the first timestamp information within the first preset time period, or any terminal receives the first timestamp information within the second preset time period; determining the waiting time of any terminal according to the number of conflicts; and reconfirming whether the first timestamp information is received at any terminal after the waiting time.
[0018] In an embodiment of the present application, it also includes: when any terminal sends the third timestamp information, the number of conflicts is updated to zero.
[0019] In an embodiment of the present application, it also includes: any terminal extracts data update content from the database of any terminal through the created trigger, and the data update content includes data operation, data update time and data content; any terminal queries the unsynchronized data to be synchronized from the synchronization record table of any terminal; any terminal assembles the data update content and the data to be synchronized into a synchronization data packet, and adds the synchronization data packet to the sending queue; any terminal traverses the synchronization data packets in the sending queue to remove the synchronization data packets from the sending queue in turn, and sends them to other terminals; any terminal monitors the feedback information of other terminals in real time to determine whether the synchronization data packet is synchronized successfully based on the feedback information, and updates the synchronization record table.
[0020] A second aspect of the present application provides a data synchronization device, including:
[0021] a memory configured to store instructions;
[0022] The processor is configured to call the instructions from the memory and implement the above-mentioned data synchronization method when executing the instructions.
[0023] A third aspect of the present application provides a terminal, comprising the above-mentioned data synchronization device.
[0024] A fourth aspect of the present application provides a data synchronization system, comprising a plurality of the above-mentioned terminals.
[0025] A fifth aspect of the present application provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to enable a machine to execute the above-mentioned data synchronization method.
[0026] Through the above technical solution, a time synchronization strategy is adopted for the unsynchronized terminals to ensure that the system time of multiple terminals in the data synchronization system remains consistent. In addition, through the above customized data synchronization rules, the process of data synchronization service can be accurately controlled in a granular manner, and flexible control of resource usage in the data synchronization service is achieved. Multifunctional data synchronization services for data storage, communication, and backup between multiple terminals are also realized. In this way, the demand trend of multi-machine and multi-control in the mixing station business can be solved. Any two terminals in the data synchronization network can achieve two-way synchronization, removing the restrictions on master-slave synchronization.
[0027] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings:
[0029] Figure 1 A schematic diagram of an application environment of a data synchronization method according to an embodiment of the present application is schematically shown;
[0030] Figure 2 A schematic diagram of a data synchronization method according to an embodiment of the present application is shown schematically;
[0031] Figure 3 A schematic diagram schematically shows a receiving end process of a data synchronization service according to an embodiment of the present application;
[0032] Figure 4 A schematic diagram schematically shows a time synchronization process of a data synchronization service according to an embodiment of the present application;
[0033] Figure 5 A schematic diagram of a process for generating a synchronization data packet according to an embodiment of the present application is shown;
[0034] Figure 6 A schematic diagram schematically shows a sending end process of a data synchronization service according to an embodiment of the present application;
[0035] Figure 7 A structural block diagram of a data synchronization device according to an embodiment of the present application is schematically shown;
[0036] Figure 8 The schematic diagram shows a structure of a computer device according to an embodiment of the present application.
[0037] Description of reference numerals:
[0038] 101 - first terminal; 102 - second terminal; 103 - third terminal. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0040] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back...), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0041] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0042] The data synchronization method provided in this application can be applied to a data synchronization system of multiple terminals. It is designed based on the principle of decentralization. Each terminal in the data synchronization system is both a sender and a receiver. Figure 1In the application environment shown. Any two terminals of the first terminal 101, the second terminal 102, and the third terminal 103 can communicate through the network. The first terminal 101, the second terminal 102, and the second terminal 103 can be, but not limited to, various personal computers, laptops, smart phones, tablet computers, portable wearable devices, industrial computers, servers, etc. The data of the first terminal 101 can be synchronized to the second terminal 102 and the third terminal 103, and the data of the second terminal 102 and the third terminal 103 can also be synchronized to the first terminal 101.
[0043] Figure 2 The following schematically shows a flow chart of a data synchronization method according to an embodiment of the present application. Figure 2 As shown, an embodiment of the present application provides a data synchronization method, which may include the following steps.
[0044] S202: When any terminal among the multiple terminals is online, the any terminal confirms whether first timestamp information sent by another terminal among the multiple terminals is received.
[0045] S204: When any terminal receives the first timestamp information, the terminal calibrates the timestamp of the terminal according to the first timestamp information.
[0046] S206, when any terminal starts the data synchronization service, it monitors the received data packets in real time.
[0047] S208, when the received data packet is a heartbeat data packet, any terminal verifies whether the terminal matches the terminal that sent the heartbeat data packet according to the pairing code carried in the heartbeat data packet.
[0048] S210, when any terminal is successfully authenticated, adds the first sender ID carried in the heartbeat data packet to the target queue.
[0049] S212: When the received data packet is a synchronization data packet, any terminal determines whether there is a second sender ID carried by the synchronization data packet in the target queue.
[0050] S214, when any terminal has the second sender ID in the target queue, the synchronization data packet is synchronized to the database of the any terminal.
[0051] It can be understood that in the process of data interaction between multiple terminals in the data synchronization system, there may be errors in the time between different terminals, so it is necessary to unify the time standards between the terminals through time synchronization processing, so that the occurrence time of database operations of different terminals can be determined to determine the order of occurrence to synchronize data, so the time synchronization between terminals is a prerequisite for data synchronization. Any terminal is any one of the multiple terminals included in the data synchronization system. The first timestamp information refers to the timestamp information sent to the arbitrary terminal by other terminals of the data synchronization system for the above arbitrary terminal, wherein the timestamp information refers to the data generated using the digital signature technology, and the object of the signature includes the original file information, signature parameters, signature time and other information. Specifically, the timestamp information can be a time packet, that is, a data packet used for synchronizing time in network communication. The first timestamp information is sent by the time terminal of the data synchronization system. In order to ensure that the system time of different terminals remains consistent, the data synchronization system should usually have and only have one terminal as the time terminal at the same time, and other terminals will use the time of the time terminal as a reference for time synchronization. After each terminal is connected, it must first perform time synchronization processing before the database service and synchronization process can be started. Then, when any terminal among the multiple terminals is online, any terminal confirms whether it has received the first timestamp information sent by another terminal among the multiple terminals. If any terminal receives the first timestamp information, the timestamp of the terminal is calibrated according to the first timestamp information, and then the data synchronization service is started.
[0052] Data synchronization service refers to ensuring data consistency and real-time performance between different data sources or data systems through certain mechanisms or methods. Its main purpose is to eliminate data silos and achieve data sharing and consistency so that the latest and most accurate data can be accessed in various scenarios. Specifically, the data communication in the data synchronization service process adopts UPD network communication, and uses its broadcast characteristics to send synchronization packets, heartbeat packets and synchronization packets, where the synchronization packets can specify IP unicast. Specifically, when any terminal starts the data synchronization service, it monitors the received data packets in real time. When the received data packet is a heartbeat packet, any terminal verifies whether the terminal matches the terminal that sent the heartbeat packet according to the pairing code carried by the heartbeat packet. It can be understood that the heartbeat packet is a packet that the client sends to the server at regular intervals in network communication. Its main purpose is to let the server know that the client is still in a "live" state and maintain the validity of the network connection. The heartbeat packet usually contains device identification information, such as the device ID, so that the server can identify which device sent the heartbeat packet. In an embodiment of the present application, in order to avoid data synchronization confusion, the heartbeat data packet carries a pairing code and a first sender ID. The pairing code is an identifier of a terminal group. The pairing code verifies whether the terminal and the terminal are in the same group. Only the terminals in the same group will perform data synchronization operations. For example, there are four terminals in the same local area network, and each group of two needs to be synchronized with each other. Then, the same pairing code is set for each group, and the group is isolated. The first sender ID is a unique code (UUID) for identifying the sender. When any terminal is successfully verified, the first sender ID carried by the heartbeat data packet is added to the target queue. The target queue refers to a list of sender IDs maintained by the terminal. For any terminal, the first sender ID that successfully verifies the pairing code will be saved in this maintained target queue. The purpose of setting the target queue is to eliminate resource occupation in the data synchronization service, and it can also isolate terminals that do not need data synchronization services. Then, when the received data packet of any terminal is a synchronization data packet, it can be determined whether there is a second sender ID carried by the synchronization data packet in the target queue. It is understandable that the second sender ID is relative to the first sender ID. The second sender is carried in the synchronization data packet, and the content of the synchronization data packet includes the data information assembled by the terminal that sends the synchronization data packet. If the second sender ID exists in the target queue of the arbitrary terminal, the synchronization data packet can be synchronized to the database of the arbitrary terminal.
[0053] Through the above technical solution, a time synchronization strategy is adopted for the unsynchronized terminals to ensure that the system time of multiple terminals in the data synchronization system remains consistent. In addition, through the above customized data synchronization rules, the process of data synchronization service can be accurately controlled in a granular manner, and flexible control of resource usage in the data synchronization service is achieved. Multifunctional data synchronization services for data storage, communication, and backup between multiple terminals are also realized. In this way, the demand trend of multi-machine and multi-control in the mixing station business can be solved. Any two terminals in the data synchronization network can achieve two-way synchronization, removing the restrictions on master-slave synchronization.
[0054] In an embodiment of the present application, it also includes: when any terminal is successfully verified, the sleepiness degree corresponding to each third sender ID included in the target queue is updated according to the first sender ID carried by the heartbeat data packet; any terminal removes the third sender ID whose sleepiness degree is greater than the preset sleepiness threshold from the target queue.
[0055] It can be understood that the third sender ID is relative to the first sender ID and the second sender ID. Multiple third sender IDs can be stored in the target queue, and the corresponding dormancy degree is maintained for each third sender ID. The dormancy degree can reflect the activity of the terminal corresponding to each third sender ID. Specifically, the lower the dormancy degree, the more active the terminal corresponding to the third sender ID is. If there is a third sender ID whose dormancy degree is greater than the preset dormancy threshold, it can be considered that the terminal corresponding to the third sender ID may have been offline, and there is no need to provide data synchronization service resources to the terminal, remove it from the target queue, and stop the terminal corresponding to the third sender ID from occupying data synchronization service resources.
[0056] In an embodiment of the present application, when any terminal is successfully verified, the sleepiness degree corresponding to each third sender ID included in the target queue is updated according to the first sender ID carried by the heartbeat data packet, including: when any terminal is successfully verified and there is a third sender ID identical to the first sender ID in the target queue, the sleepiness degree corresponding to the third sender ID is updated to zero, and the sleepiness degree corresponding to the third sender ID in the target queue that is not the same as the first sender ID is incremented.
[0057] It can be understood that each time the heartbeat data is received and the pairing code verification is successful, if there is a third sender ID that is the same as the first sender ID in the target queue of any terminal, the dormancy degree corresponding to the third sender ID is updated to zero to refresh the activity of the third sender ID. For other third sender IDs in the target queue that are not the same as the first sender ID, the corresponding dormancy degree can be +1. If there is a third sender ID whose dormancy degree is greater than the preset dormancy degree threshold, it can be removed from the target queue.
[0058] In an embodiment of the present application, when any terminal has a second sender ID in the target queue, the synchronization data packet is synchronized to the database of any terminal, including: when any terminal has a second sender ID in the target queue, determining whether the synchronization data packet is valid based on the second timestamp information carried by the synchronization data packet; when any terminal determines that the synchronization data packet is valid, the synchronization data packet is synchronized to the database of the terminal; when any terminal determines that the synchronization data packet is invalid, the invalidation information of the synchronization data packet is sent to other terminals.
[0059] It can be understood that, when a synchronization data packet is received, it can be confirmed first whether the second sending terminal ID of the terminal that sent the synchronization data packet exists in the target queue of the arbitrary terminal. If it exists, it can be determined whether the synchronization data packet is valid based on the second timestamp information carried by the synchronization data packet. The effective judgment is to confirm whether the synchronization data packet is outdated. For example, for the data content of the synchronization data packet, the arbitrary terminal may have received data that is updated relative to the data of the synchronization data packet, then the synchronization data packet is outdated, and it can be considered that the synchronization data packet has expired. In addition, whether the synchronization data packet is valid can be judged based on the data content and the second timestamp information of the synchronization data packet. When any terminal determines that the synchronization data packet is valid, it synchronizes the synchronization data packet to the database of the terminal for parsing, and sends confirmation feedback to the terminal that sent the synchronization data packet. When any terminal determines that the synchronization data packet is invalid, it can directly send the invalidation information of the synchronization data packet to other terminals.
[0060] refer to Figure 3In a specific embodiment, specifically, any terminal monitors the received data packets in real time when the data synchronization service is started. When the received data packet is a heartbeat data packet, any terminal verifies whether the terminal matches the terminal that sends the heartbeat data packet according to the pairing code carried in the heartbeat data packet. The heartbeat data packet carries the pairing code and the first sender ID. When the verification is successful, any terminal adds the first sender ID carried by the heartbeat data packet to the target queue. In addition, the dormancy degree corresponding to each third sender ID included in the target queue is updated according to the first sender ID carried by the heartbeat data packet, and any terminal removes the third sender ID whose dormancy degree is greater than the preset dormancy degree threshold from the target queue. It can be understood that, when the verification is not successful, the dormancy degree corresponding to each third sender ID included in the target queue can also be updated according to the first sender ID carried by the heartbeat data packet. Among them, when there is a third sender ID identical to the first sender ID in the target queue, the dormancy degree corresponding to the third sender ID can be updated to zero, and the dormancy degree corresponding to the third sender ID in the target queue that is not identical to the first sender ID is added by 1. When the received data packet is a synchronization data packet, the arbitrary terminal can determine whether the second sender ID carried by the synchronization data packet exists in the target queue. When the second sender ID exists in the target queue, the arbitrary terminal determines whether the synchronization data packet is valid according to the second timestamp information carried by the synchronization data packet. When the arbitrary terminal determines that the synchronization data packet is valid, the arbitrary terminal synchronizes the synchronization data packet to the database of the terminal and returns confirmation feedback. When the arbitrary terminal determines that the synchronization data packet is invalid, the invalidation information of the synchronization data packet is sent to other terminals.
[0061] In an embodiment of the present application, it also includes: when any terminal fails to receive the first timestamp information within a first preset time period, it sends a notification to other terminals among multiple terminals that it has become a time synchronization terminal; when any terminal fails to receive the first timestamp information within a second preset time period after sending the notification, it sends third timestamp information to other terminals and starts a data synchronization service; when any terminal receives the first timestamp information within the second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information has been received.
[0062] It can be understood that if any terminal does not receive the first timestamp information sent by other terminals within the first preset time length, it can be considered that the time synchronization terminal in the data synchronization system may have been offline, so a notification of becoming a time synchronization terminal is sent to other terminals among the multiple terminals to apply to become a time synchronization terminal in the data synchronization system. If the arbitrary terminal does not receive the first timestamp information sent by other terminals within the second preset time length after sending the notification, the third timestamp information is sent to other terminals, and the data synchronization service is started. At this time, it can be considered that the arbitrary terminal has successfully applied to become a time synchronization terminal in the data synchronization system, and other terminals can perform time synchronization operations according to the third timestamp information sent by the arbitrary terminal. Another possible situation is that the time synchronization terminal sends a time synchronization package (first timestamp information) regularly, and the time interval between the last sending of the time synchronization package and the next sending of the time synchronization package is greater than the first preset time length. Although the first preset time length is usually set to be greater than the time interval, the time synchronization terminal may have occasional failures, resulting in a time interval greater than the first preset time length, so that the arbitrary terminal receives the first timestamp information within the second preset time length of the notification sent by the arbitrary terminal to other terminals. At this time, the arbitrary terminal can cancel the application to become a time synchronization terminal. Another situation is that when the synchronization terminal of the data synchronization system fails or goes offline, other terminals may apply to become synchronization terminals because they cannot receive synchronization packages, and then send synchronization packages to the arbitrary terminal, so that the arbitrary terminal receives the first timestamp information within the second preset time. In order to eliminate the synchronization conflict caused by the above situation, if any terminal receives the first timestamp information within the second preset time, it can wait for a period of time to reconfirm whether the first timestamp information is received. If the first timestamp information is received again, repeat Figure 2 If not received, the above process of applying to become a time synchronization terminal to send the third timestamp information for time synchronization can be repeated.
[0063] In an embodiment of the present application, it also includes: any terminal detects in real time whether the first timestamp information is received when starting to send the third timestamp information; when any terminal receives the first timestamp information after sending the third timestamp information, it stops sending the third timestamp information, suspends the data synchronization service, and reconfirms whether the first timestamp information is received again.
[0064] It is understandable that when any terminal becomes a synchronization terminal of the data synchronization system and starts to send the third timestamp information, it still needs to detect in real time whether it has received the first timestamp information sent by other terminals. If any terminal receives the first timestamp information after sending the third timestamp information, there are two synchronization terminals in the data synchronization system at this time, and a synchronization conflict occurs, then the terminal can stop sending the third timestamp information, suspend the data synchronization service, and reconfirm whether the first timestamp information is received again. If the first timestamp information is received again, repeat Figure 2 If not received, the above process of applying to become a time synchronization terminal to send the third timestamp information for time synchronization can be repeated.
[0065] In an embodiment of the present application, when any terminal receives the first timestamp information within the second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information is received, including: when any terminal receives the first timestamp information within the second preset time period, determining the number of conflicts in which a timing conflict event occurs at any terminal, a timing conflict event means that any terminal does not receive the first timestamp information within the first preset time period, or any terminal receives the first timestamp information within the second preset time period; determining the waiting time of any terminal according to the number of conflicts; and reconfirming whether the first timestamp information is received at any terminal after the waiting time.
[0066] It can be understood that when any terminal receives the first timestamp information within the second preset time period after sending the notification, it is considered that a time synchronization conflict event has occurred at this time. A time synchronization conflict event may have occurred before. If any terminal does not receive the first timestamp information within the first preset time period, it is also a time synchronization conflict event. Then, the number of conflicts of the time synchronization conflict events that occur can be accumulated. The occurrence of a time synchronization conflict event can be considered to be that the time waiting to receive the first timestamp information is too short. Then, the waiting time to check whether the first timestamp information is received can be extended according to the number of conflicts. If any terminal reconfirms whether the first timestamp information is received after the waiting time, the occurrence of time synchronization conflict events can also be reduced, and the time synchronization operation of the data synchronization system can be completed faster.
[0067] refer to Figure 4In a specific embodiment, when any terminal among multiple terminals goes online, any terminal confirms whether it has received the first timestamp information sent by another terminal among the multiple terminals. When any terminal receives the first timestamp information, it calibrates the timestamp of any terminal according to the first timestamp information, and starts the data synchronization service after calibration. When any terminal does not receive the first timestamp information within the first preset time length, it sends a notification of becoming a time synchronization terminal to other terminals among the multiple terminals. When any terminal does not receive the first timestamp information within the second preset time length after sending the notification, it sends the third timestamp information to other terminals and starts the data synchronization service. When any terminal receives the first timestamp information within the second preset time length, it waits for a period of time and then returns to the process of confirming whether the first timestamp information is received. Any terminal detects whether the first timestamp information is received in real time from the start of sending the third timestamp information. When any terminal receives the first timestamp information after sending the third timestamp information, it stops sending the third timestamp information, suspends the data synchronization service, and then returns to the process of reconfirming whether the first timestamp information is received again. Specifically, when any terminal receives the first timestamp information within the second preset time length, the number of conflicts in which the timing conflict event occurs at any terminal is determined, where the timing conflict event refers to any terminal not receiving the first timestamp information within the first preset time length, or any terminal receiving the first timestamp information within the second preset time length; the waiting time of any terminal is determined according to the number of conflicts; and any terminal reconfirms whether the first timestamp information is received after the waiting time. When any terminal fails to receive the first timestamp information within the first preset time length for the first time, or when any terminal receives the first timestamp information within the second preset time length for the first time, a fixed waiting time length can be set. The waiting time lengthens as the number of conflicts increases. Specifically, it can be calculated according to the following formula (1):
[0068] w=s+n×K i (1)
[0069] Among them, w refers to the waiting time, s refers to the fixed waiting time, n refers to the number of conflicts, and K i Refers to the random factor set for the i-th terminal.
[0070] In an embodiment of the present application, it also includes: when any terminal sends the third timestamp information, the number of conflicts is updated to zero.
[0071] In an embodiment of the present application, it also includes: any terminal extracts data update content from the database of any terminal through the created trigger, and the data update content includes data operation, data update time and data content; any terminal queries the unsynchronized data to be synchronized from the synchronization record table of any terminal; any terminal assembles the data update content and the data to be synchronized into a synchronization data packet, and adds the synchronization data packet to the sending queue; any terminal traverses the synchronization data packets in the sending queue to remove the synchronization data packets from the sending queue in turn, and sends them to other terminals; any terminal monitors the feedback information of other terminals in real time to determine whether the synchronization data packet is synchronized successfully based on the feedback information, and updates the synchronization record table.
[0072] It can be understood that the synchronization data packet is sent by the terminal in the data synchronization system, which contains the terminal UUID and the data content that needs to be synchronized. From the perspective of the sender, a trigger is created for the operation that needs to be synchronized, and the data operation, data update time and data content are recorded in the database. Figure 5 , corresponding triggers can be set for different data tables, and any terminal can extract data update content from the database of any terminal through the created trigger. The trigger can be set on the table that needs to be synchronized in the database, record the add, delete, and modify operations on the table, and record it in the operation table. Any terminal can also periodically pull the data to be synchronized that has not been sent from the sender ID from the data record library, assemble the data update content and the data to be synchronized into a data packet and add it to the sending queue. Among them, the data update content can be queried conditionally through the query parameters, and the unsynchronized data to be synchronized can be queried in the synchronization record table to filter the operated data. The sending queue can maintain a priority and set it according to the real-time requirements of different operation tables. After the synchronization data packet is sent, the confirmation feedback is listened immediately. If the confirmation feedback is received, the mapping relationship between the sender ID, the receiver ID and the data ID is stored in the library as a mark, and the sent synchronization data packet is removed from the sending queue of the sender, and the operation record is written back to the synchronization record table. From the perspective of the receiving end, the received data packet is parsed according to the format, and firstly, it is determined whether the data is outdated according to the occurrence time. If it is outdated, the confirmation feedback is sent back directly without any processing. If it is not outdated, the addition, deletion and modification operations of different tables will be executed according to the specific rules. If the execution is successful, a confirmation feedback will be sent back.
[0073] The ultimate goal of the above is not to achieve complete data synchronization between different terminals, but to achieve key data synchronization in business scenarios. The original data does not participate in the synchronization, but the data to be synchronized is generated through trigger construction. Triggers are based on data tables and can specify different rules for different data tables. And the control of data rows and columns is achieved through trigger parameters and logic. It can save unnecessary resource overhead for data synchronization, and can more flexibly customize synchronization rules and achieve granular control.
[0074] refer to Figure 6 For the sending end, any terminal extracts the data update content from the operation table of the database of any terminal through the created trigger, assembles it into heartbeat data packets and synchronization data packets, and adds it to the sending queue. It traverses the sending queue to send data packets, removes each data packet from the queue and sends it according to the rules. After that, it monitors the feedback confirmation sent by other terminals in real time and updates the synchronization mark of the synchronization data table.
[0075] In actual business scenarios, such as data synchronization scenarios in mixing plants, real-time requirements can be met through network control devices. Production control is much more important than data integrity, and synchronization network traffic is controlled through various parameters, such as sending frequency, throughput, start time, etc. For example, during the generation process, the synchronization process is suspended to leave resources for device control. Similarly, by setting different scanning frequencies for different data tables and different priorities for different operations, the proportion of different types of data in the queue and the sending priority can be controlled. If the ratio is extremely important data in the mixing plant business and directly affects product performance, the scanning frequency can be increased or the priority can be increased. On the contrary, the production history has relatively low real-time requirements, and the scanning frequency can be reduced accordingly.
[0076] The above solution is designed to solve the demand trend of multi-machine multi-control in actual business scenarios, which cannot be adapted to the traditional synchronization of two terminals. Therefore, it is designed based on the principle of decentralization, and each terminal in the network is both a sender and a receiver. Single synchronization occurs in pairs and has a direction, but any two terminals in the synchronization network can achieve bidirectional synchronization, which removes the limitation of master-slave synchronization. A single terminal network failure does not affect the entire synchronization process. After the network is restored, it will automatically connect without affecting data integrity.
[0077] Figure 1 FIG. 1 is a flow chart of a data synchronization method in an embodiment. It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0078] Figure 7 The structure block diagram of a data synchronization device according to an embodiment of the present application is schematically shown. Figure 7As shown, an embodiment of the present application provides a data synchronization device, which may include:
[0079] a memory configured to store instructions;
[0080] The processor is configured to call instructions from the memory and implement the above data synchronization method when executing the instructions.
[0081] Specifically, in the embodiment of the present application, the processor may be configured to:
[0082] When any terminal among the multiple terminals is online, any terminal confirms whether it has received first timestamp information sent by another terminal among the multiple terminals;
[0083] When any terminal receives the first timestamp information, calibrate the timestamp of the any terminal according to the first timestamp information;
[0084] When any terminal starts the data synchronization service, it monitors the received data packets in real time;
[0085] When the data packet received by any terminal is a heartbeat data packet, the terminal verifies whether the terminal matches the terminal sending the heartbeat data packet according to the pairing code carried in the heartbeat data packet;
[0086] When any terminal successfully verifies, it adds the first sender ID carried in the heartbeat data packet to the target queue;
[0087] When any terminal receives a synchronous data packet, it determines whether the second sending end ID carried by the synchronous data packet exists in the target queue;
[0088] When any terminal has the second sender ID in the target queue, the synchronization data packet is synchronized to the database of the any terminal.
[0089] In an embodiment of the present application, the processor may also be configured to:
[0090] If any terminal succeeds in verification, it updates the sleepiness corresponding to each third transmitter ID included in the target queue according to the first transmitter ID carried in the heartbeat data packet; any terminal removes the third transmitter ID whose sleepiness is greater than the preset sleepiness threshold from the target queue.
[0091] In an embodiment of the present application, the processor may also be configured to:
[0092] When any terminal is successfully verified, the sleep degree corresponding to each third sender ID included in the target queue is updated according to the first sender ID carried in the heartbeat data packet, including: when any terminal is successfully verified and there is a third sender ID identical to the first sender ID in the target queue, the sleep degree corresponding to the third sender ID is updated to zero, and the sleep degree corresponding to the third sender ID in the target queue that is not the same as the first sender ID is incremented.
[0093] In an embodiment of the present application, the processor may also be configured to:
[0094] When any terminal has a second sender ID in the target queue, the synchronization data packet is synchronized to the database of any terminal, including: when any terminal has a second sender ID in the target queue, determining whether the synchronization data packet is valid based on the second timestamp information carried by the synchronization data packet; when any terminal determines that the synchronization data packet is valid, the synchronization data packet is synchronized to the database of the terminal; when any terminal determines that the synchronization data packet is invalid, the invalidation information of the synchronization data packet is sent to other terminals.
[0095] In an embodiment of the present application, the processor may also be configured to:
[0096] If any terminal fails to receive the first timestamp information within the first preset time period, it sends a notification to other terminals among the multiple terminals that it has become a time synchronization terminal; if any terminal fails to receive the first timestamp information within the second preset time period after sending the notification, it sends third timestamp information to other terminals and starts a data synchronization service; if any terminal receives the first timestamp information within the second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information has been received.
[0097] In an embodiment of the present application, the processor may also be configured to:
[0098] Any terminal detects in real time whether the first timestamp information is received after starting to send the third timestamp information; if any terminal receives the first timestamp information after sending the third timestamp information, it stops sending the third timestamp information, suspends the data synchronization service, and reconfirms whether the first timestamp information is received again.
[0099] In an embodiment of the present application, the processor may also be configured to:
[0100] When any terminal receives the first timestamp information within a second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information is received, including: when any terminal receives the first timestamp information within the second preset time period, determining the number of conflicts in a timing conflict event that occurs at any terminal, a timing conflict event means that any terminal does not receive the first timestamp information within the first preset time period, or any terminal receives the first timestamp information within the second preset time period; determining the waiting time for any terminal according to the number of conflicts; and reconfirming whether the first timestamp information is received at any terminal after the waiting time.
[0101] In an embodiment of the present application, the processor may also be configured to:
[0102] When any terminal sends the third timestamp information, the number of conflicts is updated to zero.
[0103] In an embodiment of the present application, the processor may also be configured to:
[0104] Any terminal extracts data update content from the database of any terminal through the created trigger, and the data update content includes data operation, data update time and data content; any terminal queries the unsynchronized data to be synchronized from the synchronization record table of any terminal; any terminal assembles the data update content and the data to be synchronized into a synchronization data packet, and adds the synchronization data packet to the sending queue; any terminal traverses the synchronization data packets in the sending queue to remove the synchronization data packets from the sending queue in turn and send them to other terminals; any terminal monitors the feedback information of other terminals in real time to determine whether the synchronization data packet is synchronized successfully based on the feedback information, and updates the synchronization record table.
[0105] An embodiment of the present application also provides a terminal, which may include the above-mentioned data synchronization device.
[0106] An embodiment of the present application also provides a data synchronization system, comprising a plurality of the above-mentioned terminals.
[0107] An embodiment of the present application also provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to enable a machine to execute the above-mentioned data synchronization method.
[0108] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8As shown. The computer device includes a processor A01, a network interface A02, a memory (not shown in the figure) and a database (not shown in the figure) connected via a system bus. Among them, the processor A01 of the computer device is used to provide computing and control capabilities. The memory of the computer device includes an internal memory A03 and a non-volatile storage medium A04. The non-volatile storage medium A04 stores an operating system B01, a computer program B02 and a database (not shown in the figure). The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 in the non-volatile storage medium A04. The database of the computer device is used to store data of a data synchronization method. The network interface A02 of the computer device is used to communicate with an external terminal through a network connection. When the computer program B02 is executed by the processor A01, a data synchronization method is implemented.
[0109] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0110] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0111] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0112] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0113] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0114] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0115] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0116] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0117] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0118] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A data synchronization method, characterized in that: The method is applied to a data synchronization system, the data synchronization system includes a plurality of terminals, and the method includes: When any terminal among the multiple terminals is online, the any terminal confirms whether first timestamp information sent by another terminal among the multiple terminals is received; When receiving the first timestamp information, the arbitrary terminal calibrates the timestamp of the arbitrary terminal according to the first timestamp information; When the data synchronization service is started, any terminal monitors the received data packets in real time; When the received data packet is a heartbeat data packet, the arbitrary terminal verifies whether the arbitrary terminal matches the terminal sending the heartbeat data packet according to the pairing code carried in the heartbeat data packet; When verification is successful, any terminal adds the first sender ID carried in the heartbeat data packet to the target queue; When the received data packet is a synchronization data packet, the arbitrary terminal determines whether the second sending end ID carried by the synchronization data packet exists in the target queue; When the second sender ID exists in the target queue, the arbitrary terminal synchronizes the synchronization data packet to the database of the arbitrary terminal.
2. The data synchronization method according to claim 1, characterized in that: Also includes: When the verification is successful, the arbitrary terminal updates the sleep degree corresponding to each third sending end ID included in the target queue according to the first sending end ID carried in the heartbeat data packet; The arbitrary terminal removes the third sending terminal ID whose sleep degree is greater than a preset sleep degree threshold from the target queue.
3. The data synchronization method according to claim 2, characterized in that: When the verification is successful, the arbitrary terminal updates the sleep degree corresponding to each third sender ID included in the target queue according to the first sender ID carried in the heartbeat data packet, including: When any terminal successfully verifies and there is a third sender ID identical to the first sender ID in the target queue, the sleep degree corresponding to the third sender ID is updated to zero, and the sleep degree corresponding to the third sender ID in the target queue that is not the same as the first sender ID is incremented.
4. The data synchronization method according to claim 1, characterized in that: When the second sender ID exists in the target queue, the arbitrary terminal synchronizes the synchronization data packet to a database of the arbitrary terminal, including: When the second sending end ID exists in the target queue, the arbitrary terminal determines whether the synchronization data packet is valid according to the second timestamp information carried by the synchronization data packet; When determining that the synchronization data packet is valid, the arbitrary terminal synchronizes the synchronization data packet to a database of the terminal; When determining that the synchronization data packet is invalid, the arbitrary terminal sends invalidation information of the synchronization data packet to the other terminals.
5. The data synchronization method according to claim 1, characterized in that: Also includes: When any terminal fails to receive the first timestamp information within a first preset time period, sending a notification of becoming a time synchronization terminal to other terminals among the multiple terminals; When the arbitrary terminal fails to receive the first timestamp information within a second preset time period after sending the notification, the arbitrary terminal sends third timestamp information to the other terminals and starts a data synchronization service; When any terminal receives the first timestamp information within a second preset time period, it waits for a period of time and then reconfirms whether the first timestamp information is received.
6. The data synchronization method according to claim 5, characterized in that: Also includes: The arbitrary terminal detects in real time whether the first timestamp information is received after starting to send the third timestamp information; When the arbitrary terminal receives the first timestamp information after sending the third timestamp information, it stops sending the third timestamp information, suspends the data synchronization service, and reconfirms whether the first timestamp information is received again.
7. The data synchronization method according to claim 5, characterized in that: When any terminal receives the first timestamp information within a second preset time period, reconfirming whether the first timestamp information is received after waiting for a time period includes: When any terminal receives the first timestamp information within a second preset time period, determining the number of conflicts in which a timing conflict event occurs at any terminal, wherein the timing conflict event refers to that any terminal fails to receive the first timestamp information within the first preset time period, or any terminal receives the first timestamp information within the second preset time period; Determining the waiting time of the arbitrary terminal according to the number of conflicts; The arbitrary terminal reconfirms whether the first timestamp information is received after the waiting period.
8. The data synchronization method according to claim 7, characterized in that: Also includes: When sending the third timestamp information, the arbitrary terminal updates the number of conflicts to zero.
9. The data synchronization method according to claim 1, characterized in that: Also includes: The arbitrary terminal extracts data update content from the database of the arbitrary terminal through the created trigger, and the data update content includes data operation, data update time and data content; The arbitrary terminal queries the unsynchronized data to be synchronized from the synchronization record table of the arbitrary terminal; The arbitrary terminal assembles the data update content and the data to be synchronized into a synchronization data packet, and adds the synchronization data packet to a sending queue; The arbitrary terminal traverses the synchronization data packets in the sending queue to remove the synchronization data packets from the sending queue in sequence and send them to the other terminals; The arbitrary terminal monitors the feedback information of the other terminals in real time, determines whether the synchronization data packet is successfully synchronized according to the feedback information, and updates the synchronization record table.
10. A data synchronization device, characterized in that: include: a memory configured to store instructions; A processor is configured to call the instruction from the memory and implement the data synchronization method according to any one of claims 1 to 9 when executing the instruction.
11. A terminal, characterized in that: The device comprises the data synchronization device according to claim 10.
12. A data synchronization system, characterized in that: Comprising a plurality of terminals as claimed in claim 11.
13. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores instructions, which are used to enable a machine to execute the data synchronization method according to any one of claims 1 to 9.