Data synchronization method and related apparatus
By calculating the structural evolution entropy and dependency graph of the data tables and dynamically adjusting the synchronization strategy, the problem of decreased synchronization timeliness caused by frequent changes in table structure is solved, and more efficient and stable multi-table synchronization is achieved.
Patent Information
- Application Number
- CN202611356209.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-02
- Publication Date
- 2026-11-24
AI Technical Summary
When faced with frequent changes in table structure, existing technologies are prone to mismatches between the synchronization strategy and the actual structural changes in multi-table synchronization tasks, leading to a decrease in synchronization timeliness.
By calculating the structural evolution entropy of the data table within a preset statistical window, the target synchronization strategy is determined, and data synchronization operations are executed according to the topological order of the dependency graph to ensure that the synchronization strategy adapts to changes in the table structure.
It improves the timeliness and stability of multi-table synchronization tasks, and reduces the situation where subsequent data tables have insufficient available synchronization time due to the increased time spent synchronizing preceding data tables.
Smart Images

Figure CN123157818A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to data synchronization methods and related apparatus. Background Technology
[0002] In business systems, data such as orders, payment records, and scheduling plans typically need to be synchronized to reporting databases or data warehouses. Due to foreign keys or business dependencies between data tables, multi-table synchronization needs to be performed in the order of dependencies to ensure data consistency between upstream and downstream systems.
[0003] In related technologies, multi-table synchronization typically employs full scan or incremental synchronization methods. When frequent changes occur in table structure, such as adding fields or modifying field types, the synchronization time for each table will vary depending on the synchronization method. Furthermore, downstream data tables can only proceed after the upstream data table synchronization is completed. The synchronization time of preceding data tables continuously compresses the available synchronization time for subsequent data tables, which can easily lead to a mismatch between the synchronization method and the remaining synchronization time for some data tables. This can cause the synchronization task to exceed the predetermined time limit, affecting the synchronization timeliness. Summary of the Invention
[0004] In view of the above problems, this application provides a data synchronization method and related apparatus to address the issue of decreased synchronization timeliness caused by frequent table structure changes and multi-table dependencies, thereby improving the adaptability and timeliness of data synchronization. The specific solution is as follows:
[0005] The first aspect of this application provides a data synchronization method, including:
[0006] In response to a table structure change event of a data table, the structural evolution entropy of the data table is obtained based on the event frequency of the table structure change event within a preset statistical window.
[0007] Based on the structural evolution entropy, determine the target synchronization strategy corresponding to the data table;
[0008] Based on the dependencies between multiple data tables in the synchronization task to which the data table belongs, construct a dependency graph;
[0009] According to the topological order of the dependency graph, and based on the target synchronization strategy corresponding to each data table and the synchronization time limit of the synchronization task, data synchronization operations are performed on the multiple data tables.
[0010] In some embodiments, the step of responding to a table structure change event of a data table and obtaining the structural evolution entropy of the data table based on the event frequency of the table structure change event within a preset statistical window includes:
[0011] Identify the event type corresponding to the table structure change event, and write the event type into the preset statistics window corresponding to the data table;
[0012] Calculate the frequency of events and the total number of events corresponding to each event type within the preset statistics window;
[0013] The probability of occurrence for each event type is determined based on the event frequency corresponding to each event type and the total number of events.
[0014] Calculate the structural evolution entropy of the data table based on the occurrence probability of each event type.
[0015] In some embodiments, identifying the event type corresponding to the table structure change event includes:
[0016] Parse the data definition statement that caused the table structure change event to obtain at least one structure change operation;
[0017] The structural change operation is split according to a preset splitting rule to obtain the structural change event corresponding to the structural change operation;
[0018] Based on the changes in the structural change event, determine the preset event type corresponding to the structural change event, and update the event frequency corresponding to the preset event type.
[0019] In some embodiments, determining the target synchronization strategy corresponding to the data table based on the structural evolution entropy includes:
[0020] The synchronization strategy interval corresponding to the data table is determined based on the structural evolution entropy.
[0021] Based on the synchronization strategy range corresponding to the data table, determine the candidate synchronization strategy corresponding to the data table;
[0022] Obtain the most recent policy switching time of the data table. If the time interval between the current time and the most recent policy switching time reaches a preset switching interval, determine the candidate synchronization policy as the target synchronization policy corresponding to the data table.
[0023] In some embodiments, performing data synchronization operations on the plurality of data tables according to the topological order of the dependency graph, based on the target synchronization strategy corresponding to each data table and the synchronization time limit of the synchronization task, includes:
[0024] For the current data table in the dependency graph, determine at least one dependency path leading to the current data table;
[0025] Based on the synchronization time of the data table located upstream of the current data table in each dependency path, determine the cumulative upstream time corresponding to the current data table;
[0026] Based on the synchronization time limit and the cumulative upstream time, determine the remaining synchronization time of the current data table;
[0027] Based on the remaining synchronization time and the target synchronization strategy corresponding to the current data table, perform a data synchronization operation on the current data table;
[0028] After the current data table completes the data synchronization operation, the next data table is synchronized according to the topological order of the dependency graph until the data synchronization operation of the multiple data tables is completed.
[0029] In some embodiments, executing the target synchronization strategy corresponding to the current data table based on the remaining synchronization duration includes:
[0030] Obtain the estimated synchronization time for the current data table when the target synchronization strategy is applied;
[0031] Compare the estimated synchronization duration with the remaining synchronization duration;
[0032] If the expected synchronization time is not greater than the remaining synchronization time, perform data synchronization operation on the current data table according to the target synchronization strategy.
[0033] If the expected synchronization duration is greater than the remaining synchronization duration, the synchronization strategy corresponding to the current data table is re-determined based on the structural evolution entropy and the remaining synchronization duration.
[0034] The estimated synchronization duration of the current data table is updated according to the redefined synchronization strategy, and the remaining synchronization duration of the downstream data table is determined based on the updated estimated synchronization duration.
[0035] In some embodiments, determining the remaining synchronization time of the current data table based on the synchronization time limit and the upstream cumulative time includes:
[0036] Obtain the historical synchronization duration of each data table in the synchronization task;
[0037] The reserved time for the synchronization task is determined based on the historical synchronization duration of each data table and the preset timeout probability.
[0038] The remaining synchronization time of the current data table is obtained by subtracting the upstream cumulative time and the reserved time from the synchronization time limit.
[0039] A second aspect of this application provides a data synchronization device, comprising:
[0040] The structure evolution entropy determination module is used to respond to table structure change events of a data table and obtain the structure evolution entropy of the data table based on the event frequency of the table structure change event within a preset statistical window.
[0041] The strategy determination module is used to determine the target synchronization strategy corresponding to the data table based on the structural evolution entropy.
[0042] The relationship graph construction module is used to construct a dependency graph based on the dependency relationships between multiple data tables in the synchronization task to which the data table belongs;
[0043] The data synchronization module is used to perform data synchronization operations on the multiple data tables according to the topological order of the dependency graph, the target synchronization strategy corresponding to each data table, and the synchronization time limit of the synchronization task.
[0044] A third aspect of this application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0045] The memory is used to store computer programs;
[0046] The processor is used to execute the computer program so that the electronic device can implement the data synchronization method of the first aspect or any implementation thereof.
[0047] A fourth aspect of this application provides a computer storage medium carrying one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the data synchronization method described in the first aspect or any implementation thereof.
[0048] The fifth aspect of this application provides a computer program product including computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the data synchronization method described in the first aspect or any implementation thereof.
[0049] By employing the above technical solution, this application obtains the structural evolution entropy, which characterizes the changes in table structure, by statistically analyzing the frequency of table structure change events within a preset statistical window. Based on this structural evolution entropy, a corresponding target synchronization strategy is determined, enabling different data tables to select appropriate synchronization methods according to their respective table structure changes. Simultaneously, a dependency graph is constructed based on the dependencies between multiple data tables. Combining the target synchronization strategy for each data table with the synchronization time limit of the synchronization task, multi-table synchronization operations are executed in topological order. Therefore, while ensuring the data table dependencies, the synchronization strategy is adapted to the changes in table structure and the time requirements of the synchronization task. This reduces the possibility of insufficient available synchronization time for subsequent data tables due to increased synchronization time of preceding data tables, thereby reducing the likelihood of multi-table synchronization tasks exceeding the predetermined time limit and improving the timeliness and stability of data synchronization. Attached Figure Description
[0050] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0051] Figure 1 A schematic diagram of an application environment provided for an embodiment of this application;
[0052] Figure 2 This is a schematic flowchart of a data synchronization method provided in an embodiment of this application;
[0053] Figure 3 This application provides a schematic flowchart of a data synchronization method in a data synchronization system.
[0054] Figure 4 This is a schematic diagram of a data synchronization device provided in an embodiment of this application;
[0055] Figure 5 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation
[0056] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.
[0057] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0058] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0059] As enterprise business systems expand, data synchronization between multiple heterogeneous data sources is often required. This includes synchronizing transaction data, customer data, or business status data from a business database to a data warehouse, analytics system, or other business systems. In practice, database table structures adjust to business needs, such as adding or deleting fields, modifying field types, and adjusting indexes or constraints. Therefore, maintaining the reliability and timeliness of the synchronization process in a heterogeneous database environment, where table structures and data are constantly changing, is a critical issue that needs to be addressed.
[0060] In related technologies, data synchronization between heterogeneous data sources typically employs either a full synchronization solution or an incremental synchronization solution based on Change Data Capture (CDC). The full synchronization solution periodically scans the target data table in the source database, reads all data, and writes it to the target database to achieve data consistency between the source and target. The CDC-based synchronization solution monitors database transaction logs, such as MySQL's Binlog, Oracle's Redo Log, or PostgreSQL's Write-Ahead Logging (WAL) logs, to capture data insertion, update, and deletion events. These events are then converted into synchronization tasks and sent to the target database, reducing the data scan scope and synchronization latency. In multi-table synchronization scenarios, related technologies usually construct the data synchronization order based on foreign key relationships or business dependencies between data tables to ensure that tables with dependencies are synchronized in a predetermined order.
[0061] However, existing database synchronization technologies are prone to mismatches between synchronization strategies and actual structural changes when facing frequently changing multi-table heterogeneous synchronization scenarios. For example, when the database table structure continues to change, the full synchronization method still needs to repeatedly scan and transmit a large amount of unchanged data, resulting in the synchronization process consuming a lot of computing and network resources. On the other hand, the incremental synchronization method based on CDC mainly deals with changes in data content. When the table structure changes and affects field types, constraints, or multi-table dependencies, it can easily lead to an increase in the complexity of the synchronization task, thereby affecting the stability of the synchronization link and the end-to-end synchronization timeliness.
[0062] Based on this, the application environment of the data synchronization method provided in this application embodiment is as follows: Figure 1 As shown, the application environment may include a data storage system 100, a server 101, and a terminal 102, which interact and transmit data through a communication network. The data storage system 100 provides the source and target data involved in the synchronization task and stores data such as table structure information, table structure change events, dependencies between tables, synchronization strategies, synchronization duration, and synchronization results. The server 101 executes processing logic such as handling table structure change events, calculating structure evolution entropy, determining synchronization strategies, constructing dependency graphs, and synchronizing multiple tables.
[0063] In some embodiments, the data storage system 100 may include one or more databases such as MySQL, Oracle, and PostgreSQL, or it may include relational databases, distributed databases, data warehouses, or other data storage devices capable of storing structured data. Different databases in the data storage system 100 can serve as the source and target of synchronization tasks, for example, synchronizing data such as orders, payment records, and scheduling plans from a business database to a reporting database or data warehouse. The data storage system 100 may also store historical synchronization records for each data table, synchronization time limits for synchronization tasks, and association information representing foreign key relationships or business dependencies between data tables, for use by the server 101 when executing data synchronization tasks.
[0064] Server 101 can be a single physical server, a server cluster, a distributed computing system, or a cloud server. Server 101 can monitor table structure change events and calculate the structural evolution entropy of the corresponding data table based on the event frequency of different types of table structure change events within a preset statistical window. Based on the structural evolution entropy, it determines the corresponding synchronization strategy. For multiple data tables in the same synchronization task, Server 101 can also obtain the dependencies between the multiple data tables and construct a dependency graph. It organizes the synchronization process of each data table according to the topological order of the dependency graph and performs data synchronization based on the synchronization strategy adopted by each data table and the synchronization time limit of the synchronization task. Server 101 can also record the actual or expected synchronization time of each data table during the synchronization process and adjust the available synchronization time for subsequent data tables based on the synchronization status of the preceding data tables.
[0065] Terminal 102 is used to interact with server 101 and may include a synchronization task configuration terminal, a database maintenance terminal, a synchronization status monitoring terminal, or a synchronization task triggering terminal. For example, terminal 102 can be a personal computer, laptop, tablet, smartphone, or other electronic device capable of performing task configuration and result viewing operations. In some implementations, terminal 102 can submit synchronization tasks to server 101, configure the source database, target database, data tables participating in synchronization, and synchronization time limits, and view the structural evolution entropy, synchronization strategy, synchronization progress, and synchronization results of each data table. In this application environment, when a data table in data storage system 100 undergoes a table structure change, server 101 can obtain the corresponding table structure change event, calculate the structural evolution entropy of the corresponding data table, and determine the synchronization strategy; when multi-table synchronization is required, server 101 completes the corresponding data synchronization operation according to the dependencies between data tables and the synchronization time limits, and can return the synchronization results to terminal 102 for display, or write them to data storage system 100 for subsequent synchronization status query, task tracing, and exception handling.
[0066] To address the aforementioned problems, embodiments of this application provide a data synchronization method. The data synchronization method of this application embodiment will be described in detail below with reference to the accompanying drawings.
[0067] Reference Figure 2 , Figure 2 This is a flowchart illustrating a data synchronization method provided in an embodiment of this application, as shown below. Figure 2 As shown in the embodiment of this application, a data synchronization method may include steps 201 to 204, which are described in detail below.
[0068] 201. In response to a table structure change event, obtain the table structure evolution entropy based on the event frequency of the table structure change event within a preset statistical window;
[0069] In this embodiment, when the fields, indexes, constraints, table names, or other structural attributes of a data table change, a corresponding table structure change event can be generated. This table structure change event characterizes the specific structural changes that occur in the data table. To statistically analyze the structural changes of the data table within a certain range, a corresponding preset statistical window can be set for the data table, and the generated table structure change events can be continuously written into the preset statistical window. The preset statistical window is used to limit the range of table structure change events participating in the current structural change statistics. The window size can be set according to the number of events, the time range, or a combination of both, and it updates as new table structure change events are generated.
[0070] After identifying the table structure change events to be included in the statistics, the events within the preset statistical window can be statistically analyzed according to their event types to obtain the event frequency for each type. The event frequency represents the number of times a corresponding type of table structure change event occurs within the preset statistical window. Based on the event frequencies corresponding to different event types, the distribution of various table structure change events within the current statistical scope can be further determined, and the structural evolution entropy of the data table can be calculated based on this distribution.
[0071] Structural evolution entropy is used to quantify the complexity of table structure changes within a current statistical range. When table structure change events are mainly concentrated in a few event types, it indicates that the table's structural changes are relatively concentrated, and the corresponding structural evolution entropy is low. Conversely, when table structure change events are dispersed across many event types, it indicates that the table's structural changes are more dispersed, and the corresponding structural evolution entropy is high. Therefore, the dispersed and difficult-to-comparate table structure changes within a statistical range can be converted into quantifiable information like structural evolution entropy, which can then be used to determine appropriate synchronization strategies based on the table's structural changes.
[0072] 202. Based on the structural evolution entropy, determine the target synchronization strategy corresponding to the data table;
[0073] After obtaining the structural evolution entropy of the data table, a corresponding target synchronization strategy can be determined based on the changes in the table structure reflected by the structural evolution entropy. The target synchronization strategy specifies the data acquisition, transmission, and target-side writing processes used when synchronizing data from the source end to the target end. In practice, a correspondence between different structural evolution entropy ranges and different synchronization processing methods can be established in advance, and the corresponding synchronization method can be determined based on the current range of the data table's structural evolution entropy. For example, when the structural evolution entropy is low, it indicates that recent table structure changes are mainly concentrated in a few types, and the structural changes are relatively concentrated; a synchronization method adapted to this change state can be adopted. When the structural evolution entropy increases, it indicates that the types of table structure changes are more dispersed; a synchronization method with higher consistency assurance capabilities can be adopted accordingly. Therefore, the structural evolution entropy obtained in step 201 can be further converted into a target synchronization strategy used when the data table actually performs synchronization, allowing the synchronization method to be adjusted according to the current structural change state of the data table.
[0074] 203. Based on the dependencies between multiple data tables in the synchronization task to which the data table belongs, construct a dependency graph;
[0075] After determining the target synchronization strategy for each data table in the synchronization task, it's also necessary to consider that the multiple data tables are not independent of each other and may have certain processing order relationships. Therefore, we can further obtain the dependency relationships between multiple data tables in the same synchronization task and construct a dependency graph based on these relationships. Here, a synchronization task refers to a set of tasks established for a group of data tables that need to be synchronized between the source and target ends; a dependency relationship refers to the association relationship where the synchronization processing of one data table requires the processing result of another data table as a prerequisite. This dependency relationship can be determined based on foreign key associations, master-slave relationships, business processing order, or other information that can indicate the order of data processing between data tables. In the dependency graph, each data table can be treated as a node, and the dependency relationship between data tables can be represented as a directed connection between nodes. For example, when the order table depends on the customer table, and the payment record table depends on the order table, a dependency relationship can be formed where the customer table points to the order table, and then the order table points to the payment record table.
[0076] 204. Following the topological order of the dependency graph, and based on the target synchronization strategy and synchronization time limit of each data table, perform data synchronization operations on multiple data tables.
[0077] After the dependency graph is constructed, the synchronization operations of multiple data tables can be organized according to the topological order determined by the dependency graph. The topological order is the execution order determined by the dependency direction in the dependency graph, ensuring that data tables that are prerequisites can be processed before subsequent data tables that depend on them. For data tables without prerequisite dependencies that already meet the execution conditions, synchronization operations can be executed separately or in parallel. The synchronization time limit limits the time allowed for the entire synchronization task to complete the predetermined synchronization scope. This time limit can be determined based on the data update cycle of the business system, report generation time, data service requirements, or pre-defined synchronization service requirements. During execution, the data tables that currently meet the dependency conditions can be identified according to the topological order, and corresponding data acquisition, transmission, and target end write operations can be performed for the target synchronization strategy determined for these data tables. Simultaneously, the synchronization process of each data table is controlled by the synchronization time limit of the entire synchronization task. After the current data table is synchronized, the subsequent data tables that meet the execution conditions are identified according to the dependency graph, until all data tables in the synchronization task are synchronized. Therefore, the aforementioned target synchronization strategy determined for a single data table can be further combined with the multi-table dependencies and overall time limit requirements for execution. This allows each data table to not only be synchronized according to its dependencies, but also to be coordinated with the completion time requirements of the entire synchronization task. This reduces the possibility that the increased synchronization time of preceding data tables will encroach on the available synchronization time of subsequent data tables, thereby causing the synchronization task to time out.
[0078] like Figure 3As shown, the data synchronization system of this application embodiment can be divided into a data source layer, a perception layer, a decision layer, an execution layer, and a verification layer according to the data processing process. The data source layer is used to access heterogeneous databases such as MySQL, Oracle, and PostgreSQL, and obtain data definitions or data operation events of data tables. The perception layer classifies the captured table structure change events, writes the corresponding events into a sliding window, counts the occurrence of different change types, and calculates the structural evolution entropy to reflect the complexity of data table structure changes. At the same time, it can further judge the predictability of the current structural change based on the entropy value. The decision layer determines the corresponding synchronization strategy according to the structural evolution entropy and the time requirements of the synchronization task, such as full synchronization, incremental synchronization, incremental synchronization based on change data capture, or locked full synchronization, so that the synchronization method can be adjusted according to the changes in the data table structure. The execution layer constructs a directed acyclic graph based on the dependencies between multiple data tables and performs cascading synchronization of multiple tables in topological order. Simultaneously, it monitors the actual synchronization time of each data table and adjusts the synchronization schedule of subsequent data tables accordingly when the synchronization time of preceding data tables changes. During synchronization, the node information of the current synchronization task can be recorded and transmitted through the thread context to facilitate anomaly location and task tracing. After synchronization is complete, the verification layer compares the data checksums, version numbers, and data row counts of the source and target ends. If the comparison matches, synchronization is confirmed to be complete; if the comparison does not match, rollback, retry, or readjustment of the synchronization strategy are executed to improve the reliability of the entire multi-table synchronization process.
[0079] In some embodiments, in response to a table structure change event of a data table, the structural evolution entropy of the data table is obtained based on the event frequency of the table structure change event within a preset statistical window. This includes: identifying the event type corresponding to the table structure change event and writing the event type into the preset statistical window corresponding to the data table; counting the event frequency and total number of events corresponding to each event type within the preset statistical window; determining the occurrence probability of each event type based on the event frequency and total number of events; and calculating the structural evolution entropy of the data table based on the occurrence probability of each event type.
[0080] In this embodiment, a preset statistical window is maintained for each data table to track changes in its table structure, thus preventing interference between table structure change events from different data tables. The table structure, also known as the database schema, describes the table's fields, data types, indexes, constraints, and other structural attributes. The preset statistical window can be implemented using a first-in-first-out (FIFO) sliding window, with a window capacity W set, for example, to 500 table structure change events. In practical applications, a data table can be associated with its corresponding statistical window using a table identifier, such as `table_id` or a combination of `schema_name` and `table_name`. When a data table is detected to have undergone Data Definition Language (DDL) changes such as `ADD_COLUMN`, `DROP_COLUMN`, or `ALTER_TYPE`, the corresponding statistical window is determined based on the data table that caused the change, and the identified event type is written into that statistical window. Therefore, each data table calculates its structural evolution entropy based on its most recent range of DDL change events, enabling the schema evolution of different data tables to be quantified separately, which facilitates the selection of synchronization strategies for the corresponding data tables during multi-table synchronization.
[0081] Specifically, K=12 types of table structure change events can be pre-set, and the event frequency of each event type in the statistics window can be counted. For the i-th type of event, let the event frequency of the i-th type of event be c. i If the total number of valid events in the statistics window is n, then the probability p of this event type occurring is... i For c i / n. Furthermore, the structural evolution entropy H of the data table is calculated using Shannon entropy. schema :
[0082] ;
[0083] The summation range is defined by K preset event types; when a certain event type does not appear in the current statistics window, i.e., p... i When = 0, it is agreed that This avoids logarithmic aberrations. Structural evolution entropy reflects the distribution of different table structure change types within a statistical window: when DDL events are mainly concentrated in a few event types, the structural evolution entropy is low; when the probability of different DDL event types tends to be dispersed, the structural evolution entropy increases accordingly. Since the above structural evolution entropy is calculated using a base-2 logarithm, the calculation result can be represented in bits. When all data tables use the same event classification method and calculation rules, the changes in table structure of different data tables can be directly compared based on the magnitude of the structural evolution entropy.
[0084] When selecting an entropy function for calculating structural evolution entropy, it is necessary to consider not only whether the entropy function can reflect the concentration or dispersion of various table structure change events, but also whether the results obtained from different data tables according to the same rules are easy to compare directly, and whether it is easy to use a unified entropy value range for synchronization strategy judgment.
[0085] Based on the above considerations, the embodiments of this application can use Shannon entropy for calculation. Shannon entropy is determined according to the probability of occurrence of various table structure change events. When events are mainly concentrated in a few types, the calculated entropy value is small; when events are dispersed across many types and the probability of occurrence of each type gradually approaches, the calculated entropy value is large. Therefore, the numerical change of Shannon entropy corresponds to the degree of dispersion of table structure change types to be described in this application.
[0086] Considering that the statistics window will not fill up immediately during system startup, when determining the probability of occurrence of each event type, statistics can be based on the valid DDL events actually collected in the current statistics window, without being limited to requiring the statistics window to reach 500 records before calculation. For example, when the statistics window currently only has 100 valid events collected, the corresponding probability of occurrence can be determined directly based on the actual number of occurrences of each event type in these 100 events. This ensures that the calculation results reflect the currently collected table structure changes and avoids affecting the probability calculation results due to the statistics window not yet being full. When the number of valid events is small, although calculations can continue and H can be updated... schema However, the synchronization strategy can be switched temporarily without relying on the entropy value. For example, 200 table structure changes can be set as the threshold for determining whether the sample has reached the stable statistical requirements. If there are fewer than 200 valid events within the statistical window, events can continue to be collected and the current synchronization strategy can be maintained. Only after 200 events are reached can the structural evolution entropy be allowed to participate in the synchronization strategy switch, so as to reduce misjudgments caused by the sparse sample in the initial startup phase.
[0087] To reduce the processing overhead of re-traversing all events every time the window is updated, an incremental statistical approach can be used to maintain the statistical window. For each data table, an event frequency array `count_per_type` corresponding to each event type, the current total number of valid events `total_count`, the current structure evolution entropy `current_H`, and an event type queue for FIFO eviction can be maintained. When a new DDL event enters the statistical window, the event frequency of the corresponding category in `count_per_type` is increased according to the event type. When the statistical window reaches its capacity limit of 500 entries, the earliest event type entering the window is retrieved from the FIFO queue, the event frequency of the corresponding category is decreased, and then the new event type is added. Subsequently, the p values for each event are determined based on the updated `count_per_type` and `total_count`. i And update current_H. Since the structural evolution entropy depends only on the frequency and total number of events of each event type, and not on the complete details of each event in the window, when the event category K is fixed at a preset value (e.g., 12), each update only needs to adjust the statistical information corresponding to the incoming and outgoing events, and complete the entropy update based on a fixed number of category statistical values. There is no need to rescan the 500 events in the window. Therefore, the amount of work required to update the statistical results when a new DDL event arrives is basically fixed, and the processing time will not increase significantly because there are already 100, 500 or even more events stored in the sliding window.
[0088] Furthermore, structural evolution entropy can be used to determine whether current table structure changes are primarily concentrated on a certain event type. Specifically, the event type with the highest probability of occurrence within the current statistical window can be considered the dominant change type, and the probability P of this dominant change type can be determined based on the structural evolution entropy H. major The lowest reference value, i.e., P major ≥2 -H When the dominant change type is used as the prediction result for the next table structure change type, the corresponding prediction error probability P err Satisfy P err ≤1-2 -H In other words, the smaller the structural evolution entropy, the more concentrated the table structure changes are on a few types, making it relatively easier to predict the type of change to occur next; conversely, the larger the structural evolution entropy, the more dispersed the changes to different types of table structures are, making it relatively more difficult to predict which type of change will occur next. Therefore, structural evolution entropy can be used to further determine whether the current table structure is stable.
[0089] In some embodiments, identifying the event type corresponding to a table structure change event includes: parsing the data definition statement that caused the table structure change event to obtain at least one structure change operation; splitting the structure change operation according to a preset splitting rule to obtain the structure change event corresponding to the structure change operation; determining the preset event type corresponding to the structure change event based on the change content in the structure change event, and updating the event frequency corresponding to the preset event type.
[0090] In this embodiment, the data definition language (DDL) statement that triggers a table structure change event can be parsed to identify the involved structure change operations. These operations can then be broken down into atomic change granularities, ensuring that each structure change event corresponds to a relatively independent schema change. For example, if a DDL statement simultaneously modifies field types, default values, and non-null constraints, these modifications can be separated into independent structure change events, and the corresponding preset event type can be determined based on the change content within each event. The preset event types include 12 categories: ADD_COLUMN (add field), DROP_COLUMN (delete field), MODIFY_COLUMN (modify field), MODIFY_TYPE (modify field type), ADD_INDEX (add index), DROP_INDEX (delete index), ADD_CONSTRAINT (add constraint), DROP_CONSTRAINT (delete constraint), RENAME_COLUMN (rename field), RENAME_TABLE (rename table), TRUNCATE (clear table data), and ALTER_COMMENT (modify comment). For attribute modifications such as default values and NOT NULL constraints, they can be categorized into the corresponding preset event types according to predefined classification rules. After event classification, the event frequency of the corresponding event type is updated and used for subsequent structural evolution entropy calculations. When changes such as ADD_COLUMN, DROP_COLUMN, and ALTER_TYPE occur in the schema, a FIFO sliding window with a capacity of W=500 rows can be used to count various change events and categorize them according to... Calculate the Shannon entropy. During window updates, only the frequency of newly entered events and eliminated events within their respective categories is adjusted. This way, when a new table structure change event enters the statistics window, only the count of that event's category needs to be increased; when the statistics window is full and the oldest event is removed, the count of the removed event's category is decreased. Then, the structure evolution entropy is recalculated based on the updated event counts. This eliminates the need to reread and count all 500 events in the statistics window each time, thus reducing the computational load during window updates. For example, if ADD_COLUMN occurs 250 times (p=0.50), ALTER_TYPE occurs 100 times (p=0.20), ADD_INDEX occurs 75 times (p=0.15), and the remaining 75 events occur 50 and 25 times respectively, the complete probability distributions are 0.50, 0.20, 0.15, 0.10, and 0.05, corresponding to a structure evolution entropy of approximately 1.923 bits.
[0091] In some embodiments, determining the target synchronization strategy corresponding to the data table based on the structural evolution entropy includes: determining the synchronization strategy range corresponding to the data table based on the structural evolution entropy; determining the candidate synchronization strategy corresponding to the data table based on the synchronization strategy range corresponding to the data table; obtaining the most recent strategy switching time of the data table; and determining the candidate synchronization strategy as the target synchronization strategy corresponding to the data table if the time interval between the current time and the most recent strategy switching time reaches a preset switching interval.
[0092] Please refer to Figure 3 In this embodiment, a Threshold Backpressure Strategy (TBLB) can be constructed based on structural evolution entropy to convert the current schema evolution state of the data table into a corresponding synchronization strategy interval. Specifically, multiple synchronization strategy intervals can be set according to the structural evolution entropy H from low to high, and corresponding synchronization strategies can be configured for different intervals. As the structural evolution entropy H increases, it indicates that the types of recent table structure changes in the data table are more dispersed and the changes are more difficult to predict. Therefore, a synchronization strategy with higher consistency assurance capability can be selected accordingly. The correspondence between the above structural evolution entropy and synchronization strategy can be expressed as a backpressure function B(H). Here, the synchronization strategy interval refers to several intervals divided according to the value range of the structural evolution entropy, and each interval corresponds to a candidate synchronization strategy. The candidate synchronization strategy refers to the synchronization method that can be used for subsequent execution judgment based on the current structural evolution entropy. The target synchronization strategy is the strategy finally determined for the current data table synchronization after the candidate synchronization strategies meet the strategy switching conditions. Through the above settings, it is possible to avoid directly selecting the synchronization method based on a single schema change event, but instead to make strategy judgments based on the overall distribution of schema change types over a period of time.
[0093] In one specific implementation, three policy switching inflection points can be set to divide the structural evolution entropy into four synchronization policy intervals. For example, when H schema When H is in the range [0, 0.5), the candidate synchronization strategy is determined to be FULL_SYNC, i.e., full synchronization; when H schema When H is in the range [0.5, 1.5), the candidate synchronization strategy is determined to be INCREMENTAL, i.e., incremental synchronization; when H schema When H is in [1.5, 2.5), the candidate synchronization strategy is determined to be CDC+INCREMENTAL, that is, incremental synchronization based on CDC captured by changed data; when H schema When the entropy is not less than 2.5, the candidate synchronization strategy is determined to be FULL_SYNC+LOCK, i.e., full synchronization with lock. The above four ranges correspond to different levels of schema change uncertainty: at low entropy, the change types are relatively concentrated, and FULL_SYNC can be used for overall synchronization and verification; at medium entropy, the change types are somewhat dispersed, and INCREMENTAL can be used to reduce synchronization overhead; at high entropy, the change types are further dispersed, and CDC+INCREMENTAL can be used to obtain change information and perform incremental synchronization; when the entropy value is in an even higher range, the schema change types tend to be uniform, and the dominant change type is not obvious, and FULL_SYNC+LOCK can be used to reduce the impact of concurrent schema changes on data consistency during synchronization.
[0094] Furthermore, the aforementioned synchronization strategy interval can be set based on the degree of concentration of table structure changes reflected by the structural evolution entropy. Specifically, within the current statistical window, the table structure change type that occurs most frequently can be taken as the dominant change type, and the probability of this type occurring can be denoted as P. major When the structural evolution entropy is low, it indicates that most table structure changes are concentrated in a few types, and the proportion of dominant change types is usually high. As the structural evolution entropy increases, various table structure changes gradually disperse, the proportion of dominant change types decreases accordingly, and it becomes more difficult to determine what type of change will occur later.
[0095] To quantify the above relationships, let the probability distribution of various table structure change events within the current statistical window be P = {p1, ..., p...} K}, the probability P of the dominant change type major =max(p i According to the properties of Shannon entropy, P can be obtained. major ≥2 (-H(P)) For example, when H = 0.5 bits, P major ≥0.707; when H=1.5 bits, Pmajor ≥0.354; when H=2.5 bits, P major ≥0.177. In other words, the higher the entropy value, the less prominent the types of changes that can occupy a dominant position, and the more dispersed the changes in table structure.
[0096] Furthermore, P can be... err =1-P major As a reference for determining the degree of difficulty in identifying the type of table structure change, we have P. err ≤1-2 (-H(P)) For example, when H = 0.5 bits, P err ≤0.293; when H=1.5 bits, P err ≤0.646; when H=2.5 bits, P err ≤0.823. Therefore, different synchronization strategy ranges can be set according to the relationship between the above entropy value and the concentration of change types: when the structural evolution entropy is low, a synchronization strategy with relatively low processing overhead is adopted; as the structural evolution entropy increases, a synchronization strategy with higher consistency guarantee capability is gradually adopted, so that the synchronization strategy matches the actual table structure changes of the current data table.
[0097] In another implementation, the strategy switching inflection point can be dynamically determined based on the actual rate of change of structural evolution entropy, with the spacing between adjacent inflection points being determined accordingly. Let ΔH max Δt represents the maximum change in structural evolution entropy per unit time, and its unit can be bits / s; hyst Let represent the policy switching hysteresis parameter, with units of seconds (s). The distance d between adjacent policy switching inflection points can be calculated using d = ΔH. max ×Δt hyst It is confirmed that the unit of the obtained d is bits. ΔH max It can be obtained statistically from historical schema evolution data, or dynamically determined based on the entropy fluctuation range observed during operation. Δt hyst It is used to reflect the stable time range that we want to maintain when adjusting the strategy. The policy interval is determined by the rate of change of structural evolution entropy and the hysteresis time. This can reduce the frequent switching caused by excessively dense thresholds, and also avoid the slow response of policy adjustment caused by excessively wide thresholds.
[0098] When actually implementing a strategy switch, a preset switching interval can be set to limit the shortest time between two strategy switches for the same data table. This preset switching interval can be denoted as Δt. min For example, it can be set to 30 seconds. After determining the candidate synchronization strategy, the time of the most recent strategy switch in the data table can be obtained, and the time interval between the current time and the most recent strategy switch time can be calculated. When this time interval is less than Δtmin Even if the current structural evolution entropy has entered the range of other synchronization strategies, the original synchronization strategy can be temporarily maintained, while new table structure change events continue to be collected and the structural evolution entropy is updated; when this time interval reaches Δt min Then, based on the latest structural evolution entropy at that time, a candidate synchronization strategy is determined, and a decision is made on whether to execute a strategy switch. For example, when Δt min When the time limit is 30 seconds, the same data table will not execute a new strategy switch within 30 seconds after the last strategy switch, thereby reducing the frequent back-and-forth switching caused by the fluctuation of structural evolution entropy near the interval boundary.
[0099] It should be noted that Δt hyst and Δt min They are used to solve different problems. Δt hyst It is mainly used to determine the appropriate interval between adjacent synchronization strategy intervals, and Δt min This is used to limit how frequently the synchronization strategy actually switches. For example, Δt can be used... min Set the interval to 30 seconds. When preparing to switch synchronization strategies, first read the last strategy switch time for the data table and calculate how much time has passed since then. If less than 30 seconds have passed, even if the current structural evolution entropy has entered another synchronization strategy interval, temporarily continue using the original synchronization strategy and do not switch immediately; during this period, continue to collect new table structure change events and update the structural evolution entropy. When 30 seconds have passed since the last strategy switch, re-determine which synchronization strategy to use based on the latest structural evolution entropy. This avoids frequent switching between the two strategies when the entropy value fluctuates around the interval boundary.
[0100] If the structural evolution entropy changes significantly, directly crossing two or more synchronization strategy intervals, the candidate synchronization strategy can be determined directly based on the interval containing the latest entropy value. For example, if the current data table previously used INCREMENTAL, and the new structural evolution entropy has entered the interval corresponding to FULL_SYNC+LOCK, FULL_SYNC+LOCK can be directly used as the candidate synchronization strategy without first switching to CDC+INCREMENTAL. It's important to note that even with such cross-interval changes, the aforementioned Δt must still be satisfied when actually executing the strategy switch. min The corresponding preset switching interval.
[0101] In some embodiments, data synchronization operations are performed on multiple data tables according to the topological order of the dependency graph, based on the target synchronization strategy and synchronization time limit of each data table, including: for the current data table in the dependency graph, determining at least one dependency path to the current data table; determining the upstream cumulative time corresponding to the current data table based on the synchronization time corresponding to the data table upstream of the current data table in each dependency path; determining the remaining synchronization time of the current data table based on the synchronization time limit and the upstream cumulative time; performing data synchronization operations on the current data table based on the remaining synchronization time and the target synchronization strategy corresponding to the current data table; after the data synchronization operation of the current data table is completed, performing data synchronization operations on the next data table according to the topological order of the dependency graph, until the data synchronization operations of multiple data tables are completed.
[0102] Furthermore, based on the synchronization time of the data table upstream of the current data table in each dependency path, the upstream cumulative time corresponding to the current data table is determined, including: accumulating the synchronization time of the data table upstream of the current data table in each dependency path to obtain the path synchronization time corresponding to each dependency path; comparing the path synchronization times corresponding to each dependency path and determining the largest path synchronization time as the upstream cumulative time; and updating the remaining synchronization time corresponding to the current data table and its downstream data tables based on the upstream cumulative time.
[0103] In this embodiment, the foreign key relationships or business dependencies between N data tables in the synchronization task can be constructed as a Directed Acyclic Graph (DAG). Each data table corresponds to a node in the dependency graph, and the dependencies between data tables correspond to directed connections between nodes. For the current data table, at least one dependency path leading to it can be determined by working backwards from the dependency graph. The directly and indirectly dependent data tables preceding the current data table are considered its upstream data tables. This not only determines the topological execution order of each data table based on the DAG, but also gradually determines the remaining synchronization time for subsequent data tables based on the synchronization time consumed by the already executed upstream data tables. This allows the dependency graph to simultaneously handle both synchronization order organization and synchronization time propagation.
[0104] Specifically, for node i in the dependency graph, the remaining synchronization duration can be represented as Budget_remaining(i), the synchronization time limit of the synchronization task can be represented as D_SLA, the upstream data table set can be represented as Ancestors, and the upstream node j adopts synchronization strategy s. j The synchronization time generated is represented by d. j (s jIf the remaining synchronization time of node i is calculated as Budget_remaining(i) = D_SLA - ΣAncestors d, then the remaining synchronization time of node i can be calculated as Budget_remaining(i) = D_SLA - ΣAncestors d. j (s j The Hoeffding margin is determined. Here, D_SLA represents the maximum allowed completion time set for the entire synchronization task according to the Service Level Agreement (SLA); Ancestors includes the current node's direct upstream nodes and indirect ancestor nodes; d j (s j The value represents the estimated synchronization delay for node j after adopting the corresponding synchronization strategy. This estimated delay can be obtained by combining historical synchronization records, the current data size, and the prediction results of the synchronization delay model, reflecting the expected time taken by the node under the current synchronization conditions. The Hoeffding margin is used to reserve for random time fluctuations that may occur during synchronization execution. This margin can be determined based on the Hoeffding inequality and the set confidence level, thereby avoiding the possibility that random factors such as network fluctuations and database load changes could cause the entire synchronization task to exceed the SLA requirements when the budget is allocated solely according to the expected synchronization duration.
[0105] For dependency paths containing only serial dependencies, the synchronization time of each upstream data table preceding the current data table along that path can be accumulated to obtain the path synchronization time of that dependency path. When the current data table can be reached by multiple dependency paths, the path synchronization time corresponding to each dependency path is calculated separately, and the largest path synchronization time is taken as the upstream accumulated time of the current data table to determine the actual time already occupied before the current data table.
[0106] For example, if two upstream data tables point to the current data table through different branches, and they can be synchronized in parallel, the current data table needs to wait for the branch with the longer execution time to complete before it can continue. Therefore, the dependency path with the longest execution time is used as the reference for the time consumption budget during data synchronization. For common ancestor nodes that appear in multiple dependency paths, the synchronization time is calculated only once in the corresponding path, thus avoiding repeated deduction of synchronization time due to path overlap.
[0107] After obtaining the cumulative upstream time for the current data table, the remaining synchronization time for the current data table can be obtained by subtracting this cumulative upstream time and the Hoeffding margin for handling random fluctuations in synchronization time from the synchronization time limit of the synchronization task. Subsequently, synchronization operations are performed based on the remaining synchronization time and the target synchronization strategy already determined for the current data table. If the synchronization strategy used by the preceding data table changes, causing a change in its actual or expected synchronization time, the remaining synchronization time available for the current data table and its downstream data tables is updated accordingly and continues to propagate downstream along the topological direction of the dependency graph. Therefore, the strategy selection and synchronization time of the upstream node directly affect the available synchronization time of the downstream node.
[0108] In a further implementation, the maximum tolerable schema evolution entropy can also be determined by combining the dependency chain length L. Where L represents the number of data tables contained in the dependency chain of the current data table. This represents the maximum acceptable degree of structural evolution under the current dependency chain length, remaining synchronization time, and SLA constraints. As the dependency chain length increases, the synchronization time occupied by upstream tables typically increases, correspondingly reducing the remaining synchronization time available for downstream tables, thus lowering the maximum allowable structural evolution entropy. For example, when the schema evolution entropy H of a certain table is 2.0, if only the table itself is considered, the synchronization time may still be within the acceptable range; however, when the table is in a longer dependency chain, multiple preceding tables have already consumed some synchronization time, compressing the available time for the current and subsequent tables. In this case, the original target synchronization strategy is not applicable to the current remaining synchronization time. Therefore, it can be combined with... The remaining synchronization time is updated, and the corresponding synchronization strategy is reassessed. Finally, the executable data tables are processed sequentially according to the topological order of the dependency graph. After each data table is synchronized, the remaining synchronization time of subsequent data tables is updated until multiple data tables in the synchronization task are completed. This reduces the risk that a single data table can be completed on time, but the entire multi-table synchronization link eventually exceeds the synchronization time limit.
[0109] In some embodiments, executing the target synchronization strategy corresponding to the current data table based on the remaining synchronization duration includes: obtaining the estimated synchronization duration of the current data table when the target synchronization strategy is adopted; comparing the estimated synchronization duration with the remaining synchronization duration; if the estimated synchronization duration is not greater than the remaining synchronization duration, performing data synchronization operation on the current data table according to the target synchronization strategy; if the estimated synchronization duration is greater than the remaining synchronization duration, redetermining the synchronization strategy corresponding to the current data table based on the structural evolution entropy and the remaining synchronization duration; updating the estimated synchronization duration of the current data table according to the redetermined synchronization strategy, and determining the remaining synchronization duration of the downstream data table based on the updated estimated synchronization duration.
[0110] In this embodiment, after determining the remaining synchronization time of the current data table, it can be further determined whether the original target synchronization strategy for the current data table can still be completed within the remaining synchronization time. Specifically, the expected synchronization time of the current data table when adopting the target synchronization strategy can be obtained based on information such as the data size of the current data table, historical synchronization records, and historical execution status under the corresponding synchronization strategy. When the expected synchronization time is not greater than the remaining synchronization time, it indicates that after executing the current target synchronization strategy, the current data table still has a high probability of completing synchronization within its allocated time range, and therefore the data synchronization operation can continue to be executed according to the target synchronization strategy; when the expected synchronization time is greater than the remaining synchronization time, it indicates that executing the original target synchronization strategy may take too much time, and it is necessary to reselect the synchronization strategy based on the structural evolution entropy of the current data table and the remaining synchronization time.
[0111] In one implementation, the synchronization strategies that the current data table can choose can be represented as the feasible strategy space F. i Let s represent any synchronization strategy in the set of candidate synchronization strategies, and H i d represents the structural evolution entropy of the current data table i. i (s) represents the estimated synchronization time when the current data table i adopts synchronization strategy s, Budget_remaining(i) represents the remaining synchronization budget of the current data table i, i.e., the aforementioned remaining synchronization time, and Desc_MinDelay(i) represents the minimum time required for its downstream data tables to continue to complete synchronization after the current data table has completed. Then the feasible strategy space F i It can be represented as:
[0112] F i ={s|d i (s)+Desc_MinDelay(i)≤Budget_remaining(i), and H i ≤ Upper limit of structural evolution entropy allowed by the corresponding strategy}.
[0113] The above conditions indicate that two aspects need to be considered simultaneously when determining whether a synchronization strategy can be adopted. Firstly, the sum of the estimated synchronization time occupied by the current data table using this strategy and the time required for the downstream data table to continue synchronization should not exceed the current remaining synchronization time, to avoid the current data table consuming all the synchronization time needed by subsequent data tables. Secondly, the structural evolution entropy of the current data table also needs to be within the range where the synchronization strategy is currently applicable, to avoid choosing a synchronization strategy that is clearly mismatched with the current table's structural changes in order to shorten synchronization time. In other words, a synchronization strategy can only be considered as an option if the time required for the current table to execute according to the strategy, plus the time that the downstream table must retain, does not exceed the current remaining time, and the current structural evolution entropy is still within the range allowed by the strategy.
[0114] The upper limit of structural evolution entropy allowed by each synchronization strategy can be dynamically determined based on the current operating conditions. Specifically, the maximum acceptable range of structural evolution entropy under the current conditions can be determined by combining information such as the length of the dependency chain containing the current data table, the current remaining synchronization time, the data size of the data table, and historical synchronization results. For example, when the dependency chain is long or the remaining synchronization time is short, more processing time needs to be reserved for subsequent data tables, and the applicable scope of some time-consuming strategies can be narrowed accordingly; when the remaining synchronization time is sufficient, synchronization strategies with higher consistency guarantee capabilities but relatively longer expected synchronization time can be selected. Thus, the applicable conditions of the synchronization strategy can be adjusted according to the actual execution of the current synchronization task.
[0115] Determine the feasible strategy space F iThen, a synchronization strategy with higher consistency guarantee capability can be selected as the redefined synchronization strategy. In one implementation, the consistency guarantee capability of different strategies can be set from high to low in the order of FULL_SYNC+LOCK, FULL_SYNC, CDC+INCREMENTAL, INCREMENTAL, and NOTIFY. FULL_SYNC+LOCK represents full synchronization with locking, which reduces the possibility of data inconsistency caused by structural changes during full synchronization by adding lock control; FULL_SYNC represents full synchronization; CDC+INCREMENTAL represents incremental synchronization based on CDC capture of changed data; INCREMENTAL represents incremental synchronization; NOTIFY indicates that under the current synchronization conditions, the aforementioned synchronization method is not directly used, but notification or subsequent exception handling is triggered. When multiple strategies satisfy the constraints of structural evolution entropy and remaining synchronization time, the strategy with higher consistency guarantee capability can be prioritized. That is, synchronization strategies that cannot be completed in time can be filtered out first based on the remaining synchronization time, and then the strategy that is suitable for the current structural changes and has a higher consistency guarantee capability can be selected from the remaining feasible strategies.
[0116] After re-determining the synchronization strategy, the estimated synchronization duration of the current data table can be recalculated based on the new strategy. Since the actual synchronization time used by the current data table changes, the remaining synchronization duration available to downstream data tables will also change. Therefore, the remaining synchronization duration of downstream data tables can be updated along the topological direction of the dependency graph. When a change in the strategy of an upstream data table reduces the remaining synchronization duration of a downstream data table, causing its original synchronization strategy to no longer belong to its new feasible strategy space, the above strategy filtering process can be repeated for that downstream data table and continue to propagate to even more downstream data tables.
[0117] In some embodiments, determining the remaining synchronization duration of the current data table based on the synchronization time limit and the cumulative upstream time consumption includes: obtaining the historical synchronization duration of each data table in the synchronization task; determining the reserved duration corresponding to the synchronization task based on the historical synchronization duration of each data table and the preset timeout probability; and subtracting the cumulative upstream time consumption and the reserved duration from the synchronization time limit to obtain the remaining synchronization duration of the current data table.
[0118] In this embodiment, to avoid the impact of network jitter, database load changes, and other factors on scheduling synchronization tasks solely based on the estimated synchronization time of each data table, a certain amount of time can be reserved for synchronization tasks based on historical synchronization duration. Historical synchronization duration refers to the actual synchronization time recorded for each data table during historical synchronization, and can be statistically analyzed separately for each data table, synchronization strategy, and synchronization task. The system can measure the synchronization time D in real time through the latency monitoring module. syncThe system generates synchronization time statistics for each data table using historical synchronization records. Based on this, a reserved timeout period is determined for each synchronization task according to the historical synchronization duration of each data table and the preset timeout probability. The preset timeout probability represents the probability that the actual synchronization time will exceed the sum of the expected synchronization time and the reserved timeout period. For example, a preset timeout probability of 0.01 indicates that the expected timeout rate is to be controlled within 1%, with a corresponding confidence level of 99%. The reserved timeout period can be determined based on the fluctuations in actual synchronization time and the required reliability of the synchronization task.
[0119] In one implementation, the Hoeffding inequality can be used to determine the reservation time. For the j-th data table in the synchronization task, the corresponding time fluctuation parameter b can be determined based on the historical synchronization time of the data table or the synchronization time prediction result. j The time consumption fluctuation parameter reflects the potential fluctuation range of the synchronization time for this data table. For a synchronization task containing N data tables, the b parameter for each data table can be obtained separately. j And calculate the sum of the squares of each time-consuming fluctuation parameter, i.e., Σb j ² = b1² + b2² + … + b N ² reflects the fluctuation in the synchronization time of each data table during the entire synchronization task.
[0120] Let the preset timeout probability be ε, and the required timeout duration for the synchronization task be t. Then, we can use exp(-2t² / Σb) j ²) = ε determines t, that is, t = √[Σb j 2×ln(1 / ε) / 2]. Here, t is the extra time reserved to cope with possible fluctuations in synchronization time during the actual process. For example, when ε is set to 0.01, it means that after calculating the reserved time according to this parameter, it is hoped that the actual synchronization time will exceed the sum of the expected synchronization time and the reserved time in about 1% of cases. The greater the historical fluctuation in synchronization time, the longer the reserved time usually needs to be; the lower the allowed timeout probability is set, the stricter the requirement for synchronization completion time, and the more the reserved time needs to be.
[0121] The time consumption fluctuation parameter can also be determined by considering the current data table structure evolution, network communication status, and the number of data tables included in the synchronization task. For example, it can be determined by: Determine the time consumption fluctuation parameters corresponding to the i-th data table. Here, H represents the structural evolution entropy of the data table; d netThe network communication latency during the synchronization process is represented by N; N represents the total number of data tables involved in the current synchronization task, reflecting the task scale of the entire directed acyclic graph (DAG). The number of nodes in a single dependency chain can be represented by L. For example, if the dependency chain "borrower table → contract table → interest rate table → repayment plan table" includes 4 data tables, then L=4 for this dependency chain, while N still represents the total number of data tables actually involved in the entire synchronization task.
[0122] For d net This can be determined based on historical synchronization records, network test results, or actual communication time collected during system operation. When the network environment used by each data table is basically the same, a unified d can be used. net When there are significant differences in the data source, target, or network link corresponding to different data tables, the corresponding d can be determined separately for each data table. net .
[0123] In the above formula, α represents the degree of influence of structural evolution entropy on synchronization time, with units such as ms / bit. For example, when the structural evolution entropy of a data table increases, structural processing and synchronization processing may require more time, and this influence can be reflected by α; β represents the degree of influence of network communication latency on synchronization time; γ represents the increased time required for task scheduling, dependency coordination, and other processing among multiple data tables, with units such as ms; δ represents the base time typically required to perform a synchronization operation, with units such as ms, which may include the time spent on data parsing, serialization, and other processing. α, β, γ, and δ can be preset using historical synchronization data and adjusted according to the actual system operation. It should be noted that δ here represents a fixed baseline time.
[0124] For example, a certain synchronization task involves N=44 data tables, the current data table structure evolution entropy H=1.54 bits, and the network communication delay d net =5ms, and taking α=50ms / bit, β=1.5, γ=10ms, δ=20ms, then we can calculate: b i =50×1.54+1.5×5+10×log2(44)+20≈159.1ms, or approximately 0.1591s. Assuming the above 44 data tables use the same time-consuming fluctuation parameter, then Σb i =44 × 0.1591² ≈ 1.1137s². When the preset timeout probability ε = 0.01, substituting it into exp(-2t² / 1.1137) = 0.01, we can calculate t ≈ 1.601s. Therefore, an additional 1.601s can be reserved for this synchronization task to accommodate the increased synchronization time caused by factors such as network fluctuations and changes in database load.
[0125] Furthermore, the estimated overall synchronization time required under the current DAG topology and the synchronization strategies adopted by each data table can be denoted as E[D], and the actual time spent executing the synchronization task can be denoted as D. In this case, E[D] + t can be used as the reference completion time for scheduling synchronization tasks under the current timeout probability requirement. For example, when E[D] = 0.65s, and the aforementioned calculation yields t ≈ 1.601s, the corresponding reference completion time is approximately 0.65 + 1.601 = 2.25s. That is, when the timeout probability ε is set to 0.01, 1.601s is reserved based on historical time fluctuations, so that the actual synchronization time exceeding 2.25s is controlled to within approximately 1%. If actual testing shows that 99% of synchronization tasks can be completed within approximately 1.89s, and 1.89s is less than 2.25s, it indicates that the reserved time calculated based on historical synchronization conditions and the preset timeout probability can cover most of the synchronization time fluctuations in the current test scenario.
[0126] After determining the reserved time, for the current data table in the dependency graph, the remaining synchronization time can be calculated by first deducting the synchronization time already used by the upstream data table from the total allowed synchronization time limit of the entire synchronization task, and then deducting the time reserved for potential time fluctuations. The remaining portion is then used as the remaining synchronization time available for the current data table. In other words, the total synchronization time in this application's data synchronization method needs to be divided into three parts: the time already used by the upstream data table, the time reserved for potential subsequent time fluctuations, and the actual time that the current and subsequent data tables can still use. The remaining synchronization time obtained in this way can more accurately reflect how much time is left for the current synchronization task and can be further used to determine whether the originally determined synchronization strategy for the current data table can still be executed.
[0127] like Figure 3 As shown, the embodiments of this application can complete multi-table data synchronization through structural evolution entropy calculation, synchronization strategy selection, DAG cascading synchronization, and consistency verification. For example, if 1000 schema changes are captured within 10 minutes during the tax filing period, including 300 ADD_COLUMN changes, 250 MODIFY_COLUMN changes, 200 MODIFY_TYPE changes, 100 ADD_INDEX changes, 80 DROP_INDEX changes, and 10 changes for each of the other 7 categories, then the probabilities of each type of event are 0.30, 0.25, 0.20, 0.10, 0.08, and 0.01, respectively. The calculated structural evolution entropy H is approximately 2.574 bits, from which P is derived. major ≥2 -2.574 ≈0.168, P err≤0.832. Since H is in the range [2.5, 3.585], FULL_SYNC+LOCK, i.e., a full synchronization strategy with locking, can be selected. For a synchronization task containing 44 data tables, a DAG can be constructed based on foreign key relationships, such as forming a dependency chain of "borrower → contract → interest rate → repayment plan", and synchronization can be performed according to the topology hierarchy: the first round of parallel synchronization of 5 core tables takes 0.3s, the second round of 12 sub-tables takes 0.4s, the third round of 15 third-level tables takes 0.5s, and the remaining 12 end tables in the fourth to sixth rounds take a total of 0.69s, so the total time to complete the synchronization of 44 tables is about 1.89s (12-18 minutes in traditional solutions). After synchronization is complete, the SM3 Cryptographic Hash Algorithm checksum, number of data rows, and version number of the source and target ends can be compared separately. For example, the SM3 of both ends of the borrower table is 0xA1B2C3D4..., the number of rows is 1,234,567, and the version is 42. The number of rows of both ends of the contract table is 3,456,789. When all three results are consistent, the synchronization is confirmed to be successful.
[0128] In some embodiments, to facilitate tracing of the multi-table cascading synchronization process, a Mapped Diagnostic Context (MDC) propagation mechanism can be set up. At the start of each synchronization task, link information such as the synchronization task identifier, the current data table identifier, and the synchronization strategy can be written into a thread context implemented using ThreadLocal. This context is then passed to subsequent synchronization processing steps during the execution of the current data table, enabling log information to be associated with the same synchronization request. When context nesting exists during synchronization, the context information before entering the current processing step can be saved, and the original context can be restored after the current processing is completed. Specifically, a try-finally structure can be used to perform context cleanup; that is, data synchronization operations are performed in the try block, and the corresponding ThreadLocal context is removed or restored in the finally block. This ensures that even if an exception occurs during synchronization and the process exits prematurely, the context information corresponding to this synchronization request can be cleared promptly, preventing this information from remaining in the thread and being used by subsequent synchronization requests. This reduces problems such as log link confusion and request identifier misuse during multi-table parallel or cascading synchronization, improving the accuracy of exception location and synchronization task tracing.
[0129] The above describes a data synchronization method provided by an embodiment of this application. The following describes the apparatus for performing the above data synchronization method.
[0130] Please see Figure 4 , Figure 4This is a schematic diagram of a data synchronization device provided in an embodiment of this application. Figure 4 As shown, the data synchronization device includes:
[0131] The structure evolution entropy determination module 401 is used to respond to a table structure change event of a data table and obtain the structure evolution entropy of the data table based on the event frequency of the table structure change event within a preset statistical window.
[0132] The strategy determination module 402 is used to determine the target synchronization strategy corresponding to the data table based on the structural evolution entropy.
[0133] The relationship graph construction module 403 is used to construct a dependency graph based on the dependency relationships between multiple data tables in the synchronization task to which the data table belongs;
[0134] The data synchronization module 404 is used to perform data synchronization operations on the multiple data tables according to the topological order of the dependency graph, the target synchronization strategy corresponding to each data table, and the synchronization time limit of the synchronization task.
[0135] In some embodiments, the structure evolution entropy determination module 401 is specifically used for: identifying the event type corresponding to the table structure change event, and writing the event type into a preset statistical window corresponding to the data table; counting the event frequency and total number of events corresponding to each event type in the preset statistical window; determining the occurrence probability of each event type based on the event frequency and the total number of events; and calculating the structure evolution entropy of the data table based on the occurrence probability of each event type.
[0136] In some embodiments, the structure evolution entropy determination module 401 is specifically used to: parse the data definition statement that causes the table structure change event to obtain at least one structure change operation; split the structure change operation according to a preset splitting rule to obtain the structure change event corresponding to the structure change operation; determine the preset event type corresponding to the structure change event based on the change content in the structure change event, and update the event frequency corresponding to the preset event type.
[0137] In some embodiments, the strategy determination module 402 is specifically configured to: parse the data definition statement that causes the table structure change event to obtain at least one structure change operation; split the structure change operation according to a preset splitting rule to obtain the structure change event corresponding to the structure change operation; determine the preset event type corresponding to the structure change event based on the change content in the structure change event, and update the event frequency corresponding to the preset event type; determine the synchronization strategy interval corresponding to the data table based on the structure evolution entropy; determine the candidate synchronization strategy corresponding to the data table based on the synchronization strategy interval corresponding to the data table; obtain the most recent strategy switching time of the data table, and if the time interval between the current time and the most recent strategy switching time reaches a preset switching interval, determine the candidate synchronization strategy as the target synchronization strategy corresponding to the data table.
[0138] In some embodiments, the data synchronization module 404 is specifically configured to: determine at least one dependency path to the current data table in the dependency graph; determine the upstream cumulative time corresponding to the current data table based on the synchronization time corresponding to the data table upstream of the current data table in each dependency path; determine the remaining synchronization time of the current data table based on the synchronization time limit and the upstream cumulative time; perform a data synchronization operation on the current data table based on the remaining synchronization time and the target synchronization strategy corresponding to the current data table; and after the current data table completes the data synchronization operation, perform a data synchronization operation on the next data table according to the topological order of the dependency graph, until the data synchronization operation of the multiple data tables is completed.
[0139] In some embodiments, the data synchronization module 404 is specifically configured to: obtain the estimated synchronization duration of the current data table when the target synchronization strategy is adopted; compare the estimated synchronization duration with the remaining synchronization duration; if the estimated synchronization duration is not greater than the remaining synchronization duration, perform a data synchronization operation on the current data table according to the target synchronization strategy; if the estimated synchronization duration is greater than the remaining synchronization duration, redetermine the synchronization strategy corresponding to the current data table based on the structural evolution entropy and the remaining synchronization duration; update the estimated synchronization duration of the current data table according to the redetermined synchronization strategy, and determine the remaining synchronization duration of the downstream data table according to the updated estimated synchronization duration.
[0140] In some embodiments, the data synchronization module 404 is specifically used to: obtain the historical synchronization duration of each data table in the synchronization task; determine the reserved duration corresponding to the synchronization task based on the historical synchronization duration of each data table and the preset timeout probability; and subtract the upstream cumulative time consumption and the reserved duration from the synchronization time limit to obtain the remaining synchronization duration of the current data table.
[0141] This application also provides an electronic device in its embodiments. (See reference...) Figure 5 The diagram illustrates a structural schematic of an electronic device suitable for implementing the data synchronization method in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0142] like Figure 5 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. When the electronic device is powered on, the RAM 503 also stores various programs and data required for the operation of the electronic device. The processing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0143] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, memory cards, hard drives, etc.; and communication devices 509. Communication device 509 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have instead.
[0144] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the data synchronization methods provided in this application.
[0145] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the data synchronization methods provided in this application.
[0146] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0147] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause an electronic device (which may be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in the various embodiments of this application.
[0148] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0149] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A data synchronization method, characterized in that, include: In response to a table structure change event of a data table, the structural evolution entropy of the data table is obtained based on the event frequency of the table structure change event within a preset statistical window. Based on the structural evolution entropy, determine the target synchronization strategy corresponding to the data table; Construct a dependency graph based on the dependencies between multiple data tables in the synchronization task to which the data table belongs; According to the topological order of the dependency graph, and based on the target synchronization strategy corresponding to each data table and the synchronization time limit of the synchronization task, data synchronization operations are performed on the multiple data tables.
2. The data synchronization method according to claim 1, characterized in that, The response to a table structure change event in response to a data table, based on the event frequency of the table structure change event within a preset statistical window, yields the structural evolution entropy of the data table, including: Identify the event type corresponding to the table structure change event, and write the event type into the preset statistics window corresponding to the data table; Calculate the frequency of events and the total number of events corresponding to each event type within the preset statistics window; Based on the event frequency corresponding to each event type and the total number of events, determine the occurrence probability corresponding to each event type; based on the occurrence probability corresponding to each event type, calculate the structural evolution entropy of the data table.
3. The data synchronization method according to claim 2, characterized in that, The identification of the event type corresponding to the table structure change event includes: Parse the data definition statement that caused the table structure change event to obtain at least one structure change operation; The structural change operation is split according to a preset splitting rule to obtain the structural change event corresponding to the structural change operation; Based on the changes in the structural change event, determine the preset event type corresponding to the structural change event, and update the event frequency corresponding to the preset event type.
4. The data synchronization method according to claim 1, characterized in that, The step of determining the target synchronization strategy corresponding to the data table based on the structural evolution entropy includes: The synchronization strategy interval corresponding to the data table is determined based on the structural evolution entropy. Based on the synchronization strategy range corresponding to the data table, determine the candidate synchronization strategy corresponding to the data table; Obtain the most recent policy switching time of the data table. If the time interval between the current time and the most recent policy switching time reaches a preset switching interval, determine the candidate synchronization policy as the target synchronization policy corresponding to the data table.
5. The data synchronization method according to claim 1, characterized in that, The step of performing data synchronization operations on the multiple data tables according to the topological order of the dependency graph, based on the target synchronization strategy corresponding to each data table and the synchronization time limit of the synchronization task, includes: For the current data table in the dependency graph, determine at least one dependency path leading to the current data table; Based on the synchronization time of the data table located upstream of the current data table in each dependency path, determine the cumulative upstream time corresponding to the current data table; Based on the synchronization time limit and the cumulative upstream time, determine the remaining synchronization time of the current data table; Based on the remaining synchronization time and the target synchronization strategy corresponding to the current data table, perform a data synchronization operation on the current data table; After the current data table completes the data synchronization operation, the next data table is synchronized according to the topological order of the dependency graph until the data synchronization operation of the multiple data tables is completed.
6. The data synchronization method according to claim 5, characterized in that, The step of executing the target synchronization strategy corresponding to the current data table based on the remaining synchronization time includes: Obtain the estimated synchronization time for the current data table when the target synchronization strategy is applied; Compare the estimated synchronization duration with the remaining synchronization duration; If the expected synchronization time is not greater than the remaining synchronization time, perform data synchronization operation on the current data table according to the target synchronization strategy. If the expected synchronization duration is greater than the remaining synchronization duration, the synchronization strategy corresponding to the current data table is re-determined based on the structural evolution entropy and the remaining synchronization duration. The estimated synchronization duration of the current data table is updated according to the redefined synchronization strategy, and the remaining synchronization duration of the downstream data table is determined based on the updated estimated synchronization duration.
7. The data synchronization method according to claim 5, characterized in that, The step of determining the remaining synchronization time of the current data table based on the synchronization time limit and the cumulative upstream time includes: Obtain the historical synchronization duration of each data table in the synchronization task; The reserved time for the synchronization task is determined based on the historical synchronization time of each data table and the preset timeout probability. The remaining synchronization time of the current data table is obtained by subtracting the upstream cumulative time and the reserved time from the synchronization time limit.
8. An electronic device, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to enable the electronic device to implement the data synchronization method as described in any one of claims 1 to 7.
9. A computer storage medium, characterized in that, The storage medium carries one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the data synchronization method as described in any one of claims 1 to 7.
10. A computer program product, characterized in that, It includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the data synchronization method as described in any one of claims 1 to 7.
