Database bidirectional synchronization method, device, equipment and medium
By recording and encrypting data change operations between the old and new databases on a relay server, and using a streaming platform to achieve incremental data synchronization, the problems of data loss and duplicate execution during database switching are solved, ensuring system stability and data consistency.
Patent Information
- Application Number
- CN202311013481.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-11
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-08-11
AI Technical Summary
During database switching, if the new database fails, directly switching back to the old database may result in data loss or request loss, which is especially detrimental to critical trading systems. Existing technologies cannot effectively mitigate this risk.
A two-way database synchronization method is adopted. Data change operations between the old and new databases are recorded in the relay database table through a relay server, and an encryption verification algorithm is used to ensure data uniqueness. The streaming platform is used to realize incremental data synchronization between the old and new databases to prevent data duplication.
When the old and new databases are running in parallel, the incremental data is synchronized in a timely manner, reducing the risks during database switching, preventing data loss and duplicate execution, and improving system stability.
Smart Images

Figure CN117171263B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of big data technology, and more specifically to a method, apparatus, device, medium, and program product for bidirectional database synchronization. Background Technology
[0002] With the increasing number of enterprise system upgrades (e.g., localization or system replacement), more and more systems will need to migrate databases, frequently requiring database switching or expansion. A common practice in related technologies is to first shut down the system, then synchronize the existing data from the source database to the target database. Once the data synchronization is complete, the application system's server is switched to connect to the new database, and then the application system's server is restarted to provide services.
[0003] Meanwhile, during the period immediately following the switch to the new database (referred to as the transition period), because the stability and performance of the new database require a certain amount of time to observe, incremental data synchronization tasks are configured to synchronize data from the new database to the old database. This ensures that if the new database encounters problems, the data on both databases will be consistent when switching back to the old database. However, this method of directly switching back to the old database after a failure in the new database may lead to data loss or request loss, which is detrimental to the stability of the application system, especially for some critical transaction systems, posing a significant risk. Summary of the Invention
[0004] In view of the above problems, this disclosure provides a method, apparatus, device, medium and program product for bidirectional database synchronization that allows a new database to run in parallel with an old database in a gray-scale manner. This can largely ensure that when an application system is split between the old and new databases through a gray-scale pilot, the incremental data in the old and new databases can be synchronized with each other, thereby gradually diverting traffic to the new database and effectively reducing the risks during database switching.
[0005] According to a first aspect of this disclosure, a method for bidirectional database synchronization is provided. The method includes: in response to a first triggering event that modifies data in a first database, storing all DML statements related to the first triggering event in chronological order into a first transit database table; in response to a second triggering event that modifies data in a second database, storing all DML statements related to the second triggering event in chronological order into a second transit database table; calculating a first encrypted value for each DML statement in the first transit database table according to an encryption verification algorithm for verifying information uniqueness, and storing it in the first transit database table; calculating a second encrypted value for each DML statement in the second transit database table according to the encryption verification algorithm, and storing it in the second transit database table; reading DML statements from the first transit database table in chronological order, and executing the first DML statement in the second database when no second encrypted value identical to the first encrypted value of the read first DML statement exists in the second transit database table; and reading DML statements from the second transit database table in chronological order, and executing the second DML statement in the first database when no first encrypted value identical to the second encrypted value of the read second DML statement exists in the first transit database table.
[0006] According to an embodiment of this disclosure, the method further includes: discarding the first DML statement when a second encrypted value identical to the first encrypted value of the first DML statement exists in the second transit database table; and discarding the second DML statement when a first encrypted value identical to the second encrypted value of the second DML statement exists in the first transit database table.
[0007] According to embodiments of this disclosure, the method further includes establishing threads for a first producer, a second producer, a first consumer, and a second consumer via a streaming platform; wherein the first producer is configured to: read DML statements from a first transit database table in chronological order; the second consumer is configured to: acquire the DML statements read by the first producer, and when no second encrypted value identical to the first encrypted value of the first DML statement read by the first producer exists in the second transit database table, control the execution of the first DML statement in the second database; the second producer is configured to: read DML statements from the second transit database table in chronological order; and the first consumer is configured to: acquire the DML statements read by the second producer, and when no first encrypted value identical to the second encrypted value of the second DML statement read by the second producer exists in the first transit database table, execute the second DML statement in the first database.
[0008] According to embodiments of this disclosure, the streaming platform includes the Apache Pulsar streaming platform.
[0009] According to embodiments of this disclosure, storing all DML statements related to the first triggering event into a first transit database table in chronological order includes: retrieving all DML statements related to the first triggering event from the archived logs of the first database. Storing all DML statements related to the second triggering event into a second transit database table in chronological order includes: retrieving all DML statements related to the second triggering event from the archived logs of the second database. Both the first and second databases are configured to have archived logs enabled.
[0010] According to embodiments of this disclosure, the encryption verification algorithm includes the MD5 message digest algorithm.
[0011] According to embodiments of this disclosure, the method further includes: comparing the first encrypted value of the first DML statement with the second encrypted value in the second transit database table; and comparing the second encrypted value of the second DML statement with the first encrypted value in the first transit database table.
[0012] In another aspect of this disclosure, a database bidirectional synchronization device is provided. The device includes a first DML statement recording module, a first encryption module, a second DML statement recording module, a second encryption module, a first data synchronization module, and a second data synchronization module. The first DML statement recording module is configured to, in response to a first triggering event that modifies data in a first database, store all DML statements related to the first triggering event in chronological order into a first transit database table. The first encryption module is configured to, according to an encryption verification algorithm for verifying the uniqueness of information, calculate a first encrypted value for each DML statement in the first transit database table and store it in the first transit database table. The second DML statement recording module is configured to, in response to a second triggering event that modifies data in a second database, store all DML statements related to the second triggering event in chronological order into a second transit database table. The second encryption module is configured to, according to the encryption verification algorithm, calculate a second encrypted value for each DML statement in the second transit database table and store it in the second transit database table. The first data synchronization module is used to read DML statements from the first transit database table in chronological order, and execute the first DML statement in the second database when the second encrypted value, which is identical to the first encrypted value of the read first DML statement, does not exist in the second transit database table. The second data synchronization module is used to read DML statements from the second transit database table in chronological order, and execute the second DML statement in the first database when the first encrypted value, which is identical to the second encrypted value of the read second DML statement, does not exist in the first transit database table.
[0013] According to embodiments of this disclosure, the first data synchronization module is further configured to discard the first DML statement when a second encrypted value identical to the first encrypted value of the first DML statement exists in the second transit database table. The second data synchronization module is further configured to discard the second DML statement when a first encrypted value identical to the second encrypted value of the second DML statement exists in the first transit database table.
[0014] According to embodiments of this disclosure, the apparatus further includes a streaming platform construction module. The streaming platform construction module establishes threads for a first producer, a second producer, a first consumer, and a second consumer within the streaming platform.
[0015] The first data synchronization module includes a first producer submodule and a second consumer submodule.
[0016] The first producer submodule is deployed in the first producer and is used to read DML statements from the first transit database table in chronological order.
[0017] The second consumer submodule belongs to the second consumer and is used to obtain the DML statement read by the first producer, and when there is no second encrypted value in the second transit database table that is the same as the first encrypted value of the first DML statement read by the first producer, control the execution of the first DML statement in the second database.
[0018] The second data synchronization module includes a second producer submodule and a first consumer submodule.
[0019] The second producer submodule is deployed in the second producer and is used to read DML statements from the second transit database table in chronological order.
[0020] The first consumer submodule is deployed on the first consumer and is used to obtain the DML statement read by the second producer, and to execute the second DML statement in the first database when there is no first encrypted value in the first transit database table that is the same as the second encrypted value of the second DML statement read by the second producer.
[0021] A third aspect of this disclosure provides an electronic device. The electronic device includes one or more processors and a memory. The memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the methods described above.
[0022] A fourth aspect of this disclosure also provides a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, cause the processor to perform the methods described above.
[0023] A fifth aspect of this disclosure also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0024] The above one or more embodiments have the following advantages or beneficial effects: They enable bidirectional database synchronization during parallel operation of old and new databases in a gray-scale pilot scenario. Firstly, the DML statements that modify data in the respective databases due to transactions distributed by the application system to the first and second databases are executed again in the other database to achieve synchronization of the incremental databases. Secondly, by comparing encrypted values, duplicate execution of DML statements that modify data during the data synchronization process between the first and second databases is prevented, thus avoiding data loops. In this way, it is ensured that the DML statements executed during database synchronization are generated independently by the other database. Attached Figure Description
[0025] The foregoing contents, as well as other objects, features, and advantages of this disclosure, will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0026] Figure 1 The illustration schematically depicts the system architecture of a database bidirectional synchronization method, apparatus, device, medium, and program product according to embodiments of the present disclosure;
[0027] Figure 2 A flowchart illustrating a database bidirectional synchronization method according to an embodiment of the present disclosure is shown schematically.
[0028] Figure 3 A flowchart illustrating a database bidirectional synchronization method according to another embodiment of the present disclosure is shown schematically;
[0029] Figure 4 The diagram illustrates an interactive flowchart of bidirectional database synchronization via a streaming platform in one embodiment of this disclosure.
[0030] Figure 5 Schematic illustration Figure 4 The flowchart shown illustrates the method for achieving database synchronization in a streaming platform where the first consumer consumes data from the second producer.
[0031] Figure 6 A block diagram of a database bidirectional synchronization apparatus according to an embodiment of the present disclosure is schematically shown; and
[0032] Figure 7 A block diagram schematically illustrates an electronic device suitable for implementing a bidirectional database synchronization method according to embodiments of the present disclosure. Detailed Implementation
[0033] The embodiments of the present disclosure will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the disclosure. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of the present disclosure for ease of explanation. However, it will be apparent that one or more embodiments may be practiced without these specific details. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concepts of the present disclosure.
[0034] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this disclosure. The terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0035] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0036] When using expressions such as "at least one of A, B, and C," the expression should generally be interpreted in accordance with the meaning commonly understood by a person skilled in the art (e.g., "a system having at least one of A, B, and C" should include, but is not limited to, having A alone, having B alone, having C alone, having A and B, having A and C, having B...).
[0037] To overcome the risks associated with switching back to the old database during the transition period when the new database encounters problems, a canary deployment approach can be used, allowing the new and old databases to run in parallel. The application system can then distribute database access between the two databases. This process requires bidirectional synchronization of incremental data between the two databases. Therefore, this disclosure provides a method, apparatus, device, medium, and program product for bidirectional database synchronization that can operate in such a canary deployment scenario. This method can largely guarantee timely synchronization of incremental data between the two databases without data loss.
[0038] Figure 1 The system architecture 100 of a database bidirectional synchronization method, apparatus, device, medium, and program product according to embodiments of the present disclosure is illustrated schematically. Figure 1 The examples shown are merely examples of system architectures that can be applied to embodiments of the present invention, in order to help those skilled in the art understand the technical content of the present invention, but do not mean that the present invention cannot be used in other devices, systems, environments or scenarios.
[0039] Combination Figure 1 The system architecture 100 includes a first database 101 and a second database 102 (the distinction between the old and new databases is not explicitly made below) that run in parallel and interact with the application server 105 respectively.
[0040] Application server 105 is a server that provides backend support for application systems. Through a pilot canary deployment strategy, application server 105 distributes requests according to certain rules. For example, requests for non-pilot transactions can be routed to the first database 101, while requests for pilot transactions can be routed to the second database 102.
[0041] The first database 101 and the second database 102 do not interact directly; instead, a relay server 103 connects to both databases 101 and 102 respectively. Simultaneously, the relay server 103 is connected to the relay database 104.
[0042] The bidirectional database synchronization method of this embodiment can be executed by a relay server 103. Specifically, the relay server 103, through a communication connection with the first database 101 and the second database 102, writes DML statements that modify data in the first database 101 and the second database 102 into a first relay database table and a second relay database table in a relay database 104, respectively. Then, based on the DML statements recorded in the first and second relay database tables, the relay server 103 can control the execution of DML statements that have only been executed in the first database 101 in the second database 102, and control the execution of DML statements that have only been executed in the second database 102 in the first database 101. In this way, data synchronization between the first database 101 and the second database 102 is achieved.
[0043] The database bidirectional synchronization device, equipment, medium, and program products of this disclosure can be correspondingly set in the relay server 103.
[0044] It should be noted that the database bidirectional synchronization method, apparatus, device, medium and program products of the present disclosure can be used in the financial field, or in any field other than the financial field. The present disclosure does not limit the application field.
[0045] The following will be based on Figure 1 The described system architecture 100, through Figures 2-5 The database bidirectional synchronization method according to embodiments of this disclosure will be described in detail. It should be noted that the sequence numbers of each operation in the following method are for descriptive purposes only and should not be considered as indicating the execution order of the operations. Unless explicitly stated otherwise, the method does not need to be executed in the exact order shown.
[0046] Figure 2 A flowchart illustrating a bidirectional database synchronization method according to an embodiment of the present disclosure is shown.
[0047] like Figure 2 As shown, the database bidirectional synchronization method includes operations S210 to S260.
[0048] In operation S210, in response to a first triggering event that modifies data in the first database 101, all DML statements related to the first triggering event are stored in the first transit database table in chronological order.
[0049] In operation S220, in response to a second triggering event that modifies data in the second database 102, all DML statements related to the second triggering event are stored in the second transit database table in chronological order.
[0050] The first triggering event and the second triggering event can be due to a transaction issued by the application server 105 to the first database 101 and the second database 102, or they can be synchronization events that trigger incremental data synchronization between the first database 101 and the second database 102 in this embodiment of the present disclosure.
[0051] In one embodiment, the first database 101 and the second database 102 can each enable archive log mode. This allows all DML statements related to the first triggering event to be retrieved from the archive logs of the first database 101, and all DML statements related to the second triggering event to be retrieved from the archive logs of the second database 102. The storage of all DML statements related to the triggering event in the corresponding transit database tables in chronological order can be achieved by adding a timestamp when storing the DML statements.
[0052] For example, relay server 103 can parse the archived logs of the first database 101 and the second database 102, such as Oracle's archived log and MySQL's binlog. When a triggering event (such as a transaction) modifies a database, all DML statements involved in the transaction can be retrieved from the archived logs of that database and stored in the corresponding relay database tables of relay database 104, with the DML statements of the first database 101 stored in the first relay database table and the DML statements of the second database 102 stored in the second relay database table.
[0053] Storing all DML statements related to the triggering event in chronological order ensures complete storage of all DML statements without omissions. Furthermore, if there are dependencies between the data operated on by all the DML statements related to the triggering event, storing them in chronological order guarantees the correctness of these dependencies and ensures the correctness of the results of these DML statements when executed in another database in chronological order.
[0054] Of course, besides retrieving DML statements from archived logs as described above, other commonly used techniques in this field can also be used. For example, one can monitor events that trigger data changes in the database (e.g., database transactions that lock database tables) and then retrieve DML statements from those transactions. However, compared to monitoring database transactions, retrieving DML statements from archived logs has lower real-time requirements and less impact on the database's operation.
[0055] In operation S230, according to the encryption verification algorithm used to verify the uniqueness of information, the first encrypted value of each DML statement in the first transit database table is calculated and stored in the first transit database table.
[0056] In operation S240, the second encrypted value of each DML statement in the second transit database table is calculated according to the above-mentioned encryption verification algorithm and stored in the second transit database table.
[0057] In one embodiment, the encryption verification algorithm can be, for example, the MD5 message digest algorithm. For instance, relay server 103 can perform HMAC MD5 digest calculation on each DML statement (using Java's MessageDigest class), obtaining a calculated value in the form of 771093e83aeb659d125100fa465bd34e. Here, HMAC MD5 is an algorithm combining key-related hash message authentication code (HMAC) and message digest algorithm (MD5), using the MD5 hash function to calculate the message verification code HMAC based on the hash value.
[0058] Of course, the encryption verification algorithm in this embodiment is not limited to MD5, but can be other encryption algorithms, such as various hash algorithms similar to MD5, such as SHA-1, SHA-256, or the encryption verification algorithm can be a combination of multiple encryption algorithms.
[0059] In operation S250, DML statements are read from the first transit database table in chronological order, and when a second encrypted value that is the same as the first encrypted value of the first DML statement read does not exist in the second transit database table, the first DML statement is executed in the second database 102.
[0060] In operation S260, DML statements are read from the second transit database table in chronological order, and when a first encrypted value that is the same as the second encrypted value of the read second DML statement does not exist in the first transit database table, the second DML statement is executed in the first database 101.
[0061] Accordingly, in one embodiment, if a second encrypted value identical to the first encrypted value of the first DML statement exists in the second transit database table, the first DML statement can be discarded. Simultaneously, if a first encrypted value identical to the second encrypted value of the second DML statement exists in the first transit database table, the second DML statement is discarded.
[0062] In this embodiment of the disclosure, by comparing encrypted values to determine whether to execute DML, it can be ensured that the DML statements from the other database executed in the first database 101 and the second database 102 are generated independently in the other database, and not generated after the DML statements generated in the own database are executed in the other database. This method can prevent data synchronization loops.
[0063] As can be seen, in this embodiment of the disclosure, during bidirectional data synchronization, on the one hand, the DML statements that cause data changes in the respective databases due to transactions distributed by the application server 105 to the first database 101 and the second database 102 can be executed again in the other database to achieve synchronization of the incremental databases of both parties. On the other hand, this process can prevent the DML statements that cause data changes during the data synchronization process between the first database 101 and the second database 102 from being executed again, thus preventing a data synchronization loop.
[0064] Figure 3 A flowchart illustrating a database bidirectional synchronization method according to another embodiment of the present disclosure is shown.
[0065] like Figure 3 As shown, according to this embodiment, the above-mentioned operation S250 may include operations S251 to S253, and the above-mentioned operation S260 may include operations S261 to S263.
[0066] Specifically, operation S250 can be divided into three steps: operation S251 reading DML statements from the intermediate database table, operation S252 performing uniqueness verification of DML statements, and operation S253 processing the read DML statements based on the verification results.
[0067] Specifically, in operation S251, DML statements and the first encrypted value of each DML statement are read from the first transit database table in chronological order.
[0068] Next, in operation S252, the first encrypted value of any first DML statement read from the first transit database table is compared with the second encrypted value in the second transit database table.
[0069] Then, in operation S253, when there is no second encrypted value in the second transit database table that is the same as the first encrypted value of the first DML statement read, the first DML statement is executed in the second database 102.
[0070] For example, a search is performed in the second transit database table for a second encrypted value that is identical to the first encrypted value of the first DML statement. If no match is found, it means that the second transit database table does not contain a DML statement identical to the first DML statement, and thus the DML statement is executed in the second database to achieve incremental data synchronization. If a match is found, it means that the second transit database contains a DML statement identical to the first DML statement, which means that the first DML statement has already been executed in the second database 102 and does not need to be executed again. In this way, DML statements generated separately in the first database 101 can be synchronously executed in the second database 102, avoiding the possibility of duplicate DML statement execution.
[0071] Accordingly, operation S260 can also be divided into three steps: operation S261 reading DML statements from the intermediate database table, operation S262 performing uniqueness verification of DML statements, and operation S263 processing the read DML statements based on the verification results.
[0072] Specifically, in operation S261, DML statements and a second encrypted value for each DML statement are read from the second transit database table in chronological order.
[0073] Next, in operation S262, the second encrypted value of any second DML statement read from the second transit database table is compared with the first encrypted value in the first transit database table. Similarly, it can also be determined by searching the first transit database table to see if the same DML statement exists there.
[0074] Then, in operation S263, when there is no first encrypted value in the first transit database table that is the same as the second encrypted value of the read second DML statement, the second DML statement is executed in the first database 101.
[0075] In this way, DML statements generated separately in the first database 102 can be executed synchronously in the second database 102, avoiding the possibility of repeatedly executing DML statements.
[0076] In this embodiment of the present disclosure, encrypted values can be read simultaneously from the relay database table while reading DML statements, avoiding the need to recalculate the encrypted values of the read DML statements before comparing them. This can save the computing resources of the relay server 103 and improve the timeliness of comparing encrypted values.
[0077] As can be seen from the above description, the bidirectional data synchronization scheme of this disclosure embodiment can be divided into two stages: a data production stage and a data consumption stage. Operations S210 to S240 belong to the data production stage, while operations S250 and S260 belong to the data consumption stage. For this purpose, a streaming platform can be used to implement the bidirectional data synchronization of this disclosure embodiment. By leveraging the asynchronous processing and data retention functions of the streaming platform, data loss during the bidirectional data synchronization process can be minimized.
[0078] Figure 4 The diagram illustrates an interactive flowchart of bidirectional database synchronization via a streaming platform in one embodiment of this disclosure.
[0079] Combination Figure 1 and Figure 4 A distributed streaming platform, such as the Apache Pulsar streaming platform or the Kafka streaming platform, can be installed on the relay server 103. The streaming platform is responsible for message processing of the incremental data in the first database 101 and the second database 102 respectively.
[0080] This section uses the Apache Pulsar streaming platform (hereinafter referred to as Pulsar) as an example for explanation.
[0081] like Figure 4 As shown, Pulsar can be deployed in relay server 103.
[0082] First, Pulsar establishes threads for a first producer and a second producer. The first producer can read DML statements from the first intermediary database table, thus the DML statements recorded in the first database 101 in operation S210 can be synchronously placed into the first producer in chronological order. The second producer can read DML statements from the second intermediary database table, thus the DML statements recorded in the second database 102 in operation S220 can be synchronously placed into the second producer in chronological order. Because the data in the intermediary database table is synchronously placed into the producer thread, the possibility of data loss can be reduced, and data security during the data synchronization process can be improved.
[0083] Simultaneously, Pulsar creates threads for the first consumer and the second consumer, respectively. The first consumer thread processes the data from the second producer thread, and the second consumer thread processes the data from the first producer thread.
[0084] Specifically, the first consumer reads the DML statements from the second producer in chronological order, and then compares the second encrypted value of the read DML statement with the first encrypted value in the first transit database table. When there is no first encrypted value in the first transit database table that is the same as the encrypted value of any read second DML statement, the second DML statement is executed in the first database 101.
[0085] The second consumer reads DML statements from the first producer, compares the first encrypted value of the read DML statement with all the second encrypted values in the second transit database table, and controls the execution of the first DML statement in the second database 102 when there is no second encrypted value in the second transit database table that is the same as the first encrypted value of any first DML statement read by the first producer.
[0086] Figure 5 Schematic illustration Figure 4 The flowchart shown illustrates the method for database synchronization in a streaming platform where the first consumer consumes data from the second producer. Figure 5 Therefore Figure 4 The following is an illustrative example of how the first consumer consumes DML statements from the second producer to synchronize incremental data in the second database 102 to the first database 101.
[0087] like Figure 5 As shown, the process by which the first consumer consumes data from the second producer may include operations S1 to S5.
[0088] First, in operation S1, the first consumer retrieves messages sequentially from the second producer, that is, reads the DML statements that cause data changes in database 102.
[0089] Next, S2 is used to process the DML statement read by S1, such as calculating its MD5 value.
[0090] Next, in operation S3, the MD5 value generated by operation S2 above is used to search the first transit database table.
[0091] If this MD5 value is found in the first transit database table, the DML statement is discarded directly in operation S4.
[0092] If the MD5 value does not exist in the first transit database table, then operation S5 controls the execution of this DML statement in the first database 101.
[0093] The DML statement is processed according to the judgment result in operation S3. This is to ensure that the DML statement is generated independently by the second database 102 and is not synchronized from the first database 101 to the second database 102, thus preventing data synchronization loops.
[0094] Correspondingly, the second consumer can also consume DML statements from the first producer in a manner similar to operations S1 to S5, so as to synchronize incremental data in the first database 101 to the second database 102.
[0095] Understandable. Figure 5 The illustration showing the first consumer calculating the MD5 value of the read DML statement in operation S2 is merely an example. In other embodiments, when the first and second producers read DML from the corresponding intermediary database tables, they can simultaneously read the encrypted value of each DML statement. In this case, when the first and second consumers consume data, they can directly obtain the encrypted value corresponding to the DML statement to be consumed from the corresponding producer.
[0096] Deploying a streaming platform in relay server 103 to achieve data synchronization between the first database 101 and the second database 102 can improve data security and largely avoid the loss of unexecuted DML statements due to anomalies during data synchronization. Furthermore, the streaming platform can decouple data synchronization from the data service functions of the first database 101 and the second database 102, reducing the impact on these functions.
[0097] Using a streaming platform to achieve bidirectional data synchronization between the first database 101 and the second database 102 leverages the platform's portability and high reusability, making the bidirectional database synchronization scheme of this embodiment a general solution that can be quickly deployed. Specifically, by connecting the producer thread to the corresponding intermediate database table and the consumer thread to the corresponding database, and through appropriate configuration, bidirectional synchronization between the two databases can be easily and quickly achieved, greatly reducing the cost and risk of gray-scale and pilot testing.
[0098] Based on the database bidirectional synchronization methods of the above embodiments, this disclosure also provides a database bidirectional synchronization apparatus. The following will be combined with... Figure 6 The device is described in detail.
[0099] Figure 6 A block diagram of a database bidirectional synchronization device 600 according to an embodiment of the present disclosure is shown schematically.
[0100] like Figure 6As shown, according to some embodiments of this disclosure, the device 600 may include a first DML statement recording module 610, a first encryption module 620, a first data synchronization module 630, a second DML statement recording module 640, a second encryption module 650, and a second data synchronization module 660. According to embodiments of this disclosure, the device 600 also includes a streaming platform building module 670. The device 600 may be located in the relay server 103 for executing reference... Figures 2-5 The method described.
[0101] The first DML statement recording module 610 is used to store all DML statements related to the first triggering event into the first transit database table in chronological order in response to a first triggering event that modifies the data in the first database 101.
[0102] The first encryption module 620 is used to calculate the first encryption value of each DML statement in the first transit database table according to the encryption verification algorithm used to verify the uniqueness of information, and store it in the first transit database table.
[0103] The second DML statement recording module 640 is used to store all DML statements related to the second triggering event in chronological order into the second transit database table in response to a second triggering event that modifies data in the second database 102.
[0104] The second encryption module 650 is used to calculate the second encryption value of each DML statement in the second transit database table according to the encryption verification algorithm, and store it in the second transit database table.
[0105] The first data synchronization module 630 is used to read DML statements from a first transit database table in chronological order, and execute the first DML statement in the second database 102 when a second encrypted value identical to the first encrypted value of the read first DML statement does not exist in the second transit database table. According to an embodiment of this disclosure, the first data synchronization module 630 is further used to discard the first DML statement when a second encrypted value identical to the first encrypted value of the first DML statement exists in the second transit database table.
[0106] The second data synchronization module 660 is used to read DML statements from the second transit database table in chronological order, and execute the second DML statement in the first database 101 when a first encrypted value identical to the second encrypted value of the read second DML statement does not exist in the first transit database table. According to an embodiment of this disclosure, the second data synchronization module 660 is further used to discard the second DML statement when a first encrypted value identical to the second encrypted value of the second DML statement exists in the first transit database table.
[0107] The streaming platform setup module 670 is used to deploy a streaming platform and establish threads for a first producer, a second producer, a first consumer, and a second consumer within the streaming platform. According to embodiments of this disclosure, the first data synchronization module 630 may include a first producer submodule 631 and a second consumer submodule 632. The second data synchronization module 660 includes a second producer submodule 661 and a first consumer submodule 662.
[0108] The first producer submodule 631 is deployed in the first producer thread and is used to read DML statements from the first intermediate database table in chronological order.
[0109] The second consumer submodule 632 belongs to the second consumer thread and is used to obtain the DML statement read by the first producer, and when there is no second encrypted value in the second transit database table that is the same as the first encrypted value of the first DML statement read by the first producer, control the execution of the first DML statement in the second database 102.
[0110] The second producer submodule 661 is deployed in the second producer thread and is used to read DML statements from the second intermediate database table in chronological order.
[0111] The first consumer submodule 662 is deployed on the first consumer thread and is used to obtain the DML statement read by the second producer, and to execute the second DML statement in the first database 101 when there is no first encrypted value in the first transit database table that is the same as the second encrypted value of the second DML statement read by the second producer.
[0112] According to embodiments of this disclosure, any multiple modules among the first DML statement recording module 610, the first encryption module 620, the first data synchronization module 630, the second DML statement recording module 640, the second encryption module 650, the second data synchronization module 660, and the streaming platform construction module 670 can be combined into one module, or any one of these modules can be split into multiple modules. Alternatively, at least some of the functions of one or more of these modules can be combined with at least some of the functions of other modules and implemented in one module. According to embodiments of this disclosure, at least one of the first DML statement recording module 610, the first encryption module 620, the first data synchronization module 630, the second DML statement recording module 640, the second encryption module 650, the second data synchronization module 660, and the streaming platform construction module 670 can be at least partially implemented as hardware circuits, such as field-programmable gate arrays (FPGAs), programmable logic arrays (PLAs), systems-on-a-chip, systems-on-a-substrate, systems-on-package, application-specific integrated circuits (ASICs), or any other reasonable means of integrating or packaging circuits, or implemented in hardware or firmware, or in any one of software, hardware, and firmware implementations, or in a suitable combination of any of these. Alternatively, at least one of the first DML statement recording module 610, the first encryption module 620, the first data synchronization module 630, the second DML statement recording module 640, the second encryption module 650, the second data synchronization module 660, and the streaming platform construction module 670 can be at least partially implemented as computer program modules, which can perform corresponding functions when the computer program module is run.
[0113] Figure 7 A block diagram schematically illustrates an electronic device suitable for implementing a bidirectional database synchronization method according to embodiments of the present disclosure.
[0114] like Figure 7 As shown, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage portion 708 into a random access memory (RAM) 703. The processor 701 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 701 may also include onboard memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0115] RAM 703 stores various programs and data required for the operation of electronic device 700. Processor 701, ROM 702, and RAM 703 are interconnected via bus 704. Processor 701 performs various operations of the method flow according to embodiments of the present disclosure by executing programs in ROM 702 and / or RAM 703. It should be noted that the programs may also be stored in one or more memories other than ROM 702 and RAM 703. Processor 701 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in said one or more memories.
[0116] According to embodiments of this disclosure, the electronic device 700 may further include an input / output (I / O) interface 705, which is also connected to a bus 704. The electronic device 700 may also include one or more of the following components connected to the I / O interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 708 as needed.
[0117] This disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of this disclosure.
[0118] According to embodiments of this disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, such as, but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this disclosure, the computer-readable storage medium may include ROM 702 and / or RAM 703 and / or one or more memories other than ROM 702 and RAM 703 described above.
[0119] Embodiments of this disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code enables the computer system to implement the bidirectional database synchronization method provided in the embodiments of this disclosure.
[0120] When the computer program is executed by the processor 701, it performs the functions defined in the system / apparatus of this disclosure embodiments. According to embodiments of this disclosure, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0121] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 709, and / or installed from a removable medium 711. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0122] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 709, and / or installed from the removable medium 711. When the computer program is executed by the processor 701, it performs the functions defined in the system of this disclosure embodiment. According to embodiments of this disclosure, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0123] According to embodiments of this disclosure, program code for executing the computer programs provided in embodiments of this disclosure can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can execute entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0124] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0125] Those skilled in the art will understand that the features described in the various embodiments and / or claims of this disclosure can be combined or combined in various ways, even if such combinations or combinations are not explicitly described in this disclosure. In particular, the features described in the various embodiments and / or claims of this disclosure can be combined or combined in various ways without departing from the spirit and teachings of this disclosure. All such combinations and / or combinations fall within the scope of this disclosure.
[0126] The embodiments of this disclosure have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of this disclosure. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. The scope of this disclosure is defined by the appended claims and their equivalents. Various substitutions and modifications can be made by those skilled in the art without departing from the scope of this disclosure, and all such substitutions and modifications should fall within the scope of this disclosure.
Claims
1. A method for bidirectional database synchronization, comprising: Establish threads for the first producer, the second producer, the first consumer, and the second consumer through the streaming platform; In response to a first triggering event that modifies data in the first database, all DML statements related to the first triggering event are stored in the first transit database table in chronological order. In response to a second triggering event that modifies data in the second database, all DML statements related to the second triggering event are stored in the second transit database table in chronological order; According to the encryption verification algorithm used to verify the uniqueness of information, calculate the first encrypted value of each DML statement in the first transit database table and store it in the first transit database table; The second encrypted value of each DML statement in the second transit database table is calculated according to the encryption verification algorithm and stored in the second transit database table; The first producer reads DML statements from the first intermediary database table in chronological order; The second consumer reads the DML statements from the first producer in chronological order, then compares the first encrypted value of the read DML statement with the second encrypted value in the second relay database table, and executes the first DML statement in the second database when there is no second encrypted value in the second relay database table that is the same as the first encrypted value of the read first DML statement. as well as The second producer reads DML statements from the second intermediary database table in chronological order; The first consumer reads DML statements from the second producer in chronological order, compares the second encrypted value of the read DML statement with the first encrypted value in the first transit database table, and executes the second DML statement in the first database when there is no first encrypted value in the first transit database table that is the same as the second encrypted value of the read second DML statement.
2. The method according to claim 1, wherein, The method further includes: If a second encrypted value exists in the second transit database table that is identical to the first encrypted value of the first DML statement, then discard the first DML statement; and If the first encrypted value, which is the same as the second encrypted value of the second DML statement, exists in the first transit database table, the second DML statement is discarded.
3. The method according to claim 1, wherein, The streaming platform includes the Apache Pulsar streaming platform.
4. The method according to claim 1, wherein, The step of storing all DML statements related to the first triggering event into the first transit database table in chronological order includes: obtaining all DML statements related to the first triggering event from the archived logs of the first database; The step of storing all DML statements related to the second triggering event into the second transit database table in chronological order includes: obtaining all DML statements related to the second triggering event from the archived logs of the second database; The first database and the second database are respectively configured to enable archive log mode.
5. The method according to claim 1, wherein, The encryption verification algorithm includes the MD5 message digest algorithm.
6. The method according to claim 1, wherein, The method further includes: By searching the second relay database table for the first encrypted value of the first DML statement, the first encrypted value of the first DML statement is compared with the second encrypted value in the second relay database table; and The second encrypted value of the second DML statement is compared with the first encrypted value in the first transit database table by searching for the second encrypted value of the second DML statement in the first transit database table.
7. A database bidirectional synchronization device, comprising: The streaming platform setup module is used to create threads for the first producer, the second producer, the first consumer, and the second consumer within the streaming platform. The first DML statement recording module is used to store all DML statements related to the first triggering event in chronological order into the first transit database table in response to a first triggering event that modifies data in the first database. The first encryption module is used to calculate the first encryption value of each DML statement in the first transit database table according to the encryption verification algorithm used to verify the uniqueness of information, and store it in the first transit database table. The second DML statement recording module is used to store all DML statements related to the second triggering event in chronological order into the second transit database table in response to a second triggering event that modifies data in the second database. The second encryption module is used to calculate the second encryption value of each DML statement in the second transit database table according to the encryption verification algorithm, and store it in the second transit database table. The first data synchronization module is configured to: read DML statements from the first transit database table in chronological order through the first producer; and read the DML statements from the first producer in chronological order through the second consumer, then compare the first encrypted value of the read DML statement with the second encrypted value in the second transit database table, and execute the first DML statement in the second database when there is no second encrypted value in the second transit database table that is the same as the first encrypted value of the read first DML statement; The second data synchronization module is configured to: read DML statements from the second transit database table in chronological order through the second producer; and read the DML statements from the second producer in chronological order through the first consumer, compare the second encrypted value of the read DML statement with the first encrypted value in the first transit database table, and execute the second DML statement in the first database when there is no first encrypted value in the first transit database table that is the same as the second encrypted value of the read second DML statement.
8. An electronic device, comprising: One or more processors; Memory, used to store one or more programs. Wherein, when the one or more programs are executed by the one or more processors, the one or more processors perform the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the method according to any one of claims 1 to 6.
10. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Heterogeneous database synchronization method and system
CN101615199A
Database increment synchronization method and system, electronic equipment and medium
CN115982284A
