Database synchronization method, apparatus and device of distributed system, medium and product

By embedding source node identifiers and transaction identifiers in the database change log, the problems of data consistency and high availability during the scaling up and down process of distributed databases are solved, realizing cross-cluster data synchronization and smooth migration without downtime, and improving the stability and reliability of the system.

CN123138338APending Publication Date: 2026-11-20CHINA UNIONPAY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611299693.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-25
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In high-concurrency scenarios such as finance, e-commerce, and cloud computing, distributed databases struggle to achieve uninterrupted data consistency and high availability during scaling up and down. This is especially true in multi-active architectures with two sites and three centers, where issues such as asymmetrical node numbers, loss of data source identifiers, and loops in synchronization operations make it difficult to balance data consistency and system high availability.

Method used

By carrying source node identifiers and transaction identifiers in the database change log, the source of transactions can be accurately identified and the transaction type can be distinguished, preventing synchronization loops and achieving cross-cluster data consistency and high availability. The target cluster can flexibly redistribute data change operations based on its own database sharding strategy.

Benefits of technology

Without interrupting business operations, it achieved smooth migration and bidirectional synchronization of data across clusters, solved synchronization loop and scaling interference issues, and improved the system's high availability and data consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123138338A_ABST
    Figure CN123138338A_ABST
Patent Text Reader

Abstract

This application provides a database synchronization method, apparatus, device, medium, and product for a distributed system. The distributed system includes multiple clusters, each cluster comprising compute nodes, synchronization nodes, and at least one database node. The method includes: for any transaction executed by a database node in any cluster, obtaining the database change log corresponding to the transaction; wherein the database change log includes a source node identifier and a transaction identifier written by the database node; determining whether transaction synchronization needs to be performed based on the transaction identifier and preset synchronization rules; if transaction synchronization is determined to be required, synchronizing the data change operation corresponding to the transaction to at least one target cluster based on the database change log. This method accurately identifies the source of transactions and effectively prevents synchronization loops by using the source node identifier and transaction identifier carried in the database change log, achieving cross-cluster data consistency and high availability without downtime.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of distributed technology, and in particular to a database synchronization method, apparatus, device, medium and product for a distributed system. Background Technology

[0002] In high-concurrency scenarios such as finance, e-commerce, and cloud computing, distributed databases need to adapt to load changes through dynamic scaling. Traditional solutions often rely on downtime switching, which is difficult to meet business continuity requirements.

[0003] In related technologies, cross-data center synchronization under a two-site three-center multi-active architecture needs to support bidirectional transmission and seamless switching. For example, when a payment tokenization system upgrades its storage, it needs to complete the smooth migration and rapid switchback of the old and new clusters without downtime.

[0004] However, existing technologies have significant shortcomings in addressing issues such as the asymmetry in the number of nodes between the source and target clusters, the loss of data source identifiers during cross-cluster synchronization, and loopbacks in synchronization operations, making it difficult to balance data consistency and high system availability. Summary of the Invention

[0005] This application provides a database synchronization method, apparatus, device, medium, and product for distributed systems. These methods aim to achieve accurate identification of transaction sources and effective prevention of synchronization loops in scaling scenarios where the number of nodes in the source cluster and the target cluster is asymmetrical. This is achieved by using the source node identifier and transaction identifier carried in the database change log to ensure data consistency and high availability across clusters without downtime.

[0006] In a first aspect, embodiments of this application provide a database synchronization method for a distributed system, the distributed system comprising multiple clusters, each cluster comprising a computing node, a synchronization node, and at least one database node; the method comprising:

[0007] For any transaction executed by a database node in any cluster, obtain the database change log corresponding to the transaction; wherein, the database change log includes a source node identifier and a transaction identifier written by the database node; the source node identifier is used to indicate the database node that first executes the data change operation corresponding to the transaction;

[0008] Based on the transaction identifier and the preset synchronization rules, determine whether the transaction needs to be synchronized.

[0009] If it is determined that transaction synchronization needs to be performed, the data change operation corresponding to the transaction is synchronized to at least one target cluster based on the database change log; wherein, the target cluster is another cluster among the plurality of clusters other than the current cluster.

[0010] In one possible implementation, before obtaining the database change log corresponding to the transaction, the method further includes:

[0011] The compute nodes in the current cluster receive business requests, generate corresponding transactions, and distribute the transactions to the database nodes in the current cluster according to the database sharding strategy.

[0012] The database nodes in the current cluster execute the transaction and write the transaction identifier and the node identifier of the database node into the logical log that records the data change operation to obtain the database change log.

[0013] In one possible implementation, the service request is a data operation request or data migration request from an external application, or a synchronization request from a synchronization node in the current cluster; the synchronization request is sent from a synchronization node in another cluster to a synchronization node in the current cluster.

[0014] In one possible implementation, writing a transaction identifier and the node identifier of the database node into a logical log recording the data change operations to obtain the database change log includes: writing a transaction identifier and the node identifier of the database node into a logical log recording the data change operations to obtain the database change log, including:

[0015] The database node performs a metadata recording operation, which carries the transaction identifier and the node identifier of the target database node. The metadata recording operation is a database operation that can be recorded to the logical log but does not generate persistent data storage.

[0016] The execution process of the metadata recording operation is recorded in the logical log so that the transaction identifier and the node identifier are recorded in the logical log, thereby obtaining the database change log.

[0017] In one possible implementation, the metadata recording operation is an insert statement for a target storage engine, which is a storage engine that does not generate actual data storage when performing a write operation.

[0018] In one possible implementation, the target storage engine is a black hole storage engine.

[0019] In one possible implementation, determining whether the transaction needs to undergo transaction synchronization based on the transaction identifier and preset synchronization rules includes:

[0020] The compute nodes in the current cluster determine the transaction type of the transaction based on the transaction identifier;

[0021] When it is determined that the transaction is either the migration transaction or the synchronization transaction, it is determined that transaction synchronization will not be performed; wherein, the migration transaction is a transaction executed to perform a data migration task, and the synchronization transaction is a transaction executed by the synchronization node from other clusters to the current cluster;

[0022] When it is determined that the transaction is a data operation transaction, it is determined that transaction synchronization needs to be performed.

[0023] In one possible implementation, based on the database change log, the data change operation corresponding to the transaction is synchronized to at least one target cluster, including:

[0024] The compute nodes in the current cluster generate a synchronization request based on the database change log and send the synchronization request to the synchronization node in the current cluster;

[0025] The synchronization node in the current cluster sends the synchronization request to the target synchronization node in the target cluster.

[0026] The target synchronization node forwards the synchronization request to the target computing node of the target cluster, so that the target computing node performs the data change operation on the target database node of the target cluster according to the synchronization request.

[0027] In one possible implementation, the target computing node performs the data change operation on the target database node of the target cluster according to the synchronization request, including:

[0028] The target computing node creates a corresponding synchronization transaction based on the synchronization request; the synchronization transaction contains at least one data change operation to be executed.

[0029] According to the database sharding strategy of the target cluster, the at least one data change operation is assigned to at least one target database node in the target cluster for execution; wherein, the at least one data change operation may be assigned to a target database node that does not correspond to the database node indicated by the source node identifier.

[0030] In one possible implementation, after obtaining the database change log corresponding to the transaction, the method further includes:

[0031] Based on the database change log and preset data backup conditions, determine whether the transaction needs to perform a data backup;

[0032] If it is determined that data backup is required, then through the computing nodes in the current cluster, according to the data change operation recorded in the database change log, a data backup operation is performed on the data object affected by the data change operation, so as to save the result data of the data object after the transaction is executed.

[0033] In one possible implementation, the data backup rules include at least one of a preset data object whitelist, a transaction type whitelist, and a node whitelist;

[0034] Based on the database change log and preset data backup conditions, determine whether the transaction needs to perform a data backup, including:

[0035] Parse the database change log to obtain the data object identifier affected by the data change operation, the transaction identifier contained in the database change log, and the node identifier;

[0036] When the data object identifier is in the data object whitelist, and / or the transaction identifier is in the transaction type whitelist, and / or the node identifier is in the node whitelist, it is determined that the transaction needs to perform data backup;

[0037] Otherwise, it is determined that the transaction does not require data backup.

[0038] Secondly, embodiments of this application provide a database synchronization device for a distributed system, the distributed system including multiple clusters, each cluster including computing nodes, synchronization nodes, and at least one database node; the device includes:

[0039] The log acquisition module is used to acquire the database change log corresponding to any transaction executed by a database node in any cluster; wherein, the database change log includes a source node identifier and a transaction identifier written by the database node; the source node identifier is used to indicate the database node that first executes the data change operation corresponding to the transaction;

[0040] The judgment module is used to determine whether the transaction needs to be synchronized based on the transaction identifier and the preset synchronization rules.

[0041] The synchronization module is used to synchronize the data change operation corresponding to the transaction to at least one target cluster based on the database change log if it is determined that transaction synchronization needs to be performed; wherein, the target cluster is another cluster among the plurality of clusters other than the current cluster.

[0042] Thirdly, embodiments of this application provide a server, including: a memory and a processor;

[0043] The memory stores computer-executed instructions;

[0044] The processor executes computer execution instructions stored in the memory, causing the processor to perform various possible implementations of the first and / or second aspects described above.

[0045] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement various possible implementations of the first and / or second aspects described above.

[0046] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements various possible implementations of the first and / or second aspects described above.

[0047] The database synchronization method, apparatus, device, medium, and product for distributed systems provided in this application, by carrying transaction identifiers in the database change log and cooperating with preset synchronization rules, enable computing nodes to accurately distinguish between data operation transactions, synchronization transactions, and migration transactions. Business transactions requiring synchronization are synchronized normally, while synchronization transactions are not returned to break the synchronization loop. Migration transactions caused by scaling are excluded from the synchronization scope to avoid operational interference. This solves the problems of synchronization loops and scaling interference caused by the inability to identify the transaction source in existing technologies. Furthermore, by embedding source node identifiers in the database change log, the original execution node information of each transaction is fully preserved. This allows the target cluster to flexibly redistribute data change operations based entirely on its own database sharding strategy, independent of the source cluster's node distribution structure, even in scaling scenarios where the number of database nodes in the source and target clusters is asymmetrical. Cross-cluster data playback can be achieved without interrupting business operations, thus solving the problem of traditional solutions' inability to smoothly scale due to node-to-node binding. Overall, it balances data consistency, system high availability, and elastic scaling capabilities in multi-cluster architectures. Attached Figure Description

[0048] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0049] Figure 1 A schematic diagram illustrating a scenario for the database synchronization method in the distributed system provided in this application;

[0050] Figure 2 A flowchart illustrating the database synchronization method for the distributed system provided in this application;

[0051] Figure 3 A schematic diagram of the structure of the database synchronization device for the distributed system provided in this application;

[0052] Figure 4 This is a schematic diagram of the structure of the database synchronization device for the distributed system provided in this application.

[0053] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0054] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0055] The collection, storage, use, processing, transmission, provision, and disclosure of financial data or user data involved in the technical solution of this application all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0056] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. The collection, use and processing of the relevant data shall comply with relevant laws, regulations and standards, and corresponding operation entry points shall be provided for users to choose to authorize or refuse.

[0057] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.

[0058] In high-concurrency scenarios such as finance, e-commerce, and cloud computing, distributed databases need to adapt to load changes through dynamic scaling. Traditional solutions often rely on downtime switching, which is difficult to meet business continuity requirements.

[0059] In related technologies, cross-data center synchronization under a two-site three-center multi-active architecture needs to support bidirectional transmission and seamless switching. For example, when a payment tokenization system upgrades its storage, it needs to complete the smooth migration and rapid switchback of the old and new clusters without downtime.

[0060] However, existing technologies have significant shortcomings in addressing issues such as the asymmetry in the number of nodes between the source and target clusters, the loss of data source identifiers during cross-cluster synchronization, and loopbacks in synchronization operations, making it difficult to balance data consistency and high system availability.

[0061] In other words, in a distributed multi-cluster architecture, data synchronization faces the challenge of both spreading data changes to all clusters to achieve high availability, strictly avoiding infinite loops of change logs between clusters (i.e., A synchronizes to B, and B then synchronizes the log back to A as a new transaction), and also dealing with the differentiated synchronization needs of different clusters undertaking different business roles.

[0062] To address the aforementioned technical issues, this embodiment provides a database synchronization method for distributed systems. This method embeds a source node identifier and a transaction identifier into the database change log of each transaction. This allows any cluster, upon obtaining the log, to distinguish the transaction type based on the source node identifier and transaction identifier, and whether the transaction is an original business operation or synchronized from another cluster. This allows for direct filtering of synchronized transactions during synchronization, fundamentally preventing synchronization loops. Furthermore, the source node identifier fully records the initial execution node information of the data change operation. Even in scaling scenarios where the number of nodes in the source and target clusters is asymmetrical, the target cluster does not need to rely on the node correspondence with the source cluster. It can flexibly redistribute and replay data change operations based on a local database sharding strategy. This achieves cross-cluster data consistency and smooth scaling without interrupting business operations, improving system high availability.

[0063] The database synchronization method for distributed systems provided in this application is applicable to high-concurrency business systems with strict requirements for data consistency and business continuity under a multi-cluster architecture.

[0064] For example, in the scenario of upgrading the storage architecture of a payment tokenization system, the number of database nodes in the source cluster and the target cluster is usually asymmetrical, and the data migration and bidirectional synchronization between the old and new clusters need to be completed without downtime. This application can completely retain the data source information through the source node identifier, so that the target cluster can be freed from the dependence on the distribution of nodes in the source cluster and independently complete the replay of data change operations. At the same time, the transaction type identifier can effectively filter the synchronization loop, ensuring the smoothness and security of the switching process.

[0065] In addition, the above methods can also be applied to scenarios such as cross-data center data synchronization in a two-site three-center multi-active architecture, data redistribution during the online scaling up and down process of distributed databases, and real-time incremental data synchronization between heterogeneous database clusters.

[0066] In summary, any business scenario that requires uninterrupted, loop-free, and strongly consistent data synchronization during changes in the number of cluster nodes or multi-cluster collaboration falls under the application scenarios of the distributed system database synchronization technology solution in this application.

[0067] Figure 1 A schematic diagram illustrating a scenario for the database synchronization method in the distributed system provided in this application. See also... Figure 1 Taking the upgrade of the storage architecture of the payment tokenization system as an example, this scenario involves a user terminal (used to initiate payment transaction requests) and a distributed database cluster system (including a source cluster and a target cluster, each containing computing nodes, synchronization nodes and multiple database nodes, used to process payment transaction data and achieve cross-cluster synchronization).

[0068] In this scenario, the number of database nodes in the source cluster is asymmetrical with that in the target cluster, and data migration and bidirectional synchronization between the old and new clusters must be completed without downtime.

[0069] Based on this, the technical solution proposed in this application includes the following steps in this scenario:

[0070] The compute nodes of the source cluster receive the payment transaction request initiated by the user terminal, create the corresponding transaction, and assign it to the database nodes of the source cluster for execution. After the database nodes of the source cluster execute the transaction, they generate a database change log and write the source node identifier (indicating the database node where the transaction is first executed) and the transaction type identifier (indicating that the transaction is a data operation transaction that requires synchronization) into the log.

[0071] The compute nodes of the source cluster obtain the database change log. If the transaction identifier determines that the transaction needs to be synchronized, a synchronization request is generated based on the database change log, and the synchronization request is sent to the target synchronization node of the target cluster through the synchronization node of the source cluster.

[0072] The target synchronization node in the target cluster forwards the synchronization request to the target compute node in the target cluster. The target compute node creates a corresponding synchronization transaction based on the synchronization request and, according to the local database sharding strategy of the target cluster, distributes the data change operations contained in the synchronization transaction to at least one target database node in the target cluster that does not correspond to the database node indicated by the source node identifier for execution. At the same time, the target cluster marks the transaction type identifier as a synchronization transaction in the database change log generated after the execution of the synchronization transaction to prevent it from being subsequently sent back to the source cluster.

[0073] Through the above steps, in the scenario of upgrading a payment system where the number of nodes in the source cluster and the target cluster is asymmetrical, smooth cross-cluster data migration and bidirectional synchronization are achieved without interrupting business operations. At the same time, by accurately distinguishing between transactions that need to be synchronized and those that do not through transaction type identifiers, synchronization loops and scaling interference are effectively prevented, ensuring the consistency of payment transaction data and high availability of the system.

[0074] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0075] Figure 2 This is a flowchart illustrating the database synchronization method for the distributed system provided in this application. Figure 2 As shown, the method includes:

[0076] S201. For any transaction executed by a database node in any cluster, obtain the database change log corresponding to the transaction.

[0077] In this embodiment, the distributed system comprises multiple clusters, each of which deploys compute nodes, synchronization nodes, and at least one database node. The compute nodes are responsible for receiving business requests and generating corresponding transactions, the database nodes are responsible for actually executing the transactions and persisting the data, and the synchronization nodes are responsible for cross-cluster data synchronization communication.

[0078] When any database node in any cluster executes a transaction, the transaction may be a business operation initiated by an external application (such as a payment transaction, order update, etc.), a migration operation initiated by a data migration tool during scaling up or down, or a synchronization operation synchronized from other clusters. For transactions from all sources, in addition to completing the actual execution of data change operations, the database node will generate a database change log corresponding to the transaction during the execution of the transaction.

[0079] Specifically, when a database node commits a transaction, it records the data changes made by that transaction in the logical log and writes two key pieces of metadata into the logical log: the source node identifier and the transaction identifier.

[0080] The source node identifier is used to indicate the database node that first executes the data change operation corresponding to the transaction. When the transaction is an original transaction directly initiated by an external application, the source node identifier is the node identifier of the database node currently executing the transaction. When the transaction is a synchronous transaction synchronized from another cluster, the source node identifier carried in its database change log is still the identifier of the database node that first executes the transaction in the source cluster, and will not be overwritten or lost due to cross-cluster transmission.

[0081] A transaction identifier can characterize the type of a transaction. For example, a transaction identifier can include a transaction type identifier, which is determined and written by the database node executing the transaction based on the transaction's origin or nature. For instance, a database node marks a regular data operation transaction initiated directly by an external application as a data operation transaction; a transaction initiated by a data migration tool during internal cluster scaling is marked as a migration transaction; and a synchronization transaction from another cluster is also marked as a synchronization transaction. Thus, transaction identifiers and predefined synchronization rules clearly distinguish whether a transaction should be considered for cross-cluster synchronization.

[0082] After the database node writes both the source node identifier and the transaction identifier to the logical log, this logical log becomes the database change log. It can be understood that the database change log not only contains the specific data modification operations performed on the database by the transaction, but also the aforementioned source node identifier and transaction identifier, ensuring that the log has complete contextual information for subsequent synchronization judgments and processing.

[0083] Based on this, compute nodes obtain the generated database change logs from database nodes through subscription or pull. For example, compute nodes and database nodes communicate through a log synchronization protocol. After a transaction is committed and a database change log is generated, the database node actively or upon request sends the log to the compute node so that the compute node can perform subsequent synchronization judgments and processing.

[0084] Through the above method, this embodiment achieves complete recording of the first execution node information and transaction type information in the database change log of each transaction. This enables any cluster's computing node to accurately identify the original execution location and synchronization attributes of the transaction after obtaining the log, even in a distributed environment with multiple clusters, multiple nodes, and complex transaction sources. This provides a reliable basis for subsequent synchronization rule judgment and cross-cluster replay.

[0085] S202. Based on the transaction identifier and the preset synchronization rules, determine whether the transaction needs to be synchronized.

[0086] After the compute node obtains the database change log, it extracts the transaction identifier from the database change log and matches the transaction identifier with the preset synchronization rules to determine whether the current transaction needs to perform cross-cluster transaction synchronization.

[0087] In one implementation, the process of determining whether a transaction needs to be synchronized may include: the compute nodes in the current cluster determining the transaction type based on the transaction identifier; when the transaction is determined to be a migration transaction or a synchronization transaction, determining that transaction synchronization should not be performed; wherein, a migration transaction is a transaction executed to perform a data migration task, and a synchronization transaction is a transaction synchronized from other clusters to the current cluster by a synchronization node and executed; when the transaction is determined to be a data operation transaction, determining that transaction synchronization needs to be performed.

[0088] In this embodiment, the transaction identifier includes a transaction type identifier, which is used to characterize the specific type of transaction. In this embodiment, the transaction types include at least the following: data operation transactions, synchronization transactions, and migration transactions.

[0089] Data manipulation transactions refer to transactions initiated directly by external applications to perform specific business data modification operations, such as payment transactions, order creation, balance updates, and inventory deductions. These transactions perform actual business data changes on the database, and the results of these changes need to be consistent across multiple clusters.

[0090] Synchronization transactions refer to transactions created and executed on the database nodes of the target cluster after the target cluster's synchronization node receives a synchronization request from the source cluster. Essentially, this type of transaction is a replay of data operation transactions in the source cluster, where the data changes have already been generated and synchronized. Synchronizing such transactions back to the source cluster or other clusters will cause a synchronization loop, leading to data inconsistencies or even system anomalies.

[0091] A migration transaction refers to a data migration operation initiated by a data migration tool when scaling up or down database nodes within a cluster. This type of transaction is used to migrate some data from one database node to another within the cluster. It is an internal cluster maintenance operation, and its data change scope is limited to the current cluster and does not need to be synchronized to other clusters.

[0092] The preset synchronization rules define the mapping relationship between transaction types and whether synchronization is required. In one implementation, these synchronization rules can be configured and stored in the compute nodes in the form of a mapping table. For example, the rules may explicitly state that synchronization is required when the transaction type is a data operation transaction, and not required when the transaction type is a synchronization transaction or a migration transaction.

[0093] After obtaining the database change log, the compute node parses the transaction type identifier in the log to determine the transaction type of the current transaction. If the current transaction is determined to be a data operation transaction, it is determined that the transaction needs to be synchronized according to the preset synchronization rules; if the current transaction is determined to be a synchronization transaction, it is determined that the transaction does not need to be synchronized according to the preset synchronization rules, thereby avoiding synchronizing the transaction back to the source cluster and effectively preventing synchronization loops; if the current transaction is determined to be a migration transaction, it is determined that the transaction does not need to be synchronized according to the preset synchronization rules, thereby preventing data migration operations during the scaling up or down process within the cluster from being propagated to other clusters, ensuring the purity of the synchronization link and the independence of scaling up or down operations.

[0094] The above method utilizes the matching and judgment between the transaction type identifier carried in the database change log and the preset synchronization rules to achieve differentiated synchronization processing for different types of transactions. Specifically, for actual data operation transactions initiated by external applications, it ensures that they are synchronized to other clusters to maintain data consistency across multiple clusters. For synchronization transactions, they are excluded from the synchronization scope to break synchronization loops. Similarly, migration transactions resulting from scaling up or down are excluded to avoid interference from operational operations on cross-cluster synchronization, thereby achieving overall stability, reliability, and data consistency of the distributed system under multi-cluster collaborative operation.

[0095] S203. If it is determined that transaction synchronization needs to be performed, then based on the database change log, synchronize the data change operations corresponding to the transaction to at least one target cluster.

[0096] Once a compute node determines that a transaction needs to be synchronized based on the transaction type identifier and preset synchronization rules, it initiates a cross-cluster synchronization process to synchronize the data change operations corresponding to the current transaction to at least one target cluster. The target cluster is any cluster in the distributed system other than the current cluster; it can be one cluster or multiple clusters, depending on the configuration of the synchronization rules or the system topology.

[0097] Specifically, the compute nodes in the current cluster first generate a synchronization request based on the acquired database change log. This synchronization request contains two parts: first, the content of the data change operation, that is, the specific operation performed on the database by the transaction as recorded in the database change log, such as table name, operation type, and data values ​​before and after the change; second, the source node identifier carried in the database change log, which indicates the database node that first executed the data change operation corresponding to the transaction.

[0098] The compute node sends the generated synchronization request to the synchronization node in the current cluster, which then forwards the synchronization request to the target synchronization node in the target cluster. Upon receiving the synchronization request, the target synchronization node forwards it to the target compute node in the target cluster.

[0099] The target synchronization node forwards the synchronization request to the target compute node in the target cluster, so that the target compute node can perform data change operations on the target database node in the target cluster according to the synchronization request.

[0100] After executing the synchronization transaction, the database nodes in the target cluster generate a new database change log, marking the transaction type as a synchronization transaction in this log. Thus, when the compute nodes in the target cluster subsequently retrieve this log and perform synchronization checks, they can identify the transaction as a synchronization transaction based on the synchronization rules, thereby determining that they do not need to perform transaction synchronization again, effectively eliminating the possibility of synchronization loops.

[0101] The database synchronization method for distributed systems provided in this application, by carrying transaction identifiers in the database change log and cooperating with preset synchronization rules, enables computing nodes to accurately distinguish between data operation transactions, synchronization transactions, and migration transactions. Business transactions requiring synchronization are synchronized normally, while synchronization transactions are not returned to break the synchronization loop. Migration transactions resulting from scaling are excluded from the synchronization scope to avoid operational interference. This solves the problems of synchronization loops and scaling interference caused by the inability to identify the transaction source in existing technologies. Furthermore, by embedding source node identifiers in the database change log, the original execution node information of each transaction is fully preserved. This allows the target cluster to flexibly redistribute data change operations based entirely on its own database sharding strategy, independent of the source cluster's node distribution structure, even in scaling scenarios where the number of database nodes in the source and target clusters is asymmetrical. Cross-cluster data playback can be achieved without interrupting business operations, thus solving the problem of traditional solutions' inability to smoothly scale due to node-to-node binding. Overall, this method balances data consistency, system high availability, and elastic scaling capabilities in multi-cluster architectures.

[0102] Next, the technical principles of the database synchronization technology solution for the distributed system provided in this application will be further explained. It should be noted that the following description is merely an exemplary implementation of the technical solution of this application and does not constitute any limitation on the technical solution of this application.

[0103] In this embodiment, before the compute node obtains the database change log corresponding to the transaction, it must first receive the business request and create the corresponding transaction, and then assign the transaction to the database node for execution to generate the database change log.

[0104] In one implementation, generating a database change log may include: a compute node in the current cluster receiving a business request, generating a corresponding transaction, and allocating the transaction to a database node in the current cluster according to a database sharding strategy; the database node in the current cluster executing the transaction and writing the transaction identifier and the node identifier of the database node into a logical log that records data change operations to obtain the database change log.

[0105] The compute nodes in the current cluster receive service requests. These service requests can come from various sources. For example, a service request may be a data operation request or data migration request from an external application, or it may be a synchronization request from a synchronization node in the current cluster; a synchronization request may be sent from a synchronization node in another cluster to a synchronization node in the current cluster.

[0106] Specifically, in one scenario, business requests originate from external applications, such as payment transaction requests, order creation requests, or account information update requests initiated by users through terminal devices. These requests fall under the category of routine data operation requests. In another scenario, business requests may originate from data migration tools, such as data migration requests initiated by the data migration tool to compute nodes when scaling up or down database nodes within a cluster. Furthermore, business requests can also be synchronization requests from synchronization nodes within the current cluster. These requests are sent from synchronization nodes in other clusters to the synchronization node in the current cluster, and then forwarded by the synchronization node in the current cluster to the compute node, used to create corresponding synchronization transactions on the target cluster side.

[0107] In this way, by uniformly accepting business requests from different sources (data operation requests or data migration requests from external applications, as well as synchronization requests from other clusters) by the computing nodes, the database nodes can accurately write the corresponding transaction identifier according to the actual source of the transaction when executing the transaction. This ensures that the subsequent synchronization judgment can correctly distinguish between data operation transactions that need to be synchronized and synchronization transactions and migration transactions that do not need to be synchronized, effectively preventing synchronization loops.

[0108] After receiving a business request, the compute node creates a corresponding transaction based on that request. This transaction contains one or more data modification operations to be executed, such as insert, update, or delete operations on a database table. The compute node then assigns the transaction to the target database node in the current cluster for execution according to a pre-defined database sharding strategy. The database sharding strategy determines which database nodes(s) should execute the transaction; for example, it may perform a hash calculation based on the sharding key of the data to be manipulated, routing the transaction to the appropriate database node.

[0109] The database node assigned to the transaction executes the transaction, completing the actual data modification operations on the database. Upon transaction commit, the database node generates a logical log recording the data modification operations. This logical log contains the specific operations performed by the transaction, such as the operation type (INSERT, UPDATE, DELETE), the table and field names involved, and the data values ​​before and after the changes.

[0110] Building upon the above, the database node also writes two identification pieces to the logical log: a transaction identifier, which characterizes the transaction type; and a node identifier, which is the identifier of the database node currently executing the transaction. This node identifier is retained in the database change log as the source node identifier, indicating the database node that first executed the data change operation corresponding to the transaction. By writing these identification pieces to the logical log, the logical log is formed into the database change log.

[0111] The above implementation method, by clearly defining the division of labor and cooperation between computing nodes responsible for request access and transaction distribution, and database nodes responsible for transaction execution and identifier writing, enables the database change log to fully record the transaction source and execution node information during the generation stage, providing a reliable information foundation for the accurate judgment of subsequent synchronization rules and the flexible replay of the target cluster.

[0112] In the above implementation, the database node also writes two identification information items into the logical log. The process of generating the database change log may include: the database node performing a metadata recording operation, which carries a transaction identifier and a node identifier of the target database node. The metadata recording operation is a database operation that can be recorded to the logical log but does not generate persistent data storage. The execution process of the metadata recording operation is recorded in the logical log so that the transaction identifier and the node identifier are recorded in the logical log, thus obtaining the database change log.

[0113] Specifically, after a database node completes the data change operations included in the current transaction and generates the corresponding logical log, it performs a metadata record operation before or within the same context as the transaction commit. This metadata record operation carries two parameters: one is the transaction identifier, which is mainly used to characterize the transaction type of the current transaction; the other is the node identifier, which is the node identifier of the database node currently executing the transaction.

[0114] By recording the execution process of metadata recording operations in the logical log, the logical log naturally contains the transaction identifier and node identifier. At this point, the logical log is transformed into a database change log, resulting in the database change log. Subsequent compute nodes, when retrieving this database change log, can parse the source node identifier and transaction identifier from it for determining synchronization rules.

[0115] It should be understood that the metadata recording operation provided in this embodiment is a special database operation, that is, the execution process of the operation can be recorded in the logical log by the database system, so that the transaction identifier and node identifier carried by the operation are written into the logical log as part of the operation content; however, at the same time, the operation itself does not produce persistent data storage effect, that is, it will not actually store any data in the database tablespace, nor will it have any impact on business data.

[0116] In the above embodiments, the identifier writing method based on metadata recording operations does not require intrusive modifications to the database kernel, nor does it require creating additional business data tables in the database to store identifier information, thus avoiding the additional storage space overhead caused by identifier information storage. Furthermore, since metadata recording operations and business transactions are executed within the same transaction context, the writing of transaction identifiers and node identifiers is consistent with the recording of data change operations, preventing the separation or asynchrony of identifier information and operation information, and ensuring the integrity and reliability of the database change log.

[0117] In one implementation, the metadata recording operation is an insert statement targeting a storage engine, which is a storage engine that does not generate actual data storage when performing a write operation.

[0118] After the database node completes the data modification operations contained in the current transaction and generates a logical log recording these operations, within the same transaction context, the database node constructs an INSERT statement. The target table of this INSERT statement is a table created based on the target storage engine, and the inserted field values ​​are the transaction identifier and node identifier to be recorded. Due to the characteristics of the target storage engine, upon receiving the insert request, the INSERT statement performs routine processes such as syntax parsing and permission verification. However, in the actual data writing phase, the target storage engine does not perform any persistent storage actions but directly returns a success message. Therefore, this insert operation does not incur any additional disk space usage and does not affect the data in the database.

[0119] Meanwhile, when a transaction is committed, the database system writes all operations performed during the transaction's execution to the logical log. Since this INSERT statement is part of the current transaction, its execution is also recorded in the logical log. The logical log does not record the table data itself, but rather the execution instructions of the INSERT statement and its parameter information. Therefore, the transaction identifier and node identifier, as parameters of the INSERT statement, are naturally embedded in the logical log's operation records.

[0120] Using the above method, a database node only needs to execute a single INSERT statement targeting the target storage engine to completely record the transaction identifier and node identifier in the logical log, thereby transforming the logical log into a database change log. This method requires no modification to the database kernel, nor does it require creating additional business data tables to specifically store the identifier information, thus incurring no additional disk space usage. Furthermore, because the INSERT statement is committed within the same transaction context as the business transaction, the writing of the transaction identifier and node identifier and the recording of data change operations have inherent transactional consistency, preventing inconsistencies caused by partial commit failures and ensuring the integrity and reliability of the database change log.

[0121] In one alternative implementation, the target storage engine is a black hole storage engine.

[0122] Specifically, the Blackhole storage engine provides a standard table operation interface, supporting common SQL statements such as CREATE TABLE and INSERT. When a database node executes an INSERT statement on a table created using the Blackhole storage engine, the engine will complete the syntax parsing, permission verification, and other processes normally, and return a successful execution result. However, in the underlying data writing phase, the Blackhole storage engine does not perform any actual data storage operations; the inserted data is not written to disk or tablespace but is directly discarded. Therefore, a table created using the Blackhole storage engine is always an empty table and does not occupy any data storage space.

[0123] In this embodiment, the database node leverages the aforementioned characteristics of the Blackhole storage engine to create a metadata record table based on the Blackhole storage engine. Transaction identifiers and node identifiers are then written to this table using INSERT statements. Since the execution of the INSERT statement is recorded in the database system's logical log, the transaction identifier and node identifier, as parameters of the INSERT statement, are naturally carried over to the logical log. The INSERT statement itself, due to the characteristics of the Blackhole storage engine, does not generate any persistent data. Thus, the database node completes the writing of identifier information to the logical log with zero storage cost, realizing the transformation of the logical log into a database change log.

[0124] The above implementation specifically limits the target storage engine to the Black Hole storage engine. By utilizing its characteristics as a built-in standard engine of the database, which requires no additional deployment and whose write operations do not generate any persistent data storage, transaction identifiers and node identifiers can be recorded in the logical log in the simplest and most reliable way, thereby realizing the generation of database change logs with zero storage cost.

[0125] Based on the above implementation method, the compute node reads the data change log of the transaction, and determines whether the transaction needs to be synchronized according to the transaction identifier in the log and the preset synchronization rules. When it is determined that transaction synchronization needs to be performed, the cross-cluster synchronization process is started.

[0126] In one implementation, the process of synchronizing data change operations corresponding to a transaction to at least one target cluster based on a database change log includes: a compute node in the current cluster generating a synchronization request based on the database change log and sending the synchronization request to a synchronization node in the current cluster; the synchronization node in the current cluster sending the synchronization request to a target synchronization node in the target cluster; and the target synchronization node forwarding the synchronization request to a target compute node in the target cluster, so that the target compute node performs the data change operation on the target database node in the target cluster according to the synchronization request.

[0127] Specifically, the compute nodes in the current cluster generate synchronization requests based on the acquired database change logs. These requests include the details of the data change operations and the source node identifier carried in the database change logs. The compute nodes then send the generated synchronization requests to the synchronization nodes in the current cluster, which are responsible for cross-cluster transmission.

[0128] The synchronization nodes in the current cluster send synchronization requests to the target synchronization node in the target cluster. Clusters communicate via dedicated synchronization links, and synchronization nodes maintain long-lived connections to ensure real-time and reliable transmission of synchronization requests. Upon receiving the synchronization request, the target synchronization node forwards it to the target compute node in the target cluster.

[0129] The target compute node performs data modification operations on the target database node of the target cluster based on the synchronization request.

[0130] Specifically, the target compute node creates a synchronization transaction based on the synchronization request. This transaction contains one or more data modification operations to be executed. According to the target cluster's local database sharding strategy, the data modification operation is assigned to at least one target database node in the target cluster for execution. This assignment process is entirely based on the target cluster's own database sharding strategy and is not constrained by the source node identifier carried in the synchronization request. Therefore, a data modification operation can be assigned to a node corresponding to the database node indicated by the source node identifier, or it can be assigned to a non-corresponding node. When a transaction contains multiple data modification operations, these operations can also be split and assigned to different target database nodes for execution. This mechanism allows the target cluster to flexibly complete data replay based on its own architecture even if the number of database nodes in the source and target clusters is asymmetrical.

[0131] After the database nodes in the target cluster have completed their execution, the transaction type is marked as a synchronous transaction in the generated database change log to ensure that the transaction will not be sent back to the source cluster, thereby effectively preventing synchronous loops.

[0132] The above implementation method, through the clear division of labor of computing nodes generating synchronization requests, synchronization nodes being responsible for cross-cluster transmission, and target computing nodes being responsible for target-side playback, enables data change operations to be efficiently and reliably transmitted to the target cluster for execution, providing a stable transmission guarantee for cross-cluster data consistency.

[0133] In the implementation of the above method, the process of the target computing node performing data change operations on the target database node of the target cluster according to the synchronization request may include: the target computing node creating a corresponding synchronization transaction according to the synchronization request; the synchronization transaction containing at least one data change operation to be executed; and, according to the database sharding strategy of the target cluster, assigning at least one data change operation to at least one target database node in the target cluster for execution; wherein, at least one data change operation may be assigned to a target database node that does not correspond to the database node indicated by the source node identifier for execution.

[0134] Specifically, the target compute node parses the synchronization request to obtain the data modification operations to be executed and the source node identifier. Based on the parsed synchronization request content, a corresponding synchronization transaction is created. This synchronization transaction contains at least one data modification operation to be executed, and these data modification operations logically correspond completely to the data modification operations of the original transaction in the source cluster to ensure cross-cluster data consistency.

[0135] The target compute node, based on the target cluster's local database sharding strategy, distributes the at least one data change operation to at least one target database node in the target cluster for execution. The database sharding strategy here refers to the target cluster's own preset data distribution rules, such as hash routing based on sharding keys or range routing strategies, used to determine which database node(s) in the cluster should execute the specific data change operation.

[0136] It should be noted that when allocating the target computing nodes as described above, the allocation is based entirely on the target cluster's own database sharding strategy, and is not constrained by the source node identifier carried in the synchronization request. This means that there is no mandatory correspondence between the target database node in the target cluster that undertakes the execution of the synchronization transaction and the database node in the source cluster that first executes the transaction, as indicated by the source node identifier. Specifically, at least one data change operation can be assigned to a target database node corresponding to the database node indicated by the source node identifier, or it can be assigned to a target database node that does not correspond to the database node indicated by the source node identifier. Furthermore, when a synchronization transaction contains multiple data change operations, these operations can be split and assigned to different target database nodes in the target cluster for execution, without having to follow the node distribution pattern of the original transaction in the source cluster.

[0137] For example, during the migration of a payment tokenization system from an older database cluster to a newer one, the older cluster might have four database nodes, while the new cluster might expand to eight. The number of nodes and sharding distribution differ between the two clusters. In this scenario, upon receiving a synchronization request, the target cluster's compute nodes can, based on the new cluster's sharding strategy (8 nodes), redistribute multiple data modification operations from a payment transaction executed on a node in the source cluster to one or more corresponding database nodes in the new cluster, without being constrained by the node distribution of the older cluster. This allows data to be redistributed simultaneously according to the new cluster's sharding strategy during cross-cluster synchronization, achieving a fusion of data synchronization and data redistribution, significantly improving the efficiency and flexibility of scaling up and down.

[0138] After allocation is complete, each target database node executes the data change operations assigned to it. Upon completion, when generating a new database change log, the database nodes in the target cluster mark the transaction type in the log as a synchronization transaction. This ensures that the transaction will not be processed as a synchronization request again on the target cluster side, effectively preventing synchronization loops.

[0139] The above implementation method, after the target computing node creates a synchronization transaction, allocates data change operations entirely according to the target cluster's own database sharding strategy, and allows operations to be allocated to database nodes that do not correspond to the source node identifier. This breaks the dependence of cross-cluster synchronization on the distribution structure of the source cluster nodes, enabling the target cluster to flexibly complete data replay in scaling scenarios where the number of nodes in the source cluster and the target cluster is asymmetrical, thus achieving the integration of data synchronization and data redistribution.

[0140] After the compute nodes obtain the database change log, in addition to determining whether cross-cluster synchronization is required based on the transaction identifier and preset synchronization rules, they further determine whether data backup is required for the transaction. Data backup and transaction synchronization are two independent but parallel operations, both based on the same database change log to complete their respective judgments and processing.

[0141] In one implementation, the process of performing data backup may include: the compute node determining whether a transaction needs to be backed up based on the database change log and preset data backup conditions; if it is determined that data backup is needed, the compute node in the current cluster performs a data backup operation on the data object affected by the data change operation based on the data change operation recorded in the database change log, so as to save the result data of the data object after the transaction is executed.

[0142] Specifically, the compute node extracts relevant information from the database change log and matches the extracted information with preset data backup conditions to determine whether the current transaction needs to perform a data backup.

[0143] When a compute node determines that a data backup is required for the current transaction, it identifies the data object affected by the data change operations recorded in the database change log and performs a data backup operation on that data object to save the resulting data of that data object after the transaction execution. The resulting data here refers to the final data state of the data object after being updated by the data change operations of the current transaction, not the transaction log itself or intermediate state data.

[0144] In one implementation, compute nodes can perform backup operations by sending backup commands to the backup storage system. These commands carry the identifiers of the data objects and the results of the transaction execution. Upon receiving the command, the backup storage system persists the results. The backup storage system can be an object storage system independent of the database cluster, a distributed file system, or a dedicated backup server, to ensure physical isolation between backup data and production data and improve data security.

[0145] In the above approach, by seamlessly embedding data backup judgment and execution into the database synchronization link, the computing node can automatically identify important data changes and trigger backups based on preset conditions while completing the synchronization judgment. This mechanism does not require the deployment of additional data capture components or modification of database nodes. Instead, it reuses the existing database change log acquisition and parsing link, achieving real-time backup protection of critical business data with extremely low system overhead, further improving the data reliability and disaster recovery capabilities of the distributed system.

[0146] In one implementation, the preset data backup conditions may include at least one of a data object whitelist, a transaction type whitelist, and a node whitelist. Accordingly, the process of determining whether a data backup is required may include: parsing the database change log to obtain the data object identifier affected by the data change operation, the transaction identifier contained in the database change log, and the node identifier; if the data object identifier is in the data object whitelist, and / or the transaction identifier is in the transaction type whitelist, and / or the node identifier is in the node whitelist, then the transaction is determined to require a data backup; otherwise, the transaction is determined not to require a data backup.

[0147] In this embodiment, preset data backup conditions are used to provide computing nodes with a basis for determining whether a transaction needs to be backed up. These data backup conditions are flexibly configurable and specifically include at least one of a data object whitelist, a transaction type whitelist, and a node whitelist. These three types of whitelists define the transaction characteristics that require data backup from different dimensions. Users can choose to use a single type of whitelist or combine multiple types of whitelists according to their actual business needs to achieve backup strategy control at different granularities.

[0148] Accordingly, after obtaining the database change log, the compute node parses the database change log and extracts the following information from the log: first, the data object identifier, that is, the identifier of the database table or data object to which the data change operation is applied; second, the transaction type identifier, that is, the identifier written by the database node when executing the transaction to represent the transaction type; and third, the node identifier, that is, the identifier of the database node that executes the transaction.

[0149] The parsed information is matched one by one with the corresponding whitelist.

[0150] In one scenario, when the data backup conditions only include a data object whitelist, the compute node determines whether the identifier of the data object affected by the data change operation is within that whitelist. If it is, a data backup is required; otherwise, it is not required. For example, an e-commerce system might configure its product inventory table and order transaction table in the data object whitelist. Any transaction involving changes to these two tables will trigger a backup. However, the user browsing log table is not in the whitelist, so transactions involving this table will not trigger a backup.

[0151] In another scenario, when the data backup conditions only include a transaction type whitelist, the compute node determines whether the transaction type identifier is within that whitelist. For example, the transaction type whitelist can be configured to only include data operation transactions, in which case all business data change transactions directly initiated by external applications will trigger backups; while synchronization and migration transactions are excluded, avoiding unnecessary backup overhead caused by cross-cluster synchronization playback and internal cluster data redistribution operations.

[0152] In another scenario, when data backup conditions only include a node whitelist, the compute node determines whether the node identifier is within that whitelist. For example, in a multi-replica deployment architecture, the primary database node, which handles the majority of business traffic, can be included in the node whitelist, while read-only replica nodes can be excluded. This ensures that only transactions executed on the primary database node are backed up, guaranteeing the protection of core data while avoiding redundant backups.

[0153] In more complex business scenarios, data backup conditions can simultaneously include two or all three of the aforementioned three whitelists, combined using "AND" or "OR" logic. For example, when the conditions are configured as an AND relationship between the data object whitelist and the transaction type whitelist, backup is triggered only if both the transaction's data object identifier and transaction type identifier are in the data object whitelist; when the conditions are configured as an OR relationship, backup is triggered if either condition is met. This flexible combination configuration allows backup strategies to precisely adapt to the differentiated data protection needs of different business systems.

[0154] In this way, computing nodes can quickly and accurately filter out the key transactions that need to be backed up from a large number of transactions, avoiding the storage and performance overhead of full backup, and realizing fine-grained management and on-demand execution of data backup.

[0155] Figure 3 This is a schematic diagram of the database synchronization device for the distributed system provided in this application. Figure 3 As shown, the database synchronization device 30 for a distributed system provided in this embodiment includes:

[0156] The log acquisition module 301 is used to acquire the database change log corresponding to any transaction executed by a database node in any cluster; wherein, the database change log includes the source node identifier and the transaction identifier written by the database node; the source node identifier is used to indicate the database node that first executes the data change operation corresponding to the transaction;

[0157] The judgment module 302 is used to determine whether a transaction needs to be synchronized based on the transaction identifier and the preset synchronization rules.

[0158] The synchronization module 303 is used to synchronize the data change operations corresponding to the transaction to at least one target cluster based on the database change log if it is determined that transaction synchronization needs to be performed; wherein, the target cluster is another cluster other than the current cluster among multiple clusters.

[0159] In one possible implementation, the device is also used for:

[0160] The compute nodes in the current cluster receive business requests, generate corresponding transactions, and distribute the transactions to the database nodes in the current cluster according to the database sharding strategy.

[0161] The database nodes in the current cluster execute transactions and write the transaction identifier and the node identifier of the database node into the logical log that records data change operations to obtain the database change log.

[0162] In one possible implementation, the business request is a data operation request or data migration request from an external application, or a synchronization request from a synchronization node in the current cluster; the synchronization request is sent from a synchronization node in another cluster to a synchronization node in the current cluster.

[0163] In one possible implementation, the device is further configured to: write transaction identifiers and database node identifiers into a logical log that records data change operations to obtain a database change log, including:

[0164] The database node performs a metadata recording operation. The metadata recording operation carries the transaction identifier and the node identifier of the target database node. The metadata recording operation is a database operation that can be recorded to the logical log but does not generate persistent data storage.

[0165] The execution process of the metadata recording operation is recorded in the logical log so that the transaction identifier and node identifier are recorded in the logical log, thus obtaining the database change log.

[0166] In one possible implementation, the metadata recording operation is an insert statement targeting a storage engine that does not generate actual data storage when performing a write operation.

[0167] In one possible implementation, the target storage engine is a black hole storage engine.

[0168] In one possible implementation, the judgment module 302 is specifically used for:

[0169] The compute nodes in the current cluster determine the transaction type based on the transaction identifier;

[0170] When a transaction is determined to be a migration transaction or a synchronization transaction, it is determined not to perform transaction synchronization. A migration transaction is a transaction executed to perform a data migration task, while a synchronization transaction is a transaction executed by a synchronization node to synchronize data from other clusters to the current cluster.

[0171] When a transaction is determined to be a data operation transaction, it is determined that transaction synchronization needs to be performed.

[0172] In one possible implementation, the synchronization module 303 is specifically used for:

[0173] The compute nodes in the current cluster generate synchronization requests based on the database change logs and send the synchronization requests to the synchronization nodes in the current cluster;

[0174] The synchronization node in the current cluster will send the synchronization request to the target synchronization node in the target cluster;

[0175] The target synchronization node forwards the synchronization request to the target compute node in the target cluster, so that the target compute node can perform data change operations on the target database node in the target cluster according to the synchronization request.

[0176] In one possible implementation, the synchronization module 303 is specifically used for:

[0177] The target compute node creates a corresponding synchronization transaction based on the synchronization request; the synchronization transaction contains at least one data change operation to be executed.

[0178] According to the database sharding strategy of the target cluster, at least one data change operation is assigned to at least one target database node in the target cluster for execution; wherein, at least one data change operation may be assigned to a target database node that does not correspond to the database node indicated by the source node identifier.

[0179] In one possible implementation, the device is also used for:

[0180] Based on the database change log and preset data backup conditions, determine whether a data backup needs to be performed for the transaction;

[0181] If it is determined that data backup is required, then through the compute nodes in the current cluster, based on the data change operations recorded in the database change log, the data backup operation is performed on the data objects affected by the data change operation to save the result data of the data objects after the transaction is executed.

[0182] In one possible implementation, the data backup rules include at least one of a preset data object whitelist, a transaction type whitelist, and a node whitelist; the device is also used for:

[0183] Parse the database change log to obtain the data object identifier affected by the data change operation, the transaction identifier contained in the database change log, and the node identifier;

[0184] When the data object identifier is in the data object whitelist, and / or the transaction identifier is in the transaction type whitelist, and / or the node identifier is in the node whitelist, it is determined that the transaction needs to perform data backup;

[0185] Otherwise, it is determined that no data backup needs to be performed for the transaction.

[0186] The database synchronization device for the distributed system provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0187] Figure 4 This is a schematic diagram of the database synchronization device for the distributed system provided in this application. Figure 4 As shown, the server 40 provided in this embodiment includes at least one processor 401 and a memory 402. Optionally, the server 40 further includes a communication component 403. The processor 401, memory 402, and communication component 403 are connected via a bus 404.

[0188] In a specific implementation, at least one processor 401 executes computer execution instructions stored in memory 402, causing at least one processor 401 to perform the above-described method.

[0189] The specific implementation process of processor 401 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0190] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0191] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0192] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0193] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0194] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0195] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0196] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0197] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0198] The units described as separate components may or may not be physically separate. 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 units can be selected to achieve the purpose of this embodiment according to actual needs.

[0199] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0200] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0201] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0202] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

Claims

1. A database synchronization method for a distributed system, characterized in that, The distributed system includes multiple clusters, each cluster including compute nodes, synchronization nodes, and at least one database node; the method includes: For any transaction executed by a database node in any cluster, obtain the database change log corresponding to the transaction; wherein, the database change log includes a source node identifier and a transaction identifier written by the database node; the source node identifier is used to indicate the database node that first executes the data change operation corresponding to the transaction; Based on the transaction identifier and the preset synchronization rules, determine whether the transaction needs to be synchronized. If it is determined that transaction synchronization needs to be performed, the data change operation corresponding to the transaction is synchronized to at least one target cluster based on the database change log; wherein, the target cluster is another cluster among the multiple clusters other than the current cluster.

2. The method according to claim 1, characterized in that, Before obtaining the database change log corresponding to the transaction, the method further includes: The compute nodes in the current cluster receive business requests, generate corresponding transactions, and distribute the transactions to the database nodes in the current cluster according to the database sharding strategy. The database node in the current cluster executes the transaction and writes the transaction identifier and the node identifier of the database node into the logical log that records the data change operation to obtain the database change log.

3. The method according to claim 2, characterized in that, The service request is a data operation request or data migration request from an external application, or a synchronization request from a synchronization node in the current cluster; the synchronization request is sent from a synchronization node in another cluster to a synchronization node in the current cluster.

4. The method according to claim 2, characterized in that, To obtain the database change log, the process involves writing a transaction identifier and the node identifier of the database node into the logical log that records the data change operations. The database node performs a metadata recording operation, which carries the transaction identifier and the node identifier of the database node. The metadata recording operation is a database operation that can be recorded to the logical log but does not generate persistent data storage. The execution process of the metadata recording operation is recorded in the logical log so that the transaction identifier and the node identifier are recorded in the logical log, thereby obtaining the database change log.

5. The method according to claim 4, characterized in that, The metadata recording operation is an insert statement for the target storage engine, which is a storage engine that does not generate actual data storage when performing a write operation.

6. The method according to claim 5, characterized in that, The target storage engine is the black hole storage engine.

7. The method according to claim 1, characterized in that, Based on the transaction identifier and preset synchronization rules, determine whether the transaction needs to be synchronized, including: The compute nodes in the current cluster determine the transaction type of the transaction based on the transaction identifier; When it is determined that the transaction is a migration transaction or a synchronization transaction, it is determined that transaction synchronization will not be performed; wherein, the migration transaction is a transaction executed to perform a data migration task, and the synchronization transaction is a transaction executed by the synchronization node from other clusters to the current cluster; When it is determined that the transaction is a data operation transaction, it is determined that transaction synchronization needs to be performed.

8. The method according to claim 1, characterized in that, Based on the database change log, the data change operations corresponding to the transaction are synchronized to at least one target cluster, including: The compute nodes in the current cluster generate a synchronization request based on the database change log and send the synchronization request to the synchronization node in the current cluster; The synchronization node in the current cluster sends the synchronization request to the target synchronization node in the target cluster. The target synchronization node forwards the synchronization request to the target computing node of the target cluster, so that the target computing node performs the data change operation on the target database node of the target cluster according to the synchronization request.

9. The method according to claim 8, characterized in that, The target computing node performs the data modification operation on the target database node of the target cluster according to the synchronization request, including: The target computing node creates a corresponding synchronization transaction based on the synchronization request; the synchronization transaction contains at least one data change operation to be executed. According to the database sharding strategy of the target cluster, the at least one data change operation is assigned to at least one target database node in the target cluster for execution; wherein, the at least one data change operation may be assigned to a target database node that does not correspond to the database node indicated by the source node identifier.

10. The method according to claim 1, characterized in that, After obtaining the database change log corresponding to the transaction, the method further includes: Based on the database change log and preset data backup conditions, determine whether the transaction needs to perform a data backup; If it is determined that data backup is required, then through the computing nodes in the current cluster, according to the data change operation recorded in the database change log, a data backup operation is performed on the data object affected by the data change operation, so as to save the result data of the data object after the transaction is executed.

11. The method according to claim 10, characterized in that, The data backup conditions include at least one of the following: a preset data object whitelist, a transaction type whitelist, and a node whitelist; Based on the database change log and preset data backup conditions, determine whether the transaction needs to perform a data backup, including: Parse the database change log to obtain the data object identifier affected by the data change operation, the transaction identifier contained in the database change log, and the node identifier; When the data object identifier is in the data object whitelist, and / or the transaction identifier is in the transaction type whitelist, and / or the node identifier is in the node whitelist, it is determined that the transaction needs to perform data backup; Otherwise, it is determined that the transaction does not require data backup.

12. A database synchronization device for a distributed system, characterized in that, include: The distributed system includes multiple clusters, each cluster including computing nodes, synchronization nodes, and at least one database node; the device includes: The log acquisition module is used to acquire the database change log corresponding to any transaction executed by a database node in any cluster; wherein, the database change log includes a source node identifier and a transaction identifier written by the database node; the source node identifier is used to indicate the database node that first executes the data change operation corresponding to the transaction; The judgment module is used to determine whether the transaction needs to be synchronized based on the transaction identifier and the preset synchronization rules. The synchronization module is used to synchronize the data change operation corresponding to the transaction to at least one target cluster based on the database change log if it is determined that transaction synchronization needs to be performed; wherein the target cluster is another cluster among the plurality of clusters other than the current cluster.

13. A server, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-11.

15. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-11.