Data flashback methods, devices, electronic equipment and storage media
By receiving data flashback requests and using structured query statements to perform overwrite operations, the problem of accidental modification or deletion of data in the database is solved, the cost of modification and recovery is reduced, and the data flashback process is simplified.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PINGCAP XINGCHEN (BEIJING) TECH CO LTD
- Filing Date
- 2023-05-04
- Publication Date
- 2026-06-30
AI Technical Summary
In existing technologies, it is difficult and costly to modify data that has been mistakenly modified or deleted in a database, and it is also difficult and costly to recover historical data.
By receiving data flashback requests, the system identifies the target data that has been pre-locked in the database and determines the reference data based on the flashback timestamp. It then uses structured query statements to overwrite the target data, enabling simple modification of mistakenly modified or deleted data.
It reduces the difficulty and cost of modifying data that has been mistakenly modified or deleted in the database, and simplifies the data recovery process.
Smart Images

Figure CN116541387B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data flashback method, apparatus, electronic device, and storage medium. Background Technology
[0002] In the database field, MVCC (Multi-version concurrency control) is commonly used to manage the versions of stored data. When a version of stored data is updated (e.g., changing or deleting data), no actual data deletion occurs; only a new version of the data is added. This allows historical data to be retained and enables the reading of historical data from the database.
[0003] However, related technologies cannot use MVCC to modify data in a database that has been accidentally modified or deleted. When users accidentally modify or delete data in the database, the only recourse is to restore from a backup or manually edit the data. This increases the difficulty and cost of modifying and recovering historical data. Summary of the Invention
[0004] This application provides a data flashback method to address the problems in related technologies, such as the high difficulty and cost of modifying data that has been mistakenly modified or deleted in a database, and the high difficulty and cost of restoring historical data in a database.
[0005] Accordingly, embodiments of this application also provide a data flashback device, an electronic device, and a storage medium to ensure the implementation and application of the above methods.
[0006] On one hand, embodiments of this application provide a data flashback method, the method comprising:
[0007] Receive a data flashback request; the data flashback request includes a flashback timestamp;
[0008] Based on the data flashback request, determine the target data in the database that is pre-locked and corresponds to the data flashback request; and determine whether there is reference data in the database corresponding to the flashback timestamp.
[0009] If it is determined that reference data exists in the database, the first overwrite operation is performed on the target data based on the comparison results between the target data and the reference data.
[0010] The database includes a pre-written first structured query statement that performs the first coverage operation.
[0011] On the other hand, embodiments of this application provide a data flashback device, the device comprising:
[0012] The data flashback request receiving module is used to receive data flashback requests; the data flashback request includes a flashback timestamp.
[0013] The flashback operation data determination module is used to determine, based on the data flashback request, the target data in the database that is pre-locked and corresponds to the data flashback request; and to determine whether there is reference data in the database corresponding to the flashback timestamp.
[0014] The flashback operation execution module is used to perform a first overwrite operation on the target data based on the comparison result between the target data and the reference data, provided that reference data exists in the database.
[0015] The database includes a pre-written first structured query statement that performs the first coverage operation.
[0016] On the other hand, embodiments of this application provide an electronic device, including a processor and a memory, which are interconnected;
[0017] The aforementioned memory is used to store computer programs;
[0018] The processor described above is configured to execute the data flashback method provided in the embodiments of this application when the computer program described above is invoked.
[0019] On the other hand, embodiments of this application provide a computer-readable storage medium storing a computer program that is executed by a processor to implement the data flashback method provided in embodiments of this application.
[0020] In this embodiment, by receiving a data flashback request, the system determines the target data in the database that is pre-locked and corresponds to the data flashback request; and by determining whether reference data corresponding to the flashback timestamp exists in the database based on the flashback timestamp in the data flashback request. If reference data exists in the database, a first overwrite operation is performed on the target data based on the comparison result between the target data and the reference data, referencing a pre-written structured query statement in the database that performs a first overwrite operation. This allows modification of the pre-locked target data in the database by executing the first structured query statement, simplifying the operation and reducing the difficulty and cost of modifying data in the database that has been mistakenly modified or deleted. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 A flowchart illustrating a data flashback method provided in an embodiment of this application is shown;
[0023] Figure 2 This illustration shows an application scenario diagram of a data flashback method provided in an embodiment of this application;
[0024] Figure 3 This paper illustrates another flowchart of a data flashback method provided in an embodiment of this application.
[0025] Figure 4 This paper shows a schematic diagram of the structure of a data flashback device provided in an embodiment of this application;
[0026] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0028] As mentioned earlier, in the database field, modifying data that has been mistakenly modified or deleted in a database through backup recovery or manual modification increases the difficulty and cost of modifying data that has been mistakenly modified or deleted.
[0029] Furthermore, in related technologies, data flashback operations on Oracle databases are typically based on undodata, requiring the additional enabling of supplemental logs. Data flashback operations on PolarDB databases are typically based on snapshot backups of PolarFS (Polar File System, FS stands for file system) and redo logs. Specifically, PolarDB recreates a new cluster using a snapshot and then restores the data to a specified point in time based on the redo logs. It is evident that each data flashback operation is relatively complex and difficult to perform.
[0030] To address this, this application provides a data flashback method, which can be applied to a data flashback device. This application does not impose specific limitations on the data flashback device. The data flashback device can be a server or terminal independent of the database, or it can be based on the functions of various components within the database service, using components with corresponding functions as the data flashback device.
[0031] The data flashback method provided in this application embodiment can be applied to databases including but not limited to TiDB databases. In specific execution, the data flashback method provided in this application embodiment can be implemented by combining components such as the database's processing engine (i.e., the component used to perform data calculation operations), storage engine (i.e., the component used to perform data storage), and scheduling engine (i.e., the component used to store metadata and schedule load balancing). Specifically, the processing engine can be used as the aforementioned data flashback device.
[0032] Specifically, the data flashback method provided in this application embodiment can be applied to application scenarios where current data has been mistakenly modified or deleted.
[0033] like Figure 1 As shown, the data flashback method includes:
[0034] Step S110: Receive a data flashback request; the data flashback request includes a flashback timestamp.
[0035] Data flashback: This is a processing method that modifies existing data (i.e., current data) in a database based on historical data.
[0036] In this implementation, a data flashback request can be used to trigger a request to execute the data flashback method. By responding to the data flashback request, the data flashback device can be triggered to perform a data flashback operation.
[0037] Step S120: Based on the data flashback request, determine the target data in the database that is pre-locked and corresponds to the data flashback request; and determine whether there is reference data in the database corresponding to the flashback timestamp.
[0038] The target data can be real-time data in the database when responding to a data flashback request. It can also be real-time data in the database when SQL is written to it. Furthermore, it can be real-time data in the database during the actual data flashback operation. The specific data can be determined based on the actual situation, and this application embodiment does not impose any particular limitations on it.
[0039] In this embodiment of the application, in order to avoid affecting the target data during the execution of the data flashback operation, it is necessary to lock the target data.
[0040] The reference data can be real-time data stored in the database corresponding to the flashback timestamp. Specifically, when determining the reference data based on the flashback timestamp, if real-time data exists in the database at the flashback timestamp, it is determined that reference data exists and is used as the reference data; if real-time data does not exist in the database at the flashback timestamp, it is determined that no reference data exists.
[0041] Wherein, the timestamp corresponding to the target data is later than the timestamp corresponding to the reference time. Step S130: If it is determined that reference data exists in the database, based on the comparison result between the target data and the reference data, a first overwrite operation is performed on the target data.
[0042] The database includes a pre-written first structured query statement that performs the first coverage operation.
[0043] In this embodiment, the operation of executing the entire data flashback method can be referred to as a data flashback operation, and the data required to execute the data flashback operation can be referred to as flashback operation data (for example, flashback operation data may include reference data and target data). When the data flashback method is executed in the manner of a structured query statement, the corresponding structured query statement can be referred to as the SQL for executing the data flashback operation.
[0044] Understandably, data flashback operations may include, but are not limited to, the first overwrite operation. Naturally, the SQL used to perform the data flashback operation may include the first structured query statement.
[0045] The first structured query statement may include a flashback timestamp.
[0046] It is understood that in practical applications, the data flashback device can also be triggered to execute the data flashback method provided in this application embodiment by writing SQL to the database for performing the data flashback operation. Alternatively, SQL for performing the data flashback operation can be pre-written to the database, and the data flashback device can be triggered to execute the data flashback method provided in this application embodiment by updating the flashback timestamp set in the SQL. This application embodiment does not limit the specific triggering mechanism.
[0047] It should be noted that before the data flashback device executes the data flashback method provided in this application embodiment based on the SQL used to perform the data flashback operation, it can also be determined whether the data flashback device meets the execution conditions of the SQL used to perform the data flashback operation. Specifically, the user's permissions for writing the SQL used to perform the data flashback operation can be authenticated, and it can be determined whether the flashback timestamp is within the time period corresponding to the preset time interval of the preset garbage collection mechanism.
[0048] Specifically, a pre-defined list of users can be set up to write SQL statements used for data flashback operations. Upon receiving such SQL statements, the system checks if the current user who wrote them is on the pre-defined list. If the current user is on the list, and the flashback timestamp falls within a pre-defined time interval corresponding to a pre-defined garbage collection mechanism, the SQL statements can be executed, meaning the execution conditions for the data flashback operation are met.
[0049] The garbage collection mechanism, or GC for short, is used to thoroughly remove data from the database whose timestamp is significantly older than the current timestamp. For example, a preset time interval of 30 minutes can be set for garbage collection. This means that if the garbage collection mechanism is set to retain data from the past 30 minutes, data with a time interval greater than 30 minutes between its current and previous timestamps will be deleted. The preset time interval is defined as the period between the current timestamp and the starting point of the preset time interval.
[0050] When overwriting data B based on data A, data A can be placed on top of data B in the storage space corresponding to data B, but data B is not deleted. This achieves the effect of hiding data B and exposing data A in the storage space corresponding to data B.
[0051] Specifically, when performing the first overwrite operation on the target data based on the comparison results of the target data and the reference data, the first overwrite operation on the target data can be achieved in various ways, such as overwriting the target data with the reference data, replacing the target data with the reference data, or modifying the target data based on the reference data. In other words, historical data can be used to modify the current data.
[0052] Specifically, the second overlay operation on the target data based on the comparison results between the target data and the reference data can be implemented in the following way:
[0053] If the target data and the reference data are the same, retain the target data;
[0054] When the target data and the reference data are different, the first overwrite operation is performed on the target data based on the reference data.
[0055] Specifically, when the target data and reference data are identical, the storage space containing the target data indicates that there is no change in the stored data between the flashback timestamp and the target timestamp corresponding to the target data. By retaining the target data—that is, not processing the data in the storage space containing the target data—the available storage space in the storage space containing the target data can be further saved.
[0056] When the target data and reference data differ, it indicates that the storage space containing the target data has changed between the flashback timestamp and the target timestamp corresponding to the target data. A first overwrite operation is performed on the target data based on the reference data; that is, within the storage space containing the target data, the reference data is used to overwrite the target data. This implements the modification operation on the target data, effectively achieving data flashback processing of the target data.
[0057] In this embodiment, by receiving a data flashback request, the system determines the target data in the database that is pre-locked and corresponds to the data flashback request; and by determining whether reference data corresponding to the flashback timestamp exists in the database based on the flashback timestamp in the data flashback request. If reference data exists in the database, a first overwrite operation is performed on the target data based on the comparison result between the target data and the reference data, referencing a pre-written structured query statement in the database that performs a first overwrite operation. This allows modification of the pre-locked target data in the database by executing the first structured query statement, simplifying the operation and reducing the difficulty and cost of modifying data in the database that has been mistakenly modified or deleted.
[0058] Optionally, the above method may further include:
[0059] If it is determined that no reference data exists in the database, a second overwrite operation is performed on the target data based on the clear command;
[0060] The database may also include a pre-written second structured query statement that performs the second coverage operation.
[0061] It should be noted that the data flashback operation described above may also include a second overwrite operation. Naturally, the SQL used to perform the data flashback operation may include a first structured query statement and a second structured query statement.
[0062] The clear command can be a DELETE command. This clear command can be preset before executing the data flashback method.
[0063] When performing a second overwrite operation on target data based on a clear instruction, a clear instruction can be written into the storage space where the target data is located, making the storage space where the target data is located "empty". However, in reality, the storage space where the target data is located still stores "hidden" target data.
[0064] In a database, different storage regions can be set up and associated with servers. Each storage region stores the interaction data between its corresponding server and the clients it serves. Specifically, each storage region can be managed through the database's storage engine.
[0065] Each server can be associated with an actual physical region, and one or more servers can be set up for each physical region. This application does not impose any limitations on this. For example, a region may include five sub-regions, each sub-region can correspond to one server, and each server can correspond to one storage region. That is, a storage region can store the interaction data between the server corresponding to that storage region and the clients within the sub-region corresponding to that server. Figure 2 As shown, storage area a can store the interactive data between server A and clients A1', A2', and A3'.
[0066] Considering that continuously providing services to the corresponding clients or external components through the database during the data flashback operation may cause the database to generate new data, affecting the processing of the data flashback operation, the following optional implementation methods are also provided in this application embodiment:
[0067] Before receiving the data flashback request, the above method may further include:
[0068] Receive data flashback preparation requests and perform data isolation operations on the database; and
[0069] Lock the target storage area in the database.
[0070] The aforementioned data flashback operation may also include the data isolation operation and the operation of locking the target storage area in the database.
[0071] In this embodiment of the application, after receiving the SQL for performing a data flashback operation, the data flashback operation can be implemented in stages by executing the SQL for performing the data flashback operation. For example, a data flashback preparation operation stage (hereinafter referred to as the first stage) and a data flashback execution operation stage (hereinafter referred to as the second stage; wherein, the data flashback execution operation can be, for example, the operation of determining reference data, the operation of determining target data, the first overlay operation, and the second overlay operation mentioned above).
[0072] Specifically, the target storage region associated with the data flashback operation can be specified in the SQL used to perform the data flashback operation, and different data processing requests can be generated based on each operation stage by executing the SQL used to perform the data flashback operation. For example, when performing the data flashback preparation operation stage, the data flashback preparation operation is performed based on the data flashback preparation request; when performing the data flashback execution operation stage, a data flashback execution request (i.e., the aforementioned data flashback request) is generated, and the data flashback execution operation is performed based on the data flashback preparation request.
[0073] Specifically, during the data flashback preparation phase, a data flashback preparation request can be sent to the storage engine, causing the storage engine to perform a data flashback preparation operation on the target storage area; during the data flashback execution phase, a data flashback request can be sent to the storage engine, causing the storage engine to perform a data flashback execution operation on the target storage area.
[0074] By implementing data flashback operations in stages, the consistency of data flashback transactions can also be guaranteed.
[0075] When performing data isolation operations on a database, all data interaction relationships with the database can be severed.
[0076] When locking a target storage area, you can specifically retain the data in the target storage area and prevent new data from being stored in the target storage area.
[0077] In this embodiment of the application, by performing data isolation operations on the database and locking the target storage area in the database, it is possible to avoid interference with the execution process of the data flashback operation due to new data generated by external components.
[0078] Optionally, the above-mentioned data isolation operations for the database may include at least one of the following:
[0079] Disable garbage collection for the database;
[0080] Set the read and write permissions for the database to read-only.
[0081] Close the connection between the database and any external component.
[0082] In this implementation, by disabling the garbage collection mechanism for the database, the accidental deletion of flashback operation data can be avoided if the data flashback operation time exceeds the preset time interval corresponding to the garbage collection mechanism.
[0083] Database read and write permissions can be set using system variables. These permissions can include read-only permissions and read-write permissions (allowing both reading and writing). For example, with a TiDB database, setting the system variable `tidb_super_read_only` to "YES" will set the TiDB database to read-only permissions; setting it to "NO" will set the TiDB database to read-write permissions.
[0084] When closing the connection between the database and any external component, a timestamp can be obtained through the scheduling engine and used as the startTS (start timestamp) for the data flashback operation. Based on the startTS, a connection disconnection command is written into the database to disconnect the database from any external component.
[0085] Understandably, after the data flashback operation is completed, it is possible to restore the various data isolation operations and the related database services. Specifically, this can be done by re-enabling the database's garbage collection mechanism; setting read and write permissions for the database to read and write permissions; and reconnecting the database to any external component.
[0086] In this embodiment of the application, by performing data isolation operations on the database, interference from external data during the data flashback operation can be avoided.
[0087] Optionally, locking the target storage area in the database as described above may include:
[0088] Identify the target row lock corresponding to the target storage area, and perform scanning and rollback operations on the target row lock;
[0089] Identify the user key with the longest time span between the storage timestamp and the flashback timestamp in the target storage area, and lock the identified user key.
[0090] The target row lock can be a row lock in a data table implemented based on MVCC, i.e., MVCC Lock.
[0091] When performing a rollback operation on the scanned target row lock, if the version of the target row lock changes, the information of the previous version of the target row lock can be recorded in the log corresponding to the target row lock, that is, the current version and the previous version information of each target row lock can be obtained.
[0092] During the rollback operation on the target row lock, the data information associated with the flashback timestamp in the target storage area can be further identified.
[0093] It is understood that, in the embodiments of this application, all locks implemented based on MVCC can also be scanned and rollback operations can be performed.
[0094] In the target storage area, the interaction data between the server and the client can be stored using a key-value storage method. The key corresponds to a client identifier, and the key-value pair represents the corresponding interaction data for that client.
[0095] The user key with the longest time span between the storage timestamp and the flashback timestamp in the target storage area is the most recently stored user key in the target storage area.
[0096] When locking a determined user key, a storage area locking instruction can be written into the target storage area based on startTS to lock the determined user key.
[0097] By locking the identified user key, it is possible to prevent the writing of updated data to the target storage area.
[0098] By scanning and rolling back the target row locks, and locking the determined user keys, the target storage area can be locked from both the data table and user data perspectives. This achieves the blocking of read, write, and scheduling operations on the database at the storage area level, preventing external data from interfering with the data flashback operation.
[0099] Understandably, after the data flashback operation is completed, the locked target storage area can be unlocked.
[0100] Optionally, the target data pre-locked in the database corresponding to the data flashback request mentioned above may include:
[0101] Identify the target user key whose key value changed in the target storage area during the time period from the flashback timestamp to the target timestamp; the target timestamp indicates the timestamp at which the identified user key was locked.
[0102] The key value corresponding to the flashback timestamp of the target user key is determined as the target data;
[0103] The above determination of whether reference data corresponding to the flashback timestamp exists in the database may include:
[0104] The key value corresponding to the target timestamp for the target user key is determined as reference data.
[0105] By determining whether each key value in the target storage area has changed within the time period corresponding to the flashback timestamp to the target timestamp, the user key whose key value has changed is identified as the target user key. Furthermore, the key value corresponding to the target timestamp is identified as reference data, and the key value corresponding to the flashback timestamp is identified as the target data. This allows for the precise determination of the flashback operation data corresponding to the data flashback request.
[0106] Optionally, after performing a data flashback operation on the target data, the above method further includes:
[0107] Update the data table corresponding to the target storage area;
[0108] If the version information corresponding to the updated data table is detected, the data table information is generated.
[0109] As described above, when locking a target storage area, you can specifically lock the data tables and user data associated with the target storage area.
[0110] When updating the data table (schema) corresponding to the target storage area, you can specifically update the data table's version (schema version).
[0111] By further detecting the version information of the updated data table, and generating the data table information when the version information corresponding to the updated data table is detected, the success of the data flashback operation can be further verified, and the synchronous update of the data table can be achieved.
[0112] To more clearly illustrate the data flashback method provided in this application's embodiments, the following uses TiDB as an example, combined with the above embodiments and... Figure 3 A detailed explanation of this data flashback method is provided below:
[0113] First, let's introduce the TiDB database:
[0114] TiDB is an open-source distributed HTAP database. A TiDB database service (i.e., a TiDB cluster) can be composed of three basic components: the processing engine TiDB Server, the storage engine TiKV Server, and the scheduling engine PD (Placement Driver) Server.
[0115] The TiDB Server, also known as a TiDB compute node, performs computational operations associated with the TiDB database. The PD Server stores metadata about the TiDB cluster and handles load balancing; it is also known as a TiDB management node. The TiKV Server stores data; it is also known as a TiDB storage node.
[0116] In this embodiment of the application, considering the specific functions of each node in the TiDB database service, the TiDB Server can be used as a data flashback device when performing data flashback operations on data in the TiDB database.
[0117] The specific steps for executing the data flashback method are as follows: Step 1: TiDB Server receives the flashback SQL and determines whether the execution conditions of the flashback SQL are met.
[0118] Step 2: When TiDB Server determines that the conditions for executing flashback SQL are met, it disables GC by executing flashback SQL and sets TiDB Server to read-only mode by setting the value of the system variable tidb_super_read_only to "YES".
[0119] Step 3: TiDB Server obtains startTS through PD, persists startTS, and disconnects the TiDB database from external components.
[0120] Step 4: The TiDB Server sends a flashback prepare request (based on RPC) to the TiKV Server. Upon receiving the flashback prepare request, the TiKV Server blocks read, write, and scheduling operations on the specified regions (i.e., the target storage areas) at the region level, causing the specified regions to enter flashback mode. Specifically:
[0121] a. Scan all MVCC Locks corresponding to TiKV and perform a rollback;
[0122] b. The TiKV Server selects the latest user key from the specified regions and locks the latest user key based on the persistent startTS.
[0123] Step 5: TiDB Server obtains the commitTS (timestamp after the locking operation is completed) through PD, persists the commitTS, and sends a flashback request (data flashback request) based on RPC to TiKV Server. After receiving the flashback request, TiKV Server scans each key-value pair in the specified regions to determine the target user key with version changes in each key-value pair, determines the target data corresponding to the persistent commitTS for the target user key, and determines whether there is reference data corresponding to the flashback timestamp in each target user key. Based on the target data and reference data, it performs a data flashback operation.
[0124] In cases where no reference data corresponding to the flashback timestamp exists in the target user key, the DELETE instruction is written into the key value corresponding to the target user key.
[0125] If there is reference data corresponding to the flashback timestamp in the target user key, and the target data corresponding to the persistent commitTS of the target user key is different from the reference data, the target data is overwritten based on the commitTS and the reference data corresponding to the target user key.
[0126] If a reference data corresponding to the flashback timestamp exists in the target user key, and the target data corresponding to the target user key in commitTS is the same as the reference data, the target data corresponding to the target user key will not be processed.
[0127] Step 6: TiDB Server updates the schema version, and after TiDB Server detects the updated schema version, it regenerates the schema information, completing the schema flashback.
[0128] Step 7: TiDB Server re-enables GC and sets TiDB Server to read-write mode by setting the value of the system variable tidb_super_read_only to "NO".
[0129] Step 8: End the data flashback operation and return a prompt to the client, such as "TiDB database can be re-enabled".
[0130] This data flashback method allows for the direct specification of a flashback timestamp in a single SQL statement within the TiDB database, enabling flashback operations on data and tables. It does not rely on components outside the TiDB database, such as logs or backup data, resulting in a lower learning curve and faster processing speed.
[0131] Furthermore, although this data flashback method can be implemented using a two-phase commit approach, it actually performs the data flashback operation by overwriting data. This does not destroy the historical data in the target storage area; it simply writes a new copy of the data in the target storage area. The timestamps of the data writes are consistent. When multiple flashbacks are required, the data flashback operation can be performed again based on the timestamps corresponding to the data in each storage area. Multiple flashbacks will not affect each other, and the data can be repeatedly flashed back on the timeline, ensuring transaction consistency and making it easier to integrate with ecosystem tools.
[0132] Based on the same principle as the data flashback method provided in the embodiments of this application, the embodiments of this application also provide a data flashback device. For example... Figure 4 As shown, the device 40 includes:
[0133] The data flashback request receiving module 401 is used to receive a data flashback request; the data flashback request includes a flashback timestamp.
[0134] The flashback operation data determination module 402 is used to determine, based on the data flashback request, the target data in the database that is pre-locked and corresponds to the data flashback request; and to determine whether there is reference data in the database corresponding to the flashback timestamp.
[0135] The flashback operation execution module 403 is used to perform a first overwrite operation on the target data based on the comparison result between the target data and the reference data, when it is determined that reference data exists in the database.
[0136] The database includes a pre-written first structured query statement that performs the first coverage operation.
[0137] Optionally, the flashback operation execution module 403 described above can also be used for:
[0138] If it is determined that no reference data exists in the database, a second overwrite operation is performed on the target data based on the clear command;
[0139] The database also includes a pre-written second structured query statement that performs the second coverage operation.
[0140] Optionally, the above-described apparatus may further include a preprocessing module, which can be used for:
[0141] Before receiving a data flashback request, receive a data flashback preparation request and perform data isolation operations on the database; and
[0142] Lock the target storage area in the database.
[0143] Optionally, the preprocessing module described above can be used to lock the target storage area in the database for:
[0144] Identify the target row lock corresponding to the target storage area, and perform scanning and rollback operations on the target row lock;
[0145] Identify the user key with the longest time span between the storage timestamp and the flashback timestamp in the target storage area, and lock the identified user key.
[0146] Optionally, when determining the target data corresponding to the data flashback request that has been pre-locked in the database, the aforementioned flashback operation data determination module 402 can be used to:
[0147] Identify the target user key whose key value changed in the target storage area during the time period from the flashback timestamp to the target timestamp; the target timestamp indicates the timestamp at which the identified user key was locked.
[0148] The key value corresponding to the flashback timestamp of the target user key is determined as the target data;
[0149] The aforementioned flashback operation data determination module 402, when determining whether reference data corresponding to the flashback timestamp exists in the database, can be used for:
[0150] The key value corresponding to the target timestamp of the target user key is determined as the reference data.
[0151] Optionally, when performing data isolation operations on the database, the preprocessing module described above can be used to perform at least one of the following operations:
[0152] Disable garbage collection for the database;
[0153] Set the read and write permissions for the database to read-only.
[0154] Close the connection between the database and any external component.
[0155] Optionally, the above-described apparatus may further include a post-processing module, which can be used for:
[0156] After performing a data flashback operation on the target data, the data table corresponding to the target storage area is updated;
[0157] If the version information corresponding to the updated data table is detected, the data table information is generated.
[0158] The apparatus in this application embodiment can execute the method provided in this application embodiment, and the implementation principle is similar. The actions performed by each module in the apparatus of each embodiment of this application correspond to the steps in the method of each embodiment of this application. For detailed functional descriptions of each module of the apparatus, please refer to the descriptions in the corresponding methods shown above, which will not be repeated here.
[0159] In this embodiment, by receiving a data flashback request, the system determines the target data in the database that is pre-locked and corresponds to the data flashback request; and by determining whether reference data corresponding to the flashback timestamp exists in the database based on the flashback timestamp in the data flashback request. If reference data exists in the database, a first overwrite operation is performed on the target data based on the comparison result between the target data and the reference data, referencing a pre-written structured query statement in the database that performs a first overwrite operation. This allows modification of the pre-locked target data in the database by executing the first structured query statement, simplifying the operation and reducing the difficulty and cost of modifying data in the database that has been mistakenly modified or deleted.
[0160] Based on the same principle as the data flashback method and apparatus provided in the embodiments of this application, the embodiments of this application also provide an electronic device (such as a server), which may include a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement:
[0161] Receive a data flashback request; the data flashback request includes a flashback timestamp;
[0162] Based on the data flashback request, determine the target data in the database that is pre-locked and corresponds to the data flashback request; and determine whether there is reference data in the database corresponding to the flashback timestamp.
[0163] If it is determined that reference data exists in the database, the first overwrite operation is performed on the target data based on the comparison results between the target data and the reference data.
[0164] The database includes a pre-written first structured query statement that performs the first coverage operation.
[0165] In this embodiment, by receiving a data flashback request, the system determines the target data in the database that is pre-locked and corresponds to the data flashback request; and by determining whether reference data corresponding to the flashback timestamp exists in the database based on the flashback timestamp in the data flashback request. If reference data exists in the database, a first overwrite operation is performed on the target data based on the comparison result between the target data and the reference data, referencing a pre-written structured query statement in the database that performs a first overwrite operation. This allows modification of the pre-locked target data in the database by executing the first structured query statement, simplifying the operation and reducing the difficulty and cost of modifying data in the database that has been mistakenly modified or deleted.
[0166] See Figure 5 , Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Figure 5 As shown, the electronic device 500 in this embodiment may include: a processor 501, a network interface 504, and a memory 505. Furthermore, the electronic device 500 may also include: an object interface 503, and at least one communication bus 502. The communication bus 502 is used to implement communication between these components. The object interface 503 may include a display screen and a keyboard; optionally, the object interface 503 may also include a standard wired interface or a wireless interface. The network interface 504 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 505 may be a high-speed RAM or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory 505 may also be at least one storage device located remotely from the aforementioned processor 501. Figure 5 As shown, the memory 505, which is a computer-readable storage medium, may include an operating system, a network communication module, an object interface module, and a device control application.
[0167] exist Figure 5 In the illustrated electronic device 500, the network interface 504 provides network communication functionality; the object interface 503 is primarily used to provide an input interface for objects; and the processor 501 can be used to call the device control application stored in the memory 505 to achieve:
[0168] In some feasible implementations, the processor 501 described above is used for:
[0169] It should be understood that in some feasible implementations, the processor 501 described above may be a central processing unit (CPU), which may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor. The memory may include read-only memory and random access memory, and provides instructions and data to the processor. A portion of the memory may also include non-volatile random access memory. For example, the memory may also store device type information.
[0170] In specific implementation, the aforementioned electronic device 500 can perform the above-described actions through its built-in functional modules. Figure 1 The implementation methods provided for each step are detailed in the above-mentioned implementation methods, and will not be repeated here.
[0171] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to implement... Figure 1 The methods provided in each step are detailed in the implementation methods provided in the above steps, and will not be repeated here.
[0172] The aforementioned computer-readable storage medium can be an internal storage unit of the data flashback device or electronic device provided in any of the foregoing embodiments, such as a hard disk or memory of the electronic device. The computer-readable storage medium can also be an external storage device of the electronic device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device. The aforementioned computer-readable storage medium can also include magnetic disks, optical disks, read-only memory (ROM), or random access memory (RAM), etc. Furthermore, the computer-readable storage medium can include both internal storage units and external storage devices of the electronic device. The computer-readable storage medium is used to store the computer program and other programs and data required by the electronic device. The computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
[0173] This application provides a computer program product, which includes a computer program that is executed by a processor. Figure 1 The methods provided for each step in the process.
[0174] The terms "first," "second," etc., in the claims, description, and drawings of this application are used to distinguish different objects, rather than to describe a specific order.
[0175] Furthermore, those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. The terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or electronic device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or electronic device.
[0176] The reference to "embodiment" herein means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The inclusion of this phrase in various locations throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments. The term "and / or" as used in this specification and the appended claims means, and includes, any combination of one or more of the associated listed items and all possible combinations.
[0177] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Those skilled in the art can implement the described functions using different methods for each specific application, but such implementations should not be considered beyond the scope of this application.
[0178] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A data flashback method, characterized in that, include: Receive data flashback preparation requests and perform data isolation operations on the database; The target storage area in the database is locked; wherein, the data isolation operation on the database includes at least one of the following: disabling the garbage collection mechanism for the database; setting the read and write permissions for the database to read-only permissions; and disabling the connection between the database and any external component. Receive a data flashback request; the data flashback request includes a flashback timestamp; Based on the data flashback request, determine the target data in the database that is pre-locked and corresponds to the data flashback request; and determine whether there is reference data in the database corresponding to the flashback timestamp. If it is determined that reference data exists in the database, a first overwrite operation is performed on the target data based on the comparison result between the target data and the reference data; The database includes a pre-written first structured query statement that executes the first overwrite operation; The step of locking the target storage area in the database includes: Determine the target row lock corresponding to the target storage area, and perform scanning and rollback operations on the target row lock; Identify the user key with the longest time span between the storage timestamp and the flashback timestamp in the target storage area, and lock the identified user key.
2. The method according to claim 1, characterized in that, The method further includes: If it is determined that no reference data exists in the database, a second overwrite operation is performed on the target data based on the clear command; The database also includes a pre-written second structured query statement that performs the second coverage operation.
3. The method according to claim 1, characterized in that, The step involves determining the target data in the database that is pre-locked and corresponds to the data flashback request; And determining whether reference data corresponding to the flashback timestamp exists in the database, including: Identify the target user key whose key value changed in the target storage area within the time period corresponding to the flashback timestamp to the target timestamp; the target timestamp indicates the timestamp at which the identified user key was locked. The key value corresponding to the target user key and the target timestamp is determined as the reference data; the key value corresponding to the target user key and the flashback timestamp is determined as the target data.
4. The method according to claim 1, characterized in that, After performing a data flashback operation on the target data, the method further includes: Update the data table corresponding to the target storage area; If the version information corresponding to the updated data table is detected, the data table information is generated.
5. A data flashback device, characterized in that, The device includes: A preprocessing module is used to receive a data flashback preparation request, perform data isolation operations on the database, and lock the target storage area in the database; wherein, the data isolation operation on the database includes at least one of the following: disabling the garbage collection mechanism for the database; setting the read and write permissions for the database to read-only permissions; and disabling the connection between the database and any external component; A data flashback request receiving module is used to receive data flashback requests; the data flashback request includes a flashback timestamp; The data determination module is used to determine, based on the data flashback request, the target data pre-locked in the database that corresponds to the data flashback request; and to determine whether reference data corresponding to the flashback timestamp exists in the database; The flashback operation execution module is used to perform a first overwrite operation on the target data based on the target data and the reference data if it is determined that the reference data exists in the database. The database includes pre-written structured query statements that execute the first overwrite operation; Wherein, when the preprocessing module locks the target storage area in the database, it is used to: Determine the target row lock corresponding to the target storage area, and perform scanning and rollback operations on the target row lock; Identify the user key with the longest time span between the storage timestamp and the flashback timestamp in the target storage area, and lock the identified user key.
6. An electronic device, characterized in that, It includes a processor and a memory, which are interconnected; The memory is used to store computer programs; The processor is configured to perform the method of any one of claims 1 to 4 when the computer program is invoked.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 4.