Database processing method and device, electronic equipment and computer program product
By using transaction identifier comparison and business data type analysis in the network partition state, a target processing strategy is formulated to insert, update and delete data in the master-slave database, which solves the data inconsistency problem of the master-slave database and improves the data recovery efficiency and accuracy.
Patent Information
- Application Number
- CN202510786396.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-09-16
AI Technical Summary
在主从数据库之间的网络分区状态下,现有技术无法有效解决数据不一致性问题,导致业务中断和数据恢复效率低下。
通过获取第一数据库和第二数据库之间的网络状态,利用事务标识符比对确定待补充业务数据,并根据业务数据类型和操作类型制定目标处理策略,包括数据插入、更新和删除策略,对第二数据库进行数据调整。
It improves the operational efficiency and accuracy of data complement in master-slave databases, reduces the time to repair data inconsistency issues, and ensures business continuity and data integrity.
Smart Images

Figure CN120653652A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and specifically, to a database processing method, device, electronic device and computer program product. Background Art
[0002] With the current transformation of IT architecture, various institutions are gradually migrating traditional data storage systems such as mainframe databases to more flexible and cost-effective open source database platforms to adapt to changing business needs and technological trends. To ensure high data availability and disaster recovery capabilities, financial institutions generally adopt a "one master and three slaves" database high-availability architecture, in which the master database is responsible for receiving and processing transaction requests, while the three slave databases are used for data replication and backup. The "one master and three slaves" high-availability strategy includes a downgrade mechanism, that is, if the master database fails to receive confirmation responses from at least a certain number of slave databases within a preset time, it will automatically switch to asynchronous replication mode to prioritize business continuity and availability.
[0003] Although the above strategy can quickly restore services when the network is unstable or the slave database fails, it sacrifices data consistency to a certain extent: in extreme cases such as network partitions, transaction data may not be successfully saved in the primary database but a successful response may be returned, resulting in inconsistency between the primary database data and the slave database data, which may further cause serious business problems such as accounting errors.
[0004] Existing database management methods lack effective remediation measures for such anomalies, particularly for data inconsistencies that may arise in network partitioning scenarios. Once some transaction data in the primary database is lost, traditional manual comparisons and reconciliations are not only time-consuming and inefficient, but also difficult to quickly restore data consistency in an emergency, negatively impacting customer service. Furthermore, due to the complexity and diversity of transaction data, simple data recovery strategies may not be able to correctly handle various database operations, further exacerbating the risk of data inconsistency.
[0005] Currently, no effective solution has been proposed to the technical problem in the related art that when the network state between the master and slave databases is in a network partition state, the data stored in the master and slave databases will be inconsistent. Summary of the Invention
[0006] The main purpose of this application is to provide a database processing method, device, electronic device and computer program product to solve the technical problem in the related art that when the network status between the master and slave databases is in a network partition state, the data stored in the master and slave databases is inconsistent.
[0007] To achieve the above-mentioned objectives, according to one aspect of the present application, a database processing method is provided. The method includes: obtaining a network status between a first database and a second database, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status includes at least an abnormal state and a normal state; when the network status is an abnormal state, obtaining a first transaction identifier of the first database and a second transaction identifier of the second database, determining M business data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer; determining a target processing strategy based on the M business data to be supplemented, and adjusting data in the second database using the target processing strategy, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least a data insertion strategy, a data update strategy, and a data deletion strategy.
[0008] Furthermore, determining the M pieces of service data to be supplemented based on the first transaction identifier and the second transaction identifier includes: comparing the total number of the first transaction identifiers and the total number of the second transaction identifiers; in a case where the total number of the first transaction identifiers and the total number of the second transaction identifiers are inconsistent, responding to the received identifier code, performing an identifier comparison on the first transaction identifier and the second transaction identifier by the identifier code to obtain a comparison result; determining different transaction identifiers according to the comparison result to obtain M missing transaction identifiers, and determining the M pieces of service data to be supplemented based on the M missing transaction identifiers.
[0009] Furthermore, determining M business data to be supplemented based on M missing transaction identifiers includes: obtaining a database log of a target database containing M missing transaction identifiers, extracting a log corresponding to each missing transaction identifier from the database log to obtain K logs, and parsing the K logs to obtain M log records, wherein the target database is the first database or the second database; obtaining a log record format configured for the first database, setting parameters for a preset log extraction tool according to the log record format to obtain a log extraction tool; using the log extraction tool to extract a query statement from each log record to obtain M query statements; in response to the received preset instructions, the preset instructions parse the M query statements to obtain M query contents, and extract M business data to be supplemented from the M query contents, wherein the M query contents include the business data to be supplemented and a business table storing the business data to be supplemented.
[0010] Furthermore, before determining the target processing strategy based on the M business data to be supplemented, the method also includes: obtaining business attributes of the business tables associated with the M business data to be supplemented, obtaining M business attributes, and determining M table types based on the M business attributes, wherein each business attribute includes the table structure and table name of each business table, and each table type includes at least one of the following: accounting type, management type, and data storage type; for one business data to be supplemented, when the table type of the business table of the business data to be supplemented is an accounting type, extracting account information from the business table, freezing the account based on the account information, and executing the step of determining the target processing strategy based on the M business data to be supplemented; when the table type of the business table of the business data to be supplemented is a management type or a data storage type, executing the step of determining the target processing strategy based on the M business data to be supplemented.
[0011] Furthermore, determining a target processing strategy based on the M business data to be supplemented includes: obtaining table types of business tables associated with the M business data to be supplemented, obtaining M table types, and determining complement priorities of the M business data to be supplemented based on the M table types; determining a complement strategy type from a query statement associated with each business data to be supplemented, obtaining M complement strategy types, wherein each complement strategy type includes at least one of the following: a data insertion strategy type, a data update strategy type, and a data deletion strategy type; generating a target processing strategy based on the M supplement priorities and the M complement strategy types.
[0012] Furthermore, determining the complement priority of M to-be-supplemented business data based on M table types includes: if the business table of the M to-be-supplemented business data includes a table type of account type, extracting N to-be-supplemented business data of account type, and determining the complement priority of the N to-be-supplemented business data of account type as the first priority, wherein N is less than or equal to M and is a positive integer; if the business table of the M to-be-supplemented business data includes a table type of management type, extracting Y to-be-supplemented business data of management type, and determining the complement priority of the Y to-be-supplemented business data of management type as the second priority, wherein Y is less than or equal to M and is a positive integer; determining the complement priority of the to-be-supplemented business data of data storage type among the M to-be-supplemented business data as the third priority, wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
[0013] Furthermore, using the target processing strategy to adjust the data of the second database includes: when the target processing strategy is a data insertion strategy, importing M business data to be supplemented into a temporary business table, and comparing the temporary business table with the business table of the first database, and when the comparison result indicates that the data is correct, importing the M business data to be supplemented into the second database; when the target processing strategy is a data update strategy, extracting updated data from the first database based on the query statement of the M business data to be supplemented, obtaining M updated data, and importing the M updated data into the second database; when the target processing strategy is a data deletion strategy, deleting the M business data to be supplemented from the second database.
[0014] To achieve the above-mentioned objectives, according to another aspect of the present application, a database processing system is provided. The system includes: a monitoring system for obtaining the network status between a first database and a second database, and sending a data processing request to the first database and the second database when the network status is abnormal; a monitoring system for receiving a first transaction identifier of the first database and a second transaction identifier of the second database, determining M business data to be supplemented based on the first transaction identifier and the second transaction identifier, determining a target processing strategy based on the M business data to be supplemented, and forwarding the target processing strategy to the second database, wherein the target processing strategy includes at least a data insertion strategy, a data update strategy, and a data deletion strategy, and M is a positive integer; a first database for sending the first transaction identifier according to the data processing request; a second database for sending the second transaction identifier according to the data processing request, and further for adjusting data using the target processing strategy.
[0015] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, which includes a stored executable program, wherein when the executable program runs, the device where the computer-readable storage medium is located is controlled to execute any of the above-mentioned database processing methods.
[0016] According to another aspect of an embodiment of the present invention, an electronic device is also provided, including one or more processors and a memory, wherein the memory stores an executable program, and the processor is used to run the program, wherein when the one or more programs are executed by one or more processors, the one or more processors implement any of the above-mentioned database processing methods.
[0017] According to another aspect of an embodiment of the present invention, a computer program product is provided. The computer program product includes a computer program, wherein when the computer program is executed by a processor, any one of the above-mentioned database processing methods is implemented.
[0018] In an embodiment of the present application, a database processing method is adopted to obtain the network status between the first database and the second database, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status at least includes: an abnormal state and a normal state; when the network status is an abnormal state, a first transaction identifier of the first database and a second transaction identifier of the second database are obtained, and M business data to be supplemented are determined based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer; according to the M business data to be supplemented, A target processing strategy is determined, and the target processing strategy is used to adjust the data of the second database, wherein the target processing strategy refers to a strategy for adjusting the second database using M business data to be supplemented, and the target processing strategy includes at least: a data insertion strategy, a data update strategy, and a data deletion strategy. This solves the technical problem in the related technology that when the network status between the master and slave databases is in a network partition state, the data stored in the master and slave databases are inconsistent. When the network status is abnormal, the business data to be supplemented is determined based on the transaction identifiers of the first database and the second database, the target processing strategy is determined according to the business data to be supplemented, and the data of the second database is adjusted using the target processing strategy, thereby achieving the technical effect of improving the operational efficiency of data supplementation in the master database and the slave database and improving the accuracy of supplementation. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which constitute part of this application, are intended to provide a further understanding of this application. The exemplary embodiments and descriptions of this application are intended to explain this application and do not constitute an improper limitation on this application. In the accompanying drawings:
[0020] Figure 1 It is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a database processing method;
[0021] Figure 2 is a flowchart of a database processing method provided in an embodiment of the present application;
[0022] Figure 3 This is a schematic diagram of a database connection provided according to an embodiment of the present application;
[0023] Figure 4 is a schematic diagram of a database processing system provided according to an embodiment of the present application;
[0024] Figure 5 is a schematic diagram of a database processing device provided according to an embodiment of the present application;
[0025] Figure 6 This is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data for analysis, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set up between this system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain the relevant information after receiving the consent information fed back by the aforementioned user or organization.
[0029] It should be noted that the collected information used in this application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant regions, take necessary confidentiality measures, do not violate public order and good customs, and provide corresponding operation entrances for users to choose to authorize or refuse use.
[0030] Example 1
[0031] According to an embodiment of the present application, an embodiment of a method for processing a database is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0032] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 It is a hardware structure diagram of a computer terminal (or mobile device) for implementing a database processing method, such as Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more ( Figure 1 The computer system includes a processor 102 (shown as 102a, 102b, ..., 102n) (the processor 102 may include but is not limited to a processing device such as a microcontroller unit (MCU) or a programmable logic device (FPGA)), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, the computer system may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS), a network interface, a keyboard, a cursor control device, a power supply, and / or a camera. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0033] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuitry". The data processing circuitry may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuitry may be a single independent processing module, or may be incorporated in whole or in part into any of the other components of the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuitry serves as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0034] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the database processing method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implementing the above-mentioned database processing method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0035] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the communications provider of the computer terminal 10. In one embodiment, the transmission device 106 includes a network interface controller (NIC) and a network interface, which can be connected to other network devices via a base station to enable communication with the Internet. In one embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0036] The display may be, for example, a touch screen liquid crystal display (LCD), which enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0037] Under the above operating environment, this application provides Figure 2 The processing method of the database shown. Figure 2 is a flowchart of a database processing method provided in an embodiment of the present application, such as Figure 2 As shown, the method includes the following steps:
[0038] Step S201: Acquire a network status between a first database and a second database, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status includes at least: an abnormal state and a normal state.
[0039] It should be noted that financial institutions' database-based applications usually adopt a "one master and three slaves" high-availability architecture, and the high-availability strategy can be a "one master and three slaves" degradable strategy. Under this strategy, business availability is prioritized, and master-slave consistency cannot be guaranteed in the event of a network partition failure. Figure 3 This is a schematic diagram of the connection of the database provided in the embodiment of the present application. Figure 3 As shown, financial institutions can set up multiple databases in two parks (i.e., Park A and Park B), Park A includes a master database and a slave database, and Park B includes two slave databases. When a transaction is performed, the business data generated by the transaction can be stored in the master database through a container, and in order to ensure data consistency management, the business data in the master database can be backed up to the slave database through semi-synchronous replication. In order to achieve timely backup and consistency management of data, it is first necessary to determine the network status between databases, that is, to accurately evaluate the network connection between the first database (which can be the master database or the slave database) and the second database (which can be the master database or the slave database) so that when network problems are discovered, they can respond in time to ensure accurate replication and complete transmission of data. Among them, network monitoring tools can be used to monitor key indicators such as network delay, packet loss rate, bandwidth usage, etc. between the two databases to determine the health status of the network connection; a heartbeat mechanism can also be set between databases to detect the stability and response time of the network connection by regularly sending heartbeat packets. If no response is received from the other party within a certain period of time, it is considered a network abnormality.
[0040] In addition, the network state can include a normal state and an abnormal state. The abnormal state can refer to a network partition state, that is, when the master database receives a new transaction, it will send the transaction to the slave database and wait for the slave database's response. If no response is received within the maximum timeout waiting time (for example, 3 seconds), the master database will switch from a semi-synchronous state to an asynchronous state, no longer waiting for the slave database's response, and directly return a prompt message indicating that the transaction was successfully written. Subsequent transactions will only notify the slave database without waiting for the slave database's response. After the fault is resolved, the slave database data gradually recovers to be close to the master database, and the high availability management component restarts the master-slave semi-synchronous replication. The transaction is successfully written and the business can proceed normally. For example, when the network between the master database and the high availability component and each slave database is abnormal, but the network between the master database and the application is normal, due to the three-second degradation, the application can continue to write business data to the master database. At this time, because the high availability component cannot detect the state of the master database, and the slave database detects that the master database is also abnormal, it will promote a slave database to the master. In this way, there will be a phenomenon where both master databases in a database group can write, thereby generating a network partition state, resulting in inconsistent business data.
[0041] Step S202: When the network status is abnormal, obtain a first transaction identifier of the first database and a second transaction identifier of the second database, and determine M business data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer.
[0042] Specifically, when a network anomaly, such as a network partition, occurs, data replication between the primary and secondary databases may be interrupted or erroneous, leading to data inconsistency. Data recovery can be performed based on a transaction identifier (GTID). A GTID, also known as a global transaction identifier, consists of a UUID (Unique Universal Identifier) and a sequence number, and identifies each transaction in a database. Under normal network conditions, GTIDs enable the secondary database to accurately track and recover transaction records from the primary database, thereby maintaining data consistency. Under abnormal network conditions, by obtaining the first transaction identifier of a first database (primary or secondary) and the second transaction identifier of a second database (another primary or secondary), the differences in the status of completed transactions between the primary and secondary databases can be compared. The GTID lists of the first and second databases can then be compared to identify the set of transactions that were executed in the first database but not successfully replicated in the second. Based on the GTID comparison results, the specific business data corresponding to the missing transaction identifiers can be analyzed to locate the scope of the data inconsistency and determine the multiple business data to be supplemented.
[0043] Step S203, determine the target processing strategy based on the M business data to be supplemented, and use the target processing strategy to adjust the data in the second database, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least: data insertion strategy, data update strategy and data deletion strategy.
[0044] Specifically, after identifying multiple pieces of business data to be supplemented that differ between databases, to adjust the data in the second database, the database operation type of each piece of business data to be supplemented can be evaluated, namely, whether it represents an INSERT, UPDATE, or DELETE operation. The data adjustment strategy is then prioritized based on the importance of the business data and the type of operation. For example, accounting data, as it involves financial security, has a higher priority than management data.
[0045] Furthermore, based on the above analysis results, specific target processing strategies are formulated for the second database. For example, for data entries that exist in the first database but are missing in the second database, a data insertion strategy is implemented; if some records in the second database are inconsistent with those in the first database, a data update strategy is adopted; after executing a DELETE operation in the first database, if the second database fails to synchronously delete the relevant records, a data deletion strategy is implemented.
[0046] It should be noted that to improve the efficiency and accuracy of data adjustments, parallel processing can be performed. This means that multiple data adjustment processes can be initiated simultaneously and processed in parallel to accelerate data recovery. When performing data insertion, update, or deletion operations, transaction management is used to ensure the atomicity of data adjustments. This means that all data adjustments must either succeed or fail, thereby avoiding possible data conflicts or inconsistencies. A strict data verification mechanism is implemented during the data adjustment process. This means that if any data errors or anomalies are discovered during the adjustment process, the adjustment is immediately stopped and the data is rolled back to restore to the state before the adjustment to avoid further data corruption.
[0047] The database processing method provided by the embodiment of the present application obtains the network status between the first database and the second database, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status at least includes: an abnormal state and a normal state; when the network status is an abnormal state, obtains a first transaction identifier of the first database and a second transaction identifier of the second database, and determines M business data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer; determines based on the M business data to be supplemented A target processing strategy is used to adjust the data of the second database using the target processing strategy, wherein the target processing strategy refers to a strategy for adjusting the second database using M business data to be supplemented, and the target processing strategy includes at least: a data insertion strategy, a data update strategy, and a data deletion strategy, which solves the technical problem in the related technology that when the network status between the master and slave databases is in a network partition state, the data stored in the master and slave databases are inconsistent. When the network status is abnormal, the business data to be supplemented is determined based on the transaction identifiers of the first database and the second database, the target processing strategy is determined according to the business data to be supplemented, and the target processing strategy is used to adjust the data of the second database, thereby achieving the technical effect of improving the operational efficiency of data supplementation in the master database and the slave database and improving the accuracy of supplementation.
[0048] Optionally, in the database processing method provided in the embodiment of the present application, determining M pieces of business data to be supplemented based on the first transaction identifier and the second transaction identifier includes: comparing the total number of the first transaction identifiers and the total number of the second transaction identifiers; in a case where the total number of the first transaction identifiers and the total number of the second transaction identifiers are inconsistent, responding to the received identifier code, performing an identifier comparison on the first transaction identifier and the second transaction identifier by the identifier code to obtain a comparison result; determining different transaction identifiers according to the comparison result to obtain M missing transaction identifiers, and determining M pieces of business data to be supplemented based on the M missing transaction identifiers.
[0049] When determining the business data to be supplemented, the missing business data can be quickly identified and supplemented based on a mechanism that compares the total number of GTIDs and locates missing transaction identifiers. Specifically, the GTID lists of the first database (e.g., the master database) and the second database (e.g., the slave database) can be obtained first, and the total number of GTIDs of each can be determined. At this point, information about the current GTID execution status can be obtained by executing the "SHOW MASTER STATUS" or "SHOW SLAVE STATUS" command.
[0050] Furthermore, the total number of GTIDs in the first database is compared with the total number of GTIDs in the second database. If the two are inconsistent, it indicates that data inconsistency occurs between the first database and the second database due to network failure, replication delay, or data loss. At this time, the received identifier code can be responded to, and a complete GTID list can be obtained from the first database. It is compared item by item with the GTID list of the second database to locate the missing GTID, that is, to obtain multiple missing transaction identifiers. Finally, the corresponding business data to be supplemented is obtained based on the missing transaction identifier. This embodiment uses the transaction identifier GTID to accurately identify which transactions are missing in the second database, thereby performing targeted data supplementation, avoiding unnecessary resource waste of blind data recovery, shortening the repair time of data consistency problems, and reducing the impact on business operations.
[0051] Optionally, in the database processing method provided in the embodiment of the present application, determining M business data to be supplemented based on M missing transaction identifiers includes: obtaining a database log of a target database containing M missing transaction identifiers, extracting a log corresponding to each missing transaction identifier from the database log to obtain K logs, and parsing the K logs to obtain M log records, wherein the target database is the first database or the second database; obtaining a log record format configured for the first database, setting parameters for a preset log extraction tool according to the log record format, and obtaining a log extraction tool; using the log extraction tool to extract a query statement from each log record to obtain M query statements; in response to the received preset instruction, parsing the M query statements by the preset instruction to obtain M query contents, and extracting M business data to be supplemented from the M query contents, wherein the M query contents include the business data to be supplemented and a business table storing the business data to be supplemented.
[0052] Specifically, after locating the missing transaction identifiers, the corresponding database logs can be accurately extracted and parsed to obtain detailed business data and operation information. First, the database log file (also known as the database log, which can be referred to as the binlog) containing the M missing transaction identifiers can be obtained. Then, the log information corresponding to each missing transaction identifier can be extracted from the database log. The binlog can record all changes to the database.
[0053] Furthermore, by using the log record format configured in the first database to set the "--base64-output=decode-rows" parameter of the log extraction tool or binlog parsing tool, and then parsing the corresponding binlog file based on the binlog parsing tool or log extraction tool, detailed information of each transaction marked with GTID (which may include INSERT, UPDATE, DELETE statements and related data) is obtained, thereby extracting specific SQL (Structured Query Language) query statements.
[0054] Furthermore, the above query statement is parsed and processed through the preset instructions of "mysqlbinlog--base64-output=decode-rows-vvmysql-bin.001619" or "showbinlogeventsin'mysql-bin.001619'" to obtain the corresponding query content, wherein the query content can include the transaction operation type (INSERT, UPDATE, DELETE), the business table involved and the specific data content. Finally, the business data to be supplemented is extracted from the query content, and finally a customized data supplement plan can be formulated based on the business data to be supplemented. For example, for the INSERT operation, the original SQL statement can be directly executed to insert the data; for the UPDATE operation, the latest data status must be queried first, and then the update statement must be executed; and for the DELETE operation, the existence of the data must be found and verified, and then the deletion must be performed safely. This embodiment parses and utilizes the database log to obtain the corresponding business data to be supplemented, thereby achieving refined recovery of missing data, reducing the possibility of operational errors, and laying a data foundation for improving the efficiency of data recovery.
[0055] Optionally, in the database processing method provided in the embodiment of the present application, before determining the target processing strategy based on the M business data to be supplemented, the method also includes: obtaining business attributes of the business table associated with the M business data to be supplemented, obtaining M business attributes, and determining M table types based on the M business attributes, wherein each business attribute includes the table structure and table name of each business table, and each table type includes at least one of the following: account type, management type, and data storage type; for one business data to be supplemented, when the table type of the business table of the business data to be supplemented is an account type, extracting account information from the business table, freezing the account based on the account information, and executing the step of determining the target processing strategy based on the M business data to be supplemented; when the table type of the business table of the business data to be supplemented is a management type or a data storage type, executing the step of determining the target processing strategy based on the M business data to be supplemented.
[0056] Specifically, before determining the target processing strategy based on the parsed business data to be supplemented, in order to minimize the impact on business operations, the business table can be processed by analyzing the business attributes of its associated business table. First, the business attributes of the business table associated with the business data to be supplemented are obtained, and the business tables are divided into different types. For example, table types can include accounting types (tables directly related to customer fund transactions), management types (tables used to manage database or system operation status), and data storage types (tables that store non-accounting, non-management business data and batch management data).
[0057] Furthermore, if the business table to be supplemented is of the account type, the relevant account information must first be extracted from the business table, including key fields such as account number, transaction amount, and transaction time. Based on this account information, the relevant accounts are temporarily frozen (i.e., locked) to prevent the risk of new data inconsistencies due to new transactions during the data supplementation process. The data supplementation operation is then performed again with the accounts frozen to ensure that the supplemented data is correct and complies with business rules.
[0058] For management-type and data storage-type business tables, if there is business data to be supplemented, data supplementation can be performed directly without freezing the account. It should be noted that although the accounts corresponding to these business tables do not require freezing, data verification is still required after data supplementation to ensure data integrity and correctness. By utilizing table types to perform corresponding account processing, this embodiment effectively controls the risks that may arise from data inconsistencies, prevents potential financial losses or service interruptions, minimizes business disruptions caused by the data supplementation process, ensures a high level of business continuity, and improves the speed and efficiency of data recovery.
[0059] Optionally, in the database processing method provided in the embodiment of the present application, determining the target processing strategy based on M business data to be supplemented includes: obtaining the table type of the business table associated with the M business data to be supplemented, obtaining M table types, and determining the complement priority of the M business data to be supplemented based on the M table types; determining the complement strategy type from the query statement associated with each business data to be supplemented, obtaining M complement strategy types, wherein each complement strategy type includes at least one of the following: data insertion strategy type, data update strategy type, and data deletion strategy type; generating the target processing strategy based on the M supplement priorities and the M complement strategy types.
[0060] Specifically, when determining the target processing strategy based on the business data to be supplemented, the table type (which can be categorized as accounting type, management type, data storage type, etc.) associated with each business data to be supplemented can be obtained first. The supplement priority is then set based on the table type. For example, since the accounting type table is directly associated with funds, it can be given the highest priority. The management type table and the data storage type table are ranked according to the business impact and data recovery difficulty, and are given a lower priority.
[0061] Furthermore, for each business data to be supplemented, its associated query statement is analyzed to determine the complement strategy type. For example, the complement strategy type can be identified as a data insertion strategy type (i.e., INSERT), a data update strategy type (i.e., UPDATE), or a data deletion strategy type (i.e., DELETE). Then, by considering the complement priority and the complement strategy type, a target processing strategy is generated. It should be noted that the business logic and dependencies of the data must also be considered when generating the strategy to ensure that data supplementation does not destroy the integrity of the business process. By setting the complement priority and the complement strategy type, this embodiment can ensure that data recovery is carried out in an orderly manner, give priority to key business data, significantly improve the efficiency of data recovery, reduce business interruption time, avoid data errors or inconsistencies caused by improper operations, and maintain the integrity and consistency of the database.
[0062] Optionally, in the database processing method provided in the embodiment of the present application, determining the complement priority of M business data to be supplemented according to M table types includes: if the business table of the M business data to be supplemented contains a table type of account type, extracting N business data to be supplemented of account type, and determining the complement priority of the business data to be supplemented of N account type as the first priority, wherein N is less than or equal to M and N is a positive integer; if the business table of the M business data to be supplemented contains a table type of management type, extracting Y business data to be supplemented of management type, and determining the complement priority of the Y business data to be supplemented of management type as the second priority, wherein Y is less than or equal to M and Y is a positive integer; determining the complement priority of the business data to be supplemented whose table type is data storage type among the M business data to be supplemented as the third priority, wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
[0063] Specifically, since different types of business data have different impacts on the business, in order to minimize the negative impact on customers and business while ensuring efficient database recovery, it is necessary to determine the priority of each business data to be supplemented. First, since account-type business data usually involves sensitive information such as customers' personal information, financial status, and transaction history, the absence or inconsistency of such data may directly affect account security and daily business operations, such as causing errors in fund transactions and inaccurate account balances. Therefore, when it is determined that account-type data exists in the business data to be supplemented, the priority of these business data to be supplemented can be determined as the first priority.
[0064] Secondly, since management-type business data, which may include system configuration information, permission management, and audit logs, is crucial for maintaining the normal operation and monitoring of the system, this data can be prioritized as second priority to ensure that the system's management and operation functions can be restored to normal as soon as possible. For data storage-type business data, it can be set as third priority, that is, it can be processed after ensuring that account-type and management-type data have been supplemented.
[0065] It should be noted that during the data supplementation process, database resources can also be dynamically allocated according to the supplementation requirements of different types of data to ensure the rapid supplementation of high-priority data while avoiding excessive pressure on database performance. Once an anomaly is found (such as data supplementation failure, etc.), the data supplementation strategy needs to be adjusted to ensure the smooth progress of data supplementation and the stability of the database system. This embodiment sets different priorities for different types of business data to be supplemented. By giving priority to supplementing account type data, it can quickly eliminate data inconsistencies that may affect customer fund security and daily operations, avoid resource waste and redundant operations, and greatly improve the overall efficiency of data recovery. By gradually supplementing business data according to priority, the accuracy and consistency of each batch of data supplementation are ensured, the error rate in the data supplementation process is reduced, and the overall data quality control of the database is strengthened.
[0066] Optionally, in the database processing method provided in the embodiment of the present application, using the target processing strategy to adjust the data of the second database includes: when the target processing strategy is a data insertion strategy, importing M business data to be supplemented into a temporary business table, and comparing the temporary business table with the business table of the first database, and when the comparison result indicates that the data is correct, importing the M business data to be supplemented into the second database; when the target processing strategy is a data update strategy, extracting updated data from the first database based on the query statement of the M business data to be supplemented, obtaining M updated data, and importing the M updated data into the second database; when the target processing strategy is a data deletion strategy, deleting the M business data to be supplemented from the second database.
[0067] Specifically, after obtaining the target processing strategy, if the target processing strategy is a data insertion strategy, first create a temporary business table in the secondary database with the same structure as the primary database's business table. Import the business data to be supplemented from the log into the temporary business table using the "mysqlbinlog --skip-gtids mysql-bin.088787.bin.flashback.bin.flashback" command according to the INSERT operation requirements. Then, query the data in the business table against the data in the primary database's business table. After confirming that they are correct, import them into the secondary database's business table.
[0068] When the target processing strategy is a data update strategy, the UPDATE statement may be modified multiple times, resulting in data loss, and cannot be added directly. At this time, it is necessary to obtain the latest data status from the first database based on the query statement of the business data to be supplemented, and then query to obtain the latest updated data, and import these updated data into the corresponding business table of the second database. For data that needs to be deleted, the DELETE operation can be performed directly in the second database to remove the redundant records corresponding to the business data to be supplemented. After executing the deletion operation, the master database and the slave database are compared again to verify whether the data is correctly and completely deleted to avoid potential data consistency issues. This embodiment ensures the accuracy and integrity of the data by using the target processing strategy to adjust the data, avoids business logic errors caused by data inconsistency, not only simplifies the data recovery process, but also improves the efficiency and security of the operation, and reduces potential errors caused by manual operation.
[0069] The embodiment of the present application also provides a database processing system, Figure 4 is a schematic diagram of a database processing system provided according to an embodiment of the present application, such as Figure 4 As shown, the system includes:
[0070] The monitoring system 401 is used to obtain the network status between the first database 402 and the second database 403, and when the network status is abnormal, send a data processing request to the first database 402 and the second database 403. It is also used to receive a first transaction identifier of the first database 402 and a second transaction identifier of the second database 403, determine M business data to be supplemented based on the first transaction identifier and the second transaction identifier, determine a target processing strategy based on the M business data to be supplemented, and forward the target processing strategy to the second database 403, wherein the target processing strategy includes at least a data insertion strategy, a data update strategy, and a data deletion strategy, and M is a positive integer.
[0071] Specifically, to promptly perform data complement operations on the databases, a monitoring system 401 can be deployed at the network layer. Monitoring system 401 can obtain key indicators such as network connectivity, latency, and packet loss rate between first database 402 and second database 403, thereby monitoring network status changes in real time. Once monitoring system 401 detects a network anomaly, such as a network partition (i.e., an abnormal state), it sends a data processing request to first database 402 and second database 403, instructing them to enter "pause replication" mode and collect transaction identifiers.
[0072] After the transaction identifier is sent by the first database 402 and the second database 403, the monitoring system 401 receives the first transaction identifier from the first database 402 and the second transaction identifier from the second database 403, and compares the transaction identifiers of the two databases. It can accurately locate which data is lost or failed to be copied during the transmission process, thereby obtaining multiple business data to be supplemented.
[0073] Furthermore, based on the located business data to be supplemented, the monitoring system 401 uses built-in intelligent algorithms and rules to judge and generate a target processing strategy, and then coordinates and forwards it to the second database 403, wherein the target processing strategy may include a data insertion strategy for supplementing lost INSERT data; a data update strategy for correcting inconsistent UPDATE data; and a data deletion strategy for cleaning up redundant DELETE data.
[0074] The first database 402 is configured to send a first transaction identifier according to a data processing request.
[0075] Specifically, the first database 402 can refer to the master database. When a network partition occurs, the business data in the master database cannot be copied to the slave database. At this time, after the monitoring system 401 sends a data processing request, the first database 402 can send a first transaction identifier to the monitoring system 401 based on the request, and then the monitoring system 401 performs data adjustment operations based on the transaction identifier.
[0076] The second database 403 is used to send a second transaction identifier according to the data processing request, and is also used to adjust the data through the target processing strategy.
[0077] Specifically, the second database 403 can refer to a slave database. When a network partition occurs, the slave database cannot receive the business data sent by the master database. Therefore, after the monitoring system 401 sends a data processing request, the second database 403 can send a second transaction identifier to the monitoring system 401 based on the request, and use the target processing strategy after the monitoring system 401 generates the target processing strategy to adjust the data. For example, data insertion, data update, and data deletion operations can be performed.
[0078] The database processing system provided in the embodiment of the present application is used to obtain the network status between the first database 402 and the second database 403 through the monitoring system 401, and send a data processing request to the first database 402 and the second database 403 when the network status is abnormal. It is also used to receive the first transaction identifier of the first database 402 and the second transaction identifier of the second database 403, determine M business data to be supplemented based on the first transaction identifier and the second transaction identifier, determine the target processing strategy based on the M business data to be supplemented, and forward the target processing strategy to the second database 403, wherein the target processing strategy includes at least a data insertion strategy, a data update strategy and a data deletion strategy, and M is a positive integer; the first database 402 is used to determine the target processing strategy based on the first transaction identifier and the second transaction identifier. The data processing request sends a first transaction identifier; the second database 403 is used to send a second transaction identifier according to the data processing request, and is also used to adjust data through a target processing strategy, which solves the technical problem in the related art that when the network status between the master and slave databases is in a network partition state, the data stored in the master and slave databases are inconsistent. When the network status is abnormal, the monitoring system 401 obtains the transaction identifiers of the first database 402 and the second database 403, and then determines the target processing strategy based on the business data to be supplemented obtained according to the transaction identifiers. Finally, the second database 403 uses the target processing strategy to adjust the data, thereby achieving the technical effect of improving the operational efficiency of data complement in the master database and the slave database and improving the accuracy of complement.
[0079] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0080] Example 2
[0081] The present application also provides a database processing device. It should be noted that the database processing device of the present application can be used to execute the database processing method provided in the present application. The following describes the database processing device provided in the present application.
[0082] According to an embodiment of the present application, a device for implementing the above database processing method is also provided. Figure 5 is a schematic diagram of a database processing device provided according to an embodiment of the present application, such as Figure 5 As shown, the device includes: a first acquiring unit 50, a second acquiring unit 51, and a determining unit 52.
[0083] A first acquiring unit 50 is configured to acquire a network status between a first database and a second database, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status includes at least an abnormal state and a normal state;
[0084] A second acquiring unit 51 is configured to, when the network state is abnormal, acquire a first transaction identifier of the first database and a second transaction identifier of the second database, and determine M pieces of service data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate execution status of transactions associated with the plurality of service data in the first database, the second transaction identifier is used to indicate execution status of transactions associated with the plurality of service data in the second database, and M is a positive integer;
[0085] The determination unit 52 is used to determine the target processing strategy based on the M business data to be supplemented, and use the target processing strategy to adjust the data of the second database, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least: data insertion strategy, data update strategy and data deletion strategy.
[0086] The database processing device provided by the embodiment of the present application obtains the network status between the first database and the second database through the first acquisition unit 50, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status at least includes: an abnormal state and a normal state; the second acquisition unit 51 obtains the first transaction identifier of the first database and the second transaction identifier of the second database when the network status is an abnormal state, and determines M business data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer; the determination unit 52 determines the business data to be supplemented based on the first transaction identifier and the second transaction identifier. A target processing strategy is determined based on M business data to be supplemented, and the target processing strategy is used to adjust the data of the second database. The target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least: a data insertion strategy, a data update strategy, and a data deletion strategy. This solves the technical problem in the related technology that when the network status between the master and slave databases is in a network partition state, the data stored in the master and slave databases are inconsistent. When the network status is abnormal, the business data to be supplemented is determined based on the transaction identifiers of the first database and the second database, the target processing strategy is determined according to the business data to be supplemented, and the data of the second database is adjusted using the target processing strategy, thereby achieving the technical effect of improving the operational efficiency of data supplementation in the master database and the slave database and improving the accuracy of supplementation.
[0087] Optionally, in the database processing device provided in the embodiment of the present application, the second acquisition unit 51 includes: a comparison module, used to compare the total number of first transaction identifiers and the total number of second transaction identifiers; a first response module, used to respond to the received identifier code when the total number of the first transaction identifiers and the total number of the second transaction identifiers are inconsistent, and perform identifier comparison on the first transaction identifier and the second transaction identifier by the identifier code to obtain a comparison result; a first determination module, used to determine different transaction identifiers according to the comparison result, obtain M missing transaction identifiers, and determine M business data to be supplemented based on the M missing transaction identifiers.
[0088] Optionally, in the database processing device provided in the embodiment of the present application, the second acquisition unit 51 includes: a first acquisition module, used to obtain the database log of the target database containing M missing transaction identifiers, extract the log corresponding to each missing transaction identifier from the database log to obtain K logs, and parse the K logs to obtain M log records, wherein the target database is the first database or the second database; a second acquisition module, used to obtain the log record format configured by the first database, set the parameters of the preset log extraction tool according to the log record format, and obtain the log extraction tool; the first extraction module, used to use the log extraction tool to extract query statements from each log record to obtain M query statements; a second response module, used to respond to the received preset instruction, parse the M query statements according to the preset instruction to obtain M query contents, and extract M business data to be supplemented from the M query contents, wherein the M query contents include the business data to be supplemented and the business table storing the business data to be supplemented.
[0089] Optionally, in the database processing device provided in the embodiment of the present application, the device also includes: a third acquisition unit, used to obtain business attributes of the business tables associated with the M business data to be supplemented before determining the target processing strategy based on the M business data to be supplemented, obtain M business attributes, and determine M table types based on the M business attributes, wherein each business attribute includes the table structure and table name of each business table, and each table type includes at least one of the following: account type, management type and data storage type; an extraction unit, used to, for one business data to be supplemented, when the table type of the business table of the business data to be supplemented is an account type, extract account information from the business table, freeze the account based on the account information, and execute the step of determining the target processing strategy based on the M business data to be supplemented; an execution unit, used to execute the step of determining the target processing strategy based on the M business data to be supplemented when the table type of the business table of the business data to be supplemented is a management type or a data storage type.
[0090] Optionally, in the database processing device provided in the embodiment of the present application, the determination unit 52 includes: a third acquisition module, used to obtain the table type of the business table associated with M business data to be supplemented, obtain M table types, and determine the complement priority of the M business data to be supplemented based on the M table types; a second determination module, used to determine the complement strategy type from the query statement associated with each business data to be supplemented, obtain M complement strategy types, wherein each complement strategy type includes at least one of the following: data insertion strategy type, data update strategy type and data deletion strategy type; a generation module, used to generate a target processing strategy based on the M supplement priorities and the M complement strategy types.
[0091] Optionally, in the database processing device provided in the embodiment of the present application, the determination unit 52 includes: a second extraction module, which is used to extract N account-type business data to be supplemented if a table type exists in the business table of the M business data to be supplemented and is an account type, and determine the complement priority of the N account-type business data to be supplemented as the first priority, wherein N is less than or equal to M and N is a positive integer; a third extraction module, which is used to extract Y management-type business data to be supplemented if a table type exists in the business table of the M business data to be supplemented and is a management type, and determine the complement priority of the Y management-type business data to be supplemented as the second priority, wherein Y is less than or equal to M and Y is a positive integer; a third determination module, which is used to determine the complement priority of the business data to be supplemented whose table type is a data storage type among the M business data to be supplemented as the third priority, wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
[0092] Optionally, in the database processing device provided in the embodiment of the present application, the determination unit 52 includes: an import module for importing M business data to be supplemented into a temporary business table when the target processing strategy is a data insertion strategy, and comparing the temporary business table with the business table of the first database; when the comparison result indicates that the data is correct, importing the M business data to be supplemented into the second database; a fourth extraction module for extracting updated data from the first database based on the query statement of the M business data to be supplemented when the target processing strategy is a data update strategy, obtaining M updated data, and importing the M updated data into the second database; a deletion module for deleting the M business data to be supplemented from the second database when the target processing strategy is a data deletion strategy.
[0093] It should be noted that the first acquisition unit 50, the second acquisition unit 51, and the determination unit 52 described above correspond to steps S201 to S203 in Example 1. The examples and application scenarios implemented by the above units and the corresponding steps are the same, but are not limited to the contents disclosed in the above Example 1. It should be noted that the above modules or units can be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above units can also be part of a device and can be run in the computer terminal 10 provided in Example 1.
[0094] Example 3
[0095] The embodiment of the present application may provide a computer terminal, which may be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the computer terminal may also be replaced by a terminal device such as a mobile terminal or an electronic device.
[0096] Optionally, in this embodiment, the computer terminal may be located in at least one network device among a plurality of network devices of a computer network.
[0097] In this embodiment, the computer terminal can execute the program code of the following steps in the database processing method: obtaining a network status between a first database and a second database, wherein the first database is a master database or a slave database, and the second database is a master database or a slave database, the first database and the second database are different, and the network status includes at least an abnormal status and a normal status; when the network status is an abnormal status, obtaining a first transaction identifier of the first database and a second transaction identifier of the second database, and determining M business data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer; determining a target processing strategy based on the M business data to be supplemented, and adjusting data in the second database using the target processing strategy, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least a data insertion strategy, a data update strategy, and a data deletion strategy.
[0098] Optionally, the computer terminal may execute the program code of the following steps in the database processing method: comparing the total number of first transaction identifiers with the total number of second transaction identifiers; in a case where the total number of first transaction identifiers and the total number of second transaction identifiers are inconsistent, responding to the received identifier code, performing an identifier comparison on the first transaction identifier and the second transaction identifier by the identifier code to obtain a comparison result; determining different transaction identifiers according to the comparison result to obtain M missing transaction identifiers, and determining M business data to be supplemented based on the M missing transaction identifiers.
[0099] Optionally, the computer terminal can execute the program code of the following steps in the database processing method: obtaining a database log of a target database containing M missing transaction identifiers, extracting a log corresponding to each missing transaction identifier from the database log to obtain K logs, and parsing the K logs to obtain M log records, wherein the target database is the first database or the second database; obtaining a log record format configured for the first database, setting parameters for a preset log extraction tool according to the log record format, and obtaining a log extraction tool; using the log extraction tool to extract a query statement from each log record to obtain M query statements; in response to the received preset instruction, the preset instruction parses the M query statements to obtain M query contents, and extracts M business data to be supplemented from the M query contents, wherein the M query contents include the business data to be supplemented and a business table storing the business data to be supplemented.
[0100] Optionally, the computer terminal may execute the program code of the following steps in the database processing method: obtaining business attributes of M business tables associated with the business data to be supplemented, obtaining M business attributes, and determining M table types based on the M business attributes, wherein each business attribute includes the table structure and table name of each business table, and each table type includes at least one of the following: accounting type, management type, and data storage type; for one business data to be supplemented, when the table type of the business table of the business data to be supplemented is an accounting type, extracting account information from the business table, freezing the account based on the account information, and executing the step of determining the target processing strategy based on the M business data to be supplemented; when the table type of the business table of the business data to be supplemented is a management type or a data storage type, executing the step of determining the target processing strategy based on the M business data to be supplemented.
[0101] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the database processing method: obtaining the table type of the business table associated with M business data to be supplemented, obtaining M table types, and determining the complement priority of the M business data to be supplemented based on the M table types; determining the complement strategy type from the query statement associated with each business data to be supplemented, obtaining M complement strategy types, wherein each complement strategy type includes at least one of the following: data insertion strategy type, data update strategy type and data deletion strategy type; generating a target processing strategy based on the M supplement priorities and the M complement strategy types.
[0102] Optionally, the computer terminal may execute the program code of the following steps in the database processing method: if the business table of the M business data to be supplemented includes a table type of account type, extract the business data to be supplemented of N account types, and determine the complement priority of the business data to be supplemented of the N account types as the first priority, wherein N is less than or equal to M and is a positive integer; if the business table of the M business data to be supplemented includes a table type of management type, extract Y business data to be supplemented of management type, and determine the complement priority of the business data to be supplemented of Y management type as the second priority, wherein Y is less than or equal to M and is a positive integer; determine the complement priority of the business data to be supplemented of the M business data to be supplemented whose table type is data storage type as the third priority, wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
[0103] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the database processing method: when the target processing strategy is a data insertion strategy, import M business data to be supplemented into a temporary business table, and compare the temporary business table with the business table of the first database. When the comparison result indicates that the data is correct, import the M business data to be supplemented into the second database; when the target processing strategy is a data update strategy, extract update data from the first database based on the query statement of the M business data to be supplemented, obtain M update data, and import the M update data into the second database; when the target processing strategy is a data deletion strategy, delete the M business data to be supplemented from the second database.
[0104] Optionally, Figure 6 This is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 6 As shown, the electronic device may include: one or more ( Figure 6 Only one is shown) processor 602, memory 604, storage controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0105] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the database processing method and device in the embodiment of the present application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned database processing method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.
[0106] The processor can call the information and application programs stored in the memory through the transmission device to execute the above steps in the above database processing method.
[0107] An embodiment of the present application provides a database processing solution. The solution obtains a network status between a first database and a second database, wherein the first database is a master database or a slave database, and the second database is a master database or a slave database, the first database and the second database are different, and the network status includes at least an abnormal state and a normal state. When the network status is abnormal, a first transaction identifier of the first database and a second transaction identifier of the second database are obtained, and M business data to be supplemented are determined based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer. A target processing strategy is determined based on the M business data to be supplemented, and data in the second database is adjusted using the target processing strategy, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least a data insertion strategy, a data update strategy, and a data deletion strategy, thereby achieving the technical effect of improving the operational efficiency and accuracy of data supplementation in the master and slave databases, and further solving the technical problem of inconsistent data stored in the master and slave databases when the network status between the master and slave databases is in a network partition state.
[0108] It can be understood by those skilled in the art that Figure 6 The structure shown is for illustration only, and the electronic device may also be a terminal device such as a smart phone, a tablet computer, a PDA, a mobile Internet device (MID), or a PAD. Figure 6 It does not limit the structure of the above electronic device. For example, the electronic device may also include Figure 6 More or fewer components (such as network interfaces, display devices, etc.) shown in, or with Figure 6 Different configurations shown.
[0109] A person skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0110] Example 4
[0111] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the database processing method provided in the first embodiment.
[0112] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0113] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: obtaining a network status between a first database and a second database, wherein the first database is a master database or a slave database, the second database is a master database or a slave database, the first database and the second database are different, and the network status includes at least an abnormal state and a normal state; when the network status is an abnormal state, obtaining a first transaction identifier of the first database and a second transaction identifier of the second database, and determining M business data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the first database, and the second transaction identifier is used to indicate the execution status of transactions associated with multiple business data in the second database, and M is a positive integer; determining a target processing strategy based on the M business data to be supplemented, and adjusting data in the second database using the target processing strategy, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least a data insertion strategy, a data update strategy, and a data deletion strategy.
[0114] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing the program steps of the database processing method.
[0115] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0116] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0117] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0118] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0119] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0120] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program code.
[0121] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A database processing method, characterized in that: include: Acquiring a network status between a first database and a second database, wherein the first database is a master database or a slave database, the second database is the master database or the slave database, the first database and the second database are different, and the network status includes at least: an abnormal state and a normal state; When the network state is the abnormal state, obtaining a first transaction identifier of the first database and a second transaction identifier of the second database, and determining M pieces of service data to be supplemented based on the first transaction identifier and the second transaction identifier, wherein the first transaction identifier is used to indicate execution status of transactions associated with multiple pieces of service data in the first database, the second transaction identifier is used to indicate execution status of transactions associated with multiple pieces of service data in the second database, and M is a positive integer; A target processing strategy is determined based on the M business data to be supplemented, and the data of the second database is adjusted using the target processing strategy, wherein the target processing strategy refers to a strategy for adjusting the second database using the M business data to be supplemented, and the target processing strategy includes at least: a data insertion strategy, a data update strategy, and a data deletion strategy.
2. The method according to claim 1, characterized in that Determining M pieces of to-be-supplemented service data based on the first transaction identifier and the second transaction identifier includes: comparing the total number of the first transaction identifiers with the total number of the second transaction identifiers; In a case where the total number of the first transaction identifiers and the total number of the second transaction identifiers are inconsistent, in response to the received identifier code, performing an identifier comparison on the first transaction identifier and the second transaction identifier by the identifier code to obtain a comparison result; Different transaction identifiers are determined according to the comparison result to obtain M missing transaction identifiers, and the M service data to be supplemented are determined based on the M missing transaction identifiers.
3. The method according to claim 2, characterized in that Determining the M to-be-supplemented service data based on the M missing transaction identifiers includes: Obtaining a database log of a target database containing the M missing transaction identifiers, extracting a log corresponding to each missing transaction identifier from the database log to obtain K logs, and parsing the K logs to obtain M log records, wherein the target database is the first database or the second database; Obtaining a log recording format configured in the first database, and setting parameters for a preset log extraction tool according to the log recording format to obtain the log extraction tool; Extracting query statements from each log record using the log extraction tool to obtain M query statements; In response to the received preset instructions, the preset instructions parse the M query statements to obtain M query contents, and extract the M business data to be supplemented from the M query contents, wherein the M query contents include the business data to be supplemented and the business table storing the business data to be supplemented.
4. The method according to claim 1, wherein Before determining a target processing strategy based on the M pieces of service data to be supplemented, the method further includes: Obtaining business attributes of the business tables associated with the M business data to be supplemented, obtaining M business attributes, and determining M table types based on the M business attributes, wherein each business attribute includes a table structure and a table name of each business table, and each table type includes at least one of the following: an accounting type, a management type, and a data storage type; For one piece of business data to be supplemented, if the table type of the business table of the business data to be supplemented is the account type, extracting account information from the business table, freezing the account based on the account information, and executing the step of determining the target processing strategy based on the M pieces of business data to be supplemented; In a case where the table type of the service table of the to-be-supplemented service data is the management type or the data storage type, the step of determining a target processing strategy according to the M to-be-supplemented service data is performed.
5. The method according to claim 1, characterized in that Determining a target processing strategy according to the M pieces of service data to be supplemented includes: Acquire table types of service tables associated with the M service data to be supplemented, obtain M table types, and determine the complement priority of the M service data to be supplemented according to the M table types; Determine a complement strategy type from a query statement associated with each service data to be complemented, and obtain M complement strategy types, wherein each complement strategy type includes at least one of the following: a data insertion strategy type, a data update strategy type, and a data deletion strategy type; The target processing strategy is generated according to the M complement priority levels and the M complement strategy types.
6. The method according to claim 5, characterized in that Determining the complement priority of the M to-be-complemented service data according to the M table types includes: If the table type of the M business data to be supplemented is an account type, extracting N account type business data to be supplemented, and determining the complement priority of the N account type business data to be supplemented as the first priority, where N is less than or equal to M and is a positive integer; If the table type of the M service data to be supplemented is a management type, extract Y service data to be supplemented of the management type, and determine the complement priority of the Y service data to be supplemented of the management type as the second priority, where Y is less than or equal to M and Y is a positive integer; The complement priority of the service data to be supplemented whose table type is data storage type among the M service data to be supplemented is determined as the third priority, wherein the first priority is higher than the second priority, and the second priority is higher than the third priority.
7. The method according to claim 1, characterized in that Adjusting data in the second database using the target processing strategy includes: When the target processing strategy is the data insertion strategy, importing the M to-be-supplemented service data into a temporary service table, and comparing the temporary service table with the service table of the first database; if the comparison result indicates that the data is correct, importing the M to-be-supplemented service data into the second database; When the target processing strategy is the data update strategy, extracting updated data from the first database based on the query statements of the M business data to be supplemented to obtain M updated data, and importing the M updated data into the second database; In a case where the target processing policy is the data deletion policy, the M pieces of service data to be supplemented are deleted from the second database.
8. A database processing system, characterized in that: include: The monitoring system is configured to obtain a network status between a first database and a second database, and when the network status is the abnormal state, send a data processing request to the first database and the second database. The monitoring system is further configured to receive a first transaction identifier of the first database and a second transaction identifier of the second database, determine M pieces of service data to be supplemented based on the first transaction identifier and the second transaction identifier, determine a target processing policy based on the M pieces of service data to be supplemented, and forward the target processing policy to the second database, wherein the target processing policy includes at least a data insertion policy, a data update policy, and a data deletion policy, and M is a positive integer. the first database being configured to send the first transaction identifier according to the data processing request; The second database is used to send the second transaction identifier according to the data processing request, and is also used to perform data adjustment through the target processing strategy.
9. An electronic device, characterized in that: include: a memory storing an executable program; A processor, configured to run the program, wherein the program, when running, executes the database processing method according to any one of claims 1 to 7.
10. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the steps of the database processing method according to any one of claims 1 to 7 are implemented.