Cluster flashback recovery method for distributed database based on multi-version control
By introducing the concepts of data forbidden areas and data black holes in distributed databases, historical version data are stored uniformly, solving the complexity and consistency problems of cluster-level flashback management in the existing technology, and realizing second-level cross-server flashback recovery and data consistency.
Patent Information
- Application Number
- CN202410944307.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-15
AI Technical Summary
Existing database flashback technology is difficult to achieve unified management in distributed database clusters, and most flashback recovery operations require different data sources, resulting in increased management complexity and cost, making it impossible to achieve cluster-level unified flashback recovery.
Using a method based on multi-version control, through the concepts of data forbidden areas and data black holes, uncommitted data is marked and managed to ensure transaction consistency, and historical version data are uniformly stored in the same location to achieve cluster-level flashback recovery.
It achieves unified management of distributed database clusters, avoids errors caused by uncommitted data, simplifies the management of historical version data, ensures transaction consistency, and completes flashback recovery of multiple database instances across servers in seconds. .
Smart Images

Figure CN118467512B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a data recovery method for a distributed database, and more specifically, the present invention mainly relates to a cluster flashback recovery method for a distributed database based on multi-version control. Background Art
[0002] Database flashback is a unique data recovery solution that can reverse logical and physical errors by selectively and effectively eliminating the impact of errors. The main features of database flashback are: 1) the historical status of data can be viewed; 2) flashback can be performed forward or backward along the timeline; 3) it can assist users in error analysis and recovery; 4) the SQL command for executing flashback is relatively simple. The current mainstream database flashback technologies include those based on UNDO mechanism, REDO log, and Binlog. The above common methods have defects to varying degrees. For example, historical version data or logs need to be managed separately, which increases the technical complexity and usage complexity. In addition, separate storage of data and logs also requires additional storage space, which increases the cost of use. When some changes occur in the metadata, the database flashback function may not be implemented. Database flashback technology can be divided into the following categories according to different objects: table flashback, database flashback, and cluster flashback. Oracle database flashback technology is a technical solution based on database log files. It uses a protection mechanism to retain the recovery data required for rollback. When Flashback Database is enabled, the changed data blocks are continuously copied from the database buffer cache to the flashback buffer; then the background process, Recovery Writer, refreshes these data to the flashback log file on the disk. The flashback process is: extract the flashback log--> copy the block image back to the data file. Oracle table flashback obtains the required flashback data from the undo data (undo data is the information required to reverse the result of the DML statement. As long as a transaction modifies the data, the original data before the update will be written into an undo segment). However, the disadvantage of Oracle database flashback is that the data required for flashback needs to be obtained from the undo segment (undo data) or flashback log. Therefore, the flashback objects are different, and the data sources required for flashback are also different, which cannot be managed uniformly. Therefore, it is necessary to further study and improve the cluster flashback technology of distributed databases. Summary of the invention
[0003] One of the purposes of the present invention is to address the above-mentioned shortcomings and provide a cluster flashback recovery method for a distributed database based on multi-version control, in the hope of solving the technical problems that similar technologies in the prior art can only implement library-level flashback and table-level flashback operations at most, and most flashback recovery operations require different data sources, which is not convenient for unified management.
[0004] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0005] On one hand, the present invention provides a cluster flash recovery method for a distributed database based on multi-version control, the method comprising the following steps:
[0006] Step A: When a distributed database cluster flashback recovery request is received, determine whether there is a data forbidden zone in the current distributed database cluster; if the determination result is yes, clear all data in the data forbidden zone; if the determination result is no, execute step B.
[0007] Step B, start the cluster flashback recovery operation, and then further determine whether the timestamp specified in the current flashback recovery request is within a reasonable time range; if the determination result is no, end the method; if the determination result is yes, flashback the distributed database cluster to the data state corresponding to the timestamp specified in the current flashback recovery request.
[0008] The above-mentioned data forbidden zone is the time domain between the current time point and the checkpoint; the above-mentioned reasonable time zone is the time domain between the above-mentioned checkpoint and the garbage collection survival time point; the above-mentioned data forbidden zone is the data marked in each node of the distributed database that has not completed the write intention due to unexpected termination.
[0009] Preferably, a further technical solution is that the current data in each node of the distributed database and the historical data used for flashback recovery are stored in the same location in the distributed database node.
[0010] A further technical solution is: there is a data black hole between the checkpoint and the garbage collection survival time point, and the data black hole is also a time domain. The time domain where the data black hole is located is closer to the checkpoint, and the timestamp of the historical data in the data black hole is also within the reasonable time area.
[0011] A further technical solution is: the checkpoint is the time point of the data version after all write-intent operations in the cluster of the distributed database are completed.
[0012] A further technical solution is: in the method, when the cluster of the distributed database is restarted due to an accident, the system finds a new checkpoint according to the operation status of each node in the cluster before the restart.
[0013] Another aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and when a computer executes the instructions, the computer executes the above method.
[0014] Compared with the prior art, one of the beneficial effects of the present invention is that by setting a data forbidden zone to mark uncommitted data in a distributed database cluster, it is ensured that data that has not achieved transaction consistency will not appear again in a restarted cluster, thereby ensuring the transaction consistency of the distributed transactional database, thereby avoiding errors caused by uncommitted data during cluster flashback recovery operations. In addition, the data forbidden zone only exists as a time domain in the database cluster, and flashback recovery operations are all obtained from the same location, which makes it more convenient to manage historical version data in the distributed database, and can automatically clean up expired data in the historical version data as needed. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a schematic diagram for illustrating the data version of the present invention.
[0016] Figure 2 Schematic diagram of marking data restricted areas in various data versions.
[0017] Figure 3 It is a schematic diagram of a time axis for illustrating a data restricted zone in one embodiment of the present invention.
[0018] Figure 4 The following is a logic flow chart of a method for illustrating one embodiment of the present invention.
[0019] Figure 5 The figure is a flowchart for describing a restart of a distributed database system in one embodiment of the present invention. DETAILED DESCRIPTION
[0020] The present invention solves the problems existing in the flashback technology in the above background technology and proposes a corresponding solution. Figure 1 As shown in the figure, all modified data will be stored and marked with different versions. When performing a flashback operation, the data with a timestamp less than or equal to "AS OF (current time point)" and closest to the timestamp of all version data is the required data.
[0021] In the technical solution provided by the present invention, all historical version data are placed in the same location. When a flashback operation is performed, the data closest to the timestamp is found from the location according to "AS OF" and the data is returned. By placing the historical version data in the same location, unified management of the flashback data source is achieved, and table flashback, database flashback, and cluster flashback all obtain data from this location. When a DML operation is performed, the historical version data will be marked for deletion. At this time, the data is not actually deleted, but the data can no longer be queried through conventional means (such as select statements) until the GC TTL (garbage collection lifetime) of the data is exceeded. When the GC TTL is exceeded, it will be added to the GC queue to wait for GC, so the data exceeding the GC TTL cannot guarantee data consistency. When a flashback operation is performed, it will be determined whether the flashback timestamp is within the range of GCTTL and the latest checkpoint. If it is not within the range, the flashback fails; if it is within the range, the historical version data of the corresponding timestamp is queried therefrom, and then the corresponding flashback query or flashback recovery operation is performed.
[0022] Two concepts are mentioned in the present invention, namely, data black hole and data forbidden zone.
[0023] The data black hole is a time zone, which means that the data in this zone will not be used under normal circumstances, but the data inside it can still be obtained through certain means (such as performing related flashback operations). Its range is the area between the latest checkpoint and the current flashback point. Figure 3 As shown in the figure, if the distributed database cluster is flashed back to time t1, then the area A2 between t1 and the checkpoint is a data black hole.
[0024] The data forbidden zone is also a time zone, which can be understood as a place to store data write intentions that have not been submitted. The scope of the data forbidden zone is as follows: Figure 3 As shown in the figure, the starting point is the start timestamp of the cluster restart, that is, the current time; the end point is the timestamp of the latest checkpoint (transactions of all nodes are aligned at this moment), such as the timestamp of the checkpoint. Figure 3 The area between the current time t2 and the latest checkpoint is the data forbidden area, and area A1 is the data forbidden area. Data cleanup in the data forbidden area will start the cleanup task when the cluster is started. That is, the data forbidden area is used to save data that has not completed the write intention due to cluster downtime. This data is considered dirty data and will cause problems in the cluster. The data forbidden area ensures that these erroneous data will not be used again after the cluster is restarted, and the data will never be accessible. This ensures the safety of restarting the cluster.
[0025] Since the present invention is aimed at a distributed transactional database, transaction consistency needs to be considered during flashback. When transactions in the entire cluster reach consistency, there will be a checkpoint, and all data before this point will reach consistency, that is, the flashback timestamp must be less than or equal to the checkpoint time to achieve transaction consistency. Data that will not achieve transaction consistency due to some reasons (such as sudden cluster downtime, etc.) will be placed in the data forbidden area. The data in the data forbidden area can never be accessed and can only wait for GC to clear it.
[0026] like Figure 2 As shown in the figure, when the cluster crashes at time T4, V4 as the write direction has not been actually submitted to each node, so the data is dirty data (unsubmitted data). When the cluster is restored, the data cannot be restored, otherwise it will cause data inconsistency in the cluster. Therefore, V3 and V4 cannot appear in the cluster again, and V3 and V4 are placed in the data restricted area. The above is the data writing situation of a certain table. The cluster may have multiple data writing and changes at the same time. All data that has not been submitted to each node needs to be placed in the data restricted area.
[0027] The present invention will be further described below in conjunction with the accompanying drawings.
[0028] refer to Figure 4 As shown, one embodiment of the present invention is a cluster flashback recovery method of a distributed database based on multi-version control. The method uses the above-mentioned data forbidden zone and is executed according to the following steps:
[0029] S1. When some special situations occur, such as a sudden system crash, the user sends a request to the distributed database system to flash back to the historical version. When the system receives the distributed database cluster flashback recovery request, it first determines whether there is a data restricted area in the current distributed database cluster.
[0030] If the judgment result is yes, then all data in the data forbidden area is cleared. If the judgment result is no, then the next step is executed.
[0031] S2. Start the cluster flashback recovery operation, and then further determine whether the timestamp specified in the current flashback recovery request is within a reasonable time range.
[0032] If the judgment result is yes, the distributed database cluster is flashbacked to the data state corresponding to the timestamp specified in the current flashback recovery request. If the judgment result is no, the method ends.
[0033] As mentioned above, the data forbidden zone in this embodiment is the time domain between the current time point and the checkpoint; the data forbidden zone is the data in each node of the distributed database that is marked as not completing the write intention due to unexpected termination. The reasonable time zone is the time domain between the checkpoint and the garbage collection survival time point;
[0034] Specifically, in this embodiment, the current data in each node of the distributed database and the historical data used for flashback recovery are stored in the same location in the distributed database node; and there is a data black hole between the above checkpoint and the garbage collection survival time point, and the data black hole is also a time domain, the time domain where the data black hole is located is closer to the checkpoint, and the timestamp of the historical data in the data black hole is also within the reasonable time area. The checkpoint is the time point where the data version is located after all write-intent operations in the distributed database cluster are completed.
[0035] exist Figure 4 In the flashback operation, when executing SQL statements such as deletion and update, the historical version data will not be cleared immediately, but marked as "deleted" and placed in a unified location. The data in this location is the data source required for the flashback operation. When the data in the above location reaches the GC TTL, the real clearing operation will be performed on these data. When receiving a data flashback request, first determine whether the flashback timestamp is within the range of the latest checkpoint and GC TTL (that is, the above reasonable flashback area). If it is out of range, the flashback fails and an error is prompted; if it is not out of range, the data closest to the flashback timestamp is returned according to the flashback request.
[0036] refer to Figure 5 As shown, based on the above-mentioned embodiment of the present invention, when the cluster of the distributed database is restarted unexpectedly, the system finds a new checkpoint according to the operation status of each node in the cluster before the restart, and then marks the data with the intention of completing the write after the checkpoint as a "data forbidden zone identifier", that is, these databases are placed in the time domain of the data forbidden zone, and then during the execution of the above-mentioned flashback recovery method, these marked data are added to the GC clear queue for removal. When the flashback timestamp is in the data forbidden zone, an error will be returned directly. And the above-mentioned data marked as "data forbidden zone identifier" is cleared, and the cleared data will not appear again, but will truly disappear.
[0037] The method of the present invention enables cluster-level flashback, which not only enables flashback of data in the cluster, but also preserves the relationship between data tables and ensures transaction consistency.
[0038] Based on the general form of computer software products, another embodiment of the present invention provides a computer-readable storage medium, which stores instructions. When a computer executes the instructions, the computer executes the cluster flash recovery method of a distributed database based on multi-version control in the above embodiment.
[0039] Among them, the computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, RAM (random access memory), ROM (read-only memory), ROM, erasable programmable read only memory (EPROM), registers, hard disks, optical fibers, CD-ROM (compact disc read-only memory), optical storage devices, magnetic storage devices, or any suitable combination of the above, or any other form of computer-readable storage media known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). In the embodiments of the present application, a computer-readable storage medium may be any tangible medium that contains or stores a program, which may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0040] Based on the above embodiments, a distributed transactional database based on a multi-version control mechanism implements cluster-level flashback, which can complete the unified return to a historical moment across multiple database instances across servers in seconds, and ensure data transaction consistency. Multi-version data stores historical version data at different time points, and reads the data closest to the current time point by default. The latest version may store an uncommitted version, which needs to be processed according to the transaction concurrency conflict mechanism; when performing a flashback operation, the data version corresponding to the specified timestamp is the latest version, and all new versions after this version are invisible. Of course, since it is a distributed transactional database, the issue of transaction consistency also needs to be considered when performing a flashback operation. This proposal proposes the concept of a data forbidden area based on the flashback data black hole. The data forbidden area is a time area, indicating that the MVCC data in this area may be uncommitted and transactionally inconsistent data. When performing a cluster flashback operation, only the records of the data forbidden area and the data black hole need to be registered in the cluster metadata. After the cluster flashback is completed, the data in the data forbidden area must be skipped regardless of the reading conditions, and the data black hole can skip the area when reading the latest data, or read the data of the data black hole according to a specific timestamp.
[0041] In addition to the above, it should be noted that "one embodiment", "another embodiment", "embodiment", etc. mentioned in this specification refer to the specific features, structures or characteristics described in conjunction with the embodiment included in at least one embodiment generally described in this application. The same expression appearing in multiple places in the specification does not necessarily refer to the same embodiment. Further, when describing a specific feature, structure or characteristic in conjunction with any embodiment, it is claimed that the realization of such feature, structure or characteristic in conjunction with other embodiments also falls within the scope of the present invention.
[0042] Although the present invention is described herein with reference to a number of illustrative embodiments of the present invention, it will be appreciated that those skilled in the art may devise many other modifications and implementations that fall within the scope and spirit of the principles disclosed herein. More specifically, within the scope of the present disclosure, drawings, and claims, a variety of variations and improvements may be made to the components and / or layout of the subject combination layout. In addition to variations and improvements made to the components and / or layout, other uses will also be apparent to those skilled in the art.
Claims
1. A cluster flashback recovery method for a distributed database based on multi-version control, characterized in that The method comprises the following steps: When receiving a distributed database cluster flashback recovery request, determine whether there is a data restricted zone in the current distributed database cluster; If the judgment result is yes, all data in the data restricted area are cleared; If the result of the judgment is no, the cluster flashback recovery operation is started, and then it is further judged whether the timestamp specified in the current flashback recovery request is within a reasonable time range; If the judgment result is yes, the distributed database cluster is flashbacked to the data state corresponding to the timestamp specified in the current flashback recovery request; If the judgment result is no, then the method ends; The data forbidden zone is the time domain between the current time point and the checkpoint; The reasonable time zone is the time domain between the checkpoint and the garbage collection survival time point; The data forbidden area is data in each node of the distributed database that is marked as not completing the write intention due to unexpected termination; The current data in each node of the distributed database and the historical data used for flashback recovery are stored in the same location in the distributed database node; There is also a data black hole between the checkpoint and the garbage collection survival time point, and the data black hole is also a time domain. The time domain where the data black hole is located is closer to the checkpoint, and the timestamp of the historical data in the data black hole is also within the reasonable time area; The checkpoint is the time point of the data version after all write-intent operations in the distributed database cluster are completed.
2. The cluster flashback recovery method of a distributed database based on multi-version control according to claim 1, characterized in that: In the method, when the cluster of the distributed database is restarted due to an accident, the system finds a new checkpoint according to the operation status of each node in the cluster before the restart.
3. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when a computer executes the instructions, the computer executes the method according to claim 1 or 2.
