WO2017162079A1 - Data synchronization method and apparatus - Google Patents

Data synchronization method and apparatus Download PDF

Info

Publication number
WO2017162079A1
WO2017162079A1 PCT/CN2017/076753 CN2017076753W WO2017162079A1 WO 2017162079 A1 WO2017162079 A1 WO 2017162079A1 CN 2017076753 W CN2017076753 W CN 2017076753W WO 2017162079 A1 WO2017162079 A1 WO 2017162079A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
terminal device
synchronization
timestamp
identifier
Prior art date
Application number
PCT/CN2017/076753
Other languages
French (fr)
Chinese (zh)
Inventor
周遥
Original Assignee
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2017162079A1 publication Critical patent/WO2017162079A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/40Support for services or applications

Definitions

  • the present invention relates to the field of network technologies, and in particular, to a data synchronization method and apparatus.
  • Solution 1 as shown in Figure 1: Adding a configuration center to the server cluster, when one of the servers (publishers) gets the data and wants to synchronize the data to other servers (subscribers), the server will The data is sent to the configuration center, and the configuration center sends the data to other servers, so that other servers synchronize according to the data.
  • the server cluster elects a publisher master through an election algorithm, and the other servers are subscribers. After the selection succeeds, when the server cluster needs to synchronize one data, the master obtains The data is sent by the master to the subscriber to be synchronized, so that the subscriber synchronizes the data, and after the subscriber synchronizes successfully, the synchronization success message is returned to the master. When the master is down, The server cluster needs to re-enter the election master.
  • Solution 1 relies on third-party devices when synchronizing data. The deployment is troublesome and the reliability is not high. In scenario 2, if the number of servers in the cluster is large, the number of successful messages returned by the subscribers will also increase. The cost of data synchronization is greatly increased, and after the Master is down, the cost of data synchronization will also increase when re-election.
  • the present invention provides a data synchronization method and apparatus for solving the problem of relying on third-party equipment in the prior art, which is troublesome to deploy and low in reliability.
  • the invention provides a data synchronization method and device, and is also used to solve the problem of high data synchronization cost in the prior art.
  • the present invention provides a method for synchronizing data, the method being applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device are synchronized,
  • the second terminal device is multiple, and the method includes:
  • the first terminal device When the first terminal device receives the data, the first terminal device adds a timestamp of receiving the data to the data;
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
  • the first terminal device performs data synchronization according to the data that is saved by adding the timestamp and the feedback data, which is specifically:
  • the first terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier
  • the first terminal device performs data synchronization according to data corresponding to the maximum time stamp.
  • the first terminal device sets a life cycle for saving the data with the timestamp added, and when the first terminal device determines the sum of the numbers of data having the same data identifier in the life cycle When not greater than the threshold, the first terminal device deletes data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
  • the first terminal device When the synchronization type in the data corresponding to the maximum timestamp is the synchronization data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp;
  • the first terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
  • a data synchronization device the data synchronization device is located at a first terminal device, and is applied to include the first terminal In the system of the end device and the plurality of second terminal devices, wherein the times of the first terminal device and the second terminal device are synchronized, the data synchronization device includes:
  • Adding a module when the first terminal device receives the data, adding a timestamp for receiving the data to the data;
  • a sending module configured to send the data that is added with the timestamp to the second terminal device, and save the data that is added with the timestamp
  • a receiving module configured to receive data that is fed back by the second terminal device according to the data added with the timestamp, so that the synchronization module in the first terminal device adds the timestamp according to the saved
  • the data and the feedback data are data synchronized.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
  • the synchronization module is specifically configured to:
  • the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
  • Data synchronization is performed based on the data corresponding to the maximum time stamp.
  • the adding module is further configured to set a life cycle for saving the data to which the time stamp is added;
  • the device also includes:
  • Deleting a module when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the synchronization module is also specifically configured to:
  • the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data
  • the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
  • a data synchronization method the method being applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device are synchronized, the second There are multiple terminal devices, and the method includes:
  • the second terminal device receives the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data feedback;
  • the second terminal device performs data synchronization according to the data added with time stamp and the feedback data
  • the timestamp is determined by the first terminal device according to the time when the data is received.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
  • the second terminal device performs data synchronization according to the data added with time stamp and the feedback data, specifically:
  • the second terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier
  • the second terminal device performs data synchronization according to data corresponding to the maximum time stamp.
  • the time-stamped data carries the first terminal device to set a life cycle for the data, and when the second terminal device determines data having the same data identifier in the life cycle, When the sum of the numbers is not greater than the threshold, the second terminal device deletes data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the second terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
  • the second terminal device When the synchronization type in the data corresponding to the maximum time stamp is the synchronization data, the second terminal device performs data synchronization according to the data corresponding to the maximum time stamp;
  • the second terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
  • the second terminal device After the second terminal device receives the time-stamped data sent by the first terminal device, the second terminal device will be in the same data as the data identifier of the time-stamped data.
  • the data with the largest timestamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
  • a data synchronization device the data synchronization device being located in a second terminal device, applied to a system including a first terminal device and a plurality of the second terminal devices, wherein the first terminal device and the second device The time of the terminal device is synchronized, and the data synchronization device includes:
  • a receiving module configured to receive the time-stamped data sent by the first terminal device and the data sent by the second terminal device according to the added time-stamped data feedback;
  • a synchronization module configured to perform data synchronization according to the time-stamped data and the feedback data
  • the timestamp is determined by the first terminal device according to the time when the data is received.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
  • the synchronization module is specifically configured to:
  • the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
  • Data synchronization is performed based on the data corresponding to the maximum time stamp.
  • the time-stamped data carries the first terminal device to set a life cycle for the data
  • the device also includes:
  • Deleting a module when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the synchronization module is also specifically configured to:
  • the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data
  • the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
  • the device also includes:
  • a sending module after receiving the time-stamped data sent by the first terminal device, the receiving module is configured to maximize a timestamp in the same data as the data identifier of the time-stamped data
  • the data is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
  • the first terminal device when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second
  • the terminal device is based on the data fed back by the data added with the time stamp, and according to the method that is saved by itself and added with the time stamp
  • the data and the feedback data are data synchronized, and the invention realizes data synchronization of the terminal device cluster without using the third party device and the election sending data device, reduces the cost in data synchronization, and the terminal in the cluster
  • the device synchronizes according to the data obtained by itself, ensuring the reliability of data synchronization.
  • FIG. 1 is a schematic flowchart of data synchronization by using a third-party device in the prior art
  • FIG. 2 is a schematic flow chart of data synchronization by an election publisher in the prior art
  • FIG. 3 is a flowchart of a method for synchronizing data according to an embodiment of the present invention.
  • FIG. 4 is a second flowchart of a method for synchronizing data according to an embodiment of the present invention.
  • FIG. 5 is a schematic flowchart of a synchronization method during data distribution according to an embodiment of the present invention
  • FIG. 6 is a schematic structural diagram of a data synchronization apparatus according to an embodiment of the present invention.
  • FIG. 7 is a second schematic structural diagram of a data synchronization apparatus according to an embodiment of the present invention.
  • the present application proposes a a method for synchronizing data, as shown in FIG. 3, the method is applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device is synchronized
  • the second terminal device is multiple, and the method includes the following steps:
  • Step 301 When the first terminal device receives the data, the first terminal device adds a timestamp of receiving the data to the data.
  • the first terminal device is a device that receives data
  • the first terminal device is not a fixed device in the cluster, and is determined according to a device that receives data in the cluster, where the data is sent by a device other than the cluster. of.
  • there are three terminal devices in the cluster namely device 1, device 2, and device 3.
  • device 1 receives the data sent by the client
  • device 1 is the first terminal device, and if device 2 receives the client.
  • the device 2 When the data is sent, the device 2 is the first terminal device.
  • the second terminal device is a terminal device other than the first terminal device in the cluster, and the second terminal device is a device in the cluster that receives data sent by the first terminal device, for example, there are 3 in the cluster.
  • the terminal devices are device 1, device 2 and device 3.
  • device 1 When device 1 is the first terminal device, device 2 and device 3 are the second terminal device.
  • device 1 and device are 3 is the second terminal device.
  • Step 302 The first terminal device sends the data with the timestamp added to the second terminal device, and saves the data with the timestamp added.
  • the first terminal device saves the data added with the timestamp for subsequent data synchronization.
  • Step 303 The first terminal device receives data that is fed back by the second terminal device according to the data that is added with the timestamp, so that the first terminal device adds the timestamp according to its own saved
  • the data and the feedback data are data synchronized.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
  • the data sent by the device outside the cluster received by the terminal device in the cluster carries the data identifier, and the data identifier of the same data sent by the device outside the cluster is the same, where the same data may be different.
  • Time is sent, the cluster is synchronized according to the received data, so the devices in the cluster may have the same data as the data identifier of the currently received data, and the devices in the cluster also exist in the same data identifier. The timestamp of receiving the data.
  • the second terminal device may have the same data identifier as the data. Therefore, when the second terminal device receives the data added with the timestamp, the second terminal device needs to be added according to the adding device. Determining, by the time stamp, the data identifier of the data that the data of the same data identifier exists in the second terminal, and then The second terminal device determines the data with the largest timestamp according to the data with the same data identifier. The data determined at this time is the latest data received by the cluster, and needs to be used as the basis for data synchronization, and the determined timestamp is the largest. The data is fed back to the first terminal device as the feedback data.
  • the first terminal device After the first terminal device receives the data with the highest timestamp fed back by the second terminal device in the cluster, the first terminal device can use the feedback data. And the data saved by itself and added with the time stamp determines the latest data, so that the first terminal device performs data synchronization according to the latest data.
  • the first terminal device performs data synchronization according to the data that is saved by adding the timestamp and the feedback data, which is specifically:
  • the first terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier
  • the first terminal device performs data synchronization according to data corresponding to the maximum time stamp.
  • the threshold is determined according to an actual situation, for example, the threshold is half of the number of terminal devices in the cluster, and the number of data having the same data identifier determined by the first terminal device indicates that the cluster is in the cluster. How many terminal devices have received the data, and when the number exceeds the threshold, it indicates that the cluster has reached the requirement of data synchronization, and at this time, the first terminal device can perform data synchronization according to the latest data in itself.
  • the first terminal device sets a life cycle for saving the data with the timestamp added, and when the first terminal device determines the sum of the numbers of data having the same data identifier in the life cycle When not greater than the threshold, the first terminal device deletes data having the same data identifier.
  • data synchronization must be completed within a certain time during data synchronization, otherwise the meaning of data synchronization is lost. Therefore, when the first terminal device adds a time stamp to the data, the data is also set.
  • the life cycle the length of the life cycle is determined according to actual conditions.
  • the data synchronization fails. Assuring that the resources of the first terminal device are not wasted, so the first terminal device deletes data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
  • the first terminal device When the synchronization type in the data corresponding to the maximum timestamp is the synchronization data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp;
  • the first terminal deletes The data value in the data corresponding to the maximum time stamp, and the data synchronization is performed according to the data corresponding to the maximum time stamp in which the data value is deleted.
  • the first terminal device in order to unify the data of the terminal devices in the cluster, when the data received by the first terminal device is synchronized, sometimes to increase data, and sometimes to delete data, if When the synchronization type of the data corresponding to the maximum timestamp determined by the first terminal device is synchronous data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp; if the first terminal When the synchronization type of the data corresponding to the maximum timestamp determined by the device is to delete the data, the first terminal device deletes the data corresponding to the maximum timestamp according to the data corresponding to the maximum timestamp.
  • the first terminal device may delete only the data itself when the data is deleted, and retain the data corresponding to Information such as timestamp, synchronization type, and data identification for subsequent queries.
  • the first terminal device And receiving, by the first terminal device, at least one data with the same data identifier sent by a device other than the cluster.
  • the first terminal device performs data synchronization according to a sequence of receiving data.
  • the first terminal device when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second
  • the terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device.
  • the data synchronization of the terminal device cluster is realized, the cost of data synchronization is reduced, and the terminal devices in the cluster are synchronized according to the data obtained by themselves, thereby ensuring the reliability in data synchronization.
  • the present invention also provides a data synchronization method, as shown in FIG. 4, the method is applied to a system including a first terminal device and a second terminal device, wherein the first terminal device and the first The time of the two terminal devices is synchronized, and the second terminal device is multiple.
  • the method includes the following steps:
  • Step 401 The second terminal device receives the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data.
  • the timestamp is determined by the first terminal device according to the time when the data is received.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
  • the terminal device cluster includes: device 1, device 2, and device 3, wherein the device 1 is a first terminal device, and device 2 and device 3 are second terminal devices.
  • the device Device 1 When the device 1 receives data, the device Device 1 is When the time-stamped data is sent to the device 2, the device 3 is also sent to the device 3, and the device 2 is the second terminal device, and the device 3 is the other second terminal device.
  • the data may have the same data identifier in the device 3, and in order to ensure that the device 2 updates the latest data when performing data synchronization, the device 3 will also determine that it has the same data identifier in itself.
  • the time-stamped data of the data is sent to the device 2 so that the device 2 can perform data synchronization based on the latest data.
  • the device 2 when the device 2 receives the data sent by the device, the device 2 also determines that the data with the highest timestamp of the data having the same data identifier in itself is sent to the device 3, so that the device 3 Data synchronization can also be performed based on the latest data.
  • Step 402 The second terminal device performs data synchronization according to the data added with time stamp and the feedback data.
  • the second terminal device after the second terminal device receives the data added with the timestamp and the data fed back by the other second terminal device, the second terminal device includes all the feedbacks of all the terminal devices in the cluster.
  • the data of the same data identifier if the second terminal device still has other data with the same data identifier, the second terminal device adds the timestamp data and the data fed back by the other second terminal device.
  • the data with the largest timestamp is determined among the other data having the same data identifier, so that the second terminal device performs data synchronization according to the data with the largest timestamp.
  • the other second terminal devices also perform data synchronization according to the above process.
  • the second terminal device performs data synchronization according to the data added with time stamp and the feedback data, specifically:
  • the second terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier
  • the second terminal device performs data synchronization according to data corresponding to the maximum time stamp.
  • the second terminal device can perform data synchronization according to the latest data in itself.
  • the time-stamped data carries the first terminal device to set a life cycle for the data, and when the second terminal device determines data having the same data identifier in the life cycle, When the sum of the numbers is not greater than the threshold, the second terminal device deletes data having the same data identifier.
  • data synchronization must be completed within a certain time during data synchronization, otherwise the meaning of data synchronization is lost. Therefore, when the first terminal device adds a time stamp to the data, the data is also set.
  • the life cycle the length of the life cycle is determined according to actual conditions.
  • the second terminal device does not receive the data with the same data identifier exceeding the threshold in the life cycle, the data synchronization fails. The resource of the second terminal device is guaranteed to be not wasted, so the first terminal device deletes data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the second terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
  • the second terminal device When the synchronization type in the data corresponding to the maximum time stamp is the synchronization data, the second terminal device performs data synchronization according to the data corresponding to the maximum time stamp;
  • the second terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
  • the data of the terminal device in the cluster is unified, and when the second terminal device performs data synchronization, sometimes it is for adding data, and sometimes for deleting data, if the second When the synchronization type of the data corresponding to the maximum timestamp determined by the terminal device is synchronous data, indicating that the data is to be added, the second terminal device performs data synchronization according to the data corresponding to the maximum timestamp; if the second terminal device determines The synchronization type of the data corresponding to the largest timestamp is deleted when the data is deleted, and the second terminal device deletes the data in the data corresponding to the maximum timestamp when synchronizing according to the data corresponding to the maximum timestamp.
  • the second terminal device may only delete the data itself, and retain the time corresponding to the data.
  • Information such as stamps, synchronization types, and data identifications for subsequent queries.
  • the second terminal device After the second terminal device receives the time-stamped data sent by the first terminal device, the second terminal device will be in the same data as the data identifier of the time-stamped data.
  • the data with the largest timestamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
  • the first terminal device when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second
  • the terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device.
  • election data transmission In the case of standby, the data synchronization of the terminal device cluster is realized, the cost of data synchronization is reduced, and the terminal devices in the cluster are synchronized according to the data obtained by themselves, thereby ensuring the reliability in data synchronization.
  • the system includes three servers: server A, server B, server C, and the three servers.
  • the client publishes a data indicated as K, and selects the sending server A. If the data state S and the time stamp T in the data are empty at this time, the server A receives the data, according to the receiving station. The time of the data is added with a timestamp in T, and S is set to SYNC, and the data is sent to the server cluster including itself.
  • the server B receives the data, it searches for the K in the temporary storage area. Other data identified by the data, if the timestamp in the other data is less than the data, the server B ignores the data, and if it is greater, the server B replaces the other data with the data, and The data is sent to the server A and the server C, and the same server C needs to complete the above process.
  • the server B determines that the number of data with the data identifier K in the temporary storage area is 2, and exceeds the threshold value, and the server B selects the data with the largest time stamp of the identification time in the temporary storage area, and the time stamp is The largest data is moved into the data area, and S is set to UPDATED. If there is data identified by K as data in the data area, the data with the highest timestamp is used to cover the data area marked with K as data. data. If the server B determines that the data whose data identifier is K is less than the threshold during the life of the data, the mobile operation is not performed, and all the data identified by the data in the server B is deleted, and the same server C needs to be completed. The above process.
  • the server A moves the data with the largest timestamp to the data area, and Set to UPDATED, if there is data identified by K as data in the data area, the data with the highest timestamp is used to overwrite the data identified by K as data in the data area. If the server A determines that the data with the data identifier K is less than the threshold during the life of the data, the mobile operation is not performed, and the server A is deleted with the K as the data identifier. All the data.
  • the server B and the server C are synchronized and fed back according to the data sent by the server A, when the number of data in which the data identifier K is determined by one of the servers is less than the threshold, the other server uses K as the data identifier. The number of data is also smaller than the threshold. Therefore, when one server deletes data identified by K as data, other servers also delete data identified by K as data. And after deleting the data identified by K as the data, the server A also feeds back the synchronization failure message to the client.
  • the client publishes a data indicated as K, and selects the sending server A. If the data state S in the data is ZOMBIE and the timestamp T is empty, the server A receives the data. Adding a timestamp to T according to the time when the data is received, and then the server A sends the data to the server cluster including itself.
  • the server B receives the data, it searches for a K in the temporary storage area. Other data identified by the data, if the timestamp in the other data is less than the data, the server B ignores the data, and if it is greater, the server B replaces the other data with the data, and The data is sent to server A and server C, and the above process also needs to be completed.
  • the server B determines that the number of data with the data identifier K in the temporary storage area is 2, and exceeds the threshold value, and the server B selects the data with the largest time stamp of the identification time in the temporary storage area, and the time stamp is The largest data is moved to the area to be deleted, and the data value corresponding to S in the data is deleted. If there is data identified by K as data in the area to be deleted, the data with the largest timestamp is used to cover the data to be deleted. Delete the data identified by K as data.
  • the server B determines that the data whose data identifier is K is less than the threshold during the life of the data, the mobile operation is not performed, and all the data identified by the data in the server B is deleted, and the same server C needs to be completed. The above process.
  • the server A moves the data with the largest timestamp to the area to be deleted. If there is data identified by K as the data in the deleted area, the data marked with K as the data in the data area is overwritten with the data with the largest timestamp. If the server A determines that the data whose data identifier is K is less than the threshold during the life of the data, the move operation is not performed, and all data identified by K as data in the server A is deleted.
  • the server A receives a plurality of data identified by the client as data, the server synchronizes the data in the order of receiving the data.
  • the present invention provides a data synchronization device.
  • the data synchronization device is located in the first terminal device and is applied to include the first terminal device and multiple second devices.
  • the data synchronization device includes:
  • An adding module 61 when the first terminal device receives the data, adding a timestamp for receiving the data to the data;
  • a sending module 62 configured to send the data that is added with the timestamp to the second terminal device, and save the data that is added with the timestamp;
  • the receiving module 63 is configured to receive data that is sent by the second terminal device according to the data added with the timestamp, so that the synchronization module in the first terminal device adds the timestamp according to the saved by itself.
  • the data and the feedback data are data synchronized.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
  • the synchronization module is specifically configured to:
  • the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
  • Data synchronization is performed based on the data corresponding to the maximum time stamp.
  • the adding module is further configured to set a life cycle for saving the data to which the time stamp is added;
  • the device also includes:
  • Deleting a module when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the synchronization module is also specifically configured to:
  • the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data
  • the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
  • the first terminal device when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second
  • the terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device. Realizing data synchronization of the terminal device cluster in the case of electing and transmitting data devices, reducing the cost of data synchronization, and in the cluster
  • the terminal device synchronizes according to the data obtained by itself, ensuring the reliability in data synchronization.
  • the present invention further provides a data synchronization device.
  • the data synchronization device is located in a second terminal device, and is applied to include a first terminal device and a plurality of the foregoing.
  • the data synchronization device includes:
  • the receiving module 71 is configured to receive the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data feedback;
  • a synchronization module 72 configured to perform data synchronization according to the time-stamped data and the feedback data
  • the timestamp is determined by the first terminal device according to the time when the data is received.
  • the same data in the first terminal device and the second terminal have the same data identifier
  • the feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
  • the synchronization module is specifically configured to:
  • the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
  • Data synchronization is performed based on the data corresponding to the maximum time stamp.
  • the time-stamped data carries the first terminal device to set a life cycle for the data
  • the device also includes:
  • Deleting a module when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
  • the data having the same data identifier also carries a synchronization type
  • the synchronization module is also specifically configured to:
  • the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data
  • the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
  • the second terminal device further includes:
  • a sending module after receiving the time-stamped data sent by the first terminal device, the receiving module is configured to maximize a timestamp in the same data as the data identifier of the time-stamped data The data Sending to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
  • the first terminal device when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second
  • the terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device.
  • the data synchronization of the terminal device cluster is realized, the cost of data synchronization is reduced, and the terminal devices in the cluster are synchronized according to the data obtained by themselves, thereby ensuring the reliability in data synchronization.
  • the aforementioned program can be stored in a computer readable storage medium.
  • the program when executed, performs the steps including the foregoing method embodiments; and the foregoing storage medium includes various media that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
  • the device embodiments described above are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, ie may be located in one place. Or it can be distributed to at least two network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. Those of ordinary skill in the art can understand and implement without deliberate labor.

Abstract

The present invention provides a data synchronization method and apparatus. The method comprises: when data is received by a first terminal device, the first terminal device adds a timestamp of the received data to the data; the first terminal device sends the data to which the timestamp is added to a second terminal device, and stores the data to which the timestamp is added; the first terminal device receives data fed back by the second terminal device according to the data to which the timestamp is added, so that the first terminal device can synchronize data according to the data to which the timestamp is added stored by the first terminal device and the feedback data. By means of the present invention, data of a terminal device cluster is synchronized without using a third party device and electing a data transmitting device, costs during data synchronization is reduced, and the reliability during data synchronization is ensured because terminal devices in the cluster perform synchronization according to the data obtained by the terminal devices

Description

一种数据的同步方法和装置Data synchronization method and device
本申请要求2016年03月25日递交的申请号为201610179749.6、发明名称为“一种数据的同步方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. Serial No. No. No. No. No. No. No. No. No. No. No. No. No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No
技术领域Technical field
本发明涉及网络技术领域,尤其涉及一种数据的同步方法和装置。The present invention relates to the field of network technologies, and in particular, to a data synchronization method and apparatus.
背景技术Background technique
在现有技术中,为了实现服务器集群中数据的一致性,提出了以下两种解决方案:In the prior art, in order to achieve data consistency in a server cluster, the following two solutions are proposed:
如图1所示的方案一:在服务器集群中增加一个配置中心,当其中一个服务器(发布者)获取到数据并要将所述数据同步到其他服务器(订阅者)中时,所述服务器将所述数据发送到所述配置中心,有所述配置中心向其他服务器发送所述数据,进而使其他服务器根据所述数据进行同步。Solution 1: as shown in Figure 1: Adding a configuration center to the server cluster, when one of the servers (publishers) gets the data and wants to synchronize the data to other servers (subscribers), the server will The data is sent to the configuration center, and the configuration center sends the data to other servers, so that other servers synchronize according to the data.
如图2所示的方案二:所述服务器集群通过选举算法选举出一个发布者Master,其他服务器为订阅者,选择成功后,当需要让所述服务器集群同步一个数据时,由所述Master获取所述数据,再由所述Master向订阅者发送需要同步的数据,以使所述订阅者进行数据同步,在订阅者同步成功后向Master返回同步成功的消息,当所述Master宕机后,所述服务器集群需要重进选举Master。As shown in FIG. 2, the server cluster elects a publisher master through an election algorithm, and the other servers are subscribers. After the selection succeeds, when the server cluster needs to synchronize one data, the master obtains The data is sent by the master to the subscriber to be synchronized, so that the subscriber synchronizes the data, and after the subscriber synchronizes successfully, the synchronization success message is returned to the master. When the master is down, The server cluster needs to re-enter the election master.
在实现本发明的过程中,发明人发现现有技术至少存在如下问题:In the process of implementing the present invention, the inventors have found that the prior art has at least the following problems:
方案一在同步数据时依赖第三方设备,部署麻烦,可靠性不高,而方案二中如果集群中的服务器数量较大时,订阅者返回的同步成功的消息数量也就会越多,进而使得数据同步时的成本大大增加,并且在Master宕机后,重新选举时也会增加数据同步时的成本。 Solution 1 relies on third-party devices when synchronizing data. The deployment is troublesome and the reliability is not high. In scenario 2, if the number of servers in the cluster is large, the number of successful messages returned by the subscribers will also increase. The cost of data synchronization is greatly increased, and after the Master is down, the cost of data synchronization will also increase when re-election.
发明内容Summary of the invention
本发明提供一种数据的同步方法和装置,用于解决现有技术中依赖第三方设备,部署麻烦,可靠性不高的问题。The present invention provides a data synchronization method and apparatus for solving the problem of relying on third-party equipment in the prior art, which is troublesome to deploy and low in reliability.
本发明提供一种数据的同步方法和装置,还用于解决现有技术中数据同步成本较高的问题。 The invention provides a data synchronization method and device, and is also used to solve the problem of high data synchronization cost in the prior art.
本发明提供一种数据的同步方法,所述方法应用于包括第一终端设备和第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述第二终端设备为多个,所述方法包括:The present invention provides a method for synchronizing data, the method being applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device are synchronized, The second terminal device is multiple, and the method includes:
当第一终端设备接收到数据时,所述第一终端设备将接收到所述数据的时间戳添加到所述数据中;When the first terminal device receives the data, the first terminal device adds a timestamp of receiving the data to the data;
所述第一终端设备将添加有所述时间戳的所述数据发送给所述第二终端设备,并保存添加有所述时间戳的所述数据;Transmitting, by the first terminal device, the data that is added with the timestamp to the second terminal device, and saving the data that is added with the timestamp;
所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,以使所述第一终端设备根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步。Receiving, by the second terminal device, the data that is fed back by the second terminal device according to the data added with the timestamp, so that the first terminal device saves the data that is added with the timestamp according to the first time Data synchronization with the feedback data.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
所述第一终端设备根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,具体为:The first terminal device performs data synchronization according to the data that is saved by adding the timestamp and the feedback data, which is specifically:
所述第一终端设备判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining, by the first terminal device, whether a sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,所述第一终端设备确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than the threshold, the first terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier;
所述第一终端设备根据最大时间戳对应的数据进行数据同步。The first terminal device performs data synchronization according to data corresponding to the maximum time stamp.
所述第一终端设备为保存添加有所述时间戳的所述数据设定生命周期,当所述第一终端设备在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,所述第一终端设备删除具有相同所述数据标识的数据。The first terminal device sets a life cycle for saving the data with the timestamp added, and when the first terminal device determines the sum of the numbers of data having the same data identifier in the life cycle When not greater than the threshold, the first terminal device deletes data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述第一终端设备根据最大时间戳对应的数据进行数据同步,具体为:The first terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
当最大时间戳对应的数据中的所述同步类型是同步数据时,所述第一终端设备根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum timestamp is the synchronization data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,所述第一终端删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum timestamp is the synchronous deletion data, the first terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
一种数据同步装置,所述数据同步装置位于第一终端设备,应用于包括所述第一终 端设备和多个第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述数据同步装置包括:A data synchronization device, the data synchronization device is located at a first terminal device, and is applied to include the first terminal In the system of the end device and the plurality of second terminal devices, wherein the times of the first terminal device and the second terminal device are synchronized, the data synchronization device includes:
添加模块,当所述第一终端设备接收到数据时,用于将接收到所述数据的时间戳添加到所述数据中;Adding a module, when the first terminal device receives the data, adding a timestamp for receiving the data to the data;
发送模块,用于将添加有所述时间戳的所述数据发送给所述第二终端设备,并保存添加有所述时间戳的所述数据;a sending module, configured to send the data that is added with the timestamp to the second terminal device, and save the data that is added with the timestamp;
接收模块,用于接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,以使所述第一终端设备中的同步模块根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步。a receiving module, configured to receive data that is fed back by the second terminal device according to the data added with the timestamp, so that the synchronization module in the first terminal device adds the timestamp according to the saved The data and the feedback data are data synchronized.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
所述同步模块具体用于:The synchronization module is specifically configured to:
判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining whether the sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
根据最大时间戳对应的数据进行数据同步。Data synchronization is performed based on the data corresponding to the maximum time stamp.
所述添加模块还用于为保存添加有所述时间戳的所述数据设定生命周期;The adding module is further configured to set a life cycle for saving the data to which the time stamp is added;
所述装置还包括:The device also includes:
删除模块,当所述同步模块在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,用于删除具有相同所述数据标识的数据。Deleting a module, when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述同步模块还具体用于:The synchronization module is also specifically configured to:
当最大时间戳对应的数据中的所述同步类型是同步数据时,根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is synchronous data, data synchronization is performed according to data corresponding to the maximum time stamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
一种数据同步方法,所述方法应用于包括第一终端设备和第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述第二终端设备为多个,所述方法包括: A data synchronization method, the method being applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device are synchronized, the second There are multiple terminal devices, and the method includes:
所述第二终端设备接收所述第一终端设备发送的添加有时间戳的数据和其他第二终端设备发送的根据所述添加有时间戳的数据反馈的数据;The second terminal device receives the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data feedback;
所述第二终端设备根据添加有时间戳的数据和所述反馈的数据进行数据同步;The second terminal device performs data synchronization according to the data added with time stamp and the feedback data;
其中,所述时间戳是所述第一终端设备根据接收到所述数据的时间确定的。The timestamp is determined by the first terminal device according to the time when the data is received.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是其他所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
所述第二终端设备根据添加有时间戳的数据和所述反馈的数据进行数据同步,具体为:The second terminal device performs data synchronization according to the data added with time stamp and the feedback data, specifically:
所述第二终端设备判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining, by the second terminal device, whether a sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,所述第二终端设备确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than the threshold, the second terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier;
所述第二终端设备根据最大时间戳对应的数据进行数据同步。The second terminal device performs data synchronization according to data corresponding to the maximum time stamp.
所述添加有时间戳的数据中携带有所述第一终端设备为所述数据设定生命周期,当所述第二终端设备在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,所述第二终端设备删除具有相同所述数据标识的数据。The time-stamped data carries the first terminal device to set a life cycle for the data, and when the second terminal device determines data having the same data identifier in the life cycle, When the sum of the numbers is not greater than the threshold, the second terminal device deletes data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述第二终端设备根据最大时间戳对应的数据进行数据同步,具体为:The second terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
当最大时间戳对应的数据中的所述同步类型是同步数据时,所述第二终端设备根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is the synchronization data, the second terminal device performs data synchronization according to the data corresponding to the maximum time stamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,所述第二终端删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum timestamp is synchronous deletion data, the second terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
在所述第二终端设备接收到所述第一终端设备发送的添加有时间戳的数据后,所述第二终端设备将与所述添加有时间戳的数据的所述数据标识相同的数据中时间戳最大的数据发送给所述第一终端设备,以使所述第一终端设备根据所述时间戳最大的数据进行数据同步。After the second terminal device receives the time-stamped data sent by the first terminal device, the second terminal device will be in the same data as the data identifier of the time-stamped data. The data with the largest timestamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
一种数据同步装置,所述数据同步装置位于第二终端设备,应用于包括第一终端设备和多个所述第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述数据同步装置包括: A data synchronization device, the data synchronization device being located in a second terminal device, applied to a system including a first terminal device and a plurality of the second terminal devices, wherein the first terminal device and the second device The time of the terminal device is synchronized, and the data synchronization device includes:
接收模块,用于接收所述第一终端设备发送的添加有时间戳的数据和其他第二终端设备发送的根据所述添加有时间戳的数据反馈的数据;a receiving module, configured to receive the time-stamped data sent by the first terminal device and the data sent by the second terminal device according to the added time-stamped data feedback;
同步模块,用于根据添加有时间戳的数据和所述反馈的数据进行数据同步;a synchronization module, configured to perform data synchronization according to the time-stamped data and the feedback data;
其中,所述时间戳是所述第一终端设备根据接收到所述数据的时间确定的。The timestamp is determined by the first terminal device according to the time when the data is received.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是其他所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
所述同步模块具体用于:The synchronization module is specifically configured to:
判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining whether the sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
根据最大时间戳对应的数据进行数据同步。Data synchronization is performed based on the data corresponding to the maximum time stamp.
所述添加有时间戳的数据中携带有所述第一终端设备为所述数据设定生命周期;The time-stamped data carries the first terminal device to set a life cycle for the data;
所述装置还包括:The device also includes:
删除模块,当所述同步模块在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,用于删除具有相同所述数据标识的数据。Deleting a module, when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述同步模块还具体用于:The synchronization module is also specifically configured to:
当最大时间戳对应的数据中的所述同步类型是同步数据时,根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is synchronous data, data synchronization is performed according to data corresponding to the maximum time stamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
所述装置还包括:The device also includes:
发送模块,在所述接收模块接收到所述第一终端设备发送的添加有时间戳的数据后,用于将与所述添加有时间戳的数据的所述数据标识相同的数据中时间戳最大的数据发送给所述第一终端设备,以使所述第一终端设备根据所述时间戳最大的数据进行数据同步。a sending module, after receiving the time-stamped data sent by the first terminal device, the receiving module is configured to maximize a timestamp in the same data as the data identifier of the time-stamped data The data is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
本发明中当第一终端设备接收到数据时,在所述数据中添加时间戳并保存,然后将添加有时间戳的数据发送给第二终端设备,所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,并根据自身保存的添加有所述时间戳的所 述数据和所述反馈的数据进行数据同步,本发明在不借助第三方设备和选举发送数据设备的情况下实现了终端设备集群的数据同步,降低了数据同步时的成本,并且集群中的终端设备是根据自身得到的数据来进行同步,保证了数据同步时的可靠性。In the present invention, when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second The terminal device is based on the data fed back by the data added with the time stamp, and according to the method that is saved by itself and added with the time stamp The data and the feedback data are data synchronized, and the invention realizes data synchronization of the terminal device cluster without using the third party device and the election sending data device, reduces the cost in data synchronization, and the terminal in the cluster The device synchronizes according to the data obtained by itself, ensuring the reliability of data synchronization.
附图说明DRAWINGS
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description of the drawings used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description It is a certain embodiment of the present invention, and other drawings can be obtained from those skilled in the art without any inventive labor.
图1为现有技术中的一种依靠第三方设备进行数据同步的流程示意图;1 is a schematic flowchart of data synchronization by using a third-party device in the prior art;
图2为现有技术中的一种通过选举发布者进行数据同步的流程示意图;2 is a schematic flow chart of data synchronization by an election publisher in the prior art;
图3为本发明实施例中的一种数据的同步方法流程图之一;3 is a flowchart of a method for synchronizing data according to an embodiment of the present invention;
图4为本发明实施例中的一种数据的同步方法流程图之二;4 is a second flowchart of a method for synchronizing data according to an embodiment of the present invention;
图5为本发明实施例中的一种数据发布时的同步方法流程示意图;FIG. 5 is a schematic flowchart of a synchronization method during data distribution according to an embodiment of the present invention; FIG.
图6为本发明实施例中的一种数据同步装置结构示意图之一;6 is a schematic structural diagram of a data synchronization apparatus according to an embodiment of the present invention;
图7为本发明实施例中的一种数据同步装置结构示意图之二。FIG. 7 is a second schematic structural diagram of a data synchronization apparatus according to an embodiment of the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings in the embodiments of the present invention. It is a partial embodiment of the invention, and not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.
在现有技术中,由于依靠第三方设备来实现同步数据的方案存在部署麻烦,可靠性不高的缺陷,依靠选举数据发布者的方案存在增加数据同步成本的缺陷,因此本申请提出了一种数据的同步方法,具体如图3所示,所述方法应用于包括第一终端设备和第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述第二终端设备为多个,所述方法包括以下步骤:In the prior art, since the scheme for implementing synchronous data by relying on a third-party device has the drawbacks of troublesome deployment and low reliability, and relying on the scheme of the election data publisher has the defect of increasing the data synchronization cost, the present application proposes a a method for synchronizing data, as shown in FIG. 3, the method is applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device is synchronized The second terminal device is multiple, and the method includes the following steps:
步骤301,当第一终端设备接收到数据时,所述第一终端设备将接收到所述数据的时间戳添加到所述数据中。 Step 301: When the first terminal device receives the data, the first terminal device adds a timestamp of receiving the data to the data.
具体的,所述第一终端设备和所述第二终端的时间是同步的是为了实现集群中的终端设备时间上的统一性,保证在第一终端设备为数据添加时间戳时具有相同的时间基础,进而保证了在集群中的终端设备能够正确的确定出相同的且时间戳最大的数据。其中,所述第一终端设备为接收数据的设备,所述第一终端设备应不是集群中的一个固定设备,是根据集群中接收数据的设备确定的,所述数据是集群之外的设备发送的。例如:集群中有3个终端设备,分别为设备1、设备2和设备3,当设备1接收到客户端发送的数据时,此时设备1为第一终端设备,如果是设备2接收到客户端发送的数据时,此时设备2为第一终端设备。同理,第二终端设备是集群中除第一终端设备之外的其他终端设备,所述第二终端设备是集群中接收所述第一终端设备发送的数据的设备,例如:集群中有3个终端设备,分别为设备1、设备2和设备3,当设备1为第一终端设备时,设备2和设备3为第二终端设备,当设备2为第一终端设备时,设备1和设备3为第二终端设备。Specifically, the time of the first terminal device and the second terminal are synchronized in order to achieve time uniformity of the terminal devices in the cluster, and ensure that the first terminal device has the same time when adding timestamps for data. The foundation, in turn, ensures that the terminal devices in the cluster can correctly determine the same and the highest timestamp data. The first terminal device is a device that receives data, and the first terminal device is not a fixed device in the cluster, and is determined according to a device that receives data in the cluster, where the data is sent by a device other than the cluster. of. For example, there are three terminal devices in the cluster, namely device 1, device 2, and device 3. When device 1 receives the data sent by the client, device 1 is the first terminal device, and if device 2 receives the client. When the data is sent, the device 2 is the first terminal device. Similarly, the second terminal device is a terminal device other than the first terminal device in the cluster, and the second terminal device is a device in the cluster that receives data sent by the first terminal device, for example, there are 3 in the cluster. The terminal devices are device 1, device 2 and device 3. When device 1 is the first terminal device, device 2 and device 3 are the second terminal device. When device 2 is the first terminal device, device 1 and device are 3 is the second terminal device.
步骤302,所述第一终端设备将添加有所述时间戳的所述数据发送给所述第二终端设备,并保存添加有所述时间戳的所述数据。Step 302: The first terminal device sends the data with the timestamp added to the second terminal device, and saves the data with the timestamp added.
具体的,所述第一终端设备保存添加有所述时间戳的所述数据是为了在后续进行数据同步。Specifically, the first terminal device saves the data added with the timestamp for subsequent data synchronization.
步骤303,所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,以使所述第一终端设备根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步。Step 303: The first terminal device receives data that is fed back by the second terminal device according to the data that is added with the timestamp, so that the first terminal device adds the timestamp according to its own saved The data and the feedback data are data synchronized.
其中,所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
具体的,在集群中的终端设备接收到的集群之外的设备发送的数据中携带有数据标识,并且集群之外的设备发送的同一数据的数据标识是相同的,其中,同一数据可能在不同时间发送,集群是根据接收到的数据进行同步的,因此集群中的设备中可能存在与当前接收到的数据的数据标识相同的数据,所述存在数据标识相同的数据中同样存在集群中的设备接收到所述数据的时间戳。Specifically, the data sent by the device outside the cluster received by the terminal device in the cluster carries the data identifier, and the data identifier of the same data sent by the device outside the cluster is the same, where the same data may be different. Time is sent, the cluster is synchronized according to the received data, so the devices in the cluster may have the same data as the data identifier of the currently received data, and the devices in the cluster also exist in the same data identifier. The timestamp of receiving the data.
所述第二终端设备中可能存在与所述数据相同的数据标识,因此在所述第二终端设备接收到添加有所述时间戳的所述数据时,所述第二终端设备需要根据添加所述时间戳的所述数据的数据标识确定出所述第二终端中存在相同数据标识的数据,然后,所述第 二终端设备根据具有相同数据标识的数据确定出时间戳最大的数据,此时确定出的数据为集群最新接收到的数据,需要以此为数据同步的依据,并将确定出的时间戳最大的数据作为反馈数据反馈给所述第一终端设备,在所述第一终端设备接收到集群中的第二终端设备反馈的时间戳最大的数据后,所述第一终端设备就可以根据反馈的数据和自身保存的添加有所述时间戳的所述数据确定出最新的数据,以使所述第一终端设备根据所述最新的数据进行数据同步。The second terminal device may have the same data identifier as the data. Therefore, when the second terminal device receives the data added with the timestamp, the second terminal device needs to be added according to the adding device. Determining, by the time stamp, the data identifier of the data that the data of the same data identifier exists in the second terminal, and then The second terminal device determines the data with the largest timestamp according to the data with the same data identifier. The data determined at this time is the latest data received by the cluster, and needs to be used as the basis for data synchronization, and the determined timestamp is the largest. The data is fed back to the first terminal device as the feedback data. After the first terminal device receives the data with the highest timestamp fed back by the second terminal device in the cluster, the first terminal device can use the feedback data. And the data saved by itself and added with the time stamp determines the latest data, so that the first terminal device performs data synchronization according to the latest data.
所述第一终端设备根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,具体为:The first terminal device performs data synchronization according to the data that is saved by adding the timestamp and the feedback data, which is specifically:
所述第一终端设备判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining, by the first terminal device, whether a sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,所述第一终端设备确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than the threshold, the first terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier;
所述第一终端设备根据最大时间戳对应的数据进行数据同步。The first terminal device performs data synchronization according to data corresponding to the maximum time stamp.
具体的,所述阈值根据实际情况确定,例如:所述阈值为集群中的终端设备数目的一半,当所述第一终端设备确定出的具有相同所述数据标识的数据的数目表示集群中就有多少个终端设备接收到了所述数据,当所述数目超过阈值时表示集群达到了数据同步的要求,此时所述第一终端设备就可以根据自身中的最新的所述数据进行数据同步。Specifically, the threshold is determined according to an actual situation, for example, the threshold is half of the number of terminal devices in the cluster, and the number of data having the same data identifier determined by the first terminal device indicates that the cluster is in the cluster. How many terminal devices have received the data, and when the number exceeds the threshold, it indicates that the cluster has reached the requirement of data synchronization, and at this time, the first terminal device can perform data synchronization according to the latest data in itself.
所述第一终端设备为保存添加有所述时间戳的所述数据设定生命周期,当所述第一终端设备在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,所述第一终端设备删除具有相同所述数据标识的数据。The first terminal device sets a life cycle for saving the data with the timestamp added, and when the first terminal device determines the sum of the numbers of data having the same data identifier in the life cycle When not greater than the threshold, the first terminal device deletes data having the same data identifier.
具体的,数据同步时必须在一定时间内完成数据同步,否则就失去了数据同步的意义,因此,在所述第一终端设备在为所述数据添加时间戳时还要为所述数据设定生命周期,所述生命周期的长短根据实际情况确定,当所述第一终端设备在所述生命周期内没有收到超过所述阈值的具有相同数据标识的数据时表示此次数据同步失败,为了保证所述第一终端设备的资源不被浪费,因此所述第一终端设备删除具有相同所述数据标识的数据。Specifically, data synchronization must be completed within a certain time during data synchronization, otherwise the meaning of data synchronization is lost. Therefore, when the first terminal device adds a time stamp to the data, the data is also set. The life cycle, the length of the life cycle is determined according to actual conditions. When the first terminal device does not receive the data with the same data identifier exceeding the threshold in the life cycle, the data synchronization fails. Assuring that the resources of the first terminal device are not wasted, so the first terminal device deletes data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述第一终端设备根据最大时间戳对应的数据进行数据同步,具体为:The first terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
当最大时间戳对应的数据中的所述同步类型是同步数据时,所述第一终端设备根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum timestamp is the synchronization data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,所述第一终端删除 最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the first terminal deletes The data value in the data corresponding to the maximum time stamp, and the data synchronization is performed according to the data corresponding to the maximum time stamp in which the data value is deleted.
具体的,在数据同步时是为了让集群中的终端设备的数据统一,而所述第一终端设备接收到的数据进行同步时,有时是为了增加数据,而有时是为了删除数据,如果所述第一终端设备确定出的最大时间戳对应的数据的同步类型是同步数据时,表示是为了增加数据,所述第一终端设备根据最大时间戳对应的数据进行数据同步;如果所述第一终端设备确定出的最大时间戳对应的数据的同步类型是删除数据时,表示是为了撤销所述数据,所述第一终端设备根据最大时间戳对应的数据进行同步时删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步,其中在删除所述数据时,所述第一终端设备可以只删除所述数据本身,保留所述数据对应的时间戳、同步类型和数据标识等信息,以供后续查询。Specifically, in data synchronization, in order to unify the data of the terminal devices in the cluster, when the data received by the first terminal device is synchronized, sometimes to increase data, and sometimes to delete data, if When the synchronization type of the data corresponding to the maximum timestamp determined by the first terminal device is synchronous data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp; if the first terminal When the synchronization type of the data corresponding to the maximum timestamp determined by the device is to delete the data, the first terminal device deletes the data corresponding to the maximum timestamp according to the data corresponding to the maximum timestamp. a data value, and performing data synchronization according to the data corresponding to the maximum timestamp of the data value, wherein the first terminal device may delete only the data itself when the data is deleted, and retain the data corresponding to Information such as timestamp, synchronization type, and data identification for subsequent queries.
当所述第一终端设备中接收集群之外的设备发送的至少一个具有相同的数据标识的数据时。所述第一终端设备根据接收数据的先后顺序进行数据同步。And receiving, by the first terminal device, at least one data with the same data identifier sent by a device other than the cluster. The first terminal device performs data synchronization according to a sequence of receiving data.
本发明中当第一终端设备接收到数据时,在所述数据中添加时间戳并保存,然后将添加有时间戳的数据发送给第二终端设备,所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,并根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,本发明在不借助第三方设备和选举发送数据设备的情况下实现了终端设备集群的数据同步,降低了数据同步时的成本,并且集群中的终端设备是根据自身得到的数据来进行同步,保证了数据同步时的可靠性。In the present invention, when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second The terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device. In the case of the election of the data device, the data synchronization of the terminal device cluster is realized, the cost of data synchronization is reduced, and the terminal devices in the cluster are synchronized according to the data obtained by themselves, thereby ensuring the reliability in data synchronization.
本发明还提供了一种数据的同步方法,具体如图4所示,所述方法应用于包括第一终端设备和第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述第二终端设备为多个,所述方法包括以下步骤:The present invention also provides a data synchronization method, as shown in FIG. 4, the method is applied to a system including a first terminal device and a second terminal device, wherein the first terminal device and the first The time of the two terminal devices is synchronized, and the second terminal device is multiple. The method includes the following steps:
步骤401,所述第二终端设备接收所述第一终端设备发送的添加有时间戳的数据和其他第二终端设备发送的根据所述添加有时间戳的数据反馈的数据。Step 401: The second terminal device receives the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data.
其中,所述时间戳是所述第一终端设备根据接收到所述数据的时间确定的。The timestamp is determined by the first terminal device according to the time when the data is received.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是其他所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
例如:终端设备集群中包括:设备1、设备2和设备3,其中所述设备1为第一终端设备,设备2和设备3为第二终端设备,在所述设备1接收到数据时,所述设备1在 将添加有时间戳的数据发送给所述设备2时还发送给了设备3,此时,所述设备2为所述第二终端设备,所述设备3为其他所述第二终端设备,由于设备3中可能存在具有相同数据标识的所述数据,为了保证设备2在进行数据同步时以使最新的数据进行更新的,所述设备3还要将确定出其自身中具有相同所述数据标识的数据的时间戳最大的数据发送给所述设备2,以使所述设备2可以根据最新的数据进行数据同步。同理,在所述设备2接收到设备发送的数据时,所述设备2也要确定出自身中具有相同数据标识的数据的时间戳最大的数据发送给所述设备3,以使所述设备3也可以根据最新的数据进行数据同步。For example, the terminal device cluster includes: device 1, device 2, and device 3, wherein the device 1 is a first terminal device, and device 2 and device 3 are second terminal devices. When the device 1 receives data, the device Device 1 is When the time-stamped data is sent to the device 2, the device 3 is also sent to the device 3, and the device 2 is the second terminal device, and the device 3 is the other second terminal device. The data may have the same data identifier in the device 3, and in order to ensure that the device 2 updates the latest data when performing data synchronization, the device 3 will also determine that it has the same data identifier in itself. The time-stamped data of the data is sent to the device 2 so that the device 2 can perform data synchronization based on the latest data. Similarly, when the device 2 receives the data sent by the device, the device 2 also determines that the data with the highest timestamp of the data having the same data identifier in itself is sent to the device 3, so that the device 3 Data synchronization can also be performed based on the latest data.
步骤402,所述第二终端设备根据添加有时间戳的数据和所述反馈的数据进行数据同步。Step 402: The second terminal device performs data synchronization according to the data added with time stamp and the feedback data.
具体的,在所述第二终端设备在接收到添加有时间戳的数据和其他第二终端设备反馈的数据后,此时所述第二终端设备中包含了集群中其他所有终端设备反馈的具有所述相同数据标识的数据,此时如果所述第二终端设备中还存在其他具有相同数据标识的数据,所述第二终端设备在添加有时间戳的数据、其他第二终端设备反馈的数据和所述其他具有相同数据标识的数据中确定出时间戳最大的数据,以使所述第二终端设备根据所述时间戳最大的数据进行数据同步。同理,其他所述第二终端设备也根据上述过程进行数据同步。Specifically, after the second terminal device receives the data added with the timestamp and the data fed back by the other second terminal device, the second terminal device includes all the feedbacks of all the terminal devices in the cluster. The data of the same data identifier, if the second terminal device still has other data with the same data identifier, the second terminal device adds the timestamp data and the data fed back by the other second terminal device. The data with the largest timestamp is determined among the other data having the same data identifier, so that the second terminal device performs data synchronization according to the data with the largest timestamp. Similarly, the other second terminal devices also perform data synchronization according to the above process.
所述第二终端设备根据添加有时间戳的数据和所述反馈的数据进行数据同步,具体为:The second terminal device performs data synchronization according to the data added with time stamp and the feedback data, specifically:
所述第二终端设备判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining, by the second terminal device, whether a sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,所述第二终端设备确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than the threshold, the second terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier;
所述第二终端设备根据最大时间戳对应的数据进行数据同步。The second terminal device performs data synchronization according to data corresponding to the maximum time stamp.
具体的,当所述第二终端设备确定出的具有相同所述数据标识的数据的数目表示集群中就有多少个终端设备接收到了所述数据,当所述数目超过阈值时表示集群达到了数据同步的要求,此时所述第二终端设备就可以根据自身中的最新的所述数据进行数据同步。Specifically, when the number of data having the same data identifier determined by the second terminal device indicates how many terminal devices in the cluster receive the data, when the number exceeds a threshold, the cluster reaches the data. The synchronization requirement, at this time, the second terminal device can perform data synchronization according to the latest data in itself.
所述添加有时间戳的数据中携带有所述第一终端设备为所述数据设定生命周期,当所述第二终端设备在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,所述第二终端设备删除具有相同所述数据标识的数据。 The time-stamped data carries the first terminal device to set a life cycle for the data, and when the second terminal device determines data having the same data identifier in the life cycle, When the sum of the numbers is not greater than the threshold, the second terminal device deletes data having the same data identifier.
具体的,数据同步时必须在一定时间内完成数据同步,否则就失去了数据同步的意义,因此,在所述第一终端设备在为所述数据添加时间戳时还要为所述数据设定生命周期,所述生命周期的长短根据实际情况确定,当所述第二终端设备在所述生命周期内没有收到超过所述阈值的具有相同数据标识的数据时表示此次数据同步失败,为了保证所述第二终端设备的资源不被浪费,因此所述第一终端设备删除具有相同所述数据标识的数据。Specifically, data synchronization must be completed within a certain time during data synchronization, otherwise the meaning of data synchronization is lost. Therefore, when the first terminal device adds a time stamp to the data, the data is also set. The life cycle, the length of the life cycle is determined according to actual conditions. When the second terminal device does not receive the data with the same data identifier exceeding the threshold in the life cycle, the data synchronization fails. The resource of the second terminal device is guaranteed to be not wasted, so the first terminal device deletes data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述第二终端设备根据最大时间戳对应的数据进行数据同步,具体为:The second terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
当最大时间戳对应的数据中的所述同步类型是同步数据时,所述第二终端设备根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is the synchronization data, the second terminal device performs data synchronization according to the data corresponding to the maximum time stamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,所述第二终端删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum timestamp is synchronous deletion data, the second terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
具体的,在数据同步时是为了让集群中的终端设备的数据统一,而所述第二终端设备在进行数据同步时,有时是为了增加数据,而有时是为了删除数据,如果所述第二终端设备确定出的最大时间戳对应的数据的同步类型是同步数据时,表示是为了增加数据,所述第二终端设备根据最大时间戳对应的数据进行数据同步;如果所述第二终端设备确定出的最大时间戳对应的数据的同步类型是删除数据时,表示是为了撤销所述数据,所述第二终端设备根据最大时间戳对应的数据进行同步时删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步,,其中在删除所述数据时,所述第二终端设备可以只删除所述数据本身,保留所述数据对应的时间戳、同步类型和数据标识等信息,以供后续查询。Specifically, in the data synchronization, the data of the terminal device in the cluster is unified, and when the second terminal device performs data synchronization, sometimes it is for adding data, and sometimes for deleting data, if the second When the synchronization type of the data corresponding to the maximum timestamp determined by the terminal device is synchronous data, indicating that the data is to be added, the second terminal device performs data synchronization according to the data corresponding to the maximum timestamp; if the second terminal device determines The synchronization type of the data corresponding to the largest timestamp is deleted when the data is deleted, and the second terminal device deletes the data in the data corresponding to the maximum timestamp when synchronizing according to the data corresponding to the maximum timestamp. And performing data synchronization according to the data corresponding to the maximum timestamp of the data value, wherein when the data is deleted, the second terminal device may only delete the data itself, and retain the time corresponding to the data. Information such as stamps, synchronization types, and data identifications for subsequent queries.
在所述第二终端设备接收到所述第一终端设备发送的添加有时间戳的数据后,所述第二终端设备将与所述添加有时间戳的数据的所述数据标识相同的数据中时间戳最大的数据发送给所述第一终端设备,以使所述第一终端设备根据所述时间戳最大的数据进行数据同步。After the second terminal device receives the time-stamped data sent by the first terminal device, the second terminal device will be in the same data as the data identifier of the time-stamped data. The data with the largest timestamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
本发明中当第一终端设备接收到数据时,在所述数据中添加时间戳并保存,然后将添加有时间戳的数据发送给第二终端设备,所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,并根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,本发明在不借助第三方设备和选举发送数据设 备的情况下实现了终端设备集群的数据同步,降低了数据同步时的成本,并且集群中的终端设备是根据自身得到的数据来进行同步,保证了数据同步时的可靠性。In the present invention, when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second The terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device. And election data transmission In the case of standby, the data synchronization of the terminal device cluster is realized, the cost of data synchronization is reduced, and the terminal devices in the cluster are synchronized according to the data obtained by themselves, thereby ensuring the reliability in data synchronization.
为了进一步阐述本发明的技术思想,现结合具体的应用场景,对本申请的技术方案进行说明,具体的,系统中包括3台服务器:服务器A、服务器B、服务器C,且所述3台服务器的时间是同步的,其中生成同步数据的终端为客户端,并且定义所述同步数据的结构:D={K,V,S,T},K表示数据标识,V表示数据值,S表示数据的状态(数据状态有:SYNC表示正在同步,UPDATED表示同步完成,ZOMBIE表示删除数据值三种状态,T表示服务器接收所述数据的时间戳,时间戳以毫秒为单位,并且,每台服务器的存储分为三部分:暂存区:用于存放同步数据,此时的同步数据的状态为SYNC,生命周期为I;数据区:里面存在已经生效的数据,此时的数据状态为UPDATED,可以被客户端读取使用;待删区:用于存放删除通知,此时数据的状态为ZOMBIE,生命周期为I,规定阈值为1.5。具体过程如图5所示。In order to further illustrate the technical idea of the present invention, the technical solution of the present application will be described in conjunction with a specific application scenario. Specifically, the system includes three servers: server A, server B, server C, and the three servers. The time is synchronized, wherein the terminal generating the synchronization data is a client, and the structure of the synchronization data is defined: D={K, V, S, T}, K represents a data identifier, V represents a data value, and S represents data. Status (data status: SYNC means that synchronization is in progress, UPDATED means synchronization is completed, ZOMBIE means to delete data values in three states, T means timestamp of the server receiving the data, timestamp in milliseconds, and storage per server It is divided into three parts: temporary storage area: used to store synchronous data. At this time, the status of the synchronous data is SYNC, and the life cycle is I; the data area: there is already valid data, and the data status at this time is UPDATED, which can be The client reads and uses; the area to be deleted is used to store the deletion notification. At this time, the status of the data is ZOMBIE, the life cycle is I, and the specified threshold is 1.5. Figure 5 shows.
客户端发布了一个表示为K的数据,并选择发送服务器A中,如果此时所述数据中数据状态S和时间戳T为空,所述服务器A在接收到所述数据后,根据接收所述数据的时间在T中添加时间戳,并将S设置为SYNC,并向包括自己在内服务器集群发送所述数据,当服务器B收到所述数据后,在暂存区中查找以K为数据标识的其他数据,如果所述其他数据中的时间戳小于所述数据,那么所述服务器B忽略所述数据,如果大于,所述服务器B用所述数据替换掉所述其他数据,并将所述数据发送给服务器A和服务器C,同理服务器C同样需要完成上述过程。此时服务器B确定暂存区中数据标识为K的数据的个数为2,超过阈值,所述服务器B选取出暂存区中以K为标识时间戳最大的数据,并将所述时间戳最大的数据移动到数据区中,并将S设置为UPDATED,如果数据区中存在以K为数据标识的数据,则用所述时间戳最大的数据覆盖所述数据区中以K为数据标识的数据。如果在所述数据的生命周期内服务器B确定数据标识为K的数据小于所述阈值,则不执行移动操作,并删除服务器B中以K为数据标识的所有数据,同理服务器C同样需要完成上述过程。The client publishes a data indicated as K, and selects the sending server A. If the data state S and the time stamp T in the data are empty at this time, the server A receives the data, according to the receiving station. The time of the data is added with a timestamp in T, and S is set to SYNC, and the data is sent to the server cluster including itself. When the server B receives the data, it searches for the K in the temporary storage area. Other data identified by the data, if the timestamp in the other data is less than the data, the server B ignores the data, and if it is greater, the server B replaces the other data with the data, and The data is sent to the server A and the server C, and the same server C needs to complete the above process. At this time, the server B determines that the number of data with the data identifier K in the temporary storage area is 2, and exceeds the threshold value, and the server B selects the data with the largest time stamp of the identification time in the temporary storage area, and the time stamp is The largest data is moved into the data area, and S is set to UPDATED. If there is data identified by K as data in the data area, the data with the highest timestamp is used to cover the data area marked with K as data. data. If the server B determines that the data whose data identifier is K is less than the threshold during the life of the data, the mobile operation is not performed, and all the data identified by the data in the server B is deleted, and the same server C needs to be completed. The above process.
在完成上述过程后,服务器A中存在至少3条以K为数据标识的数据,所述服务器A确定出时间戳最大的数据后,将所述时间戳最大的数据移动到数据区,并将S设置为UPDATED,如果数据区中存在以K为数据标识的数据,则用所述时间戳最大的数据覆盖所述数据区中以K为数据标识的数据。如果在所述数据的生命周期内服务器A确定数据标识为K的数据小于所述阈值,则不执行移动操作,并删除服务器A中以K为数据标识 的所有数据。After the above process is completed, there are at least three pieces of data identified by K as data in the server A. After determining the data with the largest timestamp, the server A moves the data with the largest timestamp to the data area, and Set to UPDATED, if there is data identified by K as data in the data area, the data with the highest timestamp is used to overwrite the data identified by K as data in the data area. If the server A determines that the data with the data identifier K is less than the threshold during the life of the data, the mobile operation is not performed, and the server A is deleted with the K as the data identifier. All the data.
由于服务器B和服务器C是根据服务器A发送的数据进行同步和反馈的,因此当其中一个服务器中确定出数据标识为K的数据的个数小于所述阈值时,其他服务器中以K为数据标识的数据的个数也小于所述阈值,因此,当一个服务器删除以K为数据标识的数据时,其他服务器也在删除以K为数据标识的数据。并且服务器A在删除以K为数据标识的数据后,还要向客户端反馈同步失败的消息。Since the server B and the server C are synchronized and fed back according to the data sent by the server A, when the number of data in which the data identifier K is determined by one of the servers is less than the threshold, the other server uses K as the data identifier. The number of data is also smaller than the threshold. Therefore, when one server deletes data identified by K as data, other servers also delete data identified by K as data. And after deleting the data identified by K as the data, the server A also feeds back the synchronization failure message to the client.
客户端发布了一个表示为K的数据,并选择发送服务器A中,如果此时所述数据中数据状态S为ZOMBIE,时间戳T为空时,所述服务器A在接收到所述数据后,根据接收所述数据的时间在T中添加时间戳,然后所述服务器A向包括自己在内服务器集群发送所述数据,当服务器B收到所述数据后,在暂存区中查找以K为数据标识的其他数据,如果所述其他数据中的时间戳小于所述数据,那么所述服务器B忽略所述数据,如果大于,所述服务器B用所述数据替换掉所述其他数据,并将所述数据发送给服务器A和服务器C,同样需要完成上述过程。此时服务器B确定暂存区中数据标识为K的数据的个数为2,超过阈值,所述服务器B选取出暂存区中以K为标识时间戳最大的数据,并将所述时间戳最大的数据移动到待删区中,并将所述数据中S对应的数据值删除,如果待删区中存在以K为数据标识的数据,则用所述时间戳最大的数据覆盖所述待删区中以K为数据标识的数据。如果在所述数据的生命周期内服务器B确定数据标识为K的数据小于所述阈值,则不执行移动操作,并删除服务器B中以K为数据标识的所有数据,同理服务器C同样需要完成上述过程。The client publishes a data indicated as K, and selects the sending server A. If the data state S in the data is ZOMBIE and the timestamp T is empty, the server A receives the data. Adding a timestamp to T according to the time when the data is received, and then the server A sends the data to the server cluster including itself. When the server B receives the data, it searches for a K in the temporary storage area. Other data identified by the data, if the timestamp in the other data is less than the data, the server B ignores the data, and if it is greater, the server B replaces the other data with the data, and The data is sent to server A and server C, and the above process also needs to be completed. At this time, the server B determines that the number of data with the data identifier K in the temporary storage area is 2, and exceeds the threshold value, and the server B selects the data with the largest time stamp of the identification time in the temporary storage area, and the time stamp is The largest data is moved to the area to be deleted, and the data value corresponding to S in the data is deleted. If there is data identified by K as data in the area to be deleted, the data with the largest timestamp is used to cover the data to be deleted. Delete the data identified by K as data. If the server B determines that the data whose data identifier is K is less than the threshold during the life of the data, the mobile operation is not performed, and all the data identified by the data in the server B is deleted, and the same server C needs to be completed. The above process.
在完成上述过程后,服务器A中存在至少3条以K为数据标识的数据,所述服务器A确定出时间戳最大的数据后,将所述时间戳最大的数据移动到待删区,如果待删区中存在以K为数据标识的数据,则用所述时间戳最大的数据覆盖所述数据区中以K为数据标识的数据。如果在所述数据的生命周期内服务器A确定数据标识为K的数据小于所述阈值,则不执行移动操作,并删除服务器A中以K为数据标识的所有数据。After the above process is completed, there are at least three pieces of data identified by K as data in the server A. After determining the data with the largest timestamp, the server A moves the data with the largest timestamp to the area to be deleted. If there is data identified by K as the data in the deleted area, the data marked with K as the data in the data area is overwritten with the data with the largest timestamp. If the server A determines that the data whose data identifier is K is less than the threshold during the life of the data, the move operation is not performed, and all data identified by K as data in the server A is deleted.
如果服务器A接收到客户端发送的多条以K为数据标识的数据时,所述服务器按照接收数据的顺序同步数据。If the server A receives a plurality of data identified by the client as data, the server synchronizes the data in the order of receiving the data.
基于与上述方法同样的申请构思,本发明提出了一种数据同步装置,如图6所示,所述数据同步装置位于第一终端设备,应用于包括所述第一终端设备和多个第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述数据同步装置包括: Based on the same application concept as the above method, the present invention provides a data synchronization device. As shown in FIG. 6, the data synchronization device is located in the first terminal device and is applied to include the first terminal device and multiple second devices. In the system of the terminal device, wherein the times of the first terminal device and the second terminal device are synchronized, the data synchronization device includes:
添加模块61,当所述第一终端设备接收到数据时,用于将接收到所述数据的时间戳添加到所述数据中;An adding module 61, when the first terminal device receives the data, adding a timestamp for receiving the data to the data;
发送模块62,用于将添加有所述时间戳的所述数据发送给所述第二终端设备,并保存添加有所述时间戳的所述数据;a sending module 62, configured to send the data that is added with the timestamp to the second terminal device, and save the data that is added with the timestamp;
接收模块63,用于接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,以使所述第一终端设备中的同步模块根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步。The receiving module 63 is configured to receive data that is sent by the second terminal device according to the data added with the timestamp, so that the synchronization module in the first terminal device adds the timestamp according to the saved by itself. The data and the feedback data are data synchronized.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
所述同步模块具体用于:The synchronization module is specifically configured to:
判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining whether the sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
根据最大时间戳对应的数据进行数据同步。Data synchronization is performed based on the data corresponding to the maximum time stamp.
所述添加模块还用于为保存添加有所述时间戳的所述数据设定生命周期;The adding module is further configured to set a life cycle for saving the data to which the time stamp is added;
所述装置还包括:The device also includes:
删除模块,当所述同步模块在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,用于删除具有相同所述数据标识的数据。Deleting a module, when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述同步模块还具体用于:The synchronization module is also specifically configured to:
当最大时间戳对应的数据中的所述同步类型是同步数据时,根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is synchronous data, data synchronization is performed according to data corresponding to the maximum time stamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
本发明中当第一终端设备接收到数据时,在所述数据中添加时间戳并保存,然后将添加有时间戳的数据发送给第二终端设备,所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,并根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,本发明在不借助第三方设备和选举发送数据设备的情况下实现了终端设备集群的数据同步,降低了数据同步时的成本,并且集群中的 终端设备是根据自身得到的数据来进行同步,保证了数据同步时的可靠性。In the present invention, when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second The terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device. Realizing data synchronization of the terminal device cluster in the case of electing and transmitting data devices, reducing the cost of data synchronization, and in the cluster The terminal device synchronizes according to the data obtained by itself, ensuring the reliability in data synchronization.
基于与上述方法同样的申请构思,本发明还提出了一种数据同步装置,具体如图7所示,所述数据同步装置位于第二终端设备,应用于包括第一终端设备和多个所述第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述数据同步装置包括:Based on the same application concept as the above method, the present invention further provides a data synchronization device. Specifically, as shown in FIG. 7, the data synchronization device is located in a second terminal device, and is applied to include a first terminal device and a plurality of the foregoing. In the system of the second terminal device, wherein the times of the first terminal device and the second terminal device are synchronized, the data synchronization device includes:
接收模块71,用于接收所述第一终端设备发送的添加有时间戳的数据和其他第二终端设备发送的根据所述添加有时间戳的数据反馈的数据;The receiving module 71 is configured to receive the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data feedback;
同步模块72,用于根据添加有时间戳的数据和所述反馈的数据进行数据同步;a synchronization module 72, configured to perform data synchronization according to the time-stamped data and the feedback data;
其中,所述时间戳是所述第一终端设备根据接收到所述数据的时间确定的。The timestamp is determined by the first terminal device according to the time when the data is received.
所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The same data in the first terminal device and the second terminal have the same data identifier;
所述反馈的数据是其他所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
所述同步模块具体用于:The synchronization module is specifically configured to:
判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining whether the sum of the numbers of data having the same data identifier is greater than a threshold;
当大于所述阈值时,确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
根据最大时间戳对应的数据进行数据同步。Data synchronization is performed based on the data corresponding to the maximum time stamp.
所述添加有时间戳的数据中携带有所述第一终端设备为所述数据设定生命周期;The time-stamped data carries the first terminal device to set a life cycle for the data;
所述装置还包括:The device also includes:
删除模块,当所述同步模块在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,用于删除具有相同所述数据标识的数据。Deleting a module, when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
具有相同所述数据标识的数据中还携带有同步类型;The data having the same data identifier also carries a synchronization type;
所述同步模块还具体用于:The synchronization module is also specifically configured to:
当最大时间戳对应的数据中的所述同步类型是同步数据时,根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is synchronous data, data synchronization is performed according to data corresponding to the maximum time stamp;
当最大时间戳对应的数据中的所述同步类型是同步删除数据时,删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
所述第二终端设备还包括:The second terminal device further includes:
发送模块,在所述接收模块接收到所述第一终端设备发送的添加有时间戳的数据后,用于将与所述添加有时间戳的数据的所述数据标识相同的数据中时间戳最大的数据 发送给所述第一终端设备,以使所述第一终端设备根据所述时间戳最大的数据进行数据同步。a sending module, after receiving the time-stamped data sent by the first terminal device, the receiving module is configured to maximize a timestamp in the same data as the data identifier of the time-stamped data The data Sending to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
本发明中当第一终端设备接收到数据时,在所述数据中添加时间戳并保存,然后将添加有时间戳的数据发送给第二终端设备,所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,并根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,本发明在不借助第三方设备和选举发送数据设备的情况下实现了终端设备集群的数据同步,降低了数据同步时的成本,并且集群中的终端设备是根据自身得到的数据来进行同步,保证了数据同步时的可靠性。In the present invention, when the first terminal device receives the data, adding a timestamp to the data and saving, and then transmitting the time-stamped data to the second terminal device, where the first terminal device receives the second The terminal device performs data synchronization according to the data fed back by the data with the timestamp added, and according to the data that is saved by the self-added timestamp and the feedback data, and the present invention does not rely on a third-party device. In the case of the election of the data device, the data synchronization of the terminal device cluster is realized, the cost of data synchronization is reduced, and the terminal devices in the cluster are synchronized according to the data obtained by themselves, thereby ensuring the reliability in data synchronization.
本领域普通技术人员可以理解:实现上述各方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成。前述的程序可以存储于一计算机可读取存储介质中。该程序在执行时,执行包括上述各方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。One of ordinary skill in the art will appreciate that all or part of the steps to implement the various method embodiments described above may be accomplished by hardware associated with the program instructions. The aforementioned program can be stored in a computer readable storage medium. The program, when executed, performs the steps including the foregoing method embodiments; and the foregoing storage medium includes various media that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
以上所描述的装置实施例仅仅是示意性的,其中作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到至少两个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, ie may be located in one place. Or it can be distributed to at least two network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. Those of ordinary skill in the art can understand and implement without deliberate labor.
最后应说明的是:以上各实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述各实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围。 Finally, it should be noted that the above embodiments are merely illustrative of the technical solutions of the present invention, and are not intended to be limiting; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that The technical solutions described in the foregoing embodiments may be modified, or some or all of the technical features may be equivalently replaced; and the modifications or substitutions do not deviate from the technical solutions of the embodiments of the present invention. range.

Claims (22)

  1. 一种数据的同步方法,其特征在于,所述方法应用于包括第一终端设备和第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述第二终端设备为多个,所述方法包括:A method for synchronizing data, wherein the method is applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device are synchronized The second terminal device is multiple, and the method includes:
    当第一终端设备接收到数据时,所述第一终端设备将接收到所述数据的时间戳添加到所述数据中;When the first terminal device receives the data, the first terminal device adds a timestamp of receiving the data to the data;
    所述第一终端设备将添加有所述时间戳的所述数据发送给所述第二终端设备,并保存添加有所述时间戳的所述数据;Transmitting, by the first terminal device, the data that is added with the timestamp to the second terminal device, and saving the data that is added with the timestamp;
    所述第一终端设备接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,以使所述第一终端设备根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步。Receiving, by the second terminal device, the data that is fed back by the second terminal device according to the data added with the timestamp, so that the first terminal device saves the data that is added with the timestamp according to the first time Data synchronization with the feedback data.
  2. 如权利要求1所述方法,其特征在于,所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The method according to claim 1, wherein the same data in the first terminal device and the second terminal have the same data identifier;
    所述反馈的数据是所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
  3. 如权利要求2所述方法,其特征在于,所述第一终端设备根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步,具体为:The method of claim 2, wherein the first terminal device performs data synchronization according to the data that is saved by the self-added timestamp and the feedback data, specifically:
    所述第一终端设备判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining, by the first terminal device, whether a sum of the numbers of data having the same data identifier is greater than a threshold;
    当大于所述阈值时,所述第一终端设备确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than the threshold, the first terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier;
    所述第一终端设备根据最大时间戳对应的数据进行数据同步。The first terminal device performs data synchronization according to data corresponding to the maximum time stamp.
  4. 如权利要求3所述方法,其特征在于,所述第一终端设备为保存添加有所述时间戳的所述数据设定生命周期,当所述第一终端设备在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,所述第一终端设备删除具有相同所述数据标识的数据。The method of claim 3, wherein the first terminal device sets a lifecycle for saving the data to which the timestamp is added, and when the first terminal device determines in the life cycle When the sum of the numbers of data having the same data identifier is not greater than the threshold, the first terminal device deletes data having the same data identifier.
  5. 如权利要求4所述方法,其特征在于,具有相同所述数据标识的数据中还携带有同步类型;The method of claim 4, wherein the data having the same data identifier further carries a synchronization type;
    所述第一终端设备根据最大时间戳对应的数据进行数据同步,具体为:The first terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
    当最大时间戳对应的数据中的所述同步类型是同步数据时,所述第一终端设备根据最大时间戳对应的数据进行数据同步; When the synchronization type in the data corresponding to the maximum timestamp is the synchronization data, the first terminal device performs data synchronization according to the data corresponding to the maximum timestamp;
    当最大时间戳对应的数据中的所述同步类型是同步删除数据时,所述第一终端删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum timestamp is the synchronous deletion data, the first terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
  6. 一种数据同步装置,其特征在于,所述数据同步装置位于第一终端设备,应用于包括所述第一终端设备和多个第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述数据同步装置包括:A data synchronization device, wherein the data synchronization device is located in a first terminal device, and is applied to a system including the first terminal device and a plurality of second terminal devices, wherein the first terminal device and The time of the second terminal device is synchronized, and the data synchronization device includes:
    添加模块,当所述第一终端设备接收到数据时,用于将接收到所述数据的时间戳添加到所述数据中;Adding a module, when the first terminal device receives the data, adding a timestamp for receiving the data to the data;
    发送模块,用于将添加有所述时间戳的所述数据发送给所述第二终端设备,并保存添加有所述时间戳的所述数据;a sending module, configured to send the data that is added with the timestamp to the second terminal device, and save the data that is added with the timestamp;
    接收模块,用于接收所述第二终端设备根据添加有所述时间戳的所述数据反馈的数据,以使所述第一终端设备中的同步模块根据自身保存的添加有所述时间戳的所述数据和所述反馈的数据进行数据同步。a receiving module, configured to receive data that is fed back by the second terminal device according to the data added with the timestamp, so that the synchronization module in the first terminal device adds the timestamp according to the saved The data and the feedback data are data synchronized.
  7. 如权利要求6所述的装置,其特征在于,所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The apparatus according to claim 6, wherein the same data in the first terminal device and the second terminal have the same data identifier;
    所述反馈的数据是所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the second terminal device according to the data having the same data identifier.
  8. 如权利要求7所述的装置,其特征在于,所述同步模块具体用于:The device according to claim 7, wherein the synchronization module is specifically configured to:
    判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining whether the sum of the numbers of data having the same data identifier is greater than a threshold;
    当大于所述阈值时,确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
    根据最大时间戳对应的数据进行数据同步。Data synchronization is performed based on the data corresponding to the maximum time stamp.
  9. 如权利要求8所述的装置,其特征在于,所述添加模块还用于为保存添加有所述时间戳的所述数据设定生命周期;The device according to claim 8, wherein the adding module is further configured to set a life cycle for saving the data to which the time stamp is added;
    所述装置还包括:The device also includes:
    删除模块,当所述同步模块在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,用于删除具有相同所述数据标识的数据。Deleting a module, when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
  10. 如权利要求9所述的装置,其特征在于,具有相同所述数据标识的数据中还携带有同步类型;The device according to claim 9, wherein the data having the same data identifier further carries a synchronization type;
    所述同步模块还具体用于: The synchronization module is also specifically configured to:
    当最大时间戳对应的数据中的所述同步类型是同步数据时,根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is synchronous data, data synchronization is performed according to data corresponding to the maximum time stamp;
    当最大时间戳对应的数据中的所述同步类型是同步删除数据时,删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
  11. 一种数据同步方法,其特征在于,所述方法应用于包括第一终端设备和第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述第二终端设备为多个,所述方法包括:A data synchronization method, wherein the method is applied to a system including a first terminal device and a second terminal device, wherein time of the first terminal device and the second terminal device are synchronized, The second terminal device is multiple, and the method includes:
    所述第二终端设备接收所述第一终端设备发送的添加有时间戳的数据和其他第二终端设备发送的根据所述添加有时间戳的数据反馈的数据;The second terminal device receives the time-stamped data sent by the first terminal device and the data sent by the other second terminal device according to the added time-stamped data feedback;
    所述第二终端设备根据添加有时间戳的数据和所述反馈的数据进行数据同步;The second terminal device performs data synchronization according to the data added with time stamp and the feedback data;
    其中,所述时间戳是所述第一终端设备根据接收到所述数据的时间确定的。The timestamp is determined by the first terminal device according to the time when the data is received.
  12. 如权利要求11所述方法,其特征在于,所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The method according to claim 11, wherein the same data in the first terminal device and the second terminal have the same data identifier;
    所述反馈的数据是其他所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
  13. 如权利要求12所述方法,其特征在于,所述第二终端设备根据添加有时间戳的数据和所述反馈的数据进行数据同步,具体为:The method of claim 12, wherein the second terminal device performs data synchronization according to the time-stamped data and the feedback data, specifically:
    所述第二终端设备判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining, by the second terminal device, whether a sum of the numbers of data having the same data identifier is greater than a threshold;
    当大于所述阈值时,所述第二终端设备确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than the threshold, the second terminal device determines data corresponding to a maximum timestamp in the data having the same data identifier;
    所述第二终端设备根据最大时间戳对应的数据进行数据同步。The second terminal device performs data synchronization according to data corresponding to the maximum time stamp.
  14. 如权利要求13所述方法,其特征在于,所述添加有时间戳的数据中携带有所述第一终端设备为所述数据设定生命周期,当所述第二终端设备在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,所述第二终端设备删除具有相同所述数据标识的数据。The method of claim 13, wherein the time-stamped data carries the first terminal device to set a life cycle for the data, when the second terminal device is in the life cycle When it is determined that the sum of the numbers of data having the same data identifier is not greater than the threshold, the second terminal device deletes data having the same data identifier.
  15. 如权利要求14所述方法,其特征在于,具有相同所述数据标识的数据中还携带有同步类型;The method of claim 14, wherein the data having the same data identifier further carries a synchronization type;
    所述第二终端设备根据最大时间戳对应的数据进行数据同步,具体为:The second terminal device performs data synchronization according to the data corresponding to the maximum timestamp, which is specifically:
    当最大时间戳对应的数据中的所述同步类型是同步数据时,所述第二终端设备根据最大时间戳对应的数据进行数据同步; When the synchronization type in the data corresponding to the maximum time stamp is the synchronization data, the second terminal device performs data synchronization according to the data corresponding to the maximum time stamp;
    当最大时间戳对应的数据中的所述同步类型是同步删除数据时,所述第二终端删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum timestamp is synchronous deletion data, the second terminal deletes the data value in the data corresponding to the maximum timestamp, and according to the data corresponding to the maximum timestamp of deleting the data value. Perform data synchronization.
  16. 如权利要求12所述方法,其特征在于,在所述第二终端设备接收到所述第一终端设备发送的添加有时间戳的数据后,所述第二终端设备将与所述添加有时间戳的数据的所述数据标识相同的数据中时间戳最大的数据发送给所述第一终端设备,以使所述第一终端设备根据所述时间戳最大的数据进行数据同步。The method of claim 12, wherein after the second terminal device receives the time-stamped data sent by the first terminal device, the second terminal device adds time with the adding The data of the stamped data identifies that the data with the highest timestamp in the same data is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
  17. 一种数据同步装置,其特征在于,所述数据同步装置位于第二终端设备,应用于包括第一终端设备和多个所述第二终端设备的系统中,其中,所述第一终端设备和所述第二终端设备的时间是同步的,所述数据同步装置包括:A data synchronization device, wherein the data synchronization device is located in a second terminal device, and is applied to a system including a first terminal device and a plurality of the second terminal devices, wherein the first terminal device and The time of the second terminal device is synchronized, and the data synchronization device includes:
    接收模块,用于接收所述第一终端设备发送的添加有时间戳的数据和其他第二终端设备发送的根据所述添加有时间戳的数据反馈的数据;a receiving module, configured to receive the time-stamped data sent by the first terminal device and the data sent by the second terminal device according to the added time-stamped data feedback;
    同步模块,用于根据添加有时间戳的数据和所述反馈的数据进行数据同步;a synchronization module, configured to perform data synchronization according to the time-stamped data and the feedback data;
    其中,所述时间戳是所述第一终端设备根据接收到所述数据的时间确定的。The timestamp is determined by the first terminal device according to the time when the data is received.
  18. 如权利要求17所述的装置,其特征在于,所述第一终端设备和所述第二终端中相同的数据具有相同的数据标识;The device according to claim 17, wherein the same data in the first terminal device and the second terminal have the same data identifier;
    所述反馈的数据是其他所述第二终端设备根据具有相同所述数据标识的数据确定的时间戳最大的数据。The feedback data is data with the largest timestamp determined by the other second terminal device according to the data having the same data identifier.
  19. 如权利要求18所述的装置,其特征在于,所述同步模块具体用于:The device according to claim 18, wherein the synchronization module is specifically configured to:
    判断具有相同所述数据标识的数据的数目之和是否大于阈值;Determining whether the sum of the numbers of data having the same data identifier is greater than a threshold;
    当大于所述阈值时,确定出具有相同所述数据标识的数据中最大时间戳对应的数据;When the threshold is greater than, the data corresponding to the largest timestamp in the data having the same data identifier is determined;
    根据最大时间戳对应的数据进行数据同步。Data synchronization is performed based on the data corresponding to the maximum time stamp.
  20. 如权利要求19所述的装置,其特征在于,所述添加有时间戳的数据中携带有所述第一终端设备为所述数据设定生命周期;The device according to claim 19, wherein the time-stamped data carries the first terminal device to set a life cycle of the data;
    所述装置还包括:The device also includes:
    删除模块,当所述同步模块在所述生命周期内判断出具有相同所述数据标识的数据的数目之和不大于所述阈值时,用于删除具有相同所述数据标识的数据。Deleting a module, when the synchronization module determines that the sum of the numbers of data having the same data identifier is not greater than the threshold value in the life cycle, for deleting data having the same data identifier.
  21. 如权利要求20所述的装置,其特征在于,具有相同所述数据标识的数据中还携带有同步类型; The device according to claim 20, wherein the data having the same data identifier further carries a synchronization type;
    所述同步模块还具体用于:The synchronization module is also specifically configured to:
    当最大时间戳对应的数据中的所述同步类型是同步数据时,根据最大时间戳对应的数据进行数据同步;When the synchronization type in the data corresponding to the maximum time stamp is synchronous data, data synchronization is performed according to data corresponding to the maximum time stamp;
    当最大时间戳对应的数据中的所述同步类型是同步删除数据时,删除最大时间戳对应的数据中的数据值,并根据删除所述数据值的最大时间戳对应的数据进行数据同步。When the synchronization type in the data corresponding to the maximum time stamp is synchronous deletion data, the data value in the data corresponding to the maximum time stamp is deleted, and data synchronization is performed according to the data corresponding to the maximum time stamp of deleting the data value.
  22. 如权利要求18所述的装置,其特征在于,所述装置还包括:The device of claim 18, wherein the device further comprises:
    发送模块,在所述接收模块接收到所述第一终端设备发送的添加有时间戳的数据后,用于将与所述添加有时间戳的数据的所述数据标识相同的数据中时间戳最大的数据发送给所述第一终端设备,以使所述第一终端设备根据所述时间戳最大的数据进行数据同步。 a sending module, after receiving the time-stamped data sent by the first terminal device, the receiving module is configured to maximize a timestamp in the same data as the data identifier of the time-stamped data The data is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest timestamp.
PCT/CN2017/076753 2016-03-25 2017-03-15 Data synchronization method and apparatus WO2017162079A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610179749.6A CN107231400B (en) 2016-03-25 2016-03-25 Data synchronization method and device
CN201610179749.6 2016-03-25

Publications (1)

Publication Number Publication Date
WO2017162079A1 true WO2017162079A1 (en) 2017-09-28

Family

ID=59899336

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/076753 WO2017162079A1 (en) 2016-03-25 2017-03-15 Data synchronization method and apparatus

Country Status (3)

Country Link
CN (1) CN107231400B (en)
TW (1) TWI746516B (en)
WO (1) WO2017162079A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019127154A1 (en) * 2017-12-27 2019-07-04 Oppo广东移动通信有限公司 Method and device for information feedback, and computer storage medium

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109033391B (en) * 2018-07-31 2019-12-31 北京嘀嘀无限科技发展有限公司 Method and system for synchronizing data among multiple data centers and computer readable storage medium
CN109032747B (en) * 2018-08-10 2021-10-15 江苏奇异点网络有限公司 Data updating method and device
CN109462661B (en) * 2018-12-19 2021-08-10 深圳市卡牛科技有限公司 Data synchronization method and device, computer equipment and storage medium
CN110768740B (en) * 2019-10-29 2020-12-01 广州趣丸网络科技有限公司 Time synchronization method and device
CN112799856A (en) * 2019-11-14 2021-05-14 华为技术有限公司 Method and device for acquiring data
CN111711663A (en) * 2020-05-26 2020-09-25 北京金山云网络技术有限公司 Processing method and device for publishing and subscribing services and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102801543A (en) * 2011-05-24 2012-11-28 中国银联股份有限公司 Method for dynamic data synchronization between active-active systems
WO2012163395A1 (en) * 2011-05-30 2012-12-06 Napatech A/S An apparatus and a method of parallel receipt, forwarding and time stamping data packets using synchronized clocks
CN104065752A (en) * 2014-07-11 2014-09-24 上海百步电子科技股份有限公司 Synchronization method of data between terminals
CN104580183A (en) * 2014-12-27 2015-04-29 北京奇虎科技有限公司 Cross-cluster data synchronization method and device
CN105162843A (en) * 2015-08-05 2015-12-16 卡斯柯信号有限公司 Dynamic planning based quick data synchronizing method

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI237766B (en) * 2003-12-17 2005-08-11 Inst Information Industry Method and system for performing interactive command in order, method and system for data synchronization between servers, and system for interaction between servers
US8935302B2 (en) * 2006-12-06 2015-01-13 Intelligent Intellectual Property Holdings 2 Llc Apparatus, system, and method for data block usage information synchronization for a non-volatile storage volume
CN101808137B (en) * 2010-03-29 2014-09-03 成都市华为赛门铁克科技有限公司 Data transmission method, device and system
US8655307B1 (en) * 2012-10-26 2014-02-18 Lookout, Inc. System and method for developing, updating, and using user device behavioral context models to modify user, device, and application state, settings and behavior for enhanced user security
CN104301428B (en) * 2014-10-29 2017-09-12 广州视源电子科技股份有限公司 A kind of method of data synchronization and server

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102801543A (en) * 2011-05-24 2012-11-28 中国银联股份有限公司 Method for dynamic data synchronization between active-active systems
WO2012163395A1 (en) * 2011-05-30 2012-12-06 Napatech A/S An apparatus and a method of parallel receipt, forwarding and time stamping data packets using synchronized clocks
CN104065752A (en) * 2014-07-11 2014-09-24 上海百步电子科技股份有限公司 Synchronization method of data between terminals
CN104580183A (en) * 2014-12-27 2015-04-29 北京奇虎科技有限公司 Cross-cluster data synchronization method and device
CN105162843A (en) * 2015-08-05 2015-12-16 卡斯柯信号有限公司 Dynamic planning based quick data synchronizing method

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019127154A1 (en) * 2017-12-27 2019-07-04 Oppo广东移动通信有限公司 Method and device for information feedback, and computer storage medium
CN111901781A (en) * 2017-12-27 2020-11-06 Oppo广东移动通信有限公司 Information feedback method and device and computer storage medium
US11412469B2 (en) 2017-12-27 2022-08-09 Guangdong Oppo Mobile Telecommunications Corp., Ltd. Method and device for selecting transmission time used to send feedback information
CN111901781B (en) * 2017-12-27 2023-03-24 Oppo广东移动通信有限公司 Information feedback method and device and computer storage medium

Also Published As

Publication number Publication date
CN107231400A (en) 2017-10-03
TWI746516B (en) 2021-11-21
TW201737107A (en) 2017-10-16
CN107231400B (en) 2020-07-03

Similar Documents

Publication Publication Date Title
WO2017162079A1 (en) Data synchronization method and apparatus
CN107465767B (en) Data synchronization method and system
CN103491055A (en) Method for synchronizing information among clients, clients and server
CN103544303B (en) A kind of method of data synchronization, system and equipment
CN106528574A (en) Data synchronization method and device
CN106453657A (en) Status information update method and device of smart home equipment
US9654995B2 (en) Method, device, and systems for managing access points controlled by an access point controller
CN105471716A (en) Method for achieving message synchronization across clients, user equipment and server
CN104954101B (en) Multiple terminals method of data synchronization based on synchronous ACK
CN105472024B (en) A kind of cross-region method of data synchronization based on message push mode
CN104750738B (en) A kind of method for updating the data information, back end, management node and system
CN107017958B (en) A kind of method for synchronizing time and corresponding system based on NTP
US20160308964A1 (en) Method, server, and system for synchronizing group member information
CN105208058A (en) Information exchange system based on web session sharing
CN107040576A (en) Information-pushing method and device, communication system
CN111831748A (en) Data synchronization method, device and storage medium
CN109802995A (en) Information push method, device, equipment and storage medium
WO2017220021A1 (en) Short message processing method and apparatus
CN110958150A (en) Management method and device for dynamic service configuration
CN114625565A (en) Data disaster tolerance backup method, Unified Data Management (UDM) entity and storage medium
CN111797352A (en) Method and device for sealing account and sealing system
WO2017016196A1 (en) Data synchronization method, apparatus, and system
CN112702361B (en) Safety blocking method, device and equipment based on lightweight distributed cooperative equipment
CN104852933A (en) Method for synchronizing browser bookmark data, system and device thereof
US10972419B2 (en) Archiving messages without message copying

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17769356

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 17769356

Country of ref document: EP

Kind code of ref document: A1