Data synchronization method, device, electronic device and storage medium

By obtaining the time delay value and global transaction identification value of the standby database in the financial system, the transaction impact and data loss problems caused by the failure of the primary database are solved, and data consistency and real-time processing stability are achieved.

CN114064795BActive Publication Date: 2025-09-23NETSUNION CLEARING CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010749698.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-30
Publication Date
2025-09-23
Estimated Expiration
2040-07-30

AI Technical Summary

Technical Problem

In financial systems, when the main database fails, it is easy to cause transaction impact, data loss or data synchronization failure.

Method used

When the primary database fails, a query delay command is sent to obtain the time delay value of the standby database, and the global transaction identifier value is obtained after the delay value reaches zero. The global transaction identifier value of the standby database is used for data synchronization to ensure data consistency.

Benefits of technology

When the primary database fails, data consistency is ensured, data loss or synchronization failure is avoided, and real-time data processing is not affected.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114064795B_ABST
    Figure CN114064795B_ABST
Patent Text Reader

Abstract

The present application proposes a data synchronization method, apparatus, electronic device, and storage medium, wherein the method includes: when a primary database fails, sending a query delay command to obtain a first time delay value of a first standby database relative to the primary database, and a second time delay value of a second standby database relative to the primary database; when both the first time delay value and the second time delay value are zero, sending a global transaction identifier acquisition instruction; obtaining a first global transaction identifier value corresponding to the primary database in the first standby database, and obtaining a second global transaction identifier value corresponding to the primary database in the second standby database; and performing data synchronization processing based on the first global transaction identifier value and the second global transaction identifier value. This solves the technical problem of transactions being affected, data loss, or data synchronization failures when a primary database fails, ensuring data consistency and ensuring that real-time data processing is not affected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a data synchronization method, device, electronic device and storage medium. Background Art

[0002] In the financial sector, distributed database architectures are often implemented using MySQL (an open-source relational database management system). When deploying data centers, each data center can be designed with separate databases. For example, a database consisting of four servers could be deployed, including two local servers, a backup server in the same city, and a backup server in a different city, to handle transaction transactions.

[0003] Specifically, each data center consists of multiple databases, each of which further includes a local master database, a local standby database, a local standby database, and a remote standby database. Figure 1 In the database shown, when the primary database fails, data processing can be switched to the local standby database. If the synchronized data in the local standby database is inconsistent with the data in the primary database, data loss or data synchronization failure may occur. Summary of the Invention

[0004] The present application aims to solve one of the technical problems in the related art at least to a certain extent.

[0005] To this end, the present application proposes a data synchronization method that solves the technical problems in the prior art of transactions being affected and data being lost or synchronization failing when the primary database fails. By comparing the global transaction identifier values ​​of the first standby database and the second standby database, the differentially processed data is compensated and stored to ensure data consistency and ensure that real-time data processing is not affected.

[0006] The present application proposes a data synchronization device.

[0007] The present application provides an electronic device.

[0008] The present application provides a computer-readable storage medium.

[0009] In one aspect, an embodiment of the present application provides a data synchronization method, which is applied to a synchronization arbitration device. The synchronization arbitration device is used to arbitrate data synchronization processes among a primary database, a first standby database, and a second standby database. The method includes:

[0010] When the primary database fails, sending a query delay command to obtain a first time delay value of the first standby database relative to the primary database and a second time delay value of the second standby database relative to the primary database;

[0011] When both the first time delay value and the second time delay value are zero, sending a global transaction identifier acquisition instruction;

[0012] Obtaining a first global transaction identifier value corresponding to the primary database in the first standby database, and obtaining a second global transaction identifier value corresponding to the primary database in the second standby database;

[0013] Data synchronization is performed according to the first global transaction identifier value and the second global transaction identifier value.

[0014] In one embodiment of the present application, the primary database and the second standby database are connected using a virtual address connection. The data synchronization processing based on the first global transaction identifier value and the second global transaction identifier value includes: if the first global transaction identifier value is less than the second global transaction identifier value, obtaining a difference between the first global transaction identifier value and the second global transaction identifier value; obtaining processed data corresponding to the difference, storing the processed data in the first standby database, switching to the first standby database for data synchronization, and switching the second standby database to the first standby database via the virtual address connection.

[0015] In one embodiment of the present application, the data synchronization method further includes: if the first global transaction identifier value is greater than or equal to the second global transaction identifier value, switching to the first standby database for data processing, and switching the second standby database to the first standby database through a virtual address connection.

[0016] In one embodiment of the present application, the primary database adopts a semi-synchronous configuration with the first standby database and the second standby database, respectively, further comprising: when the primary database is normal and the first standby database fails, if the primary database receives a confirmation message sent by the second standby database, continuing data processing and semi-synchronizing the data of the primary database to the second standby database.

[0017] In one embodiment of the present application, the primary database adopts a semi-synchronous configuration with the first standby database and the second standby database, respectively, further comprising: when the primary database is normal and the second standby database fails, if the primary database receives a confirmation message sent by the first standby database, continuing data processing and semi-synchronizing the data of the primary database to the first standby database.

[0018] In one embodiment of the present application, the data synchronization method further includes at least one of the following: when the first time delay value is not zero, controlling the first standby database to perform time synchronization with the primary database; when the second time delay value is not zero, controlling the second standby database to perform time synchronization with the primary database.

[0019] In one embodiment of the present application, the data synchronization method is characterized in that it also includes: sending a parameter setting instruction to control the target parameter of the master database to be set to a preset value, so that the master database continues data processing after receiving a confirmation message of the preset value.

[0020] Another embodiment of the present application provides a data synchronization device, including:

[0021] a first acquisition module, configured to, when the primary database fails, send a query delay command to respectively acquire a first time delay value of the first standby database relative to the primary database and a second time delay value of the second standby database relative to the primary database;

[0022] A sending module, configured to send a global transaction identifier acquisition instruction when both the first time delay value and the second time delay value are zero;

[0023] A second acquisition module is configured to acquire a first global transaction identifier value corresponding to the primary database in the first standby database, and acquire a second global transaction identifier value corresponding to the primary database in the second standby database;

[0024] The processing module is configured to perform data synchronization processing according to the first global transaction identifier value and the second global transaction identifier value.

[0025] In another aspect of the present application, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the data synchronization method as described in the aforementioned aspect of the embodiment is implemented.

[0026] In another aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the data synchronization method described in the aforementioned method embodiment is implemented.

[0027] In another aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor, the server is enabled to execute the data synchronization method described in the aforementioned method embodiment.

[0028] The technical solutions provided by the embodiments of the present application may have the following beneficial effects:

[0029] When the primary database fails, a query delay command is sent to obtain the first time delay value of the first standby database relative to the primary database, and the second time delay value of the second standby database relative to the primary database. If both the first and second time delay values ​​are zero, a global transaction identifier acquisition instruction is sent to obtain the first global transaction identifier value corresponding to the primary database in the first standby database, and the second global transaction identifier value corresponding to the primary database in the second standby database. Data synchronization is then performed based on the first and second global transaction identifier values. This solves the technical problem of transactions being affected, data being lost, or data synchronization failing when the primary database fails. By comparing the global transaction identifier values ​​of the first and second standby databases, discrepancies are stored and compensated, ensuring data consistency and unaffected real-time data processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0031] Figure 1 An example diagram of a database connection provided in an embodiment of the present application;

[0032] Figure 2 A flowchart of a data synchronization method provided in an embodiment of the present application;

[0033] Figure 3 An example diagram of a database connection provided in an embodiment of the present application;

[0034] Figure 4 An example diagram of a database connection provided in an embodiment of the present application;

[0035] Figure 5 An example diagram of a database connection provided in an embodiment of the present application;

[0036] Figure 6 A structural diagram of another data synchronization device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0037] The following describes in detail embodiments of the present application, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0038] The following describes the data synchronization method, device, electronic device, and storage medium according to the embodiments of the present application with reference to the accompanying drawings.

[0039] Specifically, if Figure 1 As shown, it includes: a local database master database, a local database standby database, a local database standby database, and a remote database standby database. The local database master database and the local database standby database are semi-synchronous configurations, the local database standby database and the local database standby database are asynchronous configurations, and the local database standby database and the remote database standby database are asynchronous configurations. Asynchronous configuration is a replication mode relative to semi-synchronous configuration or full-synchronous configuration. For example, the processed data sent by the local database standby database does not need to wait for any feedback from the local database standby database and is submitted directly, so the replicated data security is lower.

[0040] Therefore, when the local database master fails, data processing is switched to the local standby database. If the data in the local database standby database is inconsistent with the data in the local database master database, it cannot be resolved, resulting in data loss or data synchronization failure.

[0041] To address the technical issues in the prior art regarding transactions being affected, data being lost, or data synchronization failing when a primary database fails, the present application proposes a data synchronization method. When a primary database fails, a query delay command is sent to obtain a first time delay value of a first standby database relative to the primary database, and a second time delay value of a second standby database relative to the primary database. When both the first and second time delay values ​​are zero, a global transaction identifier acquisition instruction is sent to obtain the first global transaction identifier value corresponding to the primary database in the first standby database, and the second global transaction identifier value corresponding to the primary database in the second standby database. Data synchronization is then performed based on the first and second global transaction identifier values. This solves the technical issues regarding transactions being affected, data being lost, or data synchronization failing when a primary database fails. By comparing the global transaction identifier values ​​of the first and second standby databases, the discrepant data is stored for compensation, ensuring data consistency and ensuring that real-time data processing is not affected.

[0042] First, in order to make the data synchronization method described in the embodiments of the present application more clear to those skilled in the art, the semi-synchronization, global transaction identification, and automatic business isolation procedures involved are explained as follows:

[0043] Semisynchronous replication: The primary database is configured semi-synchronously with the primary and secondary standby databases to ensure data consistency between the primary and standby databases at all times. Compared to asynchronous replication, semisynchronous replication requires that each executed transaction be successfully received by at least one standby database before being returned to the user. In semisynchronous replication, the primary database must receive a response from at least one standby database before proceeding to the next transaction. The number of standby databases that respond can be set, indicating the number of responses from the primary database before the primary database proceeds. In a multi-standby database environment, setting this value greater than 1 improves data reliability.

[0044] A Global Transaction Identifier (GTID) is a unique identifier generated by the master database and bound to a transaction. It is unique not only on the master database but also within the database cluster. A GTID consists of two parts: a UUID (Universally Unique Identifier), stored in a target file in the database's data directory and cannot be deleted or changed; and a transaction identifier, whose value increases with each transaction.

[0045] The business automatic isolation program (Tdb for short) is an independent set of scripts deployed in the primary and backup databases to determine the port survival status of each other. If a port is found to be unavailable, the script execution will be triggered to isolate the database transactions.

[0046] Figure 2 A flowchart of a data synchronization method provided in an embodiment of the present application.

[0047] like Figure 2 As shown, the method is applied to a synchronization arbitration device, wherein the synchronization arbitration device is used to arbitrate the data synchronization process of the primary database, the first standby database, and the second standby database. One synchronization arbitration device can manage multiple sets of databases (one set of databases includes the primary database, the first standby database, the second standby database, etc.), and is usually independently deployed on an arbitration server.

[0048] That is, an arbitration program can be run in the synchronous arbitration device, and the primary database, the first standby database, and the second standby database all have addresses pointing to the synchronous arbitration device. Specifically, the following steps are included:

[0049] Step 101: When a primary database fails, a query delay command is sent to obtain a first time delay value of a first standby database relative to the primary database, and a second time delay value of a second standby database relative to the primary database.

[0050] Step 103: When both the first time delay value and the second time delay value are zero, a global transaction identifier acquisition instruction is sent.

[0051] In the embodiment of the present application, the primary database is semi-synchronized with the first standby database and the second standby database, and the primary database and the second standby database are connected by a virtual address.

[0052] As a possible implementation method, the database connection method of this application is as follows Figure 3 As shown, the primary database is connected to the first standby database (for example, a local database standby database), and the primary database is connected to the second standby database (for example, a local database standby database). A semi-synchronous configuration is adopted, that is, each transaction executed by the primary database requires at least one standby database (the first standby database or the second standby database) to successfully receive it before it is returned to the terminal (that is, the user).

[0053] In an embodiment of the present application, if a primary database fails, the business isolation program will have already cut off the real-time business within 3-6 seconds of the failure. The person responsible for failover needs to implement the drift of the virtual address connection. Because there are two semi-synchronous standby databases (a first standby database and a second standby database), it is necessary to increase the data synchronization status of the first standby database and the second standby database.

[0054] In the embodiment of the present application, time synchronization must first be ensured, that is, a query delay command is sent to obtain a first time delay value of the first standby database relative to the primary database, and a second time delay value of the second standby database relative to the primary database.

[0055] Furthermore, when both the first time delay value and the second time delay value are zero, it means that both the first standby database and the second standby database are synchronized with the primary database time, and a global transaction identifier acquisition instruction may be further sent.

[0056] It should be noted that when the first time delay value is not zero, the first standby database is controlled to synchronize time with the primary database, and when the second time delay value is not zero, the second standby database is controlled to synchronize time with the primary database.

[0057] Specifically, by writing scripts (including query delay commands and global transaction identifier acquisition instructions), the scripts can be deployed to the primary database and the standby database. After detecting the failure of the primary database and initiating the switch, the execution of the script is triggered, and the query delay command is sent to the first standby database and the second standby database at the same time. First, for the first and second standby databases, for example, the query delay command "Seconds_Behind_Master" is obtained through the database command "show master status". Make sure that both are 0 to ensure that there is no time delay between the first and second standby databases. If there is a delay, it is necessary to wait until the delay catches up before switching.

[0058] Step 105: Obtain a first global transaction identifier value corresponding to the primary database in the first standby database, and obtain a second global transaction identifier value corresponding to the primary database in the second standby database.

[0059] Step 107: Perform data synchronization processing according to the first global transaction identifier value and the second global transaction identifier value.

[0060] In the embodiment of the present application, each database has only one global transaction identifier, which is the global transaction identifier corresponding to the primary database. Before switching to the standby database, the global transaction identifier obtained in the database refers to the global transaction identifier corresponding to the primary database. After the primary database fails, the database switches to the standby database for data processing. The standby database will start writing its own global transaction identifier, and the global transaction identifier corresponding to the primary database will no longer change.

[0061] In an embodiment of the present application, on the first standby database and the second standby database, the first standby database obtains the global transaction identifier acquisition instruction "Executed_gtid_set" in the database command "show master status" to obtain the first global transaction identifier value corresponding to the master database, marked as A; the second standby database obtains the second global transaction identifier value corresponding to the master database by obtaining the global transaction identifier acquisition instruction "Executed_gtid_set" in the database command "show master status", marked as B; for example, B is 5ad9cb8e-2092-11e7-ac95-000c29bf823d:1-1000, 5ad9cb8e-2092-11e7-ac95-000c29bf823d is the global transaction identifier information of the master database, and the value to be compared is the value after -.

[0062] Furthermore, there are many ways to perform data synchronization processing based on the first global transaction identifier value and the second global transaction identifier value. As a possible implementation, the connection methods of the primary database, the first standby database, and the second standby database are as Figure 3 shown, all are semi-synchronous configurations, and the connection method between the primary database and the second standby database is a virtual address connection. Therefore, if the first global transaction identifier value is less than the second global transaction identifier value, the difference between the first global transaction identifier value and the second global transaction identifier value is obtained, the processing data corresponding to the difference is obtained, and the processing data is stored in the first standby database, and the data processing is switched to the first standby database. In addition, the second standby database is switched to the first standby database through a virtual address connection, and the link does not need to be changed, and the data of the first standby database can be directly synchronized.

[0063] In the embodiment of the present application, if the first global transaction identifier value is greater than or equal to the second global transaction identifier value, the data processing is switched to the first standby database, and the second standby database is switched to the first standby database through a virtual address connection.

[0064] The following is an example: Specifically, the first global transaction identifier value is:

[0065] 5ad9cb8e-2092-11e7-ac95-000c29bf823d:1-1000, and the value of A is 1000.

[0066] Specifically, the second global transaction identifier value is:

[0067] 5ad9cb8e-2092-11e7-ac95-000c29bf823d:1-999, and the value of B is 999.

[0068] Therefore, if A >= B, it means that the data on the first standby database is the latest, and the data processing can be switched to the first standby database. The missing data of the second standby database will be pulled from the first standby database through the global transaction identifier; if A < B, the processing data of the difference between B and A will be parsed from the second standby database and compensated on the first standby database, that is, the processing data will be stored in the first standby database to ensure the consistency of the two databases. Since the amount of instantaneously different data is small, the speed is very fast. If there is a difference, the data compensation can be completed within 2 - 5s. Since the second standby database synchronizes through a virtual address connection, after the primary database fails, the virtual address connection is switched to the first standby database without manual intervention, and the link can continue to be synchronized.

[0069] Specifically, as Figure 4As shown, the primary database is connected to the first standby database (for example, a local database standby database), and the primary database is connected to the second standby database (for example, a local database standby database). Both are semi-synchronous configurations, and the connection between the primary database and the second standby database is a virtual address connection. The second standby database switches to the first standby database through the virtual address connection. The link does not need to be changed, and the data of the first standby database can be directly synchronized.

[0070] In an embodiment of the present application, there are many ways to perform data synchronization processing based on the first global transaction identifier value and the second global transaction identifier value. As another possible implementation method, if the first global transaction identifier value is greater than the second global transaction identifier value, then switch to the first standby database for data processing; if the second global transaction identifier value is greater than the first global transaction identifier value, then switch to the second standby database for data processing; if the two values ​​are the same, the corresponding standby database can be selected randomly or based on factors such as database distance to perform data processing.

[0071] In the data synchronization method of an embodiment of the present application, when a primary database fails, a query delay command is sent to obtain a first time delay value of the first standby database relative to the primary database, and a second time delay value of the second standby database relative to the primary database; when both the first time delay value and the second time delay value are zero, a global transaction identifier acquisition instruction is sent; the first global transaction identifier value corresponding to the primary database in the first standby database is obtained, and the second global transaction identifier value corresponding to the primary database in the second standby database is obtained; and data synchronization processing is performed based on the first global transaction identifier value and the second global transaction identifier value. This solves the technical problem of transactions being affected and data being lost or data synchronization failing when the primary database fails. By comparing the global transaction identifier values ​​of the first and second standby databases, the discrepant processing data is compensated and stored, ensuring data consistency and ensuring that real-time data processing is not affected.

[0072] Based on the description of the above embodiment, it can also be understood that, when the primary database is normal and the first standby database fails, if the primary database receives a confirmation message sent by the second standby database, data synchronization will continue, and the data of the primary database will be semi-synchronized to the second standby database; and when the primary database is normal and the second standby database fails, if the primary database receives a confirmation character sent by the first standby database, data synchronization will continue, and the data of the primary database will be semi-synchronized to the first standby database.

[0073] In one embodiment of the present application, a parameter setting instruction is sent to control the target parameter of the primary database to be set to a preset value, so that the primary database continues data processing after receiving a confirmation message of the preset value. In other words, by setting the target parameter, the number of response standby databases can be set, indicating that the primary database will continue to the next step of processing only after receiving responses from several standby databases. In an environment with multiple standby databases, setting the number greater than 1 can improve data reliability.

[0074] Specifically, set "rpl_semi_sync_master_wait_for_slave_count" on the master database to 1. As long as one confirmation message is responded to by the first or second standby database, the master database will continue to operate. Generally speaking, the first standby database has smaller network constraints than the second standby database and receives the response the fastest.

[0075] When the first standby database fails, the business automatic isolation program performs business isolation. Due to the semi-synchronous mechanism, the second standby database returns the confirmation message. During the 3-6 seconds of business isolation, transactions can continue. This can achieve lossless isolation of business in the event of a standby database failure, such as Figure 5 As shown, the primary database is connected to the first standby database (for example, a local standby database), and the primary database is connected to the second standby database (for example, a same-city standby database). After the first standby database fails, the second standby database is connected to the primary database through a virtual address. The link does not need to be changed, and the data of the primary database can be directly synchronized.

[0076] As a result, the failure of the first backup database does not affect real-time transactions, which reduces the impact of both the primary and backup database failures. 2. The link replication architecture does not require automation or manual intervention, and the link maintains the synchronization relationship unchanged, ensuring data security.

[0077] In order to implement the above embodiment, the present application also proposes a data synchronization device

[0078] Figure 6 A schematic diagram of the structure of a data synchronization device provided in an embodiment of the present application.

[0079] like Figure 6 As shown, the device includes: a first acquisition module 601, a sending module 603, a second acquisition module 605, and a processing module 607.

[0080] The primary database is configured semi-synchronously with the first standby database and the second standby database respectively, and the primary database and the second standby database are connected by a virtual address.

[0081] The first acquisition module 601 is configured to send a query delay command to acquire a first time delay value of the first standby database relative to the primary database and a second time delay value of the second standby database relative to the primary database when the primary database fails.

[0082] The sending module 603 is configured to send a global transaction identifier acquisition instruction when both the first time delay value and the second time delay value are zero.

[0083] The second acquisition module 605 is configured to acquire a first global transaction identifier value corresponding to the primary database in the first standby database, and to acquire a second global transaction identifier value corresponding to the primary database in the second standby database.

[0084] The processing module 607 is configured to perform data synchronization processing according to the first global transaction identifier value and the second global transaction identifier value.

[0085] Furthermore, in a possible implementation of the embodiment of the present application, the primary database and the second standby database are connected in a virtual address connection manner. The processing module 607 is specifically configured to, if the first global transaction identifier value is less than the second global transaction identifier value, obtain a difference between the first global transaction identifier value and the second global transaction identifier value; obtain processed data corresponding to the difference, store the processed data in the first standby database, switch to the first standby database for data processing, and switch the second standby database to the first standby database through the virtual address connection.

[0086] Furthermore, in a possible implementation of the embodiment of the present application, the processing module 607 is specifically configured to, if the first global transaction identifier value is greater than or equal to the second global transaction identifier value, switch to the first standby database for data processing, and switch the second standby database to the first standby database through a virtual address connection.

[0087] Furthermore, in a possible implementation of the embodiment of the present application, the primary database adopts a semi-synchronous configuration with the first standby database and the second standby database respectively, and further includes: when the primary database is normal and the first standby database fails, if the primary database receives a confirmation message sent by the second standby database, it continues data processing and semi-synchronizes the data of the primary database to the second standby database.

[0088] Furthermore, in a possible implementation of an embodiment of the present application, the primary database adopts a semi-synchronous configuration with the first standby database and the second standby database, respectively, and further includes: when the primary database is normal and the second standby database fails, if the primary database receives a confirmation message sent by the first standby database, it continues data processing and semi-synchronizes the data of the primary database to the first standby database.

[0089] Furthermore, in a possible implementation of an embodiment of the present application, when the first time delay value is not zero, the first standby database is controlled to perform time synchronization with the primary database; when the second time delay value is not zero, the second standby database is controlled to perform time synchronization with the primary database.

[0090] Furthermore, in a possible implementation of the embodiment of the present application, a parameter setting instruction is sent to control the target parameter of the master database to be set to a preset value, so that the master database continues data processing after receiving a confirmation message of the preset value.

[0091] It should be noted that the above explanation of the method embodiment is also applicable to the device of this embodiment and will not be repeated here.

[0092] In the data synchronization device of the embodiment of the present application, when a primary database fails, a query delay command is sent to obtain a first time delay value of the first standby database relative to the primary database, and a second time delay value of the second standby database relative to the primary database; when both the first time delay value and the second time delay value are zero, a global transaction identifier acquisition instruction is sent; the first global transaction identifier value corresponding to the primary database in the first standby database is obtained, and the second global transaction identifier value corresponding to the primary database in the second standby database is obtained; and data synchronization processing is performed based on the first global transaction identifier value and the second global transaction identifier value. This solves the technical problem of transactions being affected and data being lost or data synchronization failing when the primary database fails. By comparing the global transaction identifier values ​​of the first and second standby databases, the discrepant processing data is compensated and stored, ensuring data consistency and ensuring that real-time data processing is not affected.

[0093] In order to implement the above-mentioned embodiment, the embodiment of the present application proposes an electronic device, including: a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, it implements the data synchronization method described in the above-mentioned terminal device execution method embodiment.

[0094] In order to implement the above embodiment, the embodiment of the present application proposes a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the data synchronization method described in the above method embodiment is implemented.

[0095] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine different embodiments or examples described in this specification and features of different embodiments or examples without contradiction.

[0096] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of such features. Throughout the description of this application, "plurality" means at least two, for example, two, three, etc., unless otherwise specifically defined.

[0097] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present application belong.

[0098] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device). For purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and a portable compact disc read-only memory (CDROM). Furthermore, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing it in another suitable manner if necessary, and then storing it in a computer memory.

[0099] It should be understood that various parts of the present application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0100] Those skilled in the art will understand that all or part of the steps in the method of the above embodiment can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.

[0101] In addition, the functional units in the various embodiments of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into a module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0102] The storage medium mentioned above may be a read-only memory, a magnetic disk, or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application. Persons skilled in the art may make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present application.

Claims

1. A data synchronization method, applied to a synchronization arbitration device, wherein: The synchronization arbitration device is used to arbitrate the data synchronization process of the primary database, the first standby database and the second standby database, and the method includes: When the primary database fails, sending a query delay command to obtain a first time delay value of the first standby database relative to the primary database and a second time delay value of the second standby database relative to the primary database; When both the first time delay value and the second time delay value are zero, sending a global transaction identifier acquisition instruction; Obtaining a first global transaction identifier value corresponding to the primary database in the first standby database, and obtaining a second global transaction identifier value corresponding to the primary database in the second standby database; Performing data synchronization processing according to the first global transaction identifier value and the second global transaction identifier value; The primary database and the second standby database are connected in a virtual address connection manner, and the data synchronization processing is performed according to the first global transaction identifier value and the second global transaction identifier value, including: If the first global transaction identifier value is less than the second global transaction identifier value, obtaining a difference between the first global transaction identifier value and the second global transaction identifier value; Obtaining processed data corresponding to the difference, storing the processed data in the first standby database, switching to the first standby database for data processing, and switching the second standby database to the first standby database through a virtual address connection; The method further comprises at least one of the following: When the first time delay value is not zero, controlling the first standby database to perform time synchronization with the primary database; When the second time delay value is not zero, the second standby database is controlled to perform time synchronization with the primary database.

2. The data synchronization method according to claim 1, wherein: Also includes: If the first global transaction identifier value is greater than or equal to the second global transaction identifier value, switching to the first standby database for data processing, and the second standby database switching to the first standby database through a virtual address connection.

3. The data synchronization method according to claim 1, wherein: The primary database is configured semi-synchronously with the first standby database and the second standby database, respectively, and further includes: When the primary database is normal and the first standby database fails, if the primary database receives a confirmation message sent by the second standby database, it continues data processing and semi-synchronizes the data of the primary database to the second standby database.

4. The data synchronization method according to claim 1, wherein: The primary database is configured semi-synchronously with the first standby database and the second standby database, respectively, and further includes: When the primary database is normal and the second standby database fails, if the primary database receives a confirmation message sent by the first standby database, it continues data processing and semi-synchronizes the data of the primary database to the first standby database.

5. The data synchronization method according to claim 1, wherein: Also includes: Send a parameter setting instruction to control the target parameter of the main database to be set to a preset value, so that the main database continues data processing after receiving a confirmation message of the preset value.

6. A data synchronization device, applied to a synchronization arbitration device, wherein: The synchronization arbitration device is used to arbitrate the data synchronization process of the primary database, the first standby database, and the second standby database, and is characterized in that the data synchronization device includes: a first acquisition module, configured to, when the primary database fails, send a query delay command to respectively acquire a first time delay value of the first standby database relative to the primary database and a second time delay value of the second standby database relative to the primary database; A sending module, configured to send a global transaction identifier acquisition instruction when both the first time delay value and the second time delay value are zero; A second acquisition module is configured to acquire a first global transaction identifier value corresponding to the primary database in the first standby database, and acquire a second global transaction identifier value corresponding to the primary database in the second standby database; A processing module, configured to perform data synchronization processing according to the first global transaction identifier value and the second global transaction identifier value; The primary database and the second standby database are connected in a virtual address connection manner, and the processing module is specifically configured to: If the first global transaction identifier value is less than the second global transaction identifier value, obtaining a difference between the first global transaction identifier value and the second global transaction identifier value; Obtaining processed data corresponding to the difference, storing the processed data in the first standby database, switching to the first standby database for data processing, and switching the second standby database to the first standby database through a virtual address connection; The data synchronization device is further used for: When the first time delay value is not zero, controlling the first standby database to perform time synchronization with the primary database; When the second time delay value is not zero, the second standby database is controlled to perform time synchronization with the primary database.

7. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data synchronization method according to any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the data synchronization method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • System and method for determining master-slave database synchronization delay and storage medium

    CN109684410A

  • Database synchronization method and device, storage medium and computer equipment

    CN110851528A