Data synchronization method, device, equipment and storage medium
By using the first application and the second application to synchronize data at the application level, the target synchronization status information is updated in real time, and the dirty reading problem caused by slow response speed of multi-store data synchronization is solved, and efficient data reading and consistency is achieved.
Patent Information
- Application Number
- CN202310651583.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-02
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2043-06-02
AI Technical Summary
In the prior art, the synchronization response speed of multi-store data is slow, resulting in dirty reading problems when users read database data.
By synchronizing data with the first application and the second application at the application level, the target synchronization status information of the data to be synchronized is updated in real time. Data is only read from the slave library when the target synchronization status information meets the preset reading conditions, otherwise data is read from the main library to avoid dirty reading.
Improve the response speed of multi-store data synchronization, avoid dirty reading, and ensure data consistency and reliability.
Smart Images

Figure CN116775758B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a data synchronization method, apparatus, device, and storage medium. Background Art
[0002] With the development of information technology, the amount of data is becoming increasingly large, and many application scenarios require data reading and writing services involving large amounts of data.
[0003] In related technologies, at the data source level, multiple slave databases are expanded from the master database, and the compensating transaction TCC (Try-Confirm-Cancel) is used to control data consistency between the multiple databases to meet the needs of reading and writing large amounts of data. Since TCC is a service-oriented two-phase commit protocol, the first phase of the service is orchestrated by business code to call the Try interface to reserve resources. Only when the Try interface in the first phase is successful will the second phase of the service submission be entered. This makes the response speed of data synchronization between multiple databases slow, resulting in dirty reads when users read database data (when the data is modified but not submitted to the database, the unmodified data is read externally). Summary of the Invention
[0004] The main purpose of this application is to provide a data synchronization method, device, equipment and storage medium, aiming to solve the technical problem of dirty read when users read data in the database in the prior art.
[0005] To achieve the above objectives, the present application provides a data synchronization method, which includes:
[0006] In response to an external data write request, obtaining the data to be synchronized and initial synchronization status information of the data to be synchronized, and saving the initial synchronization status information to the master database and the slave database;
[0007] Sending the data to be synchronized to a first application, and synchronizing the data to be synchronized to a second application based on the first application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to a master database, and the second application is used to write the data to be synchronized to a slave database;
[0008] Based on the synchronization result, the initial synchronization status information in the master database and the slave database is updated to obtain updated target synchronization status information;
[0009] In response to an external data read request for the data to be synchronized, based on a preset third application, it is determined whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions, the data to be read is read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized.
[0010] Optionally, the step of obtaining initial synchronization status information of the data to be synchronized includes:
[0011] Obtaining a slave status of the current slave, wherein the slave status includes a normal slave status and an abnormal slave status;
[0012] If the current slave database status is normal, the initial synchronization status information is determined to be a state where the synchronization notification is issued but not synchronized;
[0013] If the slave database status of the current slave database is in a slave database abnormal state, it is determined that the initial synchronization status information is a state in which the synchronization notification is not issued and synchronization is not performed.
[0014] Optionally, the step of updating the initial synchronization status information in the master database and the slave database based on the synchronization result to obtain updated target synchronization status information includes:
[0015] Based on the synchronization result and the slave database status, the initial synchronization status information in the master database and the slave database is updated;
[0016] If the synchronization result is a successful synchronization and the slave database status is a normal slave database status, the initial synchronization status information in the master database and the slave database is updated to a synchronization notification issued and synchronized status;
[0017] If the synchronization result is a successful synchronization and the slave database status is an abnormal slave database status, the initial synchronization status information in the master database and the slave database is not updated;
[0018] If the synchronization result is a synchronization failure and the slave database status is a normal slave database status, the initial synchronization status information in the master database is updated to a data rollback and clear status, and the initial synchronization status information in the slave database is updated to a synchronization notification issued and rolled back status;
[0019] If the synchronization result is synchronization failure and the slave database status is a slave database abnormal state, the initial synchronization status information in the master database is updated to a data rollback clearing state, and the initial synchronization status information in the slave database is not updated.
[0020] Optionally, the step of determining whether the target synchronization status information of the data to be synchronized in the slave library meets a preset reading condition includes:
[0021] If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and the data has been synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database meets the preset reading condition;
[0022] If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has not been issued and the data is not synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition;
[0023] If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and rolled back, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition.
[0024] Optionally, the master database and the slave database are heterogeneous databases.
[0025] Optionally, after the step of sending the data to be synchronized to the first application, and synchronizing the data to be synchronized to the second application based on the first application, and obtaining a synchronization result, the method includes:
[0026] If the synchronization result is a synchronization failure, the slave database where the synchronization failed is uninstalled, and synchronization exception processing is performed on the data to be synchronized and the target synchronization status information in the slave database.
[0027] Optionally, the slave library can be expanded in parallel, and the slave library includes at least one.
[0028] The present application also provides a data synchronization device, comprising:
[0029] An acquisition module, configured to acquire the data to be synchronized and initial synchronization status information of the data to be synchronized in response to an external data write request, and save the initial synchronization status information to the master database and the slave database;
[0030] A synchronization module, configured to send the data to be synchronized to a first application, and synchronize the data to be synchronized to a second application based on the first application, to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to a master database, and the second application is used to write the data to be synchronized to a slave database;
[0031] An updating module, configured to update the initial synchronization status information in the master database and the slave database based on the synchronization result to obtain updated target synchronization status information;
[0032] A reading module is used to respond to an external data read request for the data to be synchronized, and based on a preset third application, determine whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, the data to be read is read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized.
[0033] The present application also provides a data synchronization device, the data synchronization device comprising: a memory, a processor, and a program stored in the memory for implementing the data synchronization method.
[0034] The memory is used to store a program for implementing a data synchronization method;
[0035] The processor is used to execute a program for implementing the data synchronization method to implement the steps of the data synchronization method.
[0036] The present application also provides a storage medium, on which is stored a program for implementing the data synchronization method, and the program for implementing the data synchronization method is executed by a processor to implement the steps of the data synchronization method.
[0037] The present application provides a data synchronization method, apparatus, device and storage medium. Compared with the related art in which the response speed of data synchronization between multiple databases is slow, resulting in dirty reads when users read data in the database, in the present application, in response to an external data write request, the data to be synchronized and the initial synchronization status information of the data to be synchronized are obtained, and the initial synchronization status information is saved to the master database and the slave database; the data to be synchronized is sent to a first application, and based on the first application, the data to be synchronized is synchronized to a second application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to the master database, and the The second application is used to write the data to be synchronized to the slave library; based on the synchronization result, the initial synchronization status information in the master library and the slave library is updated to obtain the updated target synchronization status information; in response to an external data read request for the data to be synchronized, based on a preset third application, it is judged whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, and only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, the data to be read is read from the slave library, otherwise the data to be read is read from the master library to avoid dirty reading of the data to be synchronized. That is, in this application, data synchronization is performed at the application level through the first application and the second application, and the target synchronization status information of the data to be synchronized is updated in real time. Only when the target synchronization status information of the data to be synchronized meets the preset reading condition, the data to be read is read to avoid dirty reading of the data to be synchronized. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the embodiments or the description of the prior art. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without inventive work.
[0039] Figure 1 This is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present application;
[0040] Figure 2 This is a flowchart of the first embodiment of the data synchronization method of this application;
[0041] Figure 3 This is a module diagram of the data synchronization device of this application;
[0042] Figure 4 This is a schematic diagram of the system interaction process of the data synchronization method of this application;
[0043] Figure 5 A flowchart of data synchronization between applications in the data synchronization method of this application;
[0044] Figure 6 This is a flow diagram of the slave database state of the data synchronization method of this application;
[0045] Figure 7 This is a flowchart of data synchronization failure processing in the data synchronization method of this application;
[0046] Figure 8 This is a flowchart of the online synchronization exception handling process of the data synchronization method of this application.
[0047] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.
[0049] like Figure 1 As shown, Figure 1 It is a schematic diagram of the terminal structure of the hardware operating environment involved in the embodiment of the present application.
[0050] The terminal in the embodiment of the present application can be a PC, or it can be a smart phone, tablet computer, e-book reader, MP3 (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Compression Standard Audio Layer 3) player, MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Compression Standard Audio Layer 4) player, portable computer and other portable terminal devices with display function.
[0051] like Figure 1 As shown, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0052] Optionally, the terminal may also include a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. Among them, sensors include light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display screen according to the brightness of the ambient light, and the proximity sensor may turn off the display screen and / or backlight when the mobile terminal is moved to the ear. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile terminal (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; of course, the mobile terminal can also be configured with other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., which will not be repeated here.
[0053] Those skilled in the art will understand that Figure 1 The terminal structure shown in the figure does not constitute a limitation to the terminal, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0054] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating device, a network communication module, a user interface module and a data synchronization program.
[0055] exist Figure 1 In the terminal shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the data synchronization program stored in the memory 1005.
[0056] Reference Figure 2 , an embodiment of the present application provides a data synchronization method, the data synchronization method comprising:
[0057] Step S100: In response to an external data write request, obtaining data to be synchronized and initial synchronization status information of the data to be synchronized, and saving the initial synchronization status information to the master database and the slave database;
[0058] Step S200: Send the data to be synchronized to a first application, and synchronize the data to be synchronized to a second application based on the first application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to the master database, and the second application is used to write the data to be synchronized to the slave database;
[0059] Step S300: Based on the synchronization result, the initial synchronization status information in the master database and the slave database is updated to obtain updated target synchronization status information;
[0060] Step S400, in response to an external data read request for the data to be synchronized, based on a preset third application, determine whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, read the data to be read from the slave library; otherwise, read the data to be read from the master library to avoid dirty reading of the data to be synchronized.
[0061] In this embodiment, the application scenarios are:
[0062] As an example, the scenario of data synchronization can be a data reading and writing scenario that provides financial product information services. In the related technology, at the data source level, multiple slave databases are expanded from the main database, and the data consistency between the multiple databases is controlled by the compensation transaction TCC (Try-Confirm-Cancel) method to achieve the reading and writing needs of large amounts of data. Since TCC is a service-oriented two-phase commit protocol, the first phase service is orchestrated by the business code to call the Try interface to reserve resources. Only when the Try interface of the first phase is successful will the second phase service of the submission business be entered, which makes the response speed of data synchronization between multiple databases slow, resulting in dirty reading when users read the data in the database. For this scenario, the data synchronization method of this embodiment synchronizes data through the first application and the second application at the application level, and updates the target synchronization status information of the data to be synchronized in real time. Only when the target synchronization status information of the data to be synchronized meets the preset reading conditions, the data to be read is read to avoid dirty reading of the data to be synchronized.
[0063] As an example, the application scenario of data synchronization is not only the above-mentioned data reading and writing of financial product information services, but also includes various data synchronization scenarios, which are not specifically limited here.
[0064] This embodiment aims to avoid dirty reading of data.
[0065] In this embodiment, the data synchronization method is applied to a data synchronization device.
[0066] The specific steps are as follows:
[0067] Step S100: In response to an external data write request, obtaining data to be synchronized and initial synchronization status information of the data to be synchronized, and saving the initial synchronization status information to the master database and the slave database;
[0068] In this embodiment, the data write request refers to a request issued by a user when writing data into a database, wherein the data write request includes data to be synchronized, and the device obtains the data to be synchronized by parsing the data write request.
[0069] In this embodiment, the initial synchronization status information is information indicating the current synchronization status of the data to be synchronized. Before synchronizing the data to be synchronized in the master database to the slave database, the synchronization status of the data to be synchronized is determined to obtain the initial synchronization status information of the data to be synchronized. The device determines the initial synchronization status information of the data to be synchronized by determining the corresponding initial synchronization status information based on the current running status of the slave database. The initial synchronization status information is independently defined and can be a status value shared by the application, including but not limited to the slave database being able to synchronize normally, the slave database being unable to synchronize abnormally, and the data recovery process. In the following, Y is used to indicate that the slave database is able to synchronize normally, N is used to indicate that the slave database is unable to synchronize abnormally, and W is used to indicate the data recovery process, where Y, N, and W are status values shared by the application.
[0070] In this embodiment, before synchronizing the data to be synchronized in the master library to the slave library, the device saves the initial synchronization status information to the master library and the slave library, that is, the master library and the slave library need to save the initial synchronization status information of the data to be synchronized before storing the data to be synchronized before completing data synchronization. As long as there is only one slave library, the device will synchronize the data to be synchronized stored in the master library to each slave library, that is, each slave library maintains data consistency with the master library, and the master library and the slave library also contain the initial synchronization status information of the synchronized data.
[0071] Specifically, the step S100 includes the following steps S110-S130:
[0072] Step S110, obtaining the slave status of the current slave, wherein the slave status includes a normal slave status and an abnormal slave status;
[0073] In this embodiment, the device obtains the slave status of the current slave library, wherein the slave status includes a normal slave status and an abnormal slave status, and the slave status also includes a data recovery process. In the following, Y is used to indicate that the slave library is normally synchronizable, N indicates that the slave library is abnormal and cannot be synchronized, and W indicates that the data recovery process is in progress, wherein Y, N, and W are status values shared by the application.
[0074] Step S120: If the current slave state of the slave is normal, determine that the initial synchronization state information is a state where the synchronization notification is issued but not synchronized;
[0075] In this embodiment, if the current slave database status is the normal slave database status, the initial synchronization status information is determined to be a state in which the synchronization notification is issued but not synchronized, that is, when the slave database status is Y, the initial synchronization status information corresponding to the data to be synchronized is a state in which the synchronization notification is issued but not synchronized.
[0076] Step S130 : If the slave state of the current slave is an abnormal slave state, it is determined that the initial synchronization state information is a state in which the synchronization notification is not issued and synchronization is not performed.
[0077] In this embodiment, if the current slave database status is a slave database abnormal state, the initial synchronization status information is determined to be a state in which the synchronization notification has not been issued and is not synchronized, that is, when the slave database status is W, the initial synchronization status information corresponding to the data to be synchronized is a state in which the synchronization notification has not been issued and is not synchronized.
[0078] In this embodiment, if the current slave database status is in the slave database data recovery process, it is determined that the initial synchronization status information is a state in which the synchronization notification is issued but not synchronized, that is, when the slave database status is N, the initial synchronization status information corresponding to the data to be synchronized is a state in which the synchronization notification is issued but not synchronized.
[0079] In this embodiment, the initial synchronization status information includes the state where the synchronization notification is issued but not synchronized and the state where the synchronization notification is issued but not synchronized. In the following, P represents the state where the synchronization notification is issued but not synchronized; U represents the state where the synchronization notification is not issued and not synchronized.
[0080] Step S200: Send the data to be synchronized to a first application, and synchronize the data to be synchronized to a second application based on the first application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to the master database, and the second application is used to write the data to be synchronized to the slave database;
[0081] In this embodiment, the device sends the data to be synchronized to the first application, and synchronizes the data to be synchronized to the second application based on the first application to obtain a synchronization result. Figure 4 The first application is used to write the data to be synchronized to the master database, that is, to provide the master database transaction data maintenance service; the second application is responsible for receiving the transaction data from the first application and writing the data to be synchronized to the slave database. The synchronization results include successful synchronization (i.e., successful synchronization of the data between the first application and the second application) and failed synchronization (i.e., failed synchronization of the data between the first application and the second application). If the synchronization is successful, the current master database and the slave database both store the data to be synchronized and the initial synchronization status information of the data to be synchronized; if the synchronization fails, the current master database both stores the data to be synchronized and the initial synchronization status information of the data to be synchronized, and the slave database stores the initial synchronization status information of the data to be synchronized, but does not store the data to be synchronized.
[0082] Step S300: Based on the synchronization result, the initial synchronization status information in the master database and the slave database is updated to obtain updated target synchronization status information;
[0083] In this embodiment, the device updates the initial synchronization status information in the master and slave libraries based on the synchronization result to obtain updated target synchronization status information, wherein the target synchronization status information includes the status in which the synchronization notification is issued and synchronized, and the status in which the synchronization notification is issued and rolled back. In the following, C is used to represent the status in which the synchronization notification is issued and synchronized, and R is used to represent the status in which the synchronization notification is issued and rolled back. Since there is a situation in which the initial synchronization status information is not updated, the target synchronization status information in this case includes P (the status in which the synchronization notification is issued but not synchronized) and U (the status in which the synchronization notification is not issued and not synchronized). The device updates the initial synchronization status information in the master and slave libraries to obtain updated target synchronization status information, that is, if the synchronization is successful, the current master and slave libraries both store the data to be synchronized and the target synchronization status information of the data to be synchronized; if the synchronization fails, the current master library both stores the data to be synchronized and the target synchronization status information of the data to be synchronized, and the slave library stores the target synchronization status information of the data to be synchronized, but does not store the data to be synchronized.
[0084] Specifically, the step S300 includes the following steps S310-S350:
[0085] Step S310: Based on the synchronization result and the slave database status, the initial synchronization status information in the master database and the slave database is updated;
[0086] In this embodiment, in addition to the synchronization result, the device also considers the slave database status, updates the initial synchronization status information in the master database and the slave database, and determines the updated target synchronization status information.
[0087] Step S320: If the synchronization result is successful and the slave database is in a normal state, the initial synchronization status information in the master database and the slave database is updated to a state where a synchronization notification has been issued and the data has been synchronized.
[0088] In this embodiment, if the synchronization result is a successful synchronization and the slave database status is a normal slave database status, the initial synchronization status information in the master database and the slave database is updated to a state where a synchronization notification is issued and the synchronization has been completed. That is, if the data synchronization is successful in the normal slave database status, the current master database and the slave database both store the data to be synchronized and the target synchronization status information of the data to be synchronized, and the specific target synchronization status information is C (the synchronization notification is issued and the synchronization has been completed).
[0089] Step S330: If the synchronization result is a successful synchronization and the slave database status is an abnormal slave database status, the initial synchronization status information in the master database and the slave database is not updated;
[0090] In this embodiment, if the synchronization result is a successful synchronization and the slave database status is an abnormal slave database status, the initial synchronization status information in the master database and the slave database will not be updated, that is, the target synchronization status information is the same as the initial synchronization status information. Specifically, the target synchronization status information in the master database and the slave database is P (a state in which the synchronization notification is issued but not synchronized) or U (a state in which the synchronization notification is not issued and not synchronized).
[0091] Step S340: If the synchronization result is a synchronization failure and the slave database is in a normal slave database state, the initial synchronization status information in the master database is updated to a data rollback and clear status, and the initial synchronization status information in the slave database is updated to a synchronization notification issued and rolled back status;
[0092] In this embodiment, if the synchronization result is a synchronization failure and the slave database status is a normal slave database status, the initial synchronization status information in the master database is updated to a data rollback and clearing status, and the initial synchronization status information in the slave database is updated to a synchronization notification issued and rolled back status, that is, the target synchronization status information in the master database is a data rollback and clearing status, and the target synchronization status information in the slave database is a synchronization notification issued and rolled back status. In this scenario, neither the master database nor the slave database stores the data to be synchronized, that is, the storage of the data to be synchronized fails.
[0093] Step S350: If the synchronization result is synchronization failure and the slave database status is in slave database abnormal state, the initial synchronization status information in the master database is updated to a data rollback clear state, and the initial synchronization status information in the slave database is not updated.
[0094] In this embodiment, if the synchronization result is a synchronization failure and the slave database status is a slave database abnormal state, the initial synchronization status information in the master database is updated to a data rollback and clearing state, and the initial synchronization status information in the slave database is not updated, that is, the target synchronization status information in the master database is a data rollback and clearing state, and the target synchronization status information in the slave database is P (a state in which the synchronization notification is issued but not synchronized) or U (a state in which the synchronization notification is not issued and not synchronized).
[0095] In this embodiment, referring to Figure 7, application A is used to write transaction data to the master database (i.e., the first application), and application M is an application responsible for receiving transaction data from application A and writing transaction data received from the slave database (i.e., the second application). The processing flow of the synchronization status information U (synchronization notification not issued and not synchronized) generated during the slave database status N (slave database abnormally cannot be synchronized): When application M or the slave database is unavailable, application A will no longer synchronize transaction data to the slave database, and only leave a synchronization status information of U (synchronization notification not issued and not synchronized) on the master database. After application M and the slave database are restored, application A should actively send these data records of the synchronization notification not issued and not synchronized status to application M to update the data of the slave database. When the value of the synchronization switch is W (data recovery process), the scheduled scanning function on application A queries all synchronization status information with status U on the master database, and groups them according to specific transactions. Transaction data has a self-increasing version number. Application A compares the version number on the synchronization status information with the version number on the transaction data in the master database, and directly sets the status of the synchronization status information corresponding to the transaction data and with a smaller version number than the transaction data to C. If there is still synchronization status information with the same version number as the transaction data and a status of U (hereinafter referred to as "current synchronization status information"), the scheduled scanning function of application A will synchronize the corresponding transaction data to application M, and application M will update the transaction data in the slave database and set the synchronization status information of the slave database to C (if it does not exist, a new synchronization status information in the C status will be added). At this time, if application A successfully calls application M, application A will set the status of the current synchronization status information to C; if application A fails to call application M, the current synchronization status information will not be processed, and the scheduled scanning function will process the next transaction data, waiting for the next processing of the scheduled scanning function on application A.
[0096] Step S400, in response to an external data read request for the data to be synchronized, based on a preset third application, determine whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, read the data to be read from the slave library; otherwise, read the data to be read from the master library to avoid dirty reading of the data to be synchronized.
[0097] In this embodiment, referring to Figure 5Before reading the data to be synchronized, the master and slave libraries store target synchronization status information corresponding to the data to be synchronized. When in a data reading scenario, the device responds to an external data read request for the data to be synchronized, and based on a preset third application, determines whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions is the data to be read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized. That is, the target synchronization status information is used to determine whether the data to be synchronized can be read. If it can be read, it means that the data to be synchronized in the master and slave libraries are consistent. If it cannot be read, it means that the data to be synchronized in the master and slave libraries are inconsistent, thereby avoiding dirty reading of the data to be synchronized.
[0098] In this embodiment, specifically, the transaction data query request received from the external read request application is received by the third application (application T), and application T determines whether the target synchronization status information of the data to be synchronized meets the preset reading conditions. If the slave database status is Y (the slave database can be synchronized normally) and there is no target synchronization status information with a status of P (synchronization notification issued but not synchronized) in the slave database, then application T queries the transaction data from the slave database; if the slave database status is N (the slave database is abnormal and cannot be synchronized) or W (in the process of data recovery), or the target synchronization status information is P (synchronization notification issued but not synchronized), then application T queries the transaction data from the master database through application E.
[0099] In this embodiment, the device preferentially judges the target synchronization status information of the data to be synchronized in the slave library. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions, the data to be read is read from the slave library. If the target synchronization status information of the data to be synchronized in the slave library does not meet the reading conditions, the data to be read is read from the master library.
[0100] Specifically, the step S400 includes the following steps S410-S430:
[0101] Step S410: If the target synchronization status information of the data to be synchronized in the slave database is in a state where a synchronization notification has been issued and the data has been synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database meets a preset reading condition;
[0102] Step S420: If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has not been issued and the data is not synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition;
[0103] Step S430: If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and rolled back, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition.
[0104] In this embodiment, the present application provides an application-level synchronization method and a read-write library switching mechanism. This read library structure does not affect the main library, and it is easy to expand more read libraries when the transaction data query volume increases. Specifically, refer to Figure 4 By correspondingly increasing the number of "slaves," applications M, T, and synchronization switches, the read database can be expanded in parallel to accommodate increases in query volume. The interaction address between application A and application M can be fixed or configured using a list. In the above process, all calls from application A to application M can be described as a loop of calls from application A to application M1, application M2, application M3, and so on. This allows for continuous expansion of the read database or slaves with minimal impact on performance. Adding slaves does not reduce system reliability.
[0105] In this embodiment, the present application provides an application-level synchronization method and a read-write library switching mechanism, which supports data synchronization of heterogeneous databases, that is, the master library and the slave library can be heterogeneous databases. In heterogeneous databases, cost-effective equipment can be used to reduce costs.
[0106] In this embodiment, referring to Figure 6 In a preferred embodiment, the slave status includes N (slave abnormality and cannot be synchronized), Y (slave normal synchronization), and W (data recovery process). To ensure that the abnormality of the slave and application M does not affect the normal execution of the business, application A needs to detect the availability of the slave and application M itself through application M, while application T needs to actively detect the availability of the slave. The shared slave status value is determined based on the detection results. If the slave status value is Y, any application that detects that the system is unavailable will change the slave status value to N and actively notify other applications. The status value of the synchronization switch cannot be directly changed from N to Y. If the system returns to an available state after the fault is eliminated, the system can automatically detect the availability and set the slave status value to W, or the slave status value can be manually modified after the fault is eliminated. The slave status value W indicates that the data is in the recovery process. Recovery means that application A synchronizes all records with synchronization status information of U to application M and saves the transaction data corresponding to the synchronization status information to the slave. If after all data synchronization is completed, there are no more U status records within a certain period of time, then application A will set the shared slave status value to Y. Before the slave status value is modified to Y, the original value must be checked to be W. If the original value is N, it cannot be modified to Y.
[0107] After the step of sending the data to be synchronized to the first application and synchronizing the data to be synchronized to the second application based on the first application to obtain a synchronization result in step S200, the method includes the following steps A100:
[0108] Step A100: If the synchronization result is a synchronization failure, the slave database where the synchronization failed is uninstalled, and synchronization exception processing is performed on the data to be synchronized and the target synchronization status information in the slave database.
[0109] In this embodiment, if the synchronization result is a synchronization failure, the device uninstalls the slave library where the synchronization failed, and performs synchronization exception processing on the data to be synchronized and the target synchronization status information in the slave library. Specifically, the update of the data to be synchronized and the synchronization status information of the slave library is completed by application A calling application M. After application A calls application M, it is only called once regardless of success or failure. The abnormal data to be synchronized and target synchronization status information in the slave library are sent to the preset online synchronization exception processing process for repair. This will not block the normal transaction process, and can also avoid highly concurrent redundant update operations and avoid data storms.
[0110] In this embodiment, referring to Figure 8 , the specific method for handling online synchronization exceptions is as follows: Application M periodically scans the synchronization control records that are still in P state after exceeding the system-set time (which can be controlled by parameters). For each synchronization control record in P state, query the synchronization status information of the main database to application A based on the transaction information. There are two situations at this time: 1. There is no synchronization control record in the main database, which means that the transaction data on application A has been rolled back or has not been submitted, then insert a corresponding R (rolled back) state synchronization control record to mark it. If the record is inserted successfully, the R state is returned; if the insertion fails, it means that the transaction on application A has not been submitted, then an error is returned and wait for the next processing; 2. If there is a control record in the main database, the control status of the synchronization control record is returned directly. For calls that return an error, application M does not process it and waits for the next initiation. For calls that return the control status normally, application M performs specific processing according to the status:
[0111] (1) Status where P synchronization notification is issued but not synchronized: Update transaction data in the slave database, update synchronization status information to C, and call application A to update synchronization status information in the master database to C;
[0112] (2) R synchronization notification is issued and rolled back: the slave synchronization control status is updated to R;
[0113] (3) C synchronization notification is issued and the synchronization status is completed: update the slave database transaction data and update the slave database synchronization status information to C;
[0114] (4) U synchronization notification is not issued and the synchronization status is not synchronized: Update the transaction data of the slave database, update the synchronization status information of the slave database to C, and call application A to update the control status of the master database to C.
[0115] After application M completes its processing, it calls application A to update the control record status. If application A fails to update, the application M transaction is rolled back and waits for the next processing.
[0116] In this embodiment, a non-waiting control method is used for data consistency between the master database and the slave database, which reduces processing delay and prevents system data deadlock.
[0117] The present application provides a data synchronization method. Compared with the related art in which the response speed of data synchronization between multiple databases is slow, resulting in dirty reading when users read the data in the database, in the present application, in response to an external data write request, the data to be synchronized and the initial synchronization status information of the data to be synchronized are obtained, and the initial synchronization status information is saved to the master database and the slave database; the data to be synchronized is sent to a first application, and based on the first application, the data to be synchronized is synchronized to a second application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to the master database, and the second application is used to write the data to be synchronized to the master database. Used to write the data to be synchronized to the slave library; based on the synchronization result, update the initial synchronization status information in the master library and the slave library to obtain the updated target synchronization status information; in response to an external data read request for the data to be synchronized, based on a preset third application, judge whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, and only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, read the data to be read from the slave library, otherwise read the data to be read from the master library to avoid dirty reading of the data to be synchronized. That is, in this application, data synchronization is performed at the application level through the first application and the second application, and the target synchronization status information of the data to be synchronized is updated in real time. Only when the target synchronization status information of the data to be synchronized meets the preset reading condition, read the data to be read to avoid dirty reading of the data to be synchronized.
[0118] This application also provides a data synchronization device, referring to Figure 3 , the data synchronization device includes:
[0119] An acquisition module 10 is configured to acquire the data to be synchronized and initial synchronization status information of the data to be synchronized in response to an external data write request, and save the initial synchronization status information to the master database and the slave database;
[0120] A synchronization module 20 is configured to send the data to be synchronized to a first application, and synchronize the data to be synchronized to a second application based on the first application to obtain a synchronization result, wherein the first application is configured to write the data to be synchronized to a master database, and the second application is configured to write the data to be synchronized to a slave database;
[0121] An updating module 30 is configured to update the initial synchronization status information in the master database and the slave database based on the synchronization result to obtain updated target synchronization status information;
[0122] The reading module 40 is used to respond to an external data read request for the data to be synchronized, and based on a preset third application, determine whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, the data to be read is read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized.
[0123] Optionally, the acquisition module 10 includes:
[0124] A slave status acquisition module is used to acquire the slave status of the current slave, wherein the slave status includes a normal slave status and an abnormal slave status;
[0125] The first determining module is configured to determine, if the slave state of the current slave is a normal slave state, that the initial synchronization state information is a state in which a synchronization notification is issued but synchronization is not performed;
[0126] The second determining module is configured to determine, if the slave database state of the current slave database is in the slave database abnormal state, that the initial synchronization state information is a state in which the synchronization notification is not issued and synchronization is not performed.
[0127] Optionally, the updating module 30 includes:
[0128] A synchronization status information updating module, configured to update the initial synchronization status information in the master database and the slave database based on the synchronization result and the slave database status;
[0129] A third determining module is configured to update the initial synchronization status information in the master database and the slave database to a state where a synchronization notification has been issued and synchronization has been completed if the synchronization result is a successful synchronization and the slave database status is a normal slave database status;
[0130] a fourth determining module, configured to not update the initial synchronization status information in the master database and the slave database if the synchronization result is a successful synchronization and the slave database status is an abnormal slave database status;
[0131] a fifth determination module configured to update the initial synchronization status information in the master database to a data rollback and clear status if the synchronization result is a synchronization failure and the slave database status is a normal slave database status, and to update the initial synchronization status information in the slave database to a synchronization notification issued and rolled back status;
[0132] The sixth determination module is used to update the initial synchronization status information in the master database to a data rollback and clearing state if the synchronization result is a synchronization failure and the slave database state is a slave database abnormal state, and not update the initial synchronization status information in the slave database.
[0133] Optionally, the reading module 40 is configured to include:
[0134] a seventh determining module, configured to determine whether the target synchronization status information of the data to be synchronized in the slave database satisfies a preset reading condition if the target synchronization status information of the data to be synchronized in the slave database is in a state where a synchronization notification has been issued and the data has been synchronized;
[0135] an eighth determining module, configured to determine that the target synchronization status information of the data to be synchronized in the slave database does not meet a preset reading condition if the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has not been issued and the data is not synchronized;
[0136] The ninth determining module is configured to determine that the target synchronization status information of the data to be synchronized in the slave database does not meet a preset reading condition if the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and rolled back.
[0137] Optionally, the data synchronization device further includes:
[0138] The exception handling module is used to uninstall the slave database where the synchronization failed if the synchronization result is a synchronization failure, and perform synchronization exception handling on the data to be synchronized and the target synchronization status information in the slave database.
[0139] The specific implementation of the data synchronization device of the present application is basically the same as the embodiments of the above-mentioned data synchronization method, and will not be repeated here.
[0140] Reference Figure 1 , Figure 1 It is a schematic diagram of the terminal structure of the hardware operating environment involved in the embodiment of the present application.
[0141] like Figure 1As shown, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0142] Optionally, the data synchronization device may further include a rectangular user interface, a network interface, a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. The rectangular user interface may include a display and an input submodule such as a keyboard. Optionally, the rectangular user interface may also include a standard wired interface and a wireless interface. The network interface may optionally include a standard wired interface and a wireless interface (such as a WiFi interface).
[0143] Those skilled in the art will understand that Figure 1 The data synchronization device structure shown in the figure does not constitute a limitation to the data synchronization device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0144] like Figure 1 As shown, memory 1005, a storage medium, may include an operating system, a network communication module, and a data synchronization program. The operating system is a program that manages and controls the hardware and software resources of the data synchronization device and supports the operation of the data synchronization program and other software and / or programs. The network communication module is used to enable communication between the various components within memory 1005, as well as communication with other hardware and software in the data synchronization system.
[0145] exist Figure 1 In the data synchronization device shown, the processor 1001 is used to execute the data synchronization program stored in the memory 1005 to implement the steps of any of the above-mentioned data synchronization methods.
[0146] The specific implementation of the data synchronization device of this application is basically the same as the embodiments of the above-mentioned data synchronization method, and will not be repeated here.
[0147] The present application further provides a storage medium, wherein a program for implementing the data synchronization method is stored on the storage medium, and the program for implementing the data synchronization method is executed by a processor to implement the following data synchronization method:
[0148] In response to an external data write request, obtaining the data to be synchronized and initial synchronization status information of the data to be synchronized, and saving the initial synchronization status information to the master database and the slave database;
[0149] Sending the data to be synchronized to a first application, and synchronizing the data to be synchronized to a second application based on the first application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to a master database, and the second application is used to write the data to be synchronized to a slave database;
[0150] Based on the synchronization result, the initial synchronization status information in the master database and the slave database is updated to obtain updated target synchronization status information;
[0151] In response to an external data read request for the data to be synchronized, based on a preset third application, it is determined whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions, the data to be read is read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized.
[0152] Optionally, the step of obtaining initial synchronization status information of the data to be synchronized includes:
[0153] Obtaining a slave status of the current slave, wherein the slave status includes a normal slave status and an abnormal slave status;
[0154] If the current slave database status is normal, the initial synchronization status information is determined to be a state where the synchronization notification is issued but not synchronized;
[0155] If the slave database status of the current slave database is in a slave database abnormal state, it is determined that the initial synchronization status information is a state in which the synchronization notification is not issued and synchronization is not performed.
[0156] Optionally, the step of updating the initial synchronization status information in the master database and the slave database based on the synchronization result to obtain updated target synchronization status information includes:
[0157] Based on the synchronization result and the slave database status, the initial synchronization status information in the master database and the slave database is updated;
[0158] If the synchronization result is a successful synchronization and the slave database status is a normal slave database status, the initial synchronization status information in the master database and the slave database is updated to a synchronization notification issued and synchronized status;
[0159] If the synchronization result is a successful synchronization and the slave database status is an abnormal slave database status, the initial synchronization status information in the master database and the slave database is not updated;
[0160] If the synchronization result is a synchronization failure and the slave database status is a normal slave database status, the initial synchronization status information in the master database is updated to a data rollback and clear status, and the initial synchronization status information in the slave database is updated to a synchronization notification issued and rolled back status;
[0161] If the synchronization result is synchronization failure and the slave database status is a slave database abnormal state, the initial synchronization status information in the master database is updated to a data rollback clearing state, and the initial synchronization status information in the slave database is not updated.
[0162] Optionally, the step of determining whether the target synchronization status information of the data to be synchronized in the slave library meets a preset reading condition includes:
[0163] If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and the data has been synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database meets the preset reading condition;
[0164] If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has not been issued and the data is not synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition;
[0165] If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and rolled back, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition.
[0166] Optionally, the master database and the slave database are heterogeneous databases.
[0167] Optionally, after the step of sending the data to be synchronized to the first application, and synchronizing the data to be synchronized to the second application based on the first application, and obtaining a synchronization result, the method includes:
[0168] If the synchronization result is a synchronization failure, the slave database where the synchronization failed is uninstalled, and synchronization exception processing is performed on the data to be synchronized and the target synchronization status information in the slave database.
[0169] Optionally, the slave library can be expanded in parallel, and the slave library includes at least one.
[0170] The specific implementation of the storage medium of the present application is basically the same as the embodiments of the above-mentioned data synchronization method, and will not be repeated here.
[0171] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned data synchronization method when executed by a processor.
[0172] The specific implementation of the computer program product of the present application is basically the same as the various embodiments of the above-mentioned data synchronization method, and will not be repeated here.
[0173] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0174] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0175] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0176] The above are only preferred embodiments of the present application and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A data synchronization method, characterized in that: The data synchronization method includes: In response to an external data write request, obtaining the data to be synchronized and initial synchronization status information of the data to be synchronized, and saving the initial synchronization status information to the master database and the slave database; Sending the data to be synchronized to a first application, and synchronizing the data to be synchronized to a second application based on the first application to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to a master database, and the second application is used to write the data to be synchronized to a slave database; Based on the synchronization result, the initial synchronization status information in the master database and the slave database is updated to obtain updated target synchronization status information; In response to an external data read request for the data to be synchronized, based on a preset third application, it is determined whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading conditions, the data to be read is read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized.
2. The data synchronization method according to claim 1, wherein: The step of obtaining the initial synchronization status information of the data to be synchronized includes: Obtaining a slave status of the current slave, wherein the slave status includes a normal slave status and an abnormal slave status; If the current slave database status is normal, the initial synchronization status information is determined to be a state where the synchronization notification is issued but not synchronized; If the slave database status of the current slave database is in a slave database abnormal state, it is determined that the initial synchronization status information is a state in which the synchronization notification is not issued and synchronization is not performed.
3. The data synchronization method according to claim 2, wherein: The step of updating the initial synchronization status information in the master database and the slave database based on the synchronization result to obtain updated target synchronization status information includes: Based on the synchronization result and the slave database status, the initial synchronization status information in the master database and the slave database is updated; If the synchronization result is a successful synchronization and the slave database status is a normal slave database status, the initial synchronization status information in the master database and the slave database is updated to a synchronization notification issued and synchronized status; If the synchronization result is a successful synchronization and the slave database status is an abnormal slave database status, the initial synchronization status information in the master database and the slave database is not updated; If the synchronization result is a synchronization failure and the slave database status is a normal slave database status, the initial synchronization status information in the master database is updated to a data rollback and clear status, and the initial synchronization status information in the slave database is updated to a synchronization notification issued and rolled back status; If the synchronization result is synchronization failure and the slave database status is a slave database abnormal state, the initial synchronization status information in the master database is updated to a data rollback clearing state, and the initial synchronization status information in the slave database is not updated.
4. The data synchronization method according to claim 3, wherein: The step of determining whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition includes: If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and the data has been synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database meets the preset reading condition; If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has not been issued and the data is not synchronized, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition; If the target synchronization status information of the data to be synchronized in the slave database is in a state where the synchronization notification has been issued and rolled back, it is determined that the target synchronization status information of the data to be synchronized in the slave database does not meet the preset reading condition.
5. The data synchronization method according to claim 1, wherein: The master database and the slave database are heterogeneous databases.
6. The data synchronization method according to claim 1, wherein: After the step of sending the data to be synchronized to the first application, and synchronizing the data to be synchronized to the second application based on the first application to obtain a synchronization result, the method includes: If the synchronization result is a synchronization failure, the slave database where the synchronization failed is uninstalled, and synchronization exception processing is performed on the data to be synchronized and the target synchronization status information in the slave database.
7. The data synchronization method according to claim 1, wherein: The slave library can be expanded in parallel, and the slave library includes at least one.
8. A data synchronization device, characterized in that: The data synchronization device includes: An acquisition module, configured to acquire the data to be synchronized and initial synchronization status information of the data to be synchronized in response to an external data write request, and save the initial synchronization status information to the master database and the slave database; A synchronization module, configured to send the data to be synchronized to a first application, and synchronize the data to be synchronized to a second application based on the first application, to obtain a synchronization result, wherein the first application is used to write the data to be synchronized to a master database, and the second application is used to write the data to be synchronized to a slave database; An updating module, configured to update the initial synchronization status information in the master database and the slave database based on the synchronization result to obtain updated target synchronization status information; A reading module is used to respond to an external data read request for the data to be synchronized, and based on a preset third application, determine whether the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition. Only when the target synchronization status information of the data to be synchronized in the slave library meets the preset reading condition, the data to be read is read from the slave library; otherwise, the data to be read is read from the master library to avoid dirty reading of the data to be synchronized.
9. A data synchronization device, characterized in that: The data synchronization device includes: a memory, a processor, and a program stored in the memory for implementing the data synchronization method. The memory is used to store a program for implementing a data synchronization method; The processor is configured to execute a program for implementing the data synchronization method, so as to implement the steps of the data synchronization method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a program for implementing the data synchronization method, and the program for implementing the data synchronization method is executed by a processor to implement the steps of the data synchronization method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Data synchronization method and system
CN112307045A
Data synchronization method and device under read-write separation
CN113761049A