CN-122019239-A - Database exception handling method, device and equipment
Abstract
The invention provides a database exception handling method, device and equipment, which can be applied to the technical field of computers. The method comprises the steps of responding to an abnormality notification sent by a main database, determining an abnormality type triggered by the main database based on the abnormality notification, comparing the abnormality time of an operation log in the abnormality notification with a mark time to obtain a comparison result when the abnormality type is used for recording the abnormality of an operation log in a data changing process in the main database, and sending an update instruction to the main database when the comparison result represents that the mark time is earlier than the abnormality time, wherein the update instruction is used for indicating the main database to update corresponding second table data in a physical disk based on the first table data to obtain updated second table data and updating the mark time to be a target mark time.
Inventors
- LI XUZHEN
Assignees
- 天津南大通用数据技术股份有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260407
Claims (10)
- 1. A method for exception handling of a database, applied to a management component, the method comprising: In response to receiving an exception notification sent by a main database, determining an exception type triggered by the main database based on the exception notification, wherein the main database stores a process identifier pre-registered by the management component, and sending the exception notification to the management component based on the process identifier when an exception is detected; Comparing the abnormal time of the operation log in the abnormal notification with the marked time to obtain a comparison result when the abnormal type is used for recording that the operation log in the data change process in the main database is abnormal, wherein the marked time is the completion time of the corresponding second table data in the physical disk by using the first table data stored in the main database in the business processing process; and under the condition that the comparison result represents that the marking time is earlier than the abnormal time, sending an updating instruction to the main database, wherein the updating instruction is used for indicating the main database to update corresponding second table data in a physical disk based on the first table data, obtaining updated second table data, updating the marking time to be a target marking time, and carrying out data loading based on the updated second table data and/or log data positioned after the target marking time in an operation log under the condition that the main database is restarted or the main database and a standby database are subjected to data synchronization.
- 2. The abnormality processing method according to claim 1, wherein the abnormality time is a start time in an abnormality period in which abnormality occurs in the operation log, the operation log has a corresponding status flag, the method further comprising: And under the condition that the comparison result indicates that the marking time is later than the abnormal time, sending a state switching instruction to the main database, wherein the state switching instruction is used for indicating the main database to mark log data corresponding to the abnormal time period in the operation log as a failure state and switching the log state of the operation log from the abnormal state to a normal state.
- 3. The abnormality processing method according to claim 1 or 2, characterized in that the method further comprises: And in response to receiving the update completion notification sent by the main database for the second table data, sending a data sending instruction to the main database, wherein the data sending instruction is used for instructing the main database to send the updated second table data to the standby database.
- 4. The exception handling method according to claim 1, wherein the method further comprises: And sending a table data repair instruction to the main database under the condition that the abnormal type is table data abnormality, wherein the table data repair instruction is used for indicating the main database to execute the following operations: Scanning target table data with abnormality in the first table data and the second table data to identify outdated row data in the target table data, wherein the outdated row data is deleted or updated historical row data; identifying the data state of each overdue row data to obtain an identification result; Updating the data state of the abnormal expiration row data from a visible state to an invisible state under the condition that the identification result represents that the abnormal expiration row data with the data state being the visible state exists in the target table data; And marking the storage space occupied by the outdated line data as an idle state, wherein the storage space is the space in the memory or the physical disk.
- 5. The exception handling method according to claim 4, wherein the method further comprises: And responding to the received repair failure notification from the main database, controlling the main database and the standby database to perform main-standby switching so that the standby database is used as a new main database to perform service processing, wherein the repair failure notification characterizes that the repair result of the table data repair instruction to the target table data is repair failure.
- 6. The abnormality processing method according to claim 5, characterized in that said controlling of said master database and said slave database to perform master-slave switching includes: responding to the backup database to store the updated second table data, and sending a log transmission instruction to the main database, wherein the log transmission instruction is used for instructing the main database to send the operation log to the backup database; A log application instruction is sent to the standby database, and the log application instruction is used for indicating the standby database to receive and apply the operation log on the basis of updating the second table data so as to enable the data of the standby database to be consistent with the data of the main database; And in response to receiving an application completion instruction from the standby database, sending a primary lifting instruction to the standby database so as to upgrade the standby database to a new primary database, and sending a degradation instruction to the primary database so as to enable the primary database to suspend service processing or turn into the new standby database.
- 7. The exception handling method according to claim 1, wherein the method further comprises: And under the condition that the abnormal type is a database index abnormality, sending an index rebuilding instruction to the main database, wherein the index rebuilding instruction is used for indicating the main database to rebuild a database index based on table data in the main database.
- 8. The exception handling method according to claim 1, wherein the method further comprises: responding to the abnormal type as the restart of the main database, and sending a marked file inquiry instruction to the main database, wherein the marked file inquiry instruction is used for indicating the main database to inquire marked files, and the marked files are generated under the condition of normal shutdown of the main database; And in response to receiving the query result from the main database as the absence of the markup file, determining that the main database is restarted after power failure, and indicating the main database to perform abnormality detection on the operation log, the first table data, the second table data and the database index.
- 9. An exception handling apparatus for a database, for application to a management component, the apparatus comprising: The determining module is used for responding to the received abnormal notification sent by the main database, determining the abnormal type triggered by the main database based on the abnormal notification, storing a process identifier pre-registered by the management component in the main database, and sending the abnormal notification to the management component based on the process identifier when the abnormality is detected; The comparison module is used for comparing the abnormal time of the operation log in the abnormal notification with the marked time to obtain a comparison result when the abnormal type is the abnormal operation log used for recording the data change process in the main database, wherein the marked time is the completion time of the corresponding second table data in the physical disk by using the first table data stored in the memory of the main database in the service processing process; and the sending module is used for sending an update instruction to the main database when the comparison result represents that the marking time is earlier than the abnormal time, wherein the update instruction is used for indicating the main database to update corresponding second table data in a physical disk based on the first table data, obtaining updated second table data, updating the marking time to be a target marking time, and carrying out data loading based on the updated second table data and/or log data positioned after the target marking time in an operation log when the main database is restarted or the main database and the standby database are in data synchronization.
- 10. An electronic device, comprising: one or more processors; A memory for storing one or more computer programs, The method according to any one of claims 1 to 9, characterized in that the one or more processors execute the one or more computer programs to implement the steps of the exception handling method according to any one of claims 1 to 9.
Description
Database exception handling method, device and equipment Technical Field The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, and a device for processing an exception in a database. Background In database applications, stability and high availability of databases are key to ensuring business continuity. The database may suffer from various anomalies such as downtime, data damage, log anomalies and the like in the running process, and if the anomalies cannot be found and processed in time, the anomalies can cause abnormal service of the database and even data loss. However, in the related art, the monitoring module usually adopts a polling mode to sense the database abnormality, and can only sense whether the database service is available, so that it is difficult to automatically locate a specific abnormality type. Especially for the damage scene of the operation log, it is difficult to judge whether the damage can affect the restarting of the database or the data synchronization between the active and standby databases, the processing process is complex and time-consuming, and the service is easy to interrupt for a long time. Disclosure of Invention In view of the above problems, the present invention provides a method, an apparatus, and a device for processing database exceptions. According to one aspect of the invention, an exception handling method of a database is provided, the exception handling method is applied to a management component, the exception handling method is applied to the management component, the exception handling method comprises the steps of responding to an exception notification sent by a main database, determining an exception type triggered by the main database based on the exception notification, storing a process identifier which is registered in advance by the management component in the main database, sending the exception notification to the management component based on the process identifier when the exception is detected, comparing the exception time of an operation log in the exception notification with a mark time when the exception type is used for recording an exception of an operation log of a data change process in the main database, obtaining a comparison result, wherein the mark time is a completion time when the first table data stored in a memory by the main database in a service processing process is used, updating corresponding second table data in a physical disk, sending an update instruction to the main database when the comparison result represents that the mark time is earlier than the exception time, and updating the corresponding second table data in the physical disk based on the first table data, obtaining update second table data based on the first table data, updating the mark time to be a target mark time when the main database is restarted or the main database is synchronized with the second table data based on the update log or after the operation log and the operation log is loaded in the target log. The invention provides an exception handling device of a database, which is applied to a management component and comprises a determining module, a sending module and a comparing module, wherein the determining module is used for responding to an exception notification sent by a main database, determining an exception type triggered by the main database based on the exception notification, the main database stores a process identifier which is registered in advance by the management component and sends the exception notification to the management component based on the process identifier when an exception is detected, the comparing module is used for comparing the exception time of an operation log in the exception notification with a mark time when the exception type is used for recording the exception of an operation log of a data change process in the main database, obtaining a comparison result, the mark time is the completion time of the corresponding second table data stored in a memory in a service processing process by the main database, and the sending module is used for sending an update instruction to the main database when the comparison result represents the mark time is earlier than the exception time, the update instruction is used for indicating the main database to update the corresponding second table data in a physical table based on the first table data, obtaining the update second table data, and updating the mark time to be a target mark time when the main database is restarted or the main database is located in the database and the second table is synchronized with the operation log. In another aspect, the invention provides an electronic device comprising one or more processors and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method. Another aspect of t