Data synchronization method, device, equipment and computer-readable storage medium

By creating a new buffer during transaction execution to store the change operation data and sending it to the message middleware when successful, the problem of data synchronization and database transactions is solved, the correct synchronization and code decoupling of nested transactions are achieved, and the efficiency and flexibility of data synchronization are improved.

CN110333936BActive Publication Date: 2025-09-02WEBANK (CHINA)
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN201910566116.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-06-26
Publication Date
2025-09-02
Estimated Expiration
2039-06-26

AI Technical Summary

Technical Problem

In the existing data synchronization scheme, the data synchronization action is inconsistent with the database transaction, especially in nested transactions, the correct synchronization sequence requirements cannot be met, and the business logic code is closely coupled with the message sending code, making modification inconvenient.

Method used

When the target transaction is detected, a new data buffer to be synchronized is created for it, and the change operation data is stored. After the transaction is successfully executed, the buffer data is sent to the message middleware for synchronization. It can determine which data needs to be synchronized through preset domain tables and conversion rules.

Benefits of technology

It realizes consistency between data synchronization actions and database transactions, supports the correct synchronization order of nested transactions, reduces code coupling, and improves modification flexibility and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110333936B_ABST
    Figure CN110333936B_ABST
Patent Text Reader

Abstract

The present invention discloses a data synchronization method, apparatus, device, and computer-readable storage medium, relating to the field of financial technology. The method comprises the following steps: upon detecting an instruction for controlling data changes, creating a new data buffer to be synchronized for a target transaction controlled by the instruction; after the target transaction begins execution, placing the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized; upon detecting that the target transaction is successfully executed, sending all the change operation data of the target transaction in the data buffer to a message middleware for data synchronization. This ensures that each transaction is synchronized for each successful execution, thereby achieving consistency between data synchronization actions and database transaction execution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information retrieval technology in financial technology (Fintech), and in particular to a data synchronization method, apparatus, device, and computer-readable storage medium. Background Art

[0002] With the development of computer technology, more and more technologies (big data, distributed computing, blockchain, artificial intelligence, etc.) are being applied in the financial field. The traditional financial industry is gradually transforming into financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology.

[0003] In financial systems, it is often necessary to synchronize data changes (insert, update, and delete) in the system to other systems in real time through message middleware. For example, to synchronize transaction data in a trading system to a quasi-real-time query system or a transaction analysis system in real time. The general solution is: (1) to embed the data synchronization method in the business logic code, for example, after executing insert, update, or delete, the inserted, updated, or deleted data is sent to the message middleware. In this solution, if the transaction is rolled back due to an exception, the sent message cannot be withdrawn. At the same time, the code for sending messages is tightly coupled with the business logic code, making it very inconvenient to modify. (2) In addition, the general solution cannot meet the requirements of nested transactions. For example, there is the following nested transaction: main transaction starts → execute data change 1 → main transaction suspends → sub-transaction starts → execute data change 2 → sub-transaction commits → main transaction resumes → execute data change 3 → main transaction commits. According to the correct logic, when the sub-transaction commits successfully, only data change 2 needs to be synchronized; when the main transaction commits successfully, data changes 1 and 3 need to be synchronized. However, existing solutions often synchronize 1 and 2 first, then 3, or synchronize 1, 2, and 3 together after the main transaction is committed. This results in inconsistencies between data synchronization and database transactions. Summary of the Invention

[0004] The main purpose of the present invention is to provide a data synchronization method, device, equipment and computer-readable storage medium, aiming to solve the technical problem of inconsistency between data synchronization actions and database transactions in existing data synchronization solutions.

[0005] To achieve the above object, the present invention provides a data synchronization method, which includes the following steps:

[0006] When an instruction for controlling data change is detected, a new data buffer to be synchronized is created for a target transaction controlled by the instruction;

[0007] After the target transaction starts executing, the change operation data that needs to be synchronized by the target transaction is placed in the data buffer to be synchronized;

[0008] When it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are sent to the message middleware for data synchronization.

[0009] Optionally, before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction, the method further includes:

[0010] Determining a current change operation according to the instruction, and judging whether the change operation data of the current change operation needs to be synchronized;

[0011] If necessary, the step of placing the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized is executed.

[0012] Optionally, the step of determining whether the change operation data of the current change operation needs to be synchronized includes:

[0013] Obtaining the domain type and domain object of the current change operation, and determining whether the domain type and domain object of the current change operation exist in a preset domain table;

[0014] If the domain type and domain object of the current change operation exist in the preset domain table, determining whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are allowed to be synchronized;

[0015] If the corresponding representations of the domain type and domain object of the current change operation in the preset domain table indicate that synchronization is allowed, determining that the change operation data of the current change operation of the target transaction needs to be synchronized;

[0016] If the domain type and domain object of the current change operation do not exist in the preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are synchronization prohibited, it is determined that the change operation data of the current change operation of the target transaction does not need to be synchronized.

[0017] Optionally, when detecting that the target transaction is successfully executed, the step of sending all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization includes:

[0018] When it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are added to the data synchronization queue;

[0019] Obtain the type of the message middleware corresponding to the domain type of the current change operation in the preset domain table;

[0020] All change operation data of the target transaction in the data synchronization queue are sent to the corresponding type of message middleware to perform data synchronization.

[0021] Optionally, the step of placing the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized includes:

[0022] Convert the change operation data that needs to be synchronized into a preset format according to a preset conversion rule;

[0023] Putting the change operation data converted into a preset format into the data buffer to be synchronized;

[0024] The step of sending all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when the target transaction is detected to be executed successfully includes:

[0025] When it is detected that the target transaction is executed successfully, the change operation data converted into a preset format in the data buffer to be synchronized is sent to the message middleware to perform data synchronization.

[0026] Optionally, after the step of adding all the change operation data of the target transaction in the to-be-synchronized data buffer to the data synchronization queue when it is detected that the target transaction is executed successfully, the method further includes:

[0027] Delete the data buffer to be synchronized of the target transaction.

[0028] Optionally, before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction, the method further includes:

[0029] Determining whether the target transaction controlled by the instruction is a preset interception transaction;

[0030] If the target transaction controlled by the instruction is a preset interception transaction, the following steps are executed: creating a new buffer zone for data to be synchronized for the target transaction controlled by the instruction.

[0031] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a data synchronization device, comprising:

[0032] A detection module, configured to, upon detecting an instruction for controlling data change, create a new data buffer to be synchronized for a target transaction controlled by the instruction;

[0033] An insert module is used to insert the change operation data that needs to be synchronized by the target transaction into the data buffer to be synchronized after the target transaction starts executing;

[0034] The synchronization module is used to send all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when detecting that the target transaction is executed successfully.

[0035] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a data synchronization device, which includes a memory, a processor, and a data synchronization program stored on the memory and runnable on the processor, and when the data synchronization program is executed by the processor, the steps of the data synchronization method described above are implemented.

[0036] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a data synchronization program is stored, and when the data synchronization program is executed by a processor, the steps of the data synchronization method described above are implemented.

[0037] The present invention creates a new data buffer to be synchronized for the target transaction when detecting the start of the target transaction; creates a new data buffer to be synchronized for the target transaction controlled by the instruction when detecting an instruction for controlling data changes; places the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized after the target transaction starts executing; and sends all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when detecting the successful execution of the target transaction. By establishing a data buffer to be synchronized for the target transaction to store the change operation data during the execution of the transaction, and sending the change operation data in the data buffer to the message middleware after detecting the successful execution of the transaction, each transaction is synchronized for each successful execution, thereby achieving consistency between the data synchronization action and the execution of the database transaction. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 This is a schematic diagram of the structure of the device hardware operating environment involved in the data synchronization device embodiment of the present invention;

[0039] Figure 2 This is a flow chart of a first embodiment of a data synchronization method according to the present invention;

[0040] Figure 3 Schematic diagram of the functional modules of the data synchronization device of the present invention.

[0041] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0042] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0043] It should be noted that in financial systems, data changes (insert, update, and delete) in the system often need to be synchronized to other systems in real time through message middleware. For example, transaction data in the trading system can be synchronized to a quasi-real-time query system or a transaction analysis system in real time. The general solution is: (1) Embed data synchronization methods in the business logic code, for example, after executing insert, update, or delete, the inserted, updated, or deleted data is sent to the message middleware. In this solution, if the transaction is rolled back due to an exception, the sent message cannot be withdrawn. At the same time, the code for sending messages is tightly coupled with the business logic code, making it very inconvenient to modify. ((2) In addition, general solutions cannot meet the requirements of nested transactions. For example, there is a nested transaction as follows: main transaction starts → execute data change 1 → main transaction suspends → sub-transaction starts → execute data change 2 → sub-transaction commits → main transaction resumes → execute data change 3 → main transaction commits. According to the correct logic, when the sub-transaction commits successfully, only data change 2 needs to be synchronized; when the main transaction commits successfully, data changes 1 and 3 need to be synchronized. However, the existing solutions often synchronize 1 and 2 first, and then synchronize 3; or synchronize 1, 2, and 3 together after the main transaction commits. This leads to inconsistency between the data synchronization action and the database transaction.

[0044] Based on the above-mentioned defects, the present invention provides a data synchronization device, referring to Figure 1 , Figure 1 This is a schematic diagram of the structure of the device hardware operating environment involved in the data synchronization device embodiment of the present invention.

[0045] like Figure 1 As shown, the data synchronization device may include: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the user interface 1003 may optionally include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may optionally be a storage device independent of the aforementioned processor 1001.

[0046] Those skilled in the art will understand that Figure 1 The hardware structure of the data synchronization device shown in the figure does not constitute a limitation on the data synchronization device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0047] like Figure 1 As shown, memory 1005, a computer-readable storage medium, may include an operating system, a network communication module, a user interface module, and a data synchronization program. The operating system is a program that manages and controls data synchronization devices and software resources, supporting the operation of the network communication module, the user interface module, the data synchronization program, and other programs or software. The network communication module is used to manage and control the network interface 1004; the user interface module is used to manage and control the user interface 1003.

[0048] exist Figure 1 In the hardware structure of the data synchronization device shown, the network interface 1004 is mainly used to connect to the backend server and communicate data with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; the processor 1001 can call the data synchronization program stored in the memory 1005 and perform the following operations:

[0049] When an instruction for controlling data change is detected, a new data buffer to be synchronized is created for a target transaction controlled by the instruction;

[0050] After the target transaction starts executing, the change operation data that needs to be synchronized by the target transaction is placed in the data buffer to be synchronized;

[0051] When the target transaction is detected to be executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are sent to the message middleware for data synchronization.

[0052] Furthermore, before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction, the processor 1001 is further configured to call a data synchronization program stored in the memory 1005 and perform the following operations:

[0053] Determine the current change operation according to the instruction, and judge whether the change operation data of the current change operation of the target transaction needs to be synchronized;

[0054] If necessary, the step of placing the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized is executed.

[0055] Furthermore, the step of determining whether the change operation data of the current change operation needs to be synchronized includes:

[0056] Obtaining the domain type and domain object of the current change operation, and determining whether the domain type and domain object of the current change operation exist in a preset domain table;

[0057] If the domain type and domain object of the current change operation exist in the preset domain table, determining whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are allowed to be synchronized;

[0058] If the corresponding representations of the domain type and domain object of the current change operation in the preset domain table indicate that synchronization is allowed, determining that the change operation data of the current change operation of the target transaction needs to be synchronized;

[0059] If the domain type and domain object of the current change operation do not exist in the preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are synchronization prohibited, it is determined that the change operation data of the current change operation of the target transaction does not need to be synchronized.

[0060] Furthermore, when the target transaction is detected to be successfully executed, the step of sending all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization includes:

[0061] When it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are added to the data synchronization queue;

[0062] Obtain the type of the message middleware corresponding to the domain type of the current change operation in the preset domain table;

[0063] All change operation data of the target transaction in the data synchronization queue are sent to the corresponding type of message middleware to perform data synchronization.

[0064] Furthermore, the step of placing the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized includes:

[0065] Convert the change operation data that needs to be synchronized into a preset format according to a preset conversion rule;

[0066] Putting the change operation data converted into a preset format into the data buffer to be synchronized;

[0067] Furthermore, when the target transaction is detected to be successfully executed, the step of sending all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization includes:

[0068] When it is detected that the target transaction is executed successfully, the change operation data converted into a preset format in the data buffer to be synchronized is sent to the message middleware to perform data synchronization.

[0069] Furthermore, if it is detected that the target transaction is executed successfully, after the step of adding all the change operation data of the target transaction in the data buffer to be synchronized to the data synchronization queue, the processor 1001 is further configured to call the data synchronization program stored in the memory 1005 and perform the following operations:

[0070] Delete the data buffer to be synchronized of the target transaction.

[0071] Furthermore, before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction, the processor 1001 is further configured to call a data synchronization program stored in the memory 1005 and perform the following operations:

[0072] Determining whether the target transaction controlled by the instruction is a preset interception transaction;

[0073] If the target transaction controlled by the instruction is a preset interception transaction, the following steps are executed: creating a new buffer zone for data to be synchronized for the target transaction controlled by the instruction.

[0074] The specific implementation of the data synchronization device of the present invention is basically the same as the embodiments of the data synchronization method described below, and will not be repeated here.

[0075] The present invention also provides a data synchronization method.

[0076] The embodiment of the present invention provides an embodiment of a data synchronization method. It should be noted that although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in an order different from that shown here.

[0077] In various embodiments of the data synchronization method, for the sake of convenience, the execution subject is omitted to illustrate various embodiments. Figure 2 , Figure 2 This is a flowchart of a first embodiment of a data synchronization method according to the present invention. The data synchronization method includes:

[0078] Step S10, when an instruction for controlling data change is detected, a new data buffer to be synchronized is created for the target transaction controlled by the instruction;

[0079] In an embodiment of the present invention, the data synchronization device is integrated with a transaction interception function of a transaction interceptor, which can intercept a preset interception transaction at a preset entry point. In this embodiment, the preset entry point can be selected as the start of the transaction. Before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction in the above step S10, the step of determining whether the target transaction controlled by the instruction is a preset interception transaction is also included. If the target transaction is a preset interception transaction, the data synchronization device will create a new data buffer to be synchronized for the target transaction controlled by the instruction when detecting an instruction for controlling data changes. The data buffer to be synchronized is used to temporarily store the change operation data of the target transaction during transaction execution.

[0080] Step S20: after the target transaction starts executing, the change operation data that needs to be synchronized by the target transaction is placed into the data buffer to be synchronized;

[0081] In an embodiment of the present invention, since the execution of the target transaction requires calling one or more database interfaces and performing one or more change operations, each change operation generates corresponding change operation data. Sometimes it is not necessary to synchronize data for the target transaction or each change operation of the target transaction. The data synchronization device only needs to put the change operation data that needs to be synchronized into the data buffer to be synchronized.

[0082] Therefore, the data synchronization device integrates an interface operation interception function of an interface operation interceptor, which can intercept change operations that call database interfaces. Before the above-mentioned step of creating a new data buffer to be synchronized for the target transaction, the data synchronization device also includes a step of determining whether the change operation data of the current change operation of the target transaction needs to be synchronized. Specifically, the following steps are performed: obtaining the domain type and domain object of the current change operation, and determining whether the domain type and domain object of the current change operation exist in a preset domain table; if the domain type and domain object of the current change operation exist in the preset domain table, determining whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table allow synchronization; if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table allow synchronization, determining that the change operation data of the current change operation of the target transaction needs to be synchronized; if the domain type and domain object of the current change operation do not exist in the preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table prohibit synchronization, determining that the change operation data of the current change operation of the target transaction does not need to be synchronized. If the change operation data of the current change operation of the target transaction needs to be synchronized, the change operation data of the current change operation of the target transaction is placed in the target transaction's data buffer to be synchronized. If the change operation data of the current change operation of the target transaction does not need to be synchronized, the change operation data of the current change operation of the target transaction is not placed in the target transaction's data buffer to be synchronized.

[0083] Furthermore, step S20 specifically includes: converting the change operation data to be synchronized into a preset format according to a preset conversion rule; and placing the change operation data converted into the preset format into the data buffer to be synchronized. Converting the change operation data into a unified preset format lays the foundation for improving the efficiency and accuracy of data synchronization.

[0084] Step S30: When it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are sent to the message middleware for data synchronization.

[0085] In this embodiment, the above-mentioned step S30 includes: when it is detected that the target transaction is executed successfully, all change operation data of the target transaction in the data buffer to be synchronized are added to the data synchronization queue; obtaining the message middleware corresponding to the domain type of the current change operation in the preset domain table; and sending all change operation data of the target transaction in the data synchronization queue to the message middleware of the corresponding type for data synchronization.

[0086] Specifically, upon detecting that a target transaction has executed successfully, the data synchronization device retrieves all target transaction changes from its pending synchronization buffer and places them into a data synchronization queue. The device then retrieves the message middleware type corresponding to the domain type of the current change operation from a pre-set domain table and sends all changes in the data synchronization queue to the message middleware of the corresponding type, synchronizing the data with the recipient. If a target transaction fails, data synchronization is not performed for that transaction, and the pending synchronization buffer is deleted.

[0087] Furthermore, before the step of sending all changed data in the data synchronization queue to the corresponding type of message middleware, it can also include generating a text in a text format (such as JSON or XML, etc.) that can be known to the recipient based on the changed data in the data synchronization queue, and then sending the text to the corresponding type of message middleware.

[0088] This embodiment creates a new data buffer to be synchronized for the target transaction controlled by the instruction upon detecting an instruction for controlling data changes; after the target transaction begins execution, the change operation data required for synchronization of the target transaction is placed in the data buffer to be synchronized; and upon detecting successful execution of the target transaction, all change operation data of the target transaction in the data buffer to be synchronized is sent to the message middleware for data synchronization. By creating a data buffer to be synchronized for the target transaction controlled by the instruction upon detecting an instruction for controlling data changes, storing the change operation data during the execution of the transaction, and sending the change operation data in the data buffer to the message middleware upon detecting successful execution of the transaction, each transaction is synchronized upon successful execution, thereby achieving consistency between data synchronization actions and database transaction execution.

[0089] Furthermore, a second embodiment of the data synchronization method of the present invention is proposed, which includes, before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction, the following steps are further included:

[0090] Step S11, determining whether the target transaction controlled by the instruction is a preset interception transaction;

[0091] If the target transaction controlled by the instruction is a preset interception transaction, the following steps are executed: creating a new buffer zone for data to be synchronized for the target transaction controlled by the instruction.

[0092] In this embodiment, the data synchronization device is integrated with a transaction interception function of a transaction interceptor, which can intercept the preset interception transaction at a preset entry point. In this embodiment, the preset entry point can be selected as when an instruction for controlling data changes is detected. The preset interception transaction can be set by the operation and maintenance personnel as needed, and this embodiment does not impose specific restrictions. If the data synchronization device determines that the target transaction controlled by the instruction is a preset interception transaction, the transaction will not be intercepted; if the data synchronization device determines that the target transaction controlled by the instruction is a preset interception transaction, a new data buffer to be synchronized is created for the target transaction. The data buffer to be synchronized is used to temporarily store the change operation data of the target transaction during the transaction execution. To assist understanding, an example is given: the transaction interceptor can be selected as a Spring AOP (Aspect Oriented Programming) interceptor, and the aspect 1 of the interceptor is defined as:

[0093] @Pointcut("target(org.springframework.transaction.PlatformTransactionManager)")

[0094] public void isPlatformTransactionManager(){}

[0095] Section 2 is:

[0096] @Pointcut("execution(org.springframework.transaction.TransactionStatusgetTransaction(org.springframework.transaction.TransactionDefinition)))")

[0097] public void getTransaction(){}

[0098] These two aspects are used to limit the interception conditions of the transaction interceptor for Spring transactions (preset interception transactions and preset entry points).

[0099] Furthermore, before step S20, the following steps are also included:

[0100] Step S21, determining the current change operation according to the instruction, and judging whether the change operation data of the current change operation of the target transaction needs to be synchronized;

[0101] If necessary, execute step S20.

[0102] In this embodiment, since the execution of the target transaction requires calling one or more database interfaces and performing one or more change operations, each change operation generates corresponding change operation data. Sometimes it is not necessary to synchronize data for the target transaction or each change operation of the target transaction. The data synchronization device only puts the change operation data that needs to be synchronized into the data buffer to be synchronized.

[0103] The data synchronization device is integrated with the interface operation interception function of the interface operation interceptor, which can intercept the change operation of calling the database interface after the interface call is completed, that is, the database operation is completed, determine the current change operation, and judge whether the change operation data of the current change operation needs to be synchronized. If it is determined that the change operation data of the current change operation needs to be synchronized, the change operation data that needs to be synchronized for the target transaction is placed in the data buffer to be synchronized; if it is determined that the change operation data of the current change operation of the target transaction does not need to be synchronized, the change operation data that needs to be synchronized for the target transaction is not placed in the data buffer to be synchronized, so as to avoid wasting storage resources.

[0104] Furthermore, step S21 includes:

[0105] Step S211, obtaining the domain type and domain object of the current change operation, and determining whether the domain type and domain object of the current change operation exist in a preset domain table;

[0106] In this embodiment, the domain type refers to the database table definition, that is, the definition of a table in the database; the domain object refers to the table record, that is, a record in a table in the database; the preset domain table is used to store the domain types that need to be synchronized and the domain objects of the domain types that need to be synchronized. Operations and maintenance personnel can set, add or adjust the domain types and domain objects that need to be synchronized in the preset domain table as needed; the preset domain table can be refreshed at a preset frequency to obtain the latest data synchronization settings.

[0107] Specifically, after an interface call is completed, that is, a database operation is completed, the data synchronization device integrated with the interface operation interceptor extracts the target of the operation from the database operation, that is, the domain type and domain object of the current change operation, and then queries whether the type and domain object are stored in the preset domain table.

[0108] Step S212: If the domain type and domain object of the current change operation exist in the preset domain table, determining whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are allowed to be synchronized;

[0109] Step S213: If the corresponding representations of the domain type and domain object of the current change operation in the preset domain table indicate that synchronization is allowed, it is determined that the change operation data of the current change operation of the target transaction needs to be synchronized;

[0110] Step S214: If the domain type and domain object of the current change operation do not exist in the preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are synchronization prohibited, it is determined that the change operation data of the current change operation of the target transaction does not need to be synchronized.

[0111] If the domain type and domain object of the current change operation exist in the preset domain table, it is further queried whether the corresponding representation of the domain type and domain object in the preset domain table allows synchronization. If synchronization is allowed, it is determined that the change operation data of the current change operation of the target transaction needs to be synchronized; if the domain type and domain object of the current change operation do not exist in the preset domain table, or if the domain type and domain object of the current change operation are in the preset domain table but its corresponding representation in the preset domain table prohibits synchronization, it is determined that the change operation data of the current change operation of the target transaction does not need to be synchronized.

[0112] In this embodiment, the change operation of the transaction is intercepted by a preset domain table, so that only the change operation data that needs to be synchronized set by the operation and maintenance personnel is synchronized.

[0113] Furthermore, a third embodiment of the data synchronization method of the present invention is proposed, wherein the above step S30 further includes:

[0114] Step S31, when it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are added to the data synchronization queue;

[0115] In this embodiment, when detecting that the target transaction is successfully executed, the data synchronization device obtains all the changed data of the target transaction in the to-be-synchronized data buffer of the transaction, and puts all the changed data of the target transaction into the data synchronization queue.

[0116] Furthermore, if it is detected that the target transaction fails to execute, data synchronization for the transaction is not performed, and the buffer zone for the data to be synchronized for the transaction is deleted.

[0117] Step S32: Obtain the type of message middleware corresponding to the domain type of the current change operation in the preset domain table;

[0118] After placing all the target transaction's change data into the data synchronization queue, the message middleware type corresponding to the domain type of the current change operation is retrieved from the preset domain table. All the change data in the data synchronization queue is sent to the message middleware of the corresponding type to synchronize the data with the recipient. The message middleware type corresponding to the domain type of the current change operation in the preset domain table is configured by operations and maintenance personnel as needed and is not specifically limited in this embodiment.

[0119] Furthermore, the preset domain table may also include the type of message middleware corresponding to the domain type and the queue name of the message middleware. By setting the queue name of the message middleware, the receiver can locate the location of data changes more quickly to improve data synchronization efficiency.

[0120] Step S33: Send all the change operation data of the target transaction in the data synchronization queue to the corresponding type of message middleware to perform data synchronization.

[0121] Furthermore, before the step of sending all the changed data in the data synchronization queue to the corresponding type of message middleware, it can also include generating a text in a text format (such as JSON or XML, etc.) that can be known to the recipient based on the changed data in the data synchronization queue, and then sending the text to the corresponding type of message middleware for data synchronization.

[0122] Furthermore, the above step S20 includes:

[0123] Converting the change operation data to be synchronized into a preset format according to a preset conversion rule; and placing the change operation data converted into the preset format into the data buffer to be synchronized;

[0124] Furthermore, the step S30 includes:

[0125] When it is detected that the target transaction is executed successfully, the change operation data converted into a preset format in the data buffer to be synchronized is sent to the message middleware to perform data synchronization.

[0126] In this embodiment, the change operation data to be synchronized is converted into a preset format according to preset conversion rules, and the converted change operation data is placed in a data buffer to be synchronized. Converting the change operation data into a unified preset format lays the foundation for improving the efficiency and accuracy of data synchronization. The data buffer to be synchronized is represented by a stack, which consists of one or more linked lists and can be used to buffer the data to be synchronized for the main transaction and subtransactions.

[0127] For example, consider the following nested transaction: Main transaction starts → Executes data change 1 → Main transaction suspends → Subtransaction starts → Executes data change 2 → Subtransaction commits → Main transaction resumes → Executes data change 3 → Main transaction commits. Leveraging the stack's first-in, last-out nature (i.e., the first object placed on the stack is always taken out last), the main transaction's data change 1 is placed on the stack first, followed by the subtransaction's data change 2. If the subtransaction executes successfully, the subtransaction's data change 2 is removed from the stack and placed in the data synchronization queue for synchronization. The main transaction's data change 3 is then placed on the stack. If the main transaction executes successfully, both data change 3 and data change 1 are removed from the stack and placed in the data synchronization queue for synchronization. If the subtransaction fails, data change 2 and data change 1 are removed from the stack.

[0128] This embodiment automatically sends data to different message middleware by setting the type of message middleware corresponding to the domain type in the preset domain table; and lays the foundation for improving the efficiency and accuracy of data synchronization by converting the change operation data into a unified preset format.

[0129] The present invention also provides a data synchronization device.

[0130] Reference Figure 3 , Figure 3 This is a functional module diagram of a first embodiment of a data synchronization device according to the present invention, wherein the data synchronization device comprises:

[0131] The detection module 10 is configured to, upon detecting an instruction for controlling data change, create a new data buffer to be synchronized for a target transaction controlled by the instruction;

[0132] The putting module 20 is used to put the change operation data that needs to be synchronized by the target transaction into the data buffer to be synchronized after the target transaction starts to be executed;

[0133] The synchronization module 30 is configured to send all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when detecting that the target transaction is executed successfully.

[0134] Furthermore, the data synchronization device further includes:

[0135] a judgment module, configured to determine a current change operation according to the instruction, and to judge whether the change operation data of the current change operation needs to be synchronized;

[0136] The putting module is further configured to put the change operation data that needs to be synchronized by the target transaction into the data buffer to be synchronized, if necessary.

[0137] Furthermore, the judgment module further includes:

[0138] a domain table determination unit, configured to obtain the domain type and domain object of the current change operation, and determine whether the domain type and domain object of the current change operation exist in a preset domain table;

[0139] a representation judgment unit, configured to judge whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are allowed to be synchronized if the domain type and domain object of the current change operation exist in the preset domain table;

[0140] a synchronization-allowed determination unit, configured to determine that the change operation data of the current change operation of the target transaction needs to be synchronized if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table indicate that synchronization is allowed;

[0141] A synchronization prohibition determination unit is configured to determine that the change operation data of the current change operation of the target transaction does not need to be synchronized if the domain type and domain object of the current change operation do not exist in a preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are synchronization prohibited.

[0142] Furthermore, the synchronization module further includes:

[0143] an adding unit, configured to add all the change operation data of the target transaction in the to-be-synchronized data buffer to a data synchronization queue when detecting that the target transaction is successfully executed;

[0144] An acquiring unit, configured to acquire a type of message middleware corresponding to a domain type of the current change operation in a preset domain table;

[0145] The sending unit is used to send all the change operation data of the target transaction in the data synchronization queue to the corresponding type of message middleware to perform data synchronization.

[0146] Furthermore, the insert module further includes:

[0147] A conversion unit, configured to convert the change operation data to be synchronized into a preset format according to a preset conversion rule;

[0148] A data putting unit, configured to put the change operation data converted into a preset format into the data buffer to be synchronized;

[0149] The synchronization module is further configured to send the change operation data converted into a preset format in the data buffer to be synchronized to the message middleware for data synchronization when it is detected that the target transaction is executed successfully.

[0150] Furthermore, the data synchronization device further includes:

[0151] The deletion module is used to delete the buffer zone of the data to be synchronized of the target transaction.

[0152] Furthermore, the data synchronization device further includes:

[0153] A transaction determination module, configured to determine whether a target transaction controlled by the instruction is a preset interception transaction;

[0154] The detection module is further configured to create a new data buffer to be synchronized for the target transaction controlled by the instruction if the target transaction controlled by the instruction is a preset interception transaction.

[0155] The specific implementation of the data synchronization device of the present invention is basically the same as the embodiments of the above-mentioned data synchronization method, and will not be repeated here.

[0156] In addition, an embodiment of the present invention further provides a computer-readable storage medium.

[0157] A data synchronization program is stored on the computer-readable storage medium, and when the data synchronization program is executed by the processor, the steps of the data synchronization method described above are implemented.

[0158] The specific implementation of the computer-readable storage medium of the present invention is basically the same as the various embodiments of the above-mentioned data synchronization method, and will not be repeated here.

[0159] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the purpose of the present invention and the claims. Any equivalent structure or equivalent process transformation made using the contents of the description and drawings of the present invention, or directly or indirectly used in other related technical fields, all fall within the protection of the present invention.

Claims

1. A data synchronization method, characterized in that: The data synchronization method is applied to a data synchronization device, and the data synchronization device intercepts a preset interception transaction at a preset entry point. The data synchronization method includes the following steps: When an instruction for controlling data change is detected, determining whether a target transaction controlled by the instruction is a preset interception transaction; if the target transaction controlled by the instruction is a preset interception transaction, creating a new data buffer to be synchronized for the target transaction controlled by the instruction; the data buffer to be synchronized is a stack; After the target transaction starts executing, the change operation data that needs to be synchronized by the target transaction is placed in the data buffer to be synchronized; When it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are sent to the message middleware for data synchronization.

2. The data synchronization method according to claim 1, wherein: Before the step of creating a new data buffer to be synchronized for the target transaction controlled by the instruction, the method further includes: Determining a current change operation according to the instruction, and judging whether the change operation data of the current change operation needs to be synchronized; If necessary, the step of placing the change operation data that needs to be synchronized for the target transaction into the data buffer to be synchronized is executed.

3. The data synchronization method according to claim 2, wherein: The step of determining whether the change operation data of the current change operation needs to be synchronized includes: Obtaining the domain type and domain object of the current change operation, and determining whether the domain type and domain object of the current change operation exist in a preset domain table; If the domain type and domain object of the current change operation exist in the preset domain table, determining whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are allowed to be synchronized; If the corresponding representations of the domain type and domain object of the current change operation in the preset domain table indicate that synchronization is allowed, determining that the change operation data of the current change operation of the target transaction needs to be synchronized; If the domain type and domain object of the current change operation do not exist in the preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are synchronization prohibited, it is determined that the change operation data of the current change operation of the target transaction does not need to be synchronized.

4. The data synchronization method according to claim 3, wherein: The step of sending all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when the target transaction is detected to be executed successfully includes: When it is detected that the target transaction is executed successfully, all the change operation data of the target transaction in the data buffer to be synchronized are added to the data synchronization queue; Obtain the type of the message middleware corresponding to the domain type of the current change operation in the preset domain table; All change operation data of the target transaction in the data synchronization queue are sent to the corresponding type of message middleware to perform data synchronization.

5. The data synchronization method according to claim 3, wherein: The step of placing the target transaction's change operation data that needs to be synchronized into the data buffer to be synchronized comprises: Convert the change operation data that needs to be synchronized into a preset format according to a preset conversion rule; Putting the change operation data converted into a preset format into the data buffer to be synchronized; The step of sending all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when the target transaction is detected to be executed successfully includes: When it is detected that the target transaction is executed successfully, the change operation data converted into a preset format in the data buffer to be synchronized is sent to the message middleware to perform data synchronization.

6. The data synchronization method according to claim 4, wherein: After the step of adding all the change operation data of the target transaction in the to-be-synchronized data buffer to the data synchronization queue when detecting that the target transaction is successfully executed, the method further includes: Delete the data buffer to be synchronized of the target transaction.

7. A data synchronization device, characterized in that: The data synchronization device intercepts the preset interception transaction at a preset entry point, including: A detection module, configured to detect an instruction for controlling data change; A transaction determination module, configured to determine whether a target transaction controlled by the instruction is a preset interception transaction; The detection module is further configured to, if the target transaction controlled by the instruction is a preset interception transaction, create a new data buffer to be synchronized for the target transaction controlled by the instruction; the data buffer to be synchronized is a stack; An insert module is used to insert the change operation data that needs to be synchronized by the target transaction into the data buffer to be synchronized after the target transaction starts executing; The synchronization module is used to send all the change operation data of the target transaction in the data buffer to be synchronized to the message middleware for data synchronization when detecting that the target transaction is executed successfully.

8. The data synchronization device according to claim 7, wherein: The data synchronization device further includes: a judgment module, configured to determine a current change operation according to the instruction, and to judge whether the change operation data of the current change operation needs to be synchronized; The putting module is further configured to put the change operation data that needs to be synchronized by the target transaction into the data buffer to be synchronized, if necessary.

9. The data synchronization device according to claim 8, wherein: The judgment module also includes: a domain table determination unit, configured to obtain the domain type and domain object of the current change operation, and determine whether the domain type and domain object of the current change operation exist in a preset domain table; a representation judgment unit, configured to judge whether the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are allowed to be synchronized if the domain type and domain object of the current change operation exist in the preset domain table; a synchronization-allowed determination unit, configured to determine that the change operation data of the current change operation of the target transaction needs to be synchronized if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table indicate that synchronization is allowed; A synchronization prohibition determination unit is configured to determine that the change operation data of the current change operation of the target transaction does not need to be synchronized if the domain type and domain object of the current change operation do not exist in a preset domain table, or if the corresponding representations of the domain type and domain object of the current change operation in the preset domain table are synchronization prohibited.

10. The data synchronization device according to claim 9, wherein: The synchronization module also includes: an adding unit, configured to add all the change operation data of the target transaction in the to-be-synchronized data buffer to a data synchronization queue when detecting that the target transaction is successfully executed; An acquiring unit, configured to acquire a type of message middleware corresponding to a domain type of the current change operation in a preset domain table; The sending unit is used to send all the change operation data of the target transaction in the data synchronization queue to the corresponding type of message middleware to perform data synchronization.

11. The data synchronization device according to claim 9, wherein: The insert module also includes: A conversion unit, configured to convert the change operation data to be synchronized into a preset format according to a preset conversion rule; A data putting unit, configured to put the change operation data converted into a preset format into the data buffer to be synchronized; The synchronization module is further configured to send the change operation data converted into a preset format in the data buffer to be synchronized to the message middleware for data synchronization when it is detected that the target transaction is executed successfully.

12. The data synchronization device according to claim 10, wherein: The data synchronization device further includes: The deletion module is used to delete the buffer zone of the data to be synchronized of the target transaction.

13. A data synchronization device, characterized in that: The data synchronization device includes a memory, a processor, and a data synchronization program stored in the memory and executable on the processor. When the data synchronization program is executed by the processor, the steps of the data synchronization method according to any one of claims 1 to 6 are implemented.

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

15. A computer program product, characterized in that The computer program product stores instructions, and when a computer reads and executes the instructions, the computer executes the steps of the data synchronization method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data synchronous updating method and device

    CN103595807A

  • Distributed transaction management method, distributed transaction management device, distributed transaction management system and storage medium

    CN108845867A

  • Data synchronization method, apparatus, storage medium, and electronic apparatus

    CN109241175A