Data management method and device based on fast synchronization mechanism
By adopting a fast synchronization mechanism in the distributed database, the data written in the log is synchronized to the main database and the standby database at the same time, which solves the problem of data synchronization delay between the main database and the standby database, and improves the writing efficiency and performance of the distributed database. Quality of service.
Patent Information
- Application Number
- CN202410705398.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-08-23
AI Technical Summary
In a distributed database, the data writing efficiency between the primary database and the standby database is low, resulting in poor service quality. This is mainly due to the high delay in synchronizing data from the primary database to the standby database.
Using a data management method based on the fast synchronization mechanism, after receiving the write request from the client, the main database generates a data write log and sends it to other copies of the main database and the standby database at the same time to ensure that the data is between the main database and the standby database. The synchronization efficiency is improved.
It reduces the data synchronization delay between the main database and the standby database, and improves the writing efficiency and service quality of the distributed database.
Smart Images

Figure CN118535646A
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a data management method and device based on a fast synchronization mechanism. Background Art
[0002] With the rapid development of the Internet and informatization, the generation of data is growing explosively, so the requirements for databases and their management are getting higher and higher. At present, distributed databases often deal with temporary failures by setting up master and backup databases. That is, when the master database fails, the backup database can switch to the master database to continue providing services, thus avoiding the service stoppage when the database fails and affecting the service quality and efficiency.
[0003] Generally speaking, the main database of a distributed database provides external write services, and the backup database is used to back up data. In the related art, the efficiency of writing data in a distributed database including a main database and a backup database is low, resulting in poor database service quality. Summary of the invention
[0004] In view of this, one or more embodiments of the present specification provide a data management method and device based on a fast synchronization mechanism.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a data management method based on a fast synchronization mechanism is proposed, the method is applied to a master database in a data system, the data system also includes a standby database, the method includes:
[0007] In response to receiving a data write request sent by a client, writing the target data indicated by the data write request in the leader copy of the master database, and generating a data write log;
[0008] The data write log is sent to other replicas of the primary library and the standby library respectively, so that the other replicas of the primary library and the standby library respectively replay the data write log to write the target data.
[0009] In one embodiment of the present specification, sending the data write log to other replicas of the primary library and the standby library respectively so that the other replicas of the primary library and the standby library respectively replay the data write log to write the target data includes:
[0010] The data write log is sent to other replicas of the primary library and multiple replicas of the backup library respectively, so that the other replicas of the primary library and multiple replicas of the backup library respectively replay the data write log to write the target data.
[0011] In one embodiment of the present specification, the method further includes:
[0012] In response to receiving write confirmation messages returned by a first preset number of replicas in other replicas of the master database within a preset time period, determining that the target data is successfully written into the master database;
[0013] In response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time period, determining that the target data is successfully written into the standby database;
[0014] In response to the target data being successfully written into the primary database and the target data being successfully written into the standby database, a write success message is returned to the client.
[0015] In one embodiment of the present specification, the method further includes:
[0016] The first preset number and / or the second preset number are adjusted according to the adjustment instruction.
[0017] In one embodiment of the present specification, the method further includes:
[0018] At least one replica of the master database sends a leader election request to other replicas;
[0019] Each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0020] If the number or proportion of leader response messages received by any replica of the master database meets the leader election condition, the replica is determined to be the leader replica.
[0021] According to a second aspect of one or more embodiments of this specification, a data management method based on a fast synchronization mechanism is proposed, which is applied to a backup database in a data system, wherein the data system also includes a primary database. The method includes:
[0022] Receive the 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 into the standby database;
[0023] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and the standby database.
[0024] In one embodiment of the present specification, the 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 standby database includes:
[0025] Each replica of the standby database receives the data write log sent by the leader of the primary database, and replays the data write log to write the target data indicated by the data write log into the replica;
[0026] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and each copy of the standby database.
[0027] In one embodiment of the present specification, the method further includes:
[0028] Each replica of the standby 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 is successfully written in the standby database in response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time length.
[0029] In one embodiment of the present specification, the method further includes:
[0030] At least one replica of the standby database sends a leader election request to other replicas;
[0031] Each replica of the standby database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0032] If the number or proportion of leader response messages received by any replica of the standby database meets the leader election condition, the replica is determined to be the leader replica.
[0033] According to a third aspect of one or more embodiments of this specification, a data management device based on a fast synchronization mechanism is provided, which is applied to a main database in a data system, wherein the data system also includes a backup database, and the device includes:
[0034] A writing module, configured to, in response to receiving a data writing request sent by a client, write the target data indicated by the data writing request into the leader copy of the master database, and generate a data writing log;
[0035] The synchronization module is used to send the data write log to other copies of the primary library and the standby library respectively, so that the other copies of the primary library and the standby library respectively replay the data write log to write the target data.
[0036] In one embodiment of the present specification, the synchronization module is used to:
[0037] The data write log is sent to other replicas of the primary library and multiple replicas of the standby library respectively, so that the other replicas of the primary library and multiple replicas of the standby library respectively replay the data write log to write the target data.
[0038] In one embodiment of the present specification, the device further includes a response module, configured to:
[0039] In response to receiving write confirmation messages returned by a first preset number of replicas in other replicas of the master database within a preset time period, determining that the target data is successfully written into the master database;
[0040] In response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time period, determining that the target data is successfully written into the standby database;
[0041] In response to the target data being successfully written into the primary database and the target data being successfully written into the standby database, a write success message is returned to the client.
[0042] In one embodiment of the present specification, the device further includes an adjustment module, which is used to:
[0043] The first preset number and / or the second preset number are adjusted according to the adjustment instruction.
[0044] In one embodiment of the present specification, the device further includes a master library election module, which is used to:
[0045] At least one replica of the master database sends a leader election request to other replicas;
[0046] Each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0047] If the number or proportion of leader response messages received by any replica of the master database meets the leader election condition, the replica is determined to be the leader replica.
[0048] According to a third aspect of one or more embodiments of this specification, a data management device based on a fast synchronization mechanism is provided, which is applied to a backup database in a data system, wherein the data system also includes a primary database, and the device includes:
[0049] A receiving module, used 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 into the standby database;
[0050] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and the standby database.
[0051] In one embodiment of this specification, the receiving module is used to:
[0052] Each replica of the standby database receives the data write log sent by the leader of the primary database, and replays the data write log to write the target data indicated by the data write log into the replica;
[0053] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and each copy of the standby database.
[0054] In one embodiment of the present specification, the device further comprises a return module, which is used to:
[0055] Each replica of the standby 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 is successfully written in the standby database in response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time length.
[0056] In one embodiment of the present specification, the device further includes a standby database election module, which is used to:
[0057] At least one replica of the standby database sends a leader election request to other replicas;
[0058] Each replica of the standby database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0059] If the number or proportion of leader response messages received by any replica of the standby database meets the leader election condition, the replica is determined to be the leader replica.
[0060] According to a fifth aspect of one or more embodiments of this specification, a computer program product is proposed, comprising a computer program / instruction, which implements the steps of the method described in the first aspect or the second aspect when executed by a processor.
[0061] According to a sixth aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0062] processor;
[0063] a memory for storing processor-executable instructions;
[0064] The processor implements the method as described in the first aspect or the second aspect by running the executable instructions.
[0065] According to a seventh aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect or the second aspect are implemented.
[0066] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0067] The data management method provided in the embodiments of this specification is that the master database of the data system can receive a data write request sent by a client, and write the target data indicated by the data write request in the leader copy of the master database; then send the data write log generated by writing the target data 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 can replay the data write log respectively to write the target data. Since the leader copy of the master database synchronizes the data write log to other copies of the master database and the backup database at the same time after completing the writing of the target data and generating the data write log, compared with the method in the related art that the leader copy synchronizes the target data to other copies of the master database through the data write log and then synchronizes it to the backup database, the efficiency of synchronizing the target data to the backup database can be improved, the delay time of data synchronization between the master and backup databases can be reduced, and the writing efficiency of data in the distributed database including the master and backup databases can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 is a structural diagram of a data system provided by an exemplary embodiment.
[0069] Figure 2 It is a structural diagram of a main library provided by an exemplary embodiment.
[0070] Figure 3 It is a structural diagram of a standby database provided by an exemplary embodiment.
[0071] Figure 4 The figure is a flowchart of a data management method based on a fast synchronization mechanism and applied to a main database provided by an exemplary embodiment.
[0072] Figure 5 It is a schematic diagram of a flow chart of writing data into a data system provided by an exemplary embodiment.
[0073] Figure 6 This is a schematic diagram of the delay of writing data in a distributed database including a master database and a backup database in the related art.
[0074] Figure 7 The diagram is a delay diagram of writing data in a distributed database including a primary database and a backup database, provided by an exemplary embodiment.
[0075] Figure 8 It is a structural schematic diagram of a device provided by an exemplary embodiment.
[0076] Fig. 9 It is a block diagram of a data management device based on a fast synchronization mechanism and applied to a main library provided by an exemplary embodiment. DETAILED DESCRIPTION
[0077] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0078] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0079] With the rapid development of the Internet and informatization, the generation of data is growing explosively, so the requirements for databases and their management are getting higher and higher. At present, distributed databases often deal with temporary failures by setting up master and backup databases. That is, when the master database fails, the backup database can switch to the master database to continue providing services, thus avoiding the service stoppage when the database fails and affecting the service quality and efficiency.
[0080] Generally speaking, the main database of a distributed database provides write services to the outside world, and the backup database is used to back up data. In the related art, the efficiency of writing data in a distributed database including a main database and a backup database is low, resulting in poor database service quality. For example, in the related art, when writing data to a distributed database including a main database and a backup database, the data is often first written to the leader copy of the main database, and then the data written in the leader copy is synchronized to other copies of the main database. After the synchronization is successful, the above data is synchronized to the backup database, and the delay in data synchronization between the main and backup databases is high.
[0081] Based on this, on the first aspect, at least one embodiment of this specification provides a data management method based on a fast synchronization mechanism, which can reduce the data synchronization delay between the primary and backup databases when writing data to a distributed database containing a primary database and a backup database, improve data writing efficiency, and thereby improve the service quality of the distributed database.
[0082] This method can be applied to Figure 1 The distributed data system shown includes a main database A and a backup database B. It should be understood that the main and backup database roles of database A and database B are not fixed, and the allocation and switching of the main and backup database roles can be completed by running a distributed consensus protocol. Exemplarily, database A always assumes the role of the main database under normal conditions, while database B assumes the role of the backup database. Once database A is abnormal, it abandons the role of the main database and makes database B the main database; in other words, the main database role of database A is persistent, while the main database role of database B is temporary. Another exemplary example is that database A and database B randomly assume the roles of the main database and the backup database, for example, by adding arbitration nodes to form a distributed consensus protocol member group, and the member group elects the main database and switches the main database in database A and database B.
[0083] The master database A may be in the form of a database cluster, which contains multiple partitions, each partition containing multiple replicas, namely, leader replicas and common replicas. Figure 2 The main database A shown has only one partition, and the partition includes three replicas, namely, replica R1, replica R2 and replica R3, and the leader replica is replica R1. Similarly, the standby database can be in the form of a database cluster, which contains multiple partitions, and each partition contains multiple replicas, namely, leader replicas and ordinary replicas. Figure 3 The standby database B shown has only one partition, and the partition includes three replicas, namely, replica R4, replica R5 and replica R6, and the leader replica is replica R4.
[0084] This method can be completed by the main database and the standby database in the data system. Next, the method is introduced in detail from both the main database and the standby database sides.
[0085] Please refer to the attached Figure 4 , which exemplarily shows the process of the data management method applied to the main database side, including steps S401 to S402.
[0086] In step S401, in response to receiving a data write request sent by a client, the target data indicated by the data write request is written into the leader copy of the master database, and a data write log is generated.
[0087] The data write request is used to instruct the data system to write the target data. The data write request is received and processed by the master database, for example, by the leader replica of the master database to write the data. It should be understood that if the data system has a system partition and a user partition, the data write request needs to be assigned to the leader replica of the corresponding partition to execute the data write.
[0088] For example, the replicas of the leader of the master database can be pre-elected in the following way:
[0089] First, at least one replica of the master library (preferably each replica) sends a leader election request to other replicas.
[0090] Next, each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request received belongs.
[0091] Finally, if the number or ratio of leader response messages received by any replica of the master database meets the leader election condition, the replica is determined to be the leader replica. The replica can also broadcast the information that it has been elected as the leader replica to each replica of the master database.
[0092] For example, Figure 2 As shown, replicas R1, R2, and R3 of the master database A send leader election requests to other replicas respectively. Replica R1 votes for itself by sending a leader response message, replica R2 votes for replica R1 by sending a leader response message, and replica R3 votes for replica R1 by sending a leader response message. Then, replica R1 takes office as the leader replica because it receives leader response messages sent by no less than 2 replicas, and at the same time broadcasts the information that it is elected as the leader replica to replicas R1, R2, and R3.
[0093] It should be understood that if the data system has system partitions and user partitions, each partition elects a leader replica in the manner provided in the above example.
[0094] In step S402, the data write log is sent to other replicas of the primary library and the standby library respectively, so that the other replicas of the primary library and the standby library respectively replay the data write log to write the target data. For example, the leader replica of the primary library sends the data write log to other replicas of the primary library and the standby library respectively.
[0095] Exemplarily, the data write log is sent to other replicas of the primary database and multiple replicas (e.g., each replica) of the backup database, 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. Figure 5 , which shows the attached Figure 2 The main library and attached Figure 3 The data system composed of the standby database shown in the figure writes the target data according to the process of this example: first, replica R1 writes the target data and generates a data write log, and then replica R1 sends the data write log to replicas R2, R3, R4, R5, and R6 at the same time.
[0096] It should be understood that after the target data is successfully written to both the primary database and the backup database, the leader copy of the primary database can return a write success message to the client.
[0097] Please refer to the attached Figure 6 The delay diagram and attached diagram of writing data in a distributed database including a master database and a standby database in the related technology shown in FIG. Figure 7 The delay diagram of writing data in the distributed database including the main database and the backup database of the present application is shown. If the delay of a single information transmission between replicas is L, the delay of writing data in the distributed database including the main database and the backup database in the related art is 6L, and the delay of writing data in the distributed database including the main database and the backup database of the present application is 2L. It can be seen that the delay is reduced.
[0098] The data management method provided in the embodiments of this specification is that the master database of the data system can receive a data write request sent by a client, and write the target data indicated by the data write request in the leader copy of the master database; then send the data write log generated by writing the target data 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 can replay the data write log respectively to write the target data. Since the leader copy of the master database synchronizes the data write log to other copies of the master database and the backup database at the same time after completing the writing of the target data and generating the data write log, compared with the method in the related art that the leader copy synchronizes the target data to other copies of the master database through the data write log and then synchronizes it to the backup database, the efficiency of synchronizing the target data to the backup database can be improved, the delay time of data synchronization between the master and backup databases can be reduced, and the writing efficiency of data in the distributed database including the master and backup databases can be improved.
[0099] In some embodiments of the present disclosure, the master database determines that the target data is successfully written only when the leader replica and the ordinary replicas of not less than the first preset number in the master database have successfully written the target data. That is, the master database has m replicas, and the target data is successfully written only when the target data is successfully written in Q(m) replicas (Q(m) is the first preset number + 1), then its internal member group information can be [database ID, master database, (replica list), m, Q(m)]; for example, Figure 2 It is shown that the main library A has 3 replicas, Q(m) is 2, then its internal member group information can be [A, main library, (R1, R2, R3), 3, 2].
[0100] The target data is successfully written into the standby database only when the target data is successfully written into the replicas of no less than the second preset number in the standby database. That is, standby database B has n replicas, and the target data is successfully written into the standby database only when the target data is successfully written into Q(n) replicas. Then its internal member group information can be [database ID, standby database, (replica list), n, Q(n)]; for example, Figure 3 It is shown that the standby database B has 3 replicas, Q(n) is 2, and its internal member group information can be [B, standby database, (R4, R5, R6), 3, 2].
[0101] It should be understood that after receiving the data write log sent by the leader copy of the master library, the other copies of the master library will write the target data into the copy by replaying the data write log, and return a write confirmation message to the leader copy of the master library after the write is successful. After receiving the data write log sent by the leader copy of the master library, the copy of the standby library will write the target data into the copy by replaying the data write log, and return a write confirmation message to the leader copy of the master library after the write is successful.
[0102] Based on this, (the leader copy of the primary database) can determine that the target data is successfully written in the primary database in response to write confirmation messages returned by a first preset number of copies among other copies of the primary database received within a preset time length; determine that the target data is successfully written in the standby database in response to write confirmation messages returned by a second preset number of copies among multiple copies of the standby database received within a preset time length; and return a write success message to the client in response to the target data being successfully written in the primary database and the target data being successfully written in the standby database.
[0103] In addition, the first preset number and / or the second preset number can also be adjusted according to the control instruction. For example, when the number of copies of the main library or the backup library changes, the operation and maintenance personnel of the data system input an adjustment instruction to change the first preset number and / or the second preset number. For another example, the data system automatically identifies the anomaly of the main library or the backup library, and automatically generates an adjustment instruction to change the first preset number and / or the second preset number, so that the anomaly of the main library or the backup library causes the data system to be unable to provide services to the outside.
[0104] In this embodiment, the target data is determined to be successfully written into the distributed database only when the main database successfully writes the target data to multiple copies of the main database and multiple copies of the backup database respectively, which can increase the security and reliability of the target data, thereby allowing more data backups and avoiding data unrecoverability due to backup loss.
[0105] The process of the data management method applied to the standby database includes:
[0106] Receive the 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 into the standby database;
[0107] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and the standby database.
[0108] In one embodiment of the present specification, the 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 into the standby database may include:
[0109] Each replica of the standby database receives the data write log sent by the leader of the primary database, and replays the data write log to write the target data indicated by the data write log into the replica;
[0110] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and each copy of the standby database.
[0111] In one embodiment of this specification, the method may further include:
[0112] Each replica of the standby 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 is successfully written in the standby database in response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time length.
[0113] In one embodiment of the present specification, the method further includes the following leader replica election process:
[0114] First, at least one replica of the standby database sends a leader election request to other replicas;
[0115] Next, each replica of the standby database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0116] Finally, if the number or proportion of leader response messages received by any replica of the standby database meets the leader election condition, the replica is determined to be the leader replica.
[0117] For example, Figure 3 As shown, replicas R4, R5, and R6 of the master database B send leader election requests to other replicas respectively. Replica R4 votes for itself by sending a leader response message, replica R5 votes for replica R4 by sending a leader response message, and replica R6 votes for replica R4 by sending a leader response message. Then, replica R4 takes office as the leader replica because it receives leader response messages sent by no less than 2 replicas, and at the same time broadcasts the information that it is elected as the leader replica to replicas R4, R5, and R6.
[0118] It should be understood that if the data system has system partitions and user partitions, each partition elects a leader replica in the manner provided in the above example.
[0119] Figure 8 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 8At 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 hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 802 reading the corresponding computer program from the non-volatile memory 810 into the memory 808 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0120] Please refer to Fig. 9 The data management device based on the fast synchronization mechanism can be applied to Figure 8 The device shown in the figure is used to implement the technical solution of this specification. The data management device can be applied to a main database in a data system, and the data system also includes a backup database. The device includes:
[0121] The writing module 901 is used to write the target data indicated by the data writing request in the leader copy of the master database in response to receiving the data writing request sent by the client, and generate a data writing log;
[0122] The synchronization module 902 is used to send the data write log to other replicas of the primary database and the standby database respectively, so that the other replicas of the primary database and the standby database respectively replay the data write log to write the target data.
[0123] In one embodiment of the present specification, the synchronization module is used to:
[0124] The data write log is sent to other replicas of the primary library and multiple replicas of the backup library respectively, so that the other replicas of the primary library and multiple replicas of the backup library respectively replay the data write log to write the target data.
[0125] In one embodiment of the present specification, the device further includes a response module, configured to:
[0126] In response to receiving write confirmation messages returned by a first preset number of replicas in other replicas of the master database within a preset time period, determining that the target data is successfully written into the master database;
[0127] In response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time period, determining that the target data is successfully written into the standby database;
[0128] In response to the target data being successfully written into the primary database and the target data being successfully written into the standby database, a write success message is returned to the client.
[0129] In one embodiment of the present specification, the device further includes an adjustment module, which is used to:
[0130] The first preset number and / or the second preset number are adjusted according to the adjustment instruction.
[0131] In one embodiment of the present specification, the device further includes a master library election module, which is used to:
[0132] At least one replica of the master database sends a leader election request to other replicas;
[0133] Each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0134] If the number or proportion of leader response messages received by any replica of the master database meets the leader election condition, the replica is determined to be the leader replica.
[0135] The data management device based on the fast synchronization mechanism can be applied to Figure 8 The device shown in the figure is used to implement the technical solution of this specification. The data management device can be applied to a backup database in a data system, and the data system also includes a main database. The device includes:
[0136] A receiving module, used 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 into the standby database;
[0137] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and the standby database.
[0138] In one embodiment of this specification, the receiving module is used to:
[0139] Each replica of the standby database receives the data write log sent by the leader of the primary database, and replays the data write log to write the target data indicated by the data write log into the replica;
[0140] The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and each copy of the standby database.
[0141] In one embodiment of the present specification, the device further comprises a return module, which is used to:
[0142] Each replica of the standby 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 is successfully written in the standby database in response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time length.
[0143] In one embodiment of the present specification, the device further includes a standby database election module, which is used to:
[0144] At least one replica of the standby database sends a leader election request to other replicas;
[0145] Each replica of the standby database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received;
[0146] If the number or proportion of leader response messages received by any replica of the standby database meets the leader election condition, the replica is determined to be the leader replica.
[0147] One or more embodiments of the present specification also propose a computer program product, including a computer program / instruction, which implements the steps of the method described in the first aspect or the second aspect when the computer program / instruction is executed by a processor.
[0148] One or more embodiments of the present specification also propose a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method described in the first aspect or the second aspect.
[0149] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0150] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0151] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0152] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules 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 technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0153] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0154] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0155] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0156] 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, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0157] 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 specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0158] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A data management method based on a fast synchronization mechanism, applied to a master database in a data system, wherein the data system also includes a backup database, the method comprising: In response to receiving a data write request sent by a client, writing the target data indicated by the data write request in the leader copy of the master database, and generating a data write log; The data write log is sent to other replicas of the primary library and the standby library respectively, so that the other replicas of the primary library and the standby library respectively replay the data write log to write the target data.
2. According to the data management method based on the fast synchronization mechanism of claim 1, the sending of the data write log to other replicas of the primary database and the standby database respectively, so that the other replicas of the primary database and the standby database respectively replay the data write log to write the target data, comprises: The data write log is sent to other replicas of the primary library and multiple replicas of the backup library respectively, so that the other replicas of the primary library and multiple replicas of the backup library respectively replay the data write log to write the target data.
3. The data management method based on the fast synchronization mechanism according to claim 2, the method further comprising: In response to receiving write confirmation messages returned by a first preset number of replicas in other replicas of the master database within a preset time period, determining that the target data is successfully written into the master database; In response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time period, determining that the target data is successfully written into the standby database; In response to the target data being successfully written into the primary database and the target data being successfully written into the standby database, a write success message is returned to the client.
4. The data management method based on the fast synchronization mechanism according to claim 3, the method further comprising: The first preset number and / or the second preset number are adjusted according to the adjustment instruction.
5. The data management method based on the fast synchronization mechanism according to claim 1, the method further comprising: At least one replica of the master database sends a leader election request to other replicas; Each replica of the master database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received; If the number or proportion of leader response messages received by any replica of the master database meets the leader election condition, the replica is determined to be the leader replica.
6. A data management method based on a fast synchronization mechanism, applied to a backup database in a data system, wherein the data system also includes a primary database, the method comprising: Receive the 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 into the standby database; The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and the standby database.
7. According to the data management method based on the fast synchronization mechanism of claim 6, the receiving of 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 into the standby database comprises: Each replica of the standby database receives the data write log sent by the leader of the primary database, and replays the data write log to write the target data indicated by the data write log into the replica; The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and each copy of the standby database.
8. The data management method based on the fast synchronization mechanism according to claim 7, the method further comprising: Each replica of the standby 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 is successfully written in the standby database in response to receiving write confirmation messages returned by a second preset number of replicas among the multiple replicas of the standby database within a preset time length.
9. The data management method based on the fast synchronization mechanism according to claim 6, the method further comprising: At least one replica of the standby database sends a leader election request to other replicas; Each replica of the standby database returns a leader response message to the replica with the largest number among the replicas to which at least one leader election request has been received; If the number or proportion of leader response messages received by any replica of the standby database meets the leader election condition, the replica is determined to be the leader replica.
10. A data management device based on a fast synchronization mechanism, applied to a master database in a data system, the data system also including a backup database, the device comprising: A writing module, configured to, in response to receiving a data writing request sent by a client, write the target data indicated by the data writing request into the leader copy of the master database, and generate a data writing log; The synchronization module is used to send the data write log to other copies of the primary library and the standby library respectively, so that the other copies of the primary library and the standby library respectively replay the data write log to write the target data.
11. A data management device based on a fast synchronization mechanism, applied to a backup database in a data system, the data system also including a main database, the device comprising: A receiving module, used 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 into the standby database; The data write log is generated after the primary database writes the target data indicated by the data write request sent by the client into the leader copy of the primary database, and is sent to other copies of the primary database and the standby database.
12. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 9.
13. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 9 by running the executable instructions.
14. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 9.
Citation Information
Cited By
Data management based on fast synchronization mechanism
WO2025246835A1
