Data synchronization method and device, equipment and storage medium
By collecting data change information and combining strategies of immediate synchronization and asynchronous tasks, the problem of low data synchronization accuracy is solved, high accuracy and reliability of data synchronization is achieved, and the risk of data loss and delay is reduced.
Patent Information
- Application Number
- CN202411403695.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-02-11
AI Technical Summary
There are risks of data loss and delay in existing data synchronization technologies, resulting in low accuracy of data synchronization, affecting the accuracy of business decisions and system reliability.
A data synchronization method is proposed, including collecting data change information, trying to synchronize the data immediately, if it fails, it will be converted to an asynchronous task. If the asynchronous task fails, enable the data synchronization task that has not been successfully scanned until the data synchronization is successful or the pre-order is reached. Set the threshold for retry times.
Through the combination of immediate synchronization and asynchronous tasks, ensure the accuracy and reliability of data synchronization, reduce the risk of data loss and latency, and improve the overall performance and user experience of the system.
Smart Images

Figure CN119415594A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data synchronization method, device, equipment and storage medium. Background Art
[0002] As the distributed architecture of cloud environments becomes more and more popular, data synchronization across services and databases has become an indispensable part of modern information systems. This data synchronization mechanism is crucial to ensure the integrity, consistency and real-time performance of data.
[0003] At present, data loss and delay risks are common in the data synchronization process. Data loss may be caused by a variety of factors, including but not limited to network failure, hardware failure, software error or improper configuration, making it difficult to ensure the accuracy of data synchronization, which in turn affects the accuracy of business decisions, system reliability and user experience.
[0004] Therefore, how to improve the accuracy of data synchronization is a problem that needs to be solved urgently. Summary of the invention
[0005] The main purpose of this application is to provide a data synchronization method, device, equipment and storage medium, aiming to solve the technical problem of low data synchronization accuracy.
[0006] To achieve the above objectives, the present application proposes a data synchronization method, the method comprising:
[0007] Collecting data change information, and registering the data change information as a first data synchronization task;
[0008] When the online transaction is successfully committed, the data is attempted to be synchronized immediately;
[0009] If the immediate data synchronization fails, converting the first data synchronization task into a data asynchronous task;
[0010] If the data asynchronous task fails to execute, the backup scheduled task is enabled to scan the data synchronization task that failed, and a second data synchronization task is obtained;
[0011] Data synchronization is performed again based on the second data synchronization task until data synchronization succeeds or reaches a preset retry times threshold.
[0012] In one embodiment, the step of attempting to synchronize data immediately after the online transaction is successfully submitted includes:
[0013] When the online transaction is successfully submitted, the data is immediately synchronized by calling the target service;
[0014] A preset duration is set for the target service, and the preset duration is used to prevent the source service thread from being occupied for a long time due to waiting for a response from the target service.
[0015] In one embodiment, if the immediate data synchronization fails, the step of converting the first data synchronization task into a data asynchronous task includes:
[0016] If the immediate data synchronization fails, the first data synchronization task is registered in the asynchronous task queue to obtain a data asynchronous task, and the data asynchronous task is managed and executed by the asynchronous thread pool;
[0017] The data asynchronous task is scheduled for execution according to a preset task scheduling strategy, and the task scheduling strategy ensures that the data synchronization task is asynchronously executed in the background.
[0018] In one embodiment, the step of scheduling the execution of the data asynchronous task according to a preset task scheduling strategy, wherein the task scheduling strategy ensures that the data synchronization task is asynchronously executed in the background, includes:
[0019] The record lock operation is performed on the data asynchronous task through the database record lock. The database record lock mechanism ensures that each task is exclusively occupied by a single thread when the tasks are executed concurrently.
[0020] After the asynchronous task is completed, the task status is updated and the database record lock is released.
[0021] In one embodiment, after the step of performing data synchronization again based on the second data synchronization task until data synchronization succeeds or reaches a preset retry count threshold, the method includes:
[0022] Acquire key business data, perform sampling verification on the key business data, and obtain a first verification result;
[0023] Acquire the full amount of business data, and perform a full verification on the full amount of business data to obtain a second verification result;
[0024] Based on the first verification result and the second verification result, the data synchronization process is dynamically verified and abnormal monitoring and alarm are issued.
[0025] In one embodiment, the step of acquiring key business data, performing sampling verification on the key business data, and obtaining a first verification result includes:
[0026] Extract sample data of key business types within a specified time interval from the backup storage service of the source data service;
[0027] Based on the sample data, batch query corresponding data in the target data service by data key value matching;
[0028] Compare the consistency of the bilateral sample data of the source data and the target data to obtain a first verification result. In one embodiment, the step of obtaining the full amount of business data, performing a full verification on the full amount of business data, and obtaining a second verification result includes:
[0029] Obtain full business data during off-peak hours or system daily transition periods;
[0030] Splitting the full amount of business data according to a preset dimension to obtain a verification batch data set, wherein the splitting of the full amount of business data according to the preset dimension is used to ensure that the amount of data for a single verification is controllable;
[0031] Based on the batch data extracted from the source data service, batch retrieve the corresponding data in the target data service through the data key value;
[0032] The batch data of the source data and the target data are compared one by one for consistency to obtain a second verification result.
[0033] In addition, to achieve the above purpose, the present application also proposes a data synchronization device, the data synchronization device comprising:
[0034] A data acquisition module, used for acquiring data change information and registering the data change information as a first data synchronization task;
[0035] The immediate synchronization module is used to attempt to synchronize data immediately after the online transaction is successfully submitted;
[0036] A task conversion module, used for converting the first data synchronization task into a data asynchronous task if the immediate data synchronization fails;
[0037] A task scanning module, used for, if the data asynchronous task fails to execute, starting the data synchronization task that failed to scan the backup scheduled task, to obtain a second data synchronization task;
[0038] The task retry module is used to perform data synchronization again based on the second data synchronization task until the data synchronization succeeds or reaches a preset retry number threshold.
[0039] In addition, to achieve the above objectives, the present application also proposes a data synchronization device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data synchronization method described above.
[0040] In addition, to achieve the above objectives, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the data synchronization method described above are implemented.
[0041] One or more technical solutions proposed in this application have at least the following technical effects:
[0042] Collect data change information and register the data change information as the first data synchronization task. When the online transaction is successfully submitted, try to synchronize the data immediately. If the immediate data synchronization fails, convert the first data synchronization task to a data asynchronous task. If the data asynchronous task fails to execute, enable the backup scheduled task to scan the unsuccessful data synchronization tasks to obtain the second data synchronization task. Perform data synchronization again based on the second data synchronization task until the data synchronization succeeds or reaches the preset retry threshold. Use database records to persist data synchronization tasks to the database, and use scheduled jobs to continuously execute unsuccessful data synchronization tasks to ensure the consistency of the execution of data synchronization tasks and the results of online transaction processing, and ensure the correctness of data synchronization through an effective data verification mechanism. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0045] Figure 1 This is a flowchart of the first embodiment of the data synchronization method of the present application;
[0046] Figure 2 This is a flow chart of the second embodiment of the data synchronization method of the present application;
[0047] Figure 3 This is a flowchart of the third embodiment of the data synchronization method of the present application;
[0048] Figure 4 This is a schematic diagram of the overall process of cross-service data synchronization in an embodiment of the present application;
[0049] Figure 5 This is a schematic diagram of a batch check process of data from multiple data sources according to an embodiment of the present application;
[0050] Figure 6 This is a schematic diagram of the module structure of the data synchronization device according to an embodiment of the present application;
[0051] Figure 7 A schematic diagram of the device structure of the hardware operating environment involved in the data synchronization method in the embodiment of the present application.
[0052] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0054] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0055] Due to the distributed architecture of the cloud environment, cross-service and cross-database data synchronization is inevitable. Message queues (MQ) and distributed messaging systems such as Kafka are usually used as middleware for cross-service data synchronization. The basic principle of message transmission and communication of message queues is that the producer sends messages to the specified queue, while the consumer listens to the queue and receives messages from the queue for processing. In order to ensure the reliability of message transmission, a master-copy strategy is usually adopted, that is, the master node (leader) is copied to multiple replica nodes (followers). When the master node fails, a new master node will be elected from the replica nodes to take over the message transmission service, thereby realizing automatic transfer of services. This requires the cooperation of multiple parameters such as the number of replicas, reliability level, and sending mode to maximize the reliability and consistency of message transmission.
[0056] At present, the use of distributed message queues for cross-service message transmission has the following problems: when the message queue is unavailable, there is a risk of data loss, and even the throughput of the system may be affected. Secondly, the parameter configuration of the message queue is relatively complex, and improper configuration will also lead to the loss of message queue data. At the same time, in order to solve the problem of data loss, the master-copy strategy is adopted, and a reliable waiting confirmation mechanism is required between the master and the copy, thereby increasing the possibility of data synchronization delay. In order to improve the performance of online business processing, cross-database and cross-service data synchronization actions are usually converted to asynchronous processing. Asynchronous execution and online transactions need to be highly consistent. When the online transaction fails and rolls back, an effective mechanism is required to ensure that the asynchronous task is not executed; when the same record is updated multiple times instantaneously, there is a problem of how to be compatible with versions of different data states in concurrent synchronization. When data synchronization is abnormal, whether there is data loss or inconsistency, there is no auxiliary tool for large-scale data verification, and it is necessary to rely on manual analysis and investigation of large amounts of data.
[0057] The present application provides a solution to collect data change information and register the data change information as a first data synchronization task. When the online transaction is successfully submitted, the data is attempted to be synchronized immediately. If the immediate data synchronization fails, the first data synchronization task is converted to a data asynchronous task. If the data asynchronous task fails to execute, a backup scheduled task is enabled to scan the unsuccessful data synchronization tasks to obtain a second data synchronization task. Data synchronization is performed again based on the second data synchronization task until the data synchronization is successful or the preset retry count threshold is reached. Based on the preset retry count threshold, the system can adjust the retry strategy according to different scenarios, use database records to persist the data synchronization tasks to the database, and use scheduled jobs to continuously execute unsuccessful data synchronization tasks to ensure the consistency of the execution of the data synchronization tasks with the online transaction processing results, and ensure the correctness of data synchronization through an effective data verification mechanism.
[0058] Based on this, the present application embodiment provides a data synchronization method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the data synchronization method of the present application.
[0059] In this embodiment, the data synchronization method includes steps S10 to S50:
[0060] Step S10: Collect data change information and register the data change information as a first data synchronization task.
[0061] It should be noted that data change information can be understood as relevant information about data changes in a database or system, such as addition, update or deletion operations, and is usually used to record which data needs to be synchronized to other systems or databases. The first data synchronization task is a specific task of synchronizing data change information from one system or database to another system or database.
[0062] Step S20: After the online transaction is successfully submitted, attempt to synchronize the data immediately.
[0063] It should be noted that online transactions are transaction operations processed in real time in a database or system, and are usually used to handle high-frequency data operations to ensure data integrity and consistency. Typical characteristics of online transactions include atomicity, consistency, isolation, and durability, namely ACID characteristics. When a transaction is successfully submitted, it means that the data modifications involved in the transaction have been permanently saved to the database. Immediate data synchronization means that after an online transaction is successfully submitted, it immediately attempts to synchronize the changed data to other systems or databases.
[0064] Step S30: If the immediate data synchronization fails, the first data synchronization task is converted into a data asynchronous task.
[0065] It should be noted that the data asynchronous task is a data synchronization task executed asynchronously without blocking the current operation. For example, the system does not wait for the result of data synchronization, but records the task first, and performs data synchronization later or in the background.
[0066] Step S40: If the data asynchronous task fails to execute, the backup scheduled task is enabled to scan the data synchronization task that failed to succeed, and a second data synchronization task is obtained.
[0067] It should be noted that the fallback scheduled task can be understood as a fault tolerance mechanism that regularly scans unsuccessful data synchronization tasks in the system. At preset time intervals, the system regularly checks those tasks that have not been completed due to synchronization failures and attempts to synchronize again to ensure the final consistency of the data. The second data synchronization task is the new data synchronization task obtained after the asynchronous task fails to execute and the fallback scheduled task scans.
[0068] Exemplarily, step S40 may include: if the data asynchronous task fails to execute, starting a backup timing task according to a preset time interval; based on the backup timing task, scanning the unsuccessful data synchronization tasks to obtain a list of pending tasks; based on the list of pending tasks, locking the tasks in the pending task list through a database record lock; if the locking is successful, based on the backup timing task, skipping the successfully locked tasks; if the locking fails, based on the backup timing task, obtaining a second data synchronization task.
[0069] Exemplarily, the preset time interval can be the time interval at which the system periodically checks unsuccessful tasks in the catch-all scheduled task. For example, the system scans unsuccessful synchronization tasks every 5 minutes for reprocessing. The list of pending tasks can be scanned by the system to find tasks that have not been processed due to synchronization failure or other reasons. The database record lock can be part of the database concurrency control mechanism, which is used to ensure that only one task or one process can operate a record at the same time. By locking, multiple tasks are prevented from processing the same data at the same time, ensuring the correctness and consistency of task processing.
[0070] Step S50: Perform data synchronization again based on the second data synchronization task until the data synchronization succeeds or reaches a preset retry count threshold.
[0071] It should be noted that the preset retry number threshold may be the maximum retry number allowed by the system during the task retry process.
[0072] In this embodiment, data change information is collected and registered as the first data synchronization task. When the online transaction is successfully submitted, the data is attempted to be synchronized immediately. If the data synchronization fails immediately, the first data synchronization task is converted to a data asynchronous task. If the data asynchronous task fails to execute, the backup scheduled task is enabled to scan the unsuccessful data synchronization task to obtain the second data synchronization task. Data synchronization is performed again based on the second data synchronization task until the data synchronization succeeds or reaches the preset retry number threshold. By attempting to synchronize data immediately after the online transaction is successfully submitted, the lag caused by data asynchrony can be minimized and the consistency and real-time performance of system data can be improved. When the data synchronization fails immediately, the system will automatically convert the task to asynchronous execution to ensure that the data synchronization task will not be lost even if the real-time synchronization fails. By enabling the scheduled task to scan and retry the unsuccessful data synchronization task, it is ensured that even if the asynchronous task fails to execute, there is still a mechanism to synchronize the data again, reducing the risk of data loss or synchronization failure. Based on the preset retry number threshold, the system can adjust the retry strategy according to different scenarios, which not only ensures the stability of the system under high pressure, but also avoids the waste of resources caused by unlimited retries.
[0073] Reference Figure 2 , Figure 2 This is a flow chart of the second embodiment of the data synchronization method of this application, based on the above Figure 1 The first embodiment shown proposes a second embodiment of the data synchronization method of the present application.
[0074] In the second embodiment, the step S20 includes:
[0075] Step S201: after the online transaction is successfully submitted, data is immediately synchronized by calling the target service.
[0076] It should be noted that the target service can be a system or service that receives and processes the data transmitted by the source service. The main responsibility of the target service is to receive data synchronization requests from the source service and store or process the data to ensure that the data state is consistent with the source service. Immediate data synchronization can be the process in which the source service immediately transfers data to the target service after the online transaction is successfully submitted.
[0077] Step S202: setting a preset duration for the target service, where the preset duration is used to prevent the source service thread from being occupied for a long time due to waiting for a response from the target service.
[0078] It should be noted that the preset duration can be the maximum waiting time set by the source service to wait for the target service to respond when calling the target service for data synchronization. If the target service does not complete the response within the preset duration, the source service will stop waiting to avoid long-term resource occupation. The source service is the system or service that initiates the data synchronization request and passes the data to the target service. A thread represents the smallest unit that can run independently during the execution of a program.
[0079] Exemplarily, when an online transaction is successfully submitted, in order to ensure the timeliness of data synchronization, a data synchronization is triggered immediately after the transaction is submitted, that is, the data receiving target service is immediately called for real-time synchronization; the target service only handles data reception and does not perform complex calculations and logical processing, so data reception can be completed in a shorter time. At the same time, in order to ensure that this immediate synchronization does not occupy the current processing thread of the source service for a long time, a shorter timeout period, such as 10ms, needs to be set for this immediate call request. It is understandable that the immediate call will be downgraded to asynchronous processing only when the occupancy time exceeds the preset time, and the high timeliness of data synchronization is exchanged for a shorter time.
[0080] After the online transaction is successfully submitted in this embodiment, the target service is called to synchronize data immediately, which can minimize the delay of data synchronization, ensure that the data of the source system and the target system are synchronized, and improve data consistency and real-time performance. By setting a preset time, the source service thread is prevented from being blocked due to a long wait for the target service response. When the target service fails to respond within the preset time, the source service thread will be released and continue to process other tasks, ensuring that the overall resources of the system are fully utilized.
[0081] Reference Figure 3 , Figure 3 This is a flow chart of the third embodiment of the data synchronization method of this application, based on the above Figure 2 The second embodiment shown proposes a third embodiment of the data synchronization method of the present application.
[0082] In the third embodiment, the step S30 includes:
[0083] Step S301, if the immediate data synchronization fails, register the first data synchronization task into the asynchronous task queue to obtain a data asynchronous task, and the data asynchronous task is managed and executed by the asynchronous thread pool.
[0084] It should be noted that the asynchronous task queue can be a data structure for managing asynchronous tasks, which contains all data synchronization tasks that need to be executed asynchronously. When the data synchronization fails immediately, the first data synchronization task will be added to the queue and wait for asynchronous execution. The asynchronous thread pool is a set of pre-created threads used to execute tasks in the asynchronous task queue. The thread pool manages and schedules these threads to avoid the performance overhead caused by frequent creation and destruction of threads, and improve the efficiency of system processing tasks.
[0085] Step S302: Schedule the data asynchronous task according to a preset task scheduling strategy, where the task scheduling strategy ensures that the data synchronous task is asynchronously executed in the background.
[0086] It should be noted that the preset task scheduling strategy can be a set of rules or algorithms pre-set by the system for managing and scheduling the execution order and method of asynchronous tasks. The scheduling strategy can be set according to factors such as the priority of the task, the time requirement for task execution, and the utilization rate of system resources. Exemplary, common task scheduling strategies include first-in-first-out (FIFO), priority scheduling, polling scheduling, etc., to ensure that asynchronous tasks are executed in a reasonable order and manner. Background asynchronous execution means that the data synchronization task is not executed synchronously with the main thread of the source service, but is executed independently in the background by the asynchronous thread pool. This method will not block the normal operation of the source service, ensuring that the system can maintain high performance and high concurrency processing capabilities when processing data synchronization tasks.
[0087] In this embodiment, if the data synchronization fails immediately, the data asynchronous task is obtained by registering the first data synchronization task into the asynchronous task queue. The data asynchronous task is managed and executed by the asynchronous thread pool, ensuring that after the data synchronization fails immediately, the first data synchronization task will not be discarded, but will be registered into the asynchronous task queue to form a data asynchronous task, ensuring that even in the case of the failure of the data synchronization immediately, the data synchronization task can still continue, ensuring that the data can eventually be successfully synchronized to the target system. By transferring the data synchronization task to the asynchronous thread pool for execution, the source service thread is prevented from being blocked when the data synchronization fails immediately, the processing resources of the source service are released, and the source service can continue to execute other tasks. By using the asynchronous thread pool to manage and execute the data asynchronous task, the overhead of frequently creating and destroying threads is avoided, and the tasks are scheduled in an orderly manner according to the preset task scheduling strategy to ensure that the system resources are fully utilized. The preset task scheduling strategy can reasonably arrange the execution order of the data asynchronous tasks to ensure that the data synchronization tasks are executed in an orderly manner in the background.
[0088] In one implementation, based on the third embodiment described above, step S302 includes: maintaining a lock operation on the record of the data asynchronous task through a database record lock, wherein the database record lock mechanism ensures that when tasks are executed concurrently, each task is exclusively occupied by a single thread; after the asynchronous task is completed, the task status is updated and the database record lock is released.
[0089] It should be noted that the database record lock can be a database lock mechanism used to lock a specific database record (i.e., row). The record lock operation refers to locking the specified task record through the database record lock when executing the task, ensuring that the record will not be acquired or modified by other threads or processes during the task execution. Task concurrent execution can be understood as the situation where multiple tasks are executed simultaneously in a multi-threaded or multi-process environment. Concurrent execution can improve the efficiency and resource utilization of the system, but it is necessary to ensure that tasks do not interfere with each other or conflict with each other. Single-thread exclusivity can be understood as at a certain moment, only one thread can operate on a specific resource or task, and other threads cannot access or modify the resource or task during this period. Updating the task status refers to updating the execution status information of the task to the database during or after the task execution, usually including status changes, such as "to be executed", "executing", "completed" or "failed to execute". Releasing the database record lock can be an operation to unlock the database record after the task execution is completed, so that the record can be accessed and operated by other threads or processes again.
[0090] In this embodiment, by implementing a database row lock mechanism, it is ensured that only one thread can execute a specific task at the same time, thereby avoiding repeated execution or conflict of tasks. During the execution process, the update of the task status can ensure that other threads will not repeatedly process the same task, thereby ensuring the integrity and consistency of the data synchronization task.
[0091] In order to make the embodiments of the present application more complete and clear, based on the above embodiments, the overall solution process is proposed as follows Figure 4 As shown, Figure 4The real-time synchronization of cross-service data submission is divided into three main modules: data synchronization source service, data synchronization asynchronous control module, and data synchronization target service. When the source service undergoes a business change, the business logic processing outside the transaction is first performed, and the control information of the overall asynchronous task is recorded. Next, it is determined whether the transaction is successfully submitted. If the transaction is successfully submitted, the system will try to call the target service immediately for data synchronization, and set a timeout (for example, 10ms) to avoid the source service thread being occupied for a long time. If the data synchronization is successful, the process ends here; if the synchronization fails, the data synchronization task will enter the asynchronous task execution process. At this time, the asynchronous control module obtains the asynchronous task to be executed and executes it through the asynchronous thread pool, and then checks again whether the data synchronization is successful. If successful, the process ends, and if it fails, the task retry mechanism is entered. The system will regularly check the task records that have not been successfully executed through the scanning mechanism, and hand these records over to the asynchronous task retry mechanism to try to execute again until the data synchronization is successful or the preset retry limit is reached. In the entire process, the data synchronization target service is responsible for receiving the data synchronization request of the source service and making corresponding processing according to the set timeout time. Through such a design, the entire solution not only ensures the timeliness and reliability of data synchronization, but also ensures that even in the event of synchronization failure, the system can still ensure the final consistency of data through asynchronous processing and retry mechanisms, avoiding data loss or inconsistency caused by synchronization anomalies.
[0092] Since service anomalies and program defects can lead to untimely data synchronization or inconsistency, a monitoring module is needed to compare and check the source data with the target data. The assistance of monitoring tools can also avoid manual investigation and comparison in large amounts of data when data synchronization anomalies occur. In addition, considering the execution efficiency of large-scale data comparison and the impact of high-frequency execution on the access to source data services and target data services, on the one hand, batch data extraction is performed by accessing the backup data storage service to avoid impact on the primary data storage service; on the other hand, only a small amount of data sampling is performed on some key business data, and by checking a small amount of data in a short time, anomalies can be quickly discovered and alarms can be sent.
[0093] Based on this, an implementation method is proposed, which is based on the above embodiment and after step S50, includes: obtaining key business data, performing sampling verification on the key business data, and obtaining a first verification result; obtaining full business data, performing full verification on the full business data, and obtaining a second verification result; based on the first verification result and the second verification result, dynamically verifying the data synchronization process and providing abnormal monitoring and alarms.
[0094] Among them, it should be noted that the step of obtaining key business data, performing sampling verification on the key business data, and obtaining the first verification result includes: extracting sample data of key business types within a specified time interval from the backup storage service of the source data service; based on the sample data, batch querying the corresponding data in the target data service by data key value matching; comparing the consistency of the bilateral sample data of the source data and the target data to obtain the first verification result. The step of obtaining the full amount of business data, performing full verification on the full amount of business data, and obtaining the second verification result includes: obtaining the full amount of business data during the business off-peak period or the system daily transition period; splitting the full amount of business data according to the preset dimension to obtain the verification batch data set, splitting the full amount of business data according to the preset dimension to ensure that the amount of data for a single verification is controllable; based on the batch data extracted from the source data service, batch retrieving the corresponding data in the target data service by data key value; comparing the consistency of the batch data of the source data and the target data one by one to obtain the second verification result.
[0095] For example, Figure 5 As shown, sampling and checking of key business data can be understood as checking and executing by regularly triggering data sampling through the check scheduling task, such as once every 5 minutes. Extract sample data of key business types within the specified interval in the past from the backup storage service of the source data service, use the sample data extracted from the source data service as the benchmark, use the data key value to batch extract the data of the target data service, compare the consistency of the bilateral sample data, such as the total amount of data, data status, data version, other key information, etc., and send monitoring alarms for inconsistent verification results. The process of full verification of the full amount of business data can be understood as using a high-concurrency execution task to perform a full verification of the source data and the target data during the low-peak business period in the early morning. You can only access the backup storage service for batch data query, filter out the full amount of data of the previous day for verification, and send an alarm if an abnormality is found. Exemplarily, when the system is cut daily, the verification scheduling task can trigger the full verification of the previous day's data. Considering the large volume of transaction data in a day and the problem of verification efficiency, the data in a day needs to be split into multiple verification batches according to specific dimensions to ensure that the amount of data for a single verification is controllable, and that the concurrent execution of multiple batches improves the verification efficiency. For example, if the data is split according to data sub-library + sub-table + partition, data from different sub-libraries, different sub-tables, and different partitions can be executed concurrently in different batches. The system performs data verification at the split batch granularity, batch extracts the data in the current batch from the backup storage service of the source data service, and uses the data key value to batch extract the data of the target data service based on the batch data extracted from the source data service. The consistency of the bilateral batch data is compared one by one, such as data status, data version, and other key information. Finally, a monitoring alarm is sent for inconsistent verification results.
[0096] In this implementation, by regularly sampling and checking key business data, potential anomalies and inconsistencies in the data synchronization process can be discovered in a timely manner, ensuring the consistency of source data and target data at key data points. By checking the full amount of business data during the off-peak period of business, it is ensured that the results of all data synchronization operations are completely consistent with the source data, thereby avoiding the risk of data omission or error propagation to the target system. Based on the first verification result (sampling verification of key business data) and the second verification result (verification of the full amount of business data), the system can dynamically verify the data synchronization process, timely discover data synchronization anomalies and trigger monitoring alarms. Through dynamic verification, anomalies in the data synchronization process can be quickly detected, and alarms can be issued to relevant personnel in a timely manner, so as to facilitate rapid measures to correct problems and avoid long-term impacts of data inconsistency on the business. Through the dual verification mechanism of sampling verification and full verification, anomalies can be discovered and corrected at multiple stages of data synchronization, improving the fault tolerance of data synchronization and ensuring the integrity and reliability of system data.
[0097] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the data synchronization method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0098] This application also provides a data synchronization device, please refer to Figure 6 , the data synchronization device comprises:
[0099] The data collection module 10 is used to collect data change information and register the data change information as a first data synchronization task;
[0100] An immediate synchronization module 20 is used to attempt to synchronize data immediately after an online transaction is successfully submitted;
[0101] A task conversion module 30, configured to convert the first data synchronization task into a data asynchronous task if the immediate data synchronization fails;
[0102] The task scanning module 40 is used to enable the data synchronization task that failed to be scanned by the backup scheduled task to obtain a second data synchronization task if the data asynchronous task fails to be executed;
[0103] The task retry module 50 is used to perform data synchronization again based on the second data synchronization task until the data synchronization succeeds or reaches a preset retry times threshold.
[0104] The data synchronization device provided by the present application adopts the data synchronization method in the above embodiment, which can solve the technical problem of low data synchronization accuracy. Compared with the prior art, the beneficial effects of the data synchronization device provided by the present application are the same as the beneficial effects of the data synchronization method provided by the above embodiment, and the other technical features in the data synchronization device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0105] The present application provides a data synchronization device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data synchronization method in the above-mentioned embodiment one.
[0106] Reference below Figure 7 , which shows a schematic diagram of the structure of a data synchronization device suitable for implementing the embodiment of the present application. The data synchronization device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The data synchronization device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0107] like Figure 7As shown, the data synchronization device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the data synchronization device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the data synchronization device to communicate with other devices wirelessly or by wire to exchange data. Figure 7 The data synchronization device with various systems is shown, but it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have instead.
[0108] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0109] The data synchronization device provided by the present application adopts the data synchronization method in the above embodiment, which can solve the technical problem of low data synchronization accuracy. Compared with the prior art, the beneficial effects of the data synchronization device provided by the present application are the same as the beneficial effects of the data synchronization method provided by the above embodiment, and the other technical features in the data synchronization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0110] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0111] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0112] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the data synchronization method in the above-mentioned embodiment.
[0113] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0114] The computer-readable storage medium may be included in the data synchronization device; or may exist independently without being assembled into the data synchronization device.
[0115] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the data synchronization device, the data synchronization device: collects data change information and registers the data change information as a first data synchronization task; when the online transaction is successfully submitted, attempts to synchronize the data immediately; if the immediate data synchronization fails, converts the first data synchronization task into a data asynchronous task; if the data asynchronous task fails to execute, enables a backup scheduled task to scan the unsuccessful data synchronization tasks to obtain a second data synchronization task; and performs data synchronization again based on the second data synchronization task until the data synchronization is successful or a preset retry count threshold is reached.
[0116] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0117] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0118] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0119] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned data synchronization method, and can solve the technical problem of low data synchronization accuracy. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the data synchronization method provided in the above-mentioned embodiment, and will not be elaborated here.
[0120] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A data synchronization method, characterized in that: The method includes: Collecting data change information, and registering the data change information as a first data synchronization task; When the online transaction is successfully committed, the data is attempted to be synchronized immediately; If the immediate data synchronization fails, converting the first data synchronization task into a data asynchronous task; If the data asynchronous task fails to execute, the backup scheduled task is enabled to scan the data synchronization task that failed, and a second data synchronization task is obtained; Data synchronization is performed again based on the second data synchronization task until data synchronization succeeds or reaches a preset retry times threshold.
2. The method according to claim 1, characterized in that The step of attempting to synchronize data immediately after the online transaction is successfully submitted includes: When the online transaction is successfully submitted, the data is immediately synchronized by calling the target service; A preset duration is set for the target service, and the preset duration is used to prevent the source service thread from being occupied for a long time due to waiting for a response from the target service.
3. The method according to claim 1, characterized in that The step of converting the first data synchronization task into a data asynchronous task if the immediate data synchronization fails comprises: If the immediate data synchronization fails, the first data synchronization task is registered in the asynchronous task queue to obtain a data asynchronous task, and the data asynchronous task is managed and executed by the asynchronous thread pool; The data asynchronous task is scheduled for execution according to a preset task scheduling strategy, and the task scheduling strategy ensures that the data synchronization task is asynchronously executed in the background.
4. The method according to claim 3, characterized in that The step of scheduling the execution of the data asynchronous task according to the preset task scheduling strategy, wherein the task scheduling strategy ensures that the data synchronization task is asynchronously executed in the background, includes: The record lock operation is performed on the data asynchronous task through the database record lock. The database record lock mechanism ensures that each task is exclusively occupied by a single thread when the tasks are executed concurrently. After the asynchronous task is completed, the task status is updated and the database record lock is released.
5. The method according to any one of claims 1 to 4, characterized in that After the step of performing data synchronization again based on the second data synchronization task until data synchronization succeeds or reaches a preset retry count threshold, the method includes: Acquire key business data, perform sampling verification on the key business data, and obtain a first verification result; Acquire the full amount of business data, and perform a full verification on the full amount of business data to obtain a second verification result; Based on the first verification result and the second verification result, the data synchronization process is dynamically verified and abnormal monitoring and alarm are issued.
6. The method according to claim 5, characterized in that The step of acquiring key business data, performing sampling verification on the key business data, and obtaining a first verification result includes: Extract sample data of key business types within a specified time interval from the backup storage service of the source data service; Based on the sample data, batch query corresponding data in the target data service by data key value matching; Compare the consistency of the bilateral sample data of the source data and the target data to obtain the first verification result.
7. The method according to claim 5, characterized in that The step of obtaining the full amount of business data, performing full verification on the full amount of business data, and obtaining a second verification result includes: Obtain full business data during off-peak hours or system daily transition periods; Splitting the full amount of business data according to a preset dimension to obtain a verification batch data set, wherein the splitting of the full amount of business data according to the preset dimension is used to ensure that the amount of data for a single verification is controllable; Based on the batch data extracted from the source data service, batch retrieve the corresponding data in the target data service through the data key value; The batch data of the source data and the target data are compared one by one for consistency to obtain a second verification result.
8. A data synchronization device, characterized in that: The device comprises: A data acquisition module, used for acquiring data change information and registering the data change information as a first data synchronization task; The immediate synchronization module is used to attempt to synchronize data immediately after the online transaction is successfully submitted; A task conversion module, used for converting the first data synchronization task into a data asynchronous task if the immediate data synchronization fails; A task scanning module, used for, if the data asynchronous task fails to execute, starting the data synchronization task that failed to scan the backup scheduled task, to obtain a second data synchronization task; The task retry module is used to perform data synchronization again based on the second data synchronization task until the data synchronization succeeds or reaches a preset retry number threshold.
9. A data synchronization device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data synchronization method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the data synchronization method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Comprehensive administrative law enforcement management service system
CN120725627A
Data synchronization system and method, electronic equipment and readable storage medium
CN121560987A