Data synchronization method, data synchronization device, access control system and storage medium

By using data fingerprint comparison and hierarchical hash tree verification methods, the problems of low accuracy and efficiency in data synchronization under master-slave architecture are solved, achieving high accuracy and high efficiency in data synchronization, which is suitable for multi-terminal systems.

CN121193758BActive Publication Date: 2026-03-24ZHEJIANG DAHUA TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-24
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

In a master-slave architecture, existing technologies suffer from low data synchronization accuracy and low efficiency. In particular, the data inconsistency caused by clock drift in timestamp synchronization methods and the inefficiency caused by the need for full table synchronization after each modification in full data MD5 digest comparison methods.

Method used

The method employs data fingerprint comparison and hierarchical hash tree verification. It generates synchronization instructions to compare device data table fingerprints, listens for change operations, divides data blocks to construct a hash tree, compares the hash values ​​of the root node and intermediate nodes, identifies the difference data blocks, and performs difference data synchronization.

Benefits of technology

It improves the accuracy and efficiency of data synchronization, quickly skips identical data through layered verification, reduces computation and time costs, and meets the synchronization needs of multi-terminal systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121193758B_ABST
    Figure CN121193758B_ABST
Patent Text Reader

Abstract

The application relates to a data synchronization method, a data synchronization device, an access control system and a storage medium. The method is applied to a multi-terminal system, the multi-terminal system comprises a first device and a second device, and the method comprises the following steps: generating a first synchronization instruction under the condition that the second device is online; in response to the first synchronization instruction, comparing whether a first table fingerprint of a data table of the first device and a second table fingerprint of a data table of the second device are consistent; under the condition that the first table fingerprint is consistent with the second table fingerprint, listening to and transmitting a change operation and / or change data in the first device to the second device; under the condition that the first table fingerprint is inconsistent with the second table fingerprint, determining a target data block with different hash values in the data table of the first device and the data table of the second device; taking the data table of the first device as a reference, synchronizing different data in the target data block to the second device. The method can meet the requirements of high accuracy and high efficiency of data synchronization under the master-slave architecture.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data management, and in particular to data synchronization methods, data synchronization devices, access control systems, and storage media. Background Technology

[0002] The master-slave architecture employs a one-master-multiple-slave device networking mode, with the master device responsible for data management and the slave devices performing synchronization. Data synchronization requirements under a master-slave architecture are common in scenarios such as IoT devices and embedded access control systems. For example, in a multi-terminal device scenario under a master-slave architecture, there is a need to maintain consistency of access control data such as personnel, cards, and fingerprints between the master and slave devices.

[0003] Traditional techniques often rely on timestamps or full data MD5 (Message-Digest Algorithm 5) hash comparisons to determine whether master-slave devices need synchronization. However, timestamp synchronization requires strict clock synchronization between master and slave devices. If the slave device's clock drifts, changes outside the specified time window may not be synchronized, leading to data inconsistency and low synchronization accuracy. With full data MD5 hash comparisons, the MD5 hash changes after each modification, requiring a full table synchronization every time the slave device re-enters the network, resulting in low accuracy and efficiency in master-slave architectures.

[0004] There is currently no effective solution to the problems of low accuracy and low efficiency in data synchronization under master-slave architecture in related technologies. Summary of the Invention

[0005] Therefore, it is necessary to provide a data synchronization method, data synchronization device, access control system, and storage medium that can achieve both high accuracy and high efficiency in master-slave architecture to address the aforementioned technical problems.

[0006] Firstly, this embodiment provides a data synchronization method applied to a multi-terminal system, the multi-terminal system including a first device and a second device, the method comprising:

[0007] When the second device comes online, a first synchronization instruction is generated;

[0008] In response to the first synchronization command, compare whether the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device are consistent;

[0009] If the first table fingerprint and the second table fingerprint are consistent, monitor and transmit the change operation and / or change data in the first device to the second device;

[0010] If the first table fingerprint and the second table fingerprint are inconsistent, a target data block with a different hash value is identified in the data table of the first device and the data table of the second device; based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

[0011] In some embodiments, when the first table fingerprint and the second table fingerprint are inconsistent, a target data block with a different hash value is identified between the data table of the first device and the data table of the second device; synchronizing the difference data in the target data block to the second device, based on the data table of the first device, includes:

[0012] If the first table fingerprint and the second table fingerprint are inconsistent, the data table of the first device and the data table of the second device are divided into data blocks of the first device and data blocks of the second device, respectively.

[0013] Construct a first hash tree corresponding to the data blocks of the first device and a second hash tree corresponding to the data blocks of the second device;

[0014] Compare the root hash value of the root node of the first hash tree of the data block in the first device with the root hash value of the root node of the second hash tree of the corresponding data block in the second device.

[0015] If the root hash value of the root node of the first hash tree is inconsistent with the root hash value of the root node of the second hash tree, the data block currently used for comparison is determined to be the target data block.

[0016] Compare the intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device, and obtain the difference data in the target data block based on the comparison result;

[0017] Based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

[0018] In some embodiments, comparing the intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device, and obtaining the difference data in the target data block based on the comparison result, includes:

[0019] Obtain the first row of data corresponding to the middle node of the first hash tree of the target data block, and the second row of data corresponding to the middle node of the second hash tree of the target data block;

[0020] Compare the row hash value of the first row of data with the row hash value of the second row of data to see if they are the same;

[0021] Based on the comparison results, the rows of data in the target data block that show differences are obtained, and these rows of data that show differences are taken as the difference data.

[0022] In some embodiments, monitoring and transmitting change data from the first device to the second device includes:

[0023] If the change operation in the first device is detected to be a single data operation;

[0024] Acquire and encapsulate the data that the first device changes in response to the change operation;

[0025] The encapsulated data is encrypted and transmitted to the second device.

[0026] In some embodiments, the step of monitoring and transmitting change operations from the first device to the second device includes:

[0027] If the change operation detected in the first device is not a single data operation;

[0028] The change operation is compressed into a structured query language;

[0029] The compressed structured query language is transmitted to the second device.

[0030] In some embodiments, after monitoring and transmitting changed data and / or change operations from the first device to the second device, the method further includes:

[0031] Generate a second synchronization instruction;

[0032] In response to the second synchronization command, compare whether the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device are consistent;

[0033] If the first table fingerprint is inconsistent with the second table fingerprint, then when transmitting the change data to the second device, the second device is driven to synchronize the change data again, and when transmitting the change operation to the second device, the change operation is added to the execution queue of the second device.

[0034] In some embodiments, after monitoring and transmitting changed data and / or change operations from the first device to the second device, the method further includes:

[0035] Determine whether the number of times the second device is driven to synchronize the changed data and / or the number of times the change operation is added to the execution queue of the second device has reached a preset number;

[0036] If the preset number of times is reached, a target data block with a different hash value is identified between the data table of the first device and the data table of the second device; based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

[0037] Secondly, this embodiment provides a data synchronization device applied to a multi-terminal system, the multi-terminal system including a first device and a second device, the device comprising:

[0038] The instruction generation module is used to generate a first synchronization instruction when the second device comes online;

[0039] The comparison module is used to compare the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device in response to the first synchronization command to see if they are consistent.

[0040] The first synchronization module is used to listen for and transmit change operations and / or change data in the first device to the second device when the first table fingerprint and the second table fingerprint are consistent.

[0041] The second synchronization module is used to determine the target data block whose hash value is different between the data table of the first device and the data table of the second device when the first table fingerprint and the second table fingerprint are inconsistent, and synchronize the difference data in the target data block to the second device based on the data table of the first device.

[0042] Thirdly, this embodiment provides an access control system, which includes a first device and a second device;

[0043] The first device is used to implement the data synchronization method described in the first aspect above when executing;

[0044] The second device is used to receive and synchronously process change operations and / or change data from the first device.

[0045] Fourthly, this embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data synchronization method described in the first aspect above.

[0046] The aforementioned data synchronization method, data synchronization device, access control system, and storage medium can dynamically synchronize and update the data of the first and second devices when the data is the same. When the data is different, the difference data that needs to be synchronized can be determined by a layered verification method. By quickly skipping the same data, the computational and time costs are reduced, meeting the synchronization requirements of multi-terminal systems and achieving the effect of high accuracy and high efficiency in data synchronization under master-slave architecture. Attached Figure Description

[0047] Figure 1 This is a diagram illustrating the application environment of a data synchronization method in one embodiment;

[0048] Figure 2 This is a flowchart illustrating a data synchronization method in one embodiment;

[0049] Figure 3 This is a schematic diagram of a hash tree in one embodiment;

[0050] Figure 4 This is a flowchart illustrating a synchronous startup method in one embodiment;

[0051] Figure 5 This is a flowchart illustrating the operation of a synchronization method in one embodiment;

[0052] Figure 6 This is a structural block diagram of a data synchronization device in one embodiment;

[0053] Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0054] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0055] The data synchronization method provided in this application embodiment can be applied to, for example... Figure 1The application environment shown includes a multi-terminal system comprising a first device 102 and at least one second device 104. The first device 102 and the second device 104 communicate with the server 106 via a network. The first device 102 and the second device 104 can also communicate directly with each other. A data storage system stores the data that the server 106 needs to process. The data storage system can be integrated onto the server 106 or located on a cloud or other network server. The data synchronization method of this embodiment synchronizes the data stored in the first device 102 and the second device 104. The first device 102 and the second device 104 can be, but are not limited to, various personal computers, laptops, smartphones, tablets, and IoT devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart vehicle devices, smart access control devices, etc. The server 106 can be implemented using a standalone server or a server cluster composed of multiple servers.

[0056] In one embodiment, such as Figure 2 As shown, a data synchronization method is provided, applied to a multi-terminal system, which includes a first device and a second device, and includes the following steps:

[0057] Step 202: If the second device is online, generate the first synchronization command.

[0058] When one or more second devices come online, the second devices need to obtain the latest data copy from the first device to ensure that the first data and the second data are synchronized.

[0059] Optionally, the first device and the second device are embedded devices in a master-slave architecture, with the first device being the master device and the second device being the slave device. The first device actively initiates and continuously checks whether the second device is online, and generates a first synchronization command when the first device determines that the second device is online.

[0060] Step 204: In response to the first synchronization command, compare whether the first table fingerprint of the data table of the first device is consistent with the second table fingerprint of the data table of the second device.

[0061] The data table for the first device is a hash digest table built from the data in the first device that needs to be synchronized with the second device. The fingerprint of the first table is the fingerprint of the independent hash digest table for the first device, which records the total number of data entries (count) and the overall hash value (total_hash) in the first device. The data table for the second device is a hash digest table built from the data in the second device that needs to be synchronized with the first device. The fingerprint of the second table is the fingerprint of the independent hash digest table for the second device, which records the total number of data entries (count) and the overall hash value (total_hash) in the second device.

[0062] The calculation methods for the first and second table fingerprints are the same. Optionally, the first table fingerprint of the data to be synchronized in the first device is calculated, and the second table fingerprint of the data to be synchronized in the second device is calculated. The first and second table fingerprints are calculated based on the following method: the table fingerprint equals the sum of the total number of entries (count) and the total hash value (total_hash) in the synchronized data. Wherein, the total hash value (total_hash) = SUM(row_hash)%large prime number, where row_hash is the row hash value, SUM() represents summation, large prime number is a preset value, and %large prime number represents modulo a preset large prime number, thus achieving table-level dual verification for the first and second devices.

[0063] Step 206: If the fingerprints in the first table and the fingerprints in the second table are consistent, listen for and transmit the change operation and / or change data in the first device to the second device.

[0064] Here, a change operation is an operation performed by the first device to change data. Changed data is data that changes in response to the change operation. Optionally, if the fingerprints of the first and second tables match, the second device is started and monitored. Upon detecting a change operation, the change operation from the first device can be directly sent to the second device, causing the second device to execute the change operation. Alternatively, the changed data in response to the change operation can be further obtained, and the changed data from the first device can be sent to the second device, causing the second device to synchronize the changed data. Alternatively, both the change operation and the changed data can be sent to the second device simultaneously.

[0065] Step 208: If the fingerprints in the first table and the second table are inconsistent, identify the target data block whose hash value is different between the data table of the first device and the data table of the second device; using the data table of the first device as a reference, synchronize the difference data in the target data block to the second device.

[0066] Data blocks are data partitioned based on a fixed size or data identifier. Optionally, when the data tables of the first and second devices record multiple personnel IDs, the data tables of the first and second devices are partitioned separately, such that every consecutive preset number of personnel IDs in the data tables forms a data block. For example, if the data table is partitioned by personnel ID, and 200 consecutive ID rows are taken as a data block, then the total number of blocks obtained is equal to the quotient of the total number of rows in the data table and the number of rows in each data block.

[0067] Optionally, a hash verification method is used to sequentially compare the hash values ​​of data blocks in the first device and the second device. If the hash values ​​are different, the data block is taken as the target data block; if the hash values ​​are the same, the data block can be skipped, and the next data block can be compared. In the target data block, the row data of the target data block in the first device is compared with the row data of the target data block in the second device. If the row data are different, the difference data is taken as the difference data.

[0068] Optionally, based on the difference data of the target data block in the first device, the difference data of the target data block in the second device is synchronized, including: sending the difference data of the target data block in the first device to the second device and replacing the corresponding difference data in the second device.

[0069] Optionally, after synchronizing the difference data in the target data block to the second device, the steps of listening for and transmitting change operations and / or change data in the first device to the second device can be performed.

[0070] The aforementioned data synchronization method performs table-level and block-level verification sequentially to identify discrepancies in target data blocks with different hash values. This layered, progressive verification mechanism improves accuracy while quickly skipping identical data, reducing computational and time costs. Furthermore, when data is identical, dynamic synchronization updates can be performed between the first and second devices; when data differs, static synchronization updates can be performed. This differentiated synchronization strategy meets the synchronization needs of multi-terminal systems, ensuring accuracy and achieving a balance between high accuracy and efficiency in master-slave architecture data synchronization.

[0071] In one embodiment, when the first table fingerprint and the second table fingerprint are inconsistent, determining the target data block whose hash values ​​differ between the data tables of the first device and the second device; and synchronizing the difference data in the target data block to the second device based on the data table of the first device includes: when the first table fingerprint and the second table fingerprint are inconsistent, dividing the data table of the first device and the data table of the second device to obtain data blocks of the first device and data blocks of the second device; constructing a first hash tree corresponding to the data block of the first device and a second hash tree corresponding to the data block of the second device; comparing whether the root hash value of the root node of the first hash tree of the data block in the first device is consistent with the root hash value of the root node of the second hash tree of the corresponding data block in the second device; when the root hash value of the root node of the first hash tree is inconsistent with the root hash value of the root node of the second hash tree, determining the current data block used for comparison as the target data block; comparing whether the intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device is consistent with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device, and obtaining the difference data in the target data block based on the comparison result; and synchronizing the difference data in the target data block to the second device based on the data table of the first device.

[0072] This process involves using a preset identifier in the data table, such as a personnel ID, as an index for each data row. Based on this index, the data tables of the first and second devices are partitioned, such that a predetermined number of consecutive data rows in both tables are divided into a data block, resulting in at least one data block corresponding to the first device and at least one data block corresponding to the second device. A hash tree (first hash tree) corresponding to each data block of the first device can be constructed, where the root hash value is the hash value of the root node and the intermediate hash values ​​are the hash values ​​of the intermediate nodes. Similarly, a hash tree (second hash tree) corresponding to each data block of the second device can be constructed, and the root hash value of the root node and the intermediate hash value of the intermediate nodes of the data blocks in the second device can be determined. Figure 3 This is a schematic diagram of a hash tree in this embodiment, as shown below. Figure 3 As shown, the hash tree includes leaf nodes Leaf1, Leaf2, Leaf3, and Leaf4; middle nodes Middle1 and Middle2, obtained by hashing the leaf nodes; and the root node Root, obtained by hashing the middle nodes. Each leaf node is a unique fingerprint of each row of data within a block; each middle node is both the parent of a leaf node and a child of the root node, used to verify the integrity of local data within the data block. The root node serves as proof of the integrity of the entire data block.

[0073] Optionally, data blocks in the first device and data blocks in the second device are traversed in a specified order, and the first hash tree of the corresponding data blocks in the first device and the second hash tree of the second device are compared. First, the root hash values ​​of the first hash tree and the corresponding second hash tree are compared for consistency, until all data blocks have been traversed. If the root hash value of the first hash tree of the data block in the first device is consistent with the root hash value of the second hash tree of the data block in the second device, the root hash values ​​of the next data block in the first device and the corresponding next data block in the second device are compared for consistency. If the root hash value of the first hash tree of the data block in the first device is inconsistent with the root hash value of the second hash tree of the data block in the second device, the intermediate nodes of the current first hash tree and the current intermediate nodes of the second hash tree are traversed in the same order, and the intermediate hash values ​​are compared for consistency, until all intermediate nodes have been traversed. If the intermediate hash value of the intermediate node of the first hash tree is consistent with the intermediate hash value of the corresponding intermediate node of the second hash tree, the intermediate hash values ​​of the next intermediate node of the first hash tree and the next intermediate node of the second hash tree can be compared. If the intermediate hash value of the intermediate node of the first hash tree is inconsistent with the intermediate hash value of the corresponding intermediate node of the second hash tree, it can be determined that the data rows corresponding to the multiple leaf nodes used to aggregate the intermediate node include the difference data.

[0074] In this embodiment, the entire data block is first verified to be synchronized through the root node, and then the local data in the data block corresponding to each intermediate node is verified to be synchronized through the intermediate nodes. The data block is then checked again in layers based on the constructed hash tree, which further improves the efficiency of data verification.

[0075] To improve the accuracy of the acquired difference data, optionally, comparing the intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device, and obtaining the difference data in the target data block based on the comparison result includes: obtaining the first row of data corresponding to the intermediate node of the first hash tree of the target data block, and the second row of data corresponding to the intermediate node of the second hash tree of the target data block; comparing the row hash value of the first row of data with the row hash value of the second row of data; obtaining the row data in the target data block that have differences based on the comparison result, and taking the row data that have differences as the difference data.

[0076] The first row of data corresponding to the intermediate node in the first hash tree includes: the first device data row used to aggregate multiple leaf nodes to obtain the intermediate node; similarly, the second row of data corresponding to the intermediate node in the second hash tree includes: the second device data row used to aggregate multiple leaf nodes to obtain the intermediate node.

[0077] Optionally, comparing the row hash value of the first row of data with the row hash value of the second row of data includes: obtaining the data table in the first device that needs to be synchronized with the second device, adding an extra `row_hash` field to the data table, and recording the CRC32 (Cyclic Redundancy Checksum 32-bit) value calculated based on the key fields in each data row based on the `row_hash` field; where the key fields are the data in the data row that needs to be monitored for changes; the key fields can be concatenated in a preset order. Based on the same principle, the CRC32 values ​​of each row of data in the data table in the second device that needs to be synchronized with the first device can be obtained. The CRC32 values ​​of the first row of data are then compared with the CRC32 values ​​of the second row of data. If they are inconsistent, the entire row of data is considered as the difference. In addition to calculating the CRC32 value, other data integrity verification algorithms, such as CRC16 and Adler-32 algorithms, can also be used.

[0078] In this embodiment, by comparing the row data corresponding to the intermediate nodes of the first device and the second device, the range of data to be compared is further narrowed. While accurately determining the data synchronization status of the first device and the second device, the difference data rows can be quickly located.

[0079] In one embodiment, listening to and transmitting changed data in the first device to the second device includes: when the change operation in the first device is detected to be a single data operation; acquiring and encapsulating the data changed by the first device in response to the change operation; and encrypting and transmitting the encapsulated data to the second device.

[0080] Single data operations include adding, deleting, modifying, and querying a single data entry in the first device's data table. Optionally, different change operations in the first device will have different external interfaces or parameters. Different interfaces or parameters can be used to determine whether a change operation in the first device is a single data operation; and a notification indicating that the change operation is a single data operation can be generated via an event or callback.

[0081] Optionally, the data responding to the change operation is encapsulated and transmitted to the second device via the first channel based on a pre-defined protocol. Because data synchronization between the first and second devices follows a specific protocol, after receiving the encapsulated data, the second device can parse the data based on the pre-defined protocol to obtain the operation type of the first device, and locate the data that needs to be updated according to the operation type, thereby achieving data synchronization.

[0082] In this embodiment, when the change operation is a single data operation, the content or size of the changed data is controllable. The changed data is obtained in response to the single data operation, and the encapsulated data is transmitted directly, which can improve the synchronization efficiency.

[0083] In one embodiment, listening to and transmitting a change operation in the first device to the second device includes: if the change operation in the first device is detected to be a non-single data operation; compressing the change operation into a structured query language; and transmitting the compressed structured query language to the second device.

[0084] Among these, non-single-row data operations refer to operations such as adding, deleting, modifying, and querying at least two data entries in the first device's data table. Non-single-row data operations can also be called batch data operations. Optionally, different interfaces or parameters can be used to determine whether a change operation on the first device is a non-single-row data operation; and a notification indicating that the change operation is a non-single-row data operation can be generated through events or callbacks.

[0085] Optionally, multiple data modification operations can be compressed into SQL (Structured Query Language) statements and transmitted to a second device via a second encrypted channel. Upon receiving the encapsulated data, the second device can decrypt the SQL statements to obtain the operation fields of the modification operations on the first device. Based on these operation fields, the specific information of the modification operations can be determined, including the specific data being modified and operations such as updating, deleting, and inserting data.

[0086] In this embodiment, when the change operation is not a single data operation, the content or size of the changed data is uncontrollable. Directly transmitting the change operation compressed into an SQL statement allows the second device to quickly identify the change operation, thereby improving the synchronization efficiency.

[0087] In one embodiment, after listening to and transmitting changed data and / or change operations in the first device to the second device, the method further includes: generating a second synchronization instruction; in response to the second synchronization instruction, comparing whether the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device are consistent; if the first table fingerprint and the second table fingerprint are inconsistent, then, in the case of transmitting changed data to the second device, driving the second device to synchronize the changed data again, and in the case of transmitting change operations to the second device, adding the change operations to the execution queue of the second device.

[0088] This involves either driving the second device to synchronize the changed data again, or adding the change operation to the second device's execution queue, allowing the second device to synchronize and execute the change operation performed in the first device. After performing synchronization based on the monitoring results, a synchronization verification is performed again using table fingerprints to verify whether the second device has synchronized successfully, thus improving the accuracy of data synchronization.

[0089] Furthermore, after monitoring and transmitting the changed data and / or change operations in the first device to the second device, the method further includes: determining whether the number of times the second device is driven to synchronize the changed data and / or the number of times the change operations are added to the execution queue of the second device has reached a preset number; if the preset number has been reached, then identifying the target data block whose hash value is different between the data table of the first device and the data table of the second device; and synchronizing the difference data in the target data block to the second device based on the data table of the first device.

[0090] Optionally, if a preset number of comparisons is reached, the root hash value of the data block in the data table of the first device is compared with the root hash value of the corresponding data block in the data table of the second device. If the root hash value of the data block in the first device is inconsistent with the root hash value of the corresponding data block in the second device, the data block currently used for comparison is determined as the target data block. The intermediate hash value of the intermediate node of the target data block in the first device is compared with the intermediate hash value of the intermediate node of the target data block in the second device, and the difference data in the target data block is obtained according to the comparison result. Based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

[0091] Optionally, if the number of times the second device is driven to synchronize and change data and / or the number of times the change operation is added to the execution queue of the second device reaches a preset number, a synchronization error warning can also be generated for the user.

[0092] In this embodiment, if the first device fails to synchronize multiple times, the synchronization logic can be re-executed based on the hierarchical verification method to form an autonomous closed loop of synchronization, verification, and repair, thereby reducing the probability of synchronization failure.

[0093] In one embodiment, a data synchronization method is applied to a multi-terminal access control system. This enables the synchronization of access control data for scenarios such as residential communities, office buildings, and campuses. The first device is the master device of the access control system, and the second device is the slave device.

[0094] Figure 4 This is a flowchart illustrating the synchronous startup method in this embodiment, as shown below. Figure 4 The following are included:

[0095] Step 401: The slave device (slave device) goes online.

[0096] Step 402: Initiate table fingerprint verification. Table fingerprint verification compares the first table fingerprint of the data table of the first device with the second table fingerprint of the data table of the second device to determine if they match. The data tables include, but are not limited to, personnel, fingerprint, and facial recognition permission information for each device.

[0097] Step 403: Determine if the table fingerprints match. If they match, proceed to step 404; otherwise, enter listening mode.

[0098] Step 404: Initiate block-level verification.

[0099] Step 405: Determine if block-level verification is consistent. In block-level verification, the master device obtains the root hash of the hash tree of the corresponding data block from both the master and slave devices. If the root hashes match, the verification passes, and block-level verification is performed on the next data block. If the root hashes do not match, the verification fails, and the middle hash of the hash tree of the corresponding data block from both the master and slave devices is compared. Specifically, when comparing the middle hashes, if they match, the middle hash of the next intermediate node on the master device is compared with the middle hash of the corresponding intermediate node on the slave device. If the middle hashes match, proceed to step 406.

[0100] Step 406: Initiate row-level verification. In the event of a mismatch between the middel hash and the row data corresponding to the middel hash, the row_hash is compared.

[0101] Step 407: Generate a difference report and synchronize the difference row data.

[0102] Figure 5 This is a flowchart illustrating the synchronization method in this embodiment, as shown below. Figure 5 As shown, it includes:

[0103] Step 501: The master device performs data change monitoring. After the master device starts normally and starts data monitoring, if a single data operation is detected, proceed to step 502; if a batch data operation is detected, proceed to step 505.

[0104] Step 502: Real-time encapsulation of the change data corresponding to a single data operation, and transmission of the encapsulated data through the real-time channel.

[0105] Step 503: The slave device performs data synchronization for the single real-time data encapsulated by the master device.

[0106] Step 504: Determine whether the slave device has successfully synchronized. If yes, the update point is confirmed to have been successfully updated; otherwise, immediately retry the synchronization operation and proceed to step 508. Here, the update point refers to updating the data that differs between the slave and master devices.

[0107] Step 505: Compress the batch data operation into an SQL package and transmit the SQL package through the batch channel.

[0108] Step 506: Decrypt the SQL package from the device and perform batch data operations.

[0109] Step 507: Determine whether the batch data operation was successfully executed by the slave device. If yes, the update site is confirmed to be successful; otherwise, add the batch data operation to the retry queue and execute step 508.

[0110] Step 508: If the retries for the current data or the operation reach the maximum retry count, record a failure log and trigger a synchronization exception warning. Furthermore, after generating the synchronization exception warning, MD5 secondary verification can also be triggered, i.e., based on... Figure 4 Data synchronization is achieved in the manner shown.

[0111] Optionally, if the update point is successfully determined, table fingerprint verification can be initiated to determine whether the data synchronization was successful. If table fingerprint verification fails, block-level and row-level verifications are performed to synchronize the data.

[0112] In this embodiment, differentiated synchronization of the master-slave system is achieved through layered hash verification and block comparison based on a lightweight algorithm. This systematically solves the technical defects of traditional synchronization methods in terms of verification efficiency, resource consumption, conflict probability, and operational adaptability, and meets the stringent requirements of embedded access control systems for real-time performance, low overhead, and high reliability.

[0113] Based on the same inventive concept, this application also provides a data synchronization device for implementing the data synchronization method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more data synchronization device embodiments provided below can be found in the limitations of the data synchronization method described above, and will not be repeated here.

[0114] In one embodiment, such as Figure 6 As shown, a data synchronization device is provided for use in a multi-terminal system, the multi-terminal system including a first device and a second device, the device comprising:

[0115] The instruction generation module is used to generate the first synchronization instruction when the second device comes online;

[0116] The comparison module is used to compare the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device in response to the first synchronization command.

[0117] The first synchronization module is used to listen for and transmit change operations and / or change data in the first device to the second device when the first table fingerprint and the second table fingerprint are consistent.

[0118] The second synchronization module is used to identify target data blocks with different hash values ​​in the data tables of the first and second devices when the fingerprints of the first and second tables are inconsistent, and to synchronize the difference data in the target data blocks to the second device based on the data table of the first device.

[0119] In one embodiment, when the first table fingerprint and the second table fingerprint are inconsistent, the second synchronization module determines the target data block whose hash value differs between the data table of the first device and the data table of the second device; synchronizing the differing data in the target data block to the second device, based on the data table of the first device, includes: when the first table fingerprint and the second table fingerprint are inconsistent, dividing the data table of the first device and the data table of the second device respectively to obtain the data block of the first device and the data block of the second device; constructing a first hash tree corresponding to the data block of the first device and a second hash tree corresponding to the data block of the second device; comparing the first hash value of the data block in the first device with the second hash tree. The root hash value of the root node of the hash tree is compared with the root hash value of the root node of the second hash tree of the corresponding data block in the second device. If the root hash value of the root node of the first hash tree is inconsistent with the root hash value of the root node of the second hash tree, the data block currently used for comparison is determined as the target data block. The intermediate hash values ​​of the intermediate nodes of the first hash tree of the target data block in the first device are compared with the intermediate hash values ​​of the intermediate nodes of the second hash tree of the target data block in the second device, and the difference data in the target data block is obtained according to the comparison result. Based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

[0120] Optionally, the second synchronization module compares the intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device, and obtains the difference data in the target data block based on the comparison result, including: obtaining the first row of data corresponding to the intermediate node of the first hash tree of the target data block, and the second row of data corresponding to the intermediate node of the second hash tree of the target data block; comparing the row hash value of the first row of data with the row hash value of the second row of data; obtaining the row data in the target data block that have differences based on the comparison result, and taking the row data that have differences as the difference data.

[0121] The second synchronization module compares the intermediate hash value of the target data block of the first device with the intermediate hash value of the target data block of the second device, and obtains the difference data in the target data block based on the comparison result, including: obtaining the first row of data corresponding to the intermediate node of the target data block in the first device, and the second row of data corresponding to the intermediate node of the target data block in the second device; comparing the row hash value of the first row of data with the row hash value of the second row of data; obtaining the row data with differences in the target data block based on the comparison result; and updating the corresponding row data in the second device based on the row data of the first device.

[0122] In one embodiment, the first synchronization module listens for and transmits changed data in the first device to the second device, which includes: when the change operation in the first device is detected to be a single data operation; acquiring and encapsulating the data changed by the first device in response to the change operation; and encrypting and transmitting the encapsulated data to the second device.

[0123] In one embodiment, the first synchronization module listens for and transmits change operations in the first device to the second device, including: when the change operation in the first device is detected to be a non-single data operation; compressing the change operation into a structured query language; and transmitting the compressed structured query language to the second device.

[0124] In one embodiment, after the first synchronization module of the data synchronization device listens for and transmits changed data and / or change operations in the first device to the second device, it is further configured to generate a second synchronization instruction; in response to the second synchronization instruction, it compares whether the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device are consistent; if the first table fingerprint and the second table fingerprint are inconsistent, then when the changed data is transmitted to the second device, it drives the second device to synchronize the changed data again, and when the change operation is transmitted to the second device, it adds the change operation to the execution queue of the second device.

[0125] Optionally, after monitoring and transmitting the changed data and / or change operations in the first device to the second device, the first synchronization module is further used to determine whether the number of times the second device is driven to synchronize the changed data and / or the number of times the change operations are added to the execution queue of the second device has reached a preset number; if the preset number is reached, the target data block with different hash values ​​in the data table of the first device and the data table of the second device is identified; and the difference data in the target data block is synchronized to the second device based on the data table of the first device.

[0126] Each module in the aforementioned data synchronization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the corresponding operations of each module.

[0127] In one embodiment, an access control system is provided, comprising a first device and a second device; wherein the first device is used to perform the steps implementing the methods described above. The second device is used to receive and synchronously process change operations and / or change data from the first device.

[0128] Optionally, the access control system can be equipped with multiple second devices. Optionally, the data tables in the first and second devices include entered identification information such as personnel, cards, and fingerprints.

[0129] In one embodiment, a computer device is provided, the internal structure of which can be shown as follows: Figure 7 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data tables that need to be synchronized. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a data synchronization method.

[0130] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0131] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0132] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.

[0133] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.

[0134] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0135] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0136] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A data synchronization method applied to a multi-terminal system, characterized in that, The multi-terminal system includes a first device and a second device, wherein the first device and the second device are embedded devices in a master-slave architecture, and the method includes: When the second device comes online, a first synchronization instruction is generated; In response to the first synchronization command, compare whether the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device are consistent; wherein, the table fingerprint is equal to the sum of the total number of data entries and the overall hash value in the synchronized data, where total_hash=SUM(row_hash)%large prime number, total_hash is the overall hash value, row_hash is the row hash value of the data, and large prime number is a preset value; If the first table fingerprint and the second table fingerprint are consistent, monitor and transmit the change operation and / or change data in the first device to the second device; if the change operation in the first device is detected as a single data operation, acquire and encapsulate the data changed by the first device in response to the change operation, encrypt the encapsulated data and transmit it to the second device; if the change operation in the first device is detected as not a single data operation, compress the change operation into a structured query language, and transmit the compressed structured query language to the second device. If the first table fingerprint and the second table fingerprint are inconsistent, a target data block with a different hash value is identified in the data table of the first device and the data table of the second device. Based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

2. The method according to claim 1, characterized in that, In the case where the first table fingerprint and the second table fingerprint are inconsistent, the target data block whose hash value is different between the data table of the first device and the data table of the second device is determined; Based on the data table of the first device, synchronizing the difference data in the target data block to the second device includes: If the first table fingerprint and the second table fingerprint are inconsistent, the data table of the first device and the data table of the second device are divided into data blocks of the first device and data blocks of the second device, respectively. Construct a first hash tree corresponding to the data blocks of the first device and a second hash tree corresponding to the data blocks of the second device; Compare the root hash value of the root node of the first hash tree of the data block in the first device with the root hash value of the root node of the second hash tree of the corresponding data block in the second device. If the root hash value of the root node of the first hash tree is inconsistent with the root hash value of the root node of the second hash tree, the data block currently used for comparison is determined to be the target data block. Compare the intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device, and obtain the difference data in the target data block based on the comparison result; Based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

3. The method according to claim 2, characterized in that, The intermediate hash value of the intermediate node of the first hash tree of the target data block in the first device is compared with the intermediate hash value of the intermediate node of the second hash tree of the target data block in the second device. Based on the comparison result, the difference data in the target data block includes: Obtain the first row of data corresponding to the middle node of the first hash tree of the target data block, and the second row of data corresponding to the middle node of the second hash tree of the target data block; Compare the row hash value of the first row of data with the row hash value of the second row of data to see if they are the same; Based on the comparison results, the rows of data in the target data block that show differences are obtained, and these rows of data that show differences are taken as the difference data.

4. The method according to any one of claim 1 or claim 3, characterized in that, After monitoring and transmitting changed data and / or change operations from the first device to the second device, the method further includes: Generate a second synchronization instruction; In response to the second synchronization command, compare whether the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device are consistent; If the first table fingerprint is inconsistent with the second table fingerprint, then when transmitting the change data to the second device, the second device is driven to synchronize the change data again, and when transmitting the change operation to the second device, the change operation is added to the execution queue of the second device.

5. The method according to claim 4, characterized in that, After monitoring and transmitting changed data and / or change operations from the first device to the second device, the method further includes: Determine whether the number of times the second device is driven to synchronize the changed data and / or the number of times the change operation is added to the execution queue of the second device has reached a preset number; If the preset number of times is reached, a target data block with a different hash value is identified between the data table of the first device and the data table of the second device; based on the data table of the first device, the difference data in the target data block is synchronized to the second device.

6. A data synchronization device, characterized in that, Applied to a multi-terminal system, the multi-terminal system including a first device and a second device, the first device and the second device being embedded devices in a master-slave architecture, the device comprising: The instruction generation module is used to generate a first synchronization instruction when the second device comes online; The comparison module is used to compare the first table fingerprint of the data table of the first device and the second table fingerprint of the data table of the second device in response to the first synchronization instruction. The table fingerprint is equal to the sum of the total number of data entries and the overall hash value in the synchronized data, where total_hash = SUM(row_hash)%large prime number, total_hash is the overall hash value, row_hash is the row hash value of the data, and large prime number is a preset value. The first synchronization module is configured to: when the first table fingerprint and the second table fingerprint are consistent, monitor and transmit change operations and / or change data in the first device to the second device; when the change operation in the first device is detected to be a single data operation, acquire and encapsulate the data changed by the first device in response to the change operation, encrypt the encapsulated data and transmit it to the second device; when the change operation in the first device is detected to be not a single data operation, compress the change operation into a structured query language, and transmit the compressed structured query language to the second device. The second synchronization module is used to determine the target data block whose hash value is different between the data table of the first device and the data table of the second device when the first table fingerprint and the second table fingerprint are inconsistent, and synchronize the difference data in the target data block to the second device based on the data table of the first device.

7. An access control system, characterized in that, The access control system includes a first device and a second device; wherein... The first device is used to perform the steps of the method according to any one of claims 1 to 5; The second device is used to receive and synchronously process change operations and / or change data from the first device.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data verification method, device and system

    CN114281793A

  • Master-slave storage data verification method and device, equipment and storage medium

    CN116975152A

  • Multi-node database disaster recovery backup system

    CN120162197A