Mass data synchronization system and method and electronic equipment
By introducing full synchronization, incremental synchronization, exception processing and data detection modules into the massive data synchronization system, the problems of data inconsistency and resource pressure in massive data synchronization are solved, efficient and reliable data synchronization is achieved, and the user experience is improved.
Patent Information
- Application Number
- CN202411078130.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-10-15
AI Technical Summary
When existing data synchronization methods handle massive amounts of data, they can easily lead to data inconsistencies between the database and the search engine and increase resource pressure, affecting system performance and user experience.
A massive data synchronization system is designed, including a full synchronization module, an incremental synchronization module, an exception handling module and a data detection module. It ensures the consistency and integrity of data through batch writing, change log processing, exception handling and data detection. .
It achieves data consistency and integrity during massive data synchronization, reduces resource consumption, improves data synchronization reliability and user experience, and avoids data inconsistency problems.
Smart Images

Figure CN118779383A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a massive data synchronization system, method and electronic device. Background Art
[0002] Data synchronization refers to the real-time copying of data from the source database to the target system. In the field of Internet services, data synchronization is particularly important. It not only ensures the consistency and integrity of the data, but also improves the query performance and response speed of the system.
[0003] When the amount of order data reaches tens of millions, the speed of querying order data in the MySQL (My Structured Query Language) database decreases significantly. Therefore, it is necessary to migrate the order data to Elasticsearch (ES, search engine) through data synchronization to improve query performance and response speed.
[0004] However, the current data synchronization method often relies on full synchronization. Although full synchronization can migrate the data of the entire database to ES, as the amount of data grows, the resource pressure of full synchronization also increases, which can easily affect the overall performance of the system. In addition, there is a risk of inconsistency and incompleteness in the data between the database and ES, resulting in a poor user experience. Summary of the invention
[0005] The present application provides a massive data synchronization system, method and electronic device to solve or partially solve the problem of how to ensure the consistency and integrity of data during the data synchronization process.
[0006] In a first aspect, the present application provides a massive data synchronization system, wherein the massive data synchronization system is respectively connected to a database and a search engine for communication, wherein the database includes order data to be synchronized and order numbers of the order data to be synchronized; wherein the massive data synchronization system includes: A full synchronization module, used for writing the order data to be synchronized and the order numbers in batches into the search engine until the synchronization of the order data to be synchronized in the database is completed; An incremental synchronization module, configured to receive a change log for the database, extract a change event and change order data from the change log, and call a target query statement corresponding to the change event to synchronize the change order data to the search engine; an exception handling module, for responding to an abnormal synchronization instruction for the search engine, and adopting a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database; The data detection module is used to detect whether the order data in the database is consistent with the order data in the search engine, and generate a detection result.
[0007] Optionally, the full-volume synchronization module is used to respond to a batch migration instruction, wherein the batch migration instruction includes a single migration data volume; Writing the order data to be synchronized into the search engine according to the single migration data volume, and recording the current order number that has finished writing into the search engine this time; When executing the next write operation, the order data to be synchronized that is larger than the current order number is selected and written into the search engine until the order data to be synchronized in the database is synchronized completely.
[0008] Optionally, the incremental synchronization module is used to extract a new order number and new order data from the new event if it is determined that the change event is a new event; Determine the target data partition to which the newly added order data belongs by calculating the hash value of the newly added order number; Sending the newly added order data to the message queue corresponding to the target data partition; In the target data partition, an insert statement corresponding to the newly added event is called, and the newly added order data is written into the search engine through the insert statement.
[0009] Optionally, the incremental synchronization module is used to extract an update order number and update order data from the update event if it is determined that the change event is an update event; Determine the target data partition to which the updated order data belongs by calculating the hash value of the updated order number; Sending the updated order data to the message queue corresponding to the target data partition; In the target data partition, an update statement corresponding to the update event is called, and the order data corresponding to the updated order number in the search engine is replaced with the updated order data through the update statement.
[0010] Optionally, the incremental synchronization module is used to extract a deletion order number from the deletion event if it is determined that the change event is a deletion event; Determine the target data partition to which the deletion order data belongs by calculating the hash value of the deletion order number; In the target data partition, a delete statement corresponding to the deletion event is called, and the order data corresponding to the deletion order number in the search engine is deleted through the delete statement.
[0011] Optionally, the abnormal synchronization instruction includes an abnormal type, and the abnormal type includes server restart; The exception handling module is used to determine a first processing strategy corresponding to the server restart. The first processing strategy is to confirm the restart status of the server through a restart script, stop reading log data, and record the current local consumption point. After the server restart is completed, continue to read the log data from the local consumption point to keep the order data of the search engine consistent with the order data of the database.
[0012] Optionally, the exception type includes search engine write failure; The exception handling module is used to determine a second processing strategy corresponding to the search engine write failure, and the second processing strategy is to update the search engine according to a preset number of retries to keep the order data of the search engine consistent with the order data of the database.
[0013] Optionally, the data detection module is used to perform quantity detection on the order data of the database and the order data of the search engine; If the number of orders in the database is the same as the number of orders in the search engine, a synchronization success result is generated; If the order quantity of the database is different from the order quantity of the search engine, a synchronization failure result is generated.
[0014] A second aspect of the present application provides a mass data synchronization method, which is applied to a mass data synchronization system, wherein the mass data synchronization system is respectively connected to a database and a search engine for communication, wherein the database includes order data to be synchronized and order numbers of the order data to be synchronized, and the method includes: Writing the order data to be synchronized and the order numbers in batches into the search engine until the order data to be synchronized in the database is synchronized completely; receiving a change log for the database, extracting a change event and change order data from the change log, and calling a target query statement corresponding to the change event to synchronize the change order data to the search engine; In response to an abnormal synchronization instruction for the search engine, adopting a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database; Check whether the order data in the database is consistent with the order data in the search engine, and generate a test result.
[0015] A third aspect of the present application provides an electronic device, including: Processor; and The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method as described above.
[0016] The technical solution provided by this application may have the following beneficial effects: In an embodiment of the present application, a massive data synchronization system is respectively communicated with a database and a search engine, and the database includes order data to be synchronized and order numbers of the order data to be synchronized; wherein the massive data synchronization system includes: a full synchronization module, which is used to write the order data to be synchronized and the order numbers to the search engine in batches until the order data to be synchronized in the database is synchronized; an incremental synchronization module, which is used to receive a change log for the database, extract change events and changed order data from the change log, and call a target query statement corresponding to the change event to synchronize the changed order data to the search engine; an exception handling module, which is used to respond to an abnormal synchronization instruction for the search engine, and adopt a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database; a data detection module, which is used to detect whether the order data of the database and the order data of the search engine are consistent, and generate a detection result.
[0017] Compared with the related technologies, the technical solution of the present application, on the one hand, is based on the full synchronization module and combined with the incremental synchronization module to realize flexible selection of data synchronization methods according to actual needs. It can not only cope with various synchronization scenarios, but also reduce the resource consumption of data synchronization and improve the reliability of data synchronization. On the other hand, by designing an exception handling module, it is possible to respond in time when abnormal synchronization occurs, and use corresponding processing strategies to ensure data consistency. After data synchronization, the accuracy and completeness of data synchronization can be further verified through the data detection module, thereby avoiding data inconsistency problems in data synchronization and improving user experience.
[0018] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The above and other objects, features and advantages of the present application will become more apparent by describing in more detail the exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.
[0020] Figure 1 It is a structural schematic diagram of a massive data synchronization system shown in an embodiment of the present application; Figure 2 It is a flowchart of a method for synchronizing massive data according to an embodiment of the present application; Figure 3It is a schematic diagram of the overall process of synchronizing massive order data to a search engine by a massive data synchronization system shown in an embodiment of the present application; Figure 4 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0021] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0022] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0023] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0024] Since full synchronization requires transferring all data from the source database to the target system, a large amount of system resources will be consumed when the amount of data reaches tens of millions. Especially during data synchronization or migration, the load on the database and ES will increase significantly, resulting in system performance degradation or slow response, thus affecting the operation experience of online users.
[0025] In response to the above problems, an embodiment of the present application provides a massive data synchronization system that can ensure the consistency and integrity of data synchronization and improve user experience.
[0026] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0027] Figure 1 Schematic diagram of a massive data synchronization system shown in an embodiment of the present application. Figure 1The massive data synchronization system is connected to the database and the search engine respectively. The database includes the order data to be synchronized and the order number of the order data to be synchronized. The system includes at least the following modules: Full synchronization module 101, used to write the order data to be synchronized and the order number in batches to the search engine until the order data to be synchronized in the database is synchronized completely; The incremental synchronization module 102 is used to receive the change log for the database, extract the change event and the change order data from the change log, and call the target query statement corresponding to the change event to synchronize the change order data to the search engine; The exception handling module 103 is used to respond to the abnormal synchronization instruction for the search engine and adopt the processing strategy corresponding to the abnormal synchronization instruction to make the order data of the search engine consistent with the order data of the database; The data detection module 104 is used to detect whether the order data in the database and the order data in the search engine are consistent, and generate a detection result.
[0028] In an embodiment of the present application, a massive data synchronization system refers to a system that efficiently and reliably migrates or synchronizes a large amount of order data from a database to an ES. The system can ensure that after data synchronization, the database and the ES remain consistent in data.
[0029] A database refers to an organized collection of data, usually stored in a computer system for easy retrieval, management, and updating. It organizes data through a specific data model and provides interfaces to support data access, query, and management.
[0030] There can be many types of databases, including relational databases, non-relational databases, etc. In the present application, the database can be a MySQL database, which stores a large amount of order data to be synchronized and the order numbers corresponding to the order data to be synchronized.
[0031] ES refers to an open source search engine that is mainly used for full-text search, log analysis, real-time data analysis, and complex search. ES is a distributed search engine that supports efficient storage, search, and analysis of large amounts of data. It can be used to analyze log data in real time and can also be combined with other visualization tools to achieve visual display.
[0032] In an optional example of the present application, the full synchronization module 101 is mainly used to respond to a batch migration instruction, obtain the single migration data volume from the batch migration instruction, and then write the order data to be synchronized into the search engine according to the single migration data volume, and record the current order number at the end of this writing to the search engine. When executing the next write operation, select the order data to be synchronized that is greater than the current order number and write it to the search engine until the synchronization of the order data to be synchronized in the database is completed.
[0033] Among them, the batch migration instruction refers to an instruction to instruct the full synchronization module 101 to perform batch data migration or synchronization. The instruction includes the amount of data for a single migration. The size of the amount of data for a single migration can be flexibly set, such as 10,000 items / time, 15,000 items / time, etc.
[0034] The order data to be synchronized refers to the relevant order data that has not been migrated or synchronized to ES during the data synchronization process. For example, the order data to be synchronized includes at least the product name, product quantity, product price, order status, etc.
[0035] The order number is the identifier of each order. Each order number is unique in the database, so each order can be automatically identified and tracked by the order number. For example, the order ID (Identification Number) can be 123456, AB123, etc.
[0036] As an example, the database includes an order table. In the order table, order_id (order ID) is the primary key and is unique. The full synchronization module 101 can perform data synchronization according to the following steps: 1) Extract 10,000 order data from the database at one time, record the maximum order_id among the 10,000 data, and store it as the maxOrderId variable; 2) Write the extracted 10,000 order data in batches into ES; 3) After writing to ES, continue to extract the remaining order data whose order_id is greater than maxOrderId from the database, and write them to ES in batches until all order data in the database is migrated.
[0037] The full synchronization module 101 controls the amount of order data extracted each time to 10,000 and updates the maxOrderId variable to ensure data continuity. It also gradually migrates all order data to ES without causing excessive resource pressure on the database and ES.
[0038] In an optional example of the present application, the incremental synchronization module 102 is mainly used to receive a change log for the database, extract change events and change order data from the change log, and call a target query statement corresponding to the change event to synchronize the change order data to the search engine.
[0039] In this application, the massive data synchronization system subscribes to the MySQL binary log (Binary log, Binlog), and the Binlog log records all changes to the database.
[0040] Accordingly, the massive data synchronization system uses data synchronization middleware, such as DTS (Data Transmission Service) and open source tools, such as Maxwell, to call back the change log (Binlog log) to facilitate real-time monitoring of database change operations.
[0041] Among them, Maxwell can convert Binlog data into JSON format data and send it to the message queue.
[0042] The change log can be a log file or record of data changes in the database. The change log records the new operations (insert operations), update operations and delete operations of the database. The change order data and corresponding change events generated by different operations can be extracted from the change log.
[0043] The target query statement refers to a SQL (Structured Query Language) statement.
[0044] As an example, when order data sends changes, the incremental synchronization module 102 can trigger a log callback to the massive data synchronization system through data middleware and open source tools, such as a new operation triggering an Insert statement, an update operation triggering an Update statement, and a delete operation triggering a Delete statement.
[0045] If it is determined that the change event is a new event, the new order number and the new order data are extracted from the new event, and the target data partition to which the new order data belongs is determined by calculating the hash value of the new order number. The new order data is then sent to the message queue corresponding to the target data partition. In the target data partition, the insert statement corresponding to the new event is called, and the new order data is written to the search engine through the insert statement.
[0046] For example, it is detected that a new order with the order number "123456" is inserted, and the newly added order data includes product ID, quantity, price and other information.
[0047] The incremental synchronization module 102 can read the newly added order data and the newly added order number from the change log, calculate the newly added order number "123456" through the set hash function, and obtain a fixed-length numeric or letter string, and then use the mapping relationship between the hash value and the data partition to determine the target data partition corresponding to the new order, and send the newly added order data to the message queue corresponding to the target data partition.
[0048] In the target data partition, the incremental synchronization module 102 calls the Insert statement corresponding to the newly added event to write information such as product ID, quantity, price, etc. into the search engine, thereby ensuring that the data in the search engine remains up to date.
[0049] If it is determined that the change event is an update event, the update order number and update order data are extracted from the update event, and the target data partition to which the update order data belongs is determined by calculating the hash value of the update order number. Then, the update order data is sent to the message queue corresponding to the target data partition. In the target data partition, the update statement corresponding to the update event is called, and the order data corresponding to the update order number in the search engine is replaced with the update order data through the update statement.
[0050] For example, it is detected that the user has modified the order with the order number "123456". The updated order data is: the order price is changed from 200 yuan to 230 yuan.
[0051] The incremental synchronization module 102 can read the updated order data and order number from the change log, calculate the order number "123456" through the set hash function, and obtain a fixed-length numeric or letter string, and then use the mapping relationship between the hash value and the data partition to determine the target data partition corresponding to the updated order, and send the updated order data to the message queue corresponding to the target data partition.
[0052] In the target data partition, the incremental synchronization module 102 calls the Update statement corresponding to the update event to replace the original order price in the search engine with 230 yuan, thereby ensuring that the data in the search engine is consistent with the data in the database.
[0053] If it is determined that the change event is a deletion event, the deletion order number is extracted from the deletion event, and the target data partition to which the deleted order data belongs is determined by calculating the hash value of the deletion order number. In the target data partition, the deletion statement corresponding to the deletion event is called, and the order data corresponding to the deletion order number in the search engine is deleted through the deletion statement.
[0054] For example, it is detected that a user has deleted an order with the order number "123456".
[0055] The incremental synchronization module 102 can read the deleted order number from the change log, calculate the order number "123456" through the set hash function, obtain a fixed-length numeric or letter string, and then use the mapping relationship between the hash value and the data partition to determine the target data partition corresponding to the deleted order.
[0056] In the target data partition, the incremental synchronization module 102 calls the Delete statement corresponding to the deletion event, finds the order "123456" in the search engine, and deletes it, thereby ensuring that the data in the search engine is consistent with the data in the database.
[0057] It is worth noting that this application utilizes the partition order of the message queue to ensure that order data with the same order ID is sent to the same data partition.
[0058] This is because in an actual online environment, the system usually consists of multiple servers that receive messages, and each server may receive change messages for the same order.
[0059] Assume that server A receives the modified data of order number "100" first, and server B subsequently receives the added data of the same order number. If server A performs the update operation first and server B performs the add operation later, data inconsistency may occur.
[0060] Therefore, in order to avoid this situation, this application routes the data of the same order number to the same server through a message queue to ensure that all related operations are performed in the correct order and avoid data inconsistency caused by the disorder of operation order. For example, all addition, update and deletion operations of order number "100" will be sent to the designated server, and the designated server will process these operations in the correct order, thereby ensuring that the final data state is accurate and consistent.
[0061] By centralizing the data of the same order ID in one partition for processing, the communication overhead and processing complexity across partitions can be reduced, which can improve the overall performance and response speed of the system to a certain extent.
[0062] In addition, in order to solve the delay problem of subscription data, this application is configured with a "double write" strategy. The "double write" strategy can write order data to the database and ES at the same time, allowing users to query the latest order information at any time.
[0063] For example, when an order with order number "100" is updated, the update operation will be submitted to the database and ES at the same time. The system can write the updated order data with order number "100" to the database and ES at the same time, which means that no matter how long the delay in the synchronization process is, users can obtain consistent data when querying the database or ES.
[0064] In an optional example of the present application, the exception handling module 103 may respond to an abnormal synchronization instruction for the search engine and adopt a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database.
[0065] The abnormal synchronization instruction refers to an instruction indicating how to handle an abnormal situation or error when an abnormal situation or error is detected during the data synchronization process.
[0066] In the present application, the abnormal synchronization instruction includes an abnormal type, and the abnormal type includes two types: server restart and search engine write failure.
[0067] For the abnormal situation of server restart, the abnormality handling module 103 may first determine a first processing strategy corresponding to the server restart, and then continue data synchronization using the first processing strategy.
[0068] The first processing strategy is to confirm the restart status of the server through the restart script, stop reading log data, and record the current local consumption point. After the server restart is completed, continue to read log data from the local consumption point to keep the order data of the search engine consistent with the order data of the database.
[0069] Among them, the restart script is an automated script that has the functions of stopping service, recording status, restarting operation, and restoring operation.
[0070] The restart status refers to the current state or stage of the server, such as before restart, during restart, and after restart.
[0071] The local consumption point refers to the position or number of the log record that has been processed, and the position where the local consumption point record stops.
[0072] As an example, when the service is started, the restart script is first executed to confirm the restart status of the server, and the restart script is used to detect whether the server is in the process of restarting or has been restarted.
[0073] If it is detected that the server is restarting, you can pause reading and processing data from the database's binary log (Binlog) or other log sources to avoid losing or repeating data during the restart process. At the same time, record the current local consumption point (Checkpoint).
[0074] After the server restarts, you can re-read the log data from the locally recorded consumption point to continue synchronizing the order data to be synchronized to the search engine, ensuring that the order data in the search engine is consistent with the order data in the database.
[0075] For the abnormal situation of search engine writing failure, the abnormality handling module 103 may first determine a second processing strategy corresponding to the search engine writing failure, and then continue data synchronization using the second processing strategy.
[0076] The second processing strategy is to update the search engine according to a preset number of retries, so that the order data of the search engine is consistent with the order data of the database.
[0077] Among them, the preset number of retries is the number set in advance by relevant technical personnel, such as three times, four times, etc.
[0078] As an example, if it is detected that writing to the database is successful but writing to the ES fails, the search engine is updated according to the set number of retries. If the search engine still cannot be successfully written after multiple retries, the exception handling module 103 will trigger the alarm handling mechanism and the timing handling mechanism.
[0079] The alarm handling mechanism is used to notify relevant personnel or system administrators.
[0080] The timing processing mechanism is used to record failed write operations in the message queue, extract these records from the message queue at a regular interval, and try to perform the write operation again.
[0081] If the order data has been deleted during the scheduled processing, you need to query the database first to confirm the latest status of the order, and then determine whether to perform an update or delete operation in the search engine based on the actual status of the order in the database.
[0082] Designing the exception handling module 103 in the massive data synchronization system not only ensures the consistency and integrity of data synchronization, but also enables the retry mechanism to handle temporary failures or abnormal situations in a timely manner, thereby improving the reliability of data synchronization.
[0083] In an optional example of the present application, the data detection module 104 is mainly used to detect the quantity of the order data of the database and the order data of the search engine. If the quantity of the order data of the database and the order data of the search engine are the same, a synchronization success result is generated; if the quantity of the order data of the database and the order data of the search engine are different, a synchronization failure result is generated.
[0084] In the present application, the conditions for sampling detection can be set in advance, and the conditions for sampling detection are one or more of sampling detection time, sampling detection users, and sampling detection data volume.
[0085] As an example, set the sampling detection time: the sampling detection time includes the start time and the end time. The order data in the database within this time range is compared with the order data in the ES to determine whether the synchronization is successful. By setting the sampling detection time, you can ensure that the order data within a specific time period is synchronized correctly.
[0086] As another example, set up sampling detection users: each order corresponds to a user_id (user ID) field, randomly check all order data of a certain number of users, compare the quantity of each user's order data with the user's order data in ES, and determine whether the synchronization is successful. By setting sampling users, you can ensure that the order data of a specific user is synchronized correctly.
[0087] As another example, set the sampling test data volume: directly compare the total number of all orders in the database with the total number of all orders in ES to see if the synchronization is successful. By setting the sampling test quantity, you can ensure that the total amount of all order data matches, and verify the accuracy of data synchronization as a whole.
[0088] In actual applications, regarding the update and iteration of Internet products / services, the online steps of each module in the massive data synchronization system can be: 1) First, launch the processing interface of the incremental synchronization module 102 to receive the change log, extract the change order data, and synchronize it to ES. Observe for a period of time to ensure that the system can run stably and correctly handle the synchronization of incremental data; 2) Launch a new order query interface and data dual-write interface to ensure that new order data is written to the database and ES at the same time to keep the data in the database and ES consistent; 3) The processing interface of the full synchronization module 101 is launched, which is used to write the order data and order numbers to be synchronized into ES in batches until the order data to be synchronized in the database is synchronized; 4) The processing interface of the online exception processing module 103 is used to ensure that the data synchronization function runs normally before going online; 5) The processing interface of the online data detection module 104 is put online to ensure that the abnormality handling function operates normally; 6) Start A / B testing and grayscale release. Some users will start using the new order query interface. Through A / B testing and grayscale release, the stability and correctness of the new interface will be gradually verified. If there are no problems, the new interface will be fully released and all users will use the new order query interface.
[0089] At the same time, considering that instability may occur when the system is just launched, you can also configure tools such as the user order synchronization interface, the interface for synchronizing a single piece of data to ES, and the single order integrity check interface, so as to handle online problems in a timely manner and improve user experience.
[0090] It should be noted that the embodiments of the present invention include but are not limited to the above examples. It is understandable that under the guidance of the ideas of the embodiments of the present invention, those skilled in the art can make settings according to actual conditions, and the present invention is not limited to this.
[0091] In an embodiment of the present application, data synchronization is performed in combination with the full synchronization module 101 and the incremental synchronization module 102 to avoid affecting existing businesses, ensure business continuity, and eliminate the need to shut down the system to process changed order data. During data synchronization, the exception handling module 103 is used to monitor in real time whether any abnormalities occur in data synchronization. If an abnormality occurs, it can be handled in a timely manner to avoid the system shutting down due to unhandled abnormalities. The data detection module 104 is designed to verify the data consistency and integrity of data synchronization, thereby minimizing the impact on business operations and improving user experience.
[0092] Corresponding to the aforementioned application function implementation system embodiment, the present application also provides a massive data synchronization method, an electronic device and corresponding embodiments.
[0093] Figure 2 is a flow chart of a method for synchronizing massive data according to an embodiment of the present application. Figure 2 , applied to a massive data synchronization system, the massive data synchronization system is respectively connected to a database and a search engine, the database includes order data to be synchronized and order numbers of the order data to be synchronized, and the method includes at least the following steps: Step 201, batch write the order data to be synchronized and the order number to the search engine until the order data to be synchronized in the database is synchronized; Step 202, receiving a change log for a database, extracting a change event and change order data from the change log, and calling a target query statement corresponding to the change event to synchronize the change order data to a search engine; Step 203, in response to the abnormal synchronization instruction for the search engine, using a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database; Step 204, detecting whether the order data in the database and the order data in the search engine are consistent, and generating a detection result.
[0094] In an optional example of the present application, the order data to be synchronized and the order numbers are written to the search engine in batches until the order data to be synchronized in the database is synchronized completely, including: In response to a batch migration instruction, the batch migration instruction includes a single migration data amount; Write the order data to be synchronized into the search engine according to the amount of data migrated in a single time, and record the current order number that has been written to the search engine this time; When executing the next write operation, the order data to be synchronized that is greater than the current order number is selected and written into the search engine until the order data to be synchronized in the database is synchronized.
[0095] In an optional example of the present application, receiving a change log for a database, extracting a change event and change order data from the change log, and calling a target query statement corresponding to the change event to synchronize the change order data to a search engine include: If the change event is a new event, extract the new order number and the new order data from the new event; Determine the target data partition to which the newly added order data belongs by calculating the hash value of the newly added order number; Send the newly added order data to the message queue corresponding to the target data partition; In the target data partition, call the insert statement corresponding to the newly added event, and write the newly added order data into the search engine through the insert statement.
[0096] In an optional example of the present application, receiving a change log for a database, extracting a change event and change order data from the change log, and calling a target query statement corresponding to the change event to synchronize the change order data to a search engine include: If the change event is an update event, extract the update order number and update order data from the update event; Determine the target data partition to which the updated order data belongs by calculating the hash value of the updated order number; Send the updated order data to the message queue corresponding to the target data partition; In the target data partition, an update statement corresponding to the update event is called, and the order data corresponding to the updated order number in the search engine is replaced with the updated order data through the update statement.
[0097] In an optional example of the present application, receiving a change log for a database, extracting a change event and change order data from the change log, and calling a target query statement corresponding to the change event to synchronize the change order data to a search engine include: If the change event is a deletion event, the deletion order number is extracted from the deletion event; Determine the target data partition to which the deleted order data belongs by calculating the hash value of the deleted order number; In the target data partition, a delete statement corresponding to the delete event is called, and the order data corresponding to the deleted order number in the search engine is deleted through the delete statement.
[0098] In an optional example of the present application, the abnormal synchronization instruction includes an abnormal type, and the abnormal type includes server restart. In response to the abnormal synchronization instruction for the search engine, a processing strategy corresponding to the abnormal synchronization instruction is adopted to make the order data of the search engine consistent with the order data of the database, including: Determine a first processing strategy corresponding to the server restart. The first processing strategy is to confirm the restart status of the server through a restart script, stop reading log data, and record the current local consumption point. After the server restart is completed, continue to read log data from the local consumption point to keep the order data of the search engine consistent with the order data of the database.
[0099] In an optional example of the present application, the exception type includes a search engine write failure, and in response to an abnormal synchronization instruction for the search engine, a processing strategy corresponding to the abnormal synchronization instruction is adopted to make the order data of the search engine consistent with the order data of the database, including: A second processing strategy corresponding to the search engine write failure is determined, where the second processing strategy is to update the search engine according to a preset number of retries so that the order data of the search engine is consistent with the order data of the database.
[0100] In an optional example of the present application, detecting whether the order data in the database and the order data in the search engine are consistent and generating a detection result includes: Perform quantity checks on the order data in the database and the order data in the search engine; If the number of orders in the database is the same as the number of orders in the search engine, a synchronization success result is generated; If the order quantity of the database is different from the order quantity of the search engine, a synchronization failure result is generated.
[0101] As an example, see Figure 3 , Figure 3 It is a schematic diagram of the overall process of synchronizing massive order data to a search engine by a massive data synchronization system shown in an embodiment of the present application, which includes at least the following sub-steps.
[0102] S31, full synchronization: Query order data in a rolling manner, 10,000 items at a time, until synchronization is complete.
[0103] S32, incremental synchronization: You need to subscribe to the Binlog log. For new events, use the Insert statement to insert the new order data into ES. For update events, use the Update statement to update the order data in ES. For deletion events, use the Delete statement to determine and delete the corresponding order data from ES.
[0104] S33, abnormal situation handling: a) Use Rockrtemq partition order to solve the data order problem during changes; b) Use data double writing to solve the delay problem when subscribing to data; c) The subscription service restart is solved by recording the consumption point each time it is written and re-reading from the consumption point when the next restart occurs; d) Resolve the data inconsistency problem between the database and ES by retrying to write to ES and checking the data integrity of the database and ES when writing to ES.
[0105] S34, data integrity check (sampling processing): comparison based on time, comparison based on user ID, and comparison based on total order data.
[0106] S35, online steps: launch incremental data processing interface, launch new order query interface and data dual-write interface, launch full data synchronization function, launch exception handling interface, launch data detection interface, start A / B testing and grayscale release.
[0107] S36, compensation mechanism for order data: develop online gadgets and order comparison tools, develop interface tools for synchronizing the database to ES through order_id, and develop tools for batch updating of the database to ES through users.
[0108] In the embodiments of the present application, on the one hand, on the basis of full synchronization, combined with incremental synchronization, it is possible to flexibly select the data synchronization method according to actual needs, which can not only cope with various synchronization scenarios, but also reduce the resource consumption of data synchronization and improve the reliability of data synchronization. On the other hand, when abnormal synchronization occurs, it can respond in time and use corresponding processing strategies to ensure data consistency. After data synchronization, it can further verify the accuracy and completeness of data synchronization, thereby avoiding data inconsistency problems in data synchronization and improving user experience.
[0109] Regarding the method in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the system, and will not be elaborated again here.
[0110] Figure 4 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application.
[0111] See also Figure 4 , the electronic device 400 includes a memory 410 and a processor 420.
[0112] The processor 420 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0113] The memory 410 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 420 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at runtime. In addition, the memory 410 may include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 410 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. Computer-readable storage media do not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0114] The memory 410 stores executable codes, and when the executable codes are processed by the processor 420 , the processor 420 can execute part or all of the methods described above.
[0115] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.
[0116] Alternatively, the present application can also be implemented as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) on which executable code (or computer program or computer instruction code) is stored. When the executable code (or computer program or computer instruction code) is executed by a processor of an electronic device (or server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.
[0117] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A massive data synchronization system, characterized in that: The massive data synchronization system is respectively connected to a database and a search engine for communication, wherein the database includes order data to be synchronized and order numbers of the order data to be synchronized; wherein the massive data synchronization system includes: A full synchronization module, used for writing the order data to be synchronized and the order numbers in batches into the search engine until the synchronization of the order data to be synchronized in the database is completed; An incremental synchronization module, configured to receive a change log for the database, extract a change event and change order data from the change log, and call a target query statement corresponding to the change event to synchronize the change order data to the search engine; an exception handling module, for responding to an abnormal synchronization instruction for the search engine, and adopting a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database; The data detection module is used to detect whether the order data in the database is consistent with the order data in the search engine, and generate a detection result.
2. The system according to claim 1, characterized in that The full synchronization module is used to respond to a batch migration instruction, wherein the batch migration instruction includes a single migration data volume; Writing the order data to be synchronized into the search engine according to the single migration data volume, and recording the current order number that has finished writing into the search engine this time; When executing the next write operation, the order data to be synchronized that is larger than the current order number is selected and written into the search engine until the order data to be synchronized in the database is synchronized completely.
3. The system according to claim 1, characterized in that The incremental synchronization module is used to extract the newly added order number and the newly added order data from the newly added event if it is determined that the change event is a newly added event; Determine the target data partition to which the newly added order data belongs by calculating the hash value of the newly added order number; Sending the newly added order data to the message queue corresponding to the target data partition; In the target data partition, an insert statement corresponding to the newly added event is called, and the newly added order data is written into the search engine through the insert statement.
4. The system according to claim 1, characterized in that The incremental synchronization module is used to extract the update order number and the update order data from the update event if it is determined that the change event is an update event; Determine the target data partition to which the updated order data belongs by calculating the hash value of the updated order number; Sending the updated order data to the message queue corresponding to the target data partition; In the target data partition, an update statement corresponding to the update event is called, and the order data corresponding to the updated order number in the search engine is replaced with the updated order data through the update statement.
5. The system according to claim 1, characterized in that The incremental synchronization module is used to extract a deletion order number from the deletion event if it is determined that the change event is a deletion event; Determine the target data partition to which the deletion order data belongs by calculating the hash value of the deletion order number; In the target data partition, a delete statement corresponding to the deletion event is called, and the order data corresponding to the deletion order number in the search engine is deleted through the delete statement.
6. The system according to claim 1, characterized in that The abnormal synchronization instruction includes an abnormal type, and the abnormal type includes server restart; The exception handling module is used to determine a first processing strategy corresponding to the server restart. The first processing strategy is to confirm the restart status of the server through a restart script, stop reading log data, and record the current local consumption point. After the server restart is completed, continue to read the log data from the local consumption point to keep the order data of the search engine consistent with the order data of the database.
7. The system according to claim 6, characterized in that The abnormal types include search engine writing failure; The exception handling module is used to determine a second processing strategy corresponding to the search engine write failure, and the second processing strategy is to update the search engine according to a preset number of retries to keep the order data of the search engine consistent with the order data of the database.
8. The system according to claim 1, characterized in that The data detection module is used to perform quantity detection on the order data of the database and the order data of the search engine; If the number of orders in the database is the same as the number of orders in the search engine, a synchronization success result is generated; If the order quantity of the database is different from the order quantity of the search engine, a synchronization failure result is generated.
9. A method for synchronizing massive data, characterized in that: Applied to a mass data synchronization system, the mass data synchronization system is respectively connected to a database and a search engine for communication, the database includes order data to be synchronized and order numbers of the order data to be synchronized, and the method includes: Writing the order data to be synchronized and the order numbers in batches into the search engine until the order data to be synchronized in the database is synchronized completely; receiving a change log for the database, extracting a change event and change order data from the change log, and calling a target query statement corresponding to the change event to synchronize the change order data to the search engine; In response to an abnormal synchronization instruction for the search engine, adopting a processing strategy corresponding to the abnormal synchronization instruction to keep the order data of the search engine consistent with the order data of the database; Check whether the order data in the database is consistent with the order data in the search engine, and generate a test result.
10. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method as claimed in any one of claims 9.
Citation Information
Cited By
Customer relationship data processing system and method and storage medium
CN122673264A
