CN110427422B - Data consistency check method, device and storage medium when data synchronization is abnormal - Google Patents
Data consistency check method, device and storage medium when data synchronization is abnormal Download PDFInfo
- Publication number
- CN110427422B CN110427422B CN201910436428.3A CN201910436428A CN110427422B CN 110427422 B CN110427422 B CN 110427422B CN 201910436428 A CN201910436428 A CN 201910436428A CN 110427422 B CN110427422 B CN 110427422B
- Authority
- CN
- China
- Prior art keywords
- transaction
- synchronization
- auxiliary table
- data
- error
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2365—Ensuring data consistency and integrity
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Hardware Redundancy (AREA)
Abstract
本发明公开了一种数据同步异常时数据一致性校验方法、设备及存储介质,所述方法包括:首先将同步事务的事务ID插入目标端数据库中辅助表中;然后当接收到报错通知时,判断当前的同步事务处于何种操作;在为事务变更操作时,判断报错通知是否属于预设的错误类型,并在属于时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作,在为事务提交操作时,查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该事务的事务ID插入辅助表中并重新进行同步操作。本发明在同步过程中,同步事务开始时先在辅助表中登记事务标签,如果同步过程中出错,则通过根据当前的操作来做不同的判断处理,以保证同步数据的一致性。
The invention discloses a data consistency check method, device and storage medium when data synchronization is abnormal. The method includes: firstly inserting a transaction ID of a synchronization transaction into an auxiliary table in a target database; then when an error notification is received , to determine what kind of operation the current synchronization transaction is in; when it is a transaction change operation, determine whether the error notification belongs to the preset error type, and if it is, roll back the synchronization operation that has been performed and re-insert the transaction ID of the synchronization transaction Re-synchronize the transaction in the auxiliary table. When submitting the operation for the transaction, query whether the transaction ID of the synchronization transaction is contained in the auxiliary table, and if not, insert the transaction ID of the transaction into the auxiliary table and re-synchronize the operation. . In the synchronization process of the present invention, the transaction label is first registered in the auxiliary table at the beginning of the synchronization transaction, and if there is an error in the synchronization process, different judgment processing is performed according to the current operation to ensure the consistency of the synchronization data.
Description
技术领域technical field
本发明涉及数据库同步技术领域,具体涉及一种数据同步异常时数据一致性校验方法、设备及存储介质。The invention relates to the technical field of database synchronization, in particular to a data consistency check method, device and storage medium when data synchronization is abnormal.
背景技术Background technique
在数据库数据实时同步技术中,其中基于数据库日志分析的数据实时同步技术因其具备支持异构操作系统和数据库平台、对源端数据库系统侵入性较小、数据同步延时低等特点,而得到广泛研究和应用。异构数据库系统之间的日志格式及日志内容差异较大,因此数据同步源端数据库的日志内容并不能直接应用到目标数据库中。基于日志分析的数据实时同步技术,一般原理是捕获源端数据库的增量日志内容,然后通过网络发送至目标端,在目标端使用SQL逆向生成技术恢复源端数据库的事务操作SQL语句,再通过通用的数据库访问接口如ODBC、OCI等接口,执行恢复后的SQL语句,实现源和目标端的数据实时同步。Among the database data real-time synchronization technologies, the data real-time synchronization technology based on database log analysis has the characteristics of supporting heterogeneous operating systems and database platforms, less intrusiveness to the source database system, and low data synchronization delay. Extensive research and application. The log format and log content between heterogeneous database systems are quite different, so the log content of the source database for data synchronization cannot be directly applied to the target database. The general principle of the real-time data synchronization technology based on log analysis is to capture the incremental log content of the source database, and then send it to the target through the network, and use the reverse SQL generation technology on the target to restore the transaction operation SQL statement of the source database, and then pass Common database access interfaces such as ODBC, OCI, etc., execute the restored SQL statement to realize real-time synchronization of data between the source and the target.
进一步的,通过使用上述数据实时同步技术构建的数据库数据实时同步装置主要包括如下组成模块,在同步系统源端,同步软件日志读取模块实时读取源端数据库日志文件,捕获源端数据库上的事务增量日志内容;同步软件日志分析模块实时解析增量日志内容,提取日志中的事务ID、操作表ID、事务的操作类型如INSERT、UPDATE、 DELETE,事务操作时间戳、日志LSN值、操作数据等,然后将其组装成特定格式的消息,存放在发送队列中;同步软件日志发送模块,将发送队列中的消息通过TCP/IP网络发送到同步系统的目标端。Further, the database data real-time synchronization device constructed by using the above-mentioned data real-time synchronization technology mainly includes the following components. At the source end of the synchronization system, the synchronization software log reading module reads the source end database log file in real time and captures the Transaction incremental log content; the synchronization software log analysis module parses the incremental log content in real time, extracts the transaction ID, operation table ID, transaction operation type such as INSERT, UPDATE, DELETE, transaction operation timestamp, log LSN value, operation type in the log Data, etc., and then assembled into messages in a specific format and stored in the sending queue; the synchronization software log sending module sends the messages in the sending queue to the target end of the synchronization system through the TCP/IP network.
在同步系统目标端,同步软件日志接收模块,接收源端发送的消息,并解析消息内容,根据事务ID将同属于一个事务的操作进行缓存,当接收到事务的COMMIT消息时,则交由日志执行模块进行同步执行;同步软件日志执行模块,根据事务操作内容,构建SQL语句,在目标数据库同步执行。At the target end of the synchronization system, the synchronization software log receiving module receives the message sent by the source end, parses the message content, and caches the operations belonging to the same transaction according to the transaction ID. When the COMMIT message of the transaction is received, it is sent to the log. The execution module performs synchronous execution; the synchronous software log execution module constructs the SQL statement according to the transaction operation content and executes it synchronously in the target database.
上述数据库数据实时同步技术中,目标端数据同步服务在目标端数据库上进行数据入库时,存在目标端同步服务和目标端数据库之间网络异常或目标端数据库发生故障当机的情况,都有可能会造成同步事务的重复执行,影响同步数据的一致性。In the above real-time database data synchronization technology, when the target-side data synchronization service performs data storage on the target-side database, there are network abnormalities between the target-side synchronization service and the target-side database, or the target-side database fails and crashes. It may cause repeated execution of synchronous transactions and affect the consistency of synchronous data.
因而现有技术还有待于改进和提高。Therefore, the existing technology still needs to be improved and improved.
发明内容SUMMARY OF THE INVENTION
鉴于上述现有技术的不足之处,本发明的目的在于提供一种数据同步异常时数据一致性校验方法、设备及存储介质,以解决目前数据同步过程中出现异常时而导致的同步数据不一致的问题。In view of the deficiencies of the above-mentioned prior art, the purpose of the present invention is to provide a data consistency check method, device and storage medium when data synchronization is abnormal, so as to solve the problem of inconsistent synchronization data caused by abnormality in the current data synchronization process. question.
为了达到上述目的,本发明采取了以下技术方案:In order to achieve the above object, the present invention has adopted the following technical solutions:
一种数据同步异常时数据一致性校验方法,包括如下步骤:A method for verifying data consistency when data synchronization is abnormal, comprising the following steps:
接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作;Receive the log message package sent by the source, insert the transaction ID of the synchronization transaction in the log message package into the auxiliary table created in the target database, and then perform the transaction synchronization operation;
当接收到目标端数据库的报错通知时,判断当前的同步事务处于何种操作,其中所述操作包括依次执行的事务变更操作和事务提交操作;When receiving an error notification from the target database, determine what operation the current synchronization transaction is in, wherein the operation includes a transaction change operation and a transaction commit operation performed in sequence;
在当前操作为事务变更操作时,判断报错通知是否属于预设的错误类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作;When the current operation is a transaction change operation, determine whether the error notification belongs to the preset error type, roll back the synchronization operation performed when the error notification belongs to the preset error type, and re-insert the transaction ID of the synchronization transaction into the auxiliary table in and re-run the transaction synchronization operation;
在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。When the current operation is a transaction commit operation, reconnect to the target database, and query whether the transaction ID of the synchronous transaction is contained in the auxiliary table, and if not, insert the transaction ID of the synchronous transaction into the auxiliary table and re-synchronize the transaction operate.
优选的,所述的数据同步异常时数据一致性校验方法中,所述接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID 插入目标端数据库中创建的辅助表中后进行事务同步操作的步骤包括:Preferably, in the data consistency check method when data synchronization is abnormal, the log message packet sent by the source end is received, and the transaction ID of the synchronization transaction in the log message packet is inserted into the auxiliary table created in the target end database The steps to perform transaction synchronization operations include:
解析当前同步事务所在的日志消息包并获取日志消息包中的同步事务的事务ID;Parse the log message package where the current synchronization transaction is located and obtain the transaction ID of the synchronization transaction in the log message package;
在目标端数据库中创建的辅助表中执行插入操作以将所述事务 ID插入辅助表中。An insert operation is performed in the auxiliary table created in the target database to insert the transaction ID into the auxiliary table.
优选的,所述的数据同步异常时数据一致性校验方法中,所述在当前操作为事务变更操作时,判断报错通知是否属于预设的报错类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作的步骤包括:Preferably, in the data consistency check method when the data synchronization is abnormal, when the current operation is a transaction change operation, it is determined whether the error notification belongs to a preset error type, and when the error notification belongs to the preset error type The steps of rolling back the synchronization operation and re-inserting the transaction ID of the synchronization transaction into the auxiliary table and performing the transaction synchronization operation again include:
在当前操作为事务变更操作时,根据目标端数据库返回的错误码识别错误的类型;When the current operation is a transaction change operation, identify the type of error according to the error code returned by the target database;
判断该错误类型是否属于预设的错误类型;Determine whether the error type is a preset error type;
在该错误类型为预设的错误类型时,断开与目标端数据库的连接并回滚已进行的同步操作,并在回滚完成后重新将该同步事务的事务 ID插入辅助表中并重新进行事务同步操作。When the error type is the preset error type, disconnect the connection with the target database and roll back the synchronization operation that has been performed, and re-insert the transaction ID of the synchronization transaction into the auxiliary table after the rollback is completed and repeat the operation Transaction synchronization operation.
优选的,所述的数据同步异常时数据一致性校验方法中,所述所述在该错误类型为预设的错误类型时,断开与目标端数据库的连接并回滚已进行的同步操作,并在回滚完成后重新将该同步事务的事务ID 插入辅助表中并重新进行事务同步操作的步骤还包括:Preferably, in the method for verifying data consistency when data synchronization is abnormal, when the error type is a preset error type, the connection with the target database is disconnected and the synchronization operation that has been performed is rolled back. , and re-insert the transaction ID of the synchronous transaction into the auxiliary table after the rollback is completed, and the steps of re-synchronizing the transaction also include:
在该错误类型不是预设的错误类型时,执行预设的同步事务出错处理流程。When the error type is not the preset error type, the preset synchronous transaction error processing flow is executed.
优选的,所述的数据同步异常时数据一致性校验方法中,所述预设的错误类型包括网络异常错误和数据库系统级错误。Preferably, in the method for verifying data consistency when data synchronization is abnormal, the preset error types include network abnormal errors and database system-level errors.
优选的,所述的数据同步异常时数据一致性校验方法中,所述在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该同步事务的事务 ID插入辅助表中并重新进行事务同步操作的步骤包括:Preferably, in the data consistency check method when data synchronization is abnormal, when the current operation is a transaction commit operation, reconnect to the target database, and query whether the auxiliary table contains the transaction ID of the synchronization transaction, and The steps for inserting the transaction ID of the synchronized transaction into the auxiliary table and re-synchronizing the transaction when not included include:
在当前操作为事务提交操作时,断开与目标端数据库的连接并重新连接目标端数据库;When the current operation is a transaction commit operation, disconnect from the target database and reconnect to the target database;
调用目标端数据库中的辅助表,并查询所述辅助表中是否存在所述同步事务开始时登记的事务ID;Call the auxiliary table in the target database, and query whether there is a transaction ID registered at the beginning of the synchronous transaction in the auxiliary table;
在所述辅助表中不存在该事务ID时,将该同步事务ID插入目标端数据库中的辅助表中并重新开始进行事务同步操作。When the transaction ID does not exist in the auxiliary table, insert the synchronization transaction ID into the auxiliary table in the target database and restart the transaction synchronization operation.
优选的,所述的数据同步异常时数据一致性校验方法中,所述在所述辅助表中不存在该事务ID时,将该同步事务ID插入目标端数据库中的辅助表中并重新开始进行事务同步操作的步骤还包括:Preferably, in the method for verifying data consistency when data synchronization is abnormal, when the transaction ID does not exist in the auxiliary table, insert the synchronization transaction ID into the auxiliary table in the target database and start again The steps of performing a transaction synchronization operation also include:
在所述辅助表中存在该事务ID时,执行下一个同步事务。When the transaction ID exists in the auxiliary table, the next synchronization transaction is executed.
优选的,所述的数据同步异常时数据一致性校验方法中,所述事务变更操作包括插入操作、更新操作和删除操作。Preferably, in the method for verifying data consistency when data synchronization is abnormal, the transaction change operation includes an insert operation, an update operation and a delete operation.
一种数据同步异常时数据一致性校验设备,其包括:处理器、存储器和通信总线;A data consistency check device when data synchronization is abnormal, comprising: a processor, a memory and a communication bus;
所述存储器上存储有可被所述处理器执行的计算机可读程序;A computer-readable program executable by the processor is stored on the memory;
所述通信总线实现处理器和存储器之间的连接通信;The communication bus implements connection communication between the processor and the memory;
所述处理器执行所述计算机可读程序时实现如上所述的数据同步异常时数据一致性校验方法中的步骤。When the processor executes the computer-readable program, the steps in the above-mentioned method for verifying data consistency when data synchronization is abnormal is implemented.
一种计算机可读存储介质,所述计算机可读存储介质存储有一个或者多个程序,所述一个或者多个程序可被一个或者多个处理器执行,以实现如上所述的数据同步异常时数据一致性校验方法中的步骤。A computer-readable storage medium, the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors, so as to realize the abnormality of data synchronization as described above. Steps in a data consistency check method.
本发明提供的数据同步异常时数据一致性校验方法、设备及存储介质中,所述方法包括:首先接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作;然后当接收到目标端数据库的报错通知时,判断当前的同步事务处于何种操作,其中所述操作包括依次执行的事务变更操作和事务提交操作;在当前操作为事务变更操作时,判断报错通知是否属于预设的错误类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作,在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。本发明在同步过程中,同步事务开始时先在辅助表中登记事务标签,如果同步过程中出错,则通过根据当前的操作来判断事务标签是否已登记,从而进一步判断出是否已同步完成,以保证同步数据的一致性。In the method, device and storage medium for data consistency verification when data synchronization is abnormal, the method includes: firstly receiving a log message packet sent by the source end, and inserting the transaction ID of the synchronization transaction in the log message packet into the target The transaction synchronization operation is performed after the auxiliary table created in the end database; then when an error notification from the target end database is received, it is judged which operation the current synchronization transaction is in, wherein the operation includes the transaction change operation and transaction commit performed in sequence Operation; when the current operation is a transaction change operation, determine whether the error notification belongs to the preset error type, and when the error notification belongs to the preset error type, roll back the performed synchronization operation and re-insert the transaction ID of the synchronization transaction Re-run the transaction synchronization operation in the auxiliary table. When the current operation is a transaction commit operation, reconnect to the target database, and query whether the transaction ID of the synchronization transaction is contained in the auxiliary table, and if it does not contain the transaction ID of the synchronization transaction The ID is inserted into the auxiliary table and the transaction synchronization operation is repeated. In the synchronization process of the present invention, the transaction label is first registered in the auxiliary table at the beginning of the synchronization transaction. If there is an error in the synchronization process, it is judged whether the transaction label has been registered according to the current operation, so as to further determine whether the synchronization has been completed. Ensure the consistency of synchronized data.
附图说明Description of drawings
图1为本发明提供的数据同步异常时数据一致性校验方法的流程图。FIG. 1 is a flowchart of a method for verifying data consistency when data synchronization is abnormal provided by the present invention.
图2为本发明提供的数据同步异常时数据一致性校验方法中,所述步骤S100的流程图。FIG. 2 is a flowchart of the step S100 in the method for verifying data consistency when data synchronization is abnormal provided by the present invention.
图3为本发明提供的数据同步异常时数据一致性校验方法中,所述步骤S300的流程图。FIG. 3 is a flowchart of the step S300 in the method for verifying data consistency when data synchronization is abnormal provided by the present invention.
图4为本发明提供的数据同步异常时数据一致性校验方法中,所述步骤S400的流程图。FIG. 4 is a flowchart of the step S400 in the method for verifying data consistency when data synchronization is abnormal provided by the present invention.
图5为本发明数据同步异常时数据一致性校验程序的较佳实施例的运行环境示意图。FIG. 5 is a schematic diagram of the running environment of the preferred embodiment of the data consistency check program when the data synchronization is abnormal according to the present invention.
图6为本发明安装数据同步异常时数据一致性校验程序的系统较佳实施例的功能模块图。6 is a functional block diagram of a preferred embodiment of a system for installing a data consistency check program when data synchronization is abnormal according to the present invention.
具体实施方式Detailed ways
鉴于现有技术中数据同步过程中发生异常时容易出现同步数据不一致的问题,本发明的目的在于提供一种数据同步异常时数据一致性校验方法、设备及存储介质,能保证在数据同步过程中出现异常时不会出现同步数据不一致的问题。In view of the problem that synchronization data inconsistency is prone to occur when an exception occurs in the data synchronization process in the prior art, the purpose of the present invention is to provide a data consistency check method, device and storage medium when the data synchronization is abnormal, which can ensure that the data synchronization process is There is no problem of synchronization data inconsistency when an exception occurs in the system.
为使本发明的目的、技术方案及效果更加清楚、明确,以下参照附图并举实施例对本发明进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。In order to make the objectives, technical solutions and effects of the present invention clearer and clearer, the present invention will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention.
请参阅图1,本发明提供的数据同步异常时数据一致性校验方法,包括如下步骤:Referring to FIG. 1, the method for verifying data consistency when data synchronization is abnormal provided by the present invention includes the following steps:
S100、接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作。S100. Receive the log message package sent by the source end, and insert the transaction ID of the synchronization transaction in the log message package into the auxiliary table created in the target end database, and then perform the transaction synchronization operation.
具体来说,源端将需要进行数据同步的表以日志消息包的形式发送过去,故源端在进行日志消息包发送之前还需要进行日志消息包的生成,由于在异构数据库系统环境中,源端数据库所产生的增量日志信息并不能直接应用于目标端数据库,故需要通过对源端数据库的日志信息进行解析,然后生成同步服务内部特定格式的消息包,存储在发送队列中等待日志发送模块进行发送,具体实施时,源端数据同步服务的日志捕获模块基于日志捕获技术,实时捕获源端数据库系统的增量日志数据,然后将增量日志数据传递给日志分析模块进行解析,之后源端数据同步服务的日志解析模块,将增量日志解析为内部特定消息包格式,存储在发送队列中。优选的,所述日志消息包包括事务 ID、事务操作类型以及操作表名、列信息和数据值等。目标端在进行数据同步时,把接收到的同步事务根据事务ID来分类。之后,源端数据同步服务的日志发送模块,基于线程同步机制,将内部发送队列中的日志消息包通过TCP/IP网络发送给目标端数据同步服务系统中。优选的,为了保证数据传输的可靠性和数据完整性,源端日志发送模块采取了完备的消息应答机制,日志发送模块只有在得到目标端确认消息后才认为数据传输完成,否则将自动重新传输数据,目标端在接收到日志消息包后,对每个日志消息包进行序列编号同时需要返回确认信息。Specifically, the source side sends the tables that need to be synchronized in the form of log message packets. Therefore, the source side also needs to generate log message packets before sending log message packets. In a heterogeneous database system environment, The incremental log information generated by the source database cannot be directly applied to the target database. Therefore, it is necessary to parse the log information of the source database, and then generate a message packet in a specific format inside the synchronization service, which is stored in the sending queue and waiting for the log. The sending module sends. When implemented, the log capture module of the source data synchronization service captures the incremental log data of the source database system in real time based on the log capture technology, and then transmits the incremental log data to the log analysis module for analysis. The log parsing module of the source-side data synchronization service parses the incremental log into an internal specific message packet format and stores it in the sending queue. Preferably, the log message package includes transaction ID, transaction operation type, operation table name, column information and data value, and the like. When the target end performs data synchronization, it classifies the received synchronization transactions according to the transaction ID. Afterwards, the log sending module of the source data synchronization service, based on the thread synchronization mechanism, sends the log message packets in the internal sending queue to the target data synchronization service system through the TCP/IP network. Preferably, in order to ensure the reliability and data integrity of data transmission, the log sending module at the source end adopts a complete message response mechanism. The log sending module only considers the data transmission complete after receiving the confirmation message from the target end, otherwise it will automatically retransmit Data, after receiving the log message packet, the target end will serially number each log message packet and need to return confirmation information.
进一步来说,目标端数据同步服务通过数据库的驱动和目标端数据库进行交互,因此同步服务和数据库可以不在同一台机器上。分开布置以后,就需要考虑它们之间的网格发生故障的可能;另外,在同步过程中,目标端数据库有可能因为BUG发生当机或是其它原因导致数据库当机,在这些情况下,同步服务在目标端数据库上执行同步时,都需要考虑这些可能的故障,防止同步事务的重复执行或是少执行,故本发明首先在目标端数据库中创建了一个辅助表,该辅助表用于存储同步事务的事务标签,本实施例中,所述事务标签为事务ID,在同步事务开始时先在辅助表中登记当前同步事务的事务ID,然后在同步过程中出错时,根据当前的同步操作来做不同的判断处理,以保证同步数据的一致性;在将所述事务ID登记完成后,即开始进行同步事务,一个具体的同步事务如下所示:Further, the target-side data synchronization service interacts with the target-side database through the database driver, so the synchronization service and the database may not be on the same machine. After they are arranged separately, it is necessary to consider the possibility of grid failure between them; in addition, during the synchronization process, the target database may crash due to a bug or other reasons. In these cases, the synchronization When the service performs synchronization on the target database, these possible faults need to be considered to prevent repeated execution or less execution of the synchronization transaction. Therefore, the present invention first creates an auxiliary table in the target database, and the auxiliary table is used to store The transaction tag of the synchronization transaction. In this embodiment, the transaction tag is the transaction ID. When the synchronization transaction starts, the transaction ID of the current synchronization transaction is firstly registered in the auxiliary table, and then when an error occurs during the synchronization process, the current synchronization operation To do different judgment processing to ensure the consistency of synchronization data; after the transaction ID is registered, the synchronization transaction starts. A specific synchronization transaction is as follows:
BEGINBEGIN
INSERT INTO T VALUES(1);INSERT INTO T VALUES(1);
COMMIT;COMMIT;
END;END;
一个具体的辅助表的结构如下表所示:The structure of a specific auxiliary table is shown in the following table:
请参阅图2,其为所述步骤S100的流程图,包括如下步骤:Please refer to FIG. 2, which is a flowchart of the step S100, including the following steps:
S101、解析当前同步事务所在的日志消息包并获取日志消息包中的同步事务的事务ID;S101, parse the log message package in which the current synchronization transaction is located and obtain the transaction ID of the synchronization transaction in the log message package;
S102、在目标端数据库中创建的辅助表中执行插入操作以将所述事务ID插入辅助表中。S102. Perform an insert operation in the auxiliary table created in the target database to insert the transaction ID into the auxiliary table.
针对上述具体操作事务来说,在执行同步事务操作前,在辅助表上先执行一个INSERT操作,将事务ID插入辅助表中,具体示例如下:For the above specific operation transactions, before executing the synchronous transaction operation, perform an INSERT operation on the auxiliary table to insert the transaction ID into the auxiliary table. The specific example is as follows:
INSERT INTO DMHS_TRXID(TRXID)VALUES(12345);INSERT INTO DMHS_TRXID(TRXID)VALUES(12345);
S200、当接收到目标端数据库的报错通知时,判断当前的同步事务处于何种操作,其中所述操作包括依次执行的事务变更操作和事务提交操作。S200. When receiving an error notification from the target database, determine which operation the current synchronization transaction is in, wherein the operation includes a transaction change operation and a transaction commit operation performed in sequence.
本实施例中,在没有接收到目标端数据库的报错通知时,按流程执行完该同步事务,然后再执行下一个同步事务,在接收到目标端数据库的报错通知时(即同步过程中发生错误),需要判断当前的同步事务处于何种操作,一般而言,在进行同步事务时,需要先进行事务变更操作来进行数据转换,然后在转换完成后执行事务提交操作将转换后的数据输送到目标端数据库中,故本发明需通过判断操作类型来具体给出出错后的处理方法,在不同的操作阶段,处理方法具有差异,事务变更操作阶段,数据转换还没完成,故需要重新来进行数据转换,在事务提交操作阶段,数据转换已完成但可能没有入库成功,故需要验证事务ID来保证同步数据的一致性,优选的,所述事务变更操作包括插入操作(INSERT操作)、更新操作(UPDATE操作)和删除操作(DELETE操作),在同步时可以进行数据插入、更新或者删除。In this embodiment, when no error notification from the target database is received, the synchronization transaction is executed according to the process, and then the next synchronization transaction is executed. When an error notification from the target database is received (that is, an error occurs during the synchronization process) ), it is necessary to determine what operation the current synchronization transaction is in. Generally speaking, when a synchronization transaction is performed, a transaction change operation needs to be performed first to perform data conversion, and then a transaction commit operation is performed after the conversion is completed to transfer the converted data to the In the target database, the present invention needs to specifically provide the processing method after the error by judging the operation type. In different operation stages, the processing methods are different. In the transaction change operation stage, the data conversion has not been completed, so it needs to be re-executed. Data conversion, in the transaction commit operation stage, the data conversion has been completed but may not be successfully stored, so it is necessary to verify the transaction ID to ensure the consistency of synchronized data. Preferably, the transaction change operation includes an insert operation (INSERT operation), an update operation Operation (UPDATE operation) and delete operation (DELETE operation), data can be inserted, updated or deleted during synchronization.
此外,由于错误的类型很多,为了对错误进行区分,本发明设定了错误代码(errorcode)来表示错误的类型,在同步过程中如果发生错误,将通过它内部的原有的设定判断、识别而通过错误代码的显示方式现实错误,系统通过错误代码识别,快速找到错误的类型。In addition, since there are many types of errors, in order to distinguish errors, the present invention sets an error code (errorcode) to indicate the type of errors. Identify and display errors through the display of error codes, and the system can quickly find the type of errors through error code identification.
S300、在当前操作为事务变更操作时,判断报错通知是否属于预设的错误类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。S300. When the current operation is a transaction change operation, determine whether the error notification belongs to a preset error type, and when the error notification belongs to the preset error type, roll back the performed synchronization operation and re-insert the transaction ID of the synchronization transaction Auxiliary table and redo the transaction synchronization operation.
本实施例中,首先根据报错通知(本实施例中为错误码)来识别错误的类型,如果错误类型属于预设的类型,则重新执行步骤S100,所述步骤S300的具体流程图如图3所示。In this embodiment, the type of error is first identified according to the error notification (error code in this embodiment), and if the type of error belongs to a preset type, step S100 is re-executed. The specific flowchart of step S300 is shown in FIG. 3 shown.
请参阅图3,其为所述步骤S300的流程图,包括如下步骤:Please refer to FIG. 3, which is a flowchart of the step S300, including the following steps:
S301、在当前操作为事务变更操作时,根据目标端数据库返回的错误码识别错误的类型;S301. When the current operation is a transaction change operation, identify the type of error according to the error code returned by the target database;
S302、判断该错误类型是否属于预设的错误类型;S302. Determine whether the error type belongs to a preset error type;
S303、在该错误类型为预设的错误类型时,断开与目标端数据库的连接并回滚已进行的同步操作,并在回滚完成后重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。S303. When the error type is a preset error type, disconnect the connection with the target database and roll back the synchronization operation that has been performed, and re-insert the transaction ID of the synchronization transaction into the auxiliary table after the rollback is completed. Retry the transaction synchronization operation.
本实施例中,预设的错误类型包括网络异常错误和数据库系统级错误,其在进行报错时以错误码的方式呈现,如果出现此类错误,表示在进行插入操作、更新操作或删除操作时,数据同步没有正确的完成,此时为了避免异常数据导入目标数据库,需要先断开与目标数据库的连接,然后重新来进行同步操作,本发明采用回滚的方式来实现同步操作的重新同步,回滚(Rollback)指的是程序或数据处理错误,将程序或数据恢复到上一次正确状态的行为,通过回滚方式可使数据同步恢复到正确的状态,从而达到保证同步数据一致性的目的。In this embodiment, the preset error types include abnormal network errors and database system-level errors, which are presented in the form of error codes when reporting errors. If such errors occur, it means that when performing an insert operation, an update operation, or a delete operation , the data synchronization is not completed correctly. At this time, in order to avoid the import of abnormal data into the target database, it is necessary to disconnect the connection with the target database first, and then perform the synchronization operation again. The present invention adopts the rollback method to realize the resynchronization of the synchronization operation. Rollback refers to the act of restoring the program or data to the last correct state through a program or data processing error. Through the rollback method, the data can be synchronized and restored to the correct state, so as to achieve the purpose of ensuring the consistency of synchronized data. .
进一步的,所述步骤S303还包括:Further, the step S303 also includes:
在该错误类型不是预设的错误类型时,执行预设的同步事务出错处理流程。When the error type is not the preset error type, the preset synchronous transaction error processing flow is executed.
具体的,由于在同步过程中还可能出现其它的错误,故本发明对非预设性的错误设置了同步事务出错处理流程,此出错处理流程可根据实际需求来设定,本发明对具体的事务出错处理流程不做限定,例如在出现非预设错误时,直接取消当前事务的同步,进行下一事务的同步操作等等,从而能够保证系统在同步事务时,不会出现停滞状态,而影响同步的进程。Specifically, because other errors may occur in the synchronization process, the present invention sets a synchronization transaction error processing flow for non-preset errors, and the error processing flow can be set according to actual needs. The transaction error handling process is not limited. For example, when a non-preset error occurs, the synchronization of the current transaction is directly canceled, and the synchronization operation of the next transaction is performed, etc., so as to ensure that the system will not stagnate when synchronizing transactions, and Affects the synchronization process.
针对上述具体实施例中的同步事务来说,在目标端数据库上同步事务操作INSERTINTO T VALUES(1)时,如果同步报错,则需要判断目标端数据库返回的错误码来识别错误的类型,如果是网络异常或是数据库系统级的错误,需要采用断开连接的方式来回滚前面的同步操作,然后重新同步该出错的事务。For the synchronization transaction in the above-mentioned specific embodiment, when the synchronization transaction operation INSERTINTO T VALUES(1) is performed on the target database, if an error is reported synchronously, the error code returned by the target database needs to be judged to identify the type of error. For network exceptions or database system-level errors, it is necessary to disconnect the connection to roll back the previous synchronization operation, and then resynchronize the erroneous transaction.
S400、在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。S400. When the current operation is a transaction commit operation, reconnect to the target database, and query whether the transaction ID of the synchronous transaction is included in the auxiliary table, and if not included, insert the transaction ID of the synchronous transaction into the auxiliary table and perform the operation again. Transaction synchronization operation.
具体的,当向目标端数据库执行提交操作时,在等待提交操作返回时发生网络故障导致执行出错,远端的目标端数据库有可能已经完成了提交操作却无法向目标端的同步服务返回,在这种情况下,目标端同步服务需要重新连接目标端数据库,在辅助表中查询登记的事务 ID来确认上次故障时事务是否已经成功提交,此外,向目标端数据库执行提交操作时,在等待提交操作返回时数据库异常当机导致执行出错,数据库在当机时,也有可能该提交操作已经完成却还没有来得及向目标端同步服务返回,在这种情况下,目标端同步服务需要重新连接目标端数据库,在辅助表中查询登记的事务ID来确认上次故障时事务是否已经成功提交,故本发明通过来查询辅助表中是否包含该事务ID,可以确认故障时同步事务是否已经提交成功,在不成功时重新进行事务同步,以保证同步数据的一致性。Specifically, when a commit operation is performed to the target-side database, a network failure occurs while waiting for the return of the commit operation, resulting in an execution error. The remote target-side database may have completed the commit operation but cannot return to the target-side synchronization service. Here In this case, the target-side synchronization service needs to reconnect to the target-side database, and query the registered transaction ID in the auxiliary table to confirm whether the transaction has been successfully submitted when the last failure occurred. When the operation returns, the database is abnormally down, resulting in an execution error. When the database is down, it is also possible that the commit operation has been completed but has not been returned to the target-side synchronization service. In this case, the target-side synchronization service needs to reconnect to the target side. In the database, the registered transaction ID is queried in the auxiliary table to confirm whether the transaction has been successfully submitted during the last failure. Therefore, the present invention checks whether the transaction ID is included in the auxiliary table, and can confirm whether the synchronization transaction has been submitted successfully when the failure occurs. If unsuccessful, re-synchronize the transaction to ensure the consistency of synchronized data.
请参阅图4,其为所述步骤S400的流程图,包括如下步骤:Please refer to FIG. 4, which is a flowchart of the step S400, including the following steps:
S401、在当前操作为事务提交操作时,断开与目标端数据库的连接并重新连接目标端数据库;S401, when the current operation is a transaction commit operation, disconnect the connection with the target database and reconnect the target database;
S402、调用目标端数据库中的辅助表,并查询所述辅助表中是否存在所述同步事务开始时登记的事务ID;S402, call the auxiliary table in the target database, and query whether there is a transaction ID registered when the synchronization transaction starts in the auxiliary table;
S403、在所述辅助表中不存在该事务ID时,将该同步事务ID插入目标端数据库中的辅助表中并重新开始进行事务同步操作。S403. When the transaction ID does not exist in the auxiliary table, insert the synchronization transaction ID into the auxiliary table in the target database and restart the transaction synchronization operation.
本发明通过查询事务ID的方式来确认同步数据是否已经成功提交,利用辅助表和待同步的表在同一个事务中时,利用事务的ACID 特性(原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability))来保证在网格或数据库故障时的情况下同步数据的一致性。The present invention confirms whether the synchronization data has been successfully submitted by querying the transaction ID, and when the auxiliary table and the table to be synchronized are in the same transaction, the ACID characteristics of the transaction (Atomicity, Consistency, Consistency, Isolation (Isolation), Durability (Durability) to ensure the consistency of synchronized data in the event of grid or database failure.
优选的,所述步骤S403还包括:Preferably, the step S403 further includes:
在所述辅助表中存在该事务ID时,执行下一个同步事务。When the transaction ID exists in the auxiliary table, the next synchronization transaction is executed.
换而言之,本发明在判断所述辅助表中存在该事务ID时,可以确认同步已经成功,从而结束当前事务的同步转到下一个事务的同步,以保证同步数据的一致性。In other words, when judging that the transaction ID exists in the auxiliary table, the present invention can confirm that the synchronization has been successful, thereby ending the synchronization of the current transaction and transferring to the synchronization of the next transaction, so as to ensure the consistency of the synchronization data.
针对上述具体实施例中的同步事务来说,在目标端数据库上执行事务提交操作时,如果执行报错,则需要断开连接并重新连接上目标端数据库,然后查询辅助表中是否包含了事务,执行查询SELECT TRXID FROM DMHS_TRXID WHERE TRXID=12345;如果找到事务ID为12345的结果集,那说明该事务已经同步成功,结束当前事务的同步转到下一个事务的同步;否则重新同步该事务。For the synchronous transaction in the above-mentioned specific embodiment, when executing the transaction commit operation on the target database, if an error is reported, it is necessary to disconnect and reconnect to the target database, and then query whether the auxiliary table contains transactions, Execute the query SELECT TRXID FROM DMHS_TRXID WHERE TRXID=12345; if a result set with a transaction ID of 12345 is found, it means that the transaction has been successfully synchronized, and the synchronization of the current transaction is ended and the synchronization of the next transaction is performed; otherwise, the transaction is resynchronized.
如图5所示,基于上述数据同步异常时数据一致性校验方法,本发明还相应提供了一种数据同步异常时数据一致性校验设备,所述数据同步异常时数据一致性校验设备可以是移动终端、桌上型计算机、笔记本、掌上电脑及服务器等计算设备。该数据同步异常时数据一致性校验设备包括处理器10、存储器20及显示器30。图5仅示出了数据同步异常时数据一致性校验设备的部分组件,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。As shown in FIG. 5 , based on the above-mentioned data consistency check method when data synchronization is abnormal, the present invention also provides a data consistency check device when data synchronization is abnormal, and the data consistency check device when data synchronization is abnormal It can be a computing device such as a mobile terminal, a desktop computer, a notebook, a palmtop computer and a server. The device for verifying data consistency when data synchronization is abnormal includes a
所述存储器20在一些实施例中可以是所述数据同步异常时数据一致性校验设备的内部存储单元,例如数据同步异常时数据一致性校验设备的硬盘或内存。所述存储器20在另一些实施例中也可以是所述数据同步异常时数据一致性校验设备的外部存储设备,例如所述数据同步异常时数据一致性校验设备上配备的插接式硬盘,智能存储卡 (SmartMedia Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。In some embodiments, the
进一步地,所述存储器20还可以既包括数据同步异常时数据一致性校验设备的内部存储单元也包括外部存储设备。所述存储器20 用于存储安装于所述数据同步异常时数据一致性校验设备的应用软件及各类数据,例如所述安装数据同步异常时数据一致性校验设备的程序代码等。所述存储器20还可以用于暂时地存储已经输出或者将要输出的数据。在一实施例中,存储器20上存储有数据同步异常时数据一致性校验程序40,该数据同步异常时数据一致性校验程序40 可被处理器10所执行,从而实现本申请各实施例的数据同步异常时数据一致性校验方法。Further, the
所述处理器10在一些实施例中可以是一中央处理器(Central Processing Unit,CPU),微处理器或其他数据处理芯片,用于运行所述存储器20中存储的程序代码或处理数据,例如执行所述数据同步异常时数据一致性校验方法等。In some embodiments, the
所述显示器30在一些实施例中可以是LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting Diode,有机发光二极管)触摸器等。所述显示器30用于显示在所述数据同步异常时数据一致性校验设备的信息以及用于显示可视化的用户界面。所述数据同步异常时数据一致性校验设备的部件10-30通过系统总线相互通信。In some embodiments, the
在一实施例中,当处理器10执行所述存储器20中数据同步异常时数据一致性校验程序40时实现以下步骤:In one embodiment, when the
接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作;Receive the log message package sent by the source, insert the transaction ID of the synchronization transaction in the log message package into the auxiliary table created in the target database, and then perform the transaction synchronization operation;
当接收到目标端数据库的报错通知时,判断当前的同步事务处于何种操作,其中所述操作包括依次执行的事务变更操作和事务提交操作;When receiving an error notification from the target database, determine what operation the current synchronization transaction is in, wherein the operation includes a transaction change operation and a transaction commit operation performed in sequence;
在当前操作为事务变更操作时,判断报错通知是否属于预设的错误类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作;When the current operation is a transaction change operation, determine whether the error notification belongs to the preset error type, roll back the synchronization operation performed when the error notification belongs to the preset error type, and re-insert the transaction ID of the synchronization transaction into the auxiliary table in and re-run the transaction synchronization operation;
在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。When the current operation is a transaction commit operation, reconnect to the target database, and query whether the transaction ID of the synchronous transaction is contained in the auxiliary table, and if not, insert the transaction ID of the synchronous transaction into the auxiliary table and re-synchronize the transaction operate.
所述事务变更操作包括插入操作、更新操作和删除操作。The transaction modification operations include insert operations, update operations and delete operations.
进一步地,所述接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作的步骤包括:Further, the step of receiving the log message package sent by the source and inserting the transaction ID of the synchronization transaction in the log message package into the auxiliary table created in the target database includes:
解析当前同步事务所在的日志消息包并获取日志消息包中的同步事务的事务ID;Parse the log message package where the current synchronization transaction is located and obtain the transaction ID of the synchronization transaction in the log message package;
在目标端数据库中创建的辅助表中执行插入操作以将所述事务 ID插入辅助表中。An insert operation is performed in the auxiliary table created in the target database to insert the transaction ID into the auxiliary table.
进一步地,所述在当前操作为事务变更操作时,判断报错通知是否属于预设的报错类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作的步骤包括:Further, when the current operation is a transaction change operation, it is judged whether the error notification belongs to a preset error type, and when the error notification belongs to the preset error type, the synchronization operation that has been performed is rolled back and the synchronization transaction is reset. The steps for inserting the transaction ID into the secondary table and re-synchronizing the transaction include:
在当前操作为事务变更操作时,根据目标端数据库返回的错误码识别错误的类型;When the current operation is a transaction change operation, identify the type of error according to the error code returned by the target database;
判断该错误类型是否属于预设的错误类型;Determine whether the error type is a preset error type;
在该错误类型为预设的错误类型时,断开与目标端数据库的连接并回滚已进行的同步操作,并在回滚完成后重新将该同步事务的事务 ID插入辅助表中并重新进行事务同步操作。When the error type is the preset error type, disconnect the connection with the target database and roll back the synchronization operation that has been performed, and re-insert the transaction ID of the synchronization transaction into the auxiliary table after the rollback is completed and repeat the operation Transaction synchronization operation.
进一步地,所述在该错误类型为预设的错误类型时,断开与目标端数据库的连接并回滚已进行的同步操作,并在回滚完成后重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作的步骤还包括:Further, when the error type is a preset error type, disconnect the connection with the target database and roll back the synchronization operation that has been performed, and re-insert the transaction ID of the synchronization transaction into the auxiliary after the rollback is completed. The steps for re-synchronizing the transaction in the table also include:
在该错误类型不是预设的错误类型时,执行预设的同步事务出错处理流程。When the error type is not the preset error type, the preset synchronous transaction error processing flow is executed.
进一步地,所述预设的错误类型包括网络异常错误和数据库系统级错误。Further, the preset error types include abnormal network errors and database system-level errors.
进一步地,所述在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作的步骤包括:Further, when the current operation is a transaction commit operation, reconnect the target database, and query whether the transaction ID of the synchronous transaction is contained in the auxiliary table, and if not included, insert the transaction ID of the synchronous transaction into the auxiliary table. And the steps for re-synchronizing the transaction include:
在当前操作为事务提交操作时,断开与目标端数据库的连接并重新连接目标端数据库;When the current operation is a transaction commit operation, disconnect from the target database and reconnect to the target database;
调用目标端数据库中的辅助表,并查询所述辅助表中是否存在所述同步事务开始时登记的事务ID;Call the auxiliary table in the target database, and query whether there is a transaction ID registered at the beginning of the synchronous transaction in the auxiliary table;
在所述辅助表中不存在该事务ID时,将该同步事务ID插入目标端数据库中的辅助表中并重新开始进行事务同步操作。When the transaction ID does not exist in the auxiliary table, insert the synchronization transaction ID into the auxiliary table in the target database and restart the transaction synchronization operation.
进一步的,所述在所述辅助表中不存在该事务ID时,将该同步事务ID插入目标端数据库中的辅助表中并重新开始进行事务同步操作的步骤还包括:Further, when the transaction ID does not exist in the auxiliary table, the steps of inserting the synchronization transaction ID into the auxiliary table in the target database and restarting the transaction synchronization operation further include:
在所述辅助表中存在该事务ID时,执行下一个同步事务。When the transaction ID exists in the auxiliary table, the next synchronization transaction is executed.
请参阅图6,其为本发明安装数据同步异常时数据一致性校验程序的系统较佳实施例的功能模块图。在本实施例中,安装数据同步异常时数据一致性校验程序的系统可以被分割成一个或多个模块,所述一个或者多个模块被存储于所述存储器20中,并由一个或多个处理器(本实施例为所述处理器10)所执行,以完成本发明。例如,在图6中,安装数据同步异常时数据一致性校验程序的系统可以被分割成事务标签插入模块21、操作判断模块22、变更操作错误处理模块 23和提交操作错误处理模块24。本发明所称的模块是指能够完成特定功能的一系列计算机程序指令段,比程序更适合于描述所述数据同步异常时数据一致性校验程序在所述数据同步异常时数据一致性校验设备中的执行过程。以下描述将具体介绍所述模块21-24的功能。Please refer to FIG. 6 , which is a functional block diagram of a preferred embodiment of a system for installing a data consistency check program when data synchronization is abnormal according to the present invention. In this embodiment, the system for installing the data consistency check program when the data synchronization is abnormal can be divided into one or more modules, the one or more modules are stored in the
事务标签插入模块21,用于接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作;The transaction
操作判断模块22,用于当接收到目标端数据库的报错通知时,判断当前的同步事务处于何种操作,其中所述操作包括依次执行的事务变更操作和事务提交操作;The
变更操作错误处理模块23,用于在当前操作为事务变更操作时,判断报错通知是否属于预设的错误类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作;The change operation
提交操作错误处理模块24,用于在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务 ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。The commit operation
其中,所述事务变更操作包括插入操作、更新操作和删除操作。Wherein, the transaction change operation includes an insert operation, an update operation and a delete operation.
进一步的,事务标签插入模块21具体包括:Further, the transaction
事务标签获取单元,用于解析当前同步事务所在的日志消息包并获取日志消息包中的同步事务的事务ID;The transaction label acquisition unit is used to parse the log message package in which the current synchronization transaction is located and obtain the transaction ID of the synchronization transaction in the log message package;
事务标签插入单元,用于在目标端数据库中创建的辅助表中执行插入操作以将所述事务ID插入辅助表中。The transaction label insertion unit is used to perform an insert operation in the auxiliary table created in the target database to insert the transaction ID into the auxiliary table.
变更操作错误处理模块23具体包括:The change operation
错误接收单元,用于在当前操作为事务变更操作时,根据目标端数据库返回的错误码识别错误的类型;The error receiving unit is used to identify the type of error according to the error code returned by the target database when the current operation is a transaction change operation;
错误类型判断单元,用于判断该错误类型是否属于预设的错误类型;An error type judgment unit, used to judge whether the error type belongs to a preset error type;
第一错误处理单元,用于在该错误类型为预设的错误类型时,断开与目标端数据库的连接并回滚已进行的同步操作,并在回滚完成后重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。The first error processing unit is used for disconnecting the connection with the target database and rolling back the synchronization operation performed when the error type is a preset error type, and re-transaction of the synchronization transaction after the rollback is completed The ID is inserted into the auxiliary table and the transaction synchronization operation is repeated.
优选的,所述第一错误处理单元还用于在该错误类型不是预设的错误类型时,执行预设的同步事务出错处理流程。Preferably, the first error processing unit is further configured to execute a preset synchronization transaction error processing flow when the error type is not a preset error type.
优选的,所述预设的错误类型包括网络异常错误和数据库系统级错误。Preferably, the preset error types include abnormal network errors and database system-level errors.
所述提交操作错误处理模块24具体包括:The commit operation
连接断开单元,用于在当前操作为事务提交操作时,断开与目标端数据库的连接并重新连接目标端数据库;The connection disconnection unit is used to disconnect the connection with the target database and reconnect to the target database when the current operation is a transaction commit operation;
查询单元,用于调用目标端数据库中的辅助表,并查询所述辅助表中是否存在所述同步事务开始时登记的事务ID;a query unit, used to call an auxiliary table in the target database, and query whether there is a transaction ID registered at the beginning of the synchronous transaction in the auxiliary table;
第二错误处理单元,在所述辅助表中不存在该事务ID时,将该同步事务ID插入目标端数据库中的辅助表中并重新开始进行事务同步操作。The second error processing unit, when the transaction ID does not exist in the auxiliary table, inserts the synchronization transaction ID into the auxiliary table in the target database and restarts the transaction synchronization operation.
优选的,所述第二错误处理单元还用于在所述辅助表中存在该事务ID时,执行下一个同步事务。Preferably, the second error processing unit is further configured to execute the next synchronization transaction when the transaction ID exists in the auxiliary table.
综上所述,本发明提供的数据同步异常时数据一致性校验方法、设备及存储介质中,所述方法包括:首先接收源端发送的日志消息包,并将日志消息包中的同步事务的事务ID插入目标端数据库中创建的辅助表中后进行事务同步操作;然后当接收到目标端数据库的报错通知时,判断当前的同步事务处于何种操作,其中所述操作包括依次执行的事务变更操作和事务提交操作;在当前操作为事务变更操作时,判断报错通知是否属于预设的错误类型,并在报错通知属于预设的错误类型时回滚已进行的同步操作并重新将该同步事务的事务ID插入辅助表中并重新进行事务同步操作,在当前操作为事务提交操作时,重新连接目标端数据库,并查询辅助表中是否包含该同步事务的事务 ID,并在不包含时将该同步事务的事务ID插入辅助表中并重新进行事务同步操作。本发明在同步过程中,同步事务开始时先在辅助表中登记事务标签,如果同步过程中出错,则通过根据当前的操作来判断事务标签是否已登记,从而进一步判断出是否已同步完成,以保证同步数据的一致性。To sum up, in the data consistency check method, device and storage medium provided by the present invention when data synchronization is abnormal, the method includes: firstly receiving the log message package sent by the source end, and converting the synchronization transaction in the log message package After the transaction ID is inserted into the auxiliary table created in the target database, the transaction synchronization operation is performed; then when an error notification from the target database is received, it is judged what operation the current synchronization transaction is in, wherein the operation includes the transactions executed in sequence Change operation and transaction commit operation; when the current operation is a transaction change operation, determine whether the error notification belongs to the preset error type, and roll back the synchronization operation performed when the error notification belongs to the preset error type and re-synchronize the Insert the transaction ID of the transaction into the auxiliary table and perform the transaction synchronization operation again. When the current operation is a transaction commit operation, reconnect to the target database, and query whether the transaction ID of the synchronization transaction is contained in the auxiliary table, and if not The transaction ID of the synchronization transaction is inserted into the auxiliary table and the transaction synchronization operation is performed again. In the synchronization process of the present invention, the transaction label is first registered in the auxiliary table at the beginning of the synchronization transaction. If there is an error in the synchronization process, it is judged whether the transaction label has been registered according to the current operation, so as to further determine whether the synchronization has been completed. Ensure the consistency of synchronized data.
当然,本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关硬件(如处理器,控制器等)来完成,所述的程序可存储于一计算机可读取的存储介质中,该程序在执行时可包括如上述各方法实施例的流程。其中所述的存储介质可为存储器、磁碟、光盘等。Of course, those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing relevant hardware (such as processors, controllers, etc.) through a computer program, and the programs can be stored in a In the computer-readable storage medium, when the program is executed, the processes of the above-mentioned method embodiments may be included. The storage medium may be a memory, a magnetic disk, an optical disk, or the like.
应当理解的是,本发明的应用不限于上述的举例,对本领域普通技术人员来说,可以根据上述说明加以改进或变换,所有这些改进和变换都应属于本发明所附权利要求的保护范围。It should be understood that the application of the present invention is not limited to the above examples. For those of ordinary skill in the art, improvements or transformations can be made according to the above descriptions, and all these improvements and transformations should belong to the protection scope of the appended claims of the present invention.
Claims (7)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910436428.3A CN110427422B (en) | 2019-05-23 | 2019-05-23 | Data consistency check method, device and storage medium when data synchronization is abnormal |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910436428.3A CN110427422B (en) | 2019-05-23 | 2019-05-23 | Data consistency check method, device and storage medium when data synchronization is abnormal |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110427422A CN110427422A (en) | 2019-11-08 |
CN110427422B true CN110427422B (en) | 2020-10-30 |
Family
ID=68407549
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910436428.3A Active CN110427422B (en) | 2019-05-23 | 2019-05-23 | Data consistency check method, device and storage medium when data synchronization is abnormal |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110427422B (en) |
Families Citing this family (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111221800B (en) * | 2019-12-19 | 2024-09-13 | 中国平安人寿保险股份有限公司 | Database migration method and device, electronic equipment and storage medium |
CN111367705B (en) * | 2020-03-31 | 2023-08-04 | 中国工商银行股份有限公司 | SQL error reporting processing method and device |
CN111737331B (en) * | 2020-06-22 | 2023-08-18 | 中国银行股份有限公司 | Transaction consistency processing method and system for database and object storage |
CN112307118B (en) * | 2020-09-30 | 2024-03-22 | 武汉达梦数据库股份有限公司 | Method for guaranteeing data consistency based on log analysis synchronization and synchronization system |
CN113761056B (en) * | 2021-04-07 | 2025-01-14 | 西安京迅递供应链科技有限公司 | A distributed service processing method, device and system |
CN115373889A (en) * | 2021-05-19 | 2022-11-22 | 中移动信息技术有限公司 | Method and device for data comparison and verification and data restoration in data synchronization |
CN113282393A (en) * | 2021-06-04 | 2021-08-20 | 银盛支付服务股份有限公司 | Method for solving task scheduling facing to multiple portrait label jobs |
CN115630121A (en) * | 2022-10-31 | 2023-01-20 | 浪潮通用软件有限公司 | Method and device for realizing data synchronization service |
CN119127821B (en) * | 2024-08-26 | 2025-06-20 | 北京大学第三医院(北京大学第三临床医学院) | A medical data synchronization consistency verification method and system based on Elasticsearch database |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105338093A (en) * | 2015-11-16 | 2016-02-17 | 中国建设银行股份有限公司 | Data synchronizing method and system |
US9436752B2 (en) * | 2003-10-02 | 2016-09-06 | Progress Software Corporation | High availability via data services |
CN106484807A (en) * | 2016-09-23 | 2017-03-08 | 北京许继电气有限公司 | Build the method and system of autonomous controlled data storehouse dual-active or many aggregated structures living |
CN106775959A (en) * | 2016-12-06 | 2017-05-31 | 上海亿账通互联网科技有限公司 | Distributed transaction processing method and system |
CN109241185A (en) * | 2018-08-27 | 2019-01-18 | 武汉达梦数据库有限公司 | A kind of method and data synchronization unit that data are synchronous |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9959178B2 (en) * | 2014-11-25 | 2018-05-01 | Sap Se | Transactional and parallel log replay for asynchronous table replication |
CN109634970B (en) * | 2018-10-19 | 2024-05-03 | 平安科技(深圳)有限公司 | Table data synchronization method, apparatus, storage medium and device |
CN109657007A (en) * | 2018-12-17 | 2019-04-19 | 武汉达梦数据库有限公司 | Database in phase based on asynchronous submission executes method and apparatus parallel |
-
2019
- 2019-05-23 CN CN201910436428.3A patent/CN110427422B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9436752B2 (en) * | 2003-10-02 | 2016-09-06 | Progress Software Corporation | High availability via data services |
CN105338093A (en) * | 2015-11-16 | 2016-02-17 | 中国建设银行股份有限公司 | Data synchronizing method and system |
CN106484807A (en) * | 2016-09-23 | 2017-03-08 | 北京许继电气有限公司 | Build the method and system of autonomous controlled data storehouse dual-active or many aggregated structures living |
CN106775959A (en) * | 2016-12-06 | 2017-05-31 | 上海亿账通互联网科技有限公司 | Distributed transaction processing method and system |
CN109241185A (en) * | 2018-08-27 | 2019-01-18 | 武汉达梦数据库有限公司 | A kind of method and data synchronization unit that data are synchronous |
Non-Patent Citations (4)
Title |
---|
"Synchronization and Recovery in an Embedded Database System for Read-Only Transactions";Subhash Bhalla et al.;《International Conference on Embedded and Ubiquitous Computing》;20051231;全文 * |
"基于事务日志的数据同步模型研究";钟容 等;《科技创新与应用》;20160430(第10期);全文 * |
"基于操作日志的完井数据同步模型";吴雅娟 等;《计算机系统应用》;20150527;第24卷(第5期);全文 * |
"数据库同步技术的研究与实现";刘娟娟 等;《软件工程》;20170131;第20卷(第1期);全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN110427422A (en) | 2019-11-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110427422B (en) | Data consistency check method, device and storage medium when data synchronization is abnormal | |
CN110347746B (en) | Heterogeneous database synchronous data consistency checking method and device | |
US8719232B2 (en) | Systems and methods for data integrity checking | |
CN111209142B (en) | Cross-database transaction management method, device, equipment and storage medium | |
CN110222119B (en) | A data conversion synchronization method, device and storage medium for heterogeneous databases | |
CN111400104B (en) | Data synchronization method and device, electronic equipment and storage medium | |
CN103338118B (en) | A kind of communication network method of attachment and device | |
US20150317175A1 (en) | Virtual machine synchronization system | |
CN102521059A (en) | On-board data management system self fault-tolerance method | |
WO2011120452A2 (en) | Method for updating data and control apparatus thereof | |
CN114490570A (en) | Production data synchronization method and device, data synchronization system and server | |
CN116775727B (en) | Data delay statistics method, device, equipment and storage medium | |
CN116467389A (en) | Data synchronization method for coal mine two-stage data center | |
CN111198920B (en) | Method and device for determining comparison table snapshot based on database synchronization | |
CN115757428A (en) | Method and related equipment for automatically and remotely synchronizing data in multi-tenant environment | |
CN118779379A (en) | A message queue breakpoint synchronization method, storage medium and device | |
CN118689862A (en) | Heterogeneous database data migration method, device, equipment and storage medium | |
CN114138600A (en) | Storage method, device, equipment and storage medium for firmware key information | |
US7933873B2 (en) | Handling transfer of bad data to database partitions in restartable environments | |
CN115048244B (en) | A server hardware repair method, system, computer equipment and medium | |
CN111752911A (en) | A Flume-based data transmission method, system, terminal and storage medium | |
CN103312728B (en) | Method of data synchronization between a kind of storage system, system and device | |
CN116860741B (en) | Automatic data standard checking and synchronizing system and method based on message queue | |
CN117453825A (en) | Data synchronization method, device, medium and storage equipment | |
CN119512708A (en) | Business request processing method, device, equipment and medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP01 | Change in the name or title of a patent holder |
Address after: 430000 16-19 / F, building C3, future technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan, Hubei Province Patentee after: Wuhan dream database Co.,Ltd. Address before: 430000 16-19 / F, building C3, future technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan, Hubei Province Patentee before: WUHAN DAMENG DATABASE Co.,Ltd. |
|
CP01 | Change in the name or title of a patent holder | ||
CB03 | Change of inventor or designer information | ||
CB03 | Change of inventor or designer information |
Inventor after: Sun Feng Inventor after: Yu Yuanlan Inventor after: Zhao Jiawei Inventor before: Fu Quan Inventor before: Sun Feng Inventor before: Yu Yuanlan Inventor before: Zhao Jiawei |
|
TR01 | Transfer of patent right | ||
TR01 | Transfer of patent right |
Effective date of registration: 20220914 Address after: 430073 16-19 / F, building C3, future science and technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province Patentee after: Wuhan dream database Co.,Ltd. Patentee after: HUAZHONG University OF SCIENCE AND TECHNOLOGY Address before: 430000 16-19 / F, building C3, future technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan, Hubei Province Patentee before: Wuhan dream database Co.,Ltd. |
|
TR01 | Transfer of patent right | ||
TR01 | Transfer of patent right |
Effective date of registration: 20230725 Address after: 16-19/F, Building C3, Future Science and Technology Building, No. 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province, 430206 Patentee after: Wuhan dream database Co.,Ltd. Address before: 430073 16-19 / F, building C3, future science and technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province Patentee before: Wuhan dream database Co.,Ltd. Patentee before: HUAZHONG University OF SCIENCE AND TECHNOLOGY |