Data rollback method, device and computer readable storage medium

By listening to the database binary logs and reverse-engineering the rollback code, combined with a container management platform and distributed locks, the problem of low data rollback efficiency in existing technologies is solved, achieving efficient and user-friendly data rollback operations and full lifecycle monitoring.

CN116841983BActive Publication Date: 2026-01-09CHINA MERCHANTS BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310783735.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2026-01-09
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

Existing data rollback solutions require defining the data content to be rolled back, specifying the time and version, resulting in low rollback efficiency. Furthermore, they lack user-perspective data filtering and graphical interfaces, and cannot provide full lifecycle monitoring and fast rollback operations.

Method used

By monitoring the binary logs of the database, the system determines the data change information corresponding to the changed data, and generates and executes rollback code in reverse when a rollback instruction is received. Combined with a container management platform and a distributed lock mechanism, continuous monitoring and efficient rollback are achieved.

Benefits of technology

It improves data rollback efficiency, provides a user-friendly graphical interface and full lifecycle monitoring, supports rapid rollback operations, and reduces operation and maintenance time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116841983B_ABST
    Figure CN116841983B_ABST
Patent Text Reader

Abstract

The application discloses a data rollback method and device and a computer readable storage medium, and the method comprises the following steps: listening to a binary log of a database, determining data change information corresponding to changed data in the database according to the binary log; when a rollback instruction is received, determining target data change information corresponding to the rollback instruction; reversely generating a rollback code according to the target data change information, and executing the rollback code. The application aims to improve the data rollback efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database, in particular to a data rollback method and device and computer readable storage medium. BACKGROUND

[0002] In the database operation, the data modification needs to be recorded in time after the change of data, when the data error change, misdeletion and other situations occur, the data rollback is needed. At present, the data rollback scheme is directly rolled back by the database, which needs to define the data content to be rolled back, specify the time, version and the like, so that the rollback needs to consume a large amount of time, resulting in low data rollback efficiency.

[0003] The above content is only used to assist in understanding the technical solutions of the present application, and does not represent the acknowledgement of the above content as prior art. SUMMARY

[0004] The main purpose of the present application is to provide a data rollback method, device and computer readable storage medium, which aims to improve the data rollback efficiency.

[0005] In order to achieve the above purpose, the present application provides a data rollback method, which comprises:

[0006] Listening to the binary log of the database, determining the data change information corresponding to the changed data in the database according to the binary log;

[0007] When receiving a rollback instruction, determining the target data change information corresponding to the rollback instruction;

[0008] According to the target data change information, the rollback code is generated reversely, and the rollback code is executed.

[0009] Optionally, the step of listening to the binary log of the database, and determining the data change information corresponding to the changed data in the database according to the binary log comprises:

[0010] The application instance deployment log of the container management platform is listened to;

[0011] When the application instance is ready, the ready probe is triggered, and the distributed lock is competed for;

[0012] When the competition is successful, the configuration item of the log listening application is initialized based on the application instance, and the binary log is listened to based on the configuration item;

[0013] The survival probe is triggered in the running process of the application instance, and the distributed lock is renewed, so that the log listening application continuously listens to the binary log.

[0014] Optionally, after the step of triggering a survival probe during the running of the application instance, renewing the distributed lock, so that the log monitoring application continues to monitor the binary log, the method further comprises:

[0015] When a stop condition for monitoring the binary log is met, triggering a stop probe, determining a log position currently monitored by the log monitoring application based on the stop probe, and stopping the current application instance;

[0016] When a next application instance is ready, taking the log position as a corresponding monitoring start position of a log monitoring application in the next application instance;

[0017] The stop condition for monitoring the archived log comprises at least one of the following:

[0018] The application instance fails, restarts, or is redeployed;

[0019] A stop instruction for monitoring the archived log is received.

[0020] Optionally, the step of initializing the configuration item of the log monitoring application based on the application instance comprises:

[0021] Obtaining a database object set, a field, a field type, and a position of the field in a table of each data table in the database;

[0022] Taking the database object set, the field, the field type, and the position of the field in the data table as the configuration item.

[0023] Optionally, after the step of monitoring the binary log of the database and determining data change information corresponding to changed data in the database according to the binary log, the method further comprises:

[0024] Sending the data change information to a consumer queue as a consumer event;

[0025] Polling the data change information in the consumer queue based on a plurality of consumer threads, and binding a batch number identifier to the data change information;

[0026] Saving the data change information after the binding of the batch number identifier in a memory.

[0027] Optionally, before the step of polling the data change information in the consumer queue based on a plurality of consumer threads, and binding a batch number identifier to the data change information, the method further comprises:

[0028] Obtaining a transaction identifier corresponding to a current transaction of the database;

[0029] Associatively binding the batch number identifier corresponding to the changed data in the current transaction with the transaction identifier.

[0030] Optionally, the step of determining the target change data corresponding to the rollback instruction comprises:

[0031] determining a target transaction identifier according to the rollback instruction, and determining a batch number identifier associated with the target transaction identifier, and taking data change information corresponding to the batch number identifier as the target data change information; or

[0032] determining a batch number identifier according to the rollback instruction, and taking data change information corresponding to the batch number identifier as the target data change information.

[0033] Optionally, after the step of listening to the binary log of the database and determining the data change information corresponding to the change data in the database according to the binary log, the method further comprises:

[0034] determining the to-be-displayed information corresponding to each change data according to the data change information;

[0035] generating a graphical interface according to the to-be-displayed information;

[0036] receiving a rollback instruction of a user based on the graphical interface.

[0037] In addition, to achieve the above object, the present application further provides a data rollback device, which comprises a memory, a processor and a data rollback program stored in the memory and executable on the processor, and the data rollback program implements the steps of the data rollback method when executed by the processor.

[0038] In addition, to achieve the above object, the present application further provides a computer readable storage medium, which stores a data rollback program, and the data rollback program implements the steps of the data rollback method when executed by a processor.

[0039] The method determines the data change information corresponding to the change data in the database according to the binary log of the database, determines the target data change information corresponding to the rollback instruction when receiving the rollback instruction, reversely generates a rollback code according to the target data change information, and executes the rollback code. In this way, the binary log of the database is listened to to obtain the data change information corresponding to the change data, the user can specify the target change information to be rolled back through the rollback instruction, the rollback code is automatically reversely generated according to the target change information, and the rollback code is executed to realize the rollback of the change data corresponding to the target data change information, thereby improving the data rollback efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0040] Figure 1is a terminal structure schematic diagram of a hardware running environment related to an embodiment of the present application;

[0041] Figure 2 is a flowchart of an embodiment of the data rollback method of the present application;

[0042] Figure 3 is a flowchart of another embodiment of the data rollback method of the present application;

[0043] Figure 4 is a flowchart of a first application scenario related to an embodiment of the present application;

[0044] Figure 5 is a configuration item structure schematic diagram related to an embodiment of the present application;

[0045] Figure 6 is a flowchart of a second application scenario related to an embodiment of the present application;

[0046] Figure 7 is a relationship diagram of an identifier and a data table related to an embodiment of the present application;

[0047] Figure 8 is a graphical interface related to an embodiment of the present application.

[0048] The implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0049] It should be understood that the specific embodiments described herein are merely intended to explain the present application and are not intended to limit the present application.

[0050] Since the current data rollback scheme is directly data rollback through a database, this way needs to define the data content to be rolled back, specify the time, version, etc., and thus the rollback needs to consume a large amount of time, resulting in low data rollback efficiency.

[0051] In order to improve the data rollback efficiency, an embodiment of the present application proposes a data rollback method, device and computer readable storage medium, wherein the main steps of the method include:

[0052] Listening to a binary log of a database, and determining data change information corresponding to changed data in the database according to the binary log;

[0053] When a rollback instruction is received, determining target data change information corresponding to the rollback instruction;

[0054] Generating a rollback code reversely according to the target data change information, and executing the rollback code.

[0055] Thus, the binary log of the database is listened to to obtain data change information corresponding to the changed data, the user can specify target change information to be rolled back through a rollback instruction, automatically reversely roll back the code according to the target change information, and execute the rollback code to realize the rollback of the changed data corresponding to the target data change information, thereby improving the data rollback efficiency.

[0056] The application claims are described in detail below in combination with the drawings.

[0057] As Figure 1 shown, Figure 1 is a terminal structure diagram of a hardware running environment involved in an embodiment of the application.

[0058] The terminal of the embodiment of the application can be a data rollback device.

[0059] As Figure 1 shown, the terminal can include a processor 1001, such as a CPU, a memory 1003, and a communication bus 1002. The communication bus 1002 is used to realize the connection and communication between the components. The memory 1003 can be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1003 can also be a storage device independent of the aforementioned processor 1001.

[0060] Those skilled in the art can understand that Figure 1 the terminal structure shown in the above does not constitute a limitation on the terminal, and can include more or fewer components than the diagram, or combine certain components, or different component arrangements.

[0061] As Figure 1 shown, the memory 1003, as a computer storage medium, can include an operating system and a data rollback program.

[0062] In Figure 1 the terminal shown, the processor 1001 can be used to call the data rollback program stored in the memory 1003 and perform the following operations:

[0063] Listen to the binary log of the database, and determine data change information corresponding to changed data in the database according to the binary log;

[0064] When a rollback instruction is received, determine target data change information corresponding to the rollback instruction;

[0065] Generate a rollback code reversely according to the target data change information, and execute the rollback code.

[0066] Further, the processor 1001 can invoke the data rollback program stored in the memory 1003, and further perform the following operations:

[0067] deploying a log monitoring application based on an application instance of a container management platform;

[0068] When the application instance is ready, triggering a readiness probe, and racing for a distributed lock;

[0069] When the racing is successful, initializing a configuration item of the log monitoring application based on the application instance, and monitoring the binary log based on the configuration item;

[0070] During the running of the application instance, triggering a liveness probe, and renewing the distributed lock, so that the log monitoring application continuously monitors the binary log.

[0071] Further, the processor 1001 can invoke the data rollback program stored in the memory 1003, and further perform the following operations:

[0072] When a stop condition of monitoring the binary log is met, triggering a stop probe, determining a log position currently monitored by the log monitoring application based on the stop probe, and stopping the current application instance;

[0073] When a next application instance is ready, taking the log position as a monitoring start position corresponding to the log monitoring application in the next application instance;

[0074] The stop condition of monitoring the archived log includes at least one of the following:

[0075] The application instance fails, restarts, or is redeployed;

[0076] A stop instruction of monitoring the archived log is received.

[0077] Further, the processor 1001 can invoke the data rollback program stored in the memory 1003, and further perform the following operations:

[0078] Obtaining a database object set, a field, a field type, and a position of the field in a table of each data table in the database;

[0079] Taking the database object set, the field, the field type, and the position of the field in the data table as the configuration item.

[0080] Further, the processor 1001 can invoke the data rollback program stored in the memory 1003, and further perform the following operations:

[0081] Sending the data change information to a consumer queue as a consumer event;

[0082] Based on a plurality of consumer threads polling data change information in the consumption queue, and binding a batch number identifier for the data change information;

[0083] The data change information after binding the batch number identifier is saved in the memory.

[0084] Further, the processor 1001 can call the data rollback program stored in the memory 1003, and further perform the following operations:

[0085] Obtaining a transaction identifier corresponding to a current transaction of the database;

[0086] Associating and binding the batch number identifier corresponding to the changed data in the current transaction with the transaction identifier.

[0087] Further, the processor 1001 can call the data rollback program stored in the memory 1003, and further perform the following operations:

[0088] According to the rollback instruction, determine the target transaction identifier, and determine the batch number identifier associated with the target transaction identifier, and take the data change information corresponding to the batch number identifier as the target data change information; or

[0089] According to the rollback instruction, determine the batch number identifier, and take the data change information corresponding to the batch number identifier as the target data change information.

[0090] Further, the processor 1001 can call the data rollback program stored in the memory 1003, and further perform the following operations:

[0091] According to the data change information, determine the to-be-displayed information corresponding to each changed data;

[0092] Generating a graphical interface according to the to-be-displayed information;

[0093] Receiving a rollback instruction of a user based on the graphical interface.

[0094] In the following, the content claimed in the claims of the present application is explained and described through specific exemplary schemes, so that those skilled in the art can better understand the protection scope of the claims of the present application. It can be understood that the following exemplary schemes do not limit the protection scope of the present application, but are only used to explain the present application.

[0095] Exemplarily, with reference to Figure 2 In an embodiment of the data rollback method of the present application, the data rollback method comprises the following steps:

[0096] Step S10, listening to the binary log of the database, and determining the data change information corresponding to the changed data in the database according to the binary log;

[0097] In the embodiment, the database is a collection of a large amount of data stored in a computer for a long time, organized, shareable and uniformly managed. In the process of using the database, data error changes, accidental deletion and the like are inevitable, and the data change operation already performed needs to be withdrawn, so as to restore the changed data to the data before the change, that is, data rollback. However, the current data rollback is directly rolled back by the database, and the following disadvantages exist:

[0098] 1. The rollback action itself takes time, and the direct database rollback needs to define what needs to be rolled back and what does not need to be rolled back, specify time, version and the like, which are relatively very cumbersome.

[0099] 2. There is no association with business data: the rollback is based on the database level, and the positioning data and the accuracy of the data are not good, the data range affected by the user's perspective cannot be checked, and a graphical interface cannot be provided for data filtering, rollback operation and other operation and maintenance means.

[0100] 3. No full life cycle monitoring of the database table data is formed, and the process data of the change cannot be provided.

[0101] 4. For the inventory system, the data does not have a logical deletion field, and in the case of accidental deletion of data, a faster data rollback operation cannot be provided.

[0102] The log monitoring application provides continuous database data change monitoring, and the log monitoring application can be a binlog client of a mysql-binlog-connector open source component. The binlog client obtains the binlog (binary log) of the database to synchronize the changed data, parses the binlog after obtaining the binlog, and obtains the data change information of each row of each table. The data change information of each row of each table is stored, and the storage layer can be selected according to the actual situation, and the storage systems such as mysql, es and hbase can be selected.

[0103] Step S20, when the rollback instruction is received, the target data change information corresponding to the rollback instruction is determined;

[0104] In the embodiment, after the data change information is stored, when the user needs some data, such as data rollback of a row or a transaction, the rollback instruction corresponding to the changed data can be triggered to determine the changed data that needs to be rolled back in the data rollback instruction. The changed data that needs to be rolled back can be the changed data of a row that needs to be rolled back, or the changed data of a transaction that needs to be rolled back. The target data change information corresponding to the changed data that needs to be rolled back is extracted from the storage system.

[0105] Step S30, generating rollback code reversely according to target data change information, and executing the rollback code.

[0106] In the embodiment, the data change information is detailed to the change data of each row in each table before and after data change. Based on the data change information, rollback code can be generated reversely, and the rollback code in the database refers to rollback SQL. The rollback SQL is a database language with multiple functions such as data manipulation and data definition. Executing the rollback code can make the change data corresponding to the rollback instruction return to the state before data change, and realize data rollback.

[0107] In the technical solution disclosed in the embodiment, the binary log of the database is listened to, the data change information corresponding to the change data in the database is determined according to the binary log, when the rollback instruction is received, the target data change information corresponding to the rollback instruction is determined, rollback code is generated reversely according to the target data change information, and the rollback code is executed. In this way, the binary log of the database is listened to, the data change information corresponding to the change data is obtained, the user can specify the target change information to be rolled back through the rollback instruction, the rollback code is automatically generated reversely according to the target change information, and the rollback code is executed to realize the rollback of the change data corresponding to the target data change information, thereby improving the data rollback efficiency.

[0108] Further, step S10 comprises:

[0109] listening to the application instance deployment log of the container management platform based application;

[0110] when the application instance is ready, triggering a readiness probe, and competing for a distributed lock;

[0111] when the competition is successful, initializing the configuration item of the log listening application based on the application instance, and listening to the binary log based on the configuration item;

[0112] triggering a live probe in the running process of the application instance, and renewing the distributed lock, so that the log listening application continuously listens to the binary log.

[0113] In the embodiment, in order to control the log monitoring application to monitor the database binary log, a container management platform such as kubernetes that can apply a service to multiple AZs and multiple application instances in a distributed deployment scenario can be used to manage the running of the log monitoring application, thereby improving the high availability of the service. The log monitoring application is embedded in the normal business system, and the log monitoring application is deployed based on the application instance (pod) of the kubernetes container management platform. In the case of N application instances alive, if multiple log monitoring applications are started and log collection occurs at the same time, the same data change will inevitably produce N binlog log analysis data stored in the storage system, and will also cause the master database and slave database synchronization delay problem of the database, reducing the execution efficiency of the database. Therefore, the log monitoring application singleton needs to be started and executed.

[0114] The starting of the log monitoring application and the continuous log monitoring application are implemented by two probes, namely the readiness probe and the liveness probe. Referring to Figure 4 , the log monitoring application is deployed based on the application instance of the container management platform; when the application instance is ready, the readiness probe is triggered, and the distributed lock is competed for; when the competition is successful, the configuration items of the log monitoring application are initialized based on the application instance, the binary log is monitored based on the configuration items, and the liveness probe is triggered during the running of the application instance to renew the distributed lock, so that the log monitoring application continuously monitors the binary log.

[0115] Specifically, the kubernetes platform provides a readinessProbe probe (readiness probe) and a livenessProbe probe (liveness probe), a binlog client (log monitoring application) of a mysql-binlog-connector open source component is deployed based on a pod, when the pod is successfully ready, the readinessProbe probe is triggered, the distributed lock is competed for, and if the competition is successful, all related configuration items of the binlog client are initialized, these configuration item information is stored in the application memory, the configuration items can include binlog client initialization, database table description identification, last log collection position and binlog file name, and the binlog client is monitored based on the initialized binlog client. In this way, the corresponding data change information is extracted from the binlog log based on the configuration items, which can improve the log analysis data performance,

[0116] In the process of pod running, that is, the running process of the application instance, the readinessProbe probe has been successfully executed, and the current pod successfully competes for the distributed lock, the renewal of the distributed lock ensures that only the current pod can normally collect the log.

[0117] In this way, by competing for the distributed lock through the readiness probe and the liveness probe, the same binary log is avoided from being collected by multiple application instances repeatedly deploying the log monitoring application, so as to achieve the effect of singleton running and singleton log collection, ensure the normal application of monitoring the log, and thus improve the data rollback efficiency.

[0118] The step of triggering the liveness probe in the running process of the application instance, renewing the distributed lock, so that the log monitoring application continuously monitors the binary log, further comprises:

[0119] When the stop condition of monitoring the binary log is met, a stop probe is triggered, and the log position currently monitored by the log monitoring application is determined based on the stop probe, and the current application instance is stopped;

[0120] When the next application instance is ready, the log position is taken as a monitoring start position corresponding to the log monitoring application in the next application instance;

[0121] The stop condition of monitoring the archived log includes at least one of the following:

[0122] The application instance fails, restarts, or is redeployed;

[0123] A stop instruction of monitoring the archived log is received.

[0124] In this embodiment, when the application instance of the container management platform deploys the log monitoring application, the situation that the application instance needs to be stopped occurs, for example, when the application instance needs to be redeployed, restarted, or hung up, the current application instance needs to be paused, and a new application instance will replace the abnormal application instance to continue collecting the log. Thus, with reference to Figure 4 When the stop condition of monitoring the binary log is met, a stop probe is triggered. The stop condition of monitoring the binary log includes the failure, restart, or redeployment of the application instance, and / or the reception of a stop instruction of monitoring the binary log. When the stop probe is triggered, the current application instance is stopped, and the log position currently monitored by the log monitoring application can be determined based on the stop probe. When the next application instance is ready, the log position is taken as a monitoring start position corresponding to the log monitoring application in the next application instance, and the monitoring of the database is continued from the monitoring start position to ensure the integrity of the monitoring.

[0125] Specifically, the kubernetes platform also provides a preStop probe (stop probe) for stopping the running of a pod, and when the pod stops, the log monitoring application corresponding to the pod also stops running. When the pod stops, the log monitoring application can be notified through the preStop probe to record the current log collection position position, and when the next readinessProbe probe is triggered, that is, the next pod is ready, the log collection position position is a configuration item for the initialization of the readinessProbe of the next normally running pod, and the log is collected from the log collection position position.

[0126] Exemplarily, in the case where the normal database table does not change, the normal log collection is not a problem, but if the DBA or the database deployment executes a DDL sql to modify the database table, the binlog log collection needs to track the field changes of each table to ensure that each log collection can listen to the changes of all fields, and there is no data loss of the fields during rollback. This process cooperates with the log monitoring to realize full automation. However, this means that the binary log of the database needs to be listened to for a long time, and when the data in the database changes frequently, the binlog log will surge, and when the database reaches a certain size of the binlog log file or the mysql is restarted, a new binglog file will be generated to record the log. This will face the problem of how to handle too many binary logs, and how to continue to monitor after the database switches the binary log file:

[0127] For the problem of how to handle too many binary logs, a timing task can be set to realize timing monitoring, and the timing task is executed once an hour to clean up the data in the historical period. Since the production environment is not stopped for maintenance, the amount of log record data generated is large, and it is necessary to clean up the data of a more recent period, such as the data 3 days ago. The data amount in the non-production environment is small, and the cleaning time can be extended, such as cleaning the data of 7 days, so as to prevent the problem of too much data to be stored.

[0128] For the problem of how to continue to listen to the binary log file after the database switch, when the current application instance is successfully running, the readiness probe is executed successfully, the binary log file name recorded by the current log listening application is initialized, and the binary log file name recorded by the current log listening application is compared with the binary log file name obtained when the previous readiness probe is executed. If the file names are inconsistent, it means that the database has switched the binary log file, and then the log listening application will listen to the binary log file corresponding to the latest determined binary log file name, and the starting position of the binary log file will be used as the listening starting position of the log listening application in the application instance corresponding to the next readiness probe. For example, when the timing task is executed, the sql: show master status is executed to obtain the current latest recorded binlog file. If the initialized binlog file name is inconsistent with the binlog file name of the latest recorded log, it means that the mysql switches the recording log binlog file, such as from binlog.000047 to binlog.000048. The binlog client will listen to a new binlog file, and record the binlog log from the beginning of the log record, that is, from the position=4 place. And save the binlog file name and position to the database for the next initialization of the binlog client.

[0129] In this way, when the application instance fails, restarts, is redeployed, and / or receives a stop instruction for listening to the binary log, the application instance can stop listening to the database through the stop probe, and continue to listen to the log position through the record of the current listened log position when the next application instance is ready. The integrity of the database is ensured, and the data rollback efficiency is improved.

[0130] Further, the step of initializing the configuration item of the log listening application based on the application instance includes:

[0131] Obtaining the database object set corresponding to each field, the field type, and the position of the field in the table in the database;

[0132] The database object set, the field, the field type, and the position of the field in the data table are used as the configuration item.

[0133] In the embodiment, after triggering the readiness probe, the configuration item of the log listening application initialization needs to be completed, and the binary log is listened to based on the configuration item. In order to ensure that the data change information is saved to the database after the collected binary log is parsed in the log listening process, the data change information needs to be saved to the database consistent with the database of the collected log. Specifically, refer to Figure 5The database object set (schema), field type, and field position in the table of each data table in the collected database are acquired, and the database object set, field, field type, and field position in the table are taken as configuration items for initializing the log monitoring application, wherein the field type also needs to include an identifier of whether it is a primary key, because the deletion operation is based on the primary key.

[0134] In this way, the data change information and the fields of the collected log database are kept consistent, and the fields of the rollback code are also kept consistent with the fields of the collected log database, so that the changes of the fields can be recorded in real time, the initialization configuration items saved in the application local memory are convenient to obtain, and the data rollback efficiency is improved.

[0135] Optionally, referring to Figure 3 , based on any of the above embodiments, in another embodiment of the data rollback method of the application, after step S10, the data rollback method further includes:

[0136] Step S40, sending the data change information as a consumption event to a consumption queue;

[0137] Step S50, polling the data change information in the consumption queue based on multiple consumption threads, and binding a batch number identifier to the data change information;

[0138] Step S60, saving the data change information after binding the batch number identifier in the storage.

[0139] In this embodiment, in order to ensure that the data change parsing can be performed as quickly as possible, the production-consumer mode is used for rapid parsing. The production end is a log monitoring application, which is used to collect the binary log synchronized from the database. After the data is parsed in the production end to obtain the data change information, the data change information is transmitted to the local consumption queue as a consumption event. Multiple local consumption queues can be established, so that the data change information in the consumption queue is polled based on multiple consumption threads, a batch number identifier is bound to each piece of data change information, the batch number identifier is used to distinguish each piece of data change information, a single data rollback operation is facilitated, and then the data change information after binding the batch number identifier is saved in the storage.

[0140] In the technical solution disclosed in the embodiment, the data change information is sent to a consumption queue as a consumption event, data change information in the consumption queue is polled based on multiple consumption threads, and a batch number identifier is bound for the data change information, and the data change information after being bound with the batch number identifier is saved in a storage. In this way, the binary log is quickly parsed in a producer-consumer mode, and the data change information in the consumption queue is polled based on multiple consumption threads, so that the throughput performance of log consumption is improved, and the data rollback efficiency is improved.

[0141] Further, before the step of polling the data change information in the consumption queue based on multiple consumption threads and binding a batch number identifier for the data change information, the method further comprises:

[0142] obtaining a transaction identifier corresponding to a current transaction of the database;

[0143] associating and binding the batch number identifier corresponding to the changed data in the current transaction with the transaction identifier.

[0144] In the embodiment, the transaction identifier can also be set to distinguish the data change information in the execution process of each transaction, so as to facilitate the rollback operation in a transaction unit. Before the step of binding a batch number identifier for the data change information, a transaction identifier corresponding to a current transaction of the database is obtained, which is also a global transaction identifier. The transaction identifier is used for the operation based on transaction rollback, and the batch number identifier corresponding to the changed data in the current transaction is bound with the transaction identifier. In this way, when a rollback instruction corresponding to the transaction identifier is received, the corresponding batch number identifier can be indexed through the transaction identifier, so that the rollback of the changed data under a transaction is completed.

[0145] In this way, the transaction identifier is bound with the batch number identifier corresponding to the changed data in the transaction, so that the data rollback in a transaction unit can be realized, and the efficiency of data rollback is improved.

[0146] The following provides a specific application scenario, referring to Figure 6 :

[0147] The production end is a binlog client, which is used to collect the log synchronized from the master of the database, and obtain a global transaction ID, which is used for the operation based on transaction rollback. After the data is parsed in the production end, the data change information is transmitted to a local consumption queue Disruptor, so as to improve the throughput performance of log consumption. The local consumption queue trains and consumes the data change information of the production end, and a batch number identifier batchId is marked for the data change information of each row of changed data of each database table, and the batch number identifier batchId is used for the operation based on single data rollback.

[0148] Referring to Figure 7For a transaction, the mysql generates a Gtid, the transaction operates data changes of multiple tables, and the data change information of each row of each database table is bound to a batchId, and the field of the record table before and after the change data is recorded, thus forming the following necessary conditions: multiple batchIds are bound under a Gtid, which is used to implement data rollback of a transaction; and a batchId implements rollback of single-row change data of a single table.

[0149] Further, the step of determining the target change data corresponding to the rollback instruction comprises:

[0150] determining a target transaction identifier according to the rollback instruction, determining a batch number identifier associated with the target transaction identifier, and taking change data corresponding to the batch number identifier as the target change data; or

[0151] determining a batch number identifier according to the rollback instruction, and taking change data corresponding to the batch number identifier as the target change data.

[0152] In this embodiment, since each transaction identifier is bound to multiple batch number identifiers, and each batch number identifier is bound to data change information corresponding to multiple single change data, the rollback instruction can specify a target transaction identifier or a batch number identifier that needs to be rolled back, so as to implement data rollback of the target transaction or the target change data. Specifically, a target transaction identifier is determined according to the rollback instruction, a batch number identifier associated with the target transaction identifier is determined, and data change information corresponding to the batch number identifier is taken as target data change information, or a batch number identifier is determined according to the rollback instruction, and data change information corresponding to the batch number identifier is taken as target data change information.

[0153] For example, when a user triggers a rollback instruction, one-time transaction rollback, i.e., Gtid rollback, or rollback according to data change information of a row of a table, i.e., batchId rollback, can be selected, and the analysis process is as follows: selecting a rollback mode, if the rollback is based on a transaction, multiple batchIds are associated with this Gtid, and data change information of a row of a table is queried according to the batchId; if the rollback is based on a batch, data change information of a row of a table is directly queried according to the batchId.

[0154] For a delete operation: according to the data change information, the data before the change of each field is obtained, and then an insert sql is reversely generated, i.e., insert into xx table (field 1, field 2) values (field 1 changed value, field 2 changed value);

[0155] For the insert operation: according to the data change information, the changed data of each field is obtained, and the field, the primary key, and the field content are bound and associated, and a delete sql based on the primary key is reversely deleted, such as delete from xx table where primary key = 'xxx';

[0156] For the update operation: according to the data change information, the changed data of each field is obtained, and the field, the primary key, and the field content are bound and associated, and an update sql based on the primary key is reversely generated, such as update xx table set field1 = field1 changed value, field2 = field2 changed value where primary key = 'xxx'.

[0157] All the above sqls are reversely generated, which will start a database execution transaction, execute the sqls, and complete the data rollback. During the rollback operation, the database does not need to perform binlog rollback, there is no business downtime risk, and data change history can be formed for auditing.

[0158] In this way, the rollback instruction is used to realize the rollback of the transaction or the rollback of the single changed data, thereby improving the data rollback efficiency.

[0159] Further, after the step of listening to the binary log of the database and determining the data change information corresponding to the changed data in the database according to the binary log, the method further includes:

[0160] determining the to-be-displayed information corresponding to each changed data according to the data change information;

[0161] generating a graphical interface according to the to-be-displayed information;

[0162] receiving a rollback instruction of a user based on the graphical interface.

[0163] In the embodiment, in order to facilitate the user to select the target data change information to be rolled back, a graphical operation interface of the user's perspective needs to be provided. First, the data change information that can be rolled back or the data change information corresponding to the currently logged-in user that can be rolled back is determined. Then, the to-be-displayed information corresponding to each changed data that can be rolled back is determined according to the data change information, including the database of the changed data, the log recording time, the target field that is changed, the field value, the comparison before and after the data change, the DML type, and the like. The graphical interface that can perform the rollback operation on a piece of changed data or the rollback operation on a transaction is generated according to the to-be-displayed information. Refer to Figure 8 The graphical interface can also provide the data change history, including all operation conditions from addition, update to deletion, for analysis, identification, and auditing.

[0164] In this way, the user can conveniently screen the data to be operated to perform the rollback operation, the user can conveniently issue the rollback instruction, and the data rollback efficiency can be improved.

[0165] In addition, the embodiment of the present application further provides a data rollback device, which comprises a memory, a processor and a data rollback program stored in the memory and executable on the processor, and when the data rollback program is executed by the processor, the steps of the data rollback method according to the above various embodiments are implemented.

[0166] In addition, the embodiment of the present application further provides a computer readable storage medium, which stores a data rollback program, and when the data rollback program is executed by a processor, the steps of the data rollback method according to the above various embodiments are implemented.

[0167] It should be noted that, in this document, the terms "comprising", "including", or any other variant thereof are intended to cover non-exclusive inclusion, so that processes, methods, articles or systems including a series of elements not only include those elements, but also include other elements not explicitly listed, or further include elements inherent in such processes, methods, articles or systems. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or system including the element.

[0168] The above embodiment numbers of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.

[0169] From the above description of the embodiments, those skilled in the art can clearly understand that the above embodiment methods can be realized by means of software and necessary general hardware platforms, of course, they can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as a ROM / RAM, a magnetic disk, an optical disk) as described above, and includes a plurality of instructions for enabling a data rollback device to execute the method described in each embodiment of the present application.

[0170] The above is only the preferred embodiment of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied to other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A data rollback method, characterized by, The data rollback method comprises: An application instance deployment log monitoring application based on a container management platform is listened to; When the application instance is ready, a readiness probe is triggered, and a distributed lock is competed for; When the competition is successful, configuration items of the log monitoring application are initialized based on the application instance, binary logs of a database are monitored based on the configuration items, and data change information corresponding to changed data in the database is determined according to the binary logs; A liveness probe is triggered in the running process of the application instance, and the distributed lock is renewed, so that the log monitoring application continuously monitors the binary logs; When a stop condition of monitoring the binary logs is met, a stop probe is triggered, a log position currently monitored by the log monitoring application is determined based on the stop probe, and the current application instance is stopped; When a next application instance is ready, the log position is taken as a monitoring start position corresponding to the log monitoring application in the next application instance; When a rollback instruction is received, target data change information corresponding to the rollback instruction is determined; Rollback code is reversely generated according to the target data change information, and the rollback code is executed; The stop condition of monitoring the binary logs comprises at least one of the following: The application instance fails, restarts, or is redeployed; A stop instruction of monitoring the binary logs is received.

2. The data rollback method of claim 1, wherein, The step of initializing the configuration items of the log monitoring application based on the application instance comprises: Database object sets, fields, field types, and positions of the fields in tables in the database are obtained; The database object sets, the fields, the field types, and the positions of the fields in the tables are taken as the configuration items.

3. The data rollback method of claim 1, wherein, After the step of monitoring the binary logs of the database based on the configuration items and determining data change information corresponding to changed data in the database according to the binary logs, the following steps are further included: The data change information is sent to a consumer queue as a consumption event; Data change information in the consumer queue is polled based on multiple consumer threads, and batch number identifiers are bound for the data change information; The data change information bound with the batch number identifiers is saved in a storage.

4. The data rollback method of claim 3, wherein, Before the step of polling the data change information in the consumer queue based on the multiple consumer threads and binding batch number identifiers for the data change information, the following steps are further included: A transaction identifier corresponding to a current transaction of the database is obtained; Batch number identifiers corresponding to changed data in the current transaction are associated and bound with the transaction identifier.

5. The data rollback method of claim 4, wherein, The step of determining target data change information corresponding to the rollback instruction comprises: A target transaction identifier is determined according to the rollback instruction, and a batch number identifier associated and bound with the target transaction identifier is determined, and data change information corresponding to the batch number identifier is taken as the target data change information; or A batch number identifier is determined according to the rollback instruction, and data change information corresponding to the batch number identifier is taken as the target data change information.

6. The data rollback method of claim 5, wherein, After the step of monitoring the binary logs of the database based on the configuration items and determining data change information corresponding to changed data in the database according to the binary logs, the following steps are further included: determine, according to the data change information, to-be-displayed information corresponding to each change data; generate a graphical interface according to the to-be-displayed information; receive a rollback instruction of a user based on the graphical interface.

7. A data rollback apparatus, comprising: The data rollback device comprises a memory, a processor, and a data rollback program stored in the memory and executable on the processor, and the data rollback program, when executed by the processor, implements the steps of the data rollback method in any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a data rollback program, and the data rollback program, when executed by the processor, implements the steps of the data rollback method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data processing method and device, electronic equipment and computer storage medium

    CN112306743A

  • Table lock implementation method based on distributed database

    CN112835982A