A method, device and computer-readable storage medium for restoring a distributed database system
By obtaining the full backup data and incremental logs of the distributed database system, determining the trust time period and distrust time period, and processing the transactions to be matched according to the preset strategy, the complexity and performance of consistent restore in the distributed database system are solved. Problem, efficient distributed database consistency restore is achieved.
Patent Information
- Application Number
- CN202110312905.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2020-08-24
- Filing Date
- 2021-03-24
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2041-03-24
AI Technical Summary
In distributed database systems, it is difficult for the prior art to achieve consistent restoration, especially because the commit time of global transactions in each data node is inconsistent, resulting in only partial restoration of some global transactions, and the implementation of GTM components is complex and affects processing performance. Incremental backup method is not supported.
By obtaining the full backup data and incremental logs of each data node, determining the trust time period and distrust time period, and processing, rolling back or executing transactions according to the preset matching strategy to achieve consistency of the distributed database system reduction.
It realizes a distributed database consistent restore without blocking global transactions, supports restore at any point in time, significantly saving computing costs.
Smart Images

Figure CN112882870B_ABST
Abstract
Description
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to patent application number CN2020108596225 filed on August 24, 2020 and entitled “A method, device and computer-readable storage medium for restoring a distributed database system”, the entire contents of which are incorporated herein by reference. Technical Field
[0003] The present invention belongs to the technical field of distributed data systems, and in particular relates to a restoration method, device and computer-readable storage medium for a distributed database system. Background Art
[0004] This section is intended to provide a background or context to embodiments of the invention that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0005] Distributed databases store data in multiple nodes (generally called data nodes). For a global transaction, its transaction information may also be distributed in different data nodes. This makes it difficult to restore distributed stored data to a certain point in time at the same time in a distributed database scenario. Since the actual submission time of global transactions on each data node is inconsistent, the method of independently restoring each data node to a certain time node will result in only partial restoration of some global transactions. For example, a global transaction involves operations on nodes A and B. If the data nodes are restored independently, the global transaction may only restore the operations of A or B, thus causing inconsistency.
[0006] In the prior art, the consistency restoration of a distributed database usually adopts the following restoration method based on the GTM (Global Transaction Manager) component to obtain a consistent snapshot. However, the implementation of the GTM component is relatively complicated, and GTM may affect the processing performance of the distributed system. In addition, the GTM component can only perform a full snapshot backup consistency restore point, and does not support incremental backup methods.
[0007] In other words, distributed databases have long lacked a consistency restoration mechanism. Summary of the invention
[0008] In view of the problems existing in the above-mentioned prior art, a method, device and computer-readable storage medium for restoring a distributed database system are proposed. The above-mentioned problems can be solved by using this method, device and computer-readable storage medium.
[0009] The present invention provides the following solutions.
[0010] In a first aspect, a method for restoring a distributed database system is provided, the distributed database system comprising a coordinator node and a plurality of data nodes, the method comprising: obtaining a restore instruction, the restore instruction being used to instruct to restore each data node of the distributed database system to a target time point; obtaining full backup data and incremental logs of each data node according to the target time point; determining a trusted time period and an untrusted time period at the target time point; using the full backup data of each data node as a restore starting point, and rolling back or executing transactions initiated and submitted by each data node within the trusted time period according to the incremental logs of each data node; and matching transactions to be matched based on a preset matching strategy, wherein the transactions to be matched are transactions initiated and submitted by each data node within the untrusted time period.
[0011] In a possible implementation, determining a trusted time period and an untrusted time period at a target time point includes: determining transaction commit durations of multiple distributed transactions based on incremental logs of each data node; recording transaction start commit time points and transaction completion commit time points corresponding to transaction commit durations greater than a preset value into a distributed transaction time table; determining a first time point based on the distributed transaction time table, the first time point being a trust divergence time point at the target time point; and dividing the trusted time period and the untrusted time period at the target time point based on the target time point and the first time point.
[0012] In a possible implementation, determining the first time point according to the distributed transaction time-consuming table includes: searching for a distributed transaction that meets a first preset condition according to the distributed transaction time-consuming table, wherein the first preset condition is that the transaction start commit time point is before ts and the corresponding transaction completion commit time is after t, wherein t is the target time point and s is a preset value; determining the first time point to be the earliest transaction start commit time among the distributed transactions that meet the first preset condition, or a time point before the earliest transaction start commit time.
[0013] In a possible implementation, determining the first time point according to the distributed transaction time table also includes: if a distributed transaction that meets the first preset condition cannot be found in the distributed transaction time table, determining the first time point to be ts or any time point before ts, where t is the target time point and s is the preset duration.
[0014] In a possible implementation, the transaction commit durations of multiple distributed transactions are determined according to the incremental logs of each data node, including: if the distributed transaction consists of multiple two-phase branch transactions and one global transaction, the time difference between the first prepare record of the two-phase branch transaction of the distributed transaction and the log record of the global transaction is calculated by the coordinator node as the distributed transaction commit duration; or, if the distributed transaction is executed by a general participant and a last participant, and the general participant adopts a two-phase commit protocol, and the last participant adopts a one-phase commit protocol, the time difference between the first prepare record of the general participant of the distributed transaction and the commit response of the last participant is calculated by the coordinator node as the distributed transaction commit duration.
[0015] In a possible implementation, matching processing is performed on the transactions to be matched based on a preset matching strategy, including: if the first transaction in the transactions to be matched is a non-distributed transaction, replaying the first transaction; if all branch transactions corresponding to the second transaction in the transactions to be matched are implemented within a trusted time period at a target time point, replaying the second transaction; if the global log and all branch logs corresponding to the third transaction in the transactions to be matched exist, replaying the third transaction; and, not replaying the remaining transactions in the transactions to be matched.
[0016] In a possible implementation, the step of determining a third transaction from the transactions to be matched is further included, including: determining a second time point according to a distributed transaction time consumption table, the second time point being a trust divergence time point of the first time point; judging whether there is a global log and all branch logs corresponding to any one or more distributed transactions in the incremental logs between the second time point and the target time point of each data node; if so, determining that any one or more distributed transactions are the third transactions.
[0017] In a possible implementation, determining the second time point according to the distributed transaction time table includes: searching the second distributed transaction according to the distributed transaction time table, determining the second time point to be the earliest transaction start commit time in the second distributed transaction or a time point before the earliest transaction start commit time, wherein the transaction start commit time point of the second distributed transaction is before t1-s, and the transaction completion commit time is after t1; and, if the second distributed transaction cannot be found in the distributed transaction time table, determining the second time point to be t1-s or a time point before t1-s, wherein t1 is the first time point and s is a preset value.
[0018] In a possible implementation, determining the second time point according to the distributed transaction time table also includes: replacing t with ta to determine the first time point; and / or replacing t1 with t1-a to determine the second time point; wherein t is the target time point, a is the preset time deviation, and t1 is the first time point.
[0019] In a possible implementation, the method further includes: during the matching process, constraining two or more transactions having a dependency relationship.
[0020] In a possible implementation, before restoring the distributed database system, the process further includes: constructing a full backup of each data node to obtain full backup data; and obtaining an incremental log of each data node.
[0021] In a possible implementation, building a full backup of each data node includes: locking each data node after completing all two-phase transactions of the currently processed distributed transaction, and performing a full backup of each data node after locking.
[0022] In a possible implementation, constructing a full backup of each data node also includes: performing a first full backup of each data node at a first full backup time point; determining an untrusted time period at the first full backup time point, and obtaining a first incremental log set for each data node in the untrusted time period at the first full backup time point; analyzing the first incremental log set to obtain pending transactions that are in a prepared state but have not been committed or rolled back; and replaying the pending transactions on the data obtained based on the first full backup, thereby constructing a full backup of each data node.
[0023] In one possible implementation, a full backup of each data node is constructed, including: performing a second full backup on each data node at a second full backup time point; determining an untrusted time period at the second full backup time point, obtaining a second incremental log set for each data node from the start time point of the untrusted time period at the second full backup time point to any time point after the second full backup is completed; and performing fault-tolerant playback of the second incremental log set on data obtained based on the second full backup.
[0024] In a possible implementation, it also includes: determining a trust divergence time point of the full backup time point, before which all transactions in preparation can be committed or rolled back through incremental logs before the full backup time point; and determining a distrust time period of the full backup time point based on the trust divergence time point of the full backup time point.
[0025] In a possible implementation, determining a first time point according to a distributed transaction timing table includes: determining a coordinator time t′=tm according to a preset time deviation m and a target time point t, wherein the preset time deviation m is used to indicate the maximum time deviation between any two data nodes of a distributed database system: determining a trust divergence time point t1′ of the coordinator time t′ according to the distributed transaction timing table; and determining a first time point t1=t1′-m according to the time deviation value m and the trust divergence time point t1′ of the coordinator time t′.
[0026] In a possible implementation, determining a trust divergence time point t1′ of a coordinator time t′ according to a distributed transaction time table includes: searching for a distributed transaction that meets a third preset condition according to the distributed transaction time table, wherein the third preset condition is that a transaction start commit time point is before t′-s and a corresponding transaction completion commit time point is after t′, wherein s is a preset value; wherein, if there is a distributed transaction that meets the third preset condition, determining the earliest transaction start commit time or a time point before the earliest transaction start commit time as the trust divergence time point t1′ of the coordinator time t′; if there is no distributed transaction that meets the preset condition, determining t′-s or a time point before t′-s as the trust divergence time point t1′ of the coordinator time t′.
[0027] In a possible implementation, dividing the target time point into a trusted time period and an untrusted time period according to the target time point and the first time point also includes: dividing the untrusted time period [t1, t+m] of the target time point according to the target time point t, the time deviation value m and the first time point t1.
[0028] In a possible implementation, matching processing is performed on the transactions to be matched based on a preset matching strategy, including: if the fourth transaction in the transactions to be matched is a non-distributed transaction, replaying the fourth transaction; if the fifth transaction in the transactions to be matched is a distributed transaction, and the global log corresponding to the fifth transaction is landed before the target time point, replaying the fifth transaction; and, the remaining transactions in the transactions to be matched are not replayed.
[0029] In a possible implementation, replaying the fifth transaction further includes: if the branch transactions corresponding to the fifth transaction have all been committed within the untrusted time period at the target time point, directly replaying the fifth transaction; if one or more branch transactions corresponding to the fifth transaction have not been committed within the untrusted time period at the target time point, after replaying the committed global transaction and branch transactions corresponding to the fifth transaction, submitting the uncommitted one or more branch transactions at the corresponding data node.
[0030] In one possible implementation, the transaction commit duration of multiple distributed transactions is determined based on the incremental logs of each data node, including: calculating the time difference from the preparation record of the first general participant of the distributed transaction to the landing time of the submission response of the last general participant through the coordinator node as the distributed transaction submission duration.
[0031] In a second aspect, a restoration device for a distributed database system is provided, wherein the distributed database system includes a coordinator node and multiple data nodes, and the device includes: an instruction unit, used to obtain a restoration instruction, wherein the restoration instruction is used to instruct each data node of the distributed database system to be restored to a target time point; an acquisition unit, used to obtain the full backup data and incremental log of each data node according to the target time point; a determination unit, used to determine a trusted time period and an untrusted time period at the target time point; a first restoration unit, used to use the full backup data of each data node as a restoration starting point, and roll back or execute transactions initiated and submitted by each data node within the trusted time period according to the incremental log of each data node; and a second restoration unit, used to perform matchmaking processing on transactions to be matched based on a preset matchmaking strategy, wherein the transactions to be matched are transactions initiated and submitted by each data node within the untrusted time period.
[0032] In a possible implementation, the determination unit is also used to: determine the transaction commit duration of multiple distributed transactions based on the incremental logs of each data node; record the transaction start commit time point and the transaction completion commit time point corresponding to the transaction commit duration greater than a preset value in a distributed transaction time table; determine a first time point based on the distributed transaction time table, the first time point being the trust divergence time point of the target time point; and divide the target time point into a trust time period and a non-trust time period based on the target time point and the first time point.
[0033] In a possible implementation, the determination unit is also used to: search for a distributed transaction that meets a first preset condition according to a distributed transaction time-consuming table, wherein the first preset condition is that the transaction start commit time point is before ts and the corresponding transaction completion commit time is after t, wherein t is the target time point and s is a preset value; determine that the first time point is the earliest transaction start commit time among the distributed transactions that meet the first preset condition, or a time point before the earliest transaction start commit time.
[0034] In a possible implementation, the determination unit is further used to: if no distributed transaction meeting the first preset condition can be found in the distributed transaction time consumption table, determine the first time point to be ts or a time point before ts, where t is the target time point and s is the preset duration.
[0035] In a possible implementation, the determination unit is further used for: if the distributed transaction consists of multiple two-phase branch transactions and one global transaction, the time difference between the first prepare record of the two-phase branch transaction of the distributed transaction and the log record of the global transaction is calculated through the coordinator node as the distributed transaction commit duration; or, if the distributed transaction is executed by general participants and the last participant, and the general participants adopt the two-phase commit protocol, and the last participant adopts the one-phase commit protocol, then the time difference from the first prepare record of the general participants of the distributed transaction to the commit response of the last participant is calculated through the coordinator node as the distributed transaction commit duration.
[0036] In a possible implementation, the second restoration unit is further used to: if the first transaction in the transactions to be matched is a non-distributed transaction, then replay the first transaction; if all branch transactions corresponding to the second transaction in the transactions to be matched are implemented within the trust time period at the target time point, then replay the second transaction; if the global log and all branch logs corresponding to the third transaction in the transactions to be matched exist, then replay the third transaction; and, do not replay the remaining transactions in the transactions to be matched.
[0037] In a possible implementation, the second restoration unit is also used to: determine a second time point according to a distributed transaction time table, the second time point being a trust divergence time point of the first time point; in the incremental log between the second time point and the target time point of each data node, determine whether there is a global log and all branch logs corresponding to any one or more distributed transactions; if so, determine that any one or more distributed transactions are third transactions.
[0038] In a possible implementation, the second restoration unit is further used to: search for the second distributed transaction according to the distributed transaction time table, determine that the first time point is the earliest transaction start commit time in the second distributed transaction or a time point before the earliest transaction start commit time, wherein the transaction start commit time point of the second distributed transaction is before t1-s, and the transaction completion commit time is after t1; and, if the second distributed transaction cannot be found in the distributed transaction time table, determine that the second time point is t1-s or a time point before t1-s, wherein t1 is the first time point and s is a preset value.
[0039] In a possible implementation, the second restoration unit is also used to: replace t with ta to determine the first time point; and / or replace t1 with t1-a to determine the second time point; wherein t is the target time point, a is the preset time deviation, and t1 is the first time point.
[0040] In a possible implementation, the device is further used to: during the matching process, perform constraint processing on two or more transactions with a dependency relationship.
[0041] In a possible implementation, the device further includes a backup unit, which is used to: construct a full backup of each data node to obtain full backup data; and obtain an incremental log of each data node.
[0042] In a possible implementation, the backup unit is further used to: lock each data node after completing all two-phase transactions of the currently processed distributed transaction, and perform a full backup of each data node after locking.
[0043] In a possible implementation, the backup unit is further used to: perform a first full backup of each data node at a first full backup time point; determine an untrusted time period at the first full backup time point, and obtain a first incremental log set for each data node in the untrusted time period at the first full backup time point; analyze the first incremental log set to obtain pending transactions that are in a prepared state but have not been committed or rolled back; and replay the pending transactions on the data obtained based on the first full backup, thereby constructing a full backup of each data node.
[0044] In one possible implementation, the backup unit is also used to: perform a second full backup on each data node at a second full backup time point; determine an untrusted time period at the second full backup time point, and obtain a second incremental log set for each data node from the start time point of the untrusted time period at the second full backup time point to any time point after the second full backup is completed; and perform fault-tolerant playback of the second incremental log set on the data obtained based on the second full backup.
[0045] In a possible implementation, it also includes: determining a trust divergence time point of the full backup time point, before which all transactions in preparation can be committed or rolled back through incremental logs before the full backup time point; and determining a distrust time period of the full backup time point based on the trust divergence time point of the full backup time point.
[0046] In a possible implementation, the determination unit is also used to: determine the coordinator time t′=tm based on a preset time deviation m and a target time point t, where the preset time deviation m is used to indicate the maximum time deviation between any two data nodes in the distributed database system: determine the trust divergence time point t1′ of the coordinator time t′ based on the distributed transaction time table; determine the first time point t1=t1′-m based on the time deviation value m and the trust divergence time point t1′ of the coordinator time t′.
[0047] In a possible implementation, the determination unit is further used to: search for a distributed transaction that meets a third preset condition according to the distributed transaction time-consuming table, wherein the third preset condition is that the transaction start commit time point is before t′-s and the corresponding transaction completion commit time is after t′, wherein s is a preset value; wherein,
[0048] If there is a distributed transaction that meets the third preset condition, determine the trust divergence time point t1′ where the earliest transaction start commit time or the time point before the earliest transaction start commit time is the coordinator time t′;
[0049] If there is no distributed transaction that meets the preset conditions, the time point t′-s or before t′-s is determined as the trust divergence time point t1′ of the coordinator time t′.
[0050] In a possible implementation, the determination unit is further configured to: divide the target time point into an untrusted time period [t1, t+m] according to the target time point t, the time deviation value m, and the first time point t1.
[0051] In a possible implementation, the second restoration unit is further used to: if the fourth transaction in the transactions to be matched is a non-distributed transaction, then replay the fourth transaction; if the fifth transaction in the transactions to be matched is a distributed transaction, and the global log corresponding to the fifth transaction is landed before the target time point, then replay the fifth transaction; and, not replay the remaining transactions in the transactions to be matched.
[0052] In a possible implementation, the second restoration unit is further configured to: directly replay the fifth transaction if the branch transactions corresponding to the fifth transaction have all been committed within the untrusted time period at the target time point;
[0053] If one or more branch transactions corresponding to the fifth transaction are not committed within the untrusted time period at the target time point, then after replaying the committed global transaction and branch transactions corresponding to the fifth transaction, the one or more branch transactions that have not been committed are committed on the corresponding data nodes.
[0054] In one possible implementation, the transaction commit duration of multiple distributed transactions is determined based on the incremental logs of each data node, including: calculating the time difference from the preparation record of the first general participant of the distributed transaction to the landing time of the submission response of the last general participant through the coordinator node as the distributed transaction submission duration.
[0055] According to a third aspect, a restoration device for a distributed database system is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute: the method according to the first aspect.
[0056] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a program, and when the program is executed by a multi-core processor, the multi-core processor executes the method of the first aspect.
[0057] At least one of the above-mentioned technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects: the present embodiment proposes a consistency method for distributed restoration to any time point within the backup cycle without blocking global transactions, and significantly saves the computational cost of consistency restoration by dividing the time period into trusted time periods and untrusted time periods.
[0058] It should be understood that the above description is only an overview of the technical solution of the present invention, so that the technical means of the present invention can be more clearly understood and implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described below by way of example. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The advantages and benefits described herein and other advantages and benefits will be apparent to those of ordinary skill in the art by reading the detailed description of the exemplary embodiments below. The accompanying drawings are only used for the purpose of illustrating exemplary embodiments and are not to be considered as limiting the present invention. Moreover, the same reference numerals are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0060] Figure 1 is a schematic diagram of a distributed database system;
[0061] Figure 2 A schematic diagram of a distributed transaction;
[0062] Figure 3 A schematic diagram of a flow chart of a restoration method for a distributed database system according to an embodiment of the present invention;
[0063] Figure 4 is a restoration sequence diagram of a distributed database system according to an embodiment of the present invention;
[0064] Figure 5 A structural diagram of a restoration device for a distributed database system according to an embodiment of the present invention
[0065] Figure 6FIG. 4 is a schematic diagram of the structure of a restoration device of a distributed database system according to another embodiment of the present invention.
[0066] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0067] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0068] In the present invention, it should be understood that terms such as “including” or “having” are intended to indicate the existence of features, numbers, steps, behaviors, components, parts or a combination thereof disclosed in the specification, and are not intended to exclude the possibility of the existence of one or more other features, numbers, steps, behaviors, components, parts or a combination thereof.
[0069] It should also be noted that, in the absence of conflict, the embodiments and features of the embodiments of the present invention can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0070] A transaction is a unit of concurrency control and a sequence of operations defined by the user. These operations are either all done or none done, so it is an indivisible unit of work. Distributed transaction processing means that a transaction may involve multiple database operations. The key to distributed transaction processing is that there must be a way to know all the actions involved in the transaction anywhere, so that the decision to commit or roll back the transaction must produce a unified result for them (all committed or all rolled back).
[0071] Figure 1A distributed database system is provided, which includes a coordinator node 101, multiple data nodes 102 and multiple clients 103. The logic of the coordinator node 101 (Coordinator) of the distributed transaction to process transactions is as follows: if the global transaction involves only one data node, the data node can only use the one-phase protocol to commit the transaction. Of course, the two-phase protocol can also be used to commit the transaction, but it will lead to poor processing performance and increase the probability of failure; if the global transaction involves multiple data nodes, then the branch transaction will start at the data node using the two-phase (2PC) protocol (the three-phase protocol can also be used), and the coordinator will control the branch transaction to enter the Prepare state. After all branch transactions are in the Prepare state, a global transaction log (including the branch transaction information corresponding to the global transaction) is recorded. If the global transaction log record is successful (that is, it is considered that the global transaction must be successful), the branch transaction in the Prepare state will be submitted until the submission is successful. If the global transaction log record fails (that is, it is considered that the global transaction will eventually fail), all branch transactions are rolled back. In practical applications, the transaction submission is optimized as follows: one data node is selected from multiple data nodes as the last participant, and other data nodes are used as ordinary participants. When the global transaction is committed, the ordinary participants first use the two-phase protocol to make the branch transaction enter the preparation state, and before the last participant commits the branch transaction, the global transaction log is recorded (but not committed) to the local last participant using the branch transaction. After that, the last participant uses the one-phase protocol to commit the branch transaction. If the last participant commits successfully (that is, the global transaction is considered successful), the branch transactions of each general participant in the preparation stage are submitted until the submission is successful. If the last participant fails to commit (that is, the global transaction is considered failed), the branch transaction is rolled back.
[0072] Figure 2 An example of a distributed transaction is shown, such as Figure 2 As shown in the figure (where the arrow indicates time), when a user uses a distributed database system through a client, he can only see the global transaction. When using it, he will first (explicitly or implicitly) start the global transaction and then commit the global transaction. Starting a global transaction can be considered to take effect immediately, while committing a global transaction requires a processing process: from starting to commit a global transaction to completing the global transaction commit, the coordinator node will coordinate general participants A and B to use the two-phase protocol, and the last participant to use the one-phase protocol to commit the transaction. The incremental log of the participants is reflected in the two-phase log of the general participant (prepare log, commit log) and the one-phase log of the last participant (branch transaction and global transaction log). It should be noted that if the one-phase log is successfully committed, the distributed transaction will eventually be successfully committed.
[0073] The problem of consistency restoration in distributed database systems is caused by the fact that global transactions involve multiple data nodes and the two-phase protocol is enabled on the data nodes. In some scenarios, transactions cannot be recorded and obtained in the same real event.
[0074] Figure 3 This is a flow chart of a method 300 for restoring a distributed database system according to an embodiment of the present application. In this flow, from the perspective of the device, the execution subject may be one or more electronic devices; from the perspective of the program, the execution subject may be the program installed on these electronic devices.
[0075] like Figure 3 As shown, the method 300 may include:
[0076] Step 301: Obtain a restore instruction, where the restore instruction is used to instruct each data node of the distributed database system to be restored to a target time point;
[0077] Step 302: Obtain the full backup data and incremental logs of each data node according to the target time point;
[0078] When it is necessary to roll back the data of a distributed database system to a target time point, it is necessary to first obtain the most recent full backup data of each data node before the target time point at the target time point, and obtain the incremental logs of each data node between the full backup time point and the target time point. Full backup data refers to a complete data image. In a distributed database, each data node has its own corresponding full backup data. That is, at a certain moment, the full backup data of each data node contains all the data of each data node at this specific moment. Full backup does not require real-time backup, and a regular backup mechanism is often used. Full backup data and incremental logs constitute the basic conditions for data rollback in a distributed database.
[0079] For example, when the target time point of the restore instruction is 12:00, and the full backup data is backed up regularly at 11:30, the full backup data at 11:30 and the incremental logs between 11:30 and 12:00 can be obtained. The data can be rolled back to the full backup data at 11:30, and the full backup data at 11:30 can be used as the restore starting point for each data node.
[0080] Step 303: Determine a trusted time period and an untrusted time period at the target time point;
[0081] Among them, in step 303, the trusted time period and the untrusted time period for the target time point in the distributed transaction are divided. For the target time point t, the trusted time period of the target time point t means that all the transactions that are finally submitted in this time period have completed the global log landing before time t, and thus will be submitted. The untrusted time period of the target time point t means that there may be distributed transactions in this time period that cannot be determined whether to be submitted or rolled back based on the logs before time t. The trusted time period and the untrusted time period are separated by the trust divergence time point of the target time point. Before this divergence point, it is a trusted time period, and after this divergence point, it is an untrusted time period.
[0082] In a possible implementation, step 303 may specifically include: determining the transaction commit duration of multiple distributed transactions based on the incremental logs of each data node; recording the transaction start commit time point and the transaction completion commit time point corresponding to the transaction commit duration greater than a preset value in a distributed transaction time table; determining a first time point based on the distributed transaction time table, the first time point being the trust divergence time point of the target time point; and dividing the target time point into the trust time period and the untrust time period based on the target time point and the first time point.
[0083] In a possible implementation, the transaction commit duration of multiple distributed transactions is determined based on the incremental logs of each data node, specifically including: when the last participant strategy is not adopted, the distributed transaction consists of a global transaction and branch transactions of multiple general participants. In this case, the time difference between the first prepare record of the second-phase branch transaction of the distributed transaction (that is, the time when the first prepare log of the general participant is landed) and the log record of the global transaction (that is, the time when the global transaction log is landed) can be calculated by the coordinator node as the transaction commit duration of the distributed transaction; or, when the last participant strategy is adopted, refer to Figure 2 The distributed transaction is executed by the general participants and the last participants corresponding to each data node, wherein the general participants adopt a two-phase commit protocol and the last participants adopt a one-phase commit protocol. The time difference from the first preparation record of the general participant of the distributed transaction (that is, the landing time of the preparation log of the general participant A) to the submission response of the last participant can be calculated by the coordinator node as the transaction submission duration of the distributed transaction.
[0084] In one possible implementation, when adopting the above-mentioned last participant strategy, the time difference from the start of submitting the global transaction to the first-stage log submission response of the last participant for each distributed transaction can be calculated by the coordinator node as the observable transaction submission duration, wherein the observable transaction submission duration of the distributed transaction is greater than the actual transaction submission duration, so that the transaction submission duration can be more conveniently known.
[0085] In one example, as shown in Table 1, an example of a distributed transaction time table is shown, in which it can be known from experience that the transaction commit time of most distributed transactions is within s1 seconds (for example, s1=0.3). If the transaction commit time of a distributed transaction is longer than s1 seconds, the start commit time and the completion commit time of the distributed transaction will be recorded in the distributed transaction time table of Table 1; if the transaction commit time of the distributed transaction is less than or equal to s1 seconds, it does not need to be recorded in the distributed transaction time table.
[0086] Table 1:
[0087] Sequence number (distributed transaction id) Transaction commit start time Transaction completion time 111111 2020-5-28 12:22:11.61 2020-5-2812:22:11.92 222222 2020-5-29 12:22:11.61 2020-5-2912:22:11.92 333333 2020-5-30 12:22:11.61 2020-5-3012:22:11.92
[0088] In another possible implementation, the above-mentioned determination of the transaction commit duration of multiple distributed transactions based on the incremental logs of each data node may also include: regardless of whether the last participant strategy is adopted, the coordinator node may calculate the landing time difference from the landing time of the first general participant's preparation record of the distributed transaction (that is, the landing time of the first preparation log of the general participant) to the landing time of the last general participant's submission response (that is, the landing time of the last submission log of the general participant) as the transaction commit duration of the distributed transaction. For example, in Figure 2 In the example, the transaction commit duration of the distributed transaction corresponds to the landing time difference between the prepare log and the commit log in the incremental log of the general participant A.
[0089] In this embodiment, the transaction start submission time point of the distributed transaction is the landing time of the preparation record of the first general participant, and the transaction completion submission time point of the distributed transaction is the time of the submission response of the last general participant.
[0090] In one example, as shown in Table 2, the time difference between the first preparation record of a general participant of a distributed transaction and the submission response of all the general participants is used as an embodiment of the transaction submission duration, showing another example of a distributed transaction time-consuming table, wherein it can be known from experience that the transaction submission duration of most distributed transactions is within s2 seconds (for example, s2=3). If the transaction submission duration of a distributed transaction is greater than s2 seconds, the start submission time and the completion submission time of the distributed transaction will be recorded in the distributed transaction time-consuming table of Table 2; if the transaction submission duration of the distributed transaction is less than or equal to s2 seconds, it does not need to be recorded in the distributed transaction time-consuming table.
[0091] Table 2:
[0092] Sequence number (distributed transaction id) Transaction commit start time Transaction completion time 444444 2020-5-28 12:22:11.61 2020-5-2812:22:14.62 555555 2020-5-29 12:22:11.61 2020-5-2912:22:14.62 666666 2020-5-30 12:22:11.61 2020-5-3012:22:14.62
[0093] In a possible implementation, determining the first time point according to the distributed transaction time-consuming table obtained above may include: searching for a distributed transaction that meets a first preset condition according to the distributed transaction time-consuming table, wherein the first preset condition is that the transaction start commit time point is before ts and the corresponding transaction completion commit time is after t, wherein t is the target time point and s is the preset value; determining that the first time point is the earliest transaction start commit time among the distributed transactions that meet the first preset condition, or may be a time point before the earliest transaction start commit time.
[0094] In another possible implementation, determining the first time point according to the distributed transaction time table may also include: if a distributed transaction that meets the first preset condition cannot be found in the distributed transaction time table, determining the first time point to be ts or a time point before ts, wherein t is the target time point and s is the preset duration.
[0095] In another possible implementation, taking into account the inevitable time errors in distributed systems, we need to revise the above scheme and determine the first time point according to the distributed transaction timing table, which may further include: determining the coordinator time t′=tm according to the preset time deviation m and the target time point t, wherein the preset time deviation m is used to indicate the maximum time deviation between any two data nodes of the distributed database system; determining the trust divergence time point t1′ of the coordinator time t′ according to the distributed transaction timing table; determining the first time point t1=t1′-m according to the time deviation value m and the trust divergence time point t1′ of the coordinator time t′.
[0096] In this embodiment, considering the time error that must exist in the distributed system, the maximum time error between each data node can be limited to no more than m seconds (for example, m = 3 seconds). Based on this time error, the following analysis is made: For the first time point t1 of the trust divergence time point of the target time point t, since there is a time difference between each data node and it does not exceed m, it can be: 1) For the data node that is slower than the coordinator, let the coordinator time t′=tm, which can ensure that the coordinator time is earlier than all data nodes, and use the distributed time consumption table and refer to the above-mentioned trust divergence time point calculation method to obtain the trust divergence time point t1′ of the coordinator time t′, which can ensure that the data node that is slower than the coordinator meets the requirements. 2) For the data node that is faster than the coordinator, subtract a time error m from the calculated time t1′, which can ensure that its time is also slower than the coordinator, that is, t1=t1′-m, which can ensure that the data node that is faster than the coordinator meets the requirements. For any time before t1, it is the divergence time point of t. In summary, the first time point t1=t1′-m.
[0097] In a possible implementation, the trust divergence time point t1′ of the coordinator time t′ can be obtained by using a distributed time table and referring to the above-mentioned trust divergence time point calculation method, specifically including: searching for a distributed transaction that meets the third preset condition according to the distributed transaction time table, wherein the third preset condition is that the transaction start commit time point is before t′-s and the corresponding transaction completion commit time is after t′, wherein s is a preset value. Wherein, if there is a distributed transaction that meets the third preset condition, the earliest transaction start commit time or the time point before it is determined as the trust divergence time point t1′ of the coordinator time t′; on the contrary, if there is no distributed transaction that meets the preset condition, then t′-s or the time point before it is determined as the trust divergence time point t1′ of the coordinator time t′.
[0098] In addition, since each data node has a time deviation for the target time point, the time corresponding to the target time point t of each data node is not consistent. It is possible that the global log of the distributed transaction is landed before the target time point t of a certain data node, but the preparation (Prepare) record of the distributed transaction corresponding to another data node is landed after the playback point t.
[0099] In another possible implementation, in order to avoid the influence of the above-mentioned time deviation, step 303 may also include: dividing the untrusted time period [t1, t+m] of the target time point according to the target time point t, the time deviation value m and the first time point t1. In other words, during the consistency restoration process, it is necessary to obtain the processed branch transactions in the incremental log within the time interval [t1, t+m] of each branch participant according to the participant information recorded in the global log, and perform matching processing.
[0100] Optionally, the preset value s may be set to s1 or s2 based on different distributed transaction time-consuming tables such as those shown in Table 1 and Table 2 above, and may also be set to other values that conform to operational experience.
[0101] It can be understood that since the trust divergence time point of the target time point t is the first time point t1, it can be understood that any time before the first time point t1 can be regarded as the divergence time point of t. In this embodiment, the divergence time closest to the target time point t is found as much as possible, which can reduce the cost of subsequent distributed transaction matching.
[0102] Step 304: using the full backup data of each data node as a restoration starting point, and rolling back or executing transactions initiated and submitted by each data node within the trust period according to the incremental log of each data node;
[0103] In the restoration scheme of this embodiment, Figure 4 As shown, the trust divergence time point of the target time point t can be calculated as the first time point t1, which means that the distributed transactions before the first time point t1 can be determined by the incremental logs before time t to determine whether they will be rolled back or committed, while there may be distributed transactions from t1 to time t that cannot be determined by the incremental logs before time t to determine whether they will be committed or rolled back. Therefore, the incremental logs can be directly replayed on each data node to the first time point t1 without the need to match distributed transactions.
[0104] Step 305: Matching the pending matching transactions based on a preset matching strategy, where the pending matching transactions are transactions initiated and submitted by each data node within the untrusted time period.
[0105] In a possible implementation, the matching process of the transactions to be matched is performed based on a preset matching strategy in step 305, and the preset matching strategy includes: (1) if the first transaction in the transactions to be matched is a non-distributed transaction, that is, if the first transaction does not involve a distributed transaction (a one-stage transaction commit that does not contain a global transaction log) log, then replay the first transaction; (2) if the global log corresponding to the second transaction in the transactions to be matched is landed within the trust time period at the target time point, then replay the second transaction; (3) if the global log and all branch logs corresponding to the third transaction in the transactions to be matched exist, then replay the third transaction; and (4) do not replay the remaining transactions in the transactions to be matched.
[0106] In a possible implementation, for the above preset matching strategy (3), it further includes: determining the second time point t2 according to the distributed transaction time consumption table, such as Figure 4 As shown, the second time point is the trust divergence time point of the first time point; in the incremental logs between the second time point and the target time point of each data node, it is determined whether there are global logs and all branch logs corresponding to any one or more distributed transactions; if so, it is determined that any one or more distributed transactions are the third transactions.
[0107] Among them, the trust divergence time point t2 of t1 is calculated. Since the transaction before t2 is completed at t1, if the global log and branch log of the so-called "third transaction" exist, they must exist in the time period from t2 to t. Therefore, when we replay the incremental logs of each data node from t2 to t1, we record which global transaction logs and which participant logs exist, which are used for matching processing in step 305.
[0108] In a possible implementation, determining the second time point according to the distributed transaction time table includes: searching the second distributed transaction according to the distributed transaction time table, determining the first time point to be the earliest transaction start commit time in the second distributed transaction or a time point before it, wherein the transaction start commit time point of the second distributed transaction is before t1-s, and the transaction completion commit time is after t1; and, if the second distributed transaction cannot be found in the distributed transaction time table, determining the second time point to be t1-s, wherein t1 is the first time point and s is the preset value.
[0109] In one possible implementation, taking into account the time inconsistency of each data node, the trust divergence time point can be moved forward a little in actual application, that is, the preset time deviation of each data node is observed in advance as a, and ta can be used to replace t to determine the first time point; and / or t1-a can be used to replace t1 to determine the second time point; wherein t is the target time point, a is the preset time deviation, and t1 is the first time point.
[0110] In another possible implementation, the preset matching strategy in step 305 may further include: (4) if the fourth transaction in the transactions to be matched is a non-distributed transaction, replaying the fourth transaction; (5) if the fifth transaction in the transactions to be matched is a distributed transaction and the global log corresponding to the fifth transaction is landed before the target time point, replaying the fifth transaction; and (6) not replaying the remaining transactions in the transactions to be matched.
[0111] For the above-mentioned preset matching strategy (5), if the global log corresponding to the fifth transaction is landed before the target time point, it means that the global log of the fifth transaction in the untrusted time period can be used to determine whether the fifth transaction is finally rolled back or committed, so that the fifth transaction can be replayed.
[0112] In a possible implementation, the preset matching strategy (5) may further include the following strategy: if the branch transactions corresponding to the fifth transaction have all been submitted within the untrusted time period at the target time point, indicating that all global transactions and branch transactions of the fifth transaction have all been executed before the target time point, the fifth transaction may be directly replayed; if one or more branch transactions corresponding to the fifth transaction have not been submitted within the untrusted time period at the target time point, after replaying the submitted global transactions and branch transactions corresponding to the fifth transaction, the one or more branch transactions that have not been submitted are submitted at the corresponding data nodes, thereby maintaining consistency restoration.
[0113] In a possible implementation, in order to further ensure the consistent restoration of distributed transactions, during the matching process, constraints are processed for two or more transactions with dependencies. For example: if the previous transaction with a dependency cannot be replayed, then the current transaction cannot be replayed either. If the fourth transaction in the current transaction is a non-distributed transaction, it will not be replayed only in the current branch, and all subsequent transactions of the current branch that have dependency constraints on it will not be replayed; if the fifth transaction in the current transaction is a distributed transaction, the transaction should not be replayed in all branches involved, and all subsequent transactions of all branches involved that have dependency constraints on it will not be replayed until there is no dependency association after all transactions that are not replayed. Typical dependencies between transactions include: time dependency (the order in which transactions occur), row record dependency, etc.
[0114] In a possible implementation, before restoring the distributed database system, the process further includes: constructing a full backup of each data node to obtain the full backup data; and obtaining the incremental log of each data node.
[0115] This embodiment relies on full backup of each data node as the starting point for restoring each data node. It also relies on the logical log (branch transaction information record) on the data node for incremental data backup, and performs consistent transaction matching and playback on the global transaction logical log to achieve consistent restoration of the distributed database. Among them, the global transaction logical log includes the global log submission record and the relationship between the global transaction and the branch transaction.
[0116] In a possible implementation, in order to solve the problem that transactions in the preparation state are generally not recorded during the full backup of each data node, constructing the full backup of each data node may include the following three optional solutions:
[0117] (1) After each data node completes all two-phase transactions of the currently processed distributed transaction, the data node is locked, and after the locking, a full backup of each data node is performed.
[0118] (2) performing a first full backup of each data node at a first full backup time point; determining an untrusted time period at the first full backup time point, and obtaining a first incremental log set for each data node in the untrusted time period at the first full backup time point; analyzing the first incremental log set to obtain pending transactions that are in a prepared state but have not been committed or rolled back; and replaying the pending transactions on the data obtained according to the first full backup, thereby constructing a full backup of each data node.
[0119] (3) Perform a second full backup on each data node at the second full backup time point; determine the untrusted time period at the second full backup time point, obtain a second incremental log set for each data node from the start time point of the untrusted time period at the second full backup time point to any time point after the second full backup is completed; perform fault-tolerant playback on the data obtained from the second full backup. Fault-tolerant playback refers to avoiding data impact caused by repeated execution of data, such as ignoring repeated insertions, etc.
[0120] In one embodiment, for the above-mentioned optional scheme (2) or (3), the following steps may also be included: determining the untrusted time period of the first full backup time point or the second full backup time point; determining the trust divergence time point of the full backup time point, before which all transactions in a prepared state can be determined to be committed or rolled back through the incremental log before the full backup time point; determining the untrusted time period of the full backup time point according to the trust divergence time point of the full backup time point.
[0121] In this embodiment, the trust divergence time point of the full backup time point is set for each data node. The trust divergence time point on the data node is different from the trust divergence time point for the global transaction. The trust divergence time point calculated and analyzed by each data node based on the preparation phase time and the submission phase time of the branch transaction refers to the trust divergence time point i1 for the full backup time point i of the data node. All transactions in the preparation state before i1 can be determined to be committed or rolled back based on the incremental log before the full backup time point i, while the transactions in the preparation state between i1 and i cannot determine the final state of the transaction based on the incremental log before i. If optional scheme (2) or (3) is selected, it is necessary to maintain a "branch transaction time consumption table" similar to the "distributed transaction time consumption table" on each data node or on each data node to calculate the trust divergence time point on the data node.
[0122] In a possible implementation, based on the same technical concept, an embodiment of the present invention also provides a distributed database system restoration device, the distributed database system includes a coordinator node and multiple data nodes, and the device is used to execute the distributed database system restoration method provided in any of the above embodiments. Figure 5 A schematic diagram of the structure of a restoration device for a distributed database system provided by an embodiment of the present invention.
[0123] like Figure 5 As shown, the device 500 includes:
[0124] The instruction unit 501 is used to obtain a restore instruction, where the restore instruction is used to instruct to restore each data node of the distributed database system to a target time point;
[0125] The acquisition unit 502 is used to acquire the full backup data and incremental logs of each data node according to the target time point;
[0126] A determination unit 503, configured to determine a trusted time period and an untrusted time period at a target time point;
[0127] The first restoration unit 504 is used to use the full backup data of each data node as the restoration starting point, and roll back or execute the transaction initiated and submitted by each data node within the trust period according to the incremental log of each data node;
[0128] The second restoring unit 505 is used to perform matching processing on the pending matching transactions based on a preset matching strategy, where the pending matching transactions are transactions initiated and submitted by each data node within the untrusted time period.
[0129] In a possible implementation, the determination unit is also used to: determine the transaction commit duration of multiple distributed transactions based on the incremental logs of each data node; record the transaction start commit time point and the transaction completion commit time point corresponding to the transaction commit duration greater than a preset value in a distributed transaction time table; determine a first time point based on the distributed transaction time table, the first time point being the trust divergence time point of the target time point; and divide the target time point into a trust time period and a non-trust time period based on the target time point and the first time point.
[0130] In a possible implementation, the determination unit is also used to: search for a distributed transaction that meets a first preset condition according to a distributed transaction time-consuming table, wherein the first preset condition is that the transaction start commit time point is before ts and the corresponding transaction completion commit time is after t, wherein t is the target time point and s is a preset value; determine that the first time point is the earliest transaction start commit time among the distributed transactions that meet the first preset condition, or a time point before the earliest transaction start commit time.
[0131] In a possible implementation, the determination unit is further used to: if no distributed transaction meeting the first preset condition can be found in the distributed transaction time consumption table, determine the first time point to be ts or a time point before ts, where t is the target time point and s is the preset duration.
[0132] In a possible implementation, the determination unit is further used for: if the distributed transaction consists of multiple two-phase branch transactions and one global transaction, the time difference between the first prepare record of the two-phase branch transaction of the distributed transaction and the log record of the global transaction is calculated through the coordinator node as the distributed transaction commit duration; or, if the distributed transaction is executed by general participants and the last participant, and the general participants adopt the two-phase commit protocol, and the last participant adopts the one-phase commit protocol, then the time difference from the first prepare record of the general participants of the distributed transaction to the commit response of the last participant is calculated through the coordinator node as the distributed transaction commit duration.
[0133] In a possible implementation, the second restoration unit is further used to: if the first transaction in the transactions to be matched is a non-distributed transaction, then replay the first transaction; if all branch transactions corresponding to the second transaction in the transactions to be matched are implemented within the trust time period at the target time point, then replay the second transaction; if the global log and all branch logs corresponding to the third transaction in the transactions to be matched exist, then replay the third transaction; and, do not replay the remaining transactions in the transactions to be matched.
[0134] In a possible implementation, the second restoration unit is also used to: determine a second time point according to a distributed transaction time table, the second time point being a trust divergence time point of the first time point; in the incremental log between the second time point and the target time point of each data node, determine whether there is a global log and all branch logs corresponding to any one or more distributed transactions; if so, determine that any one or more distributed transactions are third transactions.
[0135] In a possible implementation, the second restoration unit is further used to: search for the second distributed transaction according to the distributed transaction time table, determine that the first time point is the earliest transaction start commit time in the second distributed transaction or a time point before the earliest transaction start commit time, wherein the transaction start commit time point of the second distributed transaction is before t1-s, and the transaction completion commit time is after t1; and, if the second distributed transaction cannot be found in the distributed transaction time table, determine that the second time point is t1-s or a time point before t1-s, wherein t1 is the first time point and s is a preset value.
[0136] In a possible implementation, the second restoration unit is also used to: replace t with ta to determine the first time point; and / or replace t1 with t1-a to determine the second time point; wherein t is the target time point, a is the preset time deviation, and t1 is the first time point.
[0137] In a possible implementation, the device is further used to: during the matching process, perform constraint processing on two or more transactions with a dependency relationship.
[0138] In a possible implementation, the device further includes a backup unit, which is used to: construct a full backup of each data node to obtain full backup data; and obtain an incremental log of each data node.
[0139] In a possible implementation, the backup unit is further used to: lock each data node after completing all two-phase transactions of the currently processed distributed transaction, and perform a full backup of each data node after locking.
[0140] In a possible implementation, the backup unit is further used to: perform a first full backup of each data node at a first full backup time point; determine an untrusted time period at the first full backup time point, and obtain a first incremental log set for each data node in the untrusted time period at the first full backup time point; analyze the first incremental log set to obtain pending transactions that are in a prepared state but have not been committed or rolled back; and replay the pending transactions on the data obtained based on the first full backup, thereby constructing a full backup of each data node.
[0141] In one possible implementation, the backup unit is also used to: perform a second full backup on each data node at a second full backup time point; determine an untrusted time period at the second full backup time point, and obtain a second incremental log set for each data node from the start time point of the untrusted time period at the second full backup time point to any time point after the second full backup is completed; and perform fault-tolerant playback of the second incremental log set on the data obtained based on the second full backup.
[0142] In a possible implementation, it also includes: determining a trust divergence time point of the full backup time point, before which all transactions in preparation can be committed or rolled back through incremental logs before the full backup time point; and determining a distrust time period of the full backup time point based on the trust divergence time point of the full backup time point.
[0143] In a possible implementation, the determination unit is also used to: determine the coordinator time t′=tm based on a preset time deviation m and a target time point t, where the preset time deviation m is used to indicate the maximum time deviation between any two data nodes in the distributed database system: determine the trust divergence time point t1′ of the coordinator time t′ based on the distributed transaction time table; determine the first time point t1=t1′-m based on the time deviation value m and the trust divergence time point t1′ of the coordinator time t′.
[0144] In a possible implementation, the determination unit is further used to: search for a distributed transaction that meets a third preset condition according to the distributed transaction time-consuming table, wherein the third preset condition is that the transaction start commit time point is before t′-s and the corresponding transaction completion commit time is after t′, wherein s is a preset value; wherein,
[0145] If there is a distributed transaction that meets the third preset condition, determine the trust divergence time point t1′ where the earliest transaction start commit time or the time point before the earliest transaction start commit time is the coordinator time t′;
[0146] If there is no distributed transaction that meets the preset conditions, the time point t′-s or before t′-s is determined as the trust divergence time point t1′ of the coordinator time t′.
[0147] In a possible implementation, the determination unit is further configured to: divide the target time point into an untrusted time period [t1, t+m] according to the target time point t, the time deviation value m, and the first time point t1.
[0148] In a possible implementation, the second restoration unit is further used to: if the fourth transaction in the transactions to be matched is a non-distributed transaction, then replay the fourth transaction; if the fifth transaction in the transactions to be matched is a distributed transaction, and the global log corresponding to the fifth transaction is landed before the target time point, then replay the fifth transaction; and, not replay the remaining transactions in the transactions to be matched.
[0149] In a possible implementation, the second restoration unit is further used to: if the branch transactions corresponding to the fifth transaction have all been committed within the untrusted time period at the target time point, directly replay the fifth transaction; if one or more branch transactions corresponding to the fifth transaction have not been committed within the untrusted time period at the target time point, after replaying the committed global transaction and branch transactions corresponding to the fifth transaction, submit the uncommitted one or more branch transactions at the corresponding data node.
[0150] In one possible implementation, the transaction commit duration of multiple distributed transactions is determined based on the incremental logs of each data node, including: calculating the time difference from the preparation record of the first general participant of the distributed transaction to the landing time of the submission response of the last general participant through the coordinator node as the distributed transaction submission duration.
[0151] Figure 6 A restore device for a distributed database system according to an embodiment of the present application is used to execute Figure 3The distributed database system restoration method shown in the figure comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the distributed database system restoration method shown in the above-mentioned embodiments.
[0152] According to some embodiments of the present application, a non-volatile computer storage medium of a data processing method is provided, on which a computer executable instruction is stored, and the computer executable instruction is configured to execute the restore method of the distributed database system shown in the above embodiments when executed by a processor.
[0153] Each embodiment in this application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and computer-readable storage medium embodiments, since they are basically similar to the method embodiments, their descriptions are simplified, and the relevant parts can be referred to the partial description of the method embodiments.
[0154] The apparatus, device and computer-readable storage medium provided in the embodiments of the present application correspond one-to-one to the method. Therefore, the apparatus, device and computer-readable storage medium also have similar beneficial technical effects as the corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the apparatus, device and computer-readable storage medium will not be repeated here.
[0155] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0156] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0157] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0159] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0160] 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.
[0161] 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, 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 technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage 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. In addition, although the operations of the method of the present invention are described in a particular order in the accompanying drawings, this does not require or imply that these operations must be performed in this particular order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step, and / or one step can be decomposed into multiple steps.
[0162] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims.
Claims
1. A method for restoring a distributed database system, characterized in that: The distributed database system includes a coordinator node and a plurality of data nodes, and the method includes: Obtaining a restore instruction, wherein the restore instruction is used to instruct to restore each data node of the distributed database system to a target time point; Obtaining full backup data and incremental logs of each data node according to the target time point; Determine a trusted time period and an untrusted time period at the target time point; the trusted time period at the target time point means that all transactions submitted in the corresponding time period have completed global log landing before the target time point, and the untrusted time period at the target time point means that there is at least one distributed transaction in the corresponding time period that cannot be determined whether it will be submitted or rolled back based on the logs before the target time point; Using the full backup data of each data node as a restoration starting point, and rolling back or executing transactions initiated and submitted by each data node within the trust time period according to the incremental log of each data node; Performing matching processing on the pending matching transactions based on a preset matching strategy, wherein the pending matching transactions are transactions initiated and submitted by each data node within the untrusted time period; The matching process of the matching transaction based on the preset matching strategy includes: If the first transaction in the transactions to be matched is a non-distributed transaction, replaying the first transaction; If all branch transactions corresponding to the second transaction in the transaction to be matched are implemented within the trust time period at the target time point, replaying the second transaction; If the global log and all branch logs corresponding to the third transaction in the transactions to be matched exist, replaying the third transaction; and, The remaining transactions in the to-be-matched transactions are not replayed.
2. The method according to claim 1, characterized in that: Determining a trusted time period and an untrusted time period at the target time point includes: Determine the transaction commit duration of multiple distributed transactions according to the incremental logs of each data node; The transaction commit start time point and the transaction commit completion time point corresponding to the transaction commit time longer than the preset value are recorded in the distributed transaction time consumption table; Determine a first time point according to the distributed transaction time consumption table, where the first time point is a trust divergence time point of the target time point; The trusted time period and the untrusted time period of the target time point are divided according to the target time point and the first time point.
3. The method according to claim 2, characterized in that The determining the first time point according to the distributed transaction time consumption table includes: Searching for a distributed transaction that meets a first preset condition according to the distributed transaction time-consuming table, wherein the first preset condition is that the transaction start commit time point is before ts and the corresponding transaction completion commit time point is after t, wherein t is the target time point and s is the preset value; The first time point is determined to be the earliest transaction commit start time among the distributed transactions that meet the first preset condition, or a time point before the earliest transaction commit start time.
4. The method according to claim 3, characterized in that The determining the first time point according to the distributed transaction time consumption table further includes: If no distributed transaction meeting the first preset condition can be found in the distributed transaction time-consuming table, the first time point is determined to be ts or any time point before ts, wherein t is the target time point and s is the preset value.
5. The method according to claim 2, characterized in that: The determining the transaction commit duration of the plurality of distributed transactions according to the incremental logs of the respective data nodes includes: If the distributed transaction consists of multiple two-phase branch transactions and one global transaction, the time difference between the first prepare record of the two-phase branch transaction of the distributed transaction and the log record of the global transaction is calculated by the coordinator node as the transaction commit duration of the distributed transaction; or, If the distributed transaction is executed by a general participant and a last participant, and the general participant adopts a two-phase commit protocol and the last participant adopts a one-phase commit protocol, the time difference from the first prepare record of the general participant of the distributed transaction to the commit response of the last participant is calculated by the coordinator node as the transaction commit duration of the distributed transaction.
6. The method according to claim 1, characterized in that The method further includes the step of determining the third transaction from the transactions to be matched, including: Determine a second time point according to the distributed transaction time consumption table, where the second time point is a trust divergence time point of the first time point; In the incremental logs between the second time point and the target time point of each data node, determining whether there are global logs and all branch logs corresponding to any one or more distributed transactions; If so, it is determined that any one or more distributed transactions are the third transactions.
7. The method according to claim 6, characterized in that The determining the second time point according to the distributed transaction time consumption table includes: Searching for a second distributed transaction according to the distributed transaction time-consuming table, determining that the second time point is the earliest transaction start commit time in the second distributed transaction or a time point before the earliest transaction start commit time, wherein the transaction start commit time point of the second distributed transaction is before t1-s, and the transaction completion commit time is after t1; and, If the second distributed transaction cannot be found in the distributed transaction time-consuming table, the second time point is determined to be t1-s or a time point before t1-s, where t1 is the first time point and s is a preset value.
8. The method according to claim 6, characterized in that The determining the second time point according to the distributed transaction time consumption table further includes: Replacing t with ta to determine the first time point; and / or replacing t1 with t1-a to determine the second time point; Among them, t is the target time point, a is a preset time deviation, and t1 is the first time point.
9. The method according to claim 1, characterized in that: The method further comprises: During the matching process, constraint processing is performed on two or more transactions having a dependency relationship.
10. The method according to claim 1, characterized in that Before restoring the distributed database system, the method further includes: Constructing a full backup of each data node to obtain the full backup data; and obtaining the incremental log of each data node.
11. The method according to claim 10, characterized in that The step of constructing a full backup of each data node includes: After each data node completes all two-phase transactions of the currently processed distributed transaction, the data node is locked, and after the locking, each data node is fully backed up.
12. The method according to claim 10, characterized in that The step of constructing a full backup of each data node further includes: Performing a first full backup on each of the data nodes at a first full backup time point; Determine an untrusted time period at the first full backup time point, and obtain a first incremental log set of each data node in the untrusted time period at the first full backup time point; Analyzing the first incremental log set to obtain pending transactions that are in a prepared state but have not been committed or rolled back; The pending transaction is replayed on the data obtained according to the first full backup, thereby constructing a full backup of each data node.
13. The method according to claim 10, characterized in that The step of constructing a full backup of each data node includes: Performing a second full backup on each of the data nodes at the second full backup time point; Determine the untrusted time period of the second full backup time point, and obtain the second incremental log set of each data node from the start time point of the untrusted time period of the second full backup time point to any time point after the second full backup is completed; The second incremental log set is replayed fault-tolerantly on the data obtained according to the second full backup.
14. The method according to claim 13, characterized in that Also includes: Determine a trust divergence time point of the full backup time point, and all transactions in a prepared state before the trust divergence time point can be determined to be committed or rolled back through the incremental logs before the full backup time point; The untrusted time period of the full backup time point is determined according to the trust divergence time point of the full backup time point.
15. The method according to claim 2, characterized in that Determining a first time point according to the distributed transaction time consumption table includes: The coordinator time t′=tm is determined according to the preset time deviation m and the target time point t, wherein the preset time deviation m is used to indicate the maximum time deviation between any two data nodes of the distributed database system: Determine the trust divergence time point t1′ of the coordinator time t′ according to the distributed transaction time consumption table; The first time point t1=t1′-m is determined according to the trust divergence time point t1′ of the preset time deviation m and the coordinator time t′.
16. The method according to claim 15, characterized in that Determining the trust divergence time point t1′ of the coordinator time t′ according to the distributed transaction time consumption table includes: According to the distributed transaction time-consuming table, a distributed transaction that meets the third preset condition is searched, wherein the third preset condition is that the transaction start submission time point is before t′-s and the corresponding transaction completion submission time is after t′, wherein s is a preset value; wherein, If there is a distributed transaction that meets the third preset condition, determine the earliest transaction start commit time or a time point before the earliest transaction start commit time as the trust divergence time point t1′ of the coordinator time t′; If the distributed transaction that meets the preset condition does not exist, the time point t′-s or before t′-s is determined as the trust divergence time point t1′ of the coordinator time t′.
17. The method according to claim 15, characterized in that Dividing the trusted time period and the untrusted time period of the target time point according to the target time point and the first time point further includes: The untrusted time period [t1, t+m] of the target time point is divided according to the target time point t, the time deviation m and the first time point t1.
18. The method according to claim 1, characterized in that The matching process of the to-be-matched transaction based on the preset matching strategy includes: If the fourth transaction in the to-be-matched transactions is a non-distributed transaction, replaying the fourth transaction; If the fifth transaction in the to-be-matched transactions is a distributed transaction, and the global log corresponding to the fifth transaction is landed before the target time point, then replay the fifth transaction; and, The remaining transactions in the to-be-matched transactions are not replayed.
19. The method according to claim 18, characterized in that Playing back the fifth transaction further includes: If the branch transactions corresponding to the fifth transaction have all been committed within the untrusted time period at the target time point, directly replay the fifth transaction; If one or more branch transactions corresponding to the fifth transaction are not committed within the untrusted time period at the target time point, after replaying the committed global transaction and branch transactions corresponding to the fifth transaction, the one or more branch transactions that have not been committed are committed on the corresponding data nodes.
20. The method according to any one of claims 2-4 or 10-19, characterized in that: The determining the transaction commit duration of the plurality of distributed transactions according to the incremental logs of the respective data nodes includes: The coordinator node calculates the time difference between the preparation record of the first general participant of the distributed transaction and the landing time of the submission response of the last general participant as the transaction submission duration of the distributed transaction.
21. A restoration device for a distributed database system, characterized in that: The distributed database system includes a coordinator node and a plurality of data nodes, and the device includes: An instruction unit, used for obtaining a restore instruction, wherein the restore instruction is used for instructing to restore each data node of the distributed database system to a target time point; An acquisition unit, configured to acquire the full backup data and incremental logs of each data node according to the target time point; A determination unit, used to determine a trusted time period and an untrusted time period at the target time point; the trusted time period at the target time point means that all transactions submitted in the corresponding time period have completed global log landing before the target time point, and the untrusted time period at the target time point means that there is at least one distributed transaction in the corresponding time period that cannot be determined whether to be submitted or rolled back based on the log before the target time point; A first restoration unit, configured to use the full backup data of each data node as a restoration starting point, and to roll back or execute transactions initiated and submitted by each data node within the trust time period according to the incremental log of each data node; A second restoration unit is used to perform matching processing on the pending matching transactions based on a preset matching strategy, where the pending matching transactions are transactions initiated and submitted by each data node within the untrusted time period; The second reduction unit is further used for: If the first transaction in the transactions to be matched is a non-distributed transaction, replaying the first transaction; If all branch transactions corresponding to the second transaction in the transaction to be matched are implemented within the trust time period at the target time point, replaying the second transaction; If the global log and all branch logs corresponding to the third transaction in the transactions to be matched exist, replaying the third transaction; and, The remaining transactions in the to-be-matched transactions are not replayed.
22. The device according to claim 21, characterized in that The determining unit is further configured to: Determine the transaction commit duration of multiple distributed transactions according to the incremental logs of each data node; The transaction commit start time point and the transaction commit completion time point corresponding to the transaction commit time longer than the preset value are recorded in the distributed transaction time consumption table; Determine a first time point according to the distributed transaction time consumption table, where the first time point is a trust divergence time point of the target time point; The trusted time period and the untrusted time period of the target time point are divided according to the target time point and the first time point.
23. The device according to claim 22, characterized in that The determining unit is further configured to: Searching for a distributed transaction that meets a first preset condition according to the distributed transaction time-consuming table, wherein the first preset condition is that the transaction start commit time point is before ts and the corresponding transaction completion commit time point is after t, wherein t is the target time point and s is a preset value; The first time point is determined to be the earliest transaction commit start time among the distributed transactions that meet the first preset condition, or a time point before the earliest transaction commit start time.
24. The device according to claim 23, characterized in that The determining unit is further configured to: If no distributed transaction meeting the first preset condition can be found in the distributed transaction time-consuming table, the first time point is determined to be ts or a time point before ts, wherein t is the target time point and s is the preset value.
25. The device according to claim 22, characterized in that The determining unit is further configured to: If the distributed transaction consists of multiple two-phase branch transactions and one global transaction, the time difference between the first prepare record of the two-phase branch transaction of the distributed transaction and the log record of the global transaction is calculated by the coordinator node as the transaction commit duration of the distributed transaction; or, If the distributed transaction is executed by a general participant and a last participant, and the general participant adopts a two-phase commit protocol and the last participant adopts a one-phase commit protocol, the time difference from the first prepare record of the general participant of the distributed transaction to the commit response of the last participant is calculated by the coordinator node as the transaction commit duration of the distributed transaction.
26. The device according to claim 21, characterized in that The second reduction unit is also used for: Determine a second time point according to the distributed transaction time consumption table, where the second time point is a trust divergence time point of the first time point; In the incremental logs between the second time point and the target time point of each data node, determining whether there are global logs and all branch logs corresponding to any one or more distributed transactions; If so, it is determined that any one or more distributed transactions are the third transactions.
27. The device according to claim 26, characterized in that The second reduction unit is also used for: Searching for a second distributed transaction according to the distributed transaction time-consuming table, determining that the first time point is the earliest transaction start commit time in the second distributed transaction or a time point before the earliest transaction start commit time, wherein the transaction start commit time point of the second distributed transaction is before t1-s, and the transaction completion commit time is after t1; and, If the second distributed transaction cannot be found in the distributed transaction time-consuming table, the second time point is determined to be t1-s or a time point before t1-s, where t1 is the first time point and s is a preset value.
28. The device according to claim 26, characterized in that The second reduction unit is also used for: Replacing t with ta to determine the first time point; and / or replacing t1 with t1-a to determine the second time point; Among them, t is the target time point, a is a preset time deviation, and t1 is the first time point.
29. The device according to claim 21, characterized in that The device is also used for: During the matching process, constraint processing is performed on two or more transactions having a dependency relationship.
30. The device according to claim 21, characterized in that The device also includes a backup unit, which is used for: Constructing a full backup of each data node to obtain the full backup data; and obtaining the incremental log of each data node.
31. The device according to claim 30, characterized in that The backup unit is also used for: After each data node completes all two-phase transactions of the currently processed distributed transaction, the data node is locked, and after the locking, each data node is fully backed up.
32. The device according to claim 30, characterized in that The backup unit is also used for: Performing a first full backup on each of the data nodes at a first full backup time point; Determine an untrusted time period at the first full backup time point, and obtain a first incremental log set of each data node in the untrusted time period at the first full backup time point; Analyzing the first incremental log set to obtain pending transactions that are in a prepared state but have not been committed or rolled back; The pending transaction is replayed on the data obtained according to the first full backup, thereby constructing a full backup of each data node.
33. The device according to claim 30, characterized in that The backup unit is also used for: Performing a second full backup on each of the data nodes at the second full backup time point; Determine the untrusted time period of the second full backup time point, and obtain the second incremental log set of each data node from the start time point of the untrusted time period of the second full backup time point to any time point after the second full backup is completed; The second incremental log set is replayed fault-tolerantly on the data obtained according to the second full backup.
34. The device according to claim 33, characterized in that Also includes: Determine a trust divergence time point of the full backup time point, and all transactions in a prepared state before the trust divergence time point can be determined to be committed or rolled back through the incremental logs before the full backup time point; The untrusted time period of the full backup time point is determined according to the trust divergence time point of the full backup time point.
35. The device according to claim 22, characterized in that The determining unit is further configured to: The coordinator time t′=tm is determined according to the preset time deviation m and the target time point t, wherein the preset time deviation m is used to indicate the maximum time deviation between any two data nodes of the distributed database system: Determine the trust divergence time point t1′ of the coordinator time t′ according to the distributed transaction time consumption table; The first time point t1=t1′-m is determined according to the trust divergence time point t1′ of the preset time deviation m and the coordinator time t′.
36. The device according to claim 35, characterized in that The determining unit is further configured to: According to the distributed transaction time-consuming table, a distributed transaction that meets the third preset condition is searched, wherein the third preset condition is that the transaction start submission time point is before t′-s and the corresponding transaction completion submission time is after t′, wherein s is a preset value; wherein, If there is a distributed transaction that meets the third preset condition, determine the earliest transaction start commit time or a time point before the earliest transaction start commit time as the trust divergence time point t1′ of the coordinator time t′; If the distributed transaction that meets the preset condition does not exist, the time point t′-s or before t′-s is determined as the trust divergence time point t1′ of the coordinator time t′.
37. The device according to claim 35, characterized in that The determining unit is further configured to: The untrusted time period [t1, t+m] of the target time point is divided according to the target time point t, the time deviation m and the first time point t1.
38. The device according to claim 22, characterized in that The second reduction unit is also used for: If the fourth transaction in the to-be-matched transactions is a non-distributed transaction, replaying the fourth transaction; If the fifth transaction in the to-be-matched transactions is a distributed transaction, and the global log corresponding to the fifth transaction is landed before the target time point, then replay the fifth transaction; and, The remaining transactions in the to-be-matched transactions are not replayed.
39. The device according to claim 38, characterized in that The second reduction unit is also used for: If the branch transactions corresponding to the fifth transaction have all been committed within the untrusted time period at the target time point, directly replay the fifth transaction; If one or more branch transactions corresponding to the fifth transaction are not committed within the untrusted time period at the target time point, after replaying the committed global transaction and branch transactions corresponding to the fifth transaction, the one or more branch transactions that have not been committed are committed on the corresponding data nodes.
40. The device according to any one of claims 22-24 or 30-39, characterized in that The determining the transaction commit duration of the plurality of distributed transactions according to the incremental logs of the respective data nodes includes: The coordinator node calculates the time difference between the preparation record of the first general participant of the distributed transaction and the landing time of the submission response of the last general participant as the transaction submission duration of the distributed transaction.
41. A restoration device for a distributed database system, characterized in that: include: at least one processor; And, a memory communicatively connected to at least one processor; wherein the memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor to enable at least one processor to execute: a method as described in any one of claims 1-20.
42. A computer-readable storage medium storing a program, which, when executed by a multi-core processor, causes the multi-core processor to execute the method according to any one of claims 1 to 20.
