Data management based on fast synchronization mechanism
By employing a fast synchronization mechanism in the distributed database to synchronize data writing logs to the primary and standby databases, the problem of low data writing efficiency between the primary and standby databases is solved, achieving more efficient data writing and better service quality.
Patent Information
- Application Number
- PCT/CN2025/093351
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-05-31
- Filing Date
- 2025-05-08
- Publication Date
- 2025-12-04
AI Technical Summary
Existing distributed databases have low data write efficiency between the master and slave databases, resulting in poor service quality.
A data management method based on a fast synchronization mechanism is adopted. After data is written to the leader replica of the primary database, a data write log is generated and simultaneously synchronized to other replicas and standby databases of the primary database, thereby improving data write efficiency.
It reduces the data synchronization latency between the primary and standby databases, and improves the data writing efficiency and service quality of the distributed database.
Smart Images

Figure CN2025093351_04122025_PF_FP_ABST
Abstract
Description
Data management based on fast synchronization mechanism Technical Field
[0001] This disclosure relates to the field of database technology, and more particularly to data management based on a fast synchronization mechanism. Background Technology
[0002] In today's era of rapid development in the internet and information technology, data generation is exploding, thus placing increasingly higher demands on databases and their management. Current distributed databases often address temporary failures by setting up primary and standby databases. This means that if the primary database fails, the standby database can take over as the primary and continue providing services, thereby avoiding service interruptions and ensuring service quality and efficiency.
[0003] Generally, in a distributed database, the primary database provides write services, while the standby database is used for data backup. In related technologies, writing data to a distributed database that includes a primary and a standby database is inefficient, resulting in poor database service quality. Summary of the Invention
[0004] In view of this, one or more embodiments of this disclosure provide a data management method and apparatus based on a fast synchronization mechanism.
[0005] To achieve the above objectives, one or more embodiments of this disclosure provide the following technical solutions.
[0006] According to a first aspect of one or more embodiments of this disclosure, a data management method based on a fast synchronization mechanism is proposed. The method is applied to a primary database in a data system, the data system further including a backup database. The method includes: in response to receiving a data write request sent by a client, writing target data indicated by the data write request into the leader replica of the primary database and generating a data write log; sending the data write log to other replicas of the primary database and the backup database respectively, so that the other replicas of the primary database and the backup database respectively replay the data write log to write the target data.
[0007] In one embodiment of this disclosure, the step of sending the data write log to other replicas of the primary database and the backup database respectively, so that the other replicas of the primary database and the backup database respectively replay the data write log to write the target data, includes: sending the data write log to other replicas of the primary database and multiple replicas of the backup database respectively, so that the other replicas of the primary database and multiple replicas of the backup database respectively replay the data write log to write the target data.
[0008] In one embodiment of this disclosure, the method further includes: determining that the target data has been successfully written to the primary database in response to receiving a write confirmation message returned by a first preset number of replicas among other replicas of the primary database within a preset time period; determining that the target data has been successfully written to the backup database in response to receiving a write confirmation message returned by a second preset number of replicas among a plurality of replicas of the backup database within a preset time period; and returning a write success message to the client in response to the successful writing of the target data in both the primary and backup databases.
[0009] In one embodiment of this disclosure, the method further includes: adjusting the first preset quantity and / or the second preset quantity according to an adjustment instruction.
[0010] In one embodiment of this disclosure, the method further includes: at least one replica of the primary database sending a leader election request to other replicas; each replica of the primary database returning a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; and determining that any replica of the primary database is the leader replica based on the number or proportion of leader response messages received that satisfy the leader election criteria.
[0011] According to a second aspect of one or more embodiments of this disclosure, a data management method based on a fast synchronization mechanism is proposed, applied to a backup database in a data system, the data system further including a primary database. The method includes: receiving a data write log sent by the leader of the primary database, and replaying the data write log to write the target data indicated by the data write log into the backup database; wherein the data write log is generated by the primary database after writing the target data indicated by a data write request sent by a client into the leader replica of the primary database, and then sending it to other replicas of the primary database and the backup database.
[0012] In one embodiment of this disclosure, receiving the data write log sent by the leader of the primary database and replaying the data write log to write the target data indicated by the data write log to the backup database includes: each replica of the backup database receiving the data write log sent by the leader of the primary database and replaying the data write log to write the target data indicated by the data write log to the replica; wherein the data write log is generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and is sent to the other replicas of the primary database and each replica of the backup database.
[0013] In one embodiment of this disclosure, the method further includes: each replica of the standby database returning a write confirmation message to the leader replica of the primary database when the target data is successfully written, so that the leader replica of the primary database determines that the target data has been successfully written to the standby database in response to receiving a second preset number of write confirmation messages from multiple replicas of the standby database within a preset time period.
[0014] In one embodiment of this disclosure, the method further includes: at least one replica of the backup database sending a leader election request to other replicas; each replica of the backup database returning a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; and determining that any replica of the backup database is the leader replica based on the number or proportion of leader response messages received that satisfy the leader election criteria.
[0015] According to a third aspect of one or more embodiments of this disclosure, a data management apparatus based on a fast synchronization mechanism is proposed, applied to a primary database in a data system, the data system further including a backup database. The apparatus includes: a writing module, configured to, in response to receiving a data write request sent by a client, write target data indicated by the data write request into the leader replica of the primary database and generate a data write log; and a synchronization module, configured to send the data write log to other replicas of the primary database and the backup database respectively, so that the other replicas of the primary database and the backup database respectively replay the data write log to write the target data.
[0016] In one embodiment of this disclosure, the synchronization module is configured to: send the data write log to other replicas of the primary database and multiple replicas of the backup database respectively, so that the other replicas of the primary database and multiple replicas of the backup database respectively replay the data write log to write the target data.
[0017] In one embodiment of this disclosure, the apparatus further includes a response module, configured to: determine that the target data has been successfully written to the primary database in response to receiving a write confirmation message returned by a first preset number of replicas among other replicas of the primary database within a preset time period; determine that the target data has been successfully written to the backup database in response to receiving a write confirmation message returned by a second preset number of replicas among a plurality of replicas of the backup database within a preset time period; and return a write success message to the client in response to the successful writing of the target data in both the primary and backup databases.
[0018] In one embodiment of this disclosure, the device further includes an adjustment module for: adjusting the first preset quantity and / or the second preset quantity according to an adjustment instruction.
[0019] In one embodiment of this disclosure, the apparatus further includes a master database election module, configured to: send a leader election request to other replicas by at least one replica of the master database; each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; and determine that any replica of the master database is the leader replica based on the number or proportion of leader response messages received that satisfy the leader election criteria.
[0020] According to a third aspect of one or more embodiments of this disclosure, a data management apparatus based on a fast synchronization mechanism is proposed, applied to a backup database in a data system, the data system further including a primary database. The apparatus includes: a receiving module, configured to receive a data write log sent by the leader of the primary database, and replay the data write log to write the target data indicated by the data write log to the backup database; wherein the data write log is generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and is sent to other replicas of the primary database and the backup database.
[0021] In one embodiment of this disclosure, the receiving module is configured to: receive a data write log sent by the leader of the primary database for each replica of the standby database, and replay the data write log to write the target data indicated by the data write log to the replica; wherein the data write log is generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and is sent to the other replicas of the primary database and each replica of the standby database.
[0022] In one embodiment of this disclosure, the apparatus further includes a return module, configured to: each replica of the backup database returns a write confirmation message to the leader replica of the primary database when the target data is successfully written, so that the leader replica of the primary database determines that the target data has been successfully written to the backup database in response to receiving a second preset number of write confirmation messages from multiple replicas of the backup database within a preset time period.
[0023] In one embodiment of this disclosure, the apparatus further includes a backup database election module, configured to: send a leader election request from at least one replica of the backup database to other replicas; each replica of the backup database returns a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; and determine that any replica of the backup database is the leader replica based on the number or proportion of leader response messages received that satisfy the leader election criteria.
[0024] According to a fifth aspect of one or more embodiments of the present disclosure, a computer program product is provided, comprising a computer program / instructions that, when executed by a processor, implement the steps of the method described in the first or second aspect.
[0025] According to a sixth aspect of one or more embodiments of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor executes the executable instructions to implement the method as described in the first or second aspect.
[0026] According to a seventh aspect of one or more embodiments of the present disclosure, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the steps of the method as described in the first or second aspect.
[0027] The technical solutions provided by the embodiments of this disclosure can include the following beneficial effects: The data management method provided by the embodiments of this disclosure allows the primary database of a data system to receive a data write request sent by a client and write the target data indicated by the data write request into the leader replica of the primary database; then, the data write log generated by writing the target data is sent to other replicas and backup databases of the primary database, so that the other replicas and backup databases of the primary database can replay the data write log to write the target data. Since the leader replica of the primary database synchronizes the data write log to other replicas and backup databases of the primary database simultaneously after completing the writing of the target data and generating the data write log, compared to the related technology where the leader replica synchronizes the target data to other replicas of the primary database through the data write log and then synchronizes it to the backup database, this method can improve the efficiency of synchronizing the target data to the backup database, reduce the latency of data synchronization between the primary and backup databases, and improve the writing efficiency of data in a distributed database containing the primary and backup databases. Attached Figure Description
[0028] Figure 1 is a structural diagram of a data system provided in an exemplary embodiment.
[0029] Figure 2 is a structural diagram of the main library provided in an exemplary embodiment.
[0030] Figure 3 is a structural diagram of a backup library provided in an exemplary embodiment.
[0031] Figure 4 is a flowchart of a data management method based on a fast synchronization mechanism applied to a master database, provided by an exemplary embodiment.
[0032] Figure 5 is a schematic diagram of the process of writing data within a data system provided by an exemplary embodiment.
[0033] Figure 6 is a schematic diagram illustrating the latency of writing data in a distributed database containing a master database and a standby database in related technologies.
[0034] Figure 7 is a schematic diagram illustrating the latency of writing data in a distributed database containing a master database and a standby database, provided by an exemplary embodiment.
[0035] Figure 8 is a schematic diagram of the structure of a device provided in an exemplary embodiment.
[0036] Figure 9 is a block diagram of a data management device based on a fast synchronization mechanism applied to a master database, provided in an exemplary embodiment. Detailed Implementation
[0037] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of this disclosure as detailed in the appended claims.
[0038] It should be noted that the steps of the corresponding methods are not necessarily performed in the order shown and described in this disclosure in other embodiments. In some other embodiments, the methods may include more or fewer steps than those described in this disclosure. Furthermore, a single step described in this disclosure may be broken down into multiple steps in other embodiments; and multiple steps described in this disclosure may be combined into a single step in other embodiments.
[0039] In today's era of rapid development in the internet and information technology, data generation is exploding, thus placing increasingly higher demands on databases and their management. Current distributed databases often address temporary failures by setting up primary and standby databases. This means that if the primary database fails, the standby database can take over as the primary and continue providing services, thereby avoiding service interruptions and ensuring service quality and efficiency.
[0040] Generally, in a distributed database, the primary database provides write services, while the secondary database is used for backup. In related technologies, writing data to a distributed database containing both a primary and secondary database is inefficient, resulting in poor quality of service. For example, when writing data to a distributed database containing a primary and secondary database, the data is often first written to the leader replica of the primary database. Then, the data written to the leader replica is synchronized to the other replicas of the primary database. Only after successful synchronization is the data synchronized to the secondary database, resulting in high latency in data synchronization between the primary and secondary databases.
[0041] Based on this, in a first aspect, at least one embodiment of this disclosure provides a data management method based on a fast synchronization mechanism. This method can reduce the data synchronization delay between the master and slave databases when writing data to a distributed database that includes a master database and a slave database, thereby improving the data writing efficiency and thus improving the service quality of the distributed database.
[0042] This method can be applied to the distributed data system shown in Figure 1, which includes a primary database A and a secondary database B. It should be understood that the primary and secondary roles of databases A and B are not static; they can be assigned and switched through a distributed consensus protocol. For example, database A always assumes the primary role under normal conditions, while database B assumes the secondary role. However, if database A malfunctions, it relinquishes its primary role, and database B becomes the new primary. In other words, the primary role of database A is persistent, while the primary role of database B is temporary. Another example is that databases A and B can randomly assume the primary and secondary roles, for instance, by adding arbitrator nodes to form a distributed consensus protocol member group. Within this group, the primary database is elected and switched between databases A and B.
[0043] The primary database A can be a database cluster containing multiple partitions, each containing multiple replicas, namely leader replicas and regular replicas. For example, the primary database A shown in Figure 2 has only one partition, and this partition includes three replicas: R1, R2, and R3, with replica R1 being the leader replica. Similarly, the standby database can be a database cluster containing multiple partitions, each containing multiple replicas, namely leader replicas and regular replicas. For example, the standby database B shown in Figure 3 has only one partition, and this partition includes three replicas: R4, R5, and R6, with replica R4 being the leader replica.
[0044] This method can be implemented by the primary database and the standby database within the data system. The following sections will provide a detailed introduction to this method from both the primary and standby database perspectives.
[0045] Please refer to Figure 4, which exemplarily illustrates the flow of a data management method applied to the master database side, including steps S401 to S402.
[0046] In step S401, in response to receiving a data write request sent by the client, the target data indicated by the data write request is written into the leader replica of the master database, and a data write log is generated.
[0047] The data write request instructs the data system to write target data. This request is received and processed by the primary database, for example, by the leader replica of the primary database. It should be understood that if the data system has system partitions and user partitions, the data write request needs to be assigned to the leader replica of the corresponding partition to perform the data write.
[0048] For example, the leader replica of the primary database can be elected in advance in the following manner.
[0049] First, at least one replica (preferably each replica) of the primary database sends a leader election request to the other replicas.
[0050] Next, each replica of the primary database returns a leader response message to the replica with the highest number among the replicas to which at least one leader election request belongs.
[0051] Finally, if any replica of the primary database receives a number or proportion of leader response messages that meet the leader election criteria, that replica is determined to be the leader replica. This replica can also broadcast its election as the leader replica to every replica of the primary database.
[0052] For example, in Figure 2, replicas R1, R2, and R3 of primary database A send leader election requests to other replicas. Replica R1 votes for itself and sends a leader response message. Replica R2 votes for replica R1 and sends a leader response message. Replica R3 votes for replica R1 and sends a leader response message. Thus, replica R1 becomes the leader replica because it receives leader response messages from at least two replicas, and broadcasts its election as the leader replica to replicas R1, R2, and R3.
[0053] It should be understood that if the data system has system partitions and user partitions, then each partition elects a leader replica in the manner provided in the example above.
[0054] In step S402, the data write log is sent to the other replicas of the primary database and the standby database, respectively, so that the other replicas of the primary database and the standby database replay the data write log to write the target data. For example, the leader replica of the primary database sends the data write log to the other replicas of the primary database and the standby database, respectively.
[0055] For example, the data write log is sent to other replicas of the primary database and multiple replicas of the standby database (e.g., each replica), so that the other replicas of the primary database and multiple replicas of the standby database replay the data write log to write the target data. Please refer to Figure 5, which shows the process of writing target data according to this example in a data system consisting of the primary database shown in Figure 2 and the standby database shown in Figure 3: First, replica R1 writes the target data and generates a data write log. Then, replica R1 simultaneously sends the data write log to replicas R2, R3, R4, R5, and R6.
[0056] It should be understood that after the target data has been successfully written to both the primary and standby databases, the leader replica of the primary database can return a write success message to the client.
[0057] Please refer to Figure 6, which shows the latency diagram for writing data in a distributed database containing a primary and secondary database in the related technology, and Figure 7, which shows the latency diagram for writing data in a distributed database containing a primary and secondary database in this application. If the latency of a single information transfer between replicas is L, then the latency for writing data in a distributed database containing a primary and secondary database in the related technology is 6L, while the latency for writing data in a distributed database containing a primary and secondary database in this application is 2L. It can be seen that the latency has been reduced.
[0058] The data management method provided in this disclosure allows the primary database of a data system to receive data write requests sent by clients and write the target data indicated by the data write request into the leader replica of the primary database. Then, the data write log generated from writing the target data is sent to other replicas and backup databases of the primary database, so that the other replicas and backup databases can replay the data write logs to write the target data. Since the leader replica of the primary database synchronizes the data write log to other replicas and backup databases simultaneously after completing the writing of the target data and generating the data write log, compared to the related technology where the leader replica synchronizes the target data to other replicas of the primary database via the data write log and then to the backup database, this method improves the efficiency of synchronizing the target data to the backup database, reduces the latency of data synchronization between the primary and backup databases, and improves the writing efficiency of data in a distributed database containing primary and backup databases.
[0059] In some embodiments of this disclosure, the primary database determines that the target data has been successfully written only when the leader replica and at least a first preset number of ordinary replicas within the primary database have all successfully written the target data. That is, if the primary database has m replicas, the target data is determined to have been successfully written to the primary database only when the target data is successfully written to Q(m) replicas (Q(m) is the first preset number + 1). Then its internal member group information can be [database ID, primary database, (replica list), m, Q(m)]; for example, as shown in Figure 2, primary database A has 3 replicas and Q(m) is 2. Then its internal member group information can be [A, primary database, (R1, R2, R3), 3, 2].
[0060] The target data is considered successfully written to the standby database only when at least a second preset number of replicas in the standby database are successfully written to the target data. That is, if standby database B has n replicas, the target data is considered successfully written to the standby database only when the target data is successfully written to Q(n) replicas. Then its internal member group information can be [database ID, standby database, (replica list), n, Q(n)]; for example, as shown in Figure 3, standby database B has 3 replicas and Q(n) is 2. Then its internal member group information can be [B, standby database, (R4, R5, R6), 3, 2].
[0061] It should be understood that after receiving data write logs from the leader replica of the primary database, other replicas will write the target data into their own replicas by replaying the data write logs, and return a write confirmation message to the leader replica of the primary database upon successful writing. Similarly, after receiving data write logs from the leader replica of the primary database, standby replicas will write the target data into their own replicas by replaying the data write logs, and return a write confirmation message to the leader replica of the primary database upon successful writing.
[0062] Based on this, (the leader replica of the primary database) can determine that the target data has been successfully written to the primary database in response to receiving a write confirmation message from a first preset number of replicas among the other replicas of the primary database within a preset time period; determine that the target data has been successfully written to the standby database in response to receiving a write confirmation message from a second preset number of replicas among the multiple replicas of the standby database within a preset time period; and return a write success message to the client in response to the successful writing of the target data in both the primary and standby databases.
[0063] Additionally, the first preset quantity and / or the second preset quantity can be adjusted according to control commands. For example, when the number of replicas in the primary or standby database changes, the data system's maintenance personnel can input adjustment commands to change the first preset quantity and / or the second preset quantity. As another example, the data system can automatically identify primary or standby database anomalies and automatically generate adjustment commands to change the first preset quantity and / or the second preset quantity, so that if a primary or standby database anomaly causes the data system to be unable to provide services, the data system can provide these services.
[0064] In this embodiment, the target data is only considered successfully written to the distributed database when the primary database successfully writes the target data to multiple replicas of the primary database and multiple replicas of the backup database. This increases the security and reliability of the target data, resulting in more data backups and preventing data from becoming unrecoverable due to backup loss.
[0065] The data management method applied to the standby database includes the following process: receiving the data write log sent by the leader of the primary database, and replaying the data write log to write the target data indicated by the data write log to the standby database; wherein, the data write log is generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and then sending it to the other replicas of the primary database and the standby database.
[0066] In one embodiment of this disclosure, receiving the data write log sent by the leader of the primary database and replaying the data write log to write the target data indicated by the data write log to the backup database may include: each replica of the backup database receiving the data write log sent by the leader of the primary database and replaying the data write log to write the target data indicated by the data write log to the replica; wherein the data write log is generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and is sent to the other replicas of the primary database and each replica of the backup database.
[0067] In one embodiment of this disclosure, the method may further include: each replica of the backup database returning a write confirmation message to the leader replica of the primary database when the target data is successfully written, so that the leader replica of the primary database determines that the target data has been successfully written to the backup database in response to receiving a second preset number of write confirmation messages from multiple replicas of the backup database within a preset time period.
[0068] In one embodiment of this disclosure, the method further includes the following leader replica election process: First, at least one replica of the backup database sends a leader election request to other replicas; next, each replica of the backup database returns a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; finally, if the number or proportion of leader response messages received by any replica of the backup database meets the leader election criteria, that replica is determined to be the leader replica.
[0069] For example, in Figure 3, replicas R4, R5, and R6 of primary database B send leader election requests to other replicas. Replica R4 votes for itself and sends a leader response message. Replica R5 votes for replica R4 and sends a leader response message. Replica R6 votes for replica R4 and sends a leader response message. Thus, replica R4 becomes the leader replica because it receives leader response messages from at least two replicas, and broadcasts its election as the leader replica to replicas R4, R5, and R6.
[0070] It should be understood that if the data system has system partitions and user partitions, then each partition elects a leader replica in the manner provided in the example above.
[0071] Figure 8 is a schematic structural diagram of a device provided in an exemplary embodiment. Referring to Figure 8, at the hardware level, the device includes a processor 802, an internal bus 804, a network interface 806, a memory 808, and a non-volatile memory 810, and may also include other hardware required for tasks. One or more embodiments of this disclosure can be implemented in software, for example, the processor 802 reads the corresponding computer program from the non-volatile memory 810 into the memory 808 and then runs it. Of course, in addition to software implementation, one or more embodiments of this disclosure do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0072] Please refer to Figure 9. The data management device based on the fast synchronization mechanism can be applied to the device shown in Figure 8 to implement the technical solution of this disclosure. The data management device can be applied to the primary database in a data system, which also includes a backup database. The device includes: a write module 901, used to respond to a data write request sent by a client, write the target data indicated by the data write request to the leader replica of the primary database, and generate a data write log; and a synchronization module 902, used to send the data write log to other replicas of the primary database and the backup database respectively, so that the other replicas of the primary database and the backup database respectively replay the data write log to write the target data.
[0073] In one embodiment of this disclosure, the synchronization module is configured to: send the data write log to other replicas of the primary database and multiple replicas of the backup database respectively, so that the other replicas of the primary database and multiple replicas of the backup database respectively replay the data write log to write the target data.
[0074] In one embodiment of this disclosure, the apparatus further includes a response module, configured to: determine that the target data has been successfully written to the primary database in response to receiving a write confirmation message returned by a first preset number of replicas among other replicas of the primary database within a preset time period; determine that the target data has been successfully written to the backup database in response to receiving a write confirmation message returned by a second preset number of replicas among a plurality of replicas of the backup database within a preset time period; and return a write success message to the client in response to the successful writing of the target data in both the primary and backup databases.
[0075] In one embodiment of this disclosure, the device further includes an adjustment module for: adjusting the first preset quantity and / or the second preset quantity according to an adjustment instruction.
[0076] In one embodiment of this disclosure, the apparatus further includes a master database election module, configured to: send a leader election request to other replicas by at least one replica of the master database; each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; and determine that any replica of the master database is the leader replica based on the number or proportion of leader response messages received that satisfy the leader election criteria.
[0077] The data management device based on the fast synchronization mechanism can be applied to the device shown in Figure 8 to implement the technical solution of this disclosure. Specifically, the data management device can be applied to a backup database in a data system, which also includes a primary database. The device includes a receiving module for receiving data write logs sent by the leader of the primary database and replaying the data write logs to write the target data indicated by the data write logs to the backup database. The data write logs are generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and then sent to other replicas of the primary database and the backup database.
[0078] In one embodiment of this disclosure, the receiving module is configured to: receive a data write log sent by the leader of the primary database for each replica of the standby database, and replay the data write log to write the target data indicated by the data write log to the replica; wherein the data write log is generated by the primary database after writing the target data indicated by the data write request sent by the client into the leader replica of the primary database, and is sent to the other replicas of the primary database and each replica of the standby database.
[0079] In one embodiment of this disclosure, the apparatus further includes a return module, configured to: each replica of the backup database returns a write confirmation message to the leader replica of the primary database when the target data is successfully written, so that the leader replica of the primary database determines that the target data has been successfully written to the backup database in response to receiving a second preset number of write confirmation messages from multiple replicas of the backup database within a preset time period.
[0080] In one embodiment of this disclosure, the apparatus further includes a backup database election module, configured to: send a leader election request from at least one replica of the backup database to other replicas; each replica of the backup database returns a leader response message to the replica with the largest number among the replicas to which the received at least one leader election request belongs; and determine that any replica of the backup database is the leader replica based on the number or proportion of leader response messages received that satisfy the leader election criteria.
[0081] One or more embodiments of this disclosure also provide a computer program product including a computer program / instructions that, when executed by a processor, implement the steps of the method described in the first or second aspect.
[0082] One or more embodiments of this disclosure also provide a computer-readable storage medium having computer instructions stored thereon that, when executed by a processor, implement the steps of the method as described in the first or second aspect.
[0083] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which can take the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.
[0084] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0085] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0086] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0087] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0088] The foregoing has described specific embodiments of this disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0089] The terminology used in one or more embodiments of this disclosure is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this disclosure. The singular forms “a,” “the,” and “the” used in one or more embodiments of this disclosure and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0090] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0091] It should be understood that although the terms first, second, third, etc., may be used to describe various information in one or more embodiments of this disclosure, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first information may also be referred to as second information without departing from the scope of one or more embodiments of this disclosure, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."
[0092] The above description is merely a preferred embodiment of one or more embodiments of this disclosure and is not intended to limit the scope of one or more embodiments of this disclosure. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this disclosure should be included within the scope of protection of one or more embodiments of this disclosure.
Claims
1. A data management method based on a fast synchronization mechanism, applied to a master in a data system, the data system further comprising a backup, the method comprising: in response to receiving a data write request sent by a client, writing target data indicated by the data write request in a leader replica of the master, and generating a data write log; and sending the data write log to other replicas of the master and the backup, respectively, so that the other replicas of the master and the backup replay the data write log, respectively, to write the target data. 2.The data management method based on the fast synchronization mechanism of claim 1, wherein the sending the data write log to the other replicas of the master and the backup, respectively, so that the other replicas of the master and the backup replay the data write log, respectively, to write the target data comprises: sending the data write log to multiple replicas of the backup and the other replicas of the master, respectively, so that the multiple replicas of the backup and the other replicas of the master replay the data write log, respectively, to write the target data. 3.The data management method based on the fast synchronization mechanism of claim 2, further comprising: in response to receiving write acknowledgement messages returned by a first preset number of replicas of the other replicas of the master within a preset time length, determining that the target data is successfully written in the master; in response to receiving write acknowledgement messages returned by a second preset number of replicas of the multiple replicas of the backup within a preset time length, determining that the target data is successfully written in the backup; and in response to the target data being successfully written in the master and the target data being successfully written in the backup, returning a write success message to the client. 4.The data management method based on the fast synchronization mechanism of claim 3, further comprising: adjusting the first preset number and / or the second preset number according to an adjustment instruction. 5.The data management method based on the fast synchronization mechanism of claim 1, further comprising: sending, by at least one replica of the master, a leader election request to other replicas; returning, by each replica of the master, a leader response message to a replica with the largest number among replicas to which at least one leader election request received by the replica belongs; and determining, by any replica of the master, that the replica is a leader replica in response to the number or proportion of leader response messages received by the replica satisfying a leader election condition. 6.A data management method based on a fast synchronization mechanism, applied to a backup in a data system, the data system further comprising a master, the method comprising: receiving a data write log sent by a leader of the master, and replaying the data write log to write target data indicated by the data write log in the backup; wherein the data write log is generated by the master after writing target data indicated by a data write request sent by a client in a leader replica of the master, and is sent to other replicas of the master and the backup. 7. The data management method based on the fast synchronization mechanism according to claim 6, wherein the receiving the data write log sent by the leader of the master database and replaying the data write log to write the target data indicated by the data write log into the backup database comprises: each copy of the backup database receiving the data write log sent by the leader of the master database and replaying the data write log to write the target data indicated by the data write log into the copy; wherein the data write log is generated by the master database after the target data indicated by the data write request sent by the client is written into the leader copy of the master database, and is sent to other copies of the master database and each copy of the backup database.
8. The data management method based on the fast synchronization mechanism according to claim 7, further comprising: each copy of the backup database returning a write confirmation message to the leader copy of the master database when the target data is successfully written, so that the leader copy of the master database determines that the target data is successfully written into the backup database in response to receiving the write confirmation messages returned by a second preset number of copies among the plurality of copies of the backup database within a preset time length.
9. The data management method based on the fast synchronization mechanism according to claim 6, further comprising: at least one copy of the backup database sending a leader election request to other copies; each copy of the backup database returning a leader response message to the copy with the largest copy number among the copies to which the received at least one leader election request belongs; any copy of the backup database determining that the copy is a leader copy when the number or proportion of leader response messages received by the copy satisfies a leader election condition.
10. A data management apparatus based on a fast synchronization mechanism, applied to a master database in a data system, the data system further comprising a backup database, the apparatus comprising: a write module configured to write target data indicated by a data write request sent by a client into a leader copy of the master database in response to receiving the data write request, and generate a data write log; a synchronization module configured to send the data write log to other copies of the master database and the backup database respectively, so that the other copies of the master database and the backup database replay the data write log respectively to write the target data.
11. A data management apparatus based on a fast synchronization mechanism, applied to a backup database in a data system, the data system further comprising a master database, the apparatus comprising: a receiving module configured to receive a data write log sent by a leader of the master database, and replay the data write log to write target data indicated by the data write log into the backup database; wherein the data write log is generated by the master database after the target data indicated by a data write request sent by the client is written into the leader copy of the master database, and is sent to other copies of the master database and the backup database.
12. A computer program product comprising computer programs / instructions which, when executed by a processor, implement the steps of the method of any one of claims 1 to 9.
13. An electronic device comprising: a processor; a memory for storing processor-executable instructions; wherein the processor, by running the executable instructions, implements the method of any one of claims 1 to 9.
14. A computer-readable storage medium having stored thereon computer instructions which, when executed by a processor, implement the steps of the method of any one of claims 1 to 9.
Citation Information
Patent Citations
Data replication method and device
CN113821362A
Transaction processing method and device, node equipment and storage medium
CN115098229A
Data processing method and device for distributed database
CN115658811A
Data processing method and device
CN116401314A
Data management method and device based on fast synchronization mechanism
CN118535646A