Database version rollback method, device, electronic device and storage medium

By regularly backing up the database version and making modifications directly on the backed-up version, the problem of low database rollback efficiency in the existing technology is solved and fast and efficient version rollback is achieved.

CN118312501BActive Publication Date: 2024-09-20PINGCAP XINGCHEN (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410733031.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-06
Publication Date
2024-09-20
Estimated Expiration
2044-06-06

AI Technical Summary

Technical Problem

The existing technology requires scanning and copying a large amount of data when the database version is rolled back, resulting in long backup times and low recovery efficiency.

Method used

By backing up the target database at preset intervals, obtain the backed-up database version and make modifications on it, avoiding rebuilding the database and directly obtaining the target rollback version.

Benefits of technology

Significantly improves the efficiency of database rollback, reduces backup and recovery time, and reduces the write load on the new database cluster.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118312501B
    Figure CN118312501B
Patent Text Reader

Abstract

The embodiments of the present application provide a database version rollback method, device, electronic device and storage medium, and the present application can be used in the field of distributed databases. The method includes: receiving a version rollback request for a target database; determining a first creation time of a target rollback version, and determining at least one reference backup version from a saved initial backup version; determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version; and modifying the target backup version to obtain a target rollback version. By backing up the target database at a preset time interval, when the target database needs to be rolled back, the backed-up database version can be directly obtained, and modifications can be made directly on the backed-up database version, without having to rewrite the data into a new database cluster for database construction, which can significantly improve the rollback efficiency of the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a database version rollback method, device, electronic device and storage medium. Background Art

[0002] With the development of information technology, enterprises have higher and higher demands for databases. Most enterprises usually store important data in databases. With the continuous increase of data volume and changes in business needs, database versions need to be rolled back in many cases (for example, when the database update fails, it is necessary to roll back to the available version before the upgrade). Therefore, how to better implement database version rollback is a problem that needs to be solved at present.

[0003] In the prior art, it is generally necessary to scan all the backed-up data in the database system, then read out the data of the version to be rolled back and write it to the backup disk to complete the construction of the database, and finally obtain the database version to be rolled back. However, this solution requires creating a full backup file set by copying data files or disk data blocks, and the full backup often has a large amount of data, which not only leads to a long data backup time, but also leads to too many files that need to be scanned and read when reading and restoring data, which leads to low efficiency of database rollback. Summary of the invention

[0004] The purpose of this application is to solve at least one of the above technical defects. The technical solutions provided by the embodiments of this application are as follows:

[0005] In a first aspect, an embodiment of the present application provides a database version rollback method, including:

[0006] Receive a version rollback request for a target database; wherein the version rollback request includes a version identifier of a target rollback version of the target database;

[0007] Determine the first creation time of the target rollback version based on the version identifier, and determine at least one reference backup version associated with the first creation time from at least one saved initial backup version of the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period;

[0008] Determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version;

[0009] Modify the target backup version to obtain the target rollback version of the target database.

[0010] In an optional embodiment of the present application, the initial backup version is generated in the following manner:

[0011] If an instruction to generate an initial backup version is received, and no initial backup version exists at the current moment, the data stored in the target database at the current moment is obtained, the data stored at the current moment is copied and a corresponding target access link is generated; wherein the target access link is used to access the data stored at the current moment; and the target database version corresponding to the target access link is used as the initial backup version;

[0012] If an instruction to generate an initial backup version is received and there is at least one initial backup version at the current moment, the key-value pairs generated between the current moment and the time when the previous initial backup version was created are copied, and the initial backup version at the current moment is generated based on each key-value pair and the previous initial backup version.

[0013] In an optional embodiment of the present application, if at least one initial backup version is created after the first creation moment;

[0014] Determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version specifically includes:

[0015] Taking the reference backup version corresponding to the second creation time which is after the first creation time and closest to the first creation time as the target backup version;

[0016] Modify the target backup version to obtain the target rollback version of the target database, including:

[0017] Delete the data in the target backup version that does not belong to the target rollback version to obtain the target rollback version.

[0018] In an optional embodiment of the present application, deleting data in the target backup version that does not belong to the target rollback version specifically includes:

[0019] Get the generation timestamp of each key-value pair in the target backup version;

[0020] Delete the key-value pairs whose generation timestamps are between the first creation time and the second creation time.

[0021] In an optional embodiment of the present application, if the second creation time of each initial backup version is before the first creation time;

[0022] Determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version specifically includes:

[0023] Taking the reference backup version corresponding to the second creation time closest to the first creation time as the target backup version;

[0024] Modify the target backup version to obtain the target rollback version of the target database, including:

[0025] Obtain modification records for the target database between the first creation time and the second creation time;

[0026] Replay the modification records of the target backup version to obtain the target rollback version.

[0027] In an optional embodiment of the present application, the modification record is obtained in the following manner:

[0028] Whenever a modification instruction is received for the target database, a timestamp corresponding to the modification instruction is obtained according to the current time;

[0029] Generate a corresponding key-value pair based on the modification instruction, and store the key-value pair and the corresponding timestamp in the target database;

[0030] A corresponding modification record is generated based on the modification instruction, and the modification record is stored.

[0031] In an optional embodiment of the present application, the method further specifically includes:

[0032] When any initial backup version is generated, the modification records before the creation time of any initial backup version are deleted.

[0033] In a second aspect, an embodiment of the present application provides a database version rollback device, including:

[0034] A request receiving module, used to receive a version rollback request for a target database; wherein the version rollback request includes a version identifier of a target rollback version of the target database;

[0035] A first backup selection module is used to determine the first creation time of the target fallback version based on the version identifier, and determine at least one reference backup version associated with the first creation time from at least one saved initial backup version of the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period;

[0036] A second backup selection module, configured to determine a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version;

[0037] The version rollback module is used to modify the target backup version to obtain the target rollback version of the target database.

[0038] In an optional embodiment of the present application, the device further includes an initial backup version generation module, which is specifically used to:

[0039] If an instruction to generate a first backup version is received, and no initial backup version exists at the current moment, the data stored in the target database at the current moment is obtained, the data stored at the current moment is copied and a corresponding target access link is generated; wherein the target access link is used to access the data stored at the current moment; and the target database version corresponding to the target access link is used as the initial backup version;

[0040] If an instruction to generate a first backup version is received and there is at least one initial backup version at the current moment, the key-value pairs generated between the current moment and the time when the previous initial backup version was created are copied, and the initial backup version at the current moment is generated based on each key-value pair and the previous initial backup version.

[0041] In an optional embodiment of the present application, the second backup selection module is specifically used to:

[0042] Taking the reference backup version corresponding to the second creation time which is after the first creation time and closest to the first creation time as the target backup version;

[0043] Modify the target backup version to obtain the target rollback version of the target database, including:

[0044] Delete the data in the target backup version that does not belong to the target rollback version to obtain the target rollback version.

[0045] In an optional embodiment of the present application, the second backup selection module is further used to:

[0046] Get the generation timestamp of each key-value pair in the target backup version;

[0047] Delete the key-value pairs whose generation timestamps are between the first creation time and the second creation time.

[0048] In an optional embodiment of the present application, the second backup selection module may also be used to:

[0049] Taking the reference backup version corresponding to the second creation time closest to the first creation time as the target backup version;

[0050] Modify the target backup version to obtain the target rollback version of the target database, including:

[0051] Obtain modification records for the target database between the first creation time and the second creation time;

[0052] Replay the modification records of the target backup version to obtain the target rollback version.

[0053] In an optional embodiment of the present application, the device further includes a modification record storage module, which is specifically used to:

[0054] Whenever a modification instruction is received for the target database, a timestamp corresponding to the modification instruction is obtained according to the current time;

[0055] Generate a corresponding key-value pair based on the modification instruction, and store the key-value pair and the corresponding timestamp in the target database;

[0056] A corresponding modification record is generated based on the modification instruction, and the modification record is stored.

[0057] In an optional embodiment of the present application, the device further includes a modification record deletion module, which is specifically used to:

[0058] When any initial backup version is generated, the modification records before the creation time of any initial backup version are deleted.

[0059] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory;

[0060] The processor executes the computer program to implement the method provided in the embodiment of the first aspect or any optional embodiment of the first aspect.

[0061] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method provided in the embodiment of the first aspect or any optional embodiment of the first aspect is implemented.

[0062] The beneficial effects of the technical solution provided by the embodiment of the present application are:

[0063] By backing up the target database at preset time intervals, when the target database needs to be rolled back, the backed-up database version can be directly obtained and modified directly on the backed-up database version, without having to rewrite the data into a new database cluster for database construction, which can significantly improve the database rollback efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in describing the embodiments of the present application.

[0065] Figure 1 A flowchart of a database version rollback method provided in an embodiment of the present application;

[0066] Figure 2A flowchart of a backup version pulling process in an example of an embodiment of the present application;

[0067] Figure 3 A schematic diagram of a process of writing a key-value pair into storage in an example of an embodiment of the present application;

[0068] Figure 4 This is a schematic diagram of an overall process of database version rollback in an example of an embodiment of the present application;

[0069] Figure 5 This is a diagram of an example of a database version rollback interaction process in an example of an embodiment of the present application;

[0070] Figure 6 This is an example diagram of a backup log in an example of an embodiment of the present application;

[0071] Figure 7 This is a schematic diagram of an overall process of data backup in an example of an embodiment of the present application;

[0072] Figure 8 This is a diagram of a data backup interaction process example in an example of an embodiment of the present application;

[0073] Fig. 9 A structural block diagram of a database version rollback device provided in an embodiment of the present application;

[0074] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0075] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.

[0076] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" may be implemented as "A", or as "B", or as "A and B".

[0077] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0078] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.

[0079] Figure 1 A flowchart of a database version rollback method is provided for an embodiment of the present application. The execution subject of the method may be a terminal (such as a computer, a mobile phone, etc.). Figure 1 As shown, the method may include:

[0080] Step S101, receiving a version rollback request for a target database; wherein the version rollback request includes a version identifier of a target rollback version of the target database.

[0081] The target database is the database that needs to be rolled back, and the embodiment of the present application can support various types of databases (such as TiDB, Mysql, Oracle, etc.). The version identifier can be used to represent the generation time of the database.

[0082] Specifically, when it is necessary to perform version rollback on the target database, the version identifier to be rolled back can be selected based on actual needs. After the version identifier is selected, the terminal can receive and process the version rollback request carrying the version identifier.

[0083] Step S102, determining the first creation time of the target fallback version based on the version identifier, and determining at least one reference backup version associated with the first creation time from at least one initial backup version saved for the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period.

[0084] The initial backup version is a historical version of the target database that has been backed up. The reference backup version can be a base version of the target rollback version, and the target rollback version can be obtained by modifying the reference backup version.

[0085] Specifically, when a version rollback request is received, the terminal can first confirm the version that needs to be rolled back for this version rollback request based on the version identifier, and then can find the first creation time of the target rollback version from the historical record. After determining the first creation time, it can determine several reference backup versions corresponding to the second creation time based on the second creation time of each initial backup version (such as obtaining several second creation times close to the first creation time).

[0086] It should be noted that in the embodiment of the present application, the terminal will back up the database regularly, and the technical means used for the backup may be snapshot backup. The principle of snapshot backup is to create a snapshot of the disk of each storage node in the target database, and the creation of the disk snapshot can be completed almost instantly, and a corresponding hyperlink is generated at the same time, through which the historical data at that moment can be accessed. Therefore, snapshots can be created for the disks of all storage nodes in a very short time, that is, the data of the entire database can be backed up in a very short time.

[0087] It should be noted that the time point for backing up the database in the embodiment of the present application needs to meet the consistency of data in each cluster of the target database, and consistency means that the data in each cluster has been synchronized. For example, user A initiates a transfer to user B. At this time, the data in the cluster corresponding to user A decreases, and the data in the cluster corresponding to user B increases at the same time. At this time, the data in the cluster is consistent.

[0088] Step S103: determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version.

[0089] Specifically, since only one of the reference backup versions needs to be modified when the target version is rolled back, it is necessary to select a backup version (i.e., the target backup version) as the basis for modification from the reference backup versions selected in step S102. Generally, in the embodiment of the present application, the reference backup version corresponding to the second creation time that is after the first creation time and closest to the first creation time is used as the target backup version.

[0090] Step S104, modify the target backup version to obtain a target rollback version of the target database.

[0091] Specifically, before obtaining the target rollback version, the embodiment of the present application first needs to add the target backup version to the new cluster. Specifically, Figure 2 As shown in the figure, the target backup version includes the scheduling layer (including management nodes PD1, PD2, and PD3, which are used to manage the database nodes), the computing layer (including computing nodes TiDB1, TiDB2, and TiDB3, which are used to execute modification instructions), and the storage layer (including storage nodes TiKV1, TiKV2, and TiKV3, which are used to store data, and the data is stored in volume sets volume1, volume2, and volume3). When backup is required, br clientbackup (Back up & Restore client backup, data backup client) writes the metadata of the current database into the snapshot backup through EBS (Elastic Block Storage) backup. At the same time, each storage node creates a corresponding disk snapshot and writes it into the snapshot backup, that is, the initial backup version snapshot at the current moment is obtained; when the initial backup version is determined as the target backup version, a new empty cluster will be created first, and then br client restore (Back up & Restore client restore, data recovery client) reads the metadata in the initial backup version and pulls each disk snapshot into the empty cluster, and then pulls up each service to obtain the initial backup version.

[0092] The solution provided in the present application backs up the target database at a preset time interval, so that when the target database needs to be rolled back, the backed-up database version can be directly obtained and modified directly on the backed-up database version, without the need to rewrite the data into a new database cluster for database construction, which can significantly improve the database rollback efficiency.

[0093] In an optional embodiment of the present application, the initial backup version is generated in the following manner:

[0094] If an instruction to generate an initial backup version is received, and no initial backup version exists at the current moment, the data stored in the target database at the current moment is obtained, the data stored at the current moment is copied and a corresponding target access link is generated; wherein the target access link is used to access the data stored at the current moment; and the target database version corresponding to the target access link is used as the initial backup version;

[0095] If an instruction to generate an initial backup version is received and there is at least one initial backup version at the current moment, the key-value pairs generated between the current moment and the time when the previous initial backup version was created are copied, and the initial backup version at the current moment is generated based on each key-value pair and the previous initial backup version.

[0096] The key-value pair is used to record the modification records of the data stored in the target database. In the embodiment of the present application, each modification of the data will be recorded through the key-value pair, and the details can be referred to Table 1.

[0097] Table 1

[0098]

[0099] As shown in Table 1, the first column (timestamp) in Table 1 indicates the time of modification, the second column (operation) indicates the operation type of this modification, the third column (Value) is the key value, indicating the data of this modification, and the fourth column is the record of this modification.

[0100] For the specific writing process, please refer to Figure 3 ,like Figure 3 As shown, the user initiates an instruction to modify a certain data through the database client, and the computing node obtains the current timestamp of initiating the modification instruction through the management node. The computing node then sends the key in the corresponding key-value pair that needs to be written in this modification instruction to the management module. The management node finds the storage node of the corresponding key-value pair based on the key and returns it to the computing node. Finally, the node writes the key-value pair corresponding to this modification instruction to the storage node.

[0101] It should be noted that in the embodiments of the present application, generally speaking, the same key has only one corresponding key value at the same time, but there may be multiple modification records of the key in the disk record of the database. At this time, the key value corresponding to the key at the current time will be determined based on the modification time of each modification record. For example, at time T1, the operation of writing key value V1 to key K is performed, and a record will be generated on the disk at this time.<K_T1,V1> ; Then at time T2, the key K is deleted again, and a record is generated on the disk<K_T2,D> ; Since time T2 is after time T1, the value corresponding to key K is empty at this time.

[0102] Specifically, when it is necessary to generate an initial backup version, the terminal will detect whether there is an initial backup version that has been backed up. If it does not exist, the data in the current target database will be copied and backed up and a target access link will be generated. For example, the backup can be performed by creating a full snapshot of the EBS disk; if it exists, there is no need to copy the data in the current target database. It is only necessary to obtain the modification record (i.e., key-value pair) between the current moment and the moment when the last initial backup version was generated, and then add the modification record to the last initial backup version to obtain the initial backup version at the current moment. For example, the key-value pair can be recorded by using the EBS disk incremental snapshot method and added to the last initial backup version.

[0103] The following is a brief introduction to "EBS disk full snapshot and disk incremental snapshot": A disk full snapshot is a complete copy of a storage volume. When an EBS volume is snapshotted for the first time, the system captures the state of all data on the volume at that moment and stores it in the cloud (the cloud has a corresponding target access connection). This snapshot contains the complete data of all blocks on the volume.

[0104] Disk incremental snapshots only record the data blocks that have changed since the last snapshot. The first time you create a snapshot, it is actually a full snapshot, but subsequent snapshots only save the changed parts. This means that each new incremental snapshot only contains the data blocks that have changed since the last snapshot. Advantages: Save storage space and cost, because only the changed parts need to be saved.

[0105] Proficient use of these two snapshot technologies can help users manage cloud storage resources more efficiently and reduce costs while ensuring data security and recoverability.

[0106] In an optional embodiment of the present application, if at least one initial backup version is created after the first creation moment;

[0107] Determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version specifically includes:

[0108] Taking the reference backup version corresponding to the second creation time which is after the first creation time and closest to the first creation time as the target backup version;

[0109] Modify the target backup version to obtain the target rollback version of the target database, including:

[0110] Delete the data in the target backup version that does not belong to the target rollback version to obtain the target rollback version.

[0111] Specifically, when the terminal detects that there is an initial backup version that has been generated after the first creation moment of the target fallback version, the reference backup version corresponding to the second creation moment that is after the first creation moment and closest to the first creation moment can be directly used as the target backup version. Since the second creation moment of the target backup version is after the first creation moment of the target fallback version, the number of key-value pairs (modification records) in the target backup version is more than the number of key-value pairs in the target fallback version. These extra key-value pairs are key-value pairs that do not belong to the target fallback version, so it is only necessary to delete the key-value pairs whose generation moment is between the first creation moment and the second creation moment (this process can also be called flashback, i.e. data flashback), and the version obtained after deletion is the target fallback version.

[0112] Combine the following Figure 4 , the overall process of applying for database version rollback is introduced, such as Figure 4 As shown, when version rollback is required, first specify the first creation time (represented by ts_restore here) of the target database version to be restored to PITR, and then query whether there is an initial backup version that has been backed up after the first creation time. If so, find the most recent initial backup version after the first creation time, restore the initial backup version to an empty cluster, delete the key-value pairs generated between the first creation time and the second creation time, and you can get the target rollback version; if not, find the most recent initial backup version before the first creation time, restore the initial backup version to an empty cluster, and replay the modification record log between the first creation time and the second creation time to get the target rollback version.

[0113] The following is an example to illustrate: Figure 5 An example diagram of a database version rollback interaction process provided in an embodiment of the present application, such as Figure 5As shown, the backup and recovery client of the target database (ie, BR client in the figure) initiates a data recovery (ie, restores the data to the target version) request. First, a request is initiated to the remote S3 to query whether there is a disk snapshot set (ie, the initial backup version) after the first creation time, and the remote S3 returns the query result to the BR client. If there is a disk snapshot set after the first creation time, then find the snapshot set whose second creation time (ie, ts_snapshot_b) is after the first creation time and closest to the first creation time, and restore the snapshot set to the empty cluster. When the recovery is completed, TiKV will return a message of successful recovery. After that, TiKV pulls the snapshot set from the remote S3 and restores the data to the empty cluster. After that, the data is sorted, that is, inconsistent data is deleted to ensure the data consistency of the entire database cluster. Finally, the data (key-value pairs) generated between the first creation time and the second creation time are deleted, and the data flashback is successful (ie, rollback to the target version).

[0114] If there is no disk snapshot set after the first creation time, find the snapshot set whose second creation time (i.e. ts_snapshot_b) is before the first creation time and closest to the first creation time, and restore the snapshot set to the empty cluster. When the recovery is completed, TiKV will return a message of successful recovery. Then TiKV pulls the snapshot set from the remote S3 and restores the data to the empty cluster. Then, TiKV organizes the data, that is, deletes inconsistent data to ensure the data consistency of the entire database cluster. Finally, obtain the modification record between the first creation time and the second creation time (i.e. MVCC (Multiversion Concurrency Control) transaction log) and replay it. After the replay is successful, the data flashback is successful (i.e., it rolls back to the target version).

[0115] The following is a brief introduction to MVCC technology. After the data is backed up, the target database can directly and continuously back up the row record data (that is, the modification record) in the storage node TiKV as a transaction log. The form of the backup log can be referred to Figure 6 The advantage of using MVCC technology is that when replaying the transaction log during recovery, the backed-up key-value pair data can be written to the corresponding storage node. There is no need to replay the log in order according to the write order, and these records can be directly written to the corresponding storage node in a disordered / parallel manner. Because no matter the order in which the records are written, after all the records are written, the records in the storage layer are searched according to the corresponding timestamps, which will not affect the consistency of the restored data. In addition, there is no problem of lock mutual exclusion when executing SQL (database instructions) during replay, which can greatly improve the speed of replaying logs and reduce the recovery time.

[0116] In an optional embodiment of the present application, deleting data in the target backup version that does not belong to the target rollback version specifically includes:

[0117] Get the generation timestamp of each key-value pair in the target backup version;

[0118] Delete the key-value pairs whose generation timestamps are between the first creation time and the second creation time.

[0119] Specifically, since each key-value pair records the corresponding generation time (ie, timestamp), it is only necessary to delete the key-value pairs whose generation time is between the first creation time and the second creation time to achieve the purpose of deleting the data in the target backup version that does not belong to the target rollback version.

[0120] In an optional embodiment of the present application, if the second creation time of each initial backup version is before the first creation time;

[0121] Determining a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version specifically includes:

[0122] Taking the reference backup version corresponding to the second creation time closest to the first creation time as the target backup version;

[0123] Modify the target backup version to obtain the target rollback version of the target database, including:

[0124] Obtain modification records for the target database between the first creation time and the second creation time;

[0125] Replay the modification records of the target backup version to obtain the target rollback version.

[0126] The modification record may be a data log of a database, and the data log may include a record of adding, deleting, and modifying data.

[0127] Specifically, when the terminal detects that there is no generated initial backup version after the first creation moment of the target rollback version, then the initial backup version with the second creation moment before the first creation moment can only be used as the target backup version for modification. At this time, it is necessary to obtain the reference backup version corresponding to the second creation moment closest to the first creation moment as the target backup version, and obtain all modification records for the target database between the second creation moment and the first creation moment, and then all modification records within the period can be replayed based on the target backup version through PITR (Point-In-Time Recovery, based on point-in-time recovery) technology to obtain the target rollback version.

[0128] It should be noted that since replaying records is essentially rewriting key-value pairs to the database, and in actual operations, the efficiency of deleting key-value pairs in the database is often higher than writing key-value pairs to the database, when conditions permit, it is generally preferred to choose the initial backup version whose second creation time is after the first creation time as the target backup version.

[0129] In an optional embodiment of the present application, the modification record is obtained in the following manner:

[0130] Whenever a modification instruction is received for the target database, a timestamp corresponding to the modification instruction is obtained according to the current time;

[0131] Generate a corresponding key-value pair based on the modification instruction, and store the key-value pair and the corresponding timestamp in the target database;

[0132] A corresponding modification record is generated based on the modification instruction, and the modification record is stored.

[0133] Specifically, since in the previous embodiment, the modification records between the first creation time and the second creation time need to be replayed for the target backup version to obtain the target backup version, the modification records within this period are stored. Specifically, whenever a modification instruction for the target database is received, the timestamp (i.e., the issuance time) and the specific modification record (key-value pair) when the modification instruction is issued are recorded, and then stored in the target database together. The target database can read these modification records when version rollback or other necessary scenarios are required.

[0134] In an optional embodiment of the present application, the method further specifically includes:

[0135] When any initial backup version is generated, the modification records before the creation time of any initial backup version are deleted.

[0136] Specifically, in an embodiment of the present application, after any initial backup version is generated, if a version rollback request is received again and the first creation time of the target rollback version corresponding to the request is after the second creation time of the initial backup version, the initial backup version can be directly used as the target backup version. Therefore, the modification records before the initial backup version do not need to be replayed. At this time, in order to save storage space of the target database, all modification records before the initial backup version can be deleted.

[0137] Combine the following Figure 7 , the overall process of data backup for this application is introduced, such as Figure 7As shown in the figure, when data needs to be backed up, the storage backup function for modification records will be enabled, and the backup time interval t will be set. When the backup time point is reached, a disk snapshot of each storage node will be created first, and all modification records before the disk snapshot creation time point will be deleted. If a backup stop instruction is received later, the data will not be backed up subsequently; if no backup stop instruction is received, the above steps will be repeated again after time t has passed after the current backup is completed.

[0138] The following is an example to illustrate: Figure 8 An example diagram of a data backup interaction process provided in an embodiment of the present application, such as Figure 8 As shown in the figure, the backup and recovery client of the target database (i.e., the BR client in the figure) initiates a data backup request. First, it initiates a request to create a log backup task to PD (management node), and PD returns a message to BR client that the log backup is enabled; then BR client initiates a request to PD to set the GC (memory) recycling time (i.e., the backup time interval), here taking 48 hours as an example, PD returns a message to BR client again that the setting is successful; then, loop operations can be performed according to the settings: 1. When TiKV (storage node) detects that the log backup task is enabled, it backs up the data modification log of this node to the remote S3 for storage to prevent the modification log from being lost locally; 2. Whenever the interval between the consistency points of the computing cluster of the target database exceeds 48 hours, BR client initiates a command to TiKV to create a disk snapshot backup, and TiKV returns a message to BR client that the creation is successful, and also stores the snapshot created this time on the remote S3. After the storage is successful, S3 will also return a message to TiKV that the storage is successful; then BR client will initiate a command to S3 to delete the modification log before the disk snapshot was created, and S3 will return a message to BR client that the deletion is successful after the deletion.

[0139] Fig. 9 A structural block diagram of a database version rollback device provided in an embodiment of the present application, such as Fig. 9 As shown, the database version device 900 may include: a request receiving module 901, a first backup selection module 902, a second backup selection module 903 and a version rollback module 904, wherein:

[0140] The request receiving module 901 is used to receive a version rollback request for a target database; wherein the version rollback request includes a version identifier of a target rollback version of the target database;

[0141] The first backup selection module 902 is used to determine the first creation time of the target rollback version based on the version identifier, and determine at least one reference backup version associated with the first creation time from at least one saved initial backup version of the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period;

[0142] The second backup selection module 903 is used to determine a target backup version from at least one reference backup version based on the first creation time and the second creation time of each reference backup version;

[0143] The version rollback module 904 is used to modify the target backup version to obtain a target rollback version of the target database.

[0144] The solution provided in the present application backs up the target database at a preset time interval, so that when the target database needs to be rolled back, the backed-up database version can be directly obtained and modified directly on the backed-up database version, without the need to rewrite the data into a new database cluster for database construction, which can significantly improve the database rollback efficiency.

[0145] In an optional embodiment of the present application, the device further includes an initial backup version generation module, which is specifically used to:

[0146] If an instruction to generate a first backup version is received, and no initial backup version exists at the current moment, the data stored in the target database at the current moment is obtained, the data stored at the current moment is copied and a corresponding target access link is generated; wherein the target access link is used to access the data stored at the current moment; and the target database version corresponding to the target access link is used as the initial backup version;

[0147] If an instruction to generate a first backup version is received and there is at least one initial backup version at the current moment, the key-value pairs generated between the current moment and the time when the previous initial backup version was created are copied, and the initial backup version at the current moment is generated based on each key-value pair and the previous initial backup version.

[0148] In an optional embodiment of the present application, the second backup selection module is specifically used to:

[0149] Taking the reference backup version corresponding to the second creation time which is after the first creation time and closest to the first creation time as the target backup version;

[0150] Modify the target backup version to obtain the target rollback version of the target database, including:

[0151] Delete the data in the target backup version that does not belong to the target rollback version to obtain the target rollback version.

[0152] In an optional embodiment of the present application, the second backup selection module is further used to:

[0153] Get the generation timestamp of each key-value pair in the target backup version;

[0154] Delete the key-value pairs whose generation timestamps are between the first creation time and the second creation time.

[0155] In an optional embodiment of the present application, the second backup selection module may also be used to:

[0156] Taking the reference backup version corresponding to the second creation time closest to the first creation time as the target backup version;

[0157] Modify the target backup version to obtain the target rollback version of the target database, including:

[0158] Obtain modification records for the target database between the first creation time and the second creation time;

[0159] Replay the modification records of the target backup version to obtain the target rollback version.

[0160] In an optional embodiment of the present application, the device further includes a modification record storage module, which is specifically used to:

[0161] Whenever a modification instruction is received for the target database, a timestamp corresponding to the modification instruction is obtained according to the current time;

[0162] Generate a corresponding key-value pair based on the modification instruction, and store the key-value pair and the corresponding timestamp in the target database;

[0163] A corresponding modification record is generated based on the modification instruction, and the modification record is stored.

[0164] In an optional embodiment of the present application, the device further includes a modification record deletion module, which is specifically used to:

[0165] When any initial backup version is generated, the modification records before the creation time of any initial backup version are deleted.

[0166] Reference below Fig.10 , which shows an electronic device suitable for implementing the embodiments of the present application (for example, Figure 1The electronic device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), wearable devices, etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.10 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0167] The electronic device includes: a memory and a processor, the memory is used to store a program for executing the method described in each of the above method embodiments; the processor is configured to execute the program stored in the memory. The processor here can be referred to as the processing device 1001 described below, and the memory can include at least one of the read-only memory (ROM) 1002, the random access memory (RAM) 1003, and the storage device 1008 described below, as shown below:

[0168] like Fig.10 As shown, the electronic device 1000 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1008 to a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the operation of the electronic device 1000 are also stored. The processing device 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0169] Typically, the following devices may be connected to the I / O interface 1005: an input device 1006 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1007 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1008 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the electronic device 1000 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.10 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0170] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 1009, or installed from the storage device 1008, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment of the present application are executed.

[0171] It should be noted that the computer-readable storage medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may 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 may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0172] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0173] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0174] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device:

[0175] A version rollback request for a target database is received; wherein the version rollback request includes a version identifier of a target rollback version of the target database; a first creation moment of the target rollback version is determined based on the version identifier, and at least one reference backup version associated with the first creation moment is determined from at least one initial backup version saved for the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period; a target backup version is determined from at least one reference backup version based on the first creation moment and a second creation moment of each reference backup version; and the target backup version is modified to obtain a target rollback version of the target database.

[0176] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0177] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0178] The modules or units involved in the embodiments of the present application may be implemented by software or hardware. The name of a module or unit does not limit the unit itself in some cases. For example, the first constraint acquisition module may also be described as a "module for acquiring the first constraint".

[0179] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0180] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0181] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0182] The above descriptions are only some embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A database version rollback method, characterized in that: include: Receive a version rollback request for a target database; wherein the version rollback request includes a version identifier of a target rollback version of the target database; Determining a first creation time of the target rollback version based on the version identifier of the target rollback version, and determining at least one reference backup version associated with the first creation time from at least one saved initial backup version of the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period; Based on the first creation time and the second creation time of each reference backup version, determining a version identifier of a target backup version from the at least one reference backup version, acquiring a backup log of the target backup version based on the version identifier of the target backup version, and generating a target backup version of the target database based on the backup log; Modifying the target backup version to obtain a target rollback version of the target database; If at least one initial backup version is created after the first creation time; The step of modifying the target backup version to obtain a target rollback version of the target database includes: Obtaining the generation timestamp of each key-value pair in the target backup version; Deleting the key-value pairs whose generation timestamps are between the first creation time and the second creation time; wherein each key-value pair is used to record modification records of the data stored in the target database; The method further comprises: Based on the key-value pairs stored in the target database and the generation timestamp of each key-value pair, the key value corresponding to each key is determined.

2. The method according to claim 1, characterized in that The initial backup version is generated in the following way: If an instruction to generate an initial backup version is received, and no initial backup version exists at the current moment, the data stored in the target database at the current moment is obtained, the data stored at the current moment is copied and a corresponding target access link is generated; wherein the target access link is used to access the data stored at the current moment; and the target database version corresponding to the target access link is used as the initial backup version; If an instruction to generate an initial backup version is received and there is at least one initial backup version at the current moment, the key-value pairs generated between the current moment and the moment when the previous initial backup version was created are copied, and the initial backup version of the current moment is generated based on each key-value pair and the previous initial backup version.

3. The method according to claim 1, characterized in that If at least one initial backup version is created after the first creation time; The determining a target backup version from the at least one reference backup version based on the first creation time and the second creation time of each reference backup version includes: The reference backup version corresponding to a second creation time that is after the first creation time and closest to the first creation time is used as the target backup version.

4. The method according to claim 1, characterized in that If the second creation time of each initial backup version is before the first creation time; The determining a target backup version from the at least one reference backup version based on the first creation time and the second creation time of each reference backup version includes: taking a reference backup version corresponding to a second creation time closest to the first creation time as the target backup version; The step of modifying the target backup version to obtain a target rollback version of the target database includes: Acquire modification records for the target database between the first creation time and the second creation time; The modification record is replayed on the target backup version to obtain the target rollback version.

5. The method according to claim 4, characterized in that The modification record is obtained in the following way: Whenever a modification instruction for the target database is received, a timestamp corresponding to the modification instruction is obtained according to the current time; Generate a corresponding key-value pair based on the modification instruction, and store the key-value pair and the corresponding timestamp in a target database; A corresponding modification record is generated based on the modification instruction, and the modification record is stored.

6. The method according to claim 5, characterized in that The method further comprises: When any initial backup version is generated, the modification record before the creation time of any initial backup version is deleted.

7. A database rollback method and device, characterized in that: include: A request receiving module, configured to receive a version rollback request for a target database; wherein the version rollback request includes a version identifier of a target rollback version of the target database; A first backup selection module is used to determine a first creation time of the target fallback version based on a version identifier of the target fallback version, and to determine at least one reference backup version associated with the first creation time from at least one saved initial backup version for the target database; each initial backup version is obtained by backing up the target database at intervals of a preset time period; a second backup selection module, which determines a version identifier of a target backup version from the at least one reference backup version based on the first creation time and the second creation time of each reference backup version, obtains a backup log of the target backup version based on the version identifier of the target backup version, and generates a target backup version of the target database based on the backup log; A version rollback module, used to modify the target backup version to obtain a target rollback version of the target database; If at least one initial backup version is created after the first creation time; The version rollback version is specifically used for: Obtaining the generation timestamp of each key-value pair in the target backup version; Deleting the key-value pairs whose generation timestamps are between the first creation time and the second creation time; wherein each key-value pair is used to record modification records of the data stored in the target database; The key value determination module is used to determine the key value corresponding to each key based on the key value pairs stored in the target database and the generation timestamp of each key value pair.

8. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.