A method and apparatus for dynamically modifying data synchronization packets

By pausing the log receiving service, constructing a virtual transaction and inserting it into the database, the problem of data inconsistency caused by changes in group configuration during database data synchronization was resolved. This enabled the tables to be modified to be updated on the target side in the order of the main transaction, ensuring database consistency.

CN117349370BActive Publication Date: 2026-11-27WUHAN DAMENG DATABASE
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311204111.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-15
Publication Date
2026-11-27
Estimated Expiration
2043-09-15

AI Technical Summary

Technical Problem

In real-time database data synchronization, existing technologies cannot guarantee the update order of tables to be modified when group configurations are changed, leading to inconsistencies between the target database and the source database and compromising the data consistency of the database system.

Method used

By pausing the log receiving service, traversing active transactions, constructing virtual transactions and adding end markers, restarting the log receiving service, and storing the active transactions to be split into the database, the operations are ensured to be stored in the database in the order of the main transactions, and the grouping configuration is modified.

Benefits of technology

Without affecting data synchronization, the operation order of the source master transaction was strictly followed, which solved the data inconsistency problem caused by group configuration modification and ensured the data consistency of the database system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117349370B_ABST
    Figure CN117349370B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of database synchronization, and provides a method and device for dynamically modifying data synchronization grouping. In the application, a sub-transaction which has not received a commit operation is set in active transaction management, a virtual transaction is set to modify the grouping to which a to-be-modified table belongs, corresponding operations are stored in a target end according to the sequence of operations in a master transaction, and the modification of the grouping configuration of the to-be-modified table between groupings is completed without affecting data synchronization. The application solves the problem that, when the grouping configuration is modified, the data of the to-be-modified table in the target end database is inconsistent with the data of the to-be-modified table in a source end database, the consistency of data in a database system is destroyed, and a data synchronization service operation error is caused due to the fact that the to-be-modified table cannot be updated according to the sequence in the master transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database synchronization technology, and in particular to a method and apparatus for dynamically modifying data synchronization groups. Background Technology

[0002] Currently, in real-time database data synchronization based on log parsing, to ensure database synchronization performance and improve parallelism, operations are often grouped according to the tables they depend on, and then the operations in different groups are synchronized separately. The tables updated by an operation are the tables it depends on. In actual production environments, grouping configurations and data synchronization strategies are often customized based on specific business needs to meet business requirements or improve the data synchronization performance of individual groups. Over time, business requirements often change, and the grouping configuration of the tables to be synchronized also needs to be changed accordingly; that is, during data synchronization, the groups to which operations dependent on the tables to be synchronized are assigned are modified.

[0003] During the operation of the data synchronization service, the latency of data synchronization among different groups may vary. Some groups may continuously synchronize data, while others may experience significant latency due to differences in synchronization efficiency. In this case, the group configuration of the table to be modified involves transaction dependencies between groups. The table to be modified is the table whose group configuration needs to be modified for synchronization, determined by comparing the group configurations before and after modification. If the group configuration of a table to be modified is adjusted multiple times within a short period, and this adjustment occurs between groups with the same group number, the single main transaction involving the table to be modified will be split into multiple parts. These sub-transactions will be scattered across multiple groups, or multiple sub-transactions may exist within a single group. These sub-transactions belong to the same main transaction, but current technology cannot execute them according to the preset order of all operations within that main transaction. This makes it impossible to guarantee the update order of the table to be synchronized, which can easily lead to inconsistencies between the data of the table to be modified in the target database and the data of the table to be modified in the source database, disrupting data consistency in the database system and causing errors in the data synchronization service.

[0004] Therefore, overcoming the shortcomings of the existing technology is an urgent problem to be solved in this technical field. Summary of the Invention

[0005] In view of the above-mentioned defects or improvement needs of the prior art, the present invention provides a method and apparatus for dynamically modifying data synchronization groups. Its purpose is to strictly adhere to the execution order of operations in the source main transaction during data synchronization, and modify the group configuration of the table to be modified without affecting data synchronization.

[0006] The present invention adopts the following technical solution:

[0007] In a first aspect, the present invention provides a method for dynamically modifying data synchronization groups, comprising:

[0008] Pause the log receiving service, iterate through all currently active transactions, and determine if there are any operations involving tables to be modified.

[0009] When such an activity exists, the active transaction corresponding to the operation is identified as the active transaction to be split. A virtual transaction is constructed according to the grouping configuration, and the virtual transaction is used as a sub-transaction of the active transaction to be split. The virtual transaction is used to change the group to which the table to be modified belongs. The grouping configuration is the grouping configuration after modification based on the modification request.

[0010] Restart the log receiving service and store the activity transactions to be split into the database.

[0011] Further, when such an operation exists, the active transaction corresponding to the operation is identified as the active transaction to be split, a virtual transaction is constructed according to the grouping configuration, and the virtual transaction is used as a sub-transaction of the active transaction to be split; the virtual transaction is used to change the group to which the table to be modified belongs, including:

[0012] The sub-transactions of the activity to be cut are designated as sub-transactions to be cut, and an end marker is added to the sub-transactions to be cut so that subsequent operations will not be assigned to the sub-transactions to be cut.

[0013] Based on the grouping configuration, obtain the target group of the table to be modified;

[0014] Construct a virtual transaction for the table to be modified, treat the virtual transaction as a sub-transaction belonging to the target group of the corresponding active transaction to be split, and add an end marker to the virtual transaction;

[0015] Construct a modification operation that assigns the table to be modified to the target group, and add the modification operation to the virtual transaction.

[0016] Furthermore, restarting the log receiving service and storing the activity transactions to be split in the database includes:

[0017] Receive a commit message, take the sub-transaction of the active transaction corresponding to the commit message as the sub-transaction to be entered into the database, and determine whether the active transaction is an active transaction to be split.

[0018] When a transaction is to be split, iterate through all the sub-transactions to be inserted into the database from the transaction to be split and find the corresponding virtual transaction.

[0019] The commit LSN of the commit message is used as the commit LSN and wait LSN of the virtual transaction; wherein, the commit number of the virtual transaction is the operation number of the last operation in the active transaction to be cut.

[0020] Add all the sub-transactions to be added to the committed list of the corresponding target group in ascending order of the combination of the commit number and the commit LSN of all the sub-transactions to be added to the database.

[0021] Based on the committed linked list and the waiting LSN, all the sub-transactions to be entered into the database.

[0022] Further, the step of inserting all pending sub-transactions into the database based on the committed linked list and the waiting LSN includes:

[0023] Sequentially determine whether the commit LSN of the sub-transaction to be added to the database in the committed list is less than or equal to the commit LSN of the corresponding target group, and determine whether the commit number of the sub-transaction to be added to the database is less than or equal to the commit number of the target group.

[0024] If yes, discard the sub-transaction to be entered into the database; if no, determine whether the sub-transaction to be entered into the database is a virtual transaction.

[0025] When it is a virtual transaction, it is determined in turn whether the commit LSN of the original group on which the virtual transaction depends is greater than or equal to the waiting LSN of the virtual transaction, and whether the commit number of the original group is greater than or equal to the commit number of the virtual transaction; if not, all the sub-transactions to be entered into the database in the target group to which the virtual transaction belongs in the committed list are not entered into the database; if yes, all the sub-transactions to be entered into the database in the target group to which the virtual transaction belongs are entered into the database.

[0026] Specifically, after each sub-transaction to be inserted into the database is executed, the commit LSN of the sub-transaction to be inserted into the database is used as the commit LSN of the corresponding target group, and the commit number of the sub-transaction to be inserted into the database is used as the commit number of the target group.

[0027] Furthermore, restarting the log receiving service and storing the activity transactions to be split in the database includes:

[0028] Continue receiving logs and determine the type of operation corresponding to the logs;

[0029] When the operation is a DML operation, the DML operation is divided into corresponding sub-transactions according to the log and grouping configuration corresponding to the DML operation; wherein, when the sub-transaction has added an end mark, the sub-transaction is a sub-transaction of the active transaction to be split, and a corresponding target sub-transaction is created according to the grouping configuration, and the operation number of the DML operation is used as the commit number of the target sub-transaction;

[0030] When the operation is a commit operation, the corresponding active transaction to be split is found according to the log corresponding to the commit operation, and the sub-transactions to be entered into the database in the active transaction to be split are entered into the database.

[0031] Furthermore, when the operation is a commit operation, finding the corresponding active transaction to be split based on the log corresponding to the commit operation, and inserting the sub-transactions to be inserted into the database within the active transaction to be split includes:

[0032] Add commit messages to all sub-transactions to be inserted into the database for the activity to be split;

[0033] The commit LSN of the commit operation shall be used as the commit LSN of all sub-transactions to be inserted into the database.

[0034] Add all the sub-transactions to be entered into the database to the committed list of the target group, and enter all the sub-transactions to be entered into the database according to the committed list.

[0035] Furthermore, before pausing the log receiving service, traversing all currently active transactions, and determining whether there are any operations involving the table to be modified, the following steps are included:

[0036] Receive logs and parse the logs to obtain at least one operation, the corresponding table information, the main transaction ID, and the operation number;

[0037] Determine whether a corresponding active transaction exists based on the main transaction ID. If no such transaction exists, create the active transaction corresponding to the main transaction ID.

[0038] Based on the table information, determine whether there is an original sub-transaction corresponding to the original group under the active transaction. If not, create the original sub-transaction; assign the operation to the original sub-transaction.

[0039] In this context, the operation number of the last operation in each original sub-transaction is used as the commit number of the corresponding original sub-transaction;

[0040] Upon receiving the commit message, the active transaction adds all original sub-transactions to the committed list of the corresponding original group in ascending order of the combination of the commit number and the commit LSN of all original sub-transactions in the active transaction, and then executes and inserts all original sub-transactions into the database according to the committed list.

[0041] Further, before restarting the log receiving service and storing the activity transactions to be split into the database, the following steps are included:

[0042] Perform a checkpoint action, create a checkpoint file, and save the current system's transaction operation information to the checkpoint file;

[0043] After saving the transaction operation information, modify the current group configuration of the table to be synchronized according to the group configuration and save it so that the current group configuration can be restored each time the data synchronization service restarts due to failure.

[0044] Furthermore, during the data synchronization service failure restart and recovery, the following applies:

[0045] Based on the checkpoint file, restore the synchronized commit LSN, commit number, and virtual transaction in each target group;

[0046] When performing the data entry after recovery, determine whether the commit LSN and commit number corresponding to the executed sub-transaction are less than or equal to the commit LSN and commit number of the last synchronized sub-transaction.

[0047] If yes, then the execution and storage of the sub-transaction will not be performed; otherwise, the sub-transaction will be executed, and the current group configuration will be modified and saved according to the modification operation in the virtual transaction.

[0048] In a second aspect, the present invention also provides an apparatus for dynamically modifying data synchronization groups, used to implement the method for dynamically modifying data synchronization groups described in the first aspect, wherein the apparatus for dynamically modifying data synchronization groups includes:

[0049] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor for performing the method for dynamically modifying data synchronization packets as described in the first aspect.

[0050] Thirdly, the present invention also provides a non-volatile computer storage medium storing computer-executable instructions that are executed by one or more processors to perform the method for dynamically modifying data synchronization groups as described in the first aspect.

[0051] Unlike existing technologies, the present invention has at least the following beneficial effects:

[0052] By setting up sub-transactions in the active transaction management system that haven't received commit operations, and then configuring virtual transactions to modify the group to which the table to be modified belongs, the system ensures that the corresponding operations are entered into the database in the order they occurred in the main transaction. This completes the modification of the grouping configuration of the table to be modified within each group without affecting data synchronization. This solves the problem that when modifying group configurations, the inability to guarantee that the table to be modified is updated in the order it occurred in the main transaction leads to inconsistencies between the data in the target database and the data in the source database, disrupting data consistency and causing errors in the data synchronization service. Attached Figure Description

[0053] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments of the present invention will be briefly described below. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.

[0054] Figure 1 This is a flowchart illustrating a method for dynamically modifying data synchronization groups provided in an embodiment of the present invention;

[0055] Figure 2 This is a schematic diagram of the specific process of step 20 in an embodiment of the present invention;

[0056] Figure 3 This is a schematic diagram of a specific process for step 30 in an embodiment of the present invention;

[0057] Figure 4 This is a schematic diagram of the specific process of step 305a in an embodiment of the present invention;

[0058] Figure 5 This is another specific flowchart of step 30 in an embodiment of the present invention;

[0059] Figure 6 This is a schematic diagram of the architecture of a device for dynamically modifying data synchronization groups provided in an embodiment of the present invention. Detailed Implementation

[0060] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0061] In the description of this invention, the terms "inner", "outer", "longitudinal", "lateral", "upper", "lower", "top", "bottom", etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and do not require that this invention must be constructed and operated in a specific orientation. Therefore, they should not be construed as limiting this invention.

[0062] In this invention, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0063] Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0064] Example 1:

[0065] In the log-parsing-based group synchronization method, the target database receives logs sent by the source database, parses the logs to obtain at least one main transaction from the source database, and each main transaction contains at least one operation. The main transaction is split and classified by table to obtain sub-transactions belonging to different groups. That is, according to the tables on which the operations in the main transaction depend, the operations are classified into the corresponding groups, and the sub-transactions in each group are executed in parallel by using multi-threading to improve data synchronization efficiency.

[0066] During the operation of the data synchronization service, there is a need to modify the grouping configuration of related tables. The following example illustrates the modification of the grouping configuration: Before the modification, operations dependent on table A and table B were assigned to the first group, and operations dependent on table C were assigned to the second group; after the modification, operations dependent on table A are assigned to the first group, and operations dependent on table B and table C are assigned to the second group; the table to be modified is table B.

[0067] When the existing technology modifies the grouping configuration of the table to be modified between groups, it only implements the operation that depends on the table to be modified after the modification, and divides it into a sub-transaction of the same main transaction in a different group than before the modification, but does not re-divide the operations that have been divided into the corresponding group before the modification but have not yet been executed. If a table to be modified is grouped multiple times in a short period of time (for example, operations on table A are first assigned to the first group, then to the second group, and finally to the third group in a short period of time), and there are adjustments between groups with the same group number (for example, operations on table A are first assigned to the first group, then to the second group, and finally to the first group), it will cause a single main transaction involving the table to be modified to be split into multiple sub-transactions in different groups in the target database, and the split sub-transactions will be scattered in multiple groups (for example, main transaction 1 is split into sub-transaction 1 in the first group and sub-transaction 2 in the second group), or there will be multiple split sub-transactions in a group (for example, since operations on table A are sequentially assigned to the first group, the second group, and the first group, there are sub-transactions 1 and 3 of main transaction 1 in the first group, and sub-transaction 2 of main transaction 1 in the second group, where the operations in main transaction 1 are sequentially divided into sub-transactions 1, 2, and 3).

[0068] When operations in different groups are executed in parallel and inserted into the database, the synchronization efficiency of sub-transactions within different groups varies. Operations belonging to different sub-transactions before and after group configuration modifications cannot be executed in the predetermined order of all operations within the main transaction. This results in tables in the target database that are to be synchronized, which were originally required to be updated in the order of the main transaction (i.e., after operation 1 updates the table to be synchronized, operation 2 continues to update based on the updated table by operation 1), no longer guarantee sequential updates after the group configuration of these tables is modified (i.e., there might be a situation where operation 2 updates the table first, and then operation 1 continues to update based on the updated table by operation 2). This can easily lead to inconsistencies between the data in the target database and the data in the source database, disrupting data consistency in the database system and causing errors in the data synchronization service.

[0069] Dynamic modifications to group configurations are often minor, and the tables requiring group configuration changes are known to the data synchronization service. After receiving the group configuration modification command, the data synchronization service analyzes it to identify the tables whose group configurations need modification. During dynamic modifications, the pause time for receiving logs is extremely short, and the data synchronization service only pauses the log receiving thread; other threads (such as execution threads) continue running. Because the pause time for receiving logs is so short, it is highly likely that a large number of operations that were assigned to corresponding groups before modification but have not yet been inserted into the database will exist. When the operations are executed in parallel according to groups after modifying the group configuration, the number of operations in sub-transactions within the same source main transaction that cannot strictly adhere to the execution order of the main transaction is significant.

[0070] To address the aforementioned problems, embodiments of the present invention provide a method for dynamically modifying data synchronization groups, such as... Figure 1 As shown, it includes:

[0071] Step 10: Pause the log receiving service, traverse all currently active transactions, and determine if there are any operations involving the table to be modified.

[0072] In this invention, a source-side master transaction corresponds to a target-side active transaction. The source-side master transaction is divided into at least one sub-transaction, and the active transaction is a set of at least one sub-transaction, all of which are sub-transactions that have not received a corresponding commit operation. The table to be modified is the table whose grouping configuration has been modified when the grouping is changed. The method for dynamically modifying data synchronization grouping in this embodiment of the invention determines the active transactions of the corresponding source-side master transactions that need to be cut based on the table to be modified in the current grouping configuration. Before modifying the grouping configuration of the table to be modified, the active transactions currently involving the table to be modified need to be cut. Therefore, it is necessary to find the active transactions involving the table to be modified first. In order to avoid new operations being assigned to active transactions during the process, which would cause changes to the active transactions, the reception of source-side logs needs to be paused before the active transactions can be cut.

[0073] Step 20: When it exists, determine the active transaction corresponding to the operation as the active transaction to be cut, construct a virtual transaction according to the group configuration, and use the virtual transaction as a sub-transaction of the active transaction to be cut; the virtual transaction is used to change the group to which the table to be modified belongs.

[0074] Specifically, the active transactions to be split are those involving the table to be modified during the current modification of group configurations; these types of active transactions need to be split. The group configuration refers to the group configuration modified in the current system. By constructing virtual transactions to save the modification operations of the group configurations and constraining the execution order of the groups before and after the table to be modified, it is ensured that the corresponding operations are entered into the database in the order of operations in the main transaction, and that the modification of the table configuration between groups is completed without affecting data synchronization.

[0075] Step 30: Restart the log receiving service and store the activity transactions to be split into the database.

[0076] In this context, "data entry" refers to performing a certain operation on the target database to achieve data synchronization.

[0077] The method for dynamically modifying data synchronization groups in this invention can solve at least the following problems: First, it addresses the data synchronization issues related to the table to be modified before and after the group configuration is changed; second, it modifies the current system's group configuration to facilitate the division of operations contained in the logs according to the modified group configuration after receiving the target's logs. Since the table to be modified is known, all active transactions involving the table to be modified are identified in the current active transactions. Sub-transactions involving these groups are then segmented and virtual transactions are constructed to constrain the execution order of the groups before and after the table modification.

[0078] By setting up sub-transactions in the active transaction management system that haven't received commit operations, and then configuring virtual transactions to modify the group to which the table to be modified belongs, the system ensures that the corresponding operations are entered into the database in the order they occurred in the main transaction. This completes the modification of the grouping configuration of the table to be modified within each group without affecting data synchronization. This solves the problem that when modifying group configurations, the inability to guarantee that the table to be modified is updated in the order it occurred in the main transaction leads to inconsistencies between the data in the target database and the data in the source database, disrupting data consistency and causing errors in the data synchronization service.

[0079] This invention, through the deployment of a log parsing service at the source end, independently numbers the parsed operations based on the main transaction at the source end, ensuring the sequential incrementality of operation numbers within the main transaction. The log corresponding to each operation is then populated with the table information involved. Those skilled in the art can specify the specific implementation of operation numbers and table information according to the specific data synchronization scenario. The target-end data synchronization service receives operations from the logs sent by the source end, categorizes them into the corresponding active transactions by main transaction ID, extracts the table information involved in the operations, locates the group to which the operation belongs using the table information, and constructs the sub-transaction corresponding to the main transaction under the active transaction based on the group information.

[0080] To better illustrate the method for dynamically modifying data synchronization groups according to the present invention, the following further explains the preparatory work required before modifying the group configuration in the embodiments of the present invention. Specifically, logs are received, and the logs are parsed to obtain at least one operation, corresponding table information, a main transaction ID, and an operation number. Based on the main transaction ID, it is determined whether a corresponding active transaction exists. If not, an active transaction corresponding to the main transaction ID is created. Based on the table information, it is determined whether an original sub-transaction corresponding to the original group exists under the active transaction. If not, the original sub-transaction is created; the operation is assigned to the original sub-transaction. The operation number of the last operation in each original sub-transaction is used as the commit number of the corresponding original sub-transaction.

[0081] Upon receiving the commit message, the active transaction adds all original sub-transactions to the committed list of the corresponding original group in ascending order of the combination of the commit number of all original sub-transactions and the commit LSN (Log Sequence Number) of all original sub-transactions. Based on the committed list, all original sub-transactions are then executed and stored in the database.

[0082] In the method for dynamically modifying data synchronization groups in this embodiment of the invention, the operations in each source-side main transaction are numbered sequentially during log parsing at the source end. Since a transaction is a collection of operations, operations within the same transaction are either committed together or not committed together. Therefore, the commit LSNs of target-side sub-transactions corresponding to the same source-side main transaction are all the same. Within a group, the operation order needs to be sorted according to the operation number to strictly distinguish the order of operations in the source-side main transaction. At the target end, when a sub-transaction is executed, the operation number of the last operation in the transaction is used to ensure data consistency after fault recovery. After receiving the log, the target end groups at least one operation in each source-side main transaction according to the tables it depends on, dividing it into multiple sub-transactions. A single main transaction obtained from parsing the log at the source end involves operations on multiple tables. When grouping at the target end, these multiple tables are divided into different groups, and the target end creates a single transaction (i.e., an active transaction) to categorize the operations of the main transaction. Multiple sub-transactions are created under the active transaction, each corresponding to a group. Operations belonging to the same group are grouped under that sub-transaction, and the operation number of the last operation in each sub-transaction is recorded as the commit number of that sub-transaction. By setting up active transactions, the main transaction on the source side is managed as a set of active transactions on the target side. This facilitates finding the sub-transactions located in each group even when the operations in the main transaction are divided according to the tables they depend on, and the grouping configuration is modified and split into multiple sub-transactions, and then inserting them into the database in the order of operations in the main transaction.

[0083] After modifying the grouping configuration of the table to be modified, the sub-transactions involved in the relevant groups are split, with the pre-modification and post-modification sub-transactions forming independent sub-transactions. Since the target end receives all logs generated by the source end during operation, it includes logs of ongoing but uncommitted operations. To maintain database consistency, synchronization is based on the commit of the source end's main transaction. That is, when the target end receives the corresponding logs, it only assigns uncommitted operations from the source end to active transactions and their corresponding groups. Data synchronization for those operations only occurs when the target end receives a committed operation.

[0084] When operations on a table to be modified are switched from one group to another, sub-transactions belonging to these two groups form a transaction dependency. Specifically, if table A in the database is updated by operations in transaction 1, and subsequent operations in transaction 2 can only update table A based on the updated table A, then transaction 2 is said to depend on transaction 1, or transaction 1 and transaction 2 have a transaction dependency. Because operations within the same sub-transaction must be executed strictly in the order of their operation numbers within the main transaction, operations switched to the target group must wait until the sub-transaction has completed its data insertion in the original group before they can begin. To address this, when switching the active transaction (corresponding to the source main transaction), a virtual transaction is added to the target group corresponding to the active transaction to check the completion status of the original group's operations. The target group checks the completion status of the original group's operations by executing the virtual transaction; only when the conditions are met can the sub-transactions belonging to the target group begin execution.

[0085] To better illustrate the method for dynamically modifying data synchronization groups according to the present invention, step 20 of the method for dynamically modifying data synchronization groups according to the embodiments of the present invention will be further refined below. Specifically, as follows: Figure 2 As shown, step 20 includes:

[0086] Step 201: Take the sub-transactions of the activity transaction to be cut as sub-transactions to be cut, and add an end marker to the sub-transactions to be cut so that the operation will not be divided into the sub-transactions to be cut in the future.

[0087] The end marker is used to mark sub-transactions that have been cut. The method for dynamically modifying data synchronization groups in this embodiment of the invention uses an end marker to identify sub-transactions created before pausing the log receiving service each time the group configuration is modified. Sub-transactions involving tables to be modified are searched within active transactions to identify these sub-transactions as those to be cut, and operations that will no longer be received are assigned to them. The active transaction corresponding to this sub-transaction is then identified as the active transaction to be cut, i.e., the active transaction to be cut.

[0088] An example of an active transaction provided by an embodiment of the present invention is as follows:

[0089] A1

[0090] {

[0091] Group G1:

[0092] G1_TRX1[Table:T1, End Marker:0, Commit LSN:0, Commit Number:1]

[0093] }

[0094] The target end is configured with two groups: G1 and G2 (the G2 group is not shown here because no sub-transactions have been created in the active transaction A1). Initially, the table to be modified is configured in the G1 group. An end marker of 0 indicates no end marker has been added, and an end marker of 1 indicates an end marker has been added. A commit LSN of 0 indicates that the sub-transaction has not received a commit message, so no commit LSN is set. The commit number of the sub-transaction is set when the operation is assigned to that sub-transaction; it is the operation number of the last operation in that sub-transaction. When an operation with a commit LSN of 21 is received from the source end, an active transaction A1 with ID 1 is created using the primary transaction ID. At this point, T1 belongs to the G1 group. A sub-transaction G1_TRX1 belonging to group G1 is created on the active transaction, and the operation is added to this sub-transaction, with the operation number 1 used as the commit number of this transaction.

[0095] Based on the table T1 to be modified, active transaction A1 is identified as the active transaction to be split. The original grouped sub-transactions involved in table T1 within the active transaction A1 to be split are then treated as sub-transactions to be split, and an end marker is added as follows:

[0096] A1

[0097] {

[0098] Group G1:

[0099] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0100] }

[0101] Step 202: Obtain the target group of the table to be modified according to the group configuration.

[0102] For example, based on the group configuration modification command, the target group of the table T1 to be modified is obtained as group G2.

[0103] Step 203: Construct a sub-transaction belonging to the target group of the active transaction to be segmented as a virtual transaction, and add an end marker to the virtual transaction. Specifically, by using the operation number of the last operation of the corresponding active transaction as the commit number of the virtual transaction, operations within the virtual transaction wait until the sub-transaction to which the original group belongs executes up to the commit LSN and commit number of this virtual transaction before execution. Those skilled in the art can specify the specific implementation of the operation number according to the specific data synchronization scenario, and this is not limited here.

[0104] Step 204: Construct a modification operation that assigns the table to be modified to the target group, and add the modification operation to the virtual transaction.

[0105] Steps 203 and 204 are illustrated below: For the target group G2 involved in the table T1 to be modified in the active transaction A1 to be split, a virtual transaction G2_TRX2 dependent on group G1 is constructed (this virtual transaction G2_TRX2 can only execute and insert data after group G1 has completed its insertion). The commit number of this transaction is the operation number of the last operation in the active transaction A1 to be split. Specifically, if the virtual transaction G2_TRX2 can only successfully insert data into the target database updated by all sub-transactions in group G1 after all sub-transactions in group G1 have completed their insertion, then the virtual transaction G2_TRX2 is said to depend on group G1. Since the active transaction to be split has not yet received a commit message, it waits for the LSN to be set to 0 and saves the modification operation of changing the grouping configuration of the table T1 from group G1 to group G2 to this virtual transaction, as detailed below:

[0106] A1

[0107] {

[0108] Group G1:

[0109] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0110] Group G2:

[0111] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0112] }

[0113] When adjusting the grouping configuration of the table to be modified on the target side, first, search all active transactions involving the table to be modified in all active transactions. Determine if there are any table-related operations in the sub-transaction. If so, the active transaction is classified as an active transaction that needs to be split, and an end marker is set for the sub-transactions in the original groups involved by these active transactions, and the operation number of the last operation is recorded. Find the sub-transactions of the target group involving the table in the active transaction. If the sub-transaction exists, the active transaction is classified as an active transaction that needs to be split. Other active transactions not involved do not need to be processed. Then, complete the modification of the grouping configuration. Insert a virtual transaction in the target group that depends on the table to be modified to modify the group to which the table to be modified belongs. Wherein, if the sub-transaction in the target group updates the table to be modified, the target group is said to depend on the table to be modified. After the grouping configuration of the table is modified, the sub-transactions involved in the relevant groups are split, and the sub-transactions before and after modification form independent sub-transactions. Since there is a logical dependency between these two sub-transactions, the execution order of the relevant groups is linked by setting a virtual transaction between these two sub-transactions to ensure that the sub-transactions before modification are executed before the sub-transactions after modification. This invention constructs sequential dependencies between groups by creating sub-transactions at different stages (before and after group configuration modification) when modifying table groupings, and inserting virtual transactions between dependent groups. Specifically, if a sub-transaction in the target group updates the table to be modified, then the target group is said to depend on the table to be modified. If all sub-transactions in group G1 have completed execution and data insertion, and only then can a sub-transaction in group G2 successfully insert data into the target database updated by all sub-transactions in group G1, then group G2 is said to depend on group G1, and group G1 and group G2 have a dependency relationship.

[0114] After completing the sub-transactions of all involved activities and modifying all related activities, the group configuration information should be modified.

[0115] Prior to step 30, the following is included:

[0116] A checkpoint action is executed, creating a checkpoint file to save the current system's transaction operation information. After saving the transaction operation information, the current group configuration of the table to be synchronized is modified and saved according to the group configuration, so that the current group configuration can be restored each time the data synchronization service restarts after a failure. Specifically, after modifying and saving the current group configuration, the current system, upon restarting the log receiving service, performs operation division and group construction based on the group configuration. A checkpoint action is executed to record the transaction status and current group configuration in the current system, so that recovery is possible in the event of a data synchronization service failure. When the modified target group or the original group receives the same main transaction operation from the source again, a sub-transaction of the target is created to categorize and include the operation.

[0117] The execution thread of the target-side data synchronization service is responsible for polling the sub-transactions corresponding to the main transaction that has been committed on the source side in each group, and then storing all sub-transactions corresponding to the main transaction into the database. To better illustrate the method for dynamically modifying data synchronization groups according to the present invention, step 30 of the method for dynamically modifying data synchronization groups in this embodiment will be further refined below. Specifically, as follows... Figure 3 As shown, step 30 includes:

[0118] Step 301a: Receive a commit message, treat the sub-transactions of the active transaction corresponding to the commit message as sub-transactions to be inserted into the database, and determine whether the active transaction is an active transaction to be split. Among them, active transactions whose corresponding sub-transactions do not have an end marker are active transactions to be split. If it is not an active transaction to be split, add all sub-transactions to the committed list of the corresponding target group in ascending order of the combination of the commit number and the commit LSN of all sub-transactions to be inserted into the database, for insertion.

[0119] Step 302a: When it is an active transaction to be split, traverse all the sub-transactions to be entered into the database from the active transaction to be split and find the corresponding virtual transaction.

[0120] Step 303a: Use the commit LSN of the commit message as the commit LSN and wait LSN of the virtual transaction; wherein, the commit number of the virtual transaction is the operation number of the last operation in the active transaction to be split. The commit number is set when the virtual transaction is constructed; the wait LSN is the commit LSN of the group the virtual transaction needs to wait for. By setting the wait LSN, the virtual transaction (the operation to modify the group configuration) can only begin execution after the sub-transactions in the waiting group that are less than or equal to the commit LSN have completed synchronization.

[0121] Step 304a: Add all sub-transactions to be added to the committed list of the corresponding target group in ascending order of the combination of their commit numbers and commit LSNs. Operations corresponding to the same source main transaction have the same commit LSN but different commit numbers. Those skilled in the art can specify the combination of commit LSNs and commit numbers according to the specific data synchronization scenario. Each group corresponds to one committed list.

[0122] Step 305a: Based on the committed linked list and the waiting LSN, write all the sub-transactions to be written into the database.

[0123] To maintain database consistency, the operations to be synchronized are first distinguished according to the tables they depend on before synchronization. This is to avoid database errors caused when multiple sub-transactions are executed in parallel because some sub-transactions in the groups they depend on have not yet been entered into the database.

[0124] To better illustrate the method for dynamically modifying data synchronization groups according to the present invention, the following will further refine step 305a of the method for dynamically modifying data synchronization groups according to the embodiment of the present invention. Specifically, as follows: Figure 4 As shown, step 305a includes:

[0125] Step 3051: Sequentially determine whether the commit LSN of the sub-transaction to be added to the database in the committed list is less than or equal to the commit LSN of the corresponding target group, and determine whether the commit number of the sub-transaction to be added to the database is less than or equal to the commit number of the target group.

[0126] For example, the active transaction A1 that has received the commit message is as follows:

[0127] A1

[0128] {

[0129] Group G1:

[0130] G1_TRX1[Table:T1, End Marker:1, Commit LSN:25, Commit Number:1]

[0131] G1_TRX4 [Depends on G2, waiting LSN:25, end marker:1, commit LSN:25, commit number:2]

[0132] G1_TRX5[Table:T1, End Marker:0, Commit LSN:25, Commit Number:4]

[0133] Group G2:

[0134] G2_TRX2 [Depends on G1, waiting LSN: 25, end marker: 1, commit LSN: 25, commit number: 1]

[0135] G2_TRX3[Table:T1, End Marker:1, Commit LSN:25, Commit Number:2]

[0136] }

[0137] The execution thread polls the G1 and G2 groups, and executes them in the committed linked lists of the G1 and G2 groups in order of the size of the combination of the transaction's commit LSN and commit number.

[0138] Step 3052: If yes, discard the sub-transaction to be entered into the database; if no, determine whether the sub-transaction to be entered into the database is a virtual transaction.

[0139] For example, the execution thread extracts the sub-transaction G1_TRX1 to be inserted into the database from the G1 group. At this time, the G1 group has not yet executed the insertion of a certain sub-transaction into the database, so the commit LSN and commit number of the G1 group are both 0. The commit LSN25 of the sub-transaction G1_TRX1 to be inserted into the database is not less than or equal to 0, and the commit number 1 is not less than or equal to 0, so it is inserted into the database.

[0140] Step 3053: When it is a virtual transaction, sequentially determine whether the commit LSN corresponding to the original group on which the virtual transaction depends is greater than or equal to the waiting LSN of the virtual transaction, and determine whether the commit number corresponding to the original group is greater than or equal to the commit number of the virtual transaction; if not, then do not enter all the pending sub-transactions to be entered into the database in the target group to which the virtual transaction belongs in the committed list; if yes, then enter all the pending sub-transactions to be entered into the database in the target group to which the virtual transaction belongs. Specifically, when it is a virtual transaction, it depends on the execution of sub-transactions in the original group before modification; when it is not a virtual transaction, it does not depend on the execution of other groups and can be executed directly.

[0141] For example, the execution thread retrieves the pending sub-transaction G1_TRX4 from group G1. It depends on the execution of group G2 and is a virtual transaction. The commit LSN25 of group G2 is equal to the waiting LSN25 of virtual transaction G1_TRX4, which satisfies the condition. The commit number 0 of group G2 (at this time, group G2 has not executed any pending sub-transaction) is not greater than or equal to the commit number 2 of virtual transaction G1_TRX4, which does not satisfy the condition. Therefore, transaction G1_TRX4 cannot be executed. The pending sub-transactions in group G1 on the currently committed list should be skipped, and the pending sub-transactions in group G2 should be retrieved.

[0142] The execution thread retrieves the pending subtransaction G2_TRX2 from group G2, which depends on the execution of group G1. At this point, group G1 has already executed G1_TRX1. Group G1's commit LSN and commit number are LSN 25 and 1, respectively. The waiting LSN 25 of the pending subtransaction G2_TRX2 equals the commit LSN 25 of group G1, satisfying the condition. The commit number 1 of group G2 equals the commit number 1 of group G1, also satisfying the condition. Therefore, the pending subtransaction G2_TRX2 is executed and inserted into the database.

[0143] Step 3054: After each pending sub-transaction is executed for data entry, the commit LSN of the pending sub-transaction is used as the commit LSN of the corresponding target group, and the commit number of the pending sub-transaction is used as the commit number of the target group. Each group also needs to record the commit LSN and commit number of the completed pending sub-transactions during execution. This is used to filter executed pending sub-transactions after a failure, ensuring data consistency.

[0144] For example, the execution thread extracts the G1_TRX1 transaction from the G1 group and stores it in the database, recording the commit LSN 25 and commit number 1 of the completed transaction as the commit LSN of the target group.

[0145] By setting up virtual transactions, when a sub-transaction involving the table to be modified is committed, the execution order of the original group and the target group, as well as the execution order of the sub-transactions formed after splitting, is guaranteed. By setting the wait LSN and commit LSN of the virtual transaction, and setting the commit number of the virtual transaction to the operation number of the last operation of the corresponding active transaction, it is ensured that during the data insertion process, the data synchronization service will not encounter runtime errors caused by the transaction dependencies of sub-transactions, and that the consistency of synchronized data will be restored when the data synchronization service fails and is recovered.

[0146] The target end continues to receive logs sent by the source end, generates or categorizes the operations within them into corresponding active transactions, and performs corresponding processing based on the operation type. To better illustrate the method for dynamically modifying data synchronization groups according to the present invention, step 30 of the method in this embodiment will be further refined below. Specifically, as follows... Figure 5 As shown, step 30 includes:

[0147] Step 301b: Continue receiving logs and determine the type of operation corresponding to the logs. DML (Data Manipulation Language) operations belonging to the same main transaction at the source end, when divided into different groups for parallel execution, often have dependency conflicts. DDL (Data Definition Language) operations generally do not have dependency conflicts and do not require the method of dynamically modifying data synchronization groups in this embodiment of the invention. After receiving a DDL operation, it is divided into the corresponding active transaction based on the tables it depends on. After receiving the corresponding commit message, it is added to the committed list according to the commit LSN and executed for database entry. When the operation is a rollback operation, all sub-transactions under the active transaction and the active transaction itself are released according to the active transaction. A rollback operation at the source end will undo all executed main transactions. To maintain the consistency between the source and target data during data synchronization, all operations on the target end involving the main transaction at the source end need to be rolled back.

[0148] Step 302b: When the operation is a DML operation, the DML operation is divided into corresponding sub-transactions according to the log and group configuration corresponding to the DML operation; wherein, when the sub-transaction has added an end mark, the sub-transaction is a sub-transaction of the active transaction to be split, and a corresponding target sub-transaction is created according to the group configuration, and the operation number of the DML operation is used as the commit number of the target sub-transaction.

[0149] For example, when a DML operation with commit LSN 22 is received, the corresponding active transaction A1 with ID 1 is located using the primary transaction ID. Within active transaction A1, the original subtransaction G1_TRX1 and the target subtransaction G2_TRX3 corresponding to the table T1 to be modified are found. Since the original subtransaction G1_TRX1 has an end marker, meaning it was a subtransaction to be split during the last group configuration modification, according to the group configuration, the table T1 to be modified now belongs to group G2. A target subtransaction G2_TRX3 belonging to group G2 is created within the active transaction, and the DML operation is added to this target subtransaction. The operation number is used as the commit number of the target subtransaction, as detailed below:

[0150] A1

[0151] {

[0152] Group G1:

[0153] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0154] Group G2:

[0155] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0156] G2_TRX3[Table:T1, End Marker:0, Commit LSN:0, Commit Number:2]

[0157] }

[0158] When a DML operation with LSN 24 is received, the active transaction A1 with ID 1 is located through the main transaction ID. At this time, T1 belongs to the G1 group. There is already a sub-transaction G1_TRX5 belonging to the G1 group on the active transaction. Its end mark is 0, that is, no end mark has been added. Therefore, the DML operation is still added to the sub-transaction G1_TRX5.

[0159] A1

[0160] {

[0161] Group G1:

[0162] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0163] G1_TRX4 [Depends on G2, waiting LSN:0, end marker:1, commit LSN:0, commit number:2]

[0164] G1_TRX5[Table:T1, End Marker:0, Commit LSN:0, Commit Number:4]

[0165] Group G2:

[0166] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0167] G2_TRX3[Table:T1, End Marker:1, Commit LSN:0, Commit Number:2]

[0168] }

[0169] Step 303b: When the operation is a commit operation, find the corresponding active transaction to be split according to the log corresponding to the commit operation, and write the sub-transactions to be entered into the database within the active transaction to be split. Specifically, the corresponding active transaction to be split is determined based on the main transaction ID in the log corresponding to the commit operation.

[0170] Specifically, a commit message is added to all sub-transactions to be inserted into the database for the activity to be split; the commit LSN of the commit operation is used as the commit LSN of all sub-transactions to be inserted into the database; all sub-transactions to be inserted into the database are added to the committed list of the target group; and all sub-transactions to be inserted into the database are inserted according to the committed list.

[0171] In this embodiment of the invention, the method for dynamically modifying data synchronization groups determines the group based on the table information parsed from the log corresponding to the operation when continuing to receive logs and dividing the corresponding operations. This group belongs to an active transaction or an active transaction to be split. If the table corresponding to the table information is not a table to be modified, it means that the corresponding active transaction does not need to be split before and after the group configuration modification, and the continued received operations are divided into sub-transactions of the active transaction.

[0172] For example, when a commit operation with commit LSN of 25 is received, the active transaction A1 with ID 1 is located through the main transaction ID. All sub-transactions of active transaction A1 are traversed and their commit LSNs are marked as the commit LSN of the current commit operation. If the sub-transaction is a virtual transaction, the waiting LSN of the group it is waiting for is set to 25, and then it is added to the committed list of the corresponding group.

[0173] A1

[0174] {

[0175] Group G1:

[0176] G1_TRX1[Table:T1, End Marker:1, Commit LSN:25, Commit Number:1]

[0177] G1_TRX4 [Depends on G2, waiting LSN:25, end marker:1, commit LSN:25, commit number:2]

[0178] G1_TRX5[Table:T1, End Marker:0, Commit LSN:25, Commit Number:4]

[0179] G2 group: G2_TRX2 [Depends on G1, waiting LSN: 25, end marker: 1, commit LSN: 25, commit number: 1]

[0180] G2_TRX3[Table:T1, End Marker:1, Commit LSN:25, Commit Number:2]

[0181] }

[0182] The submission message is not shown here. The specific implementation method can be specified by those skilled in the art according to the specific data synchronization scenario, and is not limited here.

[0183] It is worth noting that during the data synchronization service failure restart and recovery, the following should be noted:

[0184] Based on the checkpoint file, restore the synchronized commit LSN, commit number, and virtual transaction for each target group. During the post-recovery data insertion, determine if the commit LSN and commit number corresponding to the executed sub-transaction are less than or equal to the commit LSN and commit number of the last synchronized sub-transaction. If yes, do not perform the sub-transaction insertion; otherwise, execute the sub-transaction, modify the current group configuration according to the modification operations in the virtual transaction, and save. Filter sub-transactions whose commit LSN is less than or equal to the target group's commit LSN and whose commit number is less than or equal to the target group's commit number to ensure the consistency of the fault recovery data.

[0185] Example 2:

[0186] Based on Embodiment 1 above, this embodiment of the invention provides a specific example of a method for dynamically modifying data synchronization groups to better understand the entire synchronization process. This embodiment of the invention will use the log information sequence shown in the table below as an example for illustration:

[0187] The source database has a table T1 (ID INT). A transaction on the source database operates on table T1, generating the following sequential log. Upon receiving this log, the receiving thread will generate the following numbered table:

[0188] Master Transaction ID operate Submit LSN Operation number 1 INSERT INTO T1(ID)VALUES(100); 21 1 1 UPDATE T1 SET ID=200WHERE ID=100; 22 2 1 UPDATE T1 SET ID=300WHERE ID=200; 23 3 1 UPDATE T1 SET ID=400WHERE ID=300; 24 4 1 COMMIT 25 5

[0189] The target synchronization service is configured with two groups, G1 and G2. Initially, the table to be modified is configured in group G1. The table T1 is then modified to group G2, and then changed back to group G1 from group G2. The process is as follows:

[0190] Upon receiving an operation with LSN 21, an active transaction A1 with ID 1 is created. At this moment, T1 belongs to group G1. A sub-transaction G1_TRX1 belonging to group G1 is created on the active transaction, as follows:

[0191] A1

[0192] {

[0193] Group G1:

[0194] G1_TRX1[Table:T1, End Marker:0, Commit LSN:0, Commit Number:1]

[0195] }

[0196] Prepare to modify the grouping of T1, changing it from the original G1 group to the target G2 group.

[0197] Pause receiving logs from the source end, traverse active transactions, and find the active transaction A1 associated with T1.

[0198] Construct a virtual transaction G2_TRX2 that depends on G1 for the target group involved in table T1 in active transaction A1, and save the modification operation of changing the group of T1 from G1 to G2 to this virtual transaction.

[0199] A1

[0200] {

[0201] Group G1:

[0202] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0203] Group G2:

[0204] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0205] }

[0206] Perform a checkpoint on the current transaction information and the modified group configuration information in the system, and save the status of all current transactions to the checkpoint file.

[0207] Resume receiving logs from the source.

[0208] When an operation with LSN 22 is received, the active transaction A1 with ID 1 is located through the main transaction ID. At this moment, T1 belongs to the G2 group, and a sub-transaction G2_TRX3 belonging to the G2 group is created on the active transaction.

[0209] A1

[0210] {

[0211] Group G1:

[0212] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0213] Group G2:

[0214] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0215] G2_TRX3[Table:T1, End Marker:0, Commit LSN:0, Commit Number:2]

[0216] }

[0217] Prepare to modify the grouping of T1, changing it from the original G2 group to the target G1 group.

[0218] Pause receiving logs from the source end, traverse active transactions, and find the active transaction A1 associated with T1.

[0219] A1

[0220] {

[0221] Group G1:

[0222] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0223] Group G2:

[0224] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0225] G2_TRX3[Table:T1, End Marker:1, Commit LSN:0, Commit Number:2]

[0226] }

[0227] Construct a virtual transaction G1_TRX4 that depends on G2 for the target group involved in table T1 on active transaction A1, and save the modification operation of changing the group of T1 from G2 to G1 to this virtual transaction.

[0228] A1

[0229] {

[0230] Group G1:

[0231] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0232] G1_TRX4 [Depends on G2, waiting LSN:0, end marker:1, commit LSN:0, commit number:2]

[0233] Group G2:

[0234] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0235] G2_TRX3[Table:T1, End Marker:1, Commit LSN:0, Commit Number:2]

[0236] }

[0237] Perform a checkpoint on the transaction information and modified group configuration information in the current system, and save the current system state.

[0238] Resume receiving logs from the source.

[0239] When an operation with LSN 23 is received, the active transaction A1 with ID 1 is located through the main transaction ID. At this moment, T1 belongs to the G1 group. A sub-transaction G1_TRX5 belonging to the G1 group is created on the active transaction, and the operation is added to the sub-transaction.

[0240] A1

[0241] {

[0242] Group G1:

[0243] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0244] G1_TRX4 [Depends on G2, waiting LSN:0, end marker:1, commit LSN:0, commit number:2]

[0245] G1_TRX5[Table:T1, End Marker:0, Commit LSN:0, Commit Number:3]

[0246] Group G2:

[0247] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0248] G2_TRX3[Table:T1, End Marker:1, Commit LSN:0, Commit Number:2]

[0249] }

[0250] When an operation with LSN 24 is received, the active transaction A1 with ID 1 is located through the main transaction ID. At this moment, T1 belongs to the G1 group, and the operation is added to the sub-transaction G1_TRX5.

[0251] A1

[0252] {

[0253] Group G1:

[0254] G1_TRX1[Table:T1, End Marker:1, Commit LSN:0, Commit Number:1]

[0255] G1_TRX4 [Depends on G2, waiting LSN:0, end marker:1, commit LSN:0, commit number:2]

[0256] G1_TRX5[Table:T1, End Marker:0, Commit LSN:0, Commit Number:4]

[0257] Group G2:

[0258] G2_TRX2 [Depends on G1, waiting LSN:0, end marker:1, commit LSN:0, commit number:1]

[0259] G2_TRX3[Table:T1, End Marker:1, Commit LSN:0, Commit Number:2]

[0260] }

[0261] When a commit operation with LSN 25 is received, the active transaction A1 with ID 1 is located through the primary transaction ID.

[0262] A1

[0263] {

[0264] Group G1:

[0265] G1_TRX1[Table:T1, End Marker:1, Commit LSN:25, Commit Number:1]

[0266] G1_TRX4 [Depends on G2, waiting LSN:25, end marker:1, commit LSN:25, commit number:2]

[0267] G1_TRX5[Table:T1, End Marker:0, Commit LSN:25, Commit Number:4]

[0268] Group G2:

[0269] G2_TRX2 [Depends on G1, waiting LSN: 25, end marker: 1, commit LSN: 25, commit number: 1]

[0270] G2_TRX3[Table:T1, End Marker:1, Commit LSN:25, Commit Number:2]

[0271] }

[0272] The execution thread polls groups G1 and G2, and executes them in the committed list of the group according to the order of the combination of the commit LSN and commit number of the subtransaction.

[0273] The execution thread extracts the G1_TRX1 transaction from the G1 group and records the commit LSN 25 and commit number 1 after it completes the transaction.

[0274] The execution thread extracts the G1_TRX4 transaction from the G1 group, skips the G1 group (including the G1_TRX4 transaction), and retrieves the transactions from the G2 group.

[0275] The execution thread extracts the G2_TRX2 transaction from the G2 group and executes the data entry.

[0276] The execution thread extracts the G2_TRX3 transaction from the G2 group, executes it and inserts it into the database, and records the commit LSN25 and commit number 2 of the completed transaction.

[0277] The sub-transactions pending entry into the database in group G2 have been completed, and the execution thread is now executing the G1_TRX4 transaction in group G1.

[0278] The program terminated abnormally after execution. At this time, the commit LSN of G1 group was 25 and the commit number was 2; the commit LSN of G2 group was 25 and the commit number was 2.

[0279] After the target synchronization service restarts and the fault is recovered, the sub-transaction G1_TRX5 of the G1 group is executed.

[0280] Example 3:

[0281] like Figure 6 The diagram shown is an architectural schematic of a device for dynamically modifying data synchronization groups according to an embodiment of the present invention. The device for dynamically modifying data synchronization groups in this embodiment includes one or more processors 31 and a memory 32. Figure 6 Take a processor 31 as an example.

[0282] Processor 31 and memory 32 can be connected via a bus or other means. Figure 6 Taking the example of a connection between China and Israel via a bus.

[0283] The memory 32, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs and non-volatile computer-executable programs, such as the method for dynamically modifying data synchronization packets in Embodiment 1. The processor 31 executes the method for dynamically modifying data synchronization packets by running the non-volatile software program and instructions stored in the memory 32.

[0284] Memory 32 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 32 may optionally include memory remotely located relative to processor 31, which can be connected to processor 31 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0285] The program instructions / modules are stored in the memory 32. When executed by one or more processors 31, they perform the method for dynamically modifying data synchronization groups described in Embodiment 1 above, for example, performing the above-described... Figures 1-5 The steps shown.

[0286] It is worth noting that the information interaction and execution process between the modules and units in the above-mentioned device and system are based on the same concept as the processing method embodiment of the present invention. For details, please refer to the description in the method embodiment of the present invention, and will not be repeated here.

[0287] Those skilled in the art will understand that all or part of the steps in the various methods of the embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc.

[0288] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for dynamically modifying data synchronization groups, characterized in that, include: Pause the log receiving service, iterate through all currently active transactions, and determine if there are any operations involving tables to be modified. When it exists, the active transaction corresponding to the operation is determined as the active transaction to be cut, the sub-transactions of the active transaction to be cut are taken as sub-transactions to be cut, and an end marker is added to the sub-transactions to be cut so that the operation will not be divided into the sub-transactions to be cut in the future. According to the grouping configuration, obtain the target group of the table to be modified; wherein, the grouping configuration is the grouping configuration after modification based on the modification request; A virtual transaction is constructed for the table to be modified, and the virtual transaction is used as a sub-transaction belonging to the target group of the corresponding active transaction to be split. An end marker is added to the virtual transaction; wherein, the virtual transaction is used to change the group to which the table to be modified belongs; Construct modification operations that divide the table to be modified into the target group, and add the modification operations to the virtual transaction; Restart the log receiving service and add the activity transaction to be split into the database; wherein, the following steps are taken: use the commit LSN of the commit message of the activity transaction to be split as the waiting LSN of the virtual transaction, and use the operation number of the last operation in the activity transaction to be split as the commit number of the virtual transaction; execute the sub-transaction to be added into the database in the target group only when the commit LSN of the original group on which the virtual transaction depends is not less than the waiting LSN and the commit number of the original group is not less than the commit number.

2. The method for dynamically modifying data synchronization groups according to claim 1, characterized in that, Restarting the log receiving service and adding the active transactions to be split to the database includes: Receive a commit message, take the sub-transaction of the active transaction corresponding to the commit message as the sub-transaction to be entered into the database, and determine whether the active transaction is an active transaction to be split. When a transaction is to be split, iterate through all the sub-transactions to be inserted into the database from the transaction to be split and find the corresponding virtual transaction. The commit LSN of the commit message is used as the commit LSN and wait LSN of the virtual transaction; wherein, the commit number of the virtual transaction is the operation number of the last operation in the active transaction to be cut. Add all the sub-transactions to be added to the committed list of the corresponding target group in ascending order of the combination of the commit number and the commit LSN of all the sub-transactions to be added to the database. Based on the committed linked list and the waiting LSN, all the sub-transactions to be entered into the database.

3. The method for dynamically modifying data synchronization groups according to claim 2, characterized in that, The step of loading all pending sub-transactions into the database based on the committed linked list and the waiting LSN includes: Sequentially determine whether the commit LSN of the sub-transaction to be added to the database in the committed list is less than or equal to the commit LSN of the corresponding target group, and determine whether the commit number of the sub-transaction to be added to the database is less than or equal to the commit number of the target group. If yes, discard the sub-transaction to be entered into the database; if no, determine whether the sub-transaction to be entered into the database is a virtual transaction. When it is a virtual transaction, it is determined in turn whether the commit LSN of the original group on which the virtual transaction depends is greater than or equal to the waiting LSN of the virtual transaction, and whether the commit number of the original group is greater than or equal to the commit number of the virtual transaction; if not, all the sub-transactions to be entered into the database in the target group to which the virtual transaction belongs in the committed list are not entered into the database; if yes, all the sub-transactions to be entered into the database in the target group to which the virtual transaction belongs are entered into the database. Specifically, after each sub-transaction to be inserted into the database is executed, the commit LSN of the sub-transaction to be inserted into the database is used as the commit LSN of the corresponding target group, and the commit number of the sub-transaction to be inserted into the database is used as the commit number of the target group.

4. The method for dynamically modifying data synchronization groups according to claim 2, characterized in that, Restarting the log receiving service and adding the active transactions to be split to the database includes: Continue receiving logs and determine the type of operation corresponding to the logs; When the operation is a DML operation, the DML operation is divided into corresponding sub-transactions according to the log and grouping configuration corresponding to the DML operation; wherein, when the sub-transaction has added an end mark, the sub-transaction is a sub-transaction of the active transaction to be split, and a corresponding target sub-transaction is created according to the grouping configuration, and the operation number of the DML operation is used as the commit number of the target sub-transaction; When the operation is a commit operation, the corresponding active transaction to be split is found according to the log corresponding to the commit operation, and the sub-transactions to be entered into the database in the active transaction to be split are entered into the database.

5. The method for dynamically modifying data synchronization groups according to claim 4, characterized in that, When the operation is a commit operation, finding the corresponding active transaction to be split based on the log corresponding to the commit operation, and inserting the sub-transactions to be inserted into the database within the active transaction to be split includes: Add commit messages to all sub-transactions to be inserted into the database for the activity to be split; The commit LSN of the commit operation shall be used as the commit LSN of all sub-transactions to be inserted into the database. Add all the sub-transactions to be entered into the database to the committed list of the target group, and enter all the sub-transactions to be entered into the database according to the committed list.

6. The method for dynamically modifying data synchronization groups according to claim 1, characterized in that, Before pausing the log receiving service, iterating through all currently active transactions, and determining whether there are any operations involving the table to be modified, the following steps are included: Receive logs and parse the logs to obtain at least one operation, the corresponding table information, the main transaction ID, and the operation number; Determine whether a corresponding active transaction exists based on the main transaction ID. If no such transaction exists, create the active transaction corresponding to the main transaction ID. Based on the table information, determine whether there is an original sub-transaction corresponding to the original group under the active transaction. If not, create the original sub-transaction; assign the operation to the original sub-transaction. In this context, the operation number of the last operation in each original sub-transaction is used as the commit number of the corresponding original sub-transaction; Upon receiving the commit message, the active transaction adds all original sub-transactions to the committed list of the corresponding original group in ascending order of the combination of the commit number and the commit LSN of all original sub-transactions in the active transaction, and then executes and inserts all original sub-transactions into the database according to the committed list.

7. The method for dynamically modifying data synchronization groups according to claim 1, characterized in that, Before restarting the log receiving service and storing the active transactions to be split in the database, the following steps are included: Perform a checkpoint action, create a checkpoint file, and save the current system's transaction operation information to the checkpoint file; After saving the transaction operation information, modify the current group configuration of the table to be synchronized according to the group configuration and save it so that the current group configuration can be restored each time the data synchronization service restarts due to failure.

8. The method for dynamically modifying data synchronization groups according to any one of claims 1-7, characterized in that, When the data synchronization service fails and restarts, the following should be noted: Based on the checkpoint file, restore the synchronized commit LSN, commit number, and virtual transaction in each target group; When performing the data entry after recovery, determine whether the commit LSN and commit number corresponding to the executed sub-transaction are less than or equal to the commit LSN and commit number of the last synchronized sub-transaction. If yes, then the execution and storage of the sub-transaction will not be performed; otherwise, the sub-transaction will be executed, and the current group configuration will be modified and saved according to the modification operation in the virtual transaction.

9. A device for dynamically modifying data synchronization groups, characterized in that, The method includes at least one processor and a memory, which are connected via a data bus. The memory stores instructions that can be executed by the at least one processor. When executed by the processor, the instructions are used to perform the method for dynamically modifying data synchronization groups as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Database synchronization transaction processing method, storage medium and computer equipment

    CN116244380A

  • Client and server integration for replicating data

    US20150032695A1