[go: up one dir, main page]

CN114296886B - A parallel execution method and device based on range row lock - Google Patents

A parallel execution method and device based on range row lock Download PDF

Info

Publication number
CN114296886B
CN114296886B CN202111501972.5A CN202111501972A CN114296886B CN 114296886 B CN114296886 B CN 114296886B CN 202111501972 A CN202111501972 A CN 202111501972A CN 114296886 B CN114296886 B CN 114296886B
Authority
CN
China
Prior art keywords
lsn
execution
parallel
thread
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111501972.5A
Other languages
Chinese (zh)
Other versions
CN114296886A (en
Inventor
孙峰
余院兰
彭青松
刘启春
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Dream Database Co ltd
Original Assignee
Wuhan Dream Database Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Dream Database Co ltd filed Critical Wuhan Dream Database Co ltd
Priority to CN202111501972.5A priority Critical patent/CN114296886B/en
Publication of CN114296886A publication Critical patent/CN114296886A/en
Application granted granted Critical
Publication of CN114296886B publication Critical patent/CN114296886B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a parallel execution method and device based on range line lock. The method mainly comprises the following steps: merging the single transactions into multiple transactions, setting commit LSNs and parallel LSNs of the multiple transactions, and registering the multiple transactions to an execution thread linked list; single transaction processing step: the execution thread extracts the next single transaction in the multi-transaction to start execution and takes the commit LSN of the single transaction as a separation line LSN; entering a corresponding step by judging whether the operation type, the parallel LSN size, the separation line LSN size and the ROWID range lock conflict or not; thread submitting step: judging whether the current single transaction is the last single transaction, if so, executing thread submitting operation, and if not, re-entering the single transaction processing step. The method adopted by the invention can optimize the parallelism of the conflict-free data synchronization operation, thereby improving the data synchronization performance and reducing the occupation of ROWID to the memory.

Description

一种基于范围行锁的并行执行方法及设备A parallel execution method and device based on range row lock

技术领域Technical Field

本发明涉及数据库数据处理技术领域,特别是涉及一种基于范围行锁的并行执行方法及设备。The present invention relates to the technical field of database data processing, and in particular to a parallel execution method and device based on range row locks.

背景技术Background Art

目前基于日志解析的异构数据库复制技术应用广泛。这种技术在源端捕捉数据库的日志,解析出日志中的INSERT、UPDATE、DELETE操作,然后发送到目标端,目标端对日志信息进行逆向生成,恢复成SQL语句方式,然后使用数据库通用接口,应用到目标数据库,实现数据复制。因此,在数据库实时复制过程中,目标端的执行效率是影响数据同步性能的重要因素之一。Currently, heterogeneous database replication technology based on log parsing is widely used. This technology captures database logs at the source end, parses the INSERT, UPDATE, and DELETE operations in the logs, and then sends them to the target end. The target end reversely generates the log information and restores it to SQL statements. Then, it uses the database general interface and applies it to the target database to achieve data replication. Therefore, in the process of real-time database replication, the execution efficiency of the target end is one of the important factors affecting data synchronization performance.

目标端数据库上执行同步事务时,需要以事务的提交顺序为基准来执行事务操作,不然前后有关联的操作执行时就会发生错误,从而影响同步的正确性。为了追求数据同步的性能,执行同步事务时往往会采取事务合并的策略,把小事务合并为大事务,不仅可以通过合并不同事务的相同操作来减少执行的次数,还可以减少事务提交的次数,从而达到提升同步性能的目的。另外还可以通过增加执行事务的线程数,采用多线程并行的策略同时对多个合并以后的事务进行入库,进一步的提升同步的性能。但是在同时采用了事务合并和并行执行的策略以后,需要防范和解决并行执行时带来的数据冲突问题。现有技术方案中有针对单事务并行采用ROWID冲突检测的方式来防范数据冲突,后提交的事务在执行时要对先提交的事务中涉及的ROWID进行冲突检测,该方案要在事务执行时先提取出事务所涉及操作的所有ROWID,这对事务规模较小的场景是有效的,但是当事务规模较大时,一次性得取事务的全部ROWID不仅会影响数据同步的性能,而且会消耗大量的内存用来存放ROWID信息,存在内存耗尽的风险。When executing synchronization transactions on the target database, the transaction operations need to be executed based on the transaction submission order. Otherwise, errors will occur when executing related operations, thus affecting the correctness of synchronization. In order to pursue data synchronization performance, the transaction merging strategy is often adopted when executing synchronization transactions. Small transactions are merged into large transactions. This can not only reduce the number of executions by merging the same operations of different transactions, but also reduce the number of transaction submissions, thereby achieving the purpose of improving synchronization performance. In addition, the synchronization performance can be further improved by increasing the number of threads executing transactions and adopting a multi-threaded parallel strategy to simultaneously store multiple merged transactions. However, after adopting the transaction merging and parallel execution strategies at the same time, it is necessary to prevent and resolve data conflicts caused by parallel execution. In the existing technical solution, a ROWID conflict detection method is used for single transaction parallelism to prevent data conflicts. When executing a later submitted transaction, a conflict detection is performed on the ROWID involved in the earlier submitted transaction. This solution is to extract all ROWIDs of the operations involved in the transaction when the transaction is executed. This is effective for scenarios with a small transaction scale. However, when the transaction scale is large, obtaining all ROWIDs of the transaction at one time will not only affect the performance of data synchronization, but also consume a large amount of memory to store ROWID information, posing the risk of memory exhaustion.

鉴于此,如何克服现有技术所存在的缺陷,解决上述技术问题,是本技术领域待解决的难题。In view of this, how to overcome the defects of the prior art and solve the above-mentioned technical problems is a difficult problem to be solved in this technical field.

发明内容Summary of the invention

针对现有技术的以上缺陷或改进需求,本发明提供一种基于范围行锁的并行执行方法及设备,针对单事务合并以后形成的多事务之间的高效并行执行制定一种可行的方案,主要以多事务中每个单事务的提交LSN为基线来划分并行执行的区间(也即设定分隔线LSN),在第一并行区间(也即第一分隔线LSN之前的区间,第一个分隔线LSN称之为并行LSN)的操作并行执行,并在执行时提取操作的ROWID,再采用ROWID合并的方式,把多个ROWID合并为一个范围用来减小ROWID信息对内存的占用。除第一并行区间以外的其它并行区间在执行时,要确保排在前面区间的操作已经执行完成,然后使用当前操作的ROWID和前面的执行线程的ROWID范围进行冲突检测,确认无冲突以后再执行;如果有冲突,则需等待前面多事务提交以后再执行。In view of the above defects or improvement needs of the prior art, the present invention provides a parallel execution method and device based on range row locks, and formulates a feasible solution for the efficient parallel execution of multiple transactions formed after the single transaction is merged. The parallel execution interval is mainly divided based on the commit LSN of each single transaction in the multiple transactions (that is, the dividing line LSN is set), and the operations in the first parallel interval (that is, the interval before the first dividing line LSN, the first dividing line LSN is called the parallel LSN) are executed in parallel, and the ROWID of the operation is extracted during execution, and then the ROWID merging method is adopted to merge multiple ROWIDs into one range to reduce the memory usage of ROWID information. When executing other parallel intervals except the first parallel interval, it is necessary to ensure that the operations in the previous interval have been executed, and then use the ROWID of the current operation and the ROWID range of the previous execution thread to perform conflict detection, and execute after confirming that there is no conflict; if there is a conflict, it is necessary to wait for the previous multiple transactions to be committed before executing.

本发明实施例采用如下技术方案:The embodiment of the present invention adopts the following technical solution:

第一方面,本发明提供了一种基于范围行锁的并行执行方法,包括:In a first aspect, the present invention provides a parallel execution method based on range row locks, comprising:

将单事务合并为多事务且设置多事务的提交LSN以及并行LSN,并将多事务注册到执行线程链表;Merge a single transaction into multiple transactions and set the commit LSN and parallel LSN of the multiple transactions, and register the multiple transactions to the execution thread list;

单事务处理步骤:执行线程提取多事务中的下一个单事务开始执行并将该单事务的提交LSN作为分隔线LSN;Single transaction processing step: The execution thread extracts the next single transaction from the multiple transactions and starts executing it, and uses the commit LSN of the single transaction as the separator LSN;

通过对操作类型、并行LSN大小、分隔线LSN大小以及ROWID范围锁是否冲突的判断来进入相对应的步骤;Enter the corresponding step by judging the operation type, parallel LSN size, separator LSN size, and whether the ROWID range lock conflicts;

线程提交步骤:判断当前单事务是否为最后一个单事务,若是则执行线程提交操作,若不是则重新进入单事务处理步骤。Thread commit step: Determine whether the current single transaction is the last single transaction. If so, execute the thread commit operation. If not, re-enter the single transaction processing step.

进一步的,所述将单事务合并为多事务且设置多事务的提交LSN以及并行LSN,并将多事务注册到执行线程链表具体包括:Further, the step of merging a single transaction into multiple transactions, setting commit LSNs and parallel LSNs of the multiple transactions, and registering the multiple transactions into an execution thread linked list specifically includes:

目标端数据同步服务接收到源端操作后,对待执行的事务按提交操作的LSN大小顺序存入待执行链表;After the target-side data synchronization service receives the source-side operation, the transactions to be executed are stored in the pending execution linked list in the order of the LSN size of the submitted operation;

执行线程从待执行链表中按事务提交LSN的顺序摘取N个单事务合并成一个多事务,并将最后一个单事务的提交LSN设置为多事务的提交LSN,然后根据多事务的提交LSN在执行线程链表中进行注册;The execution thread extracts N single transactions from the pending execution linked list in the order of transaction commit LSNs and merges them into a multi-transaction, sets the commit LSN of the last single transaction as the commit LSN of the multi-transaction, and then registers it in the execution thread linked list according to the commit LSN of the multi-transaction;

执行线程将多事务中的第一个单事务的提交LSN设为并行LSN,其它在该执行线程之后的执行线程准备执行的操作的LSN若小于该并行LSN,则进行并行执行。The execution thread sets the commit LSN of the first single transaction in the multi-transaction as the parallel LSN. If the LSN of the operations to be executed by other execution threads after the execution thread is smaller than the parallel LSN, they are executed in parallel.

进一步的,所述单事务处理步骤还包括:判断当前执行线程的唤醒链表,将唤醒类型为执行等待并且执行LSN小于分隔线LSN的执行线程唤醒。Furthermore, the single transaction processing step also includes: determining the wake-up linked list of the current execution thread, and waking up the execution thread whose wake-up type is execution waiting and whose execution LSN is less than the dividing line LSN.

进一步的,所述通过对操作类型、并行LSN大小、分隔线LSN大小以及ROWID范围锁是否冲突的判断来进入相对应的步骤具体包括:Furthermore, the step of entering corresponding steps by judging whether the operation type, the parallel LSN size, the separator LSN size, and the ROWID range lock conflict specifically includes:

操作类型判断步骤:根据当前单事务的下一个操作的操作类型来选择进入并行LSN判断步骤或线程提交步骤;Operation type determination step: Select to enter the parallel LSN determination step or thread submission step according to the operation type of the next operation of the current single transaction;

并行LSN判断步骤:根据当前操作的LSN以及排在当前执行线程之前的执行线程的并行LSN的大小来选择进入操作类型判断步骤或分隔线LSN判断步骤;Parallel LSN determination step: selecting to enter the operation type determination step or the separator line LSN determination step according to the LSN of the current operation and the size of the parallel LSN of the execution thread before the current execution thread;

分隔线LSN判断步骤:根据当前操作的LSN以及排在当前执行线程之前的执行线程的分隔线LSN的大小来选择进入冲突检测步骤或等待唤醒;Separation line LSN judgment step: select to enter the conflict detection step or wait for wake-up according to the LSN of the current operation and the size of the separation line LSN of the execution thread before the current execution thread;

冲突检测步骤:根据当前操作的ROWID以及当前执行线程之前的执行线程的ROWID范围锁来判断是否冲突以选择进入操作类型判断步骤或等待唤醒。Conflict detection step: determine whether there is a conflict based on the ROWID of the current operation and the ROWID range lock of the execution thread before the current execution thread to choose to enter the operation type judgment step or wait for wake-up.

进一步的,所述操作类型判断步骤具体包括:判断当前单事务的下一个操作的操作类型,若操作类型为提交操作则进入线程提交步骤;否则进入并行LSN判断步骤。Furthermore, the operation type determination step specifically includes: determining the operation type of the next operation of the current single transaction, and if the operation type is a commit operation, entering a thread commit step; otherwise, entering a parallel LSN determination step.

进一步的,所述并行LSN判断步骤具体包括:判断当前操作的LSN是否小于所有排在当前执行线程之前的执行线程的并行LSN,若是则执行当前操作并提取当前操作的ROWID并入当前执行线程的ROWID范围锁,然后进入操作类型判断步骤;若否则进入分隔线LSN判断步骤。Furthermore, the parallel LSN determination step specifically includes: determining whether the LSN of the current operation is smaller than the parallel LSNs of all execution threads that are arranged before the current execution thread; if so, executing the current operation and extracting the ROWID of the current operation and merging it into the ROWID range lock of the current execution thread, and then entering the operation type determination step; if not, entering the separator line LSN determination step.

进一步的,所述分隔线LSN判断步骤具体包括:判断当前操作的LSN是否小于所有排在当前执行线程之前的执行线程的分隔线LSN,若是则进入冲突检测步骤;若否则从后向前查找到第一个分隔线LSN小于当前操作的LSN的执行线程,并将当前执行线程添加到该查找到的执行线程的唤醒链表中,且将唤醒类型标记为执行等待。Furthermore, the dividing line LSN judgment step specifically includes: judging whether the LSN of the current operation is smaller than the dividing line LSNs of all execution threads arranged before the current execution thread, and if so, entering the conflict detection step; if not, searching from back to front for the first execution thread whose dividing line LSN is smaller than the LSN of the current operation, and adding the current execution thread to the wake-up linked list of the found execution thread, and marking the wake-up type as execution wait.

进一步的,所述冲突检测步骤具体包括:提取当前操作的ROWID,并判断该ROWID是否落在当前执行线程之前的执行线程的ROWID范围锁内,若是即表示存在冲突,则将当前执行线程添加到存在冲突的执行线程的唤醒链表中,且将唤醒类型标记为提交等待;若否即表示不存在冲突,则执行当前操作,并提取当前操作的ROWID并入当前执行线程的ROWID范围锁,然后进入操作类型判断步骤。Furthermore, the conflict detection step specifically includes: extracting the ROWID of the current operation, and determining whether the ROWID falls within the ROWID range lock of the execution thread before the current execution thread. If so, it indicates that there is a conflict, then the current execution thread is added to the wake-up list of the execution thread with the conflict, and the wake-up type is marked as commit wait; if not, it indicates that there is no conflict, then the current operation is executed, and the ROWID of the current operation is extracted and incorporated into the ROWID range lock of the current execution thread, and then the operation type determination step is entered.

进一步的,所述线程提交步骤中的线程提交操作具体包括:对本执行线程进行提交并将唤醒链表中等待的其他执行线程全部唤醒,然后将本执行线程从执行线程链表中移除且释放掉ROWID范围锁。Furthermore, the thread submission operation in the thread submission step specifically includes: submitting the current execution thread and waking up all other execution threads waiting in the wake-up list, and then removing the current execution thread from the execution thread list and releasing the ROWID range lock.

另一方面,本发明提供了一种基于范围行锁的并行执行设备,具体为:包括至少一个处理器和存储器,至少一个处理器和存储器之间通过数据总线连接,存储器存储能被至少一个处理器执行的指令,指令在被处理器执行后,用于完成第一方面中的基于范围行锁的并行执行方法。On the other hand, the present invention provides a parallel execution device based on range row locks, specifically: including at least one processor and a memory, at least one processor and the memory are connected via a data bus, the memory stores instructions that can be executed by at least one processor, and after the instructions are executed by the processor, they are used to complete the parallel execution method based on range row locks in the first aspect.

与现有技术相比,本发明的有益效果在于:首先,多个执行线程并行执行多事务时,采用单事务的提交LSN来划分出不同的并行区间(也即设定分隔线LSN),在划分出的第一个并行区间(也即第一个分隔线LSN之前的区间,第一个分隔线LSN称之为并行LSN),多个执行线程中操作LSN落在此区间的操作可以无条件的并行,因为这些操作访问的资源并不冲突。Compared with the prior art, the beneficial effects of the present invention are: first, when multiple execution threads execute multiple transactions in parallel, the commit LSN of a single transaction is used to divide different parallel intervals (that is, set the separator LSN), and in the first divided parallel interval (that is, the interval before the first separator LSN, the first separator LSN is called the parallel LSN), the operations in multiple execution threads whose operation LSNs fall in this interval can be unconditionally parallelized because the resources accessed by these operations do not conflict.

其次,从划分出的第二个并行区间(也即第一个分隔线LSN之后的区间)开始,提交LSN排在后面的执行线程在此区间可能会访问到提交LSN排在前面的执行线程在第一并行区间修改的数据,但此时这些数据的修改还没有提交,那么后面的执行线程就可能会访问不到它想要的数据,针对这种情况,后面的执行线程在并行执行时要先确保处在前面并行区间的执行线程已经构造完该区间的ROWID范围锁,然后再通过ROWID冲突检测的方式,如果当前待执行操作的ROWID落在了排在之前执行线程的ROWID范围锁里面,那就说明存在数据冲突,否则,就可以和前面的事务并行执行。Secondly, starting from the second parallel interval (that is, the interval after the first separator LSN), the execution thread with the later submission LSN may access the data modified by the execution thread with the earlier submission LSN in the first parallel interval in this interval. However, the modification of these data has not been submitted at this time, so the later execution thread may not be able to access the data it wants. In this case, the later execution thread must first ensure that the execution thread in the previous parallel interval has constructed the ROWID range lock of the interval when executing in parallel, and then use the ROWID conflict detection method. If the ROWID of the current operation to be executed falls within the ROWID range lock of the previous execution thread, it means that there is a data conflict. Otherwise, it can be executed in parallel with the previous transaction.

上述方案不仅适用采用了事务合并来优化同步性能的场景,而且在构造ROWID范围锁时采取的是边执行边构造的方式,不用在执行之前先构造,相对现有的方案,本方案减少了一次对事务操作的遍历过程,可以优化那些无冲突数据同步操作的并行度,从而提升数据同步的性能,并且还减小了ROWID对内存的占用。The above solution is not only applicable to the scenario where transaction merging is used to optimize synchronization performance, but also adopts a construction-while-execution approach when constructing the ROWID range lock, without the need to construct it before execution. Compared with the existing solution, this solution reduces the traversal process of transaction operations, can optimize the parallelism of those conflict-free data synchronization operations, thereby improving the performance of data synchronization, and also reduces the memory usage of ROWID.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

为了更清楚地说明本发明实施例的技术方案,下面将对本发明实施例中所需要使用的附图作简单地介绍。显而易见地,下面所描述的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。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.

图1为本发明实施例1提供的一种基于范围行锁的并行执行方法流程图;FIG1 is a flow chart of a parallel execution method based on range row locks provided in Embodiment 1 of the present invention;

图2为本发明实施例1提供的步骤100具体流程图;FIG2 is a specific flow chart of step 100 provided in Example 1 of the present invention;

图3为本发明实施例1提供的步骤300具体流程图;FIG3 is a specific flow chart of step 300 provided in Embodiment 1 of the present invention;

图4为本发明实施例1提供的步骤400具体流程图;FIG4 is a specific flow chart of step 400 provided in Embodiment 1 of the present invention;

图5为本发明实施例1提供的步骤500具体流程图;FIG5 is a specific flow chart of step 500 provided in Embodiment 1 of the present invention;

图6为本发明实施例1提供的步骤600具体流程图;FIG6 is a specific flow chart of step 600 provided in Embodiment 1 of the present invention;

图7为本发明实施例1提供的具体的事务执行流程图;FIG7 is a specific transaction execution flow chart provided by Embodiment 1 of the present invention;

图8为本发明实施例3提供的一种基于范围行锁的并行执行设备结构示意图。FIG8 is a schematic diagram of the structure of a parallel execution device based on range row locks provided in Example 3 of the present invention.

具体实施方式DETAILED DESCRIPTION

为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention 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 invention and are not used to limit the present invention.

本发明是一种特定功能系统的体系结构,因此在具体实施例中主要说明各结构模组的功能逻辑关系,并不对具体软件和硬件实施方式做限定。The present invention is an architecture of a specific functional system, so the specific embodiments mainly illustrate the functional logical relationship between the various structural modules, and do not limit the specific software and hardware implementation methods.

此外,下面所描述的本发明各个实施方式中所涉及到的技术特征只要彼此之间未构成冲突就可以相互组合。下面就参考附图和实施例结合来详细说明本发明。实施例1:In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other. The present invention will be described in detail below with reference to the accompanying drawings and embodiments.

为了陈述方便,本发明实施例将源端日志中的事务称为“单事务”,多个单事务合并以后形成的事务称为“多事务”。另外,数据库日志中,每一个操作都有一个LSN,这些LSN在所处的位置不同,自然就会有不同的命名,不然无法区分。下面对本文中可能出现的LSN命名进行统一解释。For the sake of convenience, the embodiments of the present invention refer to transactions in the source log as "single transactions", and transactions formed by merging multiple single transactions as "multiple transactions". In addition, in the database log, each operation has an LSN. These LSNs are located in different positions, so they will naturally have different names, otherwise they cannot be distinguished. The following is a unified explanation of the LSN names that may appear in this article.

当前操作LSN:该操作在日志中的LSN。Current operation LSN: The LSN of the operation in the log.

执行LSN:执行当前操作的LSN。Execution LSN: The LSN of the current operation.

提交LSN:每个事务提交操作的LSN。Commit LSN: The LSN of each transaction commit operation.

并行LSN:多事务中第一个单事务的提交LSN。Parallel LSN: The commit LSN of the first single transaction in multiple transactions.

分隔线LSN:当前执行操作所属单事务的提交LSN。Separator LSN: The commit LSN of the single transaction to which the currently executed operation belongs.

如图1所示,本发明实施例提供一种基于范围行锁的并行执行方法,具体步骤如下。As shown in FIG. 1 , an embodiment of the present invention provides a parallel execution method based on range row locks, and the specific steps are as follows.

步骤100:将单事务合并为多事务且设置多事务的提交LSN以及并行LSN,并将多事务注册到执行线程链表。Step 100: Merge a single transaction into multiple transactions, set commit LSNs and parallel LSNs for the multiple transactions, and register the multiple transactions into an execution thread linked list.

步骤200(单事务处理步骤):执行线程提取多事务中的下一个单事务开始执行并将该单事务的提交LSN作为分隔线LSN。本步骤中,由于执行线程执行的是多个单事务合并而成的多事务,那么它在执行时,要按多事务中合并的顺序来执行单事务。本实施例的下一个单事务指下一个待执行的单事务,例如刚开始进行执行时,第一个单事务就是“下一个单事务”,当后续执行完一个单事务,再重新进入该步骤时,原本的第二个单事务就是现在的“下一个单事务”,以此类推。Step 200 (single transaction processing step): the execution thread extracts the next single transaction in the multiple transactions and starts to execute it and uses the commit LSN of the single transaction as the separator LSN. In this step, since the execution thread executes multiple transactions formed by merging multiple single transactions, it must execute the single transactions in the order of merging in the multiple transactions when executing. The next single transaction in this embodiment refers to the next single transaction to be executed. For example, when the execution just starts, the first single transaction is the "next single transaction". When a single transaction is executed later and the step is re-entered, the original second single transaction is the current "next single transaction", and so on.

步骤300-步骤600:通过对操作类型、并行LSN大小、分隔线LSN大小以及ROWID范围锁是否冲突的判断来进入相对应的步骤。Step 300-Step 600: Enter the corresponding step by judging whether the operation type, parallel LSN size, separator LSN size and ROWID range lock conflict.

步骤700(线程提交步骤):判断当前单事务是否为最后一个单事务,若是则执行线程提交操作,若不是则重新进入单事务处理步骤。Step 700 (thread commit step): determine whether the current single transaction is the last single transaction, if so, execute the thread commit operation, if not, re-enter the single transaction processing step.

上述步骤300-步骤600具体包括步骤300、步骤400、步骤500以及步骤600。各步骤如下:The above steps 300 to 600 specifically include step 300, step 400, step 500 and step 600. Each step is as follows:

步骤300(操作类型判断步骤):根据当前单事务的下一个操作的操作类型来选择进入并行LSN判断步骤或线程提交步骤;Step 300 (operation type determination step): selecting to enter the parallel LSN determination step or the thread submission step according to the operation type of the next operation of the current single transaction;

步骤400(并行LSN判断步骤):根据当前操作的LSN以及排在当前执行线程之前的执行线程的并行LSN的大小来选择进入操作类型判断步骤或分隔线LSN判断步骤;Step 400 (parallel LSN determination step): select to enter the operation type determination step or the separator line LSN determination step according to the LSN of the current operation and the size of the parallel LSN of the execution thread before the current execution thread;

步骤500(分隔线LSN判断步骤):根据当前操作的LSN以及排在当前执行线程之前的执行线程的分隔线LSN的大小来选择进入冲突检测步骤或等待唤醒;Step 500 (separation line LSN determination step): select to enter the conflict detection step or wait for wake-up according to the LSN of the current operation and the size of the separation line LSN of the execution thread before the current execution thread;

步骤600(冲突检测步骤):根据当前操作的ROWID以及当前执行线程之前的执行线程的ROWID范围锁来判断是否冲突以选择进入操作类型判断步骤或等待唤醒。Step 600 (conflict detection step): determine whether there is a conflict based on the ROWID of the current operation and the ROWID range lock of the execution thread before the current execution thread to choose to enter the operation type determination step or wait for wake-up.

通过上述步骤100-步骤700,本发明实施例当多个执行线程并行执行多事务时,采用单事务的提交LSN来划分出不同的并行区间(也即设定分隔线LSN),然后通过操作类型判断、并行LSN判断、分隔线LSN判断以及冲突检测来决定是否并行执行,上述方案由于执行线程执行的多事务中存在多个单事务,那么通过使用每个单事务的提交LSN来划分不同的并行区间,多个执行线程执行时,落在相同并行区间的操作就可以通过ROWID冲突检测,把无冲突的操作并行执行来提升数据同步的效率。相对现有的方案,本实施例减少了一次对事务操作的遍历过程,可以优化那些无冲突数据同步操作的并行度,从而提升数据同步的性能。Through the above steps 100-700, when multiple execution threads execute multiple transactions in parallel, the embodiment of the present invention uses the commit LSN of a single transaction to divide different parallel intervals (i.e., sets the separator LSN), and then determines whether to execute in parallel through operation type judgment, parallel LSN judgment, separator LSN judgment, and conflict detection. Since there are multiple single transactions in the multiple transactions executed by the execution threads, the above scheme uses the commit LSN of each single transaction to divide different parallel intervals. When multiple execution threads execute, the operations falling in the same parallel interval can be detected through ROWID conflicts, and the conflict-free operations can be executed in parallel to improve the efficiency of data synchronization. Compared with the existing scheme, this embodiment reduces the traversal process of transaction operations once, and can optimize the parallelism of those conflict-free data synchronization operations, thereby improving the performance of data synchronization.

需说明的是,本实施例在开始执行事务前,还需进行如下准备工作:在源端数据库中部署数据同步服务的日志解析模块,负责解析日志操作,在目标端数据库中部署数据同步接收服务,负责接收源端数据同步服务发过来的操作并入库。It should be noted that before starting to execute transactions, this embodiment also needs to perform the following preparations: deploy a log parsing module of the data synchronization service in the source database, which is responsible for parsing log operations; deploy a data synchronization receiving service in the target database, which is responsible for receiving operations sent by the source data synchronization service and warehousing them.

目标端同步接收服务启动以后,需要初始化待执行链表、执行线程以及执行线程链表。其中,待执行链表用于将待执行的单事务按事务提交操作的LSN大小顺序存放在该链表中,等待执行入库。每个执行线程用于从待执行链表中提取多个单事务合并成多事务,把最后一个单事务的提交LSN设为该多事务的提交LSN,然后执行入库。执行线程链表用于将执行线程按当前待执行多事务提交LSN的大小先后顺序在该链表中进行注册,注册完成以后才能开始执行多事务的操作。After the target end synchronous receiving service is started, it is necessary to initialize the pending execution linked list, execution thread and execution thread linked list. Among them, the pending execution linked list is used to store the pending single transactions in the linked list in the order of the LSN size of the transaction submission operation, waiting for execution and storage. Each execution thread is used to extract multiple single transactions from the pending execution linked list and merge them into multiple transactions, set the submission LSN of the last single transaction as the submission LSN of the multiple transactions, and then execute and store them. The execution thread linked list is used to register the execution threads in the linked list in the order of the size of the submission LSN of the current multiple transactions to be executed. The operation of executing multiple transactions can only be started after the registration is completed.

还需说明的是,本实施例中的每个执行线程都需要初始化一个ROWID范围锁,并设定一个ROWID合并的最大间隔N,当当前操作的ROWID和现存的ROWID范围之差小于N时,把这个ROWID合并入现有的ROWID范围,从而达到减小ROWID对内存的占用。需说明的是,当前操作的ROWID和现存的ROWID范围之差指的是这个当前操作的ROWID和现存的ROWID范围最大值或最小值的差值,例如范围为【2,3】,当前操作的ROWID为1,那么差值为2-1=1;范围为【2,3】,当前操作的ROWID为5,那么差值为5-3=2。It should also be noted that each execution thread in this embodiment needs to initialize a ROWID range lock and set a maximum interval N for ROWID merging. When the difference between the ROWID of the current operation and the existing ROWID range is less than N, the ROWID is merged into the existing ROWID range, thereby reducing the memory usage of ROWID. It should be noted that the difference between the ROWID of the current operation and the existing ROWID range refers to the difference between the maximum value or minimum value of the ROWID of the current operation and the existing ROWID range. For example, if the range is [2,3] and the ROWID of the current operation is 1, then the difference is 2-1=1; if the range is [2,3] and the ROWID of the current operation is 5, then the difference is 5-3=2.

每个执行线程还需要初始化一个唤醒链表,用来存放那些等待自己执行或提交的执行线程。等待类型(唤醒类型)包括提交等待和执行等待两种。其中,提交等待表示当正在操作的执行线程提交时,才唤醒标记有提交等待类型的其他执行线程;执行等待表示当正在操作的执行线程执行完一个单事务后,提取下一个单事务的提交LSN作为分隔线LSN,如果该分隔线LSN大于唤醒链表上待执行操作的LSN时,才唤醒该待执行的执行线程。Each execution thread also needs to initialize a wake-up list to store the execution threads waiting for their own execution or submission. The waiting type (wake-up type) includes two types: submission waiting and execution waiting. Among them, submission waiting means that when the operating execution thread submits, other execution threads marked with submission waiting type will be awakened; execution waiting means that when the operating execution thread completes a single transaction, the submission LSN of the next single transaction is extracted as the separator LSN. If the separator LSN is greater than the LSN of the operation to be executed on the wake-up list, the execution thread to be executed will be awakened.

如图2所示,在本优选实施例中,步骤100(将单事务合并为多事务且设置多事务的提交LSN以及并行LSN,并将多事务注册到执行线程链表)具体包括如下步骤:As shown in FIG. 2 , in this preferred embodiment, step 100 (merging a single transaction into multiple transactions and setting the commit LSN and parallel LSN of the multiple transactions, and registering the multiple transactions into the execution thread linked list) specifically includes the following steps:

步骤101:目标端数据同步服务接收到源端操作后,对待执行的事务按提交操作的LSN大小顺序存入待执行链表。该步骤中,目标端数据同步服务在接收到源端操作以后还按操作的事务ID进行分类管理,当某个事务提交以后,才把该事务按提交操作的LSN大小顺序存入待执行链表。Step 101: After receiving the source operation, the target data synchronization service stores the transactions to be executed in the pending execution linked list in the order of the LSN size of the submitted operation. In this step, after receiving the source operation, the target data synchronization service also classifies and manages the transaction ID of the operation. After a transaction is submitted, the transaction is stored in the pending execution linked list in the order of the LSN size of the submitted operation.

步骤102:执行线程从待执行链表中按事务提交LSN的顺序摘取N个单事务合并成一个多事务,并将最后一个单事务的提交LSN设置为多事务的提交LSN,然后根据多事务的提交LSN在执行线程链表中进行注册。Step 102: The execution thread extracts N single transactions from the to-be-executed linked list in the order of transaction commit LSNs and merges them into a multi-transaction, sets the commit LSN of the last single transaction as the commit LSN of the multi-transaction, and then registers the multi-transaction in the execution thread linked list according to the commit LSN of the multi-transaction.

步骤103:执行线程将多事务中的第一个单事务的提交LSN设为并行LSN(参考步骤200将单事务的提交LSN作为分隔线LSN,所以这里的并行LSN也即第一个分隔线LSN),其它在该执行线程之后的执行线程准备执行的操作的LSN若小于该并行LSN,则进行并行执行。这些小于并行LSN的操作之所以可以并行执行,是因为这些操作在源端执行时也是并行的。Step 103: The execution thread sets the commit LSN of the first single transaction in the multi-transaction as the parallel LSN (refer to step 200, the commit LSN of the single transaction is used as the separator LSN, so the parallel LSN here is also the first separator LSN). If the LSN of the operations to be executed by other execution threads after the execution thread is smaller than the parallel LSN, they are executed in parallel. The reason why these operations smaller than the parallel LSN can be executed in parallel is that these operations are also executed in parallel at the source end.

在本优选实施例中,步骤200(单事务处理步骤)除了开始执行下一个单事务并确定当前的分隔线LSN外,还包括:判断当前执行线程的唤醒链表,将唤醒类型为执行等待并且执行LSN小于分隔线LSN的执行线程唤醒。这样一来可以使小于分隔线LSN的执行线程并行处理。In this preferred embodiment, step 200 (single transaction processing step) not only starts executing the next single transaction and determines the current separation line LSN, but also includes: judging the wake-up linked list of the current execution thread, and waking up the execution thread whose wake-up type is execution waiting and whose execution LSN is less than the separation line LSN. In this way, the execution threads whose execution LSN is less than the separation line LSN can be processed in parallel.

如图3所示,在本优选实施例中,步骤300(操作类型判断步骤)具体包括如下步骤:As shown in FIG. 3 , in this preferred embodiment, step 300 (operation type determination step) specifically includes the following steps:

步骤301:判断当前单事务的下一个操作的操作类型。操作类型指的是数据库的DML操作:包括INSERT(插入),UPDATE(更新)、DELETE(删除)、COMMIT(提交)和ROLLBACK(回滚)操作。Step 301: Determine the operation type of the next operation of the current single transaction. The operation type refers to the DML operation of the database: including INSERT, UPDATE, DELETE, COMMIT and ROLLBACK operations.

步骤302:若操作类型为提交操作则进入线程提交步骤(步骤700);否则进入并行LSN判断步骤(步骤400)。Step 302: If the operation type is a commit operation, then enter the thread commit step (step 700); otherwise enter the parallel LSN determination step (step 400).

如图4所示,在本优选实施例中,步骤400(并行LSN判断步骤)具体包括如下步骤:As shown in FIG. 4 , in this preferred embodiment, step 400 (parallel LSN determination step) specifically includes the following steps:

步骤401:判断当前操作的LSN是否小于所有排在当前执行线程之前的执行线程的并行LSN。该步骤也可理解为:获取当前操作的LSN,在执行线程链表中向前判断排在当前执行线程之前的执行线程的并行LSN是否都大于该执行操作的LSN。Step 401: Determine whether the LSN of the current operation is smaller than the parallel LSNs of all execution threads that are arranged before the current execution thread. This step can also be understood as: obtaining the LSN of the current operation, and determining whether the parallel LSNs of the execution threads that are arranged before the current execution thread in the execution thread linked list are all larger than the LSN of the execution operation.

步骤402:若是则执行当前操作并提取当前操作的ROWID并入当前执行线程的ROWID范围锁,然后进入操作类型判断步骤(步骤300);若否则进入分隔线LSN判断步骤(步骤500)。在该步骤中,在把当前操作的ROWID并入当前执行线程的ROWID范围锁时,当ROWID和现存的ROWID范围之差小于N时,才把这个ROWID合并入现有的ROWID范围锁。Step 402: If yes, execute the current operation and extract the ROWID of the current operation and merge it into the ROWID range lock of the current execution thread, and then enter the operation type judgment step (step 300); if no, enter the separation line LSN judgment step (step 500). In this step, when merging the ROWID of the current operation into the ROWID range lock of the current execution thread, this ROWID is merged into the existing ROWID range lock only when the difference between the ROWID and the existing ROWID range is less than N.

如图5所示,在本优选实施例中,步骤500(分隔线LSN判断步骤)具体包括如下步骤:As shown in FIG. 5 , in this preferred embodiment, step 500 (separation line LSN determination step) specifically includes the following steps:

步骤501:判断当前操作的LSN是否小于所有排在当前执行线程之前的执行线程的分隔线LSN。该步骤也可理解为:获取当前操作的LSN,在执行线程链表中向前判断排在当前执行线程之前的执行线程的分隔线LSN是否都大于该执行操作的LSN。Step 501: Determine whether the LSN of the current operation is less than the LSN of the dividing lines of all execution threads that are arranged before the current execution thread. This step can also be understood as: obtaining the LSN of the current operation, and determining whether the LSN of the dividing lines of the execution threads that are arranged before the current execution thread in the execution thread linked list are all greater than the LSN of the execution operation.

步骤502:若是则进入冲突检测步骤(步骤600);若否则从后向前查找到第一个分隔线LSN小于当前操作的LSN的执行线程,并将当前执行线程添加到该查找到的执行线程的唤醒链表中,且将唤醒类型标记为执行等待,然后挂起等待被唤醒。在该步骤中,由于处在上一个并行区间的执行线程还没有执行完该区间内的操作,那么它在该并行区间内操作的ROWID信息就还未被提取,这时,排在后面的并行区间执行操作时就无法通过ROWID冲突检测机制来判断操作冲突,需要等待处在上一个并行区间的执行线程完成执行并构造出该区间的ROWID范围锁以后才能进行冲突检测,也即是说只有排在当前执行线程之前的执行线程的分隔线LSN都大于该执行操作的LSN时,才能进入冲突检测步骤。Step 502: If yes, then enter the conflict detection step (step 600); if not, find the first execution thread whose dividing line LSN is smaller than the LSN of the current operation from back to front, and add the current execution thread to the wake-up list of the found execution thread, and mark the wake-up type as execution waiting, and then suspend waiting to be awakened. In this step, since the execution thread in the previous parallel interval has not yet completed the operation in the interval, the ROWID information of its operation in the parallel interval has not yet been extracted. At this time, when the parallel interval behind executes the operation, it cannot judge the operation conflict through the ROWID conflict detection mechanism. It needs to wait for the execution thread in the previous parallel interval to complete the execution and construct the ROWID range lock of the interval before conflict detection can be performed. That is to say, only when the dividing line LSN of the execution thread before the current execution thread is greater than the LSN of the execution operation, can the conflict detection step be entered.

如图6所示,在本优选实施例中,步骤600(冲突检测步骤)具体包括如下步骤:As shown in FIG. 6 , in this preferred embodiment, step 600 (conflict detection step) specifically includes the following steps:

步骤601:提取当前操作的ROWID,并判断该ROWID是否落在当前执行线程之前的执行线程的ROWID范围锁内。该步骤可理解为:提取当前操作的ROWID,使用该ROWID在排在执行线程链表前面的执行线程的ROWID范围锁中定位,以判断该ROWID是否落在上述ROWID范围锁内。Step 601: extract the ROWID of the current operation, and determine whether the ROWID falls within the ROWID range lock of the execution thread before the current execution thread. This step can be understood as: extract the ROWID of the current operation, use the ROWID to locate in the ROWID range lock of the execution thread in front of the execution thread linked list, to determine whether the ROWID falls within the above ROWID range lock.

步骤602:若是即表示存在冲突,则将当前执行线程添加到存在冲突的执行线程的唤醒链表中,且将唤醒类型标记为提交等待,然后挂起等待被唤醒;若否即表示不存在冲突,则执行当前操作,并提取当前操作的ROWID并入当前执行线程的ROWID范围锁,然后进入操作类型判断步骤(步骤300)。在该步骤中,在把当前操作的ROWID并入当前执行线程的ROWID范围锁时,当ROWID和现存的ROWID范围之差小于N时,才把这个ROWID合并入现有的ROWID范围锁。Step 602: If yes, that means there is a conflict, then add the current execution thread to the wakeup list of the conflicting execution thread, and mark the wakeup type as submission waiting, and then suspend waiting to be awakened; if no, that means there is no conflict, then execute the current operation, extract the ROWID of the current operation and merge it into the ROWID range lock of the current execution thread, and then enter the operation type judgment step (step 300). In this step, when merging the ROWID of the current operation into the ROWID range lock of the current execution thread, when the difference between the ROWID and the existing ROWID range is less than N, this ROWID is merged into the existing ROWID range lock.

在本优选实施例中,步骤700(线程提交步骤)中的线程提交操作具体包括:对本执行线程进行提交并将唤醒链表中等待的其他执行线程全部唤醒,然后将本执行线程从执行线程链表中移除且释放掉ROWID范围锁。In this preferred embodiment, the thread submission operation in step 700 (thread submission step) specifically includes: submitting the current execution thread and waking up all other execution threads waiting in the wake-up list, and then removing the current execution thread from the execution thread list and releasing the ROWID range lock.

以上为对本实施例提供的方法的各个步骤的详细说明,而这些步骤合为一体后具体的事务执行流程则如图7所示,具体事务执行流程如下:目标端同步服务开始工作;执行线程合并单事务为多事务并注册到执行线程链表;然后设置第一个单事务的提交LSN为并行LSN;然后提取下一个单事务,把它的LSN作为分隔线LSN,同时把唤醒链表中满足条件的执行线程唤醒;然后提取当前单事务的下一个操作,判断它是否是提交操作,若是,再判断是否是最后一个单事务,若是则提交并把唤醒链表中所有的执行线程唤醒,至此完成该执行线程的流程,若不是最后一个单事务则重新进入“提取下一个单事务,把它的LSN作为分隔线LSN”的步骤;判断是否是提交操作时,若不是,则再判断执行LSN是否都小于之前的并行LSN,若是则执行操作入库并提取操作ROWID,把它并入ROWID范围锁,然后再重新进入“提取当前单事务的下一个操作”的步骤;若判断执行LSN是否都小于之前的并行LSN时判断为否,则再判断执行LSN是否都小于之前的分隔线LSN,若否则将执行线程添加到前面执行线程的唤醒链表,唤醒类型为执行等待;若判断执行LSN是否都小于之前的分隔线LSN时判断为是,则再在排在前面的执行线程的ROWID范围锁中进行冲突检测,若存在冲突,则将本执行线程添加到冲突执行线程的唤醒链表,并将唤醒类型设为提交等待,若不冲突,则执行操作入库,并提取操作ROWID,把它并入ROWID范围锁,然后重新进入“提取当前单事务的下一个操作”的步骤。The above is a detailed description of each step of the method provided in this embodiment, and the specific transaction execution process after these steps are combined into one is shown in Figure 7. The specific transaction execution process is as follows: the target end synchronization service starts working; the execution thread merges the single transaction into multiple transactions and registers them to the execution thread linked list; then the commit LSN of the first single transaction is set to the parallel LSN; then the next single transaction is extracted, its LSN is used as the separator LSN, and the execution threads that meet the conditions in the wake-up linked list are awakened at the same time; then the next operation of the current single transaction is extracted to determine whether it is a commit operation. If so, then determine whether it is the last single transaction. If so, commit and wake up all the execution threads in the wake-up linked list, and the process of the execution thread is completed. If it is not the last single transaction, re-enter the step of "extracting the next single transaction and using its LSN as the separator LSN"; when determining whether it is a commit operation, if not, then determine whether the execution LSN are all smaller than the previous parallel LSN. If so, the operation is executed and stored in the warehouse and the operation ROWID is extracted, and it is merged into the ROWID range lock, and then the step of "extracting the next operation of the current single transaction" is re-entered; if it is judged that the execution LSN is smaller than the previous parallel LSN, the result is no, then the execution LSN is judged that the execution LSN is smaller than the previous dividing line LSN, if not, the execution thread is added to the wake-up list of the previous execution thread, and the wake-up type is execution wait; if it is judged that the execution LSN is smaller than the previous dividing line LSN, the result is yes, then a conflict detection is performed in the ROWID range lock of the execution thread in front, if there is a conflict, the execution thread is added to the wake-up list of the conflicting execution thread, and the wake-up type is set to commit wait, if there is no conflict, the operation is executed and stored in the warehouse, and the operation ROWID is extracted, and it is merged into the ROWID range lock, and then the step of "extracting the next operation of the current single transaction" is re-entered.

综上所述,本实施例在多个执行线程并行执行多事务时,采用单事务的提交LSN来划分出不同的并行区间(也即设定分隔线LSN),在划分出的第一个并行区间(也即第一个分隔线LSN之前的区间),多个执行线程中操作LSN落在此区间的操作可以无条件的并行,因为这些操作访问的资源并不冲突。其次,从划分出的第二个并行区间(也即第一个分隔线LSN之后的区间)开始,提交LSN排在后面的执行线程在此区间可能会访问到提交LSN排在前面的执行线程在第一并行区间修改的数据,但此时这些数据的修改还没有提交,那么后面的执行线程就可能会访问不到它想要的数据,针对这种情况,后面的执行线程在并行执行时要先确保处在前面并行区间的执行线程已经构造完该区间的ROWID范围锁,然后再通过ROWID冲突检测的方式,如果当前待执行操作的ROWID落在了排在之前执行线程的ROWID范围锁里面,那就说明存在数据冲突,否则,就可以和前面的事务并行执行。In summary, when multiple execution threads execute multiple transactions in parallel, the present embodiment uses the submission LSN of a single transaction to divide different parallel intervals (i.e., set the separation line LSN). In the divided first parallel interval (i.e., the interval before the first separation line LSN), the operations of multiple execution threads whose operation LSN falls in this interval can be unconditionally parallel, because the resources accessed by these operations do not conflict. Secondly, starting from the divided second parallel interval (i.e., the interval after the first separation line LSN), the execution thread whose submission LSN is ranked behind may access the data modified by the execution thread whose submission LSN is ranked ahead in the first parallel interval in this interval, but the modification of these data has not been submitted at this time, so the subsequent execution thread may not be able to access the data it wants. In view of this situation, the subsequent execution thread must first ensure that the execution thread in the previous parallel interval has constructed the ROWID range lock of the interval when executing in parallel, and then use the ROWID conflict detection method. If the ROWID of the current operation to be executed falls into the ROWID range lock of the previous execution thread, it means that there is a data conflict. Otherwise, it can be executed in parallel with the previous transaction.

上述方案不仅适用采用了事务合并来优化同步性能的场景,而且在构造ROWID范围锁时采取的是边执行边构造的方式,不用在执行之前先构造,相对现有的方案,本实施例的方案减少了一次对事务操作的遍历过程,可以优化那些无冲突数据同步操作的并行度,从而提升数据同步的性能,并且还减小了ROWID对内存的占用。The above solution is not only applicable to the scenario where transaction merging is used to optimize synchronization performance, but also adopts a construction-while-execution approach when constructing the ROWID range lock, without the need to construct it before execution. Compared with the existing solution, the solution of this embodiment reduces the traversal process of transaction operations once, can optimize the parallelism of those conflict-free data synchronization operations, thereby improving the performance of data synchronization, and also reducing the memory usage of ROWID.

实施例2:Embodiment 2:

基于实施例1提供的基于范围行锁的并行执行方法,本实施例2通过一个具体的应用场景来对本发明进行更详细的说明。Based on the parallel execution method based on range row locks provided in Example 1, this Example 2 describes the present invention in more detail through a specific application scenario.

本实施例设ROWID范围锁合并的最大间隔N为10。In this embodiment, the maximum interval N of ROWID range lock merging is set to 10.

本实施例中的源端数据库的表T1(DATA INT)存在3行数据,它的数据在数据库中分布如下:In this embodiment, table T1 (DATA INT) of the source database contains 3 rows of data, and its data is distributed in the database as follows:

ROWIDROWID DATA列DATA column 11 11 22 22 33 33

源端有如下日志操作:The source side has the following log operations:

具体的,基于上述应用场景,本实施例2基于实施例1所体现的执行线程的建立步骤如下:Specifically, based on the above application scenario, the steps for establishing the execution thread embodied in Embodiment 1 in Embodiment 2 are as follows:

1.创建两个执行线程A和B。1. Create two execution threads A and B.

2.其中执行线程A提取单事务ID为1和2的事务合并成一个多事务,把单事务2的提交LSN 7作来该多事务的提交LSN,并在执行线程链表中注册。(各个单事务的提交LSN参考操作COMMIT对应的LSN)2. Execution thread A extracts transactions with single transaction IDs 1 and 2 and merges them into a multi-transaction. It uses the commit LSN 7 of single transaction 2 as the commit LSN of the multi-transaction and registers it in the execution thread linked list. (The commit LSN of each single transaction refers to the LSN corresponding to the COMMIT operation)

3.执行线程B提取单事务ID为3和4的事务合并成一个多事务,把单事务4的提交LSN 9作来该多事务的提交LSN,并在执行线程链表中注册,这时,执行线程链表中已经存在了执行线程A,由于B的提交LSN比A大,所以在执行线程链表中A排在B的前面。3. Execution thread B extracts transactions with single transaction IDs 3 and 4 and merges them into a multi-transaction. It uses the commit LSN 9 of single transaction 4 as the commit LSN of the multi-transaction and registers it in the execution thread linked list. At this time, execution thread A already exists in the execution thread linked list. Since B's commit LSN is larger than A's, A is ranked ahead of B in the execution thread linked list.

4.执行线程A根据单事务的提交LSN划分出并行区间[1-3]和[3-7],并把第一个单事务(单事务1)的提交LSN 3设置为并行LSN。4. Execution thread A divides the parallel intervals into [1-3] and [3-7] according to the commit LSN of the single transaction, and sets the commit LSN 3 of the first single transaction (single transaction 1) as the parallel LSN.

5.执行线程B根据单事务的提交LSN划分出并行区间[7-8]和[8-9],并把第一个单事务(单事务3)的提交LSN 8设置为并行LSN。5. Execution thread B divides the parallel intervals into [7-8] and [8-9] according to the commit LSN of the single transaction, and sets the commit LSN 8 of the first single transaction (single transaction 3) as the parallel LSN.

6.执行线程A和B开始并行执行。6. Execution threads A and B start executing in parallel.

以上执行线程A和B建立且完成准备工作后,正式进入并行执行阶段,该阶段的流程参考如下表格:After the above execution threads A and B are established and the preparation work is completed, they officially enter the parallel execution stage. The process of this stage is referred to the following table:

通过本实施例,可以从上面的并行执行的流程中看出,执行线程B执行LSN为2的操作时,由于它小于执行线程A的并行LSN,所以可以无条件的并行,这是提升同步性能的一个点,执行LSN为5的操作时,它需要等待执行线程A完成单事务1的所有操作,构造完ROWID范围锁以后,把当前操作的ROWID在执行线程A中进行冲突检测,检测没冲突以后再并行执行,这又是提升同步性能的一个点,在执行LSN为6的操作时,通过ROWID冲突检测到了和执行线程A存在访问数据上的冲突,把自己添加到了执行线程A的唤醒链表中,等执行线程A提交以后再次执行,从而保证了并行执行时数据同步的一致性。(需说明,上述表格中的空格处是可以做操作的,此表格是为了显示的突出本方案的特点,所以把它暂停了,这样才能清楚的显示出两个线程之间交互关系)Through this embodiment, it can be seen from the above parallel execution process that when execution thread B executes an operation with LSN of 2, it can be executed in parallel unconditionally because it is smaller than the parallel LSN of execution thread A. This is a point to improve synchronization performance. When executing an operation with LSN of 5, it needs to wait for execution thread A to complete all operations of single transaction 1. After constructing the ROWID range lock, the ROWID of the current operation is detected for conflict in execution thread A. After detecting that there is no conflict, parallel execution is performed. This is another point to improve synchronization performance. When executing an operation with LSN of 6, the ROWID conflict detects that there is a conflict in accessing data with execution thread A, and adds itself to the wake-up linked list of execution thread A. After execution thread A submits, it is executed again, thereby ensuring the consistency of data synchronization during parallel execution. (It should be noted that the blank spaces in the above table can be operated. This table is paused to highlight the characteristics of this solution, so that the interaction between the two threads can be clearly displayed)

对比本实施例和现有的方案可以看出,本实施例利用多事务中单事务的提交LSN来划分出并行区间,再结合ROWID冲突检测的方式,把无冲突的操作并行执行来提升同步的性能,该方案不仅采用了事务合并的优化手段,而且采用边执行边提取ROWID的方式并结合ROWID范围锁来减轻了ROWID提取对数据同步的性能影响,并减小了ROWID对内存的占用。By comparing this embodiment with the existing solutions, it can be seen that this embodiment uses the commit LSN of a single transaction in multiple transactions to divide the parallel intervals, and then combines the ROWID conflict detection method to execute non-conflicting operations in parallel to improve the synchronization performance. This solution not only uses the optimization method of transaction merging, but also uses the method of extracting ROWID while executing and combining ROWID range locks to reduce the performance impact of ROWID extraction on data synchronization and reduce the memory usage of ROWID.

实施例3:Embodiment 3:

在上述实施例1至实施例2提供的基于范围行锁的并行执行方法的基础上,本发明还提供了一种可用于实现上述方法的基于范围行锁的并行执行设备,如图8所示,是本发明实施例的设备架构示意图。本实施例的基于范围行锁的并行执行设备包括一个或多个处理器21以及存储器22。其中,图8中以一个处理器21为例。On the basis of the parallel execution method based on range row locks provided in the above-mentioned embodiments 1 and 2, the present invention further provides a parallel execution device based on range row locks that can be used to implement the above-mentioned method, as shown in FIG8 , which is a schematic diagram of the device architecture of an embodiment of the present invention. The parallel execution device based on range row locks of this embodiment includes one or more processors 21 and a memory 22. Among them, FIG8 takes one processor 21 as an example.

处理器21和存储器22可以通过总线或者其他方式连接,图8中以通过总线连接为例。The processor 21 and the memory 22 may be connected via a bus or other means, and FIG8 takes the connection via a bus as an example.

存储器22作为一种非易失性计算机可读存储介质,可用于存储非易失性软件程序、非易失性计算机可执行程序以及模块,如实施例1至实施例2中的基于范围行锁的并行执行方法、系统。处理器21通过运行存储在存储器22中的非易失性软件程序、指令以及模块,从而执行基于范围行锁的并行执行设备的各种功能应用以及数据处理,即实现实施例1至实施例2的基于范围行锁的并行执行方法。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 and system based on range row locks in Embodiments 1 and 2. The processor 21 executes various functional applications and data processing of the parallel execution device based on range row locks by running the non-volatile software programs, instructions and modules stored in the memory 22, that is, implements the parallel execution method based on range row locks in Embodiments 1 and 2.

存储器22可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件。在一些实施例中,存储器22可选包括相对于处理器21远程设置的存储器,这些远程存储器可以通过网络连接至处理器21。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。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 devices. 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.

程序指令/模块存储在存储器22中,当被一个或者多个处理器21执行时,执行上述实施例1至实施例2中的基于范围行锁的并行执行方法,例如,执行以上描述的图1至图7所示的各个步骤。The program instructions/modules are stored in the memory 22, and when executed by one or more processors 21, the parallel execution method based on range row locks in the above-mentioned embodiments 1 to 2 is executed, for example, the various steps shown in Figures 1 to 7 described above are executed.

本领域普通技术人员可以理解实施例的各种方法中的全部或部分步骤是可以通过程序来指令相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:只读存储器(ReadOnlyMemory,简写为:ROM)、随机存取存储器(RandomAccessMemory,简写为:RAM)、磁盘或光盘等。A person skilled in the art may understand that all or part of the steps in the various methods of the embodiments may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims (8)

1. A range line lock based parallel execution method, comprising:
Merging the single transactions into multiple transactions, setting commit LSNs and parallel LSNs of the multiple transactions, and registering the multiple transactions to an execution thread linked list; the method specifically comprises the following steps: after receiving the source operation, the target data synchronization service stores the transaction to be executed into a linked list to be executed according to the LSN size sequence of the submitting operation; the execution thread extracts N single transactions from the linked list to be executed according to the sequence of the transaction commit LSNs, merges the N single transactions into a multi-transaction, sets the commit LSN of the last single transaction as the commit LSN of the multi-transaction, and registers the multi-transaction commit LSN in the execution thread linked list; the execution thread sets the commit LSN of the first single transaction in the multi-transaction as a parallel LSN, and if the LSN of the operation which is ready to be executed by the execution thread after the execution thread is smaller than the parallel LSN, the execution thread performs parallel execution;
single transaction processing step: the execution thread extracts the next single transaction in the multi-transaction to start execution and takes the commit LSN of the single transaction as a separation line LSN;
Entering a corresponding step by judging whether the operation type, the parallel LSN size, the separation line LSN size and the ROWID range lock conflict or not; the method specifically comprises the following steps: an operation type judging step: selecting to enter a parallel LSN judging step or a thread submitting step according to the operation type of the next operation of the current single transaction; parallel LSN judging step: selecting an entering operation type judging step or a separation line LSN judging step according to the LSN of the current operation and the sizes of the parallel LSNs of all execution threads arranged before the current execution thread; and a separation line LSN judgment step: selecting to enter a conflict detection step or wait for awakening according to the LSN of the current operation and the size of a separation line LSN of an execution thread arranged before the current execution thread; and a conflict detection step: judging whether conflict exists according to ROWID of the current operation and ROWID range locks of the execution threads before the current execution thread so as to select to enter an operation type judging step or wait for awakening;
thread submitting step: judging whether the current single transaction is the last single transaction, if so, executing thread submitting operation, and if not, re-entering the single transaction processing step.
2. The range-line lock based parallel execution method of claim 1, wherein the single transaction step further comprises: judging a wake-up linked list of the current execution thread, and waking up the execution thread with the wake-up type of execution waiting and execution LSN smaller than that of the separation line LSN.
3. The parallel execution method based on range line lock according to claim 1, wherein the operation type determining step specifically includes: judging the operation type of the next operation of the current single transaction, and entering a thread submitting step if the operation type is a submitting operation; otherwise, enter the parallel LSN judgement step.
4. The parallel execution method based on range line lock according to claim 3, wherein the parallel LSN determining step specifically includes: judging whether the LSN of the current operation is smaller than the parallel LSNs of all execution threads arranged in front of the current execution thread, if so, executing the current operation, extracting ROWID of the current operation, merging the ROWID range lock of the current execution thread, and then entering an operation type judging step; if not, entering a separation line LSN judgment step.
5. The parallel execution method based on range line lock according to claim 4, wherein the separation line LSN determining step specifically includes: judging whether the LSN of the current operation is smaller than the LSN of all the partition lines of the execution threads arranged before the current execution thread, if so, entering a conflict detection step; if not, searching the execution thread with the first separation line LSN smaller than the LSN of the current operation from the back to the front, adding the current execution thread into a wake-up linked list of the searched execution thread, and marking the wake-up type as execution waiting.
6. The parallel execution method based on range line lock according to claim 5, wherein the collision detection step specifically includes: extracting ROWID of the current operation, judging whether the ROWID falls in a ROWID range lock of an execution thread before the current execution thread, if yes, adding the current execution thread into a wakeup linked list of the execution thread with conflict, and marking the wakeup type as commit waiting; if not, the current operation is executed, and ROWID of the current operation is extracted and incorporated into the ROWID range lock of the current execution thread, and then an operation type judging step is carried out.
7. The parallel execution method based on range line lock according to any one of claims 1 to 6, wherein the thread commit operation in the thread commit step specifically includes: and submitting the execution thread, waking up all other execution threads waiting in the wake-up linked list, and then removing the execution thread from the execution thread linked list and releasing ROWID range locks.
8. A range line lock based parallel execution device, characterized by:
Comprising at least one processor and a memory connected by a data bus, the memory storing instructions for execution by the at least one processor, the instructions, when executed by the processor, for performing the range-line lock based parallel execution method of any of claims 1-7.
CN202111501972.5A 2021-12-09 2021-12-09 A parallel execution method and device based on range row lock Active CN114296886B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111501972.5A CN114296886B (en) 2021-12-09 2021-12-09 A parallel execution method and device based on range row lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111501972.5A CN114296886B (en) 2021-12-09 2021-12-09 A parallel execution method and device based on range row lock

Publications (2)

Publication Number Publication Date
CN114296886A CN114296886A (en) 2022-04-08
CN114296886B true CN114296886B (en) 2024-11-08

Family

ID=80968562

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111501972.5A Active CN114296886B (en) 2021-12-09 2021-12-09 A parallel execution method and device based on range row lock

Country Status (1)

Country Link
CN (1) CN114296886B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117608791B (en) * 2023-12-01 2024-08-06 成都北中网芯科技有限公司 Split thread scheduling method and verification method thereof
CN119473518A (en) * 2024-11-15 2025-02-18 武汉达梦数据库股份有限公司 A method, device and system for setting transaction operation dependency based on log sequence
CN120045626B (en) * 2025-04-25 2025-08-29 北京镜舟科技有限公司 Distributed database system disaster recovery method and system based on cross-cluster data synchronization

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107077495A (en) * 2014-10-19 2017-08-18 微软技术许可有限责任公司 High performance transaction in data base management system
CN111858503A (en) * 2020-06-04 2020-10-30 武汉达梦数据库有限公司 Parallel execution method and data synchronization system based on log analysis synchronization

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9128750B1 (en) * 2008-03-03 2015-09-08 Parakinetics Inc. System and method for supporting multi-threaded transactions
US11429628B2 (en) * 2019-09-20 2022-08-30 Samsung Electronics Co., Ltd. Transaction grouping for overwrite merge
CN112035222B (en) * 2020-07-30 2022-04-19 武汉达梦数据库股份有限公司 Transaction operation merging execution method and device based on log analysis synchronization

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107077495A (en) * 2014-10-19 2017-08-18 微软技术许可有限责任公司 High performance transaction in data base management system
CN111858503A (en) * 2020-06-04 2020-10-30 武汉达梦数据库有限公司 Parallel execution method and data synchronization system based on log analysis synchronization

Also Published As

Publication number Publication date
CN114296886A (en) 2022-04-08

Similar Documents

Publication Publication Date Title
CN114296886B (en) A parallel execution method and device based on range row lock
CN111858626B (en) Parallel execution-based data synchronization method and device
CN111858503B (en) Parallel execution method and data synchronization system based on log analysis synchronization
CN111858504B (en) Operation merging execution method based on log analysis synchronization and data synchronization system
US11625389B2 (en) Snapshot isolation query transactions in distributed systems
CN108874588A (en) A kind of database instance restoration methods and device
CN111858505B (en) Parallel execution method and data synchronization system based on log analysis synchronization
CN107710203A (en) Transaction database layer on distributed key/value thesaurus
US12079205B2 (en) Snapshot isolation query transactions in distributed systems
WO2024098363A1 (en) Multicore-processor-based concurrent transaction processing method and system
CN105045563B (en) A kind of method for collision management for speculating nested software transaction storage
CN113377502B (en) Transaction processing method, device, server, database management system and medium
CN114296887B (en) A parallel execution method and device based on transaction merging
CN114296885B (en) A parallel execution method and device based on transaction merging
CN114297291B (en) Transaction combination-based parallel execution method and device
CN111930693B (en) Transaction merging execution method and device based on log analysis synchronization
CN116680041A (en) Transaction processing system and method for multi-version concurrency control oriented to separate memory
CN112612647B (en) Log parallel replay method, device, equipment and storage medium
CN119473516B (en) Method, device and system for setting operation dependency based on rollback impact
CN119473520B (en) Method, device and system for collecting conflicting TRXID setting operation dependencies during rollback
JP4139642B2 (en) Database management method and system
CN119376866B (en) A method, device and system for parallel execution of operations based on a conflicting transaction linked list
Wang et al. TXSQL: Lock Optimizations Towards High Contented Workloads (Extended Version)
CN119066081A (en) Optimization method, device and system for target-side concurrency in database synchronization
CN117687807A (en) Data processing method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant