TWI746516B - Data synchronization method and device - Google Patents

Data synchronization method and device Download PDF

Info

Publication number
TWI746516B
TWI746516B TW106105351A TW106105351A TWI746516B TW I746516 B TWI746516 B TW I746516B TW 106105351 A TW106105351 A TW 106105351A TW 106105351 A TW106105351 A TW 106105351A TW I746516 B TWI746516 B TW I746516B
Authority
TW
Taiwan
Prior art keywords
data
terminal device
time stamp
synchronization
largest
Prior art date
Application number
TW106105351A
Other languages
Chinese (zh)
Other versions
TW201737107A (en
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 TW201737107A publication Critical patent/TW201737107A/en
Application granted granted Critical
Publication of TWI746516B publication Critical patent/TWI746516B/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

Abstract

本發明提供了一種資料的同步方法,所述方法包括:當第一終端設備接收到資料時,所述第一終端設備將接收到所述資料的時間戳記添加到所述資料中;所述第一終端設備將添加有所述時間戳記的所述資料發送給所述第二終端設備,並儲存添加有所述時間戳記的所述資料;所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,以使所述第一終端設備根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步。本發明在不借助第三方設備和選舉發送資料設備的情況下實現了終端設備叢集的資料同步,降低了資料同步時的成本,並且叢集中的終端設備是根據自身得到的資料來進行同步,保證了資料同步時的可靠性。 The present invention provides a data synchronization method. The method includes: when the first terminal device receives the data, the first terminal device adds the time stamp of the received data to the data; A terminal device sends the data with the time stamp to the second terminal device, and stores the data with the time stamp; the first terminal device receives the second terminal device according to The data fed back with the time stamp added, so that the first terminal device synchronizes the data according to the data with the time stamp added and the fed back stored in the first terminal device. The present invention realizes the data synchronization of the terminal equipment cluster without resorting to the third-party equipment and the election sending data equipment, and reduces the cost of data synchronization, and the terminal equipment in the cluster synchronizes according to the data obtained by itself, ensuring The reliability of data synchronization is improved.

Description

資料的同步方法和裝置 Data synchronization method and device

本發明涉及網路技術領域,尤其涉及一種資料的同步方法和裝置。 The present invention relates to the field of network technology, in particular to a data synchronization method and device.

在現有技術中,為了實現伺服器叢集中資料的一致性,提出了以下兩種解決方案: 如圖1所示的方案一:在伺服器叢集中增加一個配置中心,當其中一個伺服器(發佈者)獲取到資料並要將所述資料同步到其他伺服器(訂閱者)中時,所述伺服器將所述資料發送到所述配置中心,有所述配置中心向其他伺服器發送所述資料,進而使其他伺服器根據所述資料進行同步。 In the prior art, in order to achieve the consistency of data in the server cluster, the following two solutions are proposed: Solution 1 shown in Figure 1: Add a configuration center to the server cluster. When one of the servers (publisher) obtains data and synchronizes the data with other servers (subscribers), The server sends the data to the configuration center, and the configuration center sends the data to other servers, so that the other servers synchronize according to the data.

如圖2所示的方案二:所述伺服器叢集透過選舉演算法選舉出一個發佈者Master,其他伺服器為訂閱者,選擇成功後,當需要讓所述伺服器叢集同步一個資料時,由所述Master獲取所述資料,再由所述Master向訂閱者發送需要同步的資料,以使所述訂閱者進行資料同步,在訂閱者同步成功後向Master回傳同步成功的消息,當所述 Master當機後,所述伺服器叢集需要重進選舉Master。 The second scheme shown in Figure 2: The server cluster elects a publisher Master through an election algorithm, and the other servers are subscribers. After the selection is successful, when the server cluster needs to synchronize a data, the The Master obtains the data, and then the Master sends the data that needs to be synchronized to the subscriber, so that the subscriber can synchronize the data. After the subscriber is successfully synchronized, the synchronization success message is sent back to the Master. When the After the master goes down, the server cluster needs to re-elect the master.

在實現本發明的過程中,發明人發現現有技術至少存在如下問題:方案一在同步資料時依賴第三方設備,部署麻煩,可靠性不高,而方案二中如果叢集中的伺服器數量較大時,訂閱者回傳的同步成功的消息數量也就會越多,進而使得資料同步時的成本大大增加,並且在Master當機後,重新選舉時也會增加資料同步時的成本。 In the process of implementing the present invention, the inventor found that the prior art has at least the following problems: Solution one relies on third-party equipment when synchronizing data, which is troublesome to deploy and has low reliability, while in solution two, if there are a large number of servers in the cluster At this time, the number of successful synchronization messages sent back by subscribers will also increase, which will greatly increase the cost of data synchronization, and after the Master crashes, the cost of data synchronization will also increase when re-election.

本發明提供一種資料的同步方法和裝置,用於解決現有技術中依賴第三方設備,部署麻煩,可靠性不高的問題;本發明提供一種資料的同步方法和裝置,還用於解決現有技術中資料同步成本較高的問題。 The present invention provides a data synchronization method and device, which is used to solve the problems of relying on third-party equipment, troublesome deployment and low reliability in the prior art; the present invention provides a data synchronization method and device, which are also used to solve the problems in the prior art. The problem of high data synchronization cost.

本發明提供一種資料的同步方法,所述方法應用於包括第一終端設備和第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述第二終端設備為多個,所述方法包括:當第一終端設備接收到資料時,所述第一終端設備將接收到所述資料的時間戳記添加到所述資料中;所述第一終端設備將添加有所述時間戳記的所述資料發送給所述第二終端設備,並儲存添加有所述時間戳記的所述資料; 所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,以使所述第一終端設備根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步。 The present invention provides a data synchronization method, which is applied to a system including a first terminal device and a second terminal device, wherein the time of the first terminal device and the second terminal device are synchronized, so There are multiple second terminal devices, and the method includes: when the first terminal device receives the data, the first terminal device adds the time stamp of the received data to the data; the first The terminal device sends the data with the time stamp to the second terminal device, and stores the data with the time stamp; The first terminal device receives the data fed back by the second terminal device based on the data added with the time stamp, so that the first terminal device stores the data based on the data added with the time stamp. Synchronize data with the feedback data.

所述第一終端設備和所述第二終端中相同的資料具有相同的資料標識;所述回饋的資料是所述第二終端設備根據具有相同所述資料標識的資料確定的時間戳記最大的資料。 The same data in the first terminal device and the second terminal have the same data ID; the feedback data is the data with the largest time stamp determined by the second terminal device based on the data with the same data ID .

所述第一終端設備根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步,具體為:所述第一終端設備判斷具有相同所述資料標識的資料的數目之和是否大於閾值;當大於所述閾值時,所述第一終端設備確定出具有相同所述資料標識的資料中最大時間戳記對應的資料;所述第一終端設備根據最大時間戳記對應的資料進行資料同步。 The first terminal device performs data synchronization according to the data added with the time stamp and the feedback data stored in the first terminal device, specifically: the first terminal device determines the number of data with the same data identifier Whether the sum is greater than a threshold; when greater than the threshold, the first terminal device determines the data corresponding to the largest time stamp among the materials with the same data identifier; the first terminal device determines the data corresponding to the largest time stamp according to the largest time stamp Synchronize data.

所述第一終端設備為儲存添加有所述時間戳記的所述資料設定生命週期,當所述第一終端設備在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,所述第一終端設備刪除具有相同所述資料標識的資料。 The first terminal device sets a life cycle for storing the data with the time stamp added, and when the first terminal device determines in the life cycle that the sum of the number of data with the same data identifier is not When it is greater than the threshold, the first terminal device deletes the data with the same data identifier.

具有相同所述資料標識的資料中還攜帶有同步類型;所述第一終端設備根據最大時間戳記對應的資料進行資料同步,具體為: 當最大時間戳記對應的資料中的所述同步類型是同步資料時,所述第一終端設備根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,所述第一終端刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the first terminal device performs data synchronization according to the data corresponding to the largest time stamp, specifically: When the synchronization type in the data corresponding to the largest time stamp is synchronization data, the first terminal device performs data synchronization according to the data corresponding to the largest time stamp; when the synchronization type in the data corresponding to the largest time stamp is synchronization When deleting data, the first terminal deletes the data value in the data corresponding to the largest time stamp, and performs data synchronization according to the data corresponding to the largest time stamp of the deleted data value.

一種資料同步裝置,所述資料同步裝置位於第一終端設備,應用於包括所述第一終端設備和多個第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述資料同步裝置包括:添加模組,當所述第一終端設備接收到資料時,用於將接收到所述資料的時間戳記添加到所述資料中;發送模組,用於將添加有所述時間戳記的所述資料發送給所述第二終端設備,並儲存添加有所述時間戳記的所述資料;接收模組,用於接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,以使所述第一終端設備中的同步模組根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步。 A 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 second terminal device The time of the device is synchronized, and the data synchronization device includes: an adding module, when the first terminal device receives the data, it is used to add the time stamp of the received data to the data; Group, used to send the data added with the time stamp to the second terminal device, and to store the data added with the time stamp; a receiving module, used to receive the second terminal device The data fed back according to the data with the time stamp added, so that the synchronization module in the first terminal device performs data according to the data with the time stamp added and the feedback data stored by itself Synchronize.

所述第一終端設備和所述第二終端中相同的資料具有相同的資料標識;所述回饋的資料是所述第二終端設備根據具有相同所述資料標識的資料確定的時間戳記最大的資料。 The same data in the first terminal device and the second terminal have the same data ID; the feedback data is the data with the largest time stamp determined by the second terminal device based on the data with the same data ID .

所述同步模組具體用於:判斷具有相同所述資料標識的資料的數目之和是否大於閾值;當大於所述閾值時,確定出具有相同所述資料標識的資料中最大時間戳記對應的資料;根據最大時間戳記對應的資料進行資料同步。 The synchronization module is specifically configured to: determine whether the sum of the number of data with the same data identifier is greater than a threshold; when it is greater than the threshold, determine the data corresponding to the largest time stamp among the data with the same data identifier ; Synchronize data according to the data corresponding to the largest timestamp.

所述添加模組還用於為儲存添加有所述時間戳記的所述資料設定生命週期;所述裝置還包括:刪除模組,當所述同步模組在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,用於刪除具有相同所述資料標識的資料。 The adding module is also used to set a life cycle for storing the data added with the time stamp; the device further includes: a deletion module, when the synchronization module determines that the data has the same When the sum of the number of the data identified by the data is not greater than the threshold value, it is used to delete the data with the same data identification.

具有相同所述資料標識的資料中還攜帶有同步類型;所述同步模組還具體用於:當最大時間戳記對應的資料中的所述同步類型是同步資料時,根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the synchronization module is also specifically used for: when the synchronization type in the data corresponding to the largest time stamp is synchronized data, according to the data corresponding to the largest time stamp Perform data synchronization; when the synchronization type in the data corresponding to the largest time stamp is to delete data synchronously, delete the data value in the data corresponding to the largest time stamp, and proceed according to the data corresponding to the largest time stamp of the deleted data value Data synchronization.

一種資料同步方法,所述方法應用於包括第一終端設備和第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述第二終端設備為多個,所述方法包括: 所述第二終端設備接收所述第一終端設備發送的添加有時間戳記的資料和其他第二終端設備發送的根據所述添加有時間戳記的資料回饋的資料;所述第二終端設備根據添加有時間戳記的資料和所述回饋的資料進行資料同步;其中,所述時間戳記是所述第一終端設備根據接收到所述資料的時間確定的。 A data synchronization method, which is applied to a system including a first terminal device and a second terminal device, wherein the time of the first terminal device and the second terminal device are synchronized, and the second terminal device There are multiple devices, and the method includes: The second terminal device receives the time-stamped data sent by the first terminal device and the data fed back based on the time-stamped data sent by other second terminal devices; The time-stamped data and the feedback data are synchronized in data; wherein, the time-stamp 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 ID; the feedback data is the largest time stamp determined by the other second terminal devices based on the data with the same data ID material.

所述第二終端設備根據添加有時間戳記的資料和所述回饋的資料進行資料同步,具體為:所述第二終端設備判斷具有相同所述資料標識的資料的數目之和是否大於閾值;當大於所述閾值時,所述第二終端設備確定出具有相同所述資料標識的資料中最大時間戳記對應的資料;所述第二終端設備根據最大時間戳記對應的資料進行資料同步。 The second terminal device performs data synchronization according to the time stamped data and the feedback data, specifically: the second terminal device determines whether the sum of the number of data with the same data identifier is greater than a threshold; when When it is greater than the threshold, the second terminal device determines the data corresponding to the largest time stamp among the data with the same data identifier; the second terminal device performs data synchronization according to the data corresponding to the largest time stamp.

所述添加有時間戳記的資料中攜帶有所述第一終端設備為所述資料設定生命週期,當所述第二終端設備在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,所述第二終端設備刪除具有相同所述資料標識的資料。 The time-stamped data carries the first terminal device to set a life cycle for the data, when the second terminal device determines the number of data with the same data identifier during the life cycle When the sum is not greater than the threshold, the second terminal device deletes the data with the same data identifier.

具有相同所述資料標識的資料中還攜帶有同步類型;所述第二終端設備根據最大時間戳記對應的資料進行資料同步,具體為:當最大時間戳記對應的資料中的所述同步類型是同步資料時,所述第二終端設備根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,所述第二終端刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the second terminal device performs data synchronization according to the data corresponding to the largest time stamp, specifically: when the synchronization type in the data corresponding to the largest time stamp is synchronization Data, the second terminal device performs data synchronization according to the data corresponding to the largest timestamp; when the synchronization type in the data corresponding to the largest timestamp is to delete data synchronously, the second terminal deletes the data corresponding to the largest timestamp The data value in the data is synchronized according to the data corresponding to the largest time stamp at which the data value is deleted.

在所述第二終端設備接收到所述第一終端設備發送的添加有時間戳記的資料後,所述第二終端設備將與所述添加有時間戳記的資料的所述資料標識相同的資料中時間戳記最大的資料發送給所述第一終端設備,以使所述第一終端設備根據所述時間戳記最大的資料進行資料同步。 After the second terminal device receives the time-stamped material sent by the first terminal device, the second terminal device stores the material with the same data identifier as the material with the time-stamp The data with the largest time stamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest time stamp.

一種資料同步裝置,所述資料同步裝置位於第二終端設備,應用於包括第一終端設備和多個所述第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述資料同步裝置包括:接收模組,用於接收所述第一終端設備發送的添加有時間戳記的資料和其他第二終端設備發送的根據所述添加有時間戳記的資料回饋的資料;同步模組,用於根據添加有時間戳記的資料和所述回饋的資料進行資料同步; 其中,所述時間戳記是所述第一終端設備根據接收到所述資料的時間確定的。 A 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 second terminal device The time of the equipment is synchronized, and the data synchronization device includes: a receiving module for receiving the time-stamped data sent by the first terminal equipment and the time-stamped data sent by other second terminal equipment according to the time stamp The data of the data feedback; the synchronization module is used to synchronize the data based on the data added with a time stamp and the data of the feedback; Wherein, the time stamp 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 ID; the feedback data is the largest time stamp determined by the other second terminal devices based on the data with the same data ID material.

所述同步模組具體用於:判斷具有相同所述資料標識的資料的數目之和是否大於閾值;當大於所述閾值時,確定出具有相同所述資料標識的資料中最大時間戳記對應的資料;根據最大時間戳記對應的資料進行資料同步。 The synchronization module is specifically configured to: determine whether the sum of the number of data with the same data identifier is greater than a threshold; when it is greater than the threshold, determine the data corresponding to the largest time stamp among the data with the same data identifier ; Synchronize data according to the data corresponding to the largest timestamp.

所述添加有時間戳記的資料中攜帶有所述第一終端設備為所述資料設定生命週期;所述裝置還包括:刪除模組,當所述同步模組在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,用於刪除具有相同所述資料標識的資料。 The time-stamped data carries the first terminal device to set a life cycle for the data; the device further includes a deletion module, when the synchronization module determines that it has When the sum of the number of materials with the same material identifier is not greater than the threshold, it is used to delete the materials with the same material identifier.

具有相同所述資料標識的資料中還攜帶有同步類型;所述同步模組還具體用於:當最大時間戳記對應的資料中的所述同步類型是同步資料時,根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,刪除最大時間戳記對應的資料中的資料值, 並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the synchronization module is also specifically used for: when the synchronization type in the data corresponding to the largest time stamp is synchronized data, according to the data corresponding to the largest time stamp Perform data synchronization; when the synchronization type in the data corresponding to the largest time stamp is to delete data synchronously, delete the data value in the data corresponding to the largest time stamp, And data synchronization is performed according to the data corresponding to the largest time stamp of the deleted data value.

所述裝置還包括:發送模組,在所述接收模組接收到所述第一終端設備發送的添加有時間戳記的資料後,用於將與所述添加有時間戳記的資料的所述資料標識相同的資料中時間戳記最大的資料發送給所述第一終端設備,以使所述第一終端設備根據所述時間戳記最大的資料進行資料同步。 The device further includes: a sending module, after the receiving module receives the time-stamped data sent by the first terminal device, it is used to combine the data with the time-stamped data The data with the largest time stamp among the data with the same identification is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest time stamp.

本發明中當第一終端設備接收到資料時,在所述資料中添加時間戳記並儲存,然後將添加有時間戳記的資料發送給第二終端設備,所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,並根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步,本發明在不借助第三方設備和選舉發送資料設備的情況下實現了終端設備叢集的資料同步,降低了資料同步時的成本,並且叢集中的終端設備是根據自身得到的資料來進行同步,保證了資料同步時的可靠性。 In the present invention, when the first terminal device receives data, it adds a time stamp to the data and stores it, and then sends the data with the time stamp to the second terminal device, and the first terminal device receives the second terminal device. The terminal device performs data synchronization based on the data fed back by the data with the time stamp added, and the data is synchronized based on the data with the time stamp added and the feedback data stored by itself. The present invention does not rely on third-party equipment In the case of the election sending data device, the data synchronization of the terminal equipment cluster is realized, which reduces the cost of data synchronization, and the terminal equipment in the cluster synchronizes according to the data obtained by itself, which ensures the reliability of the data synchronization.

301-402‧‧‧步驟 301-402‧‧‧Step

61‧‧‧添加模組 61‧‧‧Add Module

62‧‧‧發送模組 62‧‧‧Send module

63‧‧‧接收模組 63‧‧‧Receiving Module

71‧‧‧接收模組 71‧‧‧Receiving Module

72‧‧‧同步模組 72‧‧‧Sync Module

為了更清楚地說明本發明實施例或現有技術中的技術方案,下面將對實施例或現有技術描述中所需要使用的圖式作一簡單地介紹,顯而易見地,下面描述中的圖式是本發明的一些實施例,對於本領域普通技術人員來講,在不 付出創造性勞動性的前提下,還可以根據這些圖式獲得其他的圖式。 In order to more clearly explain the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are based on the present invention. Some embodiments of the invention, for those of ordinary skill in the art, will not Under the premise of devoting creative labor, you can also obtain other schemas based on these schemas.

圖1為現有技術中的一種依靠第三方設備進行資料同步的流程示意圖;圖2為現有技術中的一種透過選舉發佈者進行資料同步的流程示意圖;圖3為本發明實施例中的一種資料的同步方法流程圖之一;圖4為本發明實施例中的一種資料的同步方法流程圖之二;圖5為本發明實施例中的一種資料發佈時的同步方法流程示意圖;圖6為本發明實施例中的一種資料同步裝置結構示意圖之一;圖7為本發明實施例中的一種資料同步裝置結構示意圖之二。 Figure 1 is a schematic diagram of a data synchronization process based on a third-party device in the prior art; Figure 2 is a schematic diagram of a data synchronization process through election publishers in the prior art; Figure 3 is a schematic diagram of a data synchronization process in an embodiment of the present invention One of the flow chart of the synchronization method; Figure 4 is the second flow chart of a data synchronization method in an embodiment of the present invention; Figure 5 is a flow diagram of a synchronization method when data is released in an embodiment of the present invention; Figure 6 is the present invention The first structural diagram of a data synchronization device in the embodiment; FIG. 7 is the second structural diagram of a data synchronization device in an embodiment of the present invention.

為使本發明實施例的目的、技術方案和優點更加清楚,下面將結合本發明實施例中的圖式,對本發明實施例中的技術方案進行清楚、完整地描述,顯然,所描述的實施例是本發明一部分實施例,而不是全部的實施例。基於本發明中的實施例,本領域普通技術人員在沒有作出創造性勞動前提下所獲得的所有其他實施例,都屬於本發明保 護的範圍。 In order to make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work are guaranteed by the present invention. The scope of protection.

在現有技術中,由於依靠第三方設備來實現同步資料的方案存在部署麻煩,可靠性不高的缺陷,依靠選舉資料發佈者的方案存在增加資料同步成本的缺陷,因此本申請提出了一種資料的同步方法,具體如圖3所示,所述方法應用於包括第一終端設備和第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述第二終端設備為多個,所述方法包括以下步驟: 步驟301,當第一終端設備接收到資料時,所述第一終端設備將接收到所述資料的時間戳記添加到所述資料中。 In the prior art, the solution of relying on third-party equipment to realize data synchronization has the disadvantages of deployment troubles and low reliability, and the solution of relying on election data publishers has the disadvantage of increasing the cost of data synchronization. Therefore, this application proposes a data synchronization solution. The synchronization method is specifically shown in FIG. 3, the method is applied to a system including a first terminal device and a second terminal device, wherein the time of the first terminal device and the second terminal device are synchronized, There are multiple second terminal devices, and the method includes the following steps: Step 301: When the first terminal device receives the data, the first terminal device adds the time stamp of the received 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 realize the unity of the time of the terminal devices in the cluster, and to ensure that the first terminal device has the same time when adding a time stamp to the data The foundation further ensures that the terminal devices in the cluster can correctly determine the same data with the largest time stamp. Wherein, the first terminal device is a device that receives data, and the first terminal device should not be a fixed device in the cluster. It is determined based on the device that receives the data in the cluster, and the data is sent by a device outside the cluster. of. For example: there are 3 terminal devices in the cluster, namely device 1, device 2 and device 3. When device 1 receives the data sent by the user, then device 1 is the first terminal device, if device 2 receives the user When the data is sent by the terminal, device 2 is the first terminal device at this time. In the same way, the second terminal device is another terminal device in the cluster except the first terminal device, and the second terminal device is the receiving station in the cluster. The device for the data sent by the first terminal device, for example: there are 3 terminal devices in the cluster, namely device 1, device 2, and device 3. When device 1 is the first terminal device, device 2 and device 3 are the second terminal devices. The terminal device, when the device 2 is the first terminal device, the device 1 and the device 3 are the second terminal devices.

步驟302,所述第一終端設備將添加有所述時間戳記的所述資料發送給所述第二終端設備,並儲存添加有所述時間戳記的所述資料。 Step 302: The first terminal device sends the data with the time stamp to the second terminal device, and stores the data with the time stamp.

具體的,所述第一終端設備儲存添加有所述時間戳記的所述資料是為了在後續進行資料同步。 Specifically, the first terminal device stores the data added with the time stamp for subsequent data synchronization.

步驟303,所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,以使所述第一終端設備根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步。 Step 303: The first terminal device receives the data fed back by the second terminal device based on the data added with the time stamp, so that the first terminal device stores the data added with the time stamp according to the first terminal device. The data and the feedback data are synchronized.

其中,所述第一終端設備和所述第二終端中相同的資料具有相同的資料標識; 所述回饋的資料是所述第二終端設備根據具有相同所述資料標識的資料確定的時間戳記最大的資料。 Wherein, the same data in the first terminal device and the second terminal have the same data identifier; The feedback data is the data with the largest time stamp determined by the second terminal device according to the data with the same data identifier.

具體的,在叢集中的終端設備接收到的叢集之外的設備發送的資料中攜帶有資料標識,並且叢集之外的設備發送的同一資料的資料標識是相同的,其中,同一資料可能在不同時間發送,叢集是根據接收到的資料進行同步的,因此叢集中的設備中可能存在與當前接收到的資料的資料標識相同的資料,所述存在資料標識相同的資料中同樣存 在叢集中的設備接收到所述資料的時間戳記。 Specifically, the data sent by devices outside the cluster received by the terminal devices in the cluster carry data identifiers, and the data identifiers of the same data sent by the devices outside the cluster are the same. Among them, the same data may be different. Time transmission, the cluster is synchronized based on the received data. Therefore, the devices in the cluster may have data with the same data identifier as the currently received data, and the data with the same data identifier may also be stored in the same data. The device in the cluster received the time stamp of the data.

所述第二終端設備中可能存在與所述資料相同的資料標識,因此在所述第二終端設備接收到添加有所述時間戳記的所述資料時,所述第二終端設備需要根據添加所述時間戳記的所述資料的資料標識確定出所述第二終端中存在相同資料標識的資料,然後,所述第二終端設備根據具有相同資料標識的資料確定出時間戳記最大的資料,此時確定出的資料為叢集最新接收到的資料,需要以此為資料同步的依據,並將確定出的時間戳記最大的資料作為回饋資料回饋給所述第一終端設備,在所述第一終端設備接收到叢集中的第二終端設備回饋的時間戳記最大的資料後,所述第一終端設備就可以根據回饋的資料和自身儲存的添加有所述時間戳記的所述資料確定出最新的資料,以使所述第一終端設備根據所述最新的資料進行資料同步。 The second terminal device may have the same data identifier as the data. Therefore, when the second terminal device receives the data with the time stamp, the second terminal device needs to add the data according to the The data identifier of the data of the time stamp determines that the data with the same data identifier exists in the second terminal, and then, the second terminal device determines the data with the largest time stamp based on the data with the same data identifier. The determined data is the latest received data of the cluster, which needs to be used as the basis for data synchronization, and the determined data with the largest time stamp is used as feedback data to feed back to the first terminal device. After receiving the data with the largest time stamp returned by the second terminal device in the cluster, the first terminal device can determine the latest data based on the feedback data and the data stored with the time stamp added by the first terminal device. 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 added with the time stamp and the feedback data stored in the first terminal device, specifically: the first terminal device determines the number of data with the same data identifier Whether the sum is greater than a threshold; when greater than the threshold, the first terminal device determines the data corresponding to the largest time stamp among the materials with the same data identifier; the first terminal device determines the data corresponding to the largest time stamp according to the largest time stamp Synchronize data.

具體的,所述閾值根據實際情況確定,例如:所述閾值為叢集中的終端設備數目的一半,當所述第一終端設備 確定出的具有相同所述資料標識的資料的數目表示叢集中就有多少個終端設備接收到了所述資料,當所述數目超過閾值時表示叢集達到了資料同步的要求,此時所述第一終端設備就可以根據自身中的最新的所述資料進行資料同步。 Specifically, the threshold value is determined according to actual conditions, for example: the threshold value is half of the number of terminal devices in the cluster, when the first terminal device The determined number of data with the same data identifier indicates how many terminal devices in the cluster have received the data, and when the number exceeds the threshold, it indicates that the cluster has reached the data synchronization requirements. At this time, the first The terminal device can synchronize data according to the latest data in itself.

所述第一終端設備為儲存添加有所述時間戳記的所述資料設定生命週期,當所述第一終端設備在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,所述第一終端設備刪除具有相同所述資料標識的資料。 The first terminal device sets a life cycle for storing the data with the time stamp added, and when the first terminal device determines in the life cycle that the sum of the number of data with the same data identifier is not When it is greater than the threshold, the first terminal device deletes the data with the same data identifier.

具體的,資料同步時必須在一定時間內完成資料同步,否則就失去了資料同步的意義,因此,在所述第一終端設備在為所述資料添加時間戳記時還要為所述資料設定生命週期,所述生命週期的長短根據實際情況確定,當所述第一終端設備在所述生命週期內沒有收到超過所述閾值的具有相同資料標識的資料時表示此次資料同步失敗,為了保證所述第一終端設備的資源不被浪費,因此所述第一終端設備刪除具有相同所述資料標識的資料。 Specifically, data synchronization must be completed within a certain period of time during data synchronization, otherwise the meaning of data synchronization will be lost. Therefore, when the first terminal device adds a time stamp to the data, the life of the data must be set. Cycle, the length of the life cycle is determined according to actual conditions. When the first terminal device does not receive data with the same data identifier that exceeds the threshold during the life cycle, it means that the data synchronization has failed this time. In order to ensure The resources of the first terminal device are not wasted, so the first terminal device deletes the data with the same data identifier.

具有相同所述資料標識的資料中還攜帶有同步類型;所述第一終端設備根據最大時間戳記對應的資料進行資料同步,具體為:當最大時間戳記對應的資料中的所述同步類型是同步資料時,所述第一終端設備根據最大時間戳記對應的資料進行資料同步; 當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,所述第一終端刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the first terminal device performs data synchronization according to the data corresponding to the largest time stamp, specifically: when the synchronization type in the data corresponding to the largest time stamp is synchronization When data is being collected, the first terminal device performs data synchronization according to the data corresponding to the largest time stamp; When the synchronization type in the data corresponding to the largest time stamp is to delete data synchronously, the first terminal deletes the data value in the data corresponding to the largest time stamp, and deletes the data corresponding to the largest time stamp of the data value according to Synchronize data.

具體的,在資料同步時是為了讓叢集中的終端設備的資料統一,而所述第一終端設備接收到的資料進行同步時,有時是為了增加資料,而有時是為了刪除資料,如果所述第一終端設備確定出的最大時間戳記對應的資料的同步類型是同步資料時,表示是為了增加資料,所述第一終端設備根據最大時間戳記對應的資料進行資料同步;如果所述第一終端設備確定出的最大時間戳記對應的資料的同步類型是刪除資料時,表示是為了撤銷所述資料,所述第一終端設備根據最大時間戳記對應的資料進行同步時刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步,其中在刪除所述資料時,所述第一終端設備可以只刪除所述資料本身,保留所述資料對應的時間戳記、同步類型和資料標識等資訊,以供後續查詢。 Specifically, the data synchronization is to unify the data of the terminal devices in the cluster, and when the data received by the first terminal device is synchronized, sometimes it is to increase the data, and sometimes it is to delete the data. When the synchronization type of the data corresponding to the largest time stamp determined by the first terminal device is synchronized data, it means that it is for adding data, and the first terminal device performs data synchronization according to the data corresponding to the largest time stamp; When the synchronization type of the data corresponding to the largest time stamp determined by a terminal device is to delete the data, it means that it is to cancel the data, and the first terminal device deletes the data corresponding to the largest time stamp when synchronizing the data corresponding to the largest time stamp. The data value in the data is synchronized according to the data corresponding to the largest time stamp for deleting the data value, wherein when deleting the data, the first terminal device may only delete the data itself, and retain the data Corresponding timestamp, synchronization type, data identification and other information for subsequent query.

當所述第一終端設備中接收叢集之外的設備發送的至少一個具有相同的資料標識的資料時。所述第一終端設備根據接收資料的先後順序進行資料同步。 When the first terminal device receives at least one data with the same data identifier sent by a device outside the cluster. The first terminal device performs data synchronization according to the order of receiving the data.

本發明中當第一終端設備接收到資料時,在所述資料中添加時間戳記並儲存,然後將添加有時間戳記的資料發送給第二終端設備,所述第一終端設備接收所述第二終端 設備根據添加有所述時間戳記的所述資料回饋的資料,並根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步,本發明在不借助第三方設備和選舉發送資料設備的情況下實現了終端設備叢集的資料同步,降低了資料同步時的成本,並且叢集中的終端設備是根據自身得到的資料來進行同步,保證了資料同步時的可靠性。 In the present invention, when the first terminal device receives data, it adds a time stamp to the data and stores it, and then sends the data with the time stamp to the second terminal device, and the first terminal device receives the second terminal device. terminal The device performs data synchronization based on the data fed back by the data with the time stamp added, and the data is synchronized according to the data with the time stamp added and the feedback data stored by itself. The present invention does not use third-party equipment and In the case of electing data transmission equipment, the data synchronization of the terminal equipment cluster is realized, which reduces the cost of data synchronization, and the terminal equipment in the cluster synchronizes according to the data obtained by itself, which ensures the reliability of data synchronization.

本發明還提供了一種資料的同步方法,具體如圖4所示,所述方法應用於包括第一終端設備和第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述第二終端設備為多個,所述方法包括以下步驟:步驟401,所述第二終端設備接收所述第一終端設備發送的添加有時間戳記的資料和其他第二終端設備發送的根據所述添加有時間戳記的資料回饋的資料。 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 second terminal device The time of the terminal device is synchronized. There are multiple second terminal devices. The method includes the following steps: Step 401, the second terminal device receives the time stamped data and time stamp sent by the first terminal device. The data sent back by other second terminal devices based on the data added with a time stamp.

其中,所述時間戳記是所述第一終端設備根據接收到所述資料的時間確定的。 Wherein, the time stamp 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 ID; the feedback data is the largest time stamp determined by the other second terminal devices based on the data with the same data ID material.

例如:終端設備叢集中包括:設備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 equipment cluster includes: equipment 1, equipment 2, and equipment 3, where equipment 1 is the first terminal equipment, equipment 2 and equipment 3 are second terminal equipment, when the equipment 1 receives data, all Description of equipment 1 When sending the time-stamped data to the device 2, it also sends it to the device 3. At this time, the device 2 is the second terminal device, and the device 3 is the other second terminal device, Since the data with the same data identifier may exist in the device 3, in order to ensure that the device 2 updates the latest data when the data is synchronized, the device 3 will also determine that it has the same data. The data with the largest time stamp of the identified data is sent to the device 2, so that the device 2 can synchronize data based on the latest data. In the same way, when the device 2 receives the data sent by the device, the device 2 must also determine that the data with the same data identifier has the largest time stamp and send it to the device 3 so that the device 2 3 You can also synchronize data based on the latest data.

步驟402,所述第二終端設備根據添加有時間戳記的資料和所述回饋的資料進行資料同步。 In step 402, the second terminal device performs data synchronization according to the time-stamped data and the feedback data.

具體的,在所述第二終端設備在接收到添加有時間戳記的資料和其他第二終端設備回饋的資料後,此時所述第二終端設備中包含了叢集中其他所有終端設備回饋的具有所述相同資料標識的資料,此時如果所述第二終端設備中還存在其他具有相同資料標識的資料,所述第二終端設備在添加有時間戳記的資料、其他第二終端設備回饋的資料和所述其他具有相同資料標識的資料中確定出時間戳記最大的資料,以使所述第二終端設備根據所述時間戳記最大的資料進行資料同步。同理,其他所述第二終端設備也根據上述過程進行資料同步。 Specifically, after the second terminal device receives the time-stamped data and the data fed back by other second terminal devices, at this time, the second terminal device includes information that has been fed back by all other terminal devices in the cluster. The data with the same data ID, if there are other data with the same data ID in the second terminal device at this time, the second terminal device adds the data with a time stamp and the data returned by other second terminal devices. The data with the largest time stamp is determined from among the other data with the same data identifier, so that the second terminal device performs data synchronization according to the data with the largest time stamp. In the same way, the other second terminal devices also perform data synchronization according to the foregoing process.

所述第二終端設備根據添加有時間戳記的資料和所述回饋的資料進行資料同步,具體為:所述第二終端設備判斷具有相同所述資料標識的資料的數目之和是否大於閾值;當大於所述閾值時,所述第二終端設備確定出具有相同所述資料標識的資料中最大時間戳記對應的資料;所述第二終端設備根據最大時間戳記對應的資料進行資料同步。 The second terminal device performs data synchronization according to the time stamped data and the feedback data, specifically: the second terminal device determines whether the sum of the number of data with the same data identifier is greater than a threshold; when When it is greater than the threshold, the second terminal device determines the data corresponding to the largest time stamp among the data with the same data identifier; the second terminal device performs data synchronization according to the data corresponding to the largest time stamp.

具體的,當所述第二終端設備確定出的具有相同所述資料標識的資料的數目表示叢集中就有多少個終端設備接收到了所述資料,當所述數目超過閾值時表示叢集達到了資料同步的要求,此時所述第二終端設備就可以根據自身中的最新的所述資料進行資料同步。 Specifically, when the number of data with the same data identifier determined by the second terminal device indicates how many terminal devices in the cluster have received the data, when the number exceeds a threshold, it indicates that the cluster has reached the data Synchronization requirements, at this time, the second terminal device can synchronize data according to the latest data in itself.

所述添加有時間戳記的資料中攜帶有所述第一終端設備為所述資料設定生命週期,當所述第二終端設備在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,所述第二終端設備刪除具有相同所述資料標識的資料。 The time-stamped data carries the first terminal device to set a life cycle for the data, when the second terminal device determines the number of data with the same data identifier during the life cycle When the sum is not greater than the threshold, the second terminal device deletes the data with the same data identifier.

具體的,資料同步時必須在一定時間內完成資料同步,否則就失去了資料同步的意義,因此,在所述第一終端設備在為所述資料添加時間戳記時還要為所述資料設定生命週期,所述生命週期的長短根據實際情況確定,當所述第二終端設備在所述生命週期內沒有收到超過所述閾值的具有相同資料標識的資料時表示此次資料同步失敗,為 了保證所述第二終端設備的資源不被浪費,因此所述第一終端設備刪除具有相同所述資料標識的資料。 Specifically, data synchronization must be completed within a certain period of time during data synchronization, otherwise the meaning of data synchronization will be lost. Therefore, when the first terminal device adds a time stamp to the data, the life of the data must be set. Cycle, the length of the life cycle is determined according to actual conditions. When the second terminal device does not receive data with the same data identifier that exceeds the threshold during the life cycle, it means that the data synchronization has failed this time, which is To ensure that the resources of the second terminal device are not wasted, the first terminal device deletes the data with the same data identifier.

具有相同所述資料標識的資料中還攜帶有同步類型;所述第二終端設備根據最大時間戳記對應的資料進行資料同步,具體為:當最大時間戳記對應的資料中的所述同步類型是同步資料時,所述第二終端設備根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,所述第二終端刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the second terminal device performs data synchronization according to the data corresponding to the largest time stamp, specifically: when the synchronization type in the data corresponding to the largest time stamp is synchronization Data, the second terminal device performs data synchronization according to the data corresponding to the largest timestamp; when the synchronization type in the data corresponding to the largest timestamp is to delete data synchronously, the second terminal deletes the data corresponding to the largest timestamp The data value in the data is synchronized according to the data corresponding to the largest time stamp at which the data value is deleted.

具體的,在資料同步時是為了讓叢集中的終端設備的資料統一,而所述第二終端設備在進行資料同步時,有時是為了增加資料,而有時是為了刪除資料,如果所述第二終端設備確定出的最大時間戳記對應的資料的同步類型是同步資料時,表示是為了增加資料,所述第二終端設備根據最大時間戳記對應的資料進行資料同步;如果所述第二終端設備確定出的最大時間戳記對應的資料的同步類型是刪除資料時,表示是為了撤銷所述資料,所述第二終端設備根據最大時間戳記對應的資料進行同步時刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步,,其中在刪除所述資料時,所述第二終端設備可以只刪除所述資料本身,保 留所述資料對應的時間戳記、同步類型和資料標識等資訊,以供後續查詢。 Specifically, the data synchronization is to unify the data of the terminal devices in the cluster, and when the second terminal device synchronizes the data, sometimes it is to increase the data, and sometimes it is to delete the data. When the synchronization type of the data corresponding to the largest timestamp determined by the second terminal device is synchronized data, it means that it is for adding data, and the second terminal device performs data synchronization according to the data corresponding to the largest timestamp; if the second terminal When the synchronization type of the data corresponding to the largest time stamp determined by the device is to delete the data, it means that it is to withdraw the data, and the second terminal device deletes the data corresponding to the largest time stamp when synchronizing the data corresponding to the largest time stamp. Data value, and perform data synchronization according to the data corresponding to the largest time stamp of deleting the data value, wherein when deleting the data, the second terminal device can only delete the data itself to ensure Leave the time stamp, synchronization type, and data identification information corresponding to the data for subsequent query.

在所述第二終端設備接收到所述第一終端設備發送的添加有時間戳記的資料後,所述第二終端設備將與所述添加有時間戳記的資料的所述資料標識相同的資料中時間戳記最大的資料發送給所述第一終端設備,以使所述第一終端設備根據所述時間戳記最大的資料進行資料同步。 After the second terminal device receives the time-stamped material sent by the first terminal device, the second terminal device stores the material with the same data identifier as the material with the time-stamp The data with the largest time stamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest time stamp.

本發明中當第一終端設備接收到資料時,在所述資料中添加時間戳記並儲存,然後將添加有時間戳記的資料發送給第二終端設備,所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,並根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步,本發明在不借助第三方設備和選舉發送資料設備的情況下實現了終端設備叢集的資料同步,降低了資料同步時的成本,並且叢集中的終端設備是根據自身得到的資料來進行同步,保證了資料同步時的可靠性。 In the present invention, when the first terminal device receives data, it adds a time stamp to the data and stores it, and then sends the data with the time stamp to the second terminal device, and the first terminal device receives the second terminal device. The terminal device performs data synchronization based on the data fed back by the data with the time stamp added, and the data is synchronized based on the data with the time stamp added and the feedback data stored by itself. The present invention does not rely on third-party equipment In the case of the election sending data device, the data synchronization of the terminal equipment cluster is realized, which reduces the cost of data synchronization, and the terminal equipment in the cluster synchronizes according to the data obtained by itself, which ensures the reliability of the 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 now be described in combination with specific application scenarios. Specifically, the system includes three servers: server A, server B, and server C. The time of the three servers is synchronized, and the terminal that generates the synchronized data is the client, and the structure of the synchronized data is defined: D={K,V,S,T}, K represents the data identifier, and V represents the data value , S represents the status of the data (the status of the data is: SYNC means synchronizing, UPDATED Indicates that the synchronization is complete. ZOMBIE means three states of deleting the data value. T means the timestamp when the server receives the data. The timestamp is in milliseconds, and the storage of each server is divided into three parts: Temporary storage area: used for Store the synchronized data, the status of the synchronized data at this time is SYNC, and the life cycle is I; data area: there are valid data in it, and the data status at this time is UPDATED, which can be read and used by the client; the area to be deleted: use In the storage deletion notification, the status of the data at this time is ZOMBIE, the life cycle is I, and the specified threshold is 1.5. The specific process is shown in Figure 5.

用戶端發佈了一個表示為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 denoted as K, and chooses to send it to server A. If the data status S and the time stamp T in the data are empty at this time, the server A, after receiving the data, will The time of receiving the data is added with a time stamp in T, and S is set to SYNC, and the data is sent to the server cluster including itself. When server B receives the data, it will be stored in the temporary storage area. Find other data with K as the data identifier. If the time stamp in the other data is less than the data, then the server B ignores the data, if it is greater, the server B replaces all the data with the data. The other data is described, and the data is sent to the server A and the server C. Similarly, the server C also needs to complete the above process. At this time, server B determines that the number of data with data identification K in the temporary storage area is 2, which exceeds the threshold. The server B selects the data with the largest time stamp in the temporary storage area with K as the identification time stamp, and adds The data with the largest time stamp is moved to the data area, and S is set to UPDATED. If there is data with K as the data in the data area, the data with the largest time stamp is used to overwrite the data in the data area with K as the data Identify the information. If in During the life cycle of the data, if server B determines that the data with the data identification K is less than the threshold, it does not perform the move operation, and deletes all the data identified with K as the data in server B. The same is true for server C. Complete the above process.

在完成上述過程後,伺服器A中存在至少3條以K為資料標識的資料,所述伺服器A確定出時間戳記最大的資料後,將所述時間戳記最大的資料移動到資料區,並將S設置為UPDATED,如果資料區中存在以K為資料標識的資料,則用所述時間戳記最大的資料覆蓋所述資料區中以K為資料標識的資料。如果在所述資料的生命週期內伺服器A確定資料標識為K的資料小於所述閾值,則不執行移動操作,並刪除伺服器A中以K為資料標識的所有資料。 After completing the above process, there are at least 3 pieces of data with K as the data identifier in server A. After the server A determines the data with the largest time stamp, it moves the data with the largest time stamp to the data area, and Set S to UPDATED, and if there is data identified by K as the data in the data area, the data with the largest time stamp will be used to overwrite the data identified by K as the data in the data area. If the server A determines that the data with the data identification K is less than the threshold during the life cycle of the data, it does not perform the move operation, and deletes all the data identified with K as the data in the server A.

由於伺服器B和伺服器C是根據伺服器A發送的資料進行同步和回饋的,因此當其中一個伺服器中確定出資料標識為K的資料的個數小於所述閾值時,其他伺服器中以K為資料標識的資料的個數也小於所述閾值,因此,當一個伺服器刪除以K為資料標識的資料時,其他伺服器也在刪除以K為資料標識的資料。並且伺服器A在刪除以K為資料標識的資料後,還要向用戶端回饋同步失敗的消息。 Since server B and server C synchronize and feed back based on the data sent by server A, when one of the servers determines that the number of data with data identification K is less than the threshold, the other servers The number of data identified by K as the data is also less than the threshold. Therefore, when one server deletes the data identified by K as the data, other servers are also deleting the data identified by K as the data. In addition, after server A deletes the data identified by K as the data, it also sends a message back to the client that the synchronization has failed.

用戶端發佈了一個表示為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 denoted as K and chooses to send it to server A. If the data status S in the data is ZOMBIE and the time stamp T is empty at this time, the server A receives the data Rear, Add a time stamp 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, and when the server B receives the data, it searches in the temporary storage area For other data with K as the data identifier, if the time stamp in the other data is less than the data, then the server B ignores the data, if it is greater, the server B replaces the data with the data Other data, and sending the data to server A and server C, also need to complete the above process. At this time, server B determines that the number of data with data identification K in the temporary storage area is 2, which exceeds the threshold. The server B selects the data with the largest time stamp in the temporary storage area with K as the identification time stamp, and adds The data with the largest time stamp is moved to the area to be deleted, and the data value corresponding to S in the data is deleted. If there is a data identified by K as the data in the area to be deleted, the data with the largest time stamp is used to overwrite all the data. Describe the data marked with K in the area to be deleted. If server B determines that the data identified as K is less than the threshold during the life cycle of the data, it does not perform the move operation, and deletes all the data identified with K as the data in server B, similarly to server C The above process also needs to be completed.

在完成上述過程後,伺服器A中存在至少3條以K為資料標識的資料,所述伺服器A確定出時間戳記最大的資料後,將所述時間戳記最大的資料移動到待刪區,如果待刪區中存在以K為資料標識的資料,則用所述時間戳記最大的資料覆蓋所述資料區中以K為資料標識的資料。如果在所述資料的生命週期內伺服器A確定資料標識為K的資料小於所述閾值,則不執行移動操作,並刪除伺服器 A中以K為資料標識的所有資料。 After completing the above process, there are at least 3 pieces of data with K as the data identifier in server A. After the server A determines the data with the largest time stamp, it moves the data with the largest time stamp to the area to be deleted. If the data identified by K as the data exists in the area to be deleted, the data with the largest time stamp is used to cover the data identified by K as the data in the data area. If during the life cycle of the data server A determines that the data with the data identification K is less than the threshold, it does not perform the move operation and deletes the server All the data in A with K as the data mark.

如果伺服器A接收到用戶端發送的多條以K為資料標識的資料時,所述伺服器按照接收資料的順序同步資料。 If server A receives multiple pieces of data with K as the data identifier sent by the client, the server synchronizes the data in the order of receiving the data.

基於與上述方法同樣的申請構思,本發明提出了一種資料同步裝置,如圖6所示,所述資料同步裝置位於第一終端設備,應用於包括所述第一終端設備和多個第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述資料同步裝置包括:添加模組61,當所述第一終端設備接收到資料時,用於將接收到所述資料的時間戳記添加到所述資料中;發送模組62,用於將添加有所述時間戳記的所述資料發送給所述第二終端設備,並儲存添加有所述時間戳記的所述資料;接收模組63,用於接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,以使所述第一終端設備中的同步模組根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步。 Based on the same application concept as the above method, the present invention proposes a data synchronization device. As shown in FIG. 6, the data synchronization device is located in a first terminal device and is applied to include the first terminal device and multiple second terminals. In the system of equipment, wherein the time of the first terminal equipment and the second terminal equipment are synchronized, the data synchronization device includes: an adding module 61, when the first terminal equipment receives data, It is used to add the time stamp of the received data to the data; the sending module 62 is used to send the data added with the time stamp to the second terminal device, and store the added data. The data of the time stamp; the receiving module 63 is configured to receive the data fed back by the second terminal device according to the data with the time stamp added, so that the synchronization module in the first terminal device Synchronize data according to the data stored by itself and the data added with the time stamp and the feedback data.

所述第一終端設備和所述第二終端中相同的資料具有相同的資料標識;所述回饋的資料是所述第二終端設備根據具有相同所述資料標識的資料確定的時間戳記最大的資料。 The same data in the first terminal device and the second terminal have the same data ID; the feedback data is the data with the largest time stamp determined by the second terminal device based on the data with the same data ID .

所述同步模組具體用於:判斷具有相同所述資料標識的資料的數目之和是否大 於閾值;當大於所述閾值時,確定出具有相同所述資料標識的資料中最大時間戳記對應的資料;根據最大時間戳記對應的資料進行資料同步。 The synchronization module is specifically used to determine whether the sum of the numbers of data with the same data identifier is large When it is greater than the threshold value, determine the data corresponding to the largest time stamp among the data with the same data identifier; perform data synchronization according to the data corresponding to the largest time stamp.

所述添加模組還用於為儲存添加有所述時間戳記的所述資料設定生命週期;所述裝置還包括:刪除模組,當所述同步模組在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,用於刪除具有相同所述資料標識的資料。 The adding module is also used to set a life cycle for storing the data added with the time stamp; the device further includes: a deletion module, when the synchronization module determines that the data has the same When the sum of the number of the data identified by the data is not greater than the threshold value, it is used to delete the data with the same data identification.

具有相同所述資料標識的資料中還攜帶有同步類型;所述同步模組還具體用於:當最大時間戳記對應的資料中的所述同步類型是同步資料時,根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the synchronization module is also specifically used for: when the synchronization type in the data corresponding to the largest time stamp is synchronized data, according to the data corresponding to the largest time stamp Perform data synchronization; when the synchronization type in the data corresponding to the largest time stamp is to delete data synchronously, delete the data value in the data corresponding to the largest time stamp, and proceed according to the data corresponding to the largest time stamp of the deleted data value Data synchronization.

本發明中當第一終端設備接收到資料時,在所述資料中添加時間戳記並儲存,然後將添加有時間戳記的資料發送給第二終端設備,所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,並根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步,本發明在不借助第三方設備和選 舉發送資料設備的情況下實現了終端設備叢集的資料同步,降低了資料同步時的成本,並且叢集中的終端設備是根據自身得到的資料來進行同步,保證了資料同步時的可靠性。 In the present invention, when the first terminal device receives data, it adds a time stamp to the data and stores it, and then sends the data with the time stamp to the second terminal device, and the first terminal device receives the second terminal device. The terminal device performs data synchronization based on the data fed back by the data with the time stamp added, and the data is synchronized based on the data with the time stamp added and the feedback data stored by itself. The present invention does not rely on third-party equipment And choose In the case of sending data equipment, the data synchronization of the terminal equipment cluster is realized, which reduces the cost of data synchronization, and the terminal equipment in the cluster synchronizes according to the data obtained by itself, which ensures the reliability of data synchronization.

基於與上述方法同樣的申請構思,本發明還提出了一種資料同步裝置,具體如圖7所示,所述資料同步裝置位於第二終端設備,應用於包括第一終端設備和多個所述第二終端設備的系統中,其中,所述第一終端設備和所述第二終端設備的時間是同步的,所述資料同步裝置包括:接收模組71,用於接收所述第一終端設備發送的添加有時間戳記的資料和其他第二終端設備發送的根據所述添加有時間戳記的資料回饋的資料;同步模組72,用於根據添加有時間戳記的資料和所述回饋的資料進行資料同步;其中,所述時間戳記是所述第一終端設備根據接收到所述資料的時間確定的。 Based on the same application concept as the above method, the present invention also proposes a data synchronization device, specifically as shown in FIG. In the system of two terminal devices, wherein the time of the first terminal device and the second terminal device are synchronized, the data synchronization device includes: a receiving module 71, which is used to receive the data sent by the first terminal device The time-stamped data and the data sent by other second terminal equipment based on the time-stamped data feedback; the synchronization module 72 is used to perform data based on the time-stamped data and the feedback data Synchronization; wherein, the time stamp 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 ID; the feedback data is the largest time stamp determined by the other second terminal devices based on the data with the same data ID material.

所述同步模組具體用於:判斷具有相同所述資料標識的資料的數目之和是否大於閾值;當大於所述閾值時,確定出具有相同所述資料標識的 資料中最大時間戳記對應的資料;根據最大時間戳記對應的資料進行資料同步。 The synchronization module is specifically configured to: determine whether the sum of the number of data with the same data identifier is greater than a threshold; when it is greater than the threshold, determine whether the number of data with the same data identifier is greater than the threshold. The data corresponding to the largest time stamp in the data; data synchronization is performed based on the data corresponding to the largest time stamp.

所述添加有時間戳記的資料中攜帶有所述第一終端設備為所述資料設定生命週期;所述裝置還包括:刪除模組,當所述同步模組在所述生命週期內判斷出具有相同所述資料標識的資料的數目之和不大於所述閾值時,用於刪除具有相同所述資料標識的資料。 The time-stamped data carries the first terminal device to set a life cycle for the data; the device further includes a deletion module, when the synchronization module determines that it has When the sum of the number of materials with the same material identifier is not greater than the threshold, it is used to delete the materials with the same material identifier.

具有相同所述資料標識的資料中還攜帶有同步類型;所述同步模組還具體用於:當最大時間戳記對應的資料中的所述同步類型是同步資料時,根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的所述同步類型是同步刪除資料時,刪除最大時間戳記對應的資料中的資料值,並根據刪除所述資料值的最大時間戳記對應的資料進行資料同步。 The data with the same data identifier also carries a synchronization type; the synchronization module is also specifically used for: when the synchronization type in the data corresponding to the largest time stamp is synchronized data, according to the data corresponding to the largest time stamp Perform data synchronization; when the synchronization type in the data corresponding to the largest time stamp is to delete data synchronously, delete the data value in the data corresponding to the largest time stamp, and proceed according to the data corresponding to the largest time stamp of the deleted data value Data synchronization.

所述第二終端設備還包括:發送模組,在所述接收模組接收到所述第一終端設備發送的添加有時間戳記的資料後,用於將與所述添加有時間戳記的資料的所述資料標識相同的資料中時間戳記最大的資料發送給所述第一終端設備,以使所述第一終端設備根據所述時間戳記最大的資料進行資料同步。 The second terminal device further includes: a sending module, after the receiving module receives the time-stamped data sent by the first terminal device, it is used to compare the data with the time-stamped data Among the data with the same data identifier, the data with the largest time stamp is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest time stamp.

本發明中當第一終端設備接收到資料時,在所述資料中添加時間戳記並儲存,然後將添加有時間戳記的資料發 送給第二終端設備,所述第一終端設備接收所述第二終端設備根據添加有所述時間戳記的所述資料回饋的資料,並根據自身儲存的添加有所述時間戳記的所述資料和所述回饋的資料進行資料同步,本發明在不借助第三方設備和選舉發送資料設備的情況下實現了終端設備叢集的資料同步,降低了資料同步時的成本,並且叢集中的終端設備是根據自身得到的資料來進行同步,保證了資料同步時的可靠性。 In the present invention, when the first terminal device receives data, a time stamp is added to the data and stored, and then the data with the time stamp is sent Sent to the second terminal device, the first terminal device receives the data fed back by the second terminal device based on the data added with the time stamp, and based on the data stored by the first terminal device based on the data added with the time stamp By synchronizing the data with the feedback data, the present invention realizes the data synchronization of the terminal equipment cluster without the aid of third-party equipment and the election sending data equipment, reducing the cost of data synchronization, and the terminal equipment in the cluster is Synchronize according to the data obtained by itself, which ensures the reliability of data synchronization.

本領域普通技術人員可以理解:實現上述各方法實施例的全部或部分步驟可以透過程式指令相關的硬體來完成。前述的程式可以儲存於一電腦可讀取儲存介質中。該程式在執行時,執行包括上述各方法實施例的步驟;而前述的儲存介質包括:ROM、RAM、磁碟或者光碟等各種可以儲存程式碼的介質。 A person of ordinary skill in the art can understand that all or part of the steps in the above-mentioned method embodiments can be completed by programming related hardware. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or CD-ROM and other media that can store program codes.

以上所描述的裝置實施例僅僅是示意性的,其中作為分離元件說明的單元可以是或者也可以不是物理上分開的,作為單元顯示的元件可以是或者也可以不是物理單元,即可以位於一個地方,或者也可以分佈到至少兩個網路單元上。可以根據實際的需要選擇其中的部分或者全部模組來實現本實施例方案的目的。本領域普通技術人員在不付出創造性的勞動的情況下,即可以理解並實施。 The device embodiments described above are merely illustrative, where the units described as separate elements may or may not be physically separated, and the elements displayed as units may or may not be physical units, that is, they may be located in one place. , Or it can be distributed to at least two network units. Some or all of the modules may be selected according to actual needs to achieve the objectives of the solutions of the embodiments. Those of ordinary skill in the art can understand and implement without creative work.

最後應說明的是:以上各實施例僅用以說明本發明的技術方案,而非對其限制;儘管參照前述各實施例對本發明進行了詳細的說明,本領域的普通技術人員應當理解: 其依然可以對前述各實施例所記載的技術方案進行修改,或者對其中部分或者全部技術特徵進行等同替換;而這些修改或者替換,並不使相應技術方案的本質脫離本發明各實施例技術方案的範圍。 Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand: It is still possible to modify the technical solutions recorded in the foregoing embodiments, or equivalently replace some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the embodiments of the present invention Range.

Claims (18)

一種資料的同步方法,其特徵在於,該方法應用於包括第一終端設備和第二終端設備的系統中,其中,該第一終端設備和該第二終端設備的時間是同步的,該第二終端設備為多個,該方法包括:當第一終端設備接收到資料時,該第一終端設備將接收到該資料的時間戳記添加到該資料中;該第一終端設備將添加有該時間戳記的該資料發送給該第二終端設備,並儲存添加有該時間戳記的該資料;該第一終端設備接收該第二終端設備根據添加有該時間戳記的該資料回饋的資料,以使該第一終端設備根據自身儲存的添加有該時間戳記的該資料和該回饋的資料進行資料同步,其中,該第一終端設備和該第二終端中相同的資料具有相同的資料標識;其中,該回饋的資料是該第二終端設備根據具有相同該資料標識的資料確定的時間戳記最大的資料。 A data synchronization method, characterized in that the method is applied to a system including a first terminal device and a second terminal device, wherein the time of the first terminal device and the second terminal device are synchronized, and the second terminal device There are multiple terminal devices, and the method includes: when the first terminal device receives the data, the first terminal device adds the time stamp of the received data to the data; the first terminal device adds the time stamp Send the data to the second terminal device, and store the data with the time stamp; the first terminal device receives the data fed back by the second terminal device based on the data with the time stamp, so that the first terminal device A terminal device performs data synchronization according to the data stored with the time stamp and the feedback data, wherein the same data in the first terminal device and the second terminal have the same data identifier; wherein, the feedback The data is the data with the largest time stamp determined by the second terminal device according to the data with the same data identifier. 如請求項1所述方法,其中,該第一終端設備根據自身儲存的添加有該時間戳記的該資料和該回饋的資料進行資料同步,具體為:該第一終端設備判斷具有相同該資料標識的資料的數目之和是否大於閾值;當大於該閾值時,該第一終端設備確定出具有相同該資料標識的資料中最大時間戳記對應的資料; 該第一終端設備根據最大時間戳記對應的資料進行資料同步。 The method according to claim 1, wherein the first terminal device performs data synchronization according to the data added with the time stamp and the feedback data stored by itself, specifically: the first terminal device determines that it has the same data identifier Whether the sum of the number of data is greater than a threshold; when it is greater than the threshold, the first terminal device determines the data corresponding to the largest time stamp among the data with the same data identifier; The first terminal device performs data synchronization according to the data corresponding to the largest time stamp. 如請求項2所述方法,其中,該第一終端設備為儲存添加有該時間戳記的該資料設定生命週期,當該第一終端設備在該生命週期內判斷出具有相同該資料標識的資料的數目之和不大於該閾值時,該第一終端設備刪除具有相同該資料標識的資料。 The method according to claim 2, wherein the first terminal device sets a life cycle for storing the data with the time stamp added, and when the first terminal device determines that the data with the same data identifier is in the life cycle When the sum of the numbers is not greater than the threshold, the first terminal device deletes the data with the same data identifier. 如請求項3所述方法,其中,具有相同該資料標識的資料中還攜帶有同步類型;該第一終端設備根據最大時間戳記對應的資料進行資料同步,具體為:當最大時間戳記對應的資料中的該同步類型是同步資料時,該第一終端設備根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的該同步類型是同步刪除資料時,該第一終端刪除最大時間戳記對應的資料中的資料值,並根據刪除該資料值的最大時間戳記對應的資料進行資料同步。 For example, the method according to claim 3, wherein the data with the same data identifier also carries a synchronization type; the first terminal device performs data synchronization according to the data corresponding to the largest time stamp, specifically: when the data corresponding to the largest time stamp When the synchronization type in is synchronizing data, the first terminal device performs data synchronization according to the data corresponding to the largest time stamp; when the synchronization type in the data corresponding to the largest time stamp is synchronous deleting data, the first terminal deletes the largest The data value in the data corresponding to the time stamp, and the data is synchronized according to the data corresponding to the largest time stamp of the deleted data value. 一種資料同步裝置,其特徵在於,該資料同步裝置位於第一終端設備,應用於包括該第一終端設備和多個第二終端設備的系統中,其中,該第一終端設備和該第二終端設備的時間是同步的,該資料同步裝置包括:添加模組,當該第一終端設備接收到資料時,用於將接收到該資料的時間戳記添加到該資料中; 發送模組,用於將添加有該時間戳記的該資料發送給該第二終端設備,並儲存添加有該時間戳記的該資料;接收模組,用於接收該第二終端設備根據添加有該時間戳記的該資料回饋的資料,以使該第一終端設備中的同步模組根據自身儲存的添加有該時間戳記的該資料和該回饋的資料進行資料同步,其中,該第一終端設備和該第二終端中相同的資料具有相同的資料標識;其中,該回饋的資料是該第二終端設備根據具有相同該資料標識的資料確定的時間戳記最大的資料。 A data synchronization device is characterized in that 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 second terminal device The time of the device is synchronized, and the data synchronization device includes: an adding module, when the first terminal device receives the data, it is used to add the time stamp of the received data to the data; The sending module is used to send the data with the time stamp to the second terminal device, and to store the data with the time stamp; the receiving module is used to receive the second terminal device according to the addition of the time stamp. The data fed back by the time stamp, so that the synchronization module in the first terminal device synchronizes the data according to the data stored with the time stamp and the fed back data, wherein the first terminal device and The same data in the second terminal has the same data identifier; wherein, the feedback data is the data with the largest time stamp determined by the second terminal device according to the data with the same data identifier. 如請求項5所述的裝置,其中,該同步模組具體用於:判斷具有相同該資料標識的資料的數目之和是否大於閾值;當大於該閾值時,確定出具有相同該資料標識的資料中最大時間戳記對應的資料;根據最大時間戳記對應的資料進行資料同步。 The device according to claim 5, wherein the synchronization module is specifically configured to: determine whether the sum of the number of data with the same data identifier is greater than a threshold; when it is greater than the threshold, determine the data with the same data identifier Data corresponding to the largest time stamp in the middle; data synchronization is performed based on the data corresponding to the largest time stamp. 如請求項6所述的裝置,其中,該添加模組還用於為儲存添加有該時間戳記的該資料設定生命週期;該裝置還包括:刪除模組,當該同步模組在該生命週期內判斷出具有相同該資料標識的資料的數目之和不大於該閾值時,用於刪除具有相同該資料標識的資料。 The device according to claim 6, wherein the adding module is further used to set a life cycle for storing the data added with the time stamp; the device further includes: a deletion module, when the synchronization module is in the life cycle When it is judged that the sum of the number of materials with the same material identifier is not greater than the threshold, it is used to delete the materials with the same material identifier. 如請求項7所述的裝置,其中,具有相同該資料 標識的資料中還攜帶有同步類型;該同步模組還具體用於:當最大時間戳記對應的資料中的該同步類型是同步資料時,根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的該同步類型是同步刪除資料時,刪除最大時間戳記對應的資料中的資料值,並根據刪除該資料值的最大時間戳記對應的資料進行資料同步。 The device according to claim 7, wherein the data is the same The identified data also carries the synchronization type; the synchronization module is also specifically used for: when the synchronization type in the data corresponding to the maximum time stamp is synchronized data, data synchronization is performed according to the data corresponding to the maximum time stamp; when the maximum time When the synchronization type in the data corresponding to the stamp is to delete the data synchronously, the data value in the data corresponding to the largest time stamp is deleted, and the data is synchronized according to the data corresponding to the largest time stamp of the deleted data value. 一種資料同步方法,其特徵在於,該方法應用於包括第一終端設備和第二終端設備的系統中,其中,該第一終端設備和該第二終端設備的時間是同步的,該第二終端設備為多個,該方法包括:該第二終端設備接收該第一終端設備發送的添加有時間戳記的資料和其他第二終端設備發送的根據該添加有時間戳記的資料回饋的資料;該第二終端設備根據添加有時間戳記的資料和該回饋的資料進行資料同步;其中,該時間戳記是該第一終端設備根據接收到該資料的時間確定的,其中,該第一終端設備和該第二終端中相同的資料具有相同的資料標識;其中,該回饋的資料是其他該第二終端設備根據具有相同該資料標識的資料確定的時間戳記最大的資料。 A data synchronization method, characterized in that the method is applied to a system including a first terminal device and a second terminal device, wherein the time of the first terminal device and the second terminal device are synchronized, and the second terminal device There are multiple devices, and the method includes: the second terminal device receives the time-stamped data sent by the first terminal device and the data fed back based on the time-stamped data sent by other second terminal devices; The second terminal device synchronizes data according to the data added with a time stamp and the feedback data; wherein, the time stamp is determined by the first terminal device according to the time when the data is received, wherein the first terminal device and the first terminal device The same data in the two terminals has the same data identifier; wherein the feedback data is the data with the largest time stamp determined by the other second terminal equipment based on the data with the same data identifier. 如請求項9所述方法,其中,該第二終端設備根 據添加有時間戳記的資料和該回饋的資料進行資料同步,具體為:該第二終端設備判斷具有相同該資料標識的資料的數目之和是否大於閾值;當大於該閾值時,該第二終端設備確定出具有相同該資料標識的資料中最大時間戳記對應的資料;該第二終端設備根據最大時間戳記對應的資料進行資料同步。 The method according to claim 9, wherein the second terminal device roots Synchronizing data according to the time-stamped data and the feedback data is specifically: the second terminal device determines whether the sum of the number of data with the same data identifier is greater than a threshold; when it is greater than the threshold, the second terminal The device determines the data corresponding to the largest time stamp among the data with the same data identifier; the second terminal device performs data synchronization according to the data corresponding to the largest time stamp. 如請求項10所述方法,其中,該添加有時間戳記的資料中攜帶有該第一終端設備為該資料設定生命週期,當該第二終端設備在該生命週期內判斷出具有相同該資料標識的資料的數目之和不大於該閾值時,該第二終端設備刪除具有相同該資料標識的資料。 The method according to claim 10, wherein the time-stamped data carries the first terminal device to set a life cycle for the data, and when the second terminal device determines that it has the same data identifier during the life cycle When the sum of the number of data is not greater than the threshold, the second terminal device deletes the data with the same data identifier. 如請求項11所述方法,其中,具有相同該資料標識的資料中還攜帶有同步類型;該第二終端設備根據最大時間戳記對應的資料進行資料同步,具體為:當最大時間戳記對應的資料中的該同步類型是同步資料時,該第二終端設備根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的該同步類型是同步刪除資料時,該第二終端刪除最大時間戳記對應的資料中的資料值,並根據刪除該資料值的最大時間戳記對應的資料進行資料同步。 For example, the method according to claim 11, wherein the data with the same data identifier also carries a synchronization type; the second terminal device performs data synchronization according to the data corresponding to the largest time stamp, specifically: when the data corresponding to the largest time stamp When the synchronization type in is synchronizing data, the second terminal device performs data synchronization according to the data corresponding to the largest time stamp; when the synchronization type in the data corresponding to the largest time stamp is synchronous deleting data, the second terminal deletes the largest The data value in the data corresponding to the time stamp, and the data is synchronized according to the data corresponding to the largest time stamp of the deleted data value. 如請求項9所述方法,其中,在該第二終端設備接收到該第一終端設備發送的添加有時間戳記的資料後,該第二終端設備將與該添加有時間戳記的資料的該資料標識相同的資料中時間戳記最大的資料發送給該第一終端設備,以使該第一終端設備根據該時間戳記最大的資料進行資料同步。 The method according to claim 9, wherein, after the second terminal device receives the time-stamped data sent by the first terminal device, the second terminal device compares the data with the time-stamped data The data with the largest time stamp among the data with the same identification is sent to the first terminal device, so that the first terminal device performs data synchronization according to the data with the largest time stamp. 一種資料同步裝置,其特徵在於,該資料同步裝置位於第二終端設備,應用於包括第一終端設備和多個該第二終端設備的系統中,其中,該第一終端設備和該第二終端設備的時間是同步的,該資料同步裝置包括:接收模組,用於接收該第一終端設備發送的添加有時間戳記的資料和其他第二終端設備發送的根據該添加有時間戳記的資料回饋的資料;同步模組,用於根據添加有時間戳記的資料和該回饋的資料進行資料同步;其中,該時間戳記是該第一終端設備根據接收到該資料的時間確定的,其中,該第一終端設備和該第二終端中相同的資料具有相同的資料標識;其中,該回饋的資料是其他該第二終端設備根據具有相同該資料標識的資料確定的時間戳記最大的資料。 A data synchronization device, characterized in that 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 second terminal device The time of the device is synchronized, and the data synchronization device includes: a receiving module for receiving time-stamped data sent by the first terminal device and feedback based on the time-stamped data sent by other second terminal devices The data; synchronization module for data synchronization based on the data added with a time stamp and the feedback data; wherein, the time stamp is determined by the first terminal device according to the time when the data is received, wherein the first The same data in a terminal device and the second terminal have the same data identifier; wherein the feedback data is the data with the largest time stamp determined by other second terminal devices based on data with the same data identifier. 如請求項14所述的裝置,其中,該同步模組具體用於:判斷具有相同該資料標識的資料的數目之和是否大於 閾值;當大於該閾值時,確定出具有相同該資料標識的資料中最大時間戳記對應的資料;根據最大時間戳記對應的資料進行資料同步。 The device according to claim 14, wherein the synchronization module is specifically configured to: determine whether the sum of the number of data with the same data identifier is greater than Threshold; when it is greater than the threshold, determine the data corresponding to the largest time stamp among the data with the same data identifier; perform data synchronization based on the data corresponding to the largest time stamp. 如請求項15所述的裝置,其中,該添加有時間戳記的資料中攜帶有該第一終端設備為該資料設定生命週期;該裝置還包括:刪除模組,當該同步模組在該生命週期內判斷出具有相同該資料標識的資料的數目之和不大於該閾值時,用於刪除具有相同該資料標識的資料。 The device according to claim 15, wherein the time stamped data carries the first terminal device to set a life cycle for the data; the device further includes: a deletion module, when the synchronization module is in the life cycle When it is determined during the period that the sum of the number of materials with the same material identifier is not greater than the threshold, it is used to delete the materials with the same material identifier. 如請求項16所述的裝置,其中,具有相同該資料標識的資料中還攜帶有同步類型;該同步模組還具體用於:當最大時間戳記對應的資料中的該同步類型是同步資料時,根據最大時間戳記對應的資料進行資料同步;當最大時間戳記對應的資料中的該同步類型是同步刪除資料時,刪除最大時間戳記對應的資料中的資料值,並根據刪除該資料值的最大時間戳記對應的資料進行資料同步。 The device according to claim 16, wherein the data with the same data identifier also carries a synchronization type; the synchronization module is also specifically used for: when the synchronization type in the data corresponding to the largest time stamp is synchronized data , Synchronize data according to the data corresponding to the largest timestamp; when the synchronization type in the data corresponding to the largest timestamp is to delete data synchronously, delete the data value in the data corresponding to the largest timestamp, and delete the data value according to the largest The data corresponding to the time stamp is synchronized. 如請求項14所述的裝置,其中,該裝置還包括:發送模組,在該接收模組接收到該第一終端設備發送的添加有時間戳記的資料後,用於將與該添加有時間戳記 的資料的該資料標識相同的資料中時間戳記最大的資料發送給該第一終端設備,以使該第一終端設備根據該時間戳記最大的資料進行資料同步。 The device according to claim 14, wherein the device further comprises: a sending module, after the receiving module receives the time-stamped data sent by the first terminal device, it is used to compare the data with the time stamp. stamp Among the data with the same data identifier, the data with the largest time stamp is sent to the first terminal device, so that the first terminal device performs data synchronization based on the data with the largest time stamp.
TW106105351A 2016-03-25 2017-02-17 Data synchronization method and device TWI746516B (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 (2)

Publication Number Publication Date
TW201737107A TW201737107A (en) 2017-10-16
TWI746516B true TWI746516B (en) 2021-11-21

Family

ID=59899336

Family Applications (1)

Application Number Title Priority Date Filing Date
TW106105351A TWI746516B (en) 2016-03-25 2017-02-17 Data synchronization method and device

Country Status (3)

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

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR102500047B1 (en) * 2017-12-27 2023-02-14 광동 오포 모바일 텔레커뮤니케이션즈 코포레이션 리미티드 Information feedback method and device, computer storage medium
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 (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW200521695A (en) * 2003-12-17 2005-07-01 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
CN101808137A (en) * 2010-03-29 2010-08-18 成都市华为赛门铁克科技有限公司 Data transmission method, device and system
WO2011106394A2 (en) * 2010-02-23 2011-09-01 Fusion-Io, Inc. Apparatus, system, and method for data block usage information synchronization for a non-volatile storage volume
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

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102801543B (en) * 2011-05-24 2015-12-16 中国银联股份有限公司 A kind of method of dynamic data synchronization between dual-active system
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
CN104301428B (en) * 2014-10-29 2017-09-12 广州视源电子科技股份有限公司 A kind of method of data synchronization and server
CN104580183B (en) * 2014-12-27 2019-02-15 北京奇虎科技有限公司 A kind of method of data synchronization and device across cluster
CN105162843B (en) * 2015-08-05 2018-11-02 卡斯柯信号有限公司 A kind of rapid data synchronous method based on Dynamic Programming

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW200521695A (en) * 2003-12-17 2005-07-01 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
WO2011106394A2 (en) * 2010-02-23 2011-09-01 Fusion-Io, Inc. Apparatus, system, and method for data block usage information synchronization for a non-volatile storage volume
CN101808137A (en) * 2010-03-29 2010-08-18 成都市华为赛门铁克科技有限公司 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

Also Published As

Publication number Publication date
CN107231400A (en) 2017-10-03
TW201737107A (en) 2017-10-16
CN107231400B (en) 2020-07-03
WO2017162079A1 (en) 2017-09-28

Similar Documents

Publication Publication Date Title
TWI746516B (en) Data synchronization method and device
CN107332876B (en) Method and device for synchronizing block chain state
CN107465767B (en) Data synchronization method and system
CN108600353A (en) A kind of parallel block synchronization method of block chain node
CN103581231B (en) UGC master/slave data synchronous method and its system
CN106657174A (en) Data synchronizing and updating methods and data synchronizing and updating devices
CN104750738B (en) A kind of method for updating the data information, back end, management node and system
CN105933393A (en) Intra-local area network data synchronization method, device and user terminal
CN104954101B (en) Multiple terminals method of data synchronization based on synchronous ACK
CN110830539B (en) Network storage system and method
CN110636393B (en) Double-master-control 1+1 concurrent working method and system of OLT equipment
CN108599971A (en) Configuring information processing method, system, computer equipment and storage medium
US20110167040A1 (en) Method, apparatus and system for executing synchronization
CN108228397A (en) The method and apparatus that a kind of cluster span computer room synchronizes
US10972296B2 (en) Messaging to enforce operation serialization for consistency of a distributed data structure
CN108345617A (en) A kind of method of data synchronization, device and electronic equipment
CN109873857A (en) Mobile terminal method of data synchronization and device under a kind of no network state
CN113835369A (en) Edge terminal scene management method, device and system
CN103686300B (en) The synchronous method and system of business guide
CN102957546A (en) Method, device and system for processing configuration
CN110445657B (en) Distributed networking management system based on block chain
CN115146002A (en) Cross-data-center data synchronization method and device
CN105591892B (en) A kind of starting method and apparatus of smooth restarting process
CN111491020B (en) Data processing method, data processing device, computer equipment and storage medium
CN106488547B (en) STA authentication data management method, device and equipment