Data rollback method and device, computer equipment and storage medium
By encapsulating database change operations and migration operations into data change transactions, executing and detecting exceptions, performing Schema reverse restore and data fallback, the problem of traditional rollback methods being time-consuming and easy to miss details is solved, and efficient and secure data rollback is achieved.
Patent Information
- Application Number
- CN202411770741.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-25
AI Technical Summary
During the change of database Schema in the financial technology field, traditional methods lack transactional guarantees, resulting in the rollback that requires reverse operation of all previously executed steps, which is time-consuming and easy to miss details, resulting in inconsistent data.
By obtaining the change operation information and the migration operation information, it is encapsulated as a data change transaction, executing and recording the transaction execution information, and detecting whether it contains abnormal execution information. If an exception exists, perform Schema reverse restore and migration data fallback, and consistency verification is performed according to preset consistency rules.
It realizes effective data rollback operations on the database, improves the efficiency and security of data rollback, and ensures real-time accuracy of database data.
Smart Images

Figure CN119690944A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, specifically to the field of financial technology, and in particular to a data rollback method, device, computer equipment and storage medium. Background Art
[0002] When changing the database schema in the financial technology field, it is often accompanied by a large amount of data migration operations. This process involves multiple steps, including backing up existing data, changing the database table structure, data conversion and verification, and modifying and publishing application code. Due to the huge amount of data, each step may take a long time and there are complex dependencies between each other. If an error occurs in a step during the change process, a rollback operation is required to restore the system to a consistent state before the change.
[0003] Traditional change processes are often executed serially, and there is a lack of transactional guarantees between steps. Once an exception occurs in the middle link, all previously executed steps need to be reversed when rolling back. This is not only time-consuming, but also easy to miss details, resulting in data inconsistency. For example, when a change fails, if only the database schema is rolled back, and the rollback of the migrated data is omitted, it will cause a mismatch between the schema and the data. To implement a reliable rollback mechanism, it is necessary to consider incorporating the scattered change steps into a unified transaction management. However, since the change involves multiple systems and modules, it is difficult to handle it with a single transaction. Moreover, the execution time of different steps varies greatly, and using the same transaction to manage them lacks flexibility, making it difficult to effectively roll back the database data, thereby reducing the security and effectiveness of the database. Summary of the invention
[0004] The purpose of the embodiments of the present application is to propose a data rollback method, apparatus, computer device and storage medium to solve the problem of being unable to effectively perform data rollback operations on a database and to improve the efficiency and security of data rollback.
[0005] In order to solve the above technical problems, the embodiment of the present application provides a data rollback method, which adopts the following technical solution:
[0006] Acquire change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction;
[0007] Executing the data change transaction and recording transaction execution information;
[0008] Detecting whether the transaction execution information includes abnormal execution information;
[0009] If the transaction execution information includes the abnormal execution information, performing schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database;
[0010] The restored database is verified for consistency according to a preset consistency rule, and after the consistency verification passes, the restored database is marked as being in a repaired state.
[0011] Furthermore, the step of obtaining the change operation information and the migration operation information, and encapsulating the change operation information and the migration operation information into a data migration transaction specifically includes:
[0012] Determine whether there is a dependency relationship between the change operation information and the migration operation information;
[0013] If there is a dependency relationship between the change operation information and the migration operation information, sorting the change operation information and the migration operation information according to the dependency relationship to obtain a change operation information sequence and a migration operation information sequence;
[0014] The change operation information sequence and the migration operation information sequence are encapsulated into the same transaction to obtain the data migration transaction.
[0015] Furthermore, the step of executing the data change transaction and recording the transaction execution information specifically includes:
[0016] Creating a transaction log according to the data change transaction;
[0017] Executing the data migration transaction, and recording change operation progress information and migration operation progress information executed by the data migration transaction, and recording the change operation progress information and the migration operation progress information in the transaction log;
[0018] Acquire a database snapshot according to the change operation progress information and the migration operation progress information, and record the database snapshot in the transaction log;
[0019] The transaction log recording the change operation progress information, the migration operation progress information, and the database snapshot is used as the transaction execution information.
[0020] Furthermore, the step of detecting whether the transaction execution information includes abnormal execution information specifically includes:
[0021] Parsing the transaction execution information to obtain execution progress status information;
[0022] The execution progress status information is compared with preset execution progress status information to identify whether the transaction execution information includes the abnormal execution information.
[0023] Furthermore, the steps of performing schema reverse restoration and migration data rollback according to the transaction execution information to obtain a restored database specifically include:
[0024] Determine a rollback target time point according to the transaction execution information;
[0025] Determine whether the data state at the rollback target time point is consistent with the Schema state of the database;
[0026] If the data state at the time point is consistent with the schema state, reverse restore the schema change operation and data migration operation after the rollback target time point, and monitor the data consistency and schema consistency in the reverse restoration in real time until the reverse restoration operation is completed.
[0027] Furthermore, the step of reversely restoring the schema change operation and data migration operation after the rollback target time point specifically includes:
[0028] Determine the reverse execution operation scope according to the rollback target time point;
[0029] Perform reverse restoration of the Schema change in reverse chronological order according to the reverse execution operation scope and the transaction execution information, and record change rollback progress information;
[0030] Extracting migration operation progress information from the transaction execution information, and determining a migration data range according to the migration operation progress information;
[0031] A reverse rollback operation is performed on the data within the migration data range according to the change rollback progress information and the migration operation progress information.
[0032] Furthermore, the step of performing consistency verification on the database after data rollback according to the preset consistency rule specifically includes:
[0033] Obtaining preset consistency rules, parsing the preset consistency rules, and obtaining primary key uniqueness constraints, foreign key constraints, and custom integrity rules;
[0034] Obtain schema change information and data migration information during the data rollback process, as well as the target data snapshot at the rollback target time point during the data rollback process;
[0035] The schema change information, the data migration information, and the target data snapshot are verified for consistency according to the primary key uniqueness constraint, the foreign key constraint, and the custom integrity rule.
[0036] In order to solve the above technical problems, the embodiment of the present application further provides a data rollback device, which adopts the following technical solution:
[0037] A transaction encapsulation module, used to obtain change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction;
[0038] A transaction execution module, used to execute the data change transaction and record transaction execution information;
[0039] An execution detection module, used to detect whether the transaction execution information contains abnormal execution information;
[0040] A data rollback module, configured to perform schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database if the transaction execution information includes the abnormal execution information;
[0041] The rollback verification module is used to perform consistency verification on the restored database according to a preset consistency rule, and after the consistency verification passes, mark the restored database as a repaired state.
[0042] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0043] A computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the data rollback method as described in any one of the above when executing the computer-readable instructions.
[0044] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0045] A computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the data rollback method as described in any one of the above items are implemented.
[0046] Compared with the prior art, the embodiment of the present application has the following beneficial effects: the embodiment obtains change operation information and migration operation information, and encapsulates the change operation information and the migration operation information into a data migration transaction; executes the data migration transaction and records the transaction execution information; detects whether the transaction execution information contains abnormal execution information; if the transaction execution information contains the abnormal execution information, performs schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database; performs consistency verification on the restored database according to preset consistency rules, and after the consistency verification passes, marks the restored database as repaired. This effectively implements effective data rollback operations on the database, improves the efficiency and security of data rollback, and ensures that the database data is real-time, accurate and effective. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0048] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0049] Figure 2 A flowchart of an embodiment of a data rollback method according to the present application;
[0050] Figure 3 yes Figure 2 A flowchart of a specific implementation of step S10;
[0051] Figure 4 yes Figure 2 A flowchart of a specific implementation of step S20;
[0052] Figure 5 yes Figure 2 A flowchart of a specific implementation of step S30;
[0053] Figure 6 yes Figure 2 A flowchart of a specific implementation of step S40;
[0054] Figure 7 yes Figure 6 A flowchart of a specific implementation of step S405;
[0055] Figure 8 yes Figure 2A flowchart of a specific implementation of step S60;
[0056] Fig. 9 is a structural schematic diagram of an embodiment of a data rollback device according to the present application;
[0057] Fig.10 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0059] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor does it refer to non-related or alternative embodiments that are mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0060] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0061] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0062] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0063] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.
[0064] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .
[0065] It should be noted that the data rollback method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the data rollback device is generally arranged in the server / terminal device.
[0066] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0067] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for data rollback according to the present application. The data rollback method comprises the following steps:
[0068] Step S10, acquiring change operation information and migration operation information, and encapsulating the change operation information and the migration operation information into a data migration transaction;
[0069] In this embodiment, the change operation information refers to the detailed information of the modification operation on the database schema, which includes creating a new table, modifying the structure of an existing table (such as adding, deleting or modifying a column), deleting a table, creating or modifying an index, adding or deleting a foreign key constraint, etc. The change operation information includes: operation type, operation time, operation object, operation details, executor, transaction information, etc. Migration operation information refers to the detailed information of the migration operation on the data in the database, and the migration operation information includes: migration source and target, migration data type and scale, migration time and progress, migration tools and technology, migration strategy and steps, etc. Data migration transaction refers to a series of operations related to data change and migration, which are encapsulated as a whole to ensure the integrity, consistency and reliability of the data.
[0070] Step S20, executing the data change transaction and recording transaction execution information;
[0071] In this embodiment, corresponding operations are performed according to the contents of the change operations and data migration operations in the data change transactions. In the execution of the change operations and data migration operations, the corresponding progress information of the operation execution and the data snapshots during the operation execution are recorded through the created transaction log to obtain the recorded transaction execution information.
[0072] Step S30, detecting whether the transaction execution information contains abnormal execution information;
[0073] In this embodiment, the execution progress status information in the transaction execution information is compared with the preset execution progress status information to detect whether the transaction execution information contains abnormal execution information, wherein the execution progress status information includes the progress of each preset node (displayed as a percentage), the timestamp of the completion of each preset node, and the progress milestone. The preset execution progress status information is a judgment benchmark set based on historical data, transaction complexity, and expected execution time. The preset execution progress status information includes the expected completion time and progress milestone of each preset node.
[0074] Step S40: if the transaction execution information includes the abnormal execution information, performing schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database;
[0075] In this embodiment, the rollback target time point to which the rollback operation needs to be rolled back is first determined through the transaction execution information, and then the schema change reverse restoration and migration operation reverse rollback are performed on the data after the rollback target time point to obtain a restored database after the effective rollback operation is performed. The rollback target time point is used to indicate the time span of the rollback operation, so as to effectively perform the rollback operation on the database without affecting the data before the abnormal execution information.
[0076] Step S50: if the transaction execution information does not include the abnormal execution information, determining that the database corresponding to the transaction execution information is in a normal state;
[0077] In this embodiment, when the detection transaction execution information does not include abnormal execution information, it indicates that no abnormal situation occurs in the process of executing the data transition transaction in the database, and the database can be determined as being in a normal state.
[0078] Step S60: Perform consistency verification on the restored database according to a preset consistency rule, and after the consistency verification passes, mark the restored database as being in a repaired state.
[0079] In this embodiment, the preset consistency rules include primary key uniqueness constraints, foreign key constraints, and custom integrity rules. The restored database is verified for consistency based on the primary key uniqueness constraints, foreign key constraints, and custom integrity rules to ensure that the restored database after the reverse restore operation has completed the rollback repair.
[0080] This embodiment obtains change operation information and migration operation information, and encapsulates the change operation information and the migration operation information into a data migration transaction; executes the data migration transaction and records the transaction execution information; detects whether the transaction execution information contains abnormal execution information; if the transaction execution information contains the abnormal execution information, performs schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database; if the transaction execution information does not contain the abnormal execution information, determines that the database corresponding to the transaction execution information is in a non-abnormal state; performs consistency verification on the restored database according to preset consistency rules, and after the consistency verification passes, marks the restored database as a repaired state. This effectively implements effective data rollback operations on the database, improves the efficiency and security of data rollback, and ensures that the database data is real-time, accurate and effective.
[0081] In this embodiment, the above-mentioned data rollback method can be applied to the data processing of the financial product business system database. By rolling back the data in the database of the financial product business system, the real-time effectiveness of the financial product business system can be effectively ensured to avoid abnormal situations in the financial product business system that may cause data unavailability.
[0082] refer to Figure 3 In some optional implementations of this embodiment, step S10 includes the following steps:
[0083] Step S101, determining whether there is a dependency relationship between the change operation information and the migration operation information;
[0084] In this embodiment, the dependency relationship between the change operation information and the migration operation information includes: a certain data migration operation may need to perform a specific schema change operation first to ensure that the target database has the correct structure to receive data. The dependency relationship between the migration operation information and the change operation information includes: a certain schema change operation may need to perform a data migration operation first to clean up old data or prepare data required for a new data structure. The above dependency relationship can be determined based on a preset dependency graph, which contains all related schema change operations and data migration operations as nodes. According to the dependency relationship between each operation, a directed edge is drawn between the nodes, wherein the direction of the edge indicates the direction of the dependency, that is, from one operation to another operation on which it depends.
[0085] Step S102: If there is a dependency relationship between the change operation information and the migration operation information, the change operation information and the migration operation information are sorted according to the dependency relationship to obtain a change operation information sequence and a migration operation information sequence;
[0086] In this embodiment, a directed graph is created in which nodes represent operations and edges represent dependencies, and then a topological sorting algorithm is used to determine the execution order of the operations to implement sorting operations on change operation information and migration operation information, thereby effectively obtaining change operation information sequences and migration operation information sequences.
[0087] Step S103: if there is no dependency relationship between the change operation information and the migration operation information, the change operation information and the migration operation information are marked as non-dependency relationship information;
[0088] In this embodiment, marking information corresponding to no dependency is added to the change operation information and the migration operation information to mark the change operation information and the migration operation information as no dependency information. This operation can be implemented by marking the information in the above dependency graph.
[0089] Step S104: encapsulate the change operation information sequence and the migration operation information sequence into the same transaction to obtain the data migration transaction.
[0090] In this embodiment, the change operation information sequence and the migration operation information sequence are encapsulated into the same local transaction to obtain a data change transaction, wherein the data change transaction has atomicity and consistency. Atomicity: If any operation in the transaction fails, the entire transaction will be rolled back, including any operation that has been successfully executed. This ensures the consistency of the database state. Consistency: After the transaction is executed, the database will be in a consistent state, regardless of success or failure.
[0091] This embodiment determines whether there is a dependency relationship between the change operation information and the migration operation information; if there is a dependency relationship between the change operation information and the migration operation information, the change operation information and the migration operation information are sorted according to the dependency relationship to obtain a change operation information sequence and a migration operation information sequence; if there is no dependency relationship between the change operation information and the migration operation information, the change operation information and the migration operation information are marked as non-dependency information; the change operation information sequence and the migration operation information sequence are encapsulated into the same transaction to obtain the data migration transaction. Thus, the encapsulation of the change operation information and the migration operation information is effectively completed to obtain a data migration transaction that executes the change operation and the migration operation, which facilitates the subsequent data migration operation according to the data migration transaction.
[0092] refer to Figure 4 In some optional implementations of this embodiment, step S20 includes the following steps:
[0093] Step S201, creating a transaction log according to the data change transaction;
[0094] In this embodiment, before the data migration transaction is executed, a corresponding transaction log is created, which includes: transaction ID: uniquely identifies the data migration transaction; transaction name: describes the purpose or content of the transaction; start time: the timestamp when the transaction starts; status: the initial status, such as "not started" or "in progress"; log entry list: used for subsequent recording of change operations, migration operation progress information and database snapshots, etc.
[0095] Step S202, executing the data migration transaction, and recording the change operation progress information and the migration operation progress information executed by the data migration transaction, and recording the change operation progress information and the migration operation progress information in the transaction log;
[0096] In this embodiment, in the process of executing the data migration transaction, a new log entry is added to the transaction log to realize real-time recording of the progress information of the change operation and the migration operation. The change operation progress information is recorded according to the preset operation node, which includes the change operation ID: uniquely identifies the change operation; operation type: such as "insert", "update", "delete", etc.; operation object: affected database table or record; progress: the percentage or specific number of completed operations; timestamp: the time when the progress information is recorded. The migration operation progress information includes the migration operation ID: uniquely identifies the migration operation; source data location: the starting location of data migration; target data location: the end location of data migration; progress: the percentage or specific number of completed migration; timestamp: the time when the progress information is recorded.
[0097] Step S203, obtaining a database snapshot according to the change operation progress information and the migration operation progress information, and recording the database snapshot into the transaction log;
[0098] In this embodiment, after the data migration transaction is executed to the preset node, the current snapshot of the database is obtained and recorded in the transaction log. The database snapshot includes a snapshot ID: uniquely identifies the database snapshot; snapshot content: the current state of the database or the snapshot file path of the data; and a timestamp: the time when the snapshot was created.
[0099] Step S204: Using the transaction log recording the change operation progress information, the migration operation progress information, and the database snapshot as the transaction execution information.
[0100] In this embodiment, when the data migration transaction is completed, the change operation progress information, migration operation progress information, and database snapshot obtained by all preset nodes are recorded in the transaction log to obtain complete transaction execution information. The transaction execution information includes the end time: the timestamp of the transaction completion; the final status: such as "success", "failure" or "partial success"; transaction execution information: transaction log records containing change operation progress information, migration operation progress information, and database snapshots.
[0101] This embodiment creates a transaction log according to the data migration transaction; executes the data migration transaction, and records the change operation progress information and migration operation progress information of the data migration transaction, and records the change operation progress information and migration operation progress information in the transaction log; obtains a database snapshot according to the change operation progress information and migration operation progress information, and records the database snapshot in the transaction log; and uses the transaction log that records the change operation progress information, the migration operation progress information, and the database snapshot as the transaction execution information. Thus, the progress information of the data migration transaction and the transaction execution information of the data snapshot are effectively obtained, so as to facilitate the subsequent judgment of abnormal execution information.
[0102] refer to Figure 5 In some optional implementations of this embodiment, step S30 includes the following steps:
[0103] Step S301, parsing the transaction execution information to obtain execution progress status information;
[0104] In this embodiment, the execution progress status information includes the progress of each preset node (displayed as a percentage), the timestamp of the completion of each preset node, the progress milestone, etc. The corresponding information extraction identifier is used to query the transaction execution information to extract the corresponding execution progress status information.
[0105] Step S302: Compare the execution progress status information with preset execution progress status information to identify whether the transaction execution information includes the abnormal execution information.
[0106] In this embodiment, the extracted execution progress status information is compared in detail with the preset execution progress status information through timeline matching, progress comparison, and key milestone verification. Through comparison, it can be identified whether the transaction execution lags behind expectations, whether there is a stagnant stage, or whether certain operations are completed ahead of schedule. Abnormal execution information includes execution progress lag: a certain stage or the overall progress of the transaction is significantly behind the preset progress milestone. Progress stagnation: the transaction has not made progress for a long time at a certain stage, indicating that there may be blockage or errors. Abnormal timestamp: the recorded timestamp does not match expectations, such as a sudden time jump or a missing time period. Data inconsistency: there are contradictions or inconsistencies between the progress information of the change operation and the migration operation.
[0107] This embodiment parses the transaction execution information to obtain execution progress status information, and compares the execution progress status information with the preset execution progress status information to identify whether the transaction execution information contains the abnormal execution information, thereby effectively realizing the judgment of the abnormal execution information in the transaction execution information, so as to facilitate the subsequent corresponding processing steps.
[0108] Continue to refer Figure 6 In some optional implementations of this embodiment, step S40 includes the following steps:
[0109] Step S401, determining a rollback target time point according to the transaction execution information;
[0110] In this embodiment, the rollback target time point is determined based on the timestamp or progress information corresponding to the abnormal execution information in the transaction execution information, or the rollback target time point can be determined by the timestamp corresponding to the first abnormal execution in the error report recorded in the transaction log.
[0111] Step S402, determining whether the data state at the rollback target time point is consistent with the Schema state of the database.
[0112] In this embodiment, after determining the rollback target time point, it is necessary to verify whether the Schema state of the data at that time point is consistent with the Schema state of the database. This can be done by the following steps: checking whether the data at the rollback target time point is complete and accurate, and is not affected by subsequent transactions; verifying whether the database Schema at the rollback target time point matches the initial Schema state, that is, ensuring that the Schema structure can correctly support the data state.
[0113] Step S403: if the data state at the time point is consistent with the schema state, reverse restore the schema change operation and data migration operation after the rollback target time point, and monitor the data consistency and schema consistency in the reverse restoration in real time until the reverse restoration operation is completed;
[0114] In this embodiment, the rollback target time point is first determined as the rollback target point, and then the reverse restore operation is performed on the data after the rollback target point. The reverse restore of the schema change operation and the data migration operation in the reverse restore operation has a sequence. In this embodiment, the reverse restore of the schema change operation is performed first, and then the reverse restore of the data migration operation is performed. At the same time, during the reverse restore process, a data consistency check is performed regularly to ensure that the data in the current database matches the expected target time point data. At the same time, the database schema is regularly checked to see if it matches the expected target time point schema to ensure the effective completion of the reverse restore operation.
[0115] In this embodiment, in the above-mentioned reverse restore operation, the data between the rollback target time point and the transaction start time point can also be synchronized according to the incremental synchronization method to ensure that the data between the rollback target time point and the transaction start time point is consistent with the data before the transaction is executed, wherein the transaction start time point refers to the timestamp recorded when the data change transaction starts to execute. The synchronization processing of the above-mentioned incremental synchronization method includes: obtaining data snapshots at the rollback target time point and the transaction start time point; traversing all transaction logs between the rollback target time point and the transaction start time point, and judging whether the data corresponding to each operation needs to be synchronized according to the operation type and data in the transaction log; for the data that needs to be synchronized, using the incremental synchronization algorithm, calculating the data difference between the rollback target time point and the transaction start time point, and obtaining the incremental data that needs to be synchronized; applying the incremental data to the database, for insert operations, directly inserting the corresponding data; for update operations, updating the corresponding data; for delete operations, deleting the corresponding data, the above-mentioned insert, update, and delete operations can be processed in batches, processing a batch of data each time, reducing the number of interactions with the database; after the synchronization processing is completed, comparing the data snapshot at the rollback target time point with the data in the current database, if the two are consistent, the synchronization processing is successful.
[0116] Step S404: If the data state at the time point is inconsistent with the Schema state, the rollback target time point is determined as a non-rollback target point.
[0117] In this embodiment, when it is found that the data state and the Schema state at the rollback target time point are inconsistent, it indicates that an abnormality still exists at this time point, and it is necessary to select a time point before the rollback target time point as the rollback target point, and determine the rollback target time point as a non-rollback target point.
[0118] This embodiment determines the rollback target time point according to the transaction execution information; determines whether the data state at the rollback target time point is consistent with the schema state of the database; if the data state at the time point is consistent with the schema state, reverse restore is performed on the schema change operation and data migration operation after the rollback target time point, and the data consistency and schema consistency in the reverse restoration are monitored in real time until the reverse restoration operation is completed; if the data state at the time point is inconsistent with the schema state, the rollback target time point is determined as a non-rollback target point. This effectively implements data rollback of the schema change operation and data migration operation of the database to facilitate subsequent consistency verification operations.
[0119] Continue to refer Figure 7 In some optional implementations of this embodiment, step S403 includes the following steps:
[0120] Step S4031, determining the reverse execution operation range according to the rollback target time point;
[0121] In this embodiment, the step of determining the scope of reverse execution operations according to the rollback time point includes: determining a specific rollback time point according to the error location specified by the abnormal execution information; viewing the transaction execution log, and analyzing all schema change operations and data migration operations from the rollback time point to the current time point; based on the above analysis, determining the scope of the schema change operations and data migration operations that need to be reversed.
[0122] Step S4032, performing reverse restoration of the schema change in reverse chronological order according to the reverse execution operation scope and the transaction execution information, and recording change rollback progress information;
[0123] In this embodiment, the steps of reverse restoration of schema changes include: sorting the determined schema change operations in reverse chronological order to ensure that the reverse restoration order is correct; executing these reverse schema change operations one by one, such as undoing the modification of the table structure, deleting the index, etc.; after each reverse restoration operation, recording the progress and results of the operation to obtain change rollback progress information.
[0124] Step S4033, extracting migration operation progress information from the transaction execution information, and determining a migration data range according to the migration operation progress information;
[0125] In this embodiment, migration operation progress information related to data migration is extracted from the transaction execution information, and based on the migration operation progress information, which data has been migrated or modified is analyzed, and the specific range of these data is determined, thereby obtaining the migration data range.
[0126] Step S4034: performing a reverse rollback operation on the data within the migration data range according to the change rollback progress information and the migration operation progress information.
[0127] In this embodiment, according to the change rollback progress information and the migration operation progress information, a reverse rollback operation is performed on the data within the migration data range, such as undoing data insertion, updating or deletion, and after each reverse rollback operation, it is verified whether the rollback result meets expectations to ensure the integrity and consistency of the data, thereby effectively completing the reverse rollback operation on the data within the migration data range.
[0128] This embodiment determines the reverse execution operation range according to the rollback target time point; performs reverse restoration of the schema change in reverse chronological order according to the reverse execution operation range and the transaction execution information, and records the change rollback progress information; extracts the migration operation progress information from the transaction execution information, and determines the migration data range according to the migration operation progress information; performs a reverse rollback operation on the data within the migration data range according to the change rollback progress information and the migration operation progress information. This effectively implements the reverse restoration of the database schema change and the reverse rollback of the migration data, and effectively restores the database to the initial state before executing the data migration transaction.
[0129] Continue to refer Figure 8 In some optional implementations of this embodiment, step S60 includes the following steps:
[0130] S601, obtaining preset consistency rules, parsing the preset consistency rules, and obtaining primary key uniqueness constraints, foreign key constraints, and custom integrity rules;
[0131] In this embodiment, the primary key uniqueness constraint is used to uniquely identify each record in the table. It ensures that the value on the primary key column (which can be a combination of one or more columns) in the table is unique in the entire table and is not allowed to be empty (NULL). The foreign key constraint is used to maintain the referential integrity between tables. It ensures that the column (foreign key) in one table can reference the primary key column of another table, thereby establishing an association relationship between the two tables. Custom integrity rules are constraints defined by users based on specific business needs. Custom integrity rules may include non-empty constraints: requiring that the value of a certain column cannot be empty. Unique constraint: requires that the value of a certain column or column combination is unique in the entire table (but allows null values). Check constraint: defines a conditional expression that requires that records in the table must meet the condition. For example, age must be between 0 and 100, gender can only be "male" or "female", etc. Default value constraint: specifies a default value for a column. When a new record is inserted and no value is provided for the column, the default value will be used.
[0132] S602, obtaining schema change information and data migration information during the data rollback process, as well as a target data snapshot at a rollback target time point during the data rollback process;
[0133] In this embodiment, the schema change information describes the changes in the database structure during the data rollback process, such as table creation, deletion, and modification. The data migration information records the data migration process, including data insertion, update, and deletion operations. By rolling back the target time point, a target data snapshot at that time point is obtained, and the target data snapshot will be used as the benchmark for consistency verification.
[0134] S603: Perform consistency verification on the schema change information, the data migration information, and the target data snapshot according to the primary key uniqueness constraint, the foreign key constraint, and the custom integrity rule.
[0135] In this embodiment, verifying the primary key uniqueness constraint includes checking whether the data table after the schema change satisfies the primary key uniqueness constraint to ensure that no violation of the primary key uniqueness occurs during the data rollback process. Verifying the foreign key constraint includes checking whether the data after data migration satisfies the foreign key constraint to ensure the integrity of the reference, that is, the record referenced by the foreign key does exist in the main table. Verifying the custom integrity rules includes checking whether the state of the data after rollback meets the requirements of these rules according to the custom integrity rules, which may include specific data formats, value ranges, business logic, etc. Comprehensive verification includes combining the schema change information, data migration information and target data snapshots to perform overall consistency verification. Ensure that the state of the database remains consistent from beginning to end during the data rollback process.
[0136] This embodiment obtains preset consistency rules, parses the preset consistency rules, obtains primary key uniqueness constraints, foreign key constraints, and custom integrity rules; obtains schema change information and data migration information during data rollback, as well as the target data snapshot at the rollback target time point during data rollback; and performs consistency verification on the schema change information, data migration information, and target data snapshot according to the primary key uniqueness constraints, foreign key constraints, and custom integrity rules. This effectively completes the consistency verification of the database after data rollback to ensure the validity of the database after rollback.
[0137] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0138] 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.
[0139] Further references Fig. 9 , as a response to the above Figure 1 The present application provides an embodiment of a data rollback device, and the device embodiment is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0140] like Fig. 9 As shown, the data rollback device 700 described in this embodiment includes: a transaction encapsulation module 701, a transaction execution module 702, an execution detection module 703, a data rollback module 704, a state determination module 705, and a rollback verification module 706. Among them:
[0141] The transaction encapsulation module 701 is used to obtain change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction;
[0142] The transaction execution module 702 is used to execute the data change transaction and record the transaction execution information;
[0143] An execution detection module 703 is used to detect whether the transaction execution information contains abnormal execution information;
[0144] A data rollback module 704 is configured to perform schema reverse restoration and migration data rollback according to the transaction execution information to obtain a restored database if the transaction execution information includes the abnormal execution information;
[0145] A state determination module 705, configured to determine that the database corresponding to the transaction execution information is in a normal state if the transaction execution information does not include the abnormal execution information;
[0146] The rollback verification module 706 is used to perform consistency verification on the restored database according to a preset consistency rule, and after the consistency verification passes, mark the restored database as a repaired state.
[0147] By adopting the above-mentioned data rollback device, this embodiment can obtain change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction; execute the data change transaction and record the transaction execution information; detect whether the transaction execution information contains abnormal execution information; if the transaction execution information contains the abnormal execution information, perform schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database; perform consistency verification on the restored database according to the preset consistency rules, and after the consistency verification passes, mark the restored database as a repaired state. In this way, effective data rollback operations on the database are effectively implemented, and the efficiency and security of data rollback are improved, ensuring the real-time, accurate and effective database data.
[0148] To solve the above technical problems, the present application also provides a computer device. Fig.10 , Fig.10 This is a basic structural block diagram of the computer device in this embodiment.
[0149] The computer device 8 includes a memory 81, a processor 82, and a network interface 83 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 8 with components 81-83, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0150] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0151] The memory 81 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 81 can be an internal storage unit of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 81 can also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 81 can also include both the internal storage unit of the computer device 8 and its external storage device. In this embodiment, the memory 81 is generally used to store the operating system and various application software installed on the computer device 8, such as computer-readable instructions of the data rollback method, etc. In addition, the memory 81 can also be used to temporarily store various types of data that have been output or are to be output.
[0152] The processor 82 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 82 is generally used to control the overall operation of the computer device 8. In this embodiment, the processor 82 is used to run computer-readable instructions stored in the memory 81 or process data, such as computer-readable instructions for running the data rollback method.
[0153] The network interface 83 may include a wireless network interface or a wired network interface. The network interface 83 is generally used to establish a communication connection between the computer device 8 and other electronic devices.
[0154] By adopting the above-mentioned computer device, this embodiment can obtain change operation information and migration operation information, and encapsulate the change operation information and migration operation information into a data change transaction; execute the data change transaction and record the transaction execution information; detect whether the transaction execution information contains abnormal execution information; if the transaction execution information contains the abnormal execution information, perform schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database; perform consistency verification on the restored database according to the preset consistency rules, and after the consistency verification passes, mark the restored database as a repaired state. In this way, effective data rollback operations on the database are effectively implemented, and the efficiency and security of data rollback are improved, ensuring the real-time, accurate and effective database data.
[0155] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the data rollback method as described above.
[0156] By adopting the above-mentioned computer-readable storage medium, this embodiment can obtain change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction; execute the data change transaction and record the transaction execution information; detect whether the transaction execution information contains abnormal execution information; if the transaction execution information contains the abnormal execution information, perform schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database; perform consistency verification on the restored database according to preset consistency rules, and after the consistency verification passes, mark the restored database as a repaired state. Thereby, effective data rollback operations on the database are effectively implemented, and the efficiency and security of data rollback are improved, ensuring the real-time, accurate and effective database data.
[0157] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0158] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
[0159] The non-Company software tools or components appearing in the embodiments of this application are merely examples and do not represent actual use.
Claims
1. A data rollback method, characterized in that: The steps include: Acquire change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction; Executing the data change transaction and recording transaction execution information; Detecting whether the transaction execution information includes abnormal execution information; If the transaction execution information includes the abnormal execution information, performing schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database; The restored database is verified for consistency according to a preset consistency rule, and after the consistency verification passes, the restored database is marked as being in a repaired state.
2. The data rollback method according to claim 1, characterized in that: The step of obtaining the change operation information and the migration operation information, and encapsulating the change operation information and the migration operation information into a data migration transaction specifically includes: Determine whether there is a dependency relationship between the change operation information and the migration operation information; If there is a dependency relationship between the change operation information and the migration operation information, sorting the change operation information and the migration operation information according to the dependency relationship to obtain a change operation information sequence and a migration operation information sequence; The change operation information sequence and the migration operation information sequence are encapsulated into the same transaction to obtain the data migration transaction.
3. The data rollback method according to claim 1, characterized in that: The step of executing the data change transaction and recording the transaction execution information specifically includes: Creating a transaction log according to the data change transaction; Executing the data migration transaction, and recording change operation progress information and migration operation progress information executed by the data migration transaction, and recording the change operation progress information and the migration operation progress information in the transaction log; Acquire a database snapshot according to the change operation progress information and the migration operation progress information, and record the database snapshot in the transaction log; The transaction log recording the change operation progress information, the migration operation progress information, and the database snapshot is used as the transaction execution information.
4. The data rollback method according to claim 1, characterized in that: The step of detecting whether the transaction execution information includes abnormal execution information specifically includes: Parsing the transaction execution information to obtain execution progress status information; The execution progress status information is compared with preset execution progress status information to identify whether the transaction execution information includes the abnormal execution information.
5. The data rollback method according to claim 1, characterized in that: The steps of performing schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database specifically include: Determine a rollback target time point according to the transaction execution information; Determine whether the data state at the rollback target time point is consistent with the Schema state of the database; If the data state at the time point is consistent with the schema state, reverse restore the schema change operation and data migration operation after the rollback target time point, and monitor the data consistency and schema consistency in the reverse restoration in real time until the reverse restoration operation is completed.
6. The data rollback method according to claim 5, characterized in that: The step of reversely restoring the schema change operation and data migration operation after the rollback target time point specifically includes: Determining a reverse execution operation scope according to the rollback target time point; Perform reverse restoration of the Schema change in reverse chronological order according to the reverse execution operation scope and the transaction execution information, and record change rollback progress information; Extracting migration operation progress information from the transaction execution information, and determining a migration data range according to the migration operation progress information; A reverse rollback operation is performed on the data within the migration data range according to the change rollback progress information and the migration operation progress information.
7. The data rollback method according to claim 1, characterized in that: The step of verifying the consistency of the database after the data rollback according to the preset consistency rules specifically includes: Obtaining preset consistency rules, parsing the preset consistency rules, and obtaining primary key uniqueness constraints, foreign key constraints, and custom integrity rules; Obtain schema change information and data migration information during the data rollback process, as well as the target data snapshot at the rollback target time point during the data rollback process; The schema change information, the data migration information, and the target data snapshot are verified for consistency according to the primary key uniqueness constraint, the foreign key constraint, and the custom integrity rule.
8. A data rollback device, characterized in that: include: A transaction encapsulation module, used to obtain change operation information and migration operation information, and encapsulate the change operation information and the migration operation information into a data change transaction; A transaction execution module, used to execute the data change transaction and record transaction execution information; An execution detection module, used to detect whether the transaction execution information contains abnormal execution information; A data rollback module, configured to perform schema reverse restoration and migration data rollback respectively according to the transaction execution information to obtain a restored database if the transaction execution information includes the abnormal execution information; The rollback verification module is used to perform consistency verification on the restored database according to a preset consistency rule, and after the consistency verification passes, mark the restored database as a repaired state.
9. A computer device, characterized in that: It comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the data rollback method as claimed in any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the data rollback method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Database operation method and device and related product
CN121388044A