Data synchronization method and system, electronic equipment and storage medium

By adopting a data synchronization method of version number detection and validity verification in a distributed system, the problems of data consistency and system stability between modules are solved, real-time synchronization and fault tolerance of data are achieved, and the robustness and security of the distributed system are improved.

CN120687523APending Publication Date: 2025-09-23CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510659339.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-21
Publication Date
2025-09-23

Smart Images

  • Figure CN120687523A_ABST
    Figure CN120687523A_ABST
Patent Text Reader

Abstract

The invention provides a data synchronization method and system, electronic equipment and a storage medium, and relates to the technical field of data synchronization, and the data synchronization method provided by the invention realizes data consistency update between modules through a version number comparison mechanism between each functional module and a shared memory. When the data version of a certain module is new, the data can be synchronized to the module with the older version or the shared memory, and the latest data can be synchronized in time by other modules through periodically detecting the version number of the data in the shared memory, so that all the modules in the system are ensured to use consistent and effective data all the time. The method has good real-time performance and fault tolerance, and the data consistency and safety of the distributed system can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data synchronization technology, and in particular to a data synchronization method, system, electronic device, and storage medium. Background Art

[0002] With the rapid development of automotive technology, the demand for intelligent and diverse functions is becoming increasingly prominent. The widespread application of intelligent technologies has led to more complex and intelligent functions within automotive modules, and closer collaboration between modules. However, while highly coupled integrated systems improve overall system performance, they also pose data security challenges: a failure in one module can have a cascading impact on the data of other modules, reducing the system's resilience to risk.

[0003] Existing data synchronization mechanisms often use centralized or tightly coupled management methods, making it difficult to ensure data consistency across modules while also balancing system stability and security. Especially with the growing demand for data sharing, achieving data synchronization across different modules has become a crucial issue for improving system robustness.

[0004] Therefore, this application proposes a new data synchronization method. Summary of the Invention

[0005] In view of the above problems, embodiments of the present application provide a data synchronization method, system, electronic device, and storage medium to overcome the above problems or at least partially solve the above problems.

[0006] In a first aspect of an embodiment of the present application, a data synchronization method is provided, which is applied to a distributed system, wherein the distributed system includes multiple functional modules and a shared memory communicatively connected to each functional module. The method includes: When a first functional module detects first data that needs to be synchronized, performing version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, the first functional module being any functional module among the multiple functional modules; If the detection result indicates that the version number of the first data is inconsistent with the version number of the backup data, synchronizing the data with the newer version number and its corresponding version number with the data with the older version number and its corresponding version number to obtain updated first data and / or updated backup data; The second functional module periodically detects the version number of the updated backup data in the shared memory, and when it is detected that the version number of the updated backup data is updated compared to the version number of the second data in the second functional module, the updated backup data and its corresponding version number are synchronized with the second data and its corresponding version number. The second functional module is any functional module among the multiple functional modules except the first functional module.

[0007] Optionally, before detecting the version number of the first data and the version number of the backup data, the method further includes: respectively detecting the validity of the first data and the validity of the backup data; If both the detection results of the first data and the detection results of the backup data are valid, proceeding to the step of detecting version numbers of the first data and the backup data; In the case that a detection result of either the first data or the backup data is invalid, the data with a detection result of valid is used as a reference to synchronously replace the data with a detection result of invalid.

[0008] Optionally, the method further includes: If the detection results of both the first data and the backup data are invalid, the validity of the backup data is cyclically detected N times within a preset time period, and the detection is stopped when the number of detections N reaches a preset threshold, where N is an integer greater than 1; When the backup data is detected as valid in any detection, the first data whose detection result is invalid is synchronously replaced by the backup data whose detection result is valid; In the case that no valid backup data is detected in N detections, the first functional module is formatted.

[0009] Optionally, before synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number, the method further includes: detecting the validity of the updated backup data; If the detection result of the updated backup data is valid, the step of synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number is performed.

[0010] Optionally, before performing the step of data synchronization, the method further includes: The functional module obtains the read and write permissions of the shared memory, and the functional module is configured as a first functional module or a second functional module; If the functional module successfully obtains the read and write permissions of the shared memory, a data synchronization step is performed, and after the data synchronization step is completed, the read and write permissions of the shared memory are released, the data synchronization step including: a data synchronization step between the first data and the backup data or a data synchronization step between the updated backup data and the second data; In the case that the functional module fails to obtain the read and write permissions of the shared memory, it enters a waiting state until the read and write permissions of the shared memory are available, and then re-executes the step of obtaining the read and write permissions of the shared memory.

[0011] Optionally, the validity check of the data to be checked is performed according to the following steps, where the data to be checked is configured as first data, second data, or backup data: Perform an XOR operation on any byte of the data to be detected and the current value of the preset register to obtain the XOR result; Performing an XOR operation on the obtained XOR result and a preset polynomial, shifting the preset register right by one position, and filling the highest bit with zero, repeating the above steps until all bytes of the data to be detected are processed, and obtaining the final value of the preset register; Performing an XOR operation on the final value of the preset register and the predefined initial value to obtain the actual detection value of the data to be detected; The actual detection value is compared with the preset detection value of the data to be detected to determine the validity of the data to be detected.

[0012] Optionally, the method further includes: When the first functional module synchronizes data with the shared memory, the second functional module reduces the detection frequency of periodic detection of the shared memory, and restores the detection frequency of periodic detection after the first functional module completes data synchronization with the shared memory.

[0013] In a second aspect of an embodiment of the present application, a data synchronization system is provided, the system comprising: a version number detection module, configured to, when a first functional module detects first data that needs to be synchronized, perform version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, wherein the first functional module is any functional module among the multiple functional modules; a first synchronization module configured to synchronize the data with a newer version number and its corresponding version number with the data with an older version number and its corresponding version number, if the detection result indicates that the version number of the first data is inconsistent with the version number of the backup data, to obtain updated first data and / or updated backup data; The second synchronization module is used for the second functional module to periodically detect the version number of the backup data in the shared memory. When it is detected that the version number of the backup data is updated compared with the version number of the second data in the second functional module, the backup data and its corresponding version number are synchronized with the second data and its corresponding version number. The second functional module is any functional module among the multiple functional modules except the first functional module.

[0014] Optionally, before detecting the version number of the first data and the version number of the backup data, the system further includes: A first detection submodule, configured to detect the validity of the first data and the validity of the backup data respectively; a second detection submodule, configured to, if both the detection results of the first data and the detection results of the backup data are valid, proceed to a step of detecting version numbers of the first data and the backup data; The first synchronous replacement submodule is configured to synchronously replace the data with a detection result of invalidity based on the data with a detection result of validity when a detection result of either the first data or the backup data is invalidity.

[0015] Optionally, the system further comprises: a cyclic detection submodule, configured to, when the detection results of both the first data and the backup data are invalid, cyclically detect the validity of the backup data N times within a preset time period, and stop detecting when the number of detections N reaches a preset threshold, where N is an integer greater than 1; a second synchronous replacement submodule, which, when the backup data is detected to be valid in any detection, synchronously replaces the first data whose detection result shows invalidity with the backup data whose detection result shows valid; The formatting submodule is configured to format the first functional module if no valid backup data is detected in N detections.

[0016] Optionally, the system further comprises: A third detection submodule, configured to detect the validity of the updated backup data; The first execution submodule is configured to, if the detection result of the updated backup data is valid, execute the step of synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number.

[0017] Optionally, the system further comprises: An acquisition submodule, configured for a functional module to acquire read and write permissions for the shared memory, the functional module being configured as a first functional module or a second functional module; a second execution submodule, configured to, if the functional module successfully obtains the read and write permissions of the shared memory, execute a data synchronization step, and release the read and write permissions of the shared memory after the data synchronization step is completed, wherein the data synchronization step includes: a data synchronization step between the first data and the backup data, or a data synchronization step between the updated backup data and the second data; The third execution submodule is used to enter a waiting state when the functional module fails to obtain the read and write permissions of the shared memory, and re-execute the step of obtaining the read and write permissions of the shared memory after the read and write permissions of the shared memory are available.

[0018] Optionally, the system further comprises: The first XOR submodule is used to perform an XOR operation on any byte of the data to be detected and the current value of the preset register to obtain an XOR result; a calculation submodule, configured to perform an XOR operation on the obtained XOR result and a preset polynomial, shift the preset register right by one bit, fill the highest bit with zero, and repeat the above steps until all bytes of the data to be detected are processed, thereby obtaining the final value of the preset register; A second XOR submodule is configured to perform an XOR operation on the final value of the preset register and a predefined initial value to obtain an actual detection value of the data to be detected; The comparison submodule is used to compare the actual detection value with the preset detection value of the data to be detected to determine the validity of the data to be detected.

[0019] Optionally, the system further comprises: The fourth detection submodule is used to reduce the detection frequency of periodic detection of the shared memory by the second functional module when the first functional module synchronizes data with the shared memory, and to restore the detection frequency of periodic detection after the first functional module completes data synchronization with the shared memory.

[0020] In a third aspect of an embodiment of the present application, an electronic device is provided, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the data synchronization method as described in the first aspect of the present application.

[0021] In a fourth aspect of an embodiment of the present application, a readable storage medium is provided, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the data synchronization method described in the first aspect of the present application are implemented.

[0022] Beneficial effects of this application: The present application provides a data synchronization method, which includes: first, when a first functional module detects first data that needs to be synchronized, performing version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, and the first functional module is any functional module among the multiple functional modules; then, when the detection result shows that the version number of the first data is inconsistent with the version number of the backup data, synchronizing the data with the newer version number and its corresponding version number with the data with the older version number and its corresponding version number to obtain updated first data and / or updated backup data; finally, the second functional module periodically detects the version number of the updated backup data in the shared memory, and when it is detected that the version number of the updated backup data is updated compared to the version number of the second data in the second functional module, synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number, and the second functional module is any functional module among the multiple functional modules except the first functional module.

[0023] The present application provides a data synchronization method for distributed systems, which realizes data consistency update between modules through the version number comparison mechanism between each functional module and the shared memory. When the data version of a module is newer, the data can be synchronized to the module or shared memory with an older version. Other modules periodically detect the version number of the data in the shared memory and synchronize the latest data in a timely manner to ensure that each module in the system always uses consistent and valid data. This method has good real-time performance and fault tolerance, and can effectively improve the data consistency and security of the distributed system. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0025] Figure 1 This is a flowchart of the steps of a data synchronization method provided in an embodiment of the present application; Figure 2 This is a structural block diagram of a distributed system provided by an embodiment of the present application; Figure 3 This is a flowchart of data synchronization between a functional module and a shared memory provided by an embodiment of the present application; Figure 4 This is a flowchart of data synchronization between functional modules in a distributed system provided by an embodiment of the present application; Figure 5 is a schematic diagram of a data synchronization system provided in an embodiment of the present application; Figure 6 This is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The exemplary embodiments of the present application will be described in more detail below in conjunction with the accompanying drawings in the embodiments of the present application. Although the accompanying drawings show exemplary embodiments of the present application, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.

[0027] In a first aspect of an embodiment of the present application, a data synchronization method is provided, which is applied to a distributed system, wherein the distributed system includes multiple functional modules and a shared memory connected to each functional module. Figure 1 As shown, including: Step S101, when a first functional module detects first data that needs to be synchronized, version number detection is performed on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, where the first functional module is any functional module among the multiple functional modules.

[0028] In step S101, when the first functional module detects the first data that needs to be synchronized, it compares the version number of the first data stored locally in the first functional module with the version number of the corresponding backup data in the shared memory. The version number is used to identify the order in which the data is updated and is usually recorded in the form of an incremental count or a timestamp. By comparing the two version numbers, it is possible to determine whether the data in the current module is the latest version, or whether the data in the shared memory has been updated by other modules, thereby providing a basis for subsequent data synchronization. This step is the basis for achieving data consistency among the functional modules in the distributed system, helping to avoid redundant write operations and improve synchronization efficiency.

[0029] Step S102, when the detection result shows that the version number of the first data is inconsistent with the version number of the backup data, the data with a newer version number and its corresponding version number are synchronized with the data with an older version number and its corresponding version number to obtain updated first data and / or updated backup data.

[0030] In step S102, when the detection result indicates that the version numbers of the first data in the first functional module and the backup data in the shared memory are inconsistent, the system will automatically compare the version numbers of the two and identify the data with the newer version. Subsequently, the data with the newer version number and its corresponding version number will be used to overwrite the data with the older version number to achieve synchronous updating of the data. Specifically, if the first data version of the first functional module is updated, the first data will be written to the shared memory; if the backup data version in the shared memory is updated, the backup data will be synchronized back to the first functional module. This process ensures that in a distributed system, each module always runs based on the latest data, thereby improving the data consistency and synchronization efficiency of the system.

[0031] Step S103, the second functional module periodically detects the version number of the updated backup data in the shared memory, and when it is detected that the version number of the updated backup data is updated compared to the version number of the second data in the second functional module, the updated backup data and its corresponding version number are synchronized with the second data and its corresponding version number. The second functional module is any functional module among the multiple functional modules except the first functional module.

[0032] In step S103, the second functional module will perform version number detection on the backup data in the shared memory at a set period to determine whether there is the latest data update from other functional modules. When it is detected that the version number of the data in the shared memory is higher than the second data version number currently stored locally by the second functional module, it means that an existing functional module has updated the backup data in the shared memory. At this time, the second functional module will synchronize the updated data in the shared memory and its corresponding version number to the local area to complete the data update and consistency maintenance. Through this periodic detection and automatic synchronization mechanism, it can be ensured that when multiple modules are powered on or switched in working state at different times, they can always obtain the latest and valid data in the system, thereby ensuring the data synchronization and stability of the distributed system.

[0033] The present application provides a data synchronization method for distributed systems, which realizes data consistency update between modules through the version number comparison mechanism between each functional module and the shared memory. When the data version of a module is newer, the data can be synchronized to the module or shared memory with an older version. Other modules periodically detect the version number of the data in the shared memory and synchronize the latest data in a timely manner to ensure that each module in the system always uses consistent and valid data. This method has good real-time performance and fault tolerance, and can effectively improve the data consistency and security of the distributed system.

[0034] Figure 2The present application provides a block diagram of a distributed system, wherein the distributed system is composed of multiple functional modules, each of which can operate independently and has specific functional logic. At the same time, a shared memory is provided in the system, which is connected to each functional module through a communication interface and is used to store and transfer data that needs to be synchronized between modules. Each module accesses the shared memory to achieve cross-module data interaction and version synchronization without the need to directly establish a data channel between modules, thereby reducing the system coupling and improving the flexibility and reliability of data synchronization. In the present application, the shared memory can be a non-volatile memory such as EEPROM memory or Flash memory.

[0035] In one embodiment, before detecting the version number of the first data and the version number of the backup data, the method further includes: respectively detecting the validity of the first data and the validity of the backup data; If both the detection results of the first data and the detection results of the backup data are valid, proceeding to the step of detecting version numbers of the first data and the backup data; In the case that a detection result of either the first data or the backup data is invalid, the data with a detection result of valid is used as a reference to synchronously replace the data with a detection result of invalid.

[0036] In this embodiment, to further enhance the reliability and data consistency of the data synchronization process in a distributed system, the system prioritizes the introduction of a data validity check mechanism before performing a version number comparison between the first data in the first functional module and the backup data in the shared memory. This check mechanism is designed to ensure the integrity of the data itself before the version comparison, thereby preventing system logic confusion or data overwriting errors caused by incorrect data participating in the synchronization process.

[0037] Specifically, the validity check can utilize a pre-defined integrity check algorithm, such as the CRC32 (32-bit cyclic redundancy check) algorithm, to perform bit-level checksum calculations on the data involved in synchronization. By sequentially inputting all bytes within a data block into a CRC register and performing a modulo-2 calculation based on a pre-defined polynomial, a checksum value (i.e., a CRC code) is generated. This value is highly robust against false positives. Even minor changes to the data content will significantly alter the CRC32 checksum, enabling rapid determination of data tampering or corruption during storage or transmission.

[0038] During the validation process, the system performs validity checks on the first data in the first functional module and the backup data in the shared memory. The system then compares the CRC32 values ​​of each data source with the stored checksum according to pre-set validation rules. If both data sources are determined to be valid, meaning the data is uncorrupted and available, the system proceeds to the next phase of the version number comparison process. Based on the data version, the system determines the newness or oldness of the data and decides whether to synchronize or replace it.

[0039] However, if the test results indicate that either the first data or the backup data is invalid, meaning that the data verification fails, the system skips the version number comparison step and directly uses the "valid" data as the basis for synchronizing the "invalid" data. This approach not only avoids the use of unreliable data, but also effectively improves data recovery capabilities in abnormal scenarios such as module power failure, abnormal write, and transmission interruption.

[0040] This embodiment not only enhances the system's data redundancy and error tolerance and operational stability, but also prevents invalid or abnormal data from participating in the decision-making process, thereby ensuring that data synchronization operations in the entire distributed system are always based on correct and secure data sources, effectively improving the system's robustness, security, and consistency assurance levels.

[0041] In one embodiment, when the detection results of both the first data and the backup data are invalid, the validity of the backup data is cyclically detected N times within a preset time period, and the detection is stopped when the number of detections N reaches a preset threshold, where N is an integer greater than 1; When the backup data is detected as valid in any detection, the first data whose detection result is invalid is synchronously replaced by the backup data whose detection result is valid; In the case that no valid backup data is detected in N detections, the first functional module is formatted.

[0042] In this embodiment, to enhance the data recovery capabilities of the distributed system under extreme abnormal circumstances, when both the local first data in the first functional module and the backup data in the shared memory are determined to be invalid after validity testing, the system does not immediately abandon the synchronization operation or enter the initial value recovery process. Instead, a fault-tolerant waiting recovery mechanism is set up. Specifically, the system performs a maximum of N validity recheck operations within a preset time window, where N is an integer greater than 1. That is, within this time period, the system cyclically reads and checks the backup data in the shared memory at a set detection frequency to determine whether other functional modules have completed the update and written valid data. In addition, when the number of detections N reaches a preset threshold, the detection will stop.

[0043] For example, if a functional module has just completed the power-on process after a system power outage and has not yet completed the data writing process, if other modules immediately determine that the data is unrecoverable, this may lead to misjudgment of previously available data and trigger unnecessary initialization. Therefore, by polling and checking multiple times in a short period of time, it is possible to wait for other modules to complete data recovery or synchronization, thereby improving the overall data consistency and fault tolerance of the system.

[0044] During the cyclic detection process, if the data in the shared memory is found to be valid during any test, the system uses this valid data as the synchronization basis to replace the invalid local data (i.e., the first data) in the current first functional module, completing data recovery and skipping subsequent detection and initialization processes. This strategy significantly enhances data recoverability in the event of abnormal power outages, asynchronous module power-up, or sudden abnormalities.

[0045] However, if no valid shared memory data is detected within the set N checks, meaning that the system determines that all backup data is still invalid, then there is no usable synchronized data in the current system. This could be due to extreme situations such as the vehicle being powered on for the first time, all modules having lost power and not yet recovered, or data area being damaged. In this case, the system will trigger the formatting process for the first functional module, restoring it to its initial factory configuration and rewriting the default data to ensure the normal operation of subsequent functional logic.

[0046] Through the above mechanism, this embodiment not only improves the system's perception of the asynchronous state of cross-module data and its waiting fault tolerance, but also ensures that safe rollback can be performed in the worst case scenario where no valid data is available, further enhancing the stability, reliability and robustness of the distributed system in practical applications.

[0047] In one embodiment, before synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number, the method further includes: detecting the validity of the updated backup data; If the detection result of the updated backup data is valid, the step of synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number is performed.

[0048] In this embodiment, to ensure the reliability and integrity of the data acquired by the second functional module before data synchronization, the validity of the updated backup data and its corresponding version number needs to be checked before synchronizing the updated backup data with the second data. This validity check can also use a preset checksum algorithm such as CRC32 to verify the integrity of the updated data read from the shared memory to determine whether it has been damaged or tampered with during the writing process.

[0049] Specifically, when the second functional module periodically detects the presence of updated data with a higher version number in the shared memory, it does not immediately perform synchronization. Instead, it prioritizes validating the updated data. Only when the validation result indicates that the data is valid, i.e., the data content is consistent with its stored checksum (e.g., CRC32), confirming that the data is not corrupted, does it proceed to synchronize the updated backup data and its version number with the local second data and its version number.

[0050] This embodiment effectively prevents the propagation of erroneous data due to data corruption in shared memory during the synchronization process, thereby improving the security and accuracy of data synchronization between modules in the system. Furthermore, by introducing validity checks before synchronization operations, the system's fault tolerance for abnormal scenarios is further enhanced, ensuring that the distributed system maintains data consistency and stable operation even in complex application environments.

[0051] In one embodiment, before performing the step of data synchronization, the method further includes: The functional module obtains the read and write permissions of the shared memory, and the functional module is configured as a first functional module or a second functional module; If the functional module successfully obtains the read and write permissions of the shared memory, a data synchronization step is performed, and after the data synchronization step is completed, the read and write permissions of the shared memory are released, the data synchronization step including: a data synchronization step between the first data and the backup data or a data synchronization step between the updated backup data and the second data; In the case that the functional module fails to obtain the read and write permissions of the shared memory, it enters a waiting state until the read and write permissions of the shared memory are available, and then re-executes the step of obtaining the read and write permissions of the shared memory.

[0052] In this embodiment, in order to avoid data contention, bus conflict or synchronization disorder caused by multiple functional modules accessing the shared memory at the same time, and to improve the data consistency and stability of the system, the method must go through a unified read and write permission control mechanism before performing any form of data synchronization operation (including data synchronization between the first functional module and the shared memory, and data synchronization from the shared memory to the second functional module).

[0053] Specifically, before performing data synchronization, each functional module must first request and obtain read and write permissions for shared memory from the system. This functional module can be a primary functional module (the one that actively initiates data updates) or a secondary functional module (the one that periodically checks and synchronizes updated data from shared memory). This permission acquisition process utilizes a mutual exclusion mechanism to ensure that only one module has access to shared memory at any given time, thus preventing data errors or synchronization failures caused by simultaneous read and write operations.

[0054] Only after successfully obtaining read and write permissions can the functional module perform specific data synchronization operations. After the synchronization operation is completed, the read and write permissions must be immediately released to allow other modules to continue accessing the shared memory, achieving reasonable scheduling and concurrency management of internal system resources. Data synchronization operations include, but are not limited to: writing the first data and version number to the backup area in the shared memory, or synchronizing updated data in the shared memory to the local data area of ​​the second functional module.

[0055] If a functional module fails to obtain shared memory read / write permissions (for example, because another functional module is already using the shared memory), the module enters a waiting state. During this waiting period, the module does not actively synchronize data. Instead, it periodically checks whether shared memory permissions have been released through a pre-defined detection mechanism. Once it detects that read / write permissions are available, the functional module will retry to obtain them and immediately proceed to the data synchronization step if successful.

[0056] This implementation effectively prevents data conflicts or synchronization anomalies caused by resource preemption while ensuring concurrent operation of the system, and further improves the security, synchronization and real-time performance of data interaction between multiple modules in the distributed system.

[0057] In one embodiment, the validity check of the data to be checked is performed according to the following steps, where the data to be checked is configured as first data, second data, or backup data: Perform an XOR operation on any byte of the data to be detected and the current value of the preset register to obtain the XOR result; Performing an XOR operation on the obtained XOR result and a preset polynomial, shifting the preset register right by one position, and filling the highest bit with zero, repeating the above steps until all bytes of the data to be detected are processed, and obtaining the final value of the preset register; Performing an XOR operation on the final value of the preset register and the predefined initial value to obtain the actual detection value of the data to be detected; The actual detection value is compared with the preset detection value of the data to be detected to determine the validity of the data to be detected.

[0058] In this embodiment, to ensure that the various types of data involved in data synchronization are not damaged during storage or transmission, the system performs a validity check on the data to be tested and uses an integrity check method based on the CRC32 algorithm. The data to be tested can be the first data, the second data, or the backup data in the shared memory. The specific steps of the validity check are as follows: First, the system performs an XOR operation on each byte of the data to be checked with the current value of a preset register to generate an intermediate XOR result. This preset register is usually assigned a fixed initial value (such as 0xFFFFFFFF) at the beginning and is used to store the temporary result during the CRC check process.

[0059] The system then XORs the resulting XOR result with a pre-set polynomial, shifts the pre-set register right by one position, and pads the highest bit with zeros. This process, typical of the CRC algorithm's shift update logic, efficiently extracts data features without burdening the system's computing resources. This calculation process continues until all bytes in the data to be tested have been processed.

[0060] After processing all data bytes, the value stored in the preset register is the intermediate checksum result of this processing. To obtain the final test value, the system performs an XOR operation on this intermediate checksum result and a predefined initial value (for example, 0xFFFFFFFF) to obtain the final actual test value, which is the calculated CRC32 checksum.

[0061] Finally, the system compares the calculated actual test value with the preset test value stored in the data to be tested. If the two are completely consistent, it means that the data has not been altered during storage, reading, or transmission, and is therefore considered valid. Otherwise, the data is considered to have been tampered with, destroyed, or abnormally modified, and is therefore invalid, requiring synchronization replacement or data recovery according to system settings.

[0062] Through the above validity detection process, not only can efficient verification of data integrity be achieved in a resource-constrained environment, but it can also ensure that subsequent data synchronization operations are only performed based on reliable data, thereby significantly enhancing the system's robustness, data security, and operational accuracy.

[0063] For example, the following Table 1 is a representation of the data to be detected:

[0064] As shown in Table 1, when judging the validity of data, the CRC32 check value (0x12345678) corresponding to sequence number 0 is read first. This is the check result calculated by the system based on the valid data segment when the data was last written.

[0065] Then, all the data in the data area from sequence number 2 to sequence number 33 is used as the data to be checked, and the check value is recalculated according to the preset CRC32 algorithm. The calculation process skips sequence number 0 (the original CRC32 value) and sequence number 1 (the version number), and only processes the actual business data.

[0066] After the checksum calculation is completed, the recalculated CRC32 value is compared with the original stored value in sequence number 0: If the two are completely consistent, it means that the current data has not been tampered with during storage or reading, and the data is valid; If the two are inconsistent, it means that the data integrity has been destroyed, there is a storage anomaly or illegal modification, and it is judged to be invalid data. The system can perform replacement, recovery or initialization operations according to the settings.

[0067] In one embodiment, when the first functional module synchronizes data with the shared memory, the second functional module reduces the detection frequency of periodic detection of the shared memory, and restores the detection frequency of periodic detection after the first functional module completes data synchronization with the shared memory.

[0068] In this embodiment, to further reduce the risk of access conflicts on the system bus and optimize the efficiency of shared memory usage, the system dynamically adjusts the access policy of the second functional module while the first functional module is performing data synchronization with the shared memory. Specifically, when the second functional module detects that the first functional module is performing a data synchronization operation with the shared memory, it proactively reduces the frequency of its periodic checks on the shared memory, extending its polling interval or suspending the next round of access requests. This reduces the preemption of shared resources and avoids read / write conflicts or communication interference during the first functional module's critical write operations.

[0069] This dynamic adjustment strategy is typically triggered by the system's scheduling mechanism or inter-module synchronization signals. For example, after successfully obtaining read and write permissions for the shared memory and starting a write operation, the first functional module can signal other modules that it is currently in the "writing" state. Upon receiving this status signal, the second functional module automatically enters a low-frequency detection mode or suspends access operations. After data synchronization is completed and the first module releases shared memory permissions, its detection frequency is restored to normal levels, and the periodic data version detection and synchronization logic are continued.

[0070] This mechanism not only improves operational stability and consistency during the critical data writing phase, but also effectively reduces system load and error probability caused by bus resource contention. At the same time, this solution maintains the second functional module's real-time responsiveness to data updates, quickly resuming normal testing after data synchronization is complete, ensuring data consistency and timely synchronization across modules within the system. Therefore, this strategy not only ensures system performance and reliability, but also enhances the data scheduling flexibility and operational security of the entire distributed system.

[0071] The present application provides a data synchronization method, the method comprising: first, when a first functional module detects the first data that needs to be synchronized, performing version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, the first functional module being any functional module among the multiple functional modules; then, when the detection result shows that the version number of the first data is inconsistent with the version number of the backup data, synchronizing the data with the newer version number and its corresponding version number with the data with the older version number and its corresponding version number to obtain the updated first data and / or updated backup data; finally, the second functional module periodically detects the version number of the updated backup data in the shared memory, and when it is detected that the version number of the updated backup data is updated compared to the version number of the second data in the second functional module, synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number, the second functional module being any functional module among the multiple functional modules except the first functional module. The present application provides a data synchronization method for a distributed system, which realizes data consistency update between modules through a version number comparison mechanism between each functional module and the shared memory. When a module's data version is newer, it can be synchronized to an older module or shared memory. Other modules periodically check the version number of the data in the shared memory and synchronize the latest data in a timely manner, ensuring that all modules in the system always use consistent and valid data. This method has excellent real-time performance and fault tolerance, and can effectively improve the data consistency and security of distributed systems.

[0072] In one embodiment, the present application provides a flow chart of data synchronization between a functional module and a shared memory, such as Figure 3 As shown in the figure, after the functional module is powered on, the complete process of realizing reliable data recovery and synchronization by judging the validity and version number of the local data of the functional module and the backup data in the shared memory is as follows: S1: Functional module is powered on and started; S2: The functional module starts self-testing to determine the validity of the local data stored in the module. If the CRC32 check of the local data is correct, the local data is valid and the process jumps to S3. If the CRC32 check of the local data fails, the local data is invalid and the process jumps to S4. S3: Read the backup data stored in the shared memory and determine the validity of the backup data in the shared memory. If the backup data in the shared memory is valid, jump to S5; if the backup data in the shared memory is invalid, update the local data to the shared memory and continue to return to the step of reading the backup data stored in the shared memory; S4: Enter the data recovery process: read the backup data in the shared memory, determine whether the backup data in the shared memory is valid, if the backup data in the shared memory is valid, write the backup data in the shared memory to the local; if the backup data in the shared memory is invalid, read the backup data in the shared memory after a delay (waiting for other modules to update the shared memory), if multiple read checks fail, format the functional module, write the initial value to the local storage of the functional module, and update it to the shared memory.

[0073] S5: Determine the version information of the data stored by both parties. If the version number of the backup data in the shared memory is higher than the version number of the local data of the functional module, jump to S6; if the version number of the backup data in the shared memory is consistent with the version number of the local data of the functional module, jump to S7; if the version number of the local data of the functional module is higher than the version number of the backup data in the shared memory, jump to S8: S6: updating the backup data in the shared memory to the local storage of the functional module, and returning to step 3 to read the backup data stored in the shared memory; S7: Periodically check the backup data in the shared memory, and return to S3 to read the backup data stored in the shared memory; S8: Update local data to the shared memory, and return to S3 to read the backup data stored in the shared memory; S9: If the functional module needs to update local data, the updated local data is first stored in the table, and then the process proceeds to S3 to read the backup data stored in the shared memory.

[0074] In one embodiment, the present application provides a flow chart of data synchronization between functional modules in a distributed system, such as Figure 4 As shown, The first functional module is powered on and starts and completes self-test. During operation, if the first data that needs to be synchronized is updated, the data synchronization process will be started, and the version numbers and validity of the first data and the backup data will be periodically checked.

[0075] Data synchronization process: The first functional module seizes the read and write permissions of the shared memory (to prevent bus errors caused by simultaneous updates by other modules). If no other modules are using it, the data synchronization process begins. First, the validity of the first data stored locally in the first functional module and the backup data stored in the shared memory are determined. If both are valid, the version numbers of both are determined, the new version of the data is synchronized with the old version of the data, and the data to be updated is then written sequentially to the local storage of the first functional module and the non-shared memory, completing a data update. If the validity is invalid during the verification process, the invalid data is synchronized with the data that successfully verified, and the process returns to the step of periodically checking the version numbers and validity of the first data and the backup data.

[0076] The second functional module is powered on and starts up and completes self-test, and periodically checks the version number and validity of the second data and the backup data; If it is found that other modules are in use during the process of seizing the read and write permissions of the shared memory, wait until the other modules have finished using it, and then synchronize the data after the shared memory is free. After completing the data synchronization between the second functional module and the shared memory, return to the step of periodically checking the version number and validity of the second data and the backup data.

[0077] Based on the same inventive concept, the second aspect of the embodiment of the present application provides a data synchronization system, such as Figure 5 As shown, the system includes: a version number detection module 201 configured to, when a first functional module detects first data that needs to be synchronized, perform version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, wherein the first functional module is any one of the multiple functional modules; A first synchronization module 202 is configured to synchronize the data with the newer version number and its corresponding version number with the data with the older version number and its corresponding version number, if the detection result indicates that the version number of the first data is inconsistent with the version number of the backup data, to obtain updated first data and / or updated backup data; The second synchronization module 203 is used for the second functional module to periodically detect the version number of the backup data in the shared memory. When it is detected that the version number of the backup data is updated compared with the version number of the second data in the second functional module, the backup data and its corresponding version number are synchronized with the second data and its corresponding version number. The second functional module is any functional module among the multiple functional modules except the first functional module.

[0078] Optionally, before detecting the version number of the first data and the version number of the backup data, the system further includes: A first detection submodule, configured to detect the validity of the first data and the validity of the backup data respectively; a second detection submodule, configured to, if both the detection results of the first data and the detection results of the backup data are valid, proceed to a step of detecting version numbers of the first data and the backup data; The first synchronous replacement submodule is configured to synchronously replace the data with a detection result of invalidity based on the data with a detection result of validity when a detection result of either the first data or the backup data is invalidity.

[0079] Optionally, the system further comprises: a cyclic detection submodule, configured to, when the detection results of both the first data and the backup data are invalid, cyclically detect the validity of the backup data N times within a preset time period, and stop detecting when the number of detections N reaches a preset threshold, where N is an integer greater than 1; a second synchronous replacement submodule, which, when the backup data is detected to be valid in any detection, synchronously replaces the first data whose detection result shows invalidity with the backup data whose detection result shows valid; The formatting submodule is configured to format the first functional module if no valid backup data is detected in N detections.

[0080] Optionally, the system further comprises: A third detection submodule, configured to detect the validity of the updated backup data; The first execution submodule is configured to, if the detection result of the updated backup data is valid, execute the step of synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number.

[0081] Optionally, the system further comprises: An acquisition submodule, configured for a functional module to acquire read and write permissions for the shared memory, the functional module being configured as a first functional module or a second functional module; a second execution submodule, configured to, if the functional module successfully obtains the read and write permissions of the shared memory, execute a data synchronization step, and release the read and write permissions of the shared memory after the data synchronization step is completed, wherein the data synchronization step includes: a data synchronization step between the first data and the backup data, or a data synchronization step between the updated backup data and the second data; The third execution submodule is used to enter a waiting state when the functional module fails to obtain the read and write permissions of the shared memory, and re-execute the step of obtaining the read and write permissions of the shared memory after the read and write permissions of the shared memory are available.

[0082] Optionally, the system further comprises: The first XOR submodule is used to perform an XOR operation on any byte of the data to be detected and the current value of the preset register to obtain an XOR result; a calculation submodule, configured to perform an XOR operation on the obtained XOR result and a preset polynomial, shift the preset register right by one bit, fill the highest bit with zero, and repeat the above steps until all bytes of the data to be detected are processed, thereby obtaining the final value of the preset register; A second XOR submodule is configured to perform an XOR operation on the final value of the preset register and a predefined initial value to obtain an actual detection value of the data to be detected; The comparison submodule is used to compare the actual detection value with the preset detection value of the data to be detected to determine the validity of the data to be detected.

[0083] Optionally, the system further comprises: The fourth detection submodule is used to reduce the detection frequency of periodic detection of the shared memory by the second functional module when the first functional module synchronizes data with the shared memory, and to restore the detection frequency of periodic detection after the first functional module completes data synchronization with the shared memory.

[0084] Based on the same inventive concept, the third aspect of the embodiment of the present application provides a Figure 6 The electronic device 100 shown includes a processor 120, a memory 110, and a program or instruction stored in the memory 110 and executable on the processor 120. When the program or instruction is executed by the processor 120, the steps of the data synchronization method described in the first aspect of the present application are implemented.

[0085] Based on the same inventive concept, the fourth aspect of the embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the data synchronization method described in the first aspect of the present application are implemented.

[0086] Each embodiment in this specification focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referenced to each other.

[0087] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0088] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0089] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0090] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0091] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0092] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.

[0093] The above is a detailed introduction to the provided data synchronization method, system, electronic device and storage medium. Specific examples are used in this article to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method of this application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on this application.

Claims

1. A data synchronization method, characterized in that: Applied to a distributed system, the distributed system includes multiple functional modules and a shared memory respectively connected to each functional module for communication, the method includes: When a first functional module detects first data that needs to be synchronized, performing version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, the first functional module being any functional module among the multiple functional modules; If the detection result indicates that the version number of the first data is inconsistent with the version number of the backup data, synchronizing the data with the newer version number and its corresponding version number with the data with the older version number and its corresponding version number to obtain updated first data and / or updated backup data; The second functional module periodically detects the version number of the updated backup data in the shared memory, and when it is detected that the version number of the updated backup data is updated compared to the version number of the second data in the second functional module, the updated backup data and its corresponding version number are synchronized with the second data and its corresponding version number. The second functional module is any functional module among the multiple functional modules except the first functional module.

2. The data synchronization method according to claim 1, characterized in that: Before detecting the version number of the first data and the version number of the backup data, the method further includes: respectively detecting the validity of the first data and the validity of the backup data; If both the detection results of the first data and the detection results of the backup data are valid, proceeding to the step of detecting version numbers of the first data and the backup data; In the case that a detection result of either the first data or the backup data is invalid, the data with a detection result of valid is used as a reference to synchronously replace the data with a detection result of invalid.

3. The data synchronization method according to claim 2, wherein: The method further comprises: If the detection results of both the first data and the backup data are invalid, the validity of the backup data is cyclically detected N times within a preset time period, and the detection is stopped when the number of detections N reaches a preset threshold, where N is an integer greater than 1; When the backup data is detected as valid in any detection, the first data whose detection result is invalid is synchronously replaced by the backup data whose detection result is valid; In the case that no valid backup data is detected in N detections, the first functional module is formatted.

4. The data synchronization method according to claim 1, wherein: Before synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number, the method further includes: detecting the validity of the updated backup data; If the detection result of the updated backup data is valid, the step of synchronizing the updated backup data and its corresponding version number with the second data and its corresponding version number is performed.

5. The data synchronization method according to claim 1, wherein: Before executing the step of data synchronization, the method further includes: The functional module obtains the read and write permissions of the shared memory, and the functional module is configured as a first functional module or a second functional module; If the functional module successfully obtains the read and write permissions of the shared memory, a data synchronization step is performed, and after the data synchronization step is completed, the read and write permissions of the shared memory are released, the data synchronization step including: a data synchronization step between the first data and the backup data or a data synchronization step between the updated backup data and the second data; In the case that the functional module fails to obtain the read and write permissions of the shared memory, it enters a waiting state until the read and write permissions of the shared memory are available, and then re-executes the step of obtaining the read and write permissions of the shared memory.

6. The data synchronization method according to any one of claims 1 to 5, characterized in that: The validity check of the data to be checked is performed according to the following steps, where the data to be checked is configured as first data, second data or backup data: Perform an XOR operation on any byte of the data to be detected and the current value of the preset register to obtain the XOR result; Performing an XOR operation on the obtained XOR result and a preset polynomial, shifting the preset register right by one position, and filling the highest bit with zero, repeating the above steps until all bytes of the data to be detected are processed, and obtaining the final value of the preset register; Performing an XOR operation on the final value of the preset register and the predefined initial value to obtain an actual detection value of the data to be detected; The actual detection value is compared with the preset detection value of the data to be detected to determine the validity of the data to be detected.

7. The data synchronization method according to claim 1, characterized in that: The method further comprises: When the first functional module synchronizes data with the shared memory, the second functional module reduces the detection frequency of periodic detection of the shared memory, and restores the detection frequency of periodic detection after the first functional module completes data synchronization with the shared memory.

8. A data synchronization system, characterized in that: The system comprises: a version number detection module, configured to, when a first functional module detects first data that needs to be synchronized, perform version number detection on the first data in the first functional module and the backup data in the shared memory to obtain a detection result, wherein the first functional module is any functional module among the multiple functional modules; a first synchronization module configured to synchronize the data with a newer version number and its corresponding version number with the data with an older version number and its corresponding version number, if the detection result indicates that the version number of the first data is inconsistent with the version number of the backup data, to obtain updated first data and / or updated backup data; The second synchronization module is used for the second functional module to periodically detect the version number of the backup data in the shared memory. When it is detected that the version number of the backup data is updated compared with the version number of the second data in the second functional module, the backup data and its corresponding version number are synchronized with the second data and its corresponding version number. The second functional module is any functional module among the multiple functional modules except the first functional module.

9. An electronic device, characterized in that: The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the data synchronization method according to any one of claims 1 to 7.

10. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the data synchronization method according to any one of claims 1 to 7 are implemented.