Parallel execution method, device and system based on transaction operation dependency relationship

By determining the dependencies between transaction operations in the target-side data synchronization service and using a hash table to judge conflicts, the problem of low parallelism in the prior art is solved, and more efficient data synchronization performance is achieved.

CN119473521AActive Publication Date: 2025-02-18WUHAN DAMENG DATABASE
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411636660.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-02-18
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

In the prior art data synchronization service on the target side, the transaction commit sequence used when transactions are concurrently entered into the database, resulting in a large granularity of detection of conflicts and low parallelism, which affects the data synchronization performance.

Method used

By determining the dependencies between transaction operations, clarify which transactions you need to wait for when synchronizing operations, use a hash table-based method to judge the conflicts between operations, and maximize the parallelism of transaction execution.

Benefits of technology

It effectively improves the parallelism and performance of data synchronization, reduces the time to wait for conflicting transactions, and improves the system's processing capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473521A_ABST
    Figure CN119473521A_ABST
Patent Text Reader

Abstract

The invention relates to a parallel execution method, device and system based on a transaction operation dependency relationship. The method mainly comprises the following steps of: extracting an operation of a transaction by a working thread, judging whether the current operation is a submission operation or not, if so, waking up to wait for the working thread after submitting the current transaction; otherwise, acquiring a conflict TRXID and a conflict LSN stored in the operation, and performing conflict detection of the operation: searching whether a transaction of the conflict TRXID exists in a hash table P by using the conflict TRXID of the current operation to be executed, and if the transaction of the conflict TRXID exists, waiting to wake up the user; otherwise, the working thread uses the current to-be-executed operation table information to search whether a transaction for operating the same table exists in the hash table G or not, the submission LSN of the transaction is smaller than that of the current transaction, and the initial LSN of the transaction is smaller than the conflict LSN of the current operation, and if yes, the working thread waits to be awakened; otherwise, executing the current operation. According to the method, the concurrency of operation execution can be effectively increased, and the purpose of improving the synchronization performance is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a parallel execution method, device and system based on transaction operation dependency. Background Art

[0002] In the database real-time synchronization system (supporting heterogeneity) based on the log parsing architecture, the source-side data synchronization service is responsible for capturing the operation log of the source-side database, parsing the log and restoring the corresponding database operations, and then sending them to the target-side data synchronization service. The target-side data synchronization service is responsible for executing these operations in the target-side database, thereby completing the data synchronization process.

[0003] When the target-side data synchronization service performs synchronization operations on the target-side database, it needs to execute concurrently according to the dependency relationship of transaction operations. Conflicting transaction operations need to wait for the conflicting transaction to be executed and committed before they can start to execute. The target-side data synchronization service currently uses the transaction submission order to construct dependency relationships to achieve concurrency when concurrently storing transactions. The first submitted transaction is executed first, and the later submitted transaction is executed later. Although this method of parallel execution based on transaction submission order improves performance, the granularity of conflict detection is large and not delicate enough, resulting in low parallelism.

[0004] In view of this, how to overcome the defects of the existing technology and how to improve the parallel execution of the target-side data synchronization service to improve the performance of data synchronization have become important technical issues that need to be urgently solved in the industry. Summary of the invention

[0005] In view of the defects or improvement needs in the prior art: how to improve the parallel execution strength of the target-side data synchronization service to improve the performance of data synchronization. The present invention believes that if the dependency relationship between transaction operations can be determined, it can be clear which transactions need to be waited for during the synchronization operation, and the parallelism of synchronization can be maximized. Based on this, the present invention provides a parallel execution method, device and system based on transaction operation dependencies. The method receives synchronization transaction operations in the order in which the source-side database logs are generated. The order of each received operation is the basis for detecting whether there is a conflict. The transaction relationship that it depends on is determined for each currently received operation according to this order of reception. When the operation is executed, it is judged whether it conflicts with the currently executing transaction based on the transaction relationship that the operation depends on, thereby maximizing the parallelism of transaction execution, thereby effectively improving the performance of synchronization.

[0006] The present invention adopts the following technical solution:

[0007] In a first aspect, the present invention provides a parallel execution method based on transaction operation dependency, comprising:

[0008] The target-side data synchronization service creates hash table P, hash table G, and several worker threads;

[0009] The worker thread extracts a transaction from the committed transaction list in the order of transaction submission, registers the transaction ID into the hash table P, and registers the table information involved in the transaction and the transaction start LSN into the hash table G;

[0010] The working thread extracts an operation of the transaction and determines whether the current operation is a commit operation. If so, it commits the current transaction and wakes up the waiting working thread, and then removes the registration information of the current transaction from hash tables P and G; otherwise, it obtains the conflict TRXID and conflict LSN saved in the operation and performs conflict detection of the operation: uses the conflict TRXID of the current operation to be executed to search in hash table P whether there is a transaction with the conflict TRXID. If so, it waits for the conflicting transaction to be executed and committed before waking itself up; otherwise, the working thread uses the information of the current operation table to be executed to search in hash table G whether there is a transaction operating the same table, and the commit LSN of this transaction is smaller than the current transaction, and the start LSN of the transaction is smaller than the conflict LSN of the current operation. If so, it waits for the conflicting transaction to be executed and committed before waking itself up; otherwise, it is determined that no conflict is detected and the current operation is executed.

[0011] In some embodiments, when the target-side data synchronization service is started, a hash table R is initialized, and the record address in the hash item of the hash table R is initialized to empty, which is used to store and locate the received operations; the target-side data synchronization service creates two memory slices to store the KEY in the hash table R, and the version number of each memory slice is incremented in the order of creation, and the two memory slices are added to the memory linked list.

[0012] In some embodiments, obtaining the conflicting TRXID and the conflicting LSN includes:

[0013] After receiving the DML operation from the source, the target data synchronization service extracts the MD5 value calculated by the source in the operation as the KEY, and then extracts the transaction ID in the operation as the TRXID, and combines the KEY and TRXID into a record and saves it in the current memory slice. If the record is the first record of the current memory slice, the log LSN corresponding to the operation is marked on the memory slice as the starting LSN of the memory slice.

[0014] Use the current operation's KEY to construct a detection record X, merge the detection record X into the hash table R, and perform conflict detection and judgment during the merging process. If there is a conflicting KEY, return the TRXID value corresponding to the conflicting KEY; otherwise, return 0 as the corresponding TRXID, indicating no conflict;

[0015] The TRXID obtained by the conflict detection is set as the conflict TRXID, and the starting LSN of the first memory slice in the memory linked list corresponding to the current hash table R is written into the current operation and set as the conflict LSN.

[0016] In some embodiments, the conflict detection determination includes:

[0017] Calculate the hash value of the KEY of the current detection record X, and locate the hash item through the hash value; determine whether the record address in the hash item is empty. If so, set the record address in the hash item to the next address space of the current detection record X, and fill the address of the detection record X back into the hash item, and return 0 as the conflict TRXID, indicating that no conflict is detected; if not, proceed to the next step of conflict detection and judgment;

[0018] Determine whether the memory chip version number K in the address recorded in the hash item is less than the version number K value of the first memory chip in the memory linked list. If so, it indicates that this record Y has exceeded the inspection range. Set the address recorded in the hash item to the next address space of the current detection record X, and fill the address of the detection record X back into the hash item. Use 0 as the conflict TRXID to return, indicating that no conflict is detected; if not, proceed to the next step of conflict detection judgment;

[0019] According to the address recorded in the hash item, the corresponding record Y is loaded from the memory chip, and it is determined whether the KEY of record Y is equal to the KEY of the current detection record X and the TRXID of record Y is not equal to the TRXID of the current operation. If so, it means that there is a conflict in the operation, and record Y is removed from the record linked list of the hash item to shorten the length of the linked list in the hash item, and the record address in the hash item is set to the next address space of the current detection record X, and the address of the current detection record X is backfilled into the hash item, and the TRXID stored in record Y is used as the conflicting TRXID for return; if not, the next step of conflict detection and judgment is carried out;

[0020] Traverse the next record of record Y in sequence and perform conflict detection and judgment until the end of the record linked list.

[0021] In some embodiments, the calculation of the MD5 value includes: generating an MD5 value based on the table ID and primary key, or the table ID and unique index information, or the table ID and a custom selected column in the DML operation.

[0022] In some embodiments, the memory linked list includes two memory slices. When the first memory slice is full, it switches to the second memory slice. When the second memory slice is full, the first memory slice in the linked list is eliminated first, and then a new memory slice is created with an incremented version number and added to the linked list.

[0023] In some embodiments, when the target-side data synchronization service receives a rollback or partial rollback operation, the conflicting TRXID saved in the rolled-back operation is written back to the hash table R for conflict detection; specifically:

[0024] Locate the transaction that needs to be rolled back using the transaction ID of the rollback or partial rollback operation, and extract the number of rows included in the transaction in the rollback operation or the number of rows that need to be rolled back in the partial rollback operation;

[0025] Extract the rollback operation from the tail of the transaction operation linked list, and extract the KEY value, conflicting TRXID, and conflicting LSN saved in the operation;

[0026] Compare the conflicting LSN of the operation with the starting LSN of the first memory slice. If it is smaller than the starting LSN, terminate the writeback of the rollback operation to the hash table R; otherwise, search for the conflicting operation record with the same KEY in the hash table R according to the KEY of the operation. If not found, terminate the writeback of the rollback operation to the hash table R; otherwise, write the conflicting TRXID back to the record in the hash table R, and continue to extract the previous operation to be rolled back for the same writeback until the specified number of rows is rolled back.

[0027] In a second aspect, the present invention further provides a parallel execution device based on transaction operation dependency, the device comprising:

[0028] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to execute the parallel execution method based on transaction operation dependencies described in the first aspect.

[0029] In a third aspect, the present invention further provides a parallel execution system based on transaction operation dependencies, applying the parallel execution method based on transaction operation dependencies as described in the first aspect, the system includes a hash table and worker thread creation module, a transaction extraction module, and an operation extraction and conflict detection module, wherein:

[0030] The hash table and worker thread creation module is used to create a hash table P, a hash table G and several worker threads through the target end data synchronization service;

[0031] The transaction extraction module is used to extract a transaction from the committed transaction linked list according to the transaction submission order through a working thread, and register the transaction ID into a hash table P, and register the table information involved in the transaction and the start LSN of the transaction into a hash table G;

[0032] The operation extraction and conflict detection module is used to extract an operation of a transaction through a working thread, determine whether the current operation is a commit operation, and if so, wake up the waiting working thread after committing the current transaction, and then remove the registration information of the current transaction from the hash table P and the hash table G; otherwise, obtain the conflict TRXID and conflict LSN saved in the operation, and perform conflict detection of the operation: use the conflict TRXID of the current operation to be executed to search whether there is a transaction with the conflict TRXID in the hash table P, if so, wait for the conflicting transaction to be executed and committed before waking itself up; otherwise, the working thread uses the information of the current operation table to be executed to search whether there is a transaction operating the same table in the hash table G, and the commit LSN of this transaction is smaller than the current transaction, and the start LSN of the transaction is smaller than the conflict LSN of the current operation, if so, wait for the conflicting transaction to be executed and committed before waking itself up; otherwise, it is determined that no conflict is detected and the current operation is executed.

[0033] In a fourth aspect, the present invention further provides a non-volatile computer storage medium, wherein the computer storage medium stores computer executable instructions, which are executed by one or more processors to complete the parallel execution method based on transaction operation dependencies described in the first aspect.

[0034] Compared with the prior art, the present invention provides a parallel execution method, device and system based on transaction operation dependency, which has the following beneficial effects:

[0035] First, perform conflict detection on the operation within a fixed LSN interval, and save the detection results and LSN interval to the corresponding operation. When the working thread executes the operation, it searches for conflicting transactions in the current parallel transaction based on the conflicting transaction information saved in the operation. If so, it cannot be executed. Otherwise, it is necessary to search for transactions involving the same table as the operation based on the conflicting LSN saved in the operation, and the transaction whose start LSN is smaller than the conflicting LSN and whose commit LSN is smaller than the commit LSN of the transaction to which the current operation belongs. If so, it will not be executed and needs to wait until these transactions are completed before it can be executed; otherwise, it can be executed immediately without waiting for the transaction submitted before itself to be completed, effectively increasing the concurrency of operation execution and achieving the purpose of improving synchronization performance.

[0036] Secondly, when a partial rollback or rollback operation is received, the dependencies of the rolled back transaction operations will be written back into the conflict detection HASH table, so that it will not affect the conflict detection of subsequent operations, and each transaction that the operation depends on is a clear committed transaction.

[0037] Finally, when a transaction is committed, since all operations of the transaction have been conflict-checked during execution, transactions that conflict with the current transaction must have been committed. There is no need to worry about partially rolled back or rolled back transactions. When the current transaction is committed synchronously, it does not need to wait for transactions that were committed before it, which further improves synchronization performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0039] Figure 1 A flowchart of a parallel execution method based on transaction operation dependency provided in Example 1 of the present invention;

[0040] Figure 2 A flow chart of obtaining conflicting TRXIDs and conflicting LSNs provided in Example 1 of the present invention;

[0041] Figure 3 A flowchart of conflict detection and judgment provided in Example 1 of the present invention;

[0042] Figure 4 A flowchart of receiving a rollback operation provided in Example 1 of the present invention;

[0043] Figure 5 A module diagram of a parallel execution system based on transaction operation dependency provided in Example 1 of the present invention;

[0044] Figure 6 A schematic diagram of the structure of a parallel execution device based on transaction operation dependency provided in Example 3 of the present invention. DETAILED DESCRIPTION

[0045] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but do not limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, without departing from the concept of the present invention, several variations and improvements can also be made. These all belong to the protection scope of the present invention. It should be noted that, if there is no conflict, the various features in the embodiments of the present invention can be combined with each other, all within the protection scope of this application. In addition, although the functional module division may be performed in the device schematic diagram, and the logical order may be shown in the flow chart, in some cases, it may be different from the module division in the device, or the steps shown or described in the order in the flow chart may be performed.

[0046] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in this specification and in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. In addition, the technical features involved in each embodiment of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0047] Unless the context requires otherwise, throughout the specification and claims, the term "including" is to be interpreted as open inclusion, that is, "including, but not limited to". In the description of the specification, the terms "one embodiment", "some embodiments", "exemplary embodiments", "examples", "specific examples" or "some examples" and the like are intended to indicate that specific features, structures, materials or characteristics associated with the embodiment or example are included in at least one embodiment or example of the present disclosure. The schematic representation of the above terms does not necessarily refer to the same embodiment or example. In addition, the specific features, structures, materials or characteristics may be included in any one or more embodiments or examples in any appropriate manner, that is, although they may be carried in the embodiments or examples of the above terms due to reasons such as the order and position of appearance, it is not limited to that they can be carried in combination by one embodiment or example.

[0048] In order to make the purpose, technical scheme and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. The present invention is described in detail below with reference to the accompanying drawings and embodiments.

[0049] Embodiment 1:

[0050] like Figure 1 As shown, an embodiment of the present invention provides a parallel execution method based on transaction operation dependency, and the method includes the following steps.

[0051] Step 100: The target end data synchronization service creates hash table P, hash table G and several working threads. In this embodiment, LSN is the log sequence number; TRXID is the id that identifies a transaction; DML is the insert, update and delete operations of data; MD5 is a widely used cryptographic hash function that can generate a 128-bit (16-byte) hash value (hashvalue) to ensure the integrity and consistency of information transmission; KEY is a key that can be used to identify a specific row of records in the table; ROWID is a pseudo column used to uniquely mark rows in the table.

[0052] Step 200: The working thread extracts a transaction from the committed transaction linked list in the transaction commit order, and registers the transaction ID into the hash table P, and registers the table information involved in the transaction and the start LSN of the transaction into the hash table G.

[0053] Step 300: The working thread extracts an operation of the transaction and determines whether the current operation is a commit operation. If so, it commits the current transaction and wakes up the waiting working thread, and then removes the registration information of the current transaction from the hash table P and the hash table G. Otherwise, it obtains the conflict TRXID and conflict LSN saved in the operation and performs conflict detection of the operation: it uses the conflict TRXID of the current operation to be executed to search whether there is a transaction with the conflict TRXID in the hash table P. If so, it waits for the conflicting transaction to be executed and committed before waking itself up. Otherwise, the working thread uses the information of the current operation table to be executed to search whether there is a transaction operating the same table in the hash table G, and the commit LSN of this transaction is smaller than the current transaction, and the start LSN of the transaction is smaller than the conflict LSN of the current operation. If so, it waits for the conflicting transaction to be executed and committed before waking itself up. Otherwise, it is determined that no conflict is detected and the current operation is executed.

[0054] The target-side data synchronization service of the embodiment of the present invention marks the received operations with the transaction information on which the operation conflicts and the conflict LSN value of the dependency detection. When the operation is executed, conflict detection is performed based on the conflict transaction information attached to the operation. If no conflicting transaction is detected being executed, and no transaction is detected in the running transaction whose commit LSN is smaller than the commit LSN of the transaction to which the current operation belongs and whose transaction start LSN is smaller than the conflict LSN of the current operation, then the operation can be executed in parallel with the operation submitted before itself, without waiting for the synchronization of the transaction submitted before itself to be completed, thereby improving the synchronization performance.

[0055] This embodiment will now explain the above method in more detail.

[0056] In one embodiment, a synchronization system needs to be deployed on the source database and the target database. The source database synchronization system reads logs from the source database and parses them into operations. An MD5 value is jointly generated according to the table ID and primary key, or the table ID and unique index information, or the table ID and the custom selected column in the DML operation as the KEY of the operation. The target database synchronization system is responsible for classifying and collecting the synchronization operations sent from the source by transaction, and using the KEY of each received operation to set its dependency with the conflicting transaction received before it.

[0057] When calculating the KEY of an operation, since the order of columns in the operation parsed from the log is not fixed, you must first sort the columns in the operation by column ID, and then calculate the KEY according to the fixed order of the primary key or unique index combination columns.

[0058] The data synchronization service on the source side detects conflicts for each operation and can calculate the MD5 value of the conflict more accurately. If the data synchronization service on the target side calculates the MD5 value, if the primary key structure or column order of the target database table is inconsistent with that on the source side, then the MD5 value calculated by describing the primary key information of the target table will have errors.

[0059] In one embodiment, when the target-side data synchronization service is started, a hash table R is initialized, and the record address in the hash item of the hash table R is initialized to be empty, which is used to store and locate the received operation; the target-side data synchronization service creates two memory slices to store the KEY in the hash table R, and the memory of each memory slice is incremented in the order of creation, and the two memory slices are added to the memory linked list. Among them, the size of the hash table R can be set to N, and the size of each memory slice is set to M, that is, each memory slice is a memory space of size M.

[0060] For hash table R, the structure of the HASH item in its HASH table is a 4-byte version number, set to K; a 4-byte memory offset, set to F; K and F constitute a HASH item in the HASH table, as shown in the following table:

[0061] Version number (K) Memory offset (F)

[0062] It means that the first KEY in the HASH item is stored in the memory slice with version number K, and its offset in the memory slice is F.

[0063] In one embodiment, after the source-side data synchronization service captures a DML log operation, it obtains the table ID in the log, and obtains the primary key information and unique index of the table in the source-side database through the table ID.

[0064] In one embodiment, after parsing the current DML log operation, the source-side data synchronization service determines whether the table has a primary key or unique index. If so, the table ID and the column value of the primary key or unique index are combined to calculate an MD5 value as the KEY of this operation, which is stored in the current DML log operation and sent to the target-side synchronization service; if not, proceed to the next step. It should be noted that when a table has both a primary key and a unique index, the table ID and the primary key are preferably combined to calculate the MD5 value as the KEY; when a table has no primary key but has multiple unique indexes, the table ID and any unique index are selected to jointly calculate the MD5 value.

[0065] In one embodiment, when there is no primary key and unique index, after parsing the current DML log operation, the source-side data synchronization service combines the table ID and the ROWID value of the row data or the custom selected column to calculate an MD5 value as the KEY of this operation, which is stored in the current DML log operation and sent to the target-side synchronization service. It should be noted that when calculating the KEY for a table without a primary key or unique constraint, if it is clearly known that all columns of the table have no duplicate values ​​when combined, the ROWID of the table can be directly used to calculate the KEY, which can effectively reduce the cost of calculating the KEY; if there are duplicate rows in the table, it is necessary to use the custom selected column method to calculate the KEY, and which columns or all column values ​​to use to calculate the KEY can be selected based on the distribution of column values. In this way, the target-side synchronization service can use the KEY to prevent deadlocks caused by concurrently executed synchronization transactions operating rows with duplicate values ​​at the same time.

[0066] refer to Figure 2 As shown, in one embodiment, obtaining the conflicting TRXID and the conflicting LSN includes the following steps.

[0067] Step 101: After the target-side data synchronization service receives the DML operation from the source, it extracts the MD5 value calculated by the source in the operation as the KEY, and then extracts the transaction ID in the operation as the TRXID, and combines the KEY and TRXID into a record and saves it in the current memory slice. If the record is the first record in the current memory slice, the log LSN corresponding to the operation is marked on the memory slice as the starting LSN of the memory slice, which is also the conflicting LSN of the operation in the memory slice.

[0068] In the above steps, the target data synchronization service combines KEY and TRXID into a record and saves it to the offset F of the memory slice with the current version number K. Since the hash record needs to save the address of the next record, the record saved in the memory slice also needs to reserve the address of the next record, as shown in the following table.

[0069] KEY TRXID Next record memory chip version (K) Next record memory slice offset (F)

[0070] Step 102: Use the KEY of the current operation to construct a detection record X, merge the detection record X into the hash table R, and perform conflict detection and judgment during the merging process. If there is a conflicting KEY, return the TRXID value corresponding to the conflicting KEY; otherwise, return 0 as the corresponding TRXID, indicating no conflict.

[0071] Step 103: Set the TRXID obtained by conflict detection as the conflict TRXID, write the starting LSN of the first memory slice in the memory linked list corresponding to the current hash table R into the current operation, and set it as the conflict LSN, thereby obtaining the conflict information of this operation.

[0072] Based on the above steps, the target end data synchronization service receives the next message and saves it to the memory slice K in the manner of step 101. The memory linked list includes two memory slices. When the first memory slice is full (the written data exceeds the set size M), it switches to the second memory slice. When the second memory slice is full, the first memory slice in the linked list is eliminated first, and then a new memory slice is created with an increasing version number K and added to the linked list. When a record is saved to a new memory slice, if it is the first record in the memory slice, the operation LSN corresponding to the record should be marked as the starting LSN of the memory slice.

[0073] refer to Figure 3 As shown, in one embodiment, the conflict detection and judgment in the above step 102 specifically includes the following steps.

[0074] Step 201: Calculate the hash value of the KEY of the current detection record X, and locate the hash item through the hash value; determine whether the record address in the hash item is empty. If so, set the record address in the hash item to the next address space of the current detection record X, and fill the address of the detection record X back into the hash item, and return 0 as the conflict TRXID, indicating that no conflict is detected; if not, proceed to the next step of conflict detection judgment.

[0075] Step 202: Determine whether the memory chip version number K in the address recorded in the hash item is less than the version number K value of the first memory chip in the memory linked list. If so, it indicates that this record Y has exceeded the inspection range. The record address in the hash item is set to the next address space of the current detection record X, and the address of the detection record X is backfilled into the hash item. 0 is returned as the conflict TRXID, indicating that no conflict is detected; if not, proceed to the next step of conflict detection judgment.

[0076] Step 203: Load the corresponding record Y from the memory chip according to the address recorded in the hash item, and determine whether the KEY of record Y is equal to the KEY of the current detection record X and the TRXID of record Y is not equal to the TRXID of the current operation. If so, it means that there is a conflict in the operation, remove record Y from the record linked list of the hash item to shorten the length of the linked list in the hash item, set the record address in the hash item to the next address space of the current detection record X, fill the address of the current detection record X back into the hash item, and return the TRXID stored in record Y as the conflicting TRXID; if not, proceed to the next step of conflict detection judgment.

[0077] Step 204: traverse the next record of record Y in sequence and perform conflict detection and judgment until the record list ends. The condition for the end of the list is: the version number in the next record address of the record is less than the version number of the first memory slice in the current cache list, or the version number in the next record address is empty.

[0078] refer to Figure 4 In one embodiment, when the target-side data synchronization service receives a rollback or partial rollback operation, the conflicting TRXID saved in the rolled-back operation is written back to the hash table R for conflict detection; specifically, the following steps are included.

[0079] Step 301: Locate the transaction that needs to be rolled back by using the transaction ID of the rollback or partial rollback operation, and extract the number of rows included in the transaction in the rollback operation or the number of rows that need to be rolled back in the partial rollback operation.

[0080] Step 302: Extract the rollback operation from the tail of the transaction operation linked list, and extract the KEY value, conflicting TRXID and conflicting LSN saved in the operation.

[0081] Step 303: Compare the conflicting LSN of the operation with the starting LSN of the first memory slice. If it is smaller than the starting LSN, terminate the write back of the rollback operation to the hash table R; otherwise, search for the conflicting operation record with the same KEY in the hash table R according to the KEY of the operation. If not found, terminate the write back of the rollback operation to the hash table R; otherwise, write the conflicting TRXID back to the record in the hash table R, and continue to extract the previous operation to be rolled back for the same write back until the specified number of rows is rolled back.

[0082] By writing back the conflicting TRXID information in the rollback operation, the continuity problem of operation conflict detection can be solved. These rolled back operations can be directly discarded. Otherwise, when the transaction is executed, although the partially rolled back operations do not need to be executed, conflict detection is still required during execution. Otherwise, other transaction operations that depend on it will not be able to find the dependent conflicting transactions and will be executed in advance, resulting in inconsistent data.

[0083] In one embodiment, when the system restarts after a failure, the conflict detection mechanism will be reset, and the operations received again will not be executed in parallel with the operations before the failure. It should be noted that after the target end data synchronization service is restarted, the newly received operation LSN will be greater than the LSN of the operation before the failure, so the detection range of subsequent operations will be limited to after the LSN, that is, the transactions received after the failure will not be executed in parallel with the transactions before the failure.

[0084] In one embodiment, the target-side data synchronization service creates H working threads, executes transactions in order of the size of the submitted LSN of the received transactions, and stores the transaction operations. It should be noted that the target-side data synchronization service also needs to create a hash table P to register the transaction information (transaction ID) currently being executed, and create a hash table G to register the table information of the current transaction and the start LSN of the transaction.

[0085] In one embodiment, the working thread extracts a transaction from the committed transaction linked list according to the transaction commit order, registers the transaction ID into the hash table P, and registers the table information involved in the transaction and the start LSN of the transaction into the hash table G.

[0086] In one embodiment, the worker thread extracts an operation of the transaction and determines whether the current operation is a commit operation. If so, the worker thread that is waiting for itself wakes up after committing the current transaction, removes the registration information of the current transaction from the hash table P and the hash table G, and completes the execution of the current transaction; otherwise, the conflicting TRXID and conflicting LSN saved in the operation are obtained. It should be noted that since the transaction that each operation on the transaction depends on has been determined in the conflict detection, the transaction can be directly committed after executing all operations (indicating that the transactions it depends on have been committed), without waiting for the transaction submitted before itself to be committed first, thereby effectively improving the synchronization performance.

[0087] In one embodiment, the working thread uses the conflicting TRXID of the current operation to be executed to search whether there is a transaction with the conflicting TRXID in the hash table P. If there is, the current execution process is suspended, and the conflicting transaction is woken up after being executed and submitted; otherwise, it jumps to the next step. It should be noted that the existence of a transaction with the conflicting TRXID in the hash table P indicates that the data involved in the current operation and the transaction with the conflicting TRXID are in conflict, and the current operation cannot be executed in parallel with the conflicting transaction, and the conflicting transaction needs to be submitted before it can be executed.

[0088] In one embodiment, the working thread uses the information of the current pending operation table to search in the hash table G whether there is a transaction operating the same table, and the transaction commit LSN is smaller than the current transaction, and the transaction start LSN is smaller than the conflict LSN of the current operation. If there is, the current execution process is suspended, and the conflicting transaction is awakened after it is executed and committed; otherwise, it is determined that the conflict detection of the current pending operation of the working thread does not detect a conflict, then the current operation is executed, and then the next operation is continued. It should be noted that this step is mainly to check whether there is a transaction beyond the conflict check LSN range in the current concurrently executed transaction, because the conflict transaction information on the pending operation has a valid interval range, that is, the conflict transaction information is only valid within the interval from the conflict LSN saved in the operation to the current operation LSN, and the operation does not perform conflict detection on the operation before the conflict LSN. That is to say, when there is a transaction whose commit LSN is smaller than the commit LSN of the transaction to which the current pending operation belongs, and the transaction start LSN is smaller than the conflict LSN saved by the current pending operation, it is unknown whether the operation on this transaction conflicts with the current pending operation, so the current pending operation cannot be executed rashly, and it needs to wait until the transaction is committed before it can be executed.

[0089] Based on the above process, this embodiment proposes to provide a parallel execution method based on transaction operation dependencies, which mainly performs conflict detection on operations within a fixed LSN interval, and saves the detection results and the LSN interval to the corresponding operations. When the working thread executes the operation, it can use the conflicting transaction information saved on the operation and its detection LSN interval to determine whether there is a conflict in the current concurrently executed transaction, thereby improving the parallel execution capability.

[0090] refer to Figure 5As shown, the present embodiment further provides a parallel execution system based on transaction operation dependency, applying the aforementioned parallel execution method based on transaction operation dependency, the system includes a hash table and worker thread creation module, a transaction extraction module and an operation extraction and conflict detection module, wherein: the hash table and worker thread creation module is used to create a hash table P, a hash table G and a plurality of worker threads through a target end data synchronization service; the transaction extraction module is used to extract a transaction from a committed transaction linked list in a transaction commit sequence through a worker thread, and register the transaction ID to the hash table P, and register the table information involved in the transaction and the starting LSN of the transaction to the hash table G; the operation extraction and conflict detection module is used to extract an operation of the transaction through a worker thread, determine whether the current operation is a commit operation, and if so, , then after committing the current transaction, wake up the waiting working thread, and then remove the registration information of the current transaction from hash table P and hash table G; otherwise, obtain the conflict TRXID and conflict LSN saved in the operation, and perform conflict detection of the operation: use the conflict TRXID of the current operation to be executed to search whether there is a transaction with the conflict TRXID in hash table P. If so, wait for the conflicting transaction to be executed and committed before waking itself up; otherwise, the working thread uses the current operation table information to search in hash table G whether there is a transaction operating the same table, and the transaction commit LSN is smaller than the current transaction, and the transaction start LSN is smaller than the conflict LSN of the current operation. If so, wait for the conflicting transaction to be executed and committed before waking itself up; otherwise, judge that no conflict is detected and execute the current operation. The specific functions and principles of the system function module correspond to the specific methods in the method part, and will not be repeated here.

[0091] In summary, this embodiment proposes to provide a parallel execution method and system based on transaction operation dependency, including the following advantages: First, conflict detection is performed on the operation within a fixed LSN interval, and the detection result and the LSN interval are saved in the corresponding operation. When the working thread executes the operation, it searches for conflicting transactions in the current parallel execution transaction according to the conflicting transaction information saved in the operation. If so, it cannot be executed. Otherwise, it is also necessary to search for transactions involving the same table as the operation according to the conflicting LSN saved in the operation, and the transaction whose start LSN is smaller than the conflicting LSN and whose commit LSN is smaller than the commit LSN of the transaction to which the current operation belongs. If so, it will not be executed, and it is necessary to wait for these transactions to be executed before it can be executed; otherwise, it can be executed immediately without waiting for the transaction submitted before itself to be executed, effectively increasing the concurrency of operation execution and achieving the purpose of improving synchronization performance.

[0092] Secondly, when a partial rollback or rollback operation is received, the dependencies of the rolled back transaction operations will be written back into the conflict detection HASH table, so that it will not affect the conflict detection of subsequent operations, and each transaction that the operation depends on is a clear committed transaction.

[0093] Finally, when a transaction is committed, since all operations of the transaction have been conflict-checked during execution, transactions that conflict with the current transaction must have been committed. There is no need to worry about partially rolled back or rolled back transactions. When the current transaction is committed synchronously, it does not need to wait for transactions that were committed before it, which further improves synchronization performance.

[0094] Embodiment 2:

[0095] Based on the parallel execution method based on transaction operation dependency provided in the above-mentioned embodiment 1, embodiment 2 of the present invention provides a specific example for illustration.

[0096] For example: The source database has table T (ID INT PRIMARY KEY, C1 INT);

[0097] The source application has three transactions that perform the following operations on table T in the following order:

[0098] TRX1:INSERT INTO T(ID,C1)VALUES(1,1);

[0099] TRX1:COMMIT;

[0100] TRX2:INSERT INTO T(ID,C1)VALUES(2,2);

[0101] TRX2:UPDATE T SET C1=1WHERE ID=1;

[0102] TRX2:COMMIT;

[0103] TRX3:INSERT INTO T(ID, C1)VALUES(3, 3);

[0104] TRX3:COMMIT;

[0105] The order of the above operations represents the order of these operations in the log stream, and the resulting log stream will form the following numbered table:

[0106]

[0107]

[0108] After the target data synchronization service is started, a hash table R of size N and two memory slices of size M are initialized. The version numbers of the memory slices are incremented to 1 and 2.

[0109] The process is as follows:

[0110] 1. When parsing logs, the source-side data synchronization service needs to first obtain the primary key information C column of the table through the table ID, and then calculate the KEY of each operation after parsing the log operations based on the combination of the table ID and the C column value. For the convenience of presentation, the primary key value is used to represent the MD5 value of the KEY in the following table.

[0111] Transaction ID operate LSN Number KEY TRX1 INSERT INTO T(ID,C1)VALUES(1,1); 1 1 TRX1 COMMIT; 2 TRX2 INSERT INTO T(ID,C1)VALUES(2,2); 3 2 TRX2 UPDATE T SET C1=1WHERE ID=1; 4 1 TRX2 COMMIT; 5 TRX3 INSERT INTO T(ID,C1)VALUES(3,3); 6 3 TRX3 COMMIT; 7

[0112] 2. The log receiving thread receives the operation with LSN 1, extracts its KEY as 1, combines the TRXID and the space of the next record to make the length 32, and first stores its KEY and transaction ID in the first memory slice, expressed as [version number (K): memory offset (F)], and its offset in the memory slice is [1:0].

[0113] KEY:1TRXID:1NEXT:empty

[0114] Since the KEY information is the first operation information of the current memory slice, the LSN value of the operation should be set to the starting LSN of the memory slice, and the starting LSN of the memory slice should be set to 1.

[0115] 3. Insert the KEY into the hash table R. The returned TRXID is 0, indicating no conflict. The TRXID 0 indicating no conflict and the minimum starting LSN of the memory slice 1 are written back into the operation.

[0116] 4. The log receiving thread receives the operation with LSN 3, extracts its KEY 2, and combines the TRXID and the space of the next record to make the length 32. First, store its KEY and transaction ID in the first memory slice. Its offset in the memory slice is [1:32].

[0117] KEY:1TRXID:1NEXT:empty KEY:2TRXID:2NEXT:null

[0118] 5. Insert the KEY into the hash table R. The returned TRXID is 0, indicating no conflict. The TRXID 0 indicating no conflict and the minimum starting LSN of the memory slice 1 are written back into the operation.

[0119] 6. The log receiving thread receives the operation with LSN 4, extracts its KEY as 1, combines the TRXID and the space of the next record to make the length 32, and first stores its KEY and transaction ID in the first memory slice. Its offset in the memory slice is [1:64].

[0120] KEY:1TRXID:1NEXT:empty KEY:2TRXID:2NEXT:null KEY:1TRXID:2NEXT:null

[0121] 7. Insert the KEY into the hash table R. Since the operation information with KEY 1 already exists in the HASH, the conflicting TRXID returned is 1, which means that there is a conflict between the current operation and the transaction with transaction ID 1. The conflicting TRXID 1 and the minimum starting LSN of the memory chip 1 are written back to the operation.

[0122] 8. Remove the conflicting KEY information with KEY 1 from the HASH table.

[0123] 9. Set the address in the hash table R with KEY 1 to the next record of the current KEY information, and get the following table.

[0124] KEY:1TRXID:1NEXT:empty KEY:2TRXID:2NEXT:null KEY:1TRXID:2NEXT:1:0

[0125] 10. Restart the target data synchronization service. The information in the memory linked list of the target data synchronization service will be reset, and a new round of reception will start again.

[0126] 11. The log receiving thread receives the operation with LSN 6, extracts its KEY 3, combines the TRXID and the space of the next record to make the length 32, and first stores its KEY and transaction ID in the first memory slice, whose offset in the memory slice is [1:0]. Since it is the first KEY information of the memory slice, its LSN 6 should be set as the starting LSN of the memory slice.

[0127] KEY:3 ​​TRXID:3 NEXT: empty

[0128] Insert the KEY into the hash table R, and the returned TRXID is 0, indicating no conflict. The TRXID 0 indicating no conflict and the minimum starting LSN of the memory slice 6 are written back into the operation.

[0129] After all operation conflicts are detected, the following detection results are formed.

[0130]

[0131] 12. Create three working threads and execute TRX1, TRX2 and TRX3 respectively in the order in which the transactions were submitted.

[0132] 13. Worker thread 1 extracts the TRX1 transaction, registers the transaction information TRXID as 1 in the hash table P, and registers the starting LSN of the table information T associated transaction as 1 in the hash table G.

[0133] 14. Worker thread 2 extracts the TRX2 transaction, registers the transaction information TRXID as 2 into hash table P, and registers the starting LSN of the transaction associated with table information T as 3 into hash table G.

[0134] 15. Worker thread 3 extracts the TRX3 transaction, registers the transaction information TRXID 3 into hash table P, and registers the starting LSN 6 of the transaction associated with table information T into hash table G.

[0135] 16. Worker thread 1 extracts the insert operation with LSN 1 on TRX1, obtains the conflicting TRXID and conflicting LSN on the operation for conflict detection.

[0136] (1) This operation conflicts. TRXID is 0, indicating no conflict.

[0137] (2) Get the table information T and the conflict LSN of the operation as 1, and search the hash table G for conflicting transactions involving table T and with commit LSN less than 2 and transaction minimum start LSN less than 1. If no conflicting transaction is found, it can be executed directly.

[0138] 17. Worker thread 2 extracts the insert operation with LSN 3 on TRX2, obtains the conflicting TRXID and conflicting LSN on the operation for conflict detection.

[0139] (1) This operation conflicts. TRXID is 0, indicating no conflict.

[0140] (2) Obtain table information T and conflict LSN 1 for the operation, and search hash table G for conflicting transactions involving table T and with commit LSN less than 5 and transaction minimum start LSN less than 1. If no conflicting transactions are found, the operation can be executed directly.

[0141] 18. Work thread 2 extracts the update operation with LSN 4 on TRX2, obtains the conflicting TRXID and conflicting LSN on the operation for conflict detection.

[0142] (1) The conflicting operation TRXID is 1, indicating that there is a conflict with transaction TRX1. The current working thread needs to be suspended and woken up after the working thread 1 completes the synchronization of transaction TRX1.

[0143] 19. Work thread 3 extracts the insert operation with LSN 6 on TRX3, obtains the conflicting TRXID and conflicting LSN on the operation for conflict detection.

[0144] (1) This operation conflicts. TRXID is 0, indicating no conflict.

[0145] (2) Get the table information T and the conflict LSN of 6 for the operation, search the hash table G for conflicting transactions involving table T and with a commit LSN less than 7 and a minimum transaction start LSN less than 6. Find that both TRX1 and TRX2 transactions meet the conflict condition. Since the commit LSN of TRX2 is larger than that of TRX1, the current working thread needs to be suspended and woken up after the working thread 2 completes the synchronization of transaction TRX2.

[0146] 20. After worker thread 1 executes the commit operation of TRX1, it deletes the current transaction information from hash table P and hash table G respectively, and then wakes up the execution of TRX2 transaction on worker thread 2.

[0147] 21. After worker thread 2 executes the commit operation of TRX2, it deletes the current transaction information from hash table P and hash table G respectively, and then wakes up the execution of TRX3 transaction on worker thread 3.

[0148] 22. After worker thread 3 executes the commit operation of TRX3, it deletes the current transaction information from hash table P and hash table G respectively, and completes the execution of all transactions.

[0149] From the above process, we can see that transaction TRX1 is submitted first and will not conflict with the transactions submitted later, so it can be executed smoothly; the update operation of transaction TRX2 conflicts with the insert operation of TRX1 during conflict detection, so when executing TRX2, it is necessary to wait for TRX1 to be completed before executing; from the data point of view, the insert operation of transaction TRX3 does not conflict with TRX1 and TRX2, but because it is a conflict detection re-performed after the failure, its detection conflict LSN is reset to 6, so although it has no conflicting transactions, it can search for eligible transactions when using the conflict LSN to determine whether it can be executed, so it must wait for the conflicting transaction to be completed before it can start executing.

[0150] Embodiment 3:

[0151] It should be noted that for rollback transactions, since the rollback transactions will not be executed, there are three ways to process the rollback transaction operations in the hash table R.

[0152] The first method: do not roll back the impact of the rollback transaction operation on the operation dependency in the hash table R, and do not collect the conflicting TRXIDs of the rollback transaction operation dependency. Directly release all the operations of the rollback transaction. This rollback transaction will be dependent on other operations. The rollback transaction must also be added to the pending execution list for execution to ensure the continuity of the operation dependency. When this solution is adopted, the operations of the rollback transaction are directly released as a whole, which can improve the processing performance of the rollback transaction. However, the operations that depend on the rollback transaction must wait until the rollback transaction is released in the pending execution list before they can be executed. Since the conflicting transactions of the operation dependency were not collected before the release of the rollback transaction, it is necessary to wait until all transactions whose commit LSN or rollback LSN is less than its own rollback LSN are executed before they can be released, which will affect the synchronization efficiency. This method corresponds to that when the target-side data synchronization service receives the rollback transaction, all operations on this transaction do not need to be executed and are directly discarded. Only the retained transaction information is added to the pending execution queue. For example, when the target-side data synchronization service receives a rollback or partial rollback operation, it needs to locate the transaction based on the transaction ID in the operation, and then mark the transaction to indicate that some operations in the transaction are rolled back. If the operation is a rollback operation, then all operations in the transaction do not need to be executed and are directly discarded. Only the retained transaction information is added to the queue to be executed. The transaction information of the rolled back transaction cannot be discarded.

[0153] The second method: do not roll back the impact of the rollback transaction operation on the operation dependency in the hash table R, but collect the conflicting TRXIDs of the rollback transaction operation dependency, for example, record it in the conflicting TRXID dependency list L. This rollback transaction will be relied upon by other operations, and the rollback transaction must also be added to the pending execution list for execution to ensure the continuity of the operation dependency. When this solution is adopted, the conflicting TRXIDs in the operation must be collected before the rollback transaction operation is released. Although the processing performance of the rollback transaction is reduced, the release performance of the rollback transaction will be improved during execution. The operation that depends on the rollback transaction must wait until the rollback transaction is released in the pending execution list before it can be executed. Since the conflicting transactions of the operation dependency were collected before the release operation, the rollback transaction can be released only after these conflicting transactions are executed, without waiting for all transactions whose commit LSN or rollback LSN is less than its own rollback LSN to be executed. Compared with the first solution, this will partially improve the efficiency of synchronization. This method corresponds to that when the target-side data synchronization service receives a rollback or partial rollback operation, it collects the conflicting TRXIDs saved in the rolled-back operation, and for the rollback operation, the corresponding transaction cannot be discarded, but is added to the queue of pending transactions.

[0154] The third type: roll back the impact of the rolled-back transaction operation on the operation dependencies in the hash table R, then the rolled-back transaction will not be dependent on other operations, and the rolled-back transaction does not need to be added to the pending execution linked list. When this solution is adopted, after receiving the rollback operation, the transaction needs to roll back the impact of all operations in the transaction on the operation dependencies in the hash table R. Since the transaction scale is uncontrollable, when a large transaction is rolled back, the rollback action will affect the progress of receiving the operation, thereby affecting the efficiency of synchronization. This method corresponds to that when the target-side data synchronization service receives a rollback or partial rollback operation, the conflicting TRXID saved in the rolled-back operation is written back to the hash table R. The description of the rollback part in Example 1 of the present invention is an example description under this method.

[0155] The above three solutions for rolling back transactions have their own advantages and disadvantages. The first solution is suitable for large-scale transaction rollback, the second solution is suitable for medium-scale transaction rollback, and the third solution is suitable for small-scale transaction rollback. Therefore, two parameters W1 and W2 are set. W1 represents the minimum number of DML operations in large-scale transactions, and W2 represents the minimum number of DML operations in medium-scale transactions. Based on this, after the target-side data synchronization service receives the DML operation from the source, it is also necessary to manage the received DML operations by transaction classification, and count the scale S of DML operations received by each transaction (S is the number of DML operations received in a single transaction). When the target-side data synchronization service receives a rollback operation, it takes corresponding actions according to the scale S of DML operations in the transaction.

[0156] When the scale S of the rolled-back transaction is greater than or equal to W1, it corresponds to the large-scale transaction rollback in the first solution. In this case, the impact of the rolled-back transaction operation on the operation dependency in the hash table R is not rolled back, and the conflicting TRXIDs of the rolled-back transaction operation dependency are not collected. All operations of the rolled-back transaction are directly released. This rolled-back transaction will be dependent on other operations, and the rolled-back transaction must also be added to the pending execution list for execution to ensure the continuity of the operation dependency.

[0157] When the scale S of the rolled-back transaction is greater than or equal to W2 and less than W1, it corresponds to the medium-scale transaction rollback in the second solution. In this case, the impact of the rolled-back transaction operation on the operation dependency in the hash table R is not rolled back, but the conflicting TRXIDs of the rolled-back transaction operation dependency are collected, and it can be selected to be recorded in the conflicting TRXID dependency linked list L. This rolled-back transaction will be dependent on other operations, and the rolled-back transaction must also be added to the pending execution linked list for execution to ensure the continuity of the operation dependency.

[0158] When the scale S of the rolled-back transaction is less than W2, it corresponds to the small-scale transaction rollback in the third solution. In this case, the impact of the rolled-back transaction operation on the operation dependency in the hash table R is rolled back, and the rolled-back transaction does not need to be added to the pending execution linked list and is directly released. The description of the rollback part in Embodiment 1 of the present invention is an example description when the scale S of the rolled-back transaction is less than W2.

[0159] Furthermore, for partial rollback operations, due to the particularity of partial rollback, partial rollback itself needs to traverse the operations to be rolled back, so adding the process of collecting conflicting TRXIDs on these operations will not significantly reduce the performance of processing partial rollbacks. Based on this, when the target-side data synchronization service receives a partial rollback operation, it is necessary to count the total number of rolled back rows S1, and perform the following processing according to the size of S1: When the number of rollback operation rows S1 is less than W2, the impact of the rollback operation on the operation dependency in the hash table R is rolled back, that is, the conflicting TRXIDs saved in the rolled back operation are written back to the hash table R. When the number of rollback operation rows S1 is greater than W2, the impact of the rollback transaction operation on the operation dependency in the hash table R is not rolled back, that is, the conflicting TRXIDs saved in the rolled back operation are not written back to the hash table R, but the conflicting TRXIDs of the rollback transaction operation dependency are collected, and the conflicting TRXIDs can be recorded in the conflicting TRXID dependency linked list L.

[0160] Based on the above settings, after the target-side data synchronization service creates a working thread, the working thread extracts a transaction from the committed transaction list in the order in which the transaction is committed, and determines whether the transaction is a rollback transaction. If the current transaction is a rollback transaction, it is necessary to determine whether the rollback transaction has a conflicting TRXID linked list L.

[0161] If the rolled back transaction does not have a conflicting TRXID linked list L, it is necessary to wait for all transactions with a smaller LSN than the current transaction to be committed before waking up the waiting worker thread, and then remove the registration information of the current transaction from the hash table P and hash table G to complete the execution of the current transaction. This is because the operations on the rolled back transaction do not need to be executed and are discarded, so the transaction information they depend on is also unclear. Therefore, when submitting, it is necessary to wait until all transactions submitted earlier than itself are submitted to ensure the correctness of the transaction dependency order.

[0162] If the rolled back transaction has a conflicting TRXID linked list L, it is necessary to wait for all conflicting transactions on the conflicting transaction linked list L to commit before waking up the waiting worker thread, and then remove the registration information of the current transaction from the hash table P and hash table G to complete the execution of the current transaction. Specifically, extract a conflicting TRXID from the current transaction conflicting transaction linked list L in turn, and check whether it exists in the hash table P. If it exists, it is necessary to wait for the transaction to be completed before waking itself up. After waking up, the next conflicting TRXID is extracted from the conflicting transaction linked list L and the same check is performed until all conflicting transactions in the conflicting transaction linked list L are completed. This is because the operations on the rolled back transaction do not need to be executed and are discarded. When the rollback operation is discarded, the conflicting TRXIDs on the operation are collected, so the transaction information they depend on is very clear. Then, when releasing, you only need to wait for these conflicting transactions to be committed to ensure the correctness of the transaction dependency order.

[0163] In summary, since the rollback transaction will not be executed, it will generate three schemes during conflict detection. Each scheme has its own advantages, and appropriate values ​​need to be set to give full play to the advantages of the three schemes, so as to achieve the purpose of improving the overall synchronization performance. In addition, for the partial rollback operation of the committed transaction, the conflicting TRXIDs referenced by them are collected in a targeted manner during the rollback operation, which can effectively reduce the performance loss caused by the partial rollback operation writing back the conflict detection hash table R, so as to achieve the purpose of improving the overall synchronization performance. This embodiment processes the rollback transaction and partial rollback operation in a targeted manner according to the agreed operation scale, and finds the balance point between the cost of operation rollback and rollback transaction execution, thereby improving the overall synchronization performance.

[0164] In addition, in some embodiments, the KEY in the hash table R can be stored in a file or in a memory chip. Specifically, the difference between the two is that when using files for storage, although the storage performance is low and affects the efficiency of conflict detection, after a data synchronization failure, the state of the hash table R between failures can be restored by storing the KEY value in the file, so that when performing conflict detection on the received operations after the failure, there is continuity with the failure, and the synchronization performance will not drop drastically due to the failure; when using memory chips for storage, the performance of conflict detection will be greatly improved compared to the file storage solution, but the data of the previous conflict detection will be lost after the failure, and the recovery detection can only start from the currently received LSN, which will cause a discontinuity between the subsequent conflict detection and the failure, and the synchronization performance will drop drastically at the failure location during synchronization execution. When the storage performance is high (for example, using SSD fixed storage), the performance requirements of conflict detection can be met, and the efficiency of operation reception can be balanced with synchronous execution. Then, the method of storing the KEY in the hash table R through files can effectively avoid the loss of synchronization performance caused by failures; when the storage performance affects the efficiency of conflict detection, the bottleneck of synchronization exists in the operation reception. At this time, the method of storing the KEY in the hash table R through a memory chip can effectively improve the reception performance of the operation, thereby improving the overall synchronization performance. Embodiment 1 of the present application is an example of a method of storing the KEY in the hash table R through memory.

[0165] In some embodiments, you can choose to calculate the MD5 value at the source or target end as the KEY of the operation. The data synchronization service at the source end detects conflicts for each operation and can calculate the MD5 value of the conflict more accurately. If the primary key structure or column order of the target database table is inconsistent with the source end, the MD5 value calculated by the primary key information of the target end table will have errors. Based on this, it is generally chosen to calculate the MD5 value at the source end as the KEY of the operation. After the target end data synchronization service receives the DML operation at the source end, it can directly extract the MD5 value calculated by the source end as the KEY.

[0166] In some embodiments, when calculating the KEY of an operation, since the order of columns in the operation parsed from the log is not fixed, the columns in the operation must first be sorted by column ID, and then the KEY is calculated according to the fixed order of the primary key or unique index combination columns. After the source-side data synchronization service captures a DML log operation, it obtains the table ID in the log, and obtains the primary key information and unique index of the table in the source-side database through the table ID. After parsing the current DML log operation, the source-side data synchronization service determines whether the table has a primary key or unique index. If there is a primary key or unique index, the table ID and the column value of the primary key or unique index are combined to calculate an MD5 value as the KEY of this operation, which is stored in the current DML log operation and sent to the target-side synchronization service. It should be noted that when a table has both a primary key and a unique index, the table ID and the primary key are preferably selected to jointly calculate the MD5 value as the KEY; when a table has no primary key but has multiple unique indexes, the table ID and any unique index are selected to jointly calculate the MD5 value. If there is no primary key or unique index, after parsing the current DML log operation, the source-side data synchronization service combines the table ID and the row data's ROWID value or custom selected column to calculate an MD5 value as the KEY for this operation, stores it in the current DML log operation, and sends it to the target-side synchronization service. It should be noted that when calculating the KEY for a table without a primary key or unique constraint, if it is clear that all columns of the table have no duplicate values ​​when combined, the table's ROWID can be used directly to calculate the KEY, which can effectively reduce the cost of calculating the KEY; if the table has duplicate rows, then it is necessary to use custom selected columns to calculate the KEY, and which columns or all column values ​​to use to calculate the KEY can be selected based on the distribution of column values, so that the target-side synchronization service can use the KEY to prevent deadlocks caused by concurrently executed synchronization transactions operating rows with duplicate values ​​at the same time.

[0167] Embodiment 4:

[0168] Based on the parallel execution method based on transaction operation dependency provided in the above embodiment 1, the present invention also provides a parallel execution device based on transaction operation dependency that can be used to implement the above method and system, such as Figure 6 , which is a schematic diagram of the device architecture of an embodiment of the present invention. The parallel execution device based on transaction operation dependency of this embodiment includes one or more processors 21 and a memory 22. Figure 6 A processor 21 is taken as an example.

[0169] The processor 21 and the memory 22 may be connected via a bus or other means. Figure 6 The example of connecting through bus is taken in the following.

[0170] The memory 22, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as the parallel execution method based on transactional operation dependency in Example 1. The processor 21 executes various functional applications and data processing of the parallel execution device based on transactional operation dependency by running the non-volatile software programs, instructions and modules stored in the memory 22, that is, implements the parallel execution method based on transactional operation dependency in Example 1.

[0171] The memory 22 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 22 may optionally include a memory remotely arranged relative to the processor 21, and these remote memories may be connected to the processor 21 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0172] The program instructions / modules are stored in the memory 22. When executed by one or more processors 21, the parallel execution method based on transaction operation dependency in the above embodiment 1 is executed, for example, the above described Figure 1-Figure 4 The steps shown.

[0173] The above-mentioned product can execute the method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the method provided in the embodiment of the present application.

[0174] It should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0175] Through the description of the above implementation methods, ordinary technicians in this field can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Ordinary technicians in this field can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0176] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Under the concept of the present invention, the technical features in the above embodiments or different embodiments may also be combined, the steps may be implemented in any order, and there are many other changes in different aspects of the present invention as described above, which are not provided in detail for the sake of simplicity. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A parallel execution method based on transaction operation dependency, characterized in that: include: The target-side data synchronization service creates hash table P, hash table G, and several worker threads; The worker thread extracts a transaction from the committed transaction list in the order of transaction submission, registers the transaction ID into the hash table P, and registers the table information involved in the transaction and the transaction start LSN into the hash table G; The worker thread extracts an operation of the transaction and determines whether the current operation is a commit operation. If so, it commits the current transaction and wakes up the waiting worker thread, and then removes the registration information of the current transaction from hash tables P and G. Otherwise, obtain the conflicting TRXID and conflicting LSN saved in the operation, and perform conflict detection of the operation: use the conflicting TRXID of the current operation to be executed to search whether there is a transaction with the conflicting TRXID in the hash table P. If so, wait for the conflicting transaction to be executed and committed before waking itself up; Otherwise, the worker thread uses the information of the current pending operation table to search in the hash table G to see if there is a transaction operating the same table, and the transaction commit LSN is smaller than the current transaction, and the transaction start LSN is smaller than the conflict LSN of the current operation. If there is, it will wait for the conflicting transaction to be executed and committed before waking itself up; Otherwise, it is determined that no conflict is detected and the current operation is performed.

2. The parallel execution method based on transaction operation dependency according to claim 1, characterized in that: When the target-side data synchronization service is started, a hash table R is initialized, and the record address in the hash item of the hash table R is initialized to empty, which is used to store and locate the received operations; the target-side data synchronization service creates two memory slices to store the KEY in the hash table R, and the version number of each memory slice is incremented in the order of creation, and the two memory slices are added to the memory linked list.

3. The parallel execution method based on transaction operation dependency according to claim 2, characterized in that: The acquisition of the conflicting TRXID and the conflicting LSN includes: After receiving the DML operation from the source, the target data synchronization service extracts the MD5 value calculated by the source in the operation as the KEY, and then extracts the transaction ID in the operation as the TRXID, and combines the KEY and TRXID into a record and saves it in the current memory slice. If the record is the first record of the current memory slice, the log LSN corresponding to the operation is marked on the memory slice as the starting LSN of the memory slice. Use the current operation's KEY to construct a detection record X, merge the detection record X into the hash table R, and perform conflict detection and judgment during the merging process. If there is a conflicting KEY, return the TRXID value corresponding to the conflicting KEY; otherwise, return 0 as the corresponding TRXID, indicating no conflict; The TRXID obtained by the conflict detection is set as the conflict TRXID, and the starting LSN of the first memory slice in the memory linked list corresponding to the current hash table R is written into the current operation and set as the conflict LSN.

4. The parallel execution method based on transaction operation dependency according to claim 3, characterized in that: The conflict detection and judgment comprises: Calculate the hash value of the KEY of the current detection record X, and locate the hash item through the hash value; determine whether the record address in the hash item is empty. If so, set the record address in the hash item to the next address space of the current detection record X, and fill the address of the detection record X back into the hash item, and return 0 as the conflict TRXID, indicating that no conflict is detected; if not, proceed to the next step of conflict detection and judgment; Determine whether the memory chip version number K in the address recorded in the hash item is less than the version number K value of the first memory chip in the memory linked list. If so, it indicates that this record Y has exceeded the inspection range. Set the address recorded in the hash item to the next address space of the current detection record X, and fill the address of the detection record X back into the hash item. Use 0 as the conflict TRXID to return, indicating that no conflict is detected; if not, proceed to the next step of conflict detection judgment; According to the address recorded in the hash item, the corresponding record Y is loaded from the memory chip, and it is determined whether the KEY of record Y is equal to the KEY of the current detection record X and the TRXID of record Y is not equal to the TRXID of the current operation. If so, it means that there is a conflict in the operation, and record Y is removed from the record linked list of the hash item to shorten the length of the linked list in the hash item, and the record address in the hash item is set to the next address space of the current detection record X, and the address of the current detection record X is backfilled into the hash item, and the TRXID stored in record Y is used as the conflicting TRXID for return; if not, the next step of conflict detection and judgment is carried out; Traverse the next record of record Y in sequence and perform conflict detection and judgment until the end of the record linked list.

5. The parallel execution method based on transaction operation dependency according to claim 3, characterized in that: The calculation of the MD5 value includes: generating an MD5 value based on the table ID and the primary key, or the table ID and the unique index information, or the table ID and the custom selected column in the DML operation.

6. The parallel execution method based on transaction operation dependency according to claim 2, characterized in that: The memory linked list includes two memory slices. When the first memory slice is full, it switches to the second memory slice. When the second memory slice is full, the first memory slice in the linked list is eliminated first, and then a new memory slice is created with an increasing version number and added to the linked list.

7. The parallel execution method based on transaction operation dependency according to claim 2, characterized in that: When the target-side data synchronization service receives a rollback or partial rollback operation, it writes the conflicting TRXID saved in the rolled-back operation back to the hash table R for conflict detection; specifically: Locate the transaction that needs to be rolled back using the transaction ID of the rollback or partial rollback operation, and extract the number of rows included in the transaction in the rollback operation or the number of rows that need to be rolled back in the partial rollback operation; Extract the rollback operation from the tail of the transaction operation linked list, and extract the KEY value, conflicting TRXID, and conflicting LSN saved in the operation; Compare the conflicting LSN of the operation with the starting LSN of the first memory slice. If it is smaller than the starting LSN, terminate the writeback of the rollback operation to the hash table R; otherwise, search for the conflicting operation record with the same KEY in the hash table R according to the KEY of the operation. If not found, terminate the writeback of the rollback operation to the hash table R; otherwise, write the conflicting TRXID back to the record in the hash table R, and continue to extract the previous operation to be rolled back for the same writeback until the specified number of rows is rolled back.

8. A parallel execution device based on transaction operation dependency, characterized in that: The device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to execute the parallel execution method based on transaction operation dependencies described in any one of claims 1-7.

9. A parallel execution system based on transaction operation dependency, applying the parallel execution method based on transaction operation dependency as claimed in any one of claims 1 to 7, characterized in that: The system includes a hash table and work thread creation module, a transaction extraction module, and an operation extraction and conflict detection module, wherein: The hash table and worker thread creation module is used to create a hash table P, a hash table G and several worker threads through the target end data synchronization service; The transaction extraction module is used to extract a transaction from the committed transaction linked list according to the transaction submission order through a working thread, and register the transaction ID into a hash table P, and register the table information involved in the transaction and the start LSN of the transaction into a hash table G; The operation extraction and conflict detection module is used to extract an operation of a transaction through a working thread, determine whether the current operation is a commit operation, and if so, wake up the waiting working thread after committing the current transaction, and then remove the registration information of the current transaction from the hash table P and the hash table G; otherwise, obtain the conflict TRXID and conflict LSN saved in the operation, and perform conflict detection of the operation: use the conflict TRXID of the current operation to be executed to search whether there is a transaction with the conflict TRXID in the hash table P, if so, wait for the conflicting transaction to be executed and committed before waking itself up; otherwise, the working thread uses the information of the current operation table to be executed to search whether there is a transaction operating the same table in the hash table G, and the commit LSN of this transaction is smaller than the current transaction, and the start LSN of the transaction is smaller than the conflict LSN of the current operation, if so, wait for the conflicting transaction to be executed and committed before waking itself up; otherwise, it is determined that no conflict is detected and the current operation is executed.

10. A non-volatile computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, which are executed by one or more processors to complete the parallel execution method based on transaction operation dependency as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Parallel execution method based on log analysis synchronization and data synchronization system

    CN111858503A

  • Data synchronization method and device based on parallel execution

    CN111858626A

  • Method and equipment for log analysis and synchronous transaction storage

    CN115756766A

  • Transaction processing method and device, computer equipment and storage medium

    CN116561137A