WO2011009274A1 - Method and apparatus of concurrency control - Google Patents

Method and apparatus of concurrency control Download PDF

Info

Publication number
WO2011009274A1
WO2011009274A1 PCT/CN2009/076082 CN2009076082W WO2011009274A1 WO 2011009274 A1 WO2011009274 A1 WO 2011009274A1 CN 2009076082 W CN2009076082 W CN 2009076082W WO 2011009274 A1 WO2011009274 A1 WO 2011009274A1
Authority
WO
WIPO (PCT)
Prior art keywords
lock
transaction
concurrency control
granted
control method
Prior art date
Application number
PCT/CN2009/076082
Other languages
French (fr)
Chinese (zh)
Inventor
印和平
常二鹏
卢勤元
丁奇鹏
陈河堆
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2011009274A1 publication Critical patent/WO2011009274A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details

Definitions

  • the present invention relates to the field of databases, and in particular to a concurrency control method and apparatus. Background technique
  • a database is a shared resource.
  • multiple transactions will access the same database at the same time. This leads to various conflicts.
  • the transactions T1 and ⁇ 2 may have the following three types of conflicts during concurrent execution:
  • Serial scheduling guarantees data consistency, but it is not conducive to system performance. Therefore, the Database Management System (DBMS) must provide transaction concurrency control mechanisms.
  • Serializable is the criterion for the correctness of concurrent transactions, so a given concurrency control is properly controlled if and only if it is serializable.
  • Strict 2-Phase Locking (Strict 2PL) protocol guarantees the serializability of concurrency control. Its contents are as follows: 1) Read/write lock must be added before reading/writing database objects; 2) Transaction After execution (commit or rollback), release the lock it owns.
  • a concurrency control method is provided in the related art, which is performed on a database that is operated Record locks and queue other concurrent transactions to prevent the record from being modified by other transactions at the same time.
  • the concurrency control method in the related art causes all concurrent transactions requesting operations on the same database record to enter the waiting queue until the lock operation is released after the lock transaction execution ends, and other concurrent transactions can be operated on the database again.
  • the concurrency of transaction control is low, and concurrency control is poor.
  • the present invention is directed to a concurrency control method and apparatus, which can solve the concurrency control method in the related art, so that all concurrent transactions requesting operations on the same database record enter the waiting queue until the lock transaction is terminated, and the lock is released. After that, other concurrent transactions can be operated on the database again, resulting in low concurrency of transaction control and poor system performance.
  • a concurrency control method including the following steps: determining, according to a lock relationship table, whether a to-be-operated location of a transaction has a lock that conflicts with a lock to be granted, and the lock relationship table is used to save a transaction and a lock. The relationship; grants a lock to the transaction based on the result of the judgment, and executes the transaction; when the execution of the transaction ends, the lock held by the transaction is released, and the lock of the released lock that does not need to continue waiting is granted to other concurrent transactions.
  • the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking queued waiting locks; and a linked list for associating transactions With a lock.
  • the lock is granted to the transaction according to the judgment result, and executing the transaction specifically includes: if the to-be-operated position of the transaction has no lock, grant the lock to the transaction, and execute the transaction.
  • the lock is granted to the transaction according to the judgment result
  • the executing the transaction specifically includes: if there is a lock in the to-be-operated position of the transaction, checking whether there is a conflict between the existing lock and the lock to be granted; The transaction grants a lock and executes the transaction.
  • a lock is granted to the transaction according to the check result
  • the line transaction specifically includes: If there is no conflict between the existing lock and the pending lock, the lock is granted to the transaction, and the transaction is executed.
  • the lock is granted to the transaction according to the check result, and executing the transaction specifically includes: if the existing lock conflicts with the pending latch, setting the transaction queue waiting until the lock is to be re-acquired; executing the transaction.
  • the executing transaction includes at least one of the following: performing an adding operation, performing a deleting operation, performing a modifying operation, and performing a reading operation.
  • the end of the transaction execution includes: a transaction completion submission or a transaction completion rollback.
  • granting the lock that does not need to continue waiting in the released lock to the other concurrent transaction specifically includes: detecting, for each lock in the linked list of the released lock, whether there is a waiting flag; when there is a waiting flag And when the detected lock does not have a lock type conflict with other locks at the same operation position of other concurrent transactions, the detected lock is granted to other concurrent transactions, and other concurrent transactions are resumed.
  • the lock types include shared locks and exclusive locks. .
  • a concurrency control device including: a judging module, configured to determine, according to the lock relationship table, whether a to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is used. The relationship between the transaction and the lock is saved; the execution module is configured to grant a lock to the transaction according to the judgment result, and execute the transaction; and release the module, when the transaction execution ends, release the lock held by the transaction, and the released lock does not need to continue The waiting lock is granted to other concurrent transactions.
  • the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking the queued waiting lock; a linked list for the associated transaction With a lock.
  • FIG. 1 is a flow chart showing a concurrency control method according to a first embodiment of the present invention
  • FIG. 2 is a view showing a lock hash table used in the concurrency control method of FIG.
  • FIG. 3 is a flow chart showing a concurrency control method according to a second embodiment of the present invention.
  • FIG. 4 is a block diagram showing a concurrency control device according to a third embodiment of the present invention.
  • FIG. 1 shows a flow chart of a concurrency control method according to a first embodiment of the present invention, the method comprising the following steps:
  • Step S101 when the database is operated, determining, according to the lock relationship table, whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is configured to save the relationship between the transaction and the lock; Step S102, according to the judgment result, the transaction Grant a lock, and execute a transaction;
  • Step S103 when the execution of the transaction ends, the lock held by the transaction is released, and the lock of the released lock that does not need to continue to wait is granted to other concurrent transactions.
  • the lock relationship table it is determined whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and then the lock is granted to the transaction according to the judgment result, and the transaction is executed, and finally, when the execution of the transaction ends, the transaction is held. Lock, and grant the lock that does not need to wait for the released lock to other concurrent transactions. Since the lock relationship table is used to save the relationship between the transaction and its corresponding lock, it is possible to judge whether there is a conflict between different locks pointing to the same to-be-operated position.
  • the concurrency control method has low concurrency for transaction control and poor system performance, which improves the concurrency of transaction control and improves the concurrency control effect.
  • the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking queued waiting locks; and a linked list for associating transactions With a lock.
  • the lock relationship table in this embodiment specifically includes a transaction list, a lock hash table, and a lock list.
  • the setting of the above table enables the concurrency control method of the embodiment to effectively manage transactions and locks, including fast index positioning and traversal search. And so on, further determining whether there is a conflict in different locks pointing to the same to-be-operated position, and providing strong support for the above-mentioned concurrency control method.
  • the transaction list holds transaction information of other transactions executed concurrently in the system at the time of execution of the current transaction, and is inserted according to the principle that the latecomer inserts into the queue.
  • the transaction information includes the transaction ID, the transaction type, the pointer to the front and rear nodes in the transaction list, and the chain. Table header pointers, etc.
  • Each time a transaction is started the transaction is inserted into the transaction list, and the transaction information for that transaction is saved to the transaction list.
  • the transaction structure contains a thread structure information, which contains the event object. When the transaction is suspended due to waiting for the lock, the thread executing the transaction waits for the event object. When the transaction grants the lock and is awakened, the thread that granted the lock sets the event object. .
  • FIG. 2 is a schematic diagram of a lock hash table used in the concurrency control method of FIG. 1. As shown in FIG. 2, each entry of the lock hash table corresponds to a header of a linked list, so that the lock is made The file space number and page number recorded in the structure are calculated by the key, and the corresponding lock list can be located through the corresponding lock hash table entry.
  • the linked list is used to associate the records recorded in the transaction list with the locks recorded in the lock hash table.
  • each linked list includes multiple lock structures, and each lock structure records the database of lock locks waiting in line. Recorded file space number, page number, lock bitmap, number of bits occupied by the lock bitmap, lock type (shared lock, exclusive lock), lock flag (waiting, grant), belonging transaction, etc.,
  • the first heap_no bit of the lock bitmap is the identifier of the location record to be operated.
  • Each transaction corresponds to one
  • each transaction is applied to a lock list, and the lock list holds the lock held by the transaction.
  • Each pair of records operates, and the corresponding lock is inserted into the corresponding transaction. In the list of chains.
  • a lock structure can be shared by other locks of the same type on the same page. If you need to add the same type of lock to other records, you only need to find the lock in the linked list. If you find it, you will lock the corresponding heap_no of the bitmap. The position bit, which solves the hash conflict by using a single linked list, and effectively saves memory space.
  • step S102 specifically includes: if the to-be-operated position of the transaction has no lock, grant a lock to the transaction, and execute the transaction.
  • step S102 specifically includes: if there is a lock in the to-be-operated position of the transaction, checking whether there is a conflict between the existing lock and the lock to be granted; granting a lock to the transaction according to the check result, and executing the transaction.
  • the conflict includes: WR conflict, RW conflict, and WW highlight, and then grant the transaction according to the check result.
  • Lock, and execute the transaction in this way, the difference between the conflicting and non-existing conflicts can be handled differently, instead of waiting for the existing locks, all other transactions are suspended and waiting for the control to improve the concurrency of the control. .
  • the lock is granted to the transaction according to the check result, and executing the transaction specifically includes: if the existing lock does not conflict with the lock to be granted, grant the lock to the transaction, and execute the transaction.
  • the result of the check is that there is no conflict between the existing lock and the lock to be granted. At this time, the lock is still granted to the transaction, and the transaction is executed.
  • This embodiment grasps the execution timing of concurrent transactions without affecting each other, so that the available resources are maximized.
  • the concurrency of control is effectively improved than the concurrency control method in the related art.
  • the lock is granted to the transaction according to the check result, and executing the transaction specifically includes: if the existing lock conflicts with the pending latch, setting the transaction queue waiting until the lock is to be re-acquired; executing the transaction.
  • the transaction is set to hang, and the insertion wait queue is queued until the lock to be granted is regained, and the transaction is executed.
  • the wait is pending, that is, the transaction waits only when it is determined that it will be affected by other concurrent transactions. Under the premise of correctness of control, the concurrency of control is improved.
  • the executing transaction includes at least one of: performing an insert (also called an insert) operation, performing a delete operation, performing a modify operation, and performing a read operation.
  • an insert also called an insert
  • performing a delete operation performing a modify operation
  • performing a read operation performing a read operation.
  • Execution transactions in this embodiment may be additions, deletions, modifications, reads, or a combination thereof.
  • the concurrency control method of this embodiment is not limited to a certain operation, but can be extended to the above four basic operations, or a combination thereof, to expand the application range.
  • FIG. 3 is a flowchart of a concurrency control method according to a second embodiment of the present invention.
  • an insertion operation is taken as an example, and the method includes the following steps:
  • Step S301 the listening thread receives a Structured Query Language (SQL) statement query request, and allocates a worker thread to process the query request;
  • SQL Structured Query Language
  • Step S302 the worker thread performs SQL query analysis and SQL query optimization to generate an execution plan
  • Step S303 the worker thread adds an intent exclusive lock to the lock operation table, indicating that the write operation is to be performed on the table;
  • Step S305 determining whether a unique index is built on the table and the number of fields matching the cursor is greater than or equal to the number of unique key fields, and if so, executing step 306; otherwise, proceeding to step S314;
  • Step S307 if the maximum transaction ID on the page is greater than or equal to the minimum transaction ID in the current active transaction, check whether there is an implicit lock on the current record, if yes, go to step S309; otherwise, go to step S308;
  • Step S308 the insertion operation is queued
  • Step S309 acquiring a clustered index record corresponding to the current index record. If the record is just inserted, the record has an implicit lock, and the implicit lock is converted into an explicit lock;
  • Step S311, reporting a duplicate key error, proceeds to step S305;
  • Step S312 sharing a lock on the record
  • Step S314 checking whether there is a lock on the next record of the current record, that is, calculating the file space number and page number of the record as the key Hash value, locates an entry on the lock hash table, traverses the linked list with the table entry as the header, checks whether the heap_no bit in the lock bitmap of each lock is set, if the lock bitmap The heap_no bit is not set, that is, there is no lock on the record, go to step S316; there is a lock on the record, go to step S315;
  • Step S315 if the first heap_no bit in the lock bitmap is set, it indicates that there is a lock on the record, continue to determine whether there is a lock conflict, if there is a lock conflict, go to step S308; otherwise, go to step S316; Step S316, applying for locking successfully, inserting data, preventing other transactions from modifying the record; Step S317, if there is a lock on the next record of the inserted record, inheriting the lock on the next record, and setting the waiting state to the granted state ;
  • Step S318 the transaction execution ends, that is, the transaction completes the commit or the transaction completes the rollback, releases the held lock, and scans the lock hash table lock queue to grant the lock that no longer needs to wait.
  • This embodiment is applied to a database system, such as a database system for an IPTV electronic program guide. Since each electronic program guide system can accommodate a limited number of users, an IPTV system requires a large number of electronic program listings. Each electronic program in the related art runs a commercial database in the background, resulting in high cost, and the embodiment adopts the above concurrency control method to reduce the cost while satisfying the performance of the commercial database, and better satisfies the IPTV system. Requirements, as well as standard database features, including transaction integrity, transaction concurrency control, failure recovery, and more. This embodiment effectively controls the concurrent execution of transactions while ensuring system performance to the greatest extent.
  • the end of the transaction execution includes: a transaction completion submission or a transaction completion rollback.
  • the execution of the transaction includes a transaction completion submission or a transaction completion rollback, that is, when the transaction completes the commit or the transaction completes the rollback, the lock held by the transaction is released.
  • a transaction completion submission or a transaction completion rollback that is, when the transaction completes the commit or the transaction completes the rollback, the lock held by the transaction is released.
  • the lock completes the locking task it is released immediately, so that other concurrent transactions can obtain corresponding locks to obtain an opportunity to be executed, which helps to improve the concurrency of the control.
  • the lock held by the release transaction specifically includes, for each lock in the linked list of the released lock, is deleted from the lock list, and is deleted from the corresponding lock hash table. .
  • the lock held by the transaction is deleted from the lock list corresponding to the transaction, and is also deleted from the corresponding lock hash table.
  • the lock is removed by deleting the lock from the corresponding lock list and the lock hash table. Release, the operation of the cartridge is easy, and when the lock completes the locking task for a transaction, it is released immediately, so that other concurrent transactions can obtain the corresponding lock to obtain the opportunity to be executed, which helps to improve the concurrency of the control.
  • granting the lock that does not need to continue waiting in the released lock to the other concurrent transaction specifically includes: detecting, for each lock in the linked list of the released lock, whether there is a waiting flag; when there is a waiting flag And when the detected lock does not have a lock type conflict with other locks at the same operation position of other concurrent transactions, the detected lock is granted to other concurrent transactions, and other concurrent transactions are resumed.
  • the lock types include shared locks and exclusive locks. .
  • the hash is calculated by using the file space number and the page number of the lock locked record in the waiting state as a key.
  • FIG. 4 is a structural diagram of a concurrency control apparatus according to a third embodiment of the present invention. As shown in FIG. 4, the apparatus includes:
  • the determining module 10 is configured to determine, according to the lock relationship table, whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is configured to save the relationship between the transaction and the lock;
  • the execution module 20 is configured to grant a lock to the transaction according to the judgment result, and execute the transaction;
  • the release module 30 is configured to release the lock held by the transaction when the execution of the transaction ends, and grant the lock of the released lock without waiting for the other Concurrent transactions.
  • the determining module 10 first determines whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted according to the lock relationship table, and then uses the execution module 20 to grant the transaction according to the judgment result.
  • the lock is executed, and the transaction is executed.
  • the release module 30 releases the lock held by the transaction when the execution of the transaction ends, and grants the lock in the released lock without waiting for the other concurrent transaction, because the lock relationship table is used to save the transaction and Corresponding lock relationship, it is possible to judge whether there is conflict in different locks pointing to the same to-be-operated position, and perform differential processing according to the judgment result, instead of being like the concurrency control method in the related art, once the position to be operated is locked All the transactions corresponding to other locks are included in the waiting queue, so the concurrency of the concurrency control method in the related art is low, the system performance is poor, and the concurrency of the transaction control is improved, and the concurrency is improved. Control effect.
  • the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking the queued waiting lock; a linked list for the associated transaction With a lock.
  • the lock relationship table in this embodiment specifically includes a transaction list, a lock hash table, and a lock list.
  • the setting of the above table enables the concurrency control method of the embodiment to effectively manage transactions and locks, including fast index positioning and traversal search. And so on, further determining whether there is a conflict in different locks pointing to the same to-be-operated position, and providing strong support for the above-mentioned concurrency control method.
  • the transaction list holds transaction information of other transactions executed concurrently in the system at the time of execution of the current transaction, and is inserted according to the principle that the latecomer inserts into the queue.
  • the transaction information includes the transaction ID, the transaction type, the pointer to the front and rear nodes in the transaction list, and the chain. Table header pointers, etc.
  • Each time a transaction is started the transaction is inserted into the transaction list, and the transaction information for that transaction is saved to the transaction list.
  • the transaction structure contains a thread structure information, which contains the event object. When the transaction is suspended due to waiting for the lock, the thread executing the transaction waits for the event object. When the transaction grants the lock and is awakened, the thread that granted the lock sets the event object. .
  • each entry of the lock hash table corresponds to a header of a linked list.
  • the hash value is calculated by using the file space number and the page number recorded in the lock structure as keys, and then the The corresponding lock hash table entry is located to the corresponding linked list.
  • the linked list is used to associate the records recorded in the transaction list with the locks recorded in the lock hash table.
  • each linked list includes multiple lock structures, and each lock structure records the database of lock locks waiting in line. Recorded file space number, page number, lock bitmap, number of bits occupied by the lock bitmap, lock type (shared lock, exclusive lock), lock flag (waiting, grant), belonging transaction, etc.
  • the first heap_no bit of the bitmap is the identifier of the location record to be operated.
  • Each transaction corresponds to a linked list.
  • Each transaction is applied to a lock list.
  • the lock list holds the lock held by the transaction.
  • Each pair of records is operated, and the corresponding The lock is inserted into the corresponding linked list of the transaction.
  • a lock structure can be shared by other locks of the same type on the same page. If you need to add the same type of lock to other records, you only need to find the lock in the linked list. If you find it, you will lock the corresponding heap_no of the bitmap.
  • the position bit which solves the hash conflict by using a single linked list, and effectively saves memory space.
  • modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device, or they may be separately fabricated into individual integrated circuit modules, or they may be Multiple modules or steps are made into a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method of concurrency control includes the following steps: first, judging, according to a lock relation list, whether the position at which a transaction is waiting to be performed has a lock conflicting with a lock waiting to be allotted, said lock relation list being used to store the relations between transactions and locks; second, allotting a lock to the transaction according to the judgment and performing the transaction; third, when the transaction is complete, releasing the lock held by the transaction, and allotting any locks of all released locks which do not need to continue waiting to other concurrency transactions. Also provided is a concurrency control apparatus which includes: a judging module; a performing module; a releasing module.

Description

并发控制方法及装置 技术领域  Concurrent control method and device
本发明涉及数据库领域, 具体而言, 涉及一种并发控制方法及装置。 背景技术  The present invention relates to the field of databases, and in particular to a concurrency control method and apparatus. Background technique
数据库是一个共享资源, 在数据库系统中, 同一时刻可能存在多个并 发执行的事务, 当多个用户并发地对数据库进行存取操作时, 就会造成多 个事务同时存取同一数据库的情况, 从而带来各种冲突, 比如, 事务 Tl、 Τ2在并发执行时可能存在以下三种冲突:  A database is a shared resource. In a database system, there may be multiple concurrently executed transactions at the same time. When multiple users access the database concurrently, multiple transactions will access the same database at the same time. This leads to various conflicts. For example, the transactions T1 and Τ2 may have the following three types of conflicts during concurrent execution:
1 )写-读 (Write/Read, WR ) 冲突, 即 T2读入刚被 T1修改过且尚未 提交的数据, 这样, T2读入的是脏数据, 也称作 "脏读";  1) Write-read (WR) conflict, that is, T2 reads data that has just been modified by T1 and has not yet been committed, so that T2 reads dirty data, also called "dirty read";
2 )读-写 (Read/Write, RW ) 冲突, 即 T2修改刚被 T1读入的数据且 T1 尚未结束, 这样 T1若再次读入同一对象, 则其值会发生变化, 也称作 2) Read-Write (RW) conflict, that is, T2 modifies the data just read by T1 and T1 has not yet ended, so if T1 reads the same object again, its value will change, also called
"不可重复读"; "Cannot read repeatedly";
3 )写-写 ( Write/Write, WW )冲突, 即 T2覆写刚被 T1修改过的值且 T1尚未结束, 这样会导致数据的不一致。  3) Write-Write (WW) conflict, that is, T2 overwrites the value that has just been modified by T1 and T1 has not yet ended, which will result in inconsistent data.
串行调度可保证数据的一致性, 但不利于系统性能, 因此, 数据库管 理系统( Database Management System, DBMS )须提供事务并发控制机制。 可串行化是并发事务正确性的准则, 故一个给定的并发控制, 当且仅当它 是可串行化时, 才是正确控制。  Serial scheduling guarantees data consistency, but it is not conducive to system performance. Therefore, the Database Management System (DBMS) must provide transaction concurrency control mechanisms. Serializable is the criterion for the correctness of concurrent transactions, so a given concurrency control is properly controlled if and only if it is serializable.
严格的二阶段锁 ( Strict 2-Phase Locking, Strict 2PL )协议保证了并发 控制的可串行性, 其内容为: 1 )读 /写数据库对象前, 必须先加读 /写锁; 2 ) 事务执行完 (提交或回滚), 再释放其拥有的锁。  Strict 2-Phase Locking (Strict 2PL) protocol guarantees the serializability of concurrency control. Its contents are as follows: 1) Read/write lock must be added before reading/writing database objects; 2) Transaction After execution (commit or rollback), release the lock it owns.
相关技术中提供了一种并发控制方法, 该方法通过对被操作的数据库 记录上锁, 并让其他并发事务排队等待, 来防止该记录同时被其他事务修 改。 A concurrency control method is provided in the related art, which is performed on a database that is operated Record locks and queue other concurrent transactions to prevent the record from being modified by other transactions at the same time.
但是, 相关技术中的并发控制方法使得所有请求对同一数据库记录进 行操作的其他并发事务均进入等待队列, 直至被上锁事务执行结束将锁释 放后, 其他并发事务才得以再对数据库进行操作, 导致事务控制的并发性 较低, 并发控制效果较差。 发明内容  However, the concurrency control method in the related art causes all concurrent transactions requesting operations on the same database record to enter the waiting queue until the lock operation is released after the lock transaction execution ends, and other concurrent transactions can be operated on the database again. The concurrency of transaction control is low, and concurrency control is poor. Summary of the invention
本发明旨在提供一种并发控制方法和装置, 能够解决相关技术中的并 发控制方法使得所有请求对同一数据库记录进行操作的其他并发事务均进 入等待队列, 直至被上锁事务执行结束将锁释放后, 其他并发事务才得以 再对数据库进行操作, 导致事务控制的并发性较低, 系统性能较差的问题。  The present invention is directed to a concurrency control method and apparatus, which can solve the concurrency control method in the related art, so that all concurrent transactions requesting operations on the same database record enter the waiting queue until the lock transaction is terminated, and the lock is released. After that, other concurrent transactions can be operated on the database again, resulting in low concurrency of transaction control and poor system performance.
在本发明的实施例中, 提供了一种并发控制方法, 包括以下步骤: 根 据锁关系表判断事务的待操作位置是否有与待授予锁相冲突的锁, 锁关系 表用于保存事务与锁的关系; 根据判断结果对事务授予锁, 并执行事务; 当事务执行结束时, 释放事务持有的锁, 并将释放的锁中无需继续等待的 锁授予其他并发事务。  In an embodiment of the present invention, a concurrency control method is provided, including the following steps: determining, according to a lock relationship table, whether a to-be-operated location of a transaction has a lock that conflicts with a lock to be granted, and the lock relationship table is used to save a transaction and a lock. The relationship; grants a lock to the transaction based on the result of the judgment, and executes the transaction; when the execution of the transaction ends, the lock held by the transaction is released, and the lock of the released lock that does not need to continue waiting is granted to other concurrent transactions.
优选地, 在上述并发控制方法中, 锁关系表具体包括: 事务列表, 用 于保存并发执行且未提交的事务; 锁哈希表, 用于跟踪排队等待的锁; 锁 链表, 用于关联事务与锁。  Preferably, in the concurrency control method, the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking queued waiting locks; and a linked list for associating transactions With a lock.
优选地, 在上述并发控制方法中, 根据判断结果对事务授予锁, 并执 行事务具体包括: 若事务的待操作位置无锁, 对事务授予锁, 并执行事务。  Preferably, in the concurrency control method, the lock is granted to the transaction according to the judgment result, and executing the transaction specifically includes: if the to-be-operated position of the transaction has no lock, grant the lock to the transaction, and execute the transaction.
优选地, 在上述并发控制方法中, 根据判断结果对事务授予锁, 并执 行事务具体包括: 若事务的待操作位置已有锁, 检查已有锁与待授予锁是 否存在冲突; 根据检查结果对事务授予锁, 并执行事务。  Preferably, in the concurrency control method, the lock is granted to the transaction according to the judgment result, and the executing the transaction specifically includes: if there is a lock in the to-be-operated position of the transaction, checking whether there is a conflict between the existing lock and the lock to be granted; The transaction grants a lock and executes the transaction.
优选地, 在上述并发控制方法中, 根据检查结果对事务授予锁, 并执 行事务具体包括: 若已有锁与待授予锁不存在冲突, 对事务授予锁, 并执 行事务。 Preferably, in the above concurrency control method, a lock is granted to the transaction according to the check result, and The line transaction specifically includes: If there is no conflict between the existing lock and the pending lock, the lock is granted to the transaction, and the transaction is executed.
优选地, 在上述并发控制方法中, 根据检查结果对事务授予锁, 并执 行事务具体包括: 若已有锁与待授予锁存在冲突, 设置事务排队等待, 直 至重新获得待授予锁; 执行事务。  Preferably, in the concurrency control method, the lock is granted to the transaction according to the check result, and executing the transaction specifically includes: if the existing lock conflicts with the pending latch, setting the transaction queue waiting until the lock is to be re-acquired; executing the transaction.
优选地, 在上述并发控制方法中, 执行事务包括以下至少之一: 进行 增加操作、 进行删除操作、 进行修改操作、 进行读取操作。  Preferably, in the concurrency control method described above, the executing transaction includes at least one of the following: performing an adding operation, performing a deleting operation, performing a modifying operation, and performing a reading operation.
优选地, 在上述并发控制方法中, 事务执行结束包括: 事务完成提交 或事务完成回滚。  Preferably, in the above concurrency control method, the end of the transaction execution includes: a transaction completion submission or a transaction completion rollback.
优选地, 在上述并发控制方法中, 将释放的锁中无需继续等待的锁授 予其他并发事务具体包括: 对释放的锁所在锁链表中的每个锁, 检测是否 有等待标志; 当有等待标志, 且被检测的锁与其他并发事务的同一操作位 置上其他锁不存在锁类型冲突时, 将被检测的锁授予其他并发事务, 唤醒 其他并发事务继续执行, 锁类型包括共享锁和排它锁。  Preferably, in the above concurrency control method, granting the lock that does not need to continue waiting in the released lock to the other concurrent transaction specifically includes: detecting, for each lock in the linked list of the released lock, whether there is a waiting flag; when there is a waiting flag And when the detected lock does not have a lock type conflict with other locks at the same operation position of other concurrent transactions, the detected lock is granted to other concurrent transactions, and other concurrent transactions are resumed. The lock types include shared locks and exclusive locks. .
在本发明的实施例中, 还提供了一种并发控制装置, 包括: 判断模块, 用于根据锁关系表判断事务的待操作位置是否有与待授予锁相冲突的锁, 锁关系表用于保存事务与锁的关系; 执行模块, 用于根据判断结果对事务 授予锁, 并执行事务; 释放模块, 用于当事务执行结束时, 释放事务持有 的锁, 并将释放的锁中无需继续等待的锁授予其他并发事务。  In an embodiment of the present invention, a concurrency control device is further provided, including: a judging module, configured to determine, according to the lock relationship table, whether a to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is used. The relationship between the transaction and the lock is saved; the execution module is configured to grant a lock to the transaction according to the judgment result, and execute the transaction; and release the module, when the transaction execution ends, release the lock held by the transaction, and the released lock does not need to continue The waiting lock is granted to other concurrent transactions.
优选地, 在上述并发控制装置中, 锁关系表具体包括: 事务列表, 用 于保存并发执行且未提交的事务; 锁哈希表, 用于跟踪排队等待的锁; 锁 链表, 用于关联事务与锁。  Preferably, in the concurrency control device, the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking the queued waiting lock; a linked list for the associated transaction With a lock.
上述实施例由于采用锁关系表保存事务与其相应的锁的关系, 故可对 指向同一待操作位置的不同锁进行是否存在冲突的判断, 并根据判断结果 进行区别处理, 而不是像相关技术中并发控制方法那样, 一旦待操作位置 有锁便将所有其他锁对应的事务均列入等待队列, 所以克服了相关技术中 的并发控制方法对事务控制的并发性较低, 系统性能较差的问题, 进而提 高了事务控制的并发性, 改善了并发控制效果。 附图说明 In the above embodiment, since the relationship between the transaction and its corresponding lock is saved by using the lock relationship table, it is possible to judge whether there is a conflict between different locks pointing to the same to-be-operated position, and perform differential processing according to the judgment result, instead of concurrently as in the related art. Like the control method, once the position to be operated When there is a lock, all the transactions corresponding to other locks are included in the waiting queue, so the concurrency of the concurrency control method in the related art is low, the system performance is poor, and the concurrency of the transaction control is improved. , improved concurrency control effects. DRAWINGS
图 1示出了根据本发明第一实施例的并发控制方法的流程图; 图 2示出了图 1中并发控制方法采用的锁哈希表的示意图;  1 is a flow chart showing a concurrency control method according to a first embodiment of the present invention; FIG. 2 is a view showing a lock hash table used in the concurrency control method of FIG.
图 3示出了根据本发明第二实施例的并发控制方法的流程图; 图 4示出了根据本发明第三实施例的并发控制装置的结构图。 具体实施方式  3 is a flow chart showing a concurrency control method according to a second embodiment of the present invention; and FIG. 4 is a block diagram showing a concurrency control device according to a third embodiment of the present invention. detailed description
下面将参考附图并结合实施例, 来详细说明本发明。  The invention will be described in detail below with reference to the drawings in conjunction with the embodiments.
图 1 示出了根据本发明第一实施例的并发控制方法的流程图, 该方法 包括以下步骤:  1 shows a flow chart of a concurrency control method according to a first embodiment of the present invention, the method comprising the following steps:
步骤 S101 , 对数据库进行操作时, 根据锁关系表判断事务的待操作位 置是否有与待授予锁相冲突的锁, 锁关系表用于保存事务与锁的关系; 步骤 S102, 根据判断结果对事务授予锁, 并执行事务;  Step S101, when the database is operated, determining, according to the lock relationship table, whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is configured to save the relationship between the transaction and the lock; Step S102, according to the judgment result, the transaction Grant a lock, and execute a transaction;
步骤 S103 , 当事务执行结束时, 释放事务持有的锁, 并将释放的锁中 无需继续等待的锁授予其他并发事务。  Step S103, when the execution of the transaction ends, the lock held by the transaction is released, and the lock of the released lock that does not need to continue to wait is granted to other concurrent transactions.
本实施例首先根据锁关系表判断事务的待操作位置是否有与待授予锁 相冲突的锁, 然后根据判断结果对事务授予锁, 并执行事务, 最后当事务 执行结束时, 释放事务持有的锁, 并将释放的锁中无需继续等待的锁授予 其他并发事务, 由于采用了锁关系表保存事务与其相应的锁的关系, 故可 对指向同一待操作位置的不同锁进行是否存在冲突的判断, 并根据判断结 果进行区别处理, 而不是像相关技术中并发控制方法那样一旦待操作位置 有锁便将所有其他锁对应的事务均列入等待队列, 所以克服了相关技术中 的并发控制方法对事务控制的并发性较低, 系统性能较差的问题, 进而提 高了事务控制的并发性, 改善了并发控制效果。 In this embodiment, first, according to the lock relationship table, it is determined whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and then the lock is granted to the transaction according to the judgment result, and the transaction is executed, and finally, when the execution of the transaction ends, the transaction is held. Lock, and grant the lock that does not need to wait for the released lock to other concurrent transactions. Since the lock relationship table is used to save the relationship between the transaction and its corresponding lock, it is possible to judge whether there is a conflict between different locks pointing to the same to-be-operated position. And distinguishing according to the judgment result, instead of including the transaction corresponding to all other locks in the waiting queue once the position to be operated is locked, as in the concurrency control method in the related art, thus overcoming the related art The concurrency control method has low concurrency for transaction control and poor system performance, which improves the concurrency of transaction control and improves the concurrency control effect.
优选地, 在上述并发控制方法中, 锁关系表具体包括: 事务列表, 用 于保存并发执行且未提交的事务; 锁哈希表, 用于跟踪排队等待的锁; 锁 链表, 用于关联事务与锁。  Preferably, in the concurrency control method, the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking queued waiting locks; and a linked list for associating transactions With a lock.
本实施例中的锁关系表具体包括事务列表、 锁哈希表和锁链表, 上述 表的设置使得本实施例的并发控制方法可对事务和锁进行有效管理, 包括 快速地索引定位、 遍历搜索等, 进而实现了对指向同一待操作位置的不同 锁进行是否存在冲突的判断, 为上述并发控制方法提供了有力支持。  The lock relationship table in this embodiment specifically includes a transaction list, a lock hash table, and a lock list. The setting of the above table enables the concurrency control method of the embodiment to effectively manage transactions and locks, including fast index positioning and traversal search. And so on, further determining whether there is a conflict in different locks pointing to the same to-be-operated position, and providing strong support for the above-mentioned concurrency control method.
事务列表保存有当前事务执行时系统中并发执行的其它事务的事务信 息, 按照后来者插入到队头的原则插入, 事务信息具体包括事务 ID、 事务 类型、 指向事务列表中前后节点的指针、 锁链表的表头指针等。 每次启动 一个事务均会将该事务插入到事务列表中, 即会将该事务的事务信息保存 到事务列表中。 事务结构中包含一个线程结构信息, 其中包含了事件对象, 当事务因等待锁挂起时, 执行事务的线程等待该事件对象; 当事务授予锁 因而被唤醒时, 授予锁的线程设置该事件对象。  The transaction list holds transaction information of other transactions executed concurrently in the system at the time of execution of the current transaction, and is inserted according to the principle that the latecomer inserts into the queue. The transaction information includes the transaction ID, the transaction type, the pointer to the front and rear nodes in the transaction list, and the chain. Table header pointers, etc. Each time a transaction is started, the transaction is inserted into the transaction list, and the transaction information for that transaction is saved to the transaction list. The transaction structure contains a thread structure information, which contains the event object. When the transaction is suspended due to waiting for the lock, the thread executing the transaction waits for the event object. When the transaction grants the lock and is awakened, the thread that granted the lock sets the event object. .
图 2示出了图 1中并发控制方法采用的锁哈希表的示意图, 如图 2所 示, 锁哈希表的每个表项对应于一个锁链表的表头, 这样做, 使得以锁结 构中记录的文件空间号和页号为键计算哈希值, 即可通过相应的锁哈希表 表项定位到相应的锁链表。  2 is a schematic diagram of a lock hash table used in the concurrency control method of FIG. 1. As shown in FIG. 2, each entry of the lock hash table corresponds to a header of a linked list, so that the lock is made The file space number and page number recorded in the structure are calculated by the key, and the corresponding lock list can be located through the corresponding lock hash table entry.
锁链表用于关联事务列表中记录的事务与锁哈希表中记录的锁,如图 2 所示, 每个锁链表包括多个锁结构, 每个锁结构记录了排队等待的锁锁定 的数据库记录的文件空间号、 页号、 锁位图、 锁位图所占比特(bit )数、 锁类型 (共享锁、 排它锁)、 锁标志 (等待、 授予)、 所属事务等信息, 其 中,锁位图的第 heap_no位为待操作位置记录的标识。每个事务对应于一个 锁链表, 事务每申请一把锁, 都链入到相应的锁链表中, 该锁链表保存有 该事务持有的锁, 每对一条记录进行操作, 便会将相应的锁插入该事务相 应的锁链表中。 一个锁结构可被同一页上同类型的其它锁共享, 如果需要 在其它记录上加相同类型的锁, 只需在锁链表中查找有无类似的锁, 如果 找到则将锁位图的相应 heap_no位置位, 这样采用单链表即解决了散列冲 突, 并有效地节省了内存空间。 The linked list is used to associate the records recorded in the transaction list with the locks recorded in the lock hash table. As shown in Figure 2, each linked list includes multiple lock structures, and each lock structure records the database of lock locks waiting in line. Recorded file space number, page number, lock bitmap, number of bits occupied by the lock bitmap, lock type (shared lock, exclusive lock), lock flag (waiting, grant), belonging transaction, etc., The first heap_no bit of the lock bitmap is the identifier of the location record to be operated. Each transaction corresponds to one The linked list, each transaction is applied to a lock list, and the lock list holds the lock held by the transaction. Each pair of records operates, and the corresponding lock is inserted into the corresponding transaction. In the list of chains. A lock structure can be shared by other locks of the same type on the same page. If you need to add the same type of lock to other records, you only need to find the lock in the linked list. If you find it, you will lock the corresponding heap_no of the bitmap. The position bit, which solves the hash conflict by using a single linked list, and effectively saves memory space.
优选地, 在上述并发控制方法中, 步骤 S102具体包括: 若事务的待操 作位置无锁, 对事务授予锁, 并执行事务。  Preferably, in the above concurrency control method, step S102 specifically includes: if the to-be-operated position of the transaction has no lock, grant a lock to the transaction, and execute the transaction.
本实施例中若事务的待操作位置无锁, 则对本事务授予锁, 并执行相 应事务, 这样做, 使得待操作的数据库记录当没有其他事务操作时, 接受 本事务的操作, 在保证并发控制正确性的前提下, 提高了控制的并发性。  In this embodiment, if there is no lock in the to-be-operated position of the transaction, the lock is granted to the transaction, and the corresponding transaction is executed. In this way, the database record to be operated accepts the operation of the transaction when there is no other transaction, and the concurrent control is guaranteed. Under the premise of correctness, the concurrency of control is improved.
优选地, 在上述并发控制方法中, 步骤 S102具体包括: 若事务的待操 作位置已有锁, 检查已有锁与待授予锁是否存在冲突; 根据检查结果对事 务授予锁, 并执行事务。  Preferably, in the above concurrency control method, step S102 specifically includes: if there is a lock in the to-be-operated position of the transaction, checking whether there is a conflict between the existing lock and the lock to be granted; granting a lock to the transaction according to the check result, and executing the transaction.
本实施例中若事务的待操作位置已有锁, 则需继续检查已有锁与待授 予锁是否存在冲突, 该冲突包括: WR冲突、 RW冲突和 WW突出, 然后 再根据检查结果对事务授予锁, 并执行事务, 这样做, 可对存在冲突和不 存在冲突两种不同情况进行区别处理, 而不是在判断得到已有锁之后, 便 将所有其他事务挂起等待, 提高了控制的并发性。  In this embodiment, if there is a lock in the to-be-operated position of the transaction, it is necessary to continue to check whether there is a conflict between the existing lock and the lock to be granted. The conflict includes: WR conflict, RW conflict, and WW highlight, and then grant the transaction according to the check result. Lock, and execute the transaction, in this way, the difference between the conflicting and non-existing conflicts can be handled differently, instead of waiting for the existing locks, all other transactions are suspended and waiting for the control to improve the concurrency of the control. .
优选地, 在上述并发控制方法中, 根据检查结果对事务授予锁, 并执 行事务具体包括: 若已有锁与待授予锁不存在冲突, 对事务授予锁, 并执 行事务。  Preferably, in the concurrency control method, the lock is granted to the transaction according to the check result, and executing the transaction specifically includes: if the existing lock does not conflict with the lock to be granted, grant the lock to the transaction, and execute the transaction.
本实施例中虽然事务的待操作位置已有锁, 但检查结果为已有锁与待 授予锁不存在冲突, 此时, 仍对事务授予锁, 并执行事务。 本实施例抓住 了并发事务在互不影响的情况下的执行时机, 使得可利用资源最大化, 相 比相关技术中的并发控制方法有效地提高了控制的并发性。 In this embodiment, although the pending location of the transaction has a lock, the result of the check is that there is no conflict between the existing lock and the lock to be granted. At this time, the lock is still granted to the transaction, and the transaction is executed. This embodiment grasps the execution timing of concurrent transactions without affecting each other, so that the available resources are maximized. The concurrency of control is effectively improved than the concurrency control method in the related art.
优选地, 在上述并发控制方法中, 根据检查结果对事务授予锁, 并执 行事务具体包括: 若已有锁与待授予锁存在冲突, 设置事务排队等待, 直 至重新获得待授予锁; 执行事务。  Preferably, in the concurrency control method, the lock is granted to the transaction according to the check result, and executing the transaction specifically includes: if the existing lock conflicts with the pending latch, setting the transaction queue waiting until the lock is to be re-acquired; executing the transaction.
本实施例中若事务的待操作位置已有锁, 且已有锁与待授予锁存在冲 突, 则设置该事务挂起, 插入等待队列排队等待, 直至重新获得待授予锁, 并执行事务, 这样做, 使得事务必须同时满足待操作位置已有锁且已有锁 与待授予锁存在冲突的条件下才会挂起等待, 即事务只有在确定会受到其 他并发事务影响时才等待, 在保证并发控制正确性的前提下, 提高了控制 的并发性。  In this embodiment, if the to-be-operated position of the transaction has a lock, and the existing lock conflicts with the pending latch, the transaction is set to hang, and the insertion wait queue is queued until the lock to be granted is regained, and the transaction is executed. Do, so that the transaction must satisfy the existing lock at the position to be operated and the existing lock and the pending lock are in conflict condition, then the wait is pending, that is, the transaction waits only when it is determined that it will be affected by other concurrent transactions. Under the premise of correctness of control, the concurrency of control is improved.
优选地, 在上述并发控制方法中, 执行事务包括以下至少之一: 进行 增加 (insert, 也称作插入)操作、 进行删除操作、 进行修改操作、 进行读 取操作。  Preferably, in the concurrency control method described above, the executing transaction includes at least one of: performing an insert (also called an insert) operation, performing a delete operation, performing a modify operation, and performing a read operation.
本实施例中执行事务可以为增加、 删除、 修改、 读取, 或其组合。 本 实施例的并发控制方法并不局限于某一种操作, 而是可推广至上述四种基 本操作, 或者其组合, 扩展了应用范围。  Execution transactions in this embodiment may be additions, deletions, modifications, reads, or a combination thereof. The concurrency control method of this embodiment is not limited to a certain operation, but can be extended to the above four basic operations, or a combination thereof, to expand the application range.
图 3 示出了根据本发明第二实施例的并发控制方法的流程图, 本实施 例中以插入操作为例说明, 该方法包括以下步骤:  FIG. 3 is a flowchart of a concurrency control method according to a second embodiment of the present invention. In this embodiment, an insertion operation is taken as an example, and the method includes the following steps:
步骤 S301 ,监听线程接收结构化查询语言( Structured Query Language, SQL )语句查询请求, 并分配一工作线程处理查询请求;  Step S301, the listening thread receives a Structured Query Language (SQL) statement query request, and allocates a worker thread to process the query request;
步骤 S302, 工作线程执行 SQL查询分析和 SQL查询优化, 生成执行 计划;  Step S302, the worker thread performs SQL query analysis and SQL query optimization to generate an execution plan;
步骤 S303 , 工作线程对锁操作表加意向排它锁, 表明即将对表执行写 操作;  Step S303, the worker thread adds an intent exclusive lock to the lock operation table, indicating that the write operation is to be performed on the table;
步骤 S304, 工作线程从待插入数据记录构造索引项元组(tuple ), 定位 到第一条满足 X<=tuple的记录, 以利用索引快速定位到待插入记录的页, 其中, X为索引记录; Step S304, the worker thread constructs an index item tuple (tuple) from the data record to be inserted, and locates Go to the first record that satisfies X<=tuple, and use the index to quickly locate the page to be inserted into the record, where X is the index record;
步骤 S305 , 判断表上是否建了唯一索引且游标匹配的字段数大于等于 唯一键字段数, 如果是, 执行步骤 306; 否则, 转到步骤 S314;  Step S305, determining whether a unique index is built on the table and the number of fields matching the cursor is greater than or equal to the number of unique key fields, and if so, executing step 306; otherwise, proceeding to step S314;
步骤 S306, 从待插入数据记录构造索引项元组(tuple ), 定位到第一条 满足 X>=tuple的记录, X为索引记录;  Step S306, constructing an index item tuple (tuple) from the data record to be inserted, and positioning the first record satisfying X>=tuple, where X is an index record;
步骤 S307,如果页面上最大事务 ID大于等于当前活动事务中最小事务 ID, 则检查当前记录上是否有隐式锁, 如果有, 转到步骤 S309; 否则, 撞 到步骤 S308;  Step S307, if the maximum transaction ID on the page is greater than or equal to the minimum transaction ID in the current active transaction, check whether there is an implicit lock on the current record, if yes, go to step S309; otherwise, go to step S308;
步骤 S308, 本次插入操作排队等待;  Step S308, the insertion operation is queued;
步骤 S309, 获取当前索引记录对应的聚集索引记录, 如果该记录是刚 插入的, 则该记录上有隐式锁, 将该隐式锁转换为显式锁;  Step S309, acquiring a clustered index record corresponding to the current index record. If the record is just inserted, the record has an implicit lock, and the implicit lock is converted into an explicit lock;
步骤 S310, 判断 X=tuple是否成立, X=tuple表示存在唯一键冲突, 也 表示违反唯一键约束, 执行步骤 S311; 若不成立, 转到步骤 S312;  Step S310, determining whether X=tuple is established, X=tuple indicating that there is a unique key conflict, and also indicating that the unique key constraint is violated, and performing step S311; if not, proceeding to step S312;
步骤 S311 , 报重复键错误, 转到步骤 S305;  Step S311, reporting a duplicate key error, proceeds to step S305;
步骤 S312, 在记录上共享锁;  Step S312, sharing a lock on the record;
步骤 S313, 重新定位到第一条满足 X<=tuple的记录, X为索引记录; 步骤 S314, 检查当前记录的下一条记录上是否存在锁, 即以记录所在 文件空间号和页号为键计算哈希值, 定位到锁哈希表上某个表项, 遍历以 该表项为表头的锁链表,检查每个锁的锁位图中第 heap_no位是否置位,若 锁位图中第 heap_no位未被置位, 即该记录上不存在锁, 转到步骤 S316; 该记录上存在锁, 转到步骤 S315;  Step S313, relocating to the first record satisfying X<=tuple, X is an index record; Step S314, checking whether there is a lock on the next record of the current record, that is, calculating the file space number and page number of the record as the key Hash value, locates an entry on the lock hash table, traverses the linked list with the table entry as the header, checks whether the heap_no bit in the lock bitmap of each lock is set, if the lock bitmap The heap_no bit is not set, that is, there is no lock on the record, go to step S316; there is a lock on the record, go to step S315;
步骤 S315 , 若锁位图中第 heap_no位被置位, 则表示该记录上存在锁, 继续判断是否存在锁冲突, 若存在锁冲突, 转到步骤 S308; 否则, 转到步 骤 S316; 步骤 S316, 申请加锁成功, 插入数据, 防止了其它事务修改该记录; 步骤 S317 , 如果插入记录的下一条记录上有锁, 则继承下一条记录上 的锁, 同时将等待状态置为授予状态; Step S315, if the first heap_no bit in the lock bitmap is set, it indicates that there is a lock on the record, continue to determine whether there is a lock conflict, if there is a lock conflict, go to step S308; otherwise, go to step S316; Step S316, applying for locking successfully, inserting data, preventing other transactions from modifying the record; Step S317, if there is a lock on the next record of the inserted record, inheriting the lock on the next record, and setting the waiting state to the granted state ;
步骤 S318 , 事务执行结束, 即事务完成提交或事务完成回滚, 释放持 有的锁, 同时扫描锁哈希表锁队列, 授予不再需要等待的锁。  Step S318, the transaction execution ends, that is, the transaction completes the commit or the transaction completes the rollback, releases the held lock, and scans the lock hash table lock queue to grant the lock that no longer needs to wait.
本实施例应用于数据库系统中, 比如 IPTV电子节目单的数据库系统。 由于每个电子节目单系统能容纳的用户数量有限,因此一套 IPTV系统需要 部署很多个电子节目单。 相关技术中的每个电子节目单后台都运行一个商 用数据库, 导致成本较高, 而本实施例采用上述并发控制方法在接近商用 数据库性能的同时, 降低了成本, 较好地满足了 IPTV系统的需求, 同时具 备标准的数据库特性, 这些特性包括事务完整性、 事务并发控制、 故障恢 复等。 本实施例有效地控制了事务并发执行, 同时在最大程度上保证了系 统性能。  This embodiment is applied to a database system, such as a database system for an IPTV electronic program guide. Since each electronic program guide system can accommodate a limited number of users, an IPTV system requires a large number of electronic program listings. Each electronic program in the related art runs a commercial database in the background, resulting in high cost, and the embodiment adopts the above concurrency control method to reduce the cost while satisfying the performance of the commercial database, and better satisfies the IPTV system. Requirements, as well as standard database features, including transaction integrity, transaction concurrency control, failure recovery, and more. This embodiment effectively controls the concurrent execution of transactions while ensuring system performance to the greatest extent.
优选地, 在上述并发控制方法中, 事务执行结束包括: 事务完成提交 或事务完成回滚。  Preferably, in the above concurrency control method, the end of the transaction execution includes: a transaction completion submission or a transaction completion rollback.
本实施例中事务执行结束包括事务完成提交或事务完成回滚, 即当事 务完成提交或事务完成回滚时, 释放该事务持有的锁。 本实施例中当锁完 成锁定任务时立刻被释放掉, 便于其他并发事务获得相应的锁, 以获得被 执行的机会, 有助于提高控制的并发性。  In this embodiment, the execution of the transaction includes a transaction completion submission or a transaction completion rollback, that is, when the transaction completes the commit or the transaction completes the rollback, the lock held by the transaction is released. In this embodiment, when the lock completes the locking task, it is released immediately, so that other concurrent transactions can obtain corresponding locks to obtain an opportunity to be executed, which helps to improve the concurrency of the control.
优选地, 在上述并发控制方法中, 释放事务持有的锁具体包括对释放 的锁所在锁链表中的每个锁, 将其从该锁链表中删除, 同时从对应的锁哈 希表中删除。  Preferably, in the above concurrency control method, the lock held by the release transaction specifically includes, for each lock in the linked list of the released lock, is deleted from the lock list, and is deleted from the corresponding lock hash table. .
本实施例中当事务执行结束, 即该事务完成提交或完成回滚时, 将该 事务持有的锁从该事务对应的锁链表中删除, 同时也从对应的锁哈希表中 删除。 本实施例采用将锁从相应的锁链表和锁哈希表中删除来实现对锁的 释放, 操作筒单易行, 且使得当锁完成对某事务的锁定任务后立刻被释放 掉, 便于其他并发事务获得相应的锁, 以获得被执行的机会, 有助于提高 控制的并发性。 In this embodiment, when the transaction execution ends, that is, when the transaction completes the commit or completes the rollback, the lock held by the transaction is deleted from the lock list corresponding to the transaction, and is also deleted from the corresponding lock hash table. In this embodiment, the lock is removed by deleting the lock from the corresponding lock list and the lock hash table. Release, the operation of the cartridge is easy, and when the lock completes the locking task for a transaction, it is released immediately, so that other concurrent transactions can obtain the corresponding lock to obtain the opportunity to be executed, which helps to improve the concurrency of the control.
优选地, 在上述并发控制方法中, 将释放的锁中无需继续等待的锁授 予其他并发事务具体包括: 对释放的锁所在锁链表中的每个锁, 检测是否 有等待标志; 当有等待标志, 且被检测的锁与其他并发事务的同一操作位 置上其他锁不存在锁类型冲突时, 将被检测的锁授予其他并发事务, 唤醒 其他并发事务继续执行, 锁类型包括共享锁和排它锁。  Preferably, in the above concurrency control method, granting the lock that does not need to continue waiting in the released lock to the other concurrent transaction specifically includes: detecting, for each lock in the linked list of the released lock, whether there is a waiting flag; when there is a waiting flag And when the detected lock does not have a lock type conflict with other locks at the same operation position of other concurrent transactions, the detected lock is granted to other concurrent transactions, and other concurrent transactions are resumed. The lock types include shared locks and exclusive locks. .
本实施例首先检测被释放锁的锁类型中是否有等待标志, 如果有等待 标志, 则表明锁处于等待状态, 然后以等待状态的锁锁定的记录所在文件 空间号和页号为键计算哈希值, 定位到锁哈希表上相应锁链表的表头, 扫 描锁所在链表, 对链表中每个锁检查是否有其它锁与之存在锁类型冲突, 若存在锁类型冲突, 则被检测的锁需等待与之存在锁类型冲突的锁被释放 才有可能获得授予机会; 若不存在锁类型冲突, 则被检测的锁无需等待, 将被检测的锁授予其他并发事务, 重置该锁的等待标志, 即将该锁由等待 状态改为授予状态, 并唤醒被检测的锁对应的其他并发事务继续执行。  In this embodiment, it is first detected whether there is a waiting flag in the lock type of the released lock. If there is a waiting flag, it indicates that the lock is in a waiting state, and then the hash is calculated by using the file space number and the page number of the lock locked record in the waiting state as a key. Value, locates the header of the corresponding linked list on the lock hash table, scans the linked list of the lock, checks whether each lock in the linked list has a lock type conflict with the lock, and if there is a lock type conflict, the detected lock It is possible to obtain a chance to grant a lock that is waiting for a lock type conflict with it; if there is no lock type conflict, the detected lock does not have to wait, grant the detected lock to other concurrent transactions, and wait for the lock to be reset. The flag changes the lock from the wait state to the grant state, and wakes up other concurrent transactions corresponding to the detected lock to continue execution.
图 4示出了根据本发明第三实施例的并发控制装置的结构图, 如图 4 所示, 该装置包括:  4 is a structural diagram of a concurrency control apparatus according to a third embodiment of the present invention. As shown in FIG. 4, the apparatus includes:
判断模块 10, 用于根据锁关系表判断事务的待操作位置是否有与待授 予锁相冲突的锁, 锁关系表用于保存事务与锁的关系;  The determining module 10 is configured to determine, according to the lock relationship table, whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is configured to save the relationship between the transaction and the lock;
执行模块 20, 用于根据判断结果对事务授予锁, 并执行事务; 释放模块 30, 用于当事务执行结束时, 释放事务持有的锁, 并将释放 的锁中无需继续等待的锁授予其他并发事务。  The execution module 20 is configured to grant a lock to the transaction according to the judgment result, and execute the transaction; the release module 30 is configured to release the lock held by the transaction when the execution of the transaction ends, and grant the lock of the released lock without waiting for the other Concurrent transactions.
本实施例首先采用判断模块 10根据锁关系表判断事务的待操作位置是 否有与待授予锁相冲突的锁, 然后采用执行模块 20根据判断结果对事务授 予锁, 并执行事务, 最后采用释放模块 30当事务执行结束时, 释放事务持 有的锁, 并将释放的锁中无需继续等待的锁授予其他并发事务, 由于采用 了锁关系表保存事务与其相应的锁的关系, 故可对指向同一待操作位置的 不同锁进行是否存在冲突的判断, 并根据判断结果进行区别处理, 而不是 像相关技术中并发控制方法那样一旦待操作位置有锁便将所有其他锁对应 的事务均列入等待队列, 所以克服了相关技术中的并发控制方法对事务控 制的并发性较低, 系统性能较差的问题, 进而提高了事务控制的并发性, 改善了并发控制效果。 In this embodiment, the determining module 10 first determines whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted according to the lock relationship table, and then uses the execution module 20 to grant the transaction according to the judgment result. The lock is executed, and the transaction is executed. Finally, the release module 30 releases the lock held by the transaction when the execution of the transaction ends, and grants the lock in the released lock without waiting for the other concurrent transaction, because the lock relationship table is used to save the transaction and Corresponding lock relationship, it is possible to judge whether there is conflict in different locks pointing to the same to-be-operated position, and perform differential processing according to the judgment result, instead of being like the concurrency control method in the related art, once the position to be operated is locked All the transactions corresponding to other locks are included in the waiting queue, so the concurrency of the concurrency control method in the related art is low, the system performance is poor, and the concurrency of the transaction control is improved, and the concurrency is improved. Control effect.
优选地, 在上述并发控制装置中, 锁关系表具体包括: 事务列表, 用 于保存并发执行且未提交的事务; 锁哈希表, 用于跟踪排队等待的锁; 锁 链表, 用于关联事务与锁。  Preferably, in the concurrency control device, the lock relationship table specifically includes: a transaction list for storing concurrently executed and uncommitted transactions; a lock hash table for tracking the queued waiting lock; a linked list for the associated transaction With a lock.
本实施例中的锁关系表具体包括事务列表、 锁哈希表和锁链表, 上述 表的设置使得本实施例的并发控制方法可对事务和锁进行有效管理, 包括 快速地索引定位、 遍历搜索等, 进而实现了对指向同一待操作位置的不同 锁进行是否存在冲突的判断, 为上述并发控制方法提供了有力支持。  The lock relationship table in this embodiment specifically includes a transaction list, a lock hash table, and a lock list. The setting of the above table enables the concurrency control method of the embodiment to effectively manage transactions and locks, including fast index positioning and traversal search. And so on, further determining whether there is a conflict in different locks pointing to the same to-be-operated position, and providing strong support for the above-mentioned concurrency control method.
事务列表保存有当前事务执行时系统中并发执行的其它事务的事务信 息, 按照后来者插入到队头的原则插入, 事务信息具体包括事务 ID、 事务 类型、 指向事务列表中前后节点的指针、 锁链表的表头指针等。 每次启动 一个事务均会将该事务插入到事务列表中, 即会将该事务的事务信息保存 到事务列表中。 事务结构中包含一个线程结构信息, 其中包含了事件对象, 当事务因等待锁挂起时, 执行事务的线程等待该事件对象; 当事务授予锁 因而被唤醒时, 授予锁的线程设置该事件对象。  The transaction list holds transaction information of other transactions executed concurrently in the system at the time of execution of the current transaction, and is inserted according to the principle that the latecomer inserts into the queue. The transaction information includes the transaction ID, the transaction type, the pointer to the front and rear nodes in the transaction list, and the chain. Table header pointers, etc. Each time a transaction is started, the transaction is inserted into the transaction list, and the transaction information for that transaction is saved to the transaction list. The transaction structure contains a thread structure information, which contains the event object. When the transaction is suspended due to waiting for the lock, the thread executing the transaction waits for the event object. When the transaction grants the lock and is awakened, the thread that granted the lock sets the event object. .
如图 2所示, 锁哈希表的每个表项对应于一个锁链表的表头, 这样做, 使得以锁结构中记录的文件空间号和页号为键计算哈希值, 即可通过相应 的锁哈希表表项定位到相应的锁链表。 锁链表用于关联事务列表中记录的事务与锁哈希表中记录的锁,如图 2 所示, 每个锁链表包括多个锁结构, 每个锁结构记录了排队等待的锁锁定 的数据库记录的文件空间号、 页号、 锁位图、 锁位图所占比特(bit )数、 锁类型 (共享锁、 排它锁)、 锁标志 (等待、 授予)、 所属事务等信息, 其 中锁位图的第 heap_no位为待操作位置记录的标识。每个事务对应于一个锁 链表, 事务每申请一把锁, 都链入到相应的锁链表中, 该锁链表保存有该 事务持有的锁, 每对一条记录进行操作, 便会将相应的锁插入该事务相应 的锁链表中。 一个锁结构可被同一页上同类型的其它锁共享, 如果需要在 其它记录上加相同类型的锁, 只需在锁链表中查找有无类似的锁, 如果找 到则将锁位图的相应 heap_no位置位, 这样采用单链表即解决了散列冲突, 并有效地节省了内存空间。 As shown in FIG. 2, each entry of the lock hash table corresponds to a header of a linked list. In this way, the hash value is calculated by using the file space number and the page number recorded in the lock structure as keys, and then the The corresponding lock hash table entry is located to the corresponding linked list. The linked list is used to associate the records recorded in the transaction list with the locks recorded in the lock hash table. As shown in Figure 2, each linked list includes multiple lock structures, and each lock structure records the database of lock locks waiting in line. Recorded file space number, page number, lock bitmap, number of bits occupied by the lock bitmap, lock type (shared lock, exclusive lock), lock flag (waiting, grant), belonging transaction, etc. The first heap_no bit of the bitmap is the identifier of the location record to be operated. Each transaction corresponds to a linked list. Each transaction is applied to a lock list. The lock list holds the lock held by the transaction. Each pair of records is operated, and the corresponding The lock is inserted into the corresponding linked list of the transaction. A lock structure can be shared by other locks of the same type on the same page. If you need to add the same type of lock to other records, you only need to find the lock in the linked list. If you find it, you will lock the corresponding heap_no of the bitmap. The position bit, which solves the hash conflict by using a single linked list, and effectively saves memory space.
从以上的描述中, 可以看出, 本发明上述的实施例提高了事务控制的 并发性, 改善了并发控制效果。  From the above description, it can be seen that the above-described embodiment of the present invention improves the concurrency of transaction control and improves the concurrency control effect.
显然, 本领域的技术人员应该明白, 上述的本发明的各模块或各步骤 可以用通用的计算装置来实现, 它们可以集中在单个的计算装置上, 或者 分布在多个计算装置所组成的网络上, 可选地, 它们可以用计算装置可执 行的程序代码来实现, 从而, 可以将它们存储在存储装置中由计算装置来 执行, 或者将它们分别制作成各个集成电路模块, 或者将它们中的多个模 块或步骤制作成单个集成电路模块来实现。 这样, 本发明不限制于任何特 定的硬件和软件结合。  Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device, or they may be separately fabricated into individual integrated circuit modules, or they may be Multiple modules or steps are made into a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software.
以上所述仅为本发明的优选实施例而已, 并不用于限制本发明, 对于 本领域的技术人员来说, 本发明可以有各种更改和变化。 凡在本发明的精 神和原则之内, 所作的任何修改、 等同替换、 改进等, 均应包含在本发明 的保护范围之内。  The above is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. within the spirit and scope of the invention are intended to be included within the scope of the invention.

Claims

权利要求书 Claim
1.一种并发控制方法, 其特征在于, 该方法包括以下步骤:  A concurrency control method, characterized in that the method comprises the following steps:
对数据库进行操作时, 根据锁关系表判断事务的待操作位置是否有与 待授予锁相冲突的锁, 所述锁关系表用于保存所述事务与锁的关系;  When the database is operated, it is determined according to the lock relationship table whether there is a lock in the to-be-operated position of the transaction that conflicts with the lock to be granted, and the lock relationship table is used to save the relationship between the transaction and the lock;
根据判断结果对所述事务授予锁, 并执行所述事务;  Granting a lock to the transaction according to the judgment result, and executing the transaction;
当所述事务执行结束时, 释放所述事务持有的锁, 并将释放的所述锁 中无需继续等待的锁授予其他并发事务。  When the execution of the transaction ends, the lock held by the transaction is released, and the released lock of the lock that does not need to continue waiting is granted to other concurrent transactions.
2.根据权利要求 1 所述的并发控制方法, 其特征在于, 所述锁关系表 具体包括:  The concurrency control method according to claim 1, wherein the lock relationship table specifically includes:
事务列表, 用于保存并发执行且未提交的事务;  A transaction list that holds concurrently executed and uncommitted transactions;
锁哈希表, 用于跟踪排队等待的锁;  a lock hash table for tracking locks waiting in line;
锁链表, 用于关联所述事务与所述锁。  a linked list for associating the transaction with the lock.
3.根据权利要求 2所述的并发控制方法, 其特征在于, 所述根据判断 结果对所述事务授予锁, 并执行所述事务具体包括:  The concurrency control method according to claim 2, wherein the granting a lock to the transaction according to the judgment result, and executing the transaction specifically includes:
所述事务的所述待操作位置无锁, 则对所述事务授予锁, 并执行所述 事务。  The lock operation location of the transaction is unlocked, the lock is granted to the transaction, and the transaction is executed.
4.根据权利要求 2所述的并发控制方法, 其特征在于, 所述根据判断 结果对所述事务授予锁, 并执行所述事务具体包括:  The concurrency control method according to claim 2, wherein the granting a lock to the transaction according to the judgment result, and executing the transaction specifically includes:
所述事务的所述待操作位置已有锁, 则检查已有锁与所述待授予锁是 否存在冲突;  If the to-be-operated position of the transaction has a lock, it is checked whether there is a conflict between the existing lock and the to-be-granted lock;
根据检查结果对所述事务授予锁, 并执行所述事务。  A lock is granted to the transaction based on the result of the check, and the transaction is executed.
5.根据权利要求 4所述的并发控制方法, 其特征在于, 所述根据检查 结果对所述事务授予锁, 并执行所述事务具体包括:  The concurrency control method according to claim 4, wherein the granting a lock to the transaction according to the check result, and executing the transaction specifically includes:
所述已有锁与所述待授予锁不存在冲突, 则对所述事务授予锁, 并执 行所述事务。 The existing lock does not conflict with the to-be-granted lock, and the lock is granted to the transaction, and the transaction is executed.
6.根据权利要求 4所述的并发控制方法, 其特征在于, 所述根据检查 结果对所述事务授予锁, 并执行所述事务具体包括: The concurrency control method according to claim 4, wherein the granting a lock to the transaction according to the check result, and executing the transaction specifically includes:
所述已有锁与所述待授予锁存在冲突, 则设置所述事务排队等待, 直 至重新获得所述待授予锁;  The existing lock conflicts with the pending grant, and the transaction is queued until the lock to be granted is regained;
执行所述事务。  Execute the transaction.
7.根据权利要求 3、 5或 6所述的并发控制方法, 其特征在于, 执行所 述事务包括以下至少之一: 进行增加操作、 进行删除操作、 进行修改操作、 进行读取操作。  The concurrency control method according to claim 3, 5 or 6, wherein the executing the transaction comprises at least one of: performing an adding operation, performing a deleting operation, performing a modifying operation, and performing a reading operation.
8.根据权利要求 1或 2所述的并发控制方法, 其特征在于, 所述事务 执行结束包括: 所述事务完成提交或所述事务完成回滚。  The concurrency control method according to claim 1 or 2, wherein the end of the transaction execution comprises: the transaction completion submission or the transaction completion rollback.
9.根据权利要求 1或 2所述的并发控制方法, 其特征在于, 所述将释 放的所述锁中无需继续等待的锁授予其他并发事务具体包括:  The concurrency control method according to claim 1 or 2, wherein the granting the lock that does not need to continue waiting in the lock to be released to the other concurrent transaction specifically includes:
对释放的所述锁所在锁链表中的每个锁, 检测是否有等待标志; 当有等待标志, 且被检测的所述锁与所述其他并发事务的同一操作位 置上其他锁不存在锁类型冲突时, 将被检测的所述锁授予所述其他并发事 务, 唤醒所述其他并发事务继续执行, 所述锁类型包括共享锁和排它锁。  Detecting whether there is a wait flag for each lock in the linked list in which the lock is released; when there is a wait flag, and the other locks in the same operation position of the detected lock and the other concurrent transaction do not have a lock type In the event of a conflict, the lock to be detected is granted to the other concurrent transaction, and the other concurrent transaction is awakened to continue execution, the lock type including a shared lock and an exclusive lock.
10. 一种并发控制装置, 其特征在于, 该装置包括:  10. A concurrent control device, the device comprising:
判断模块, 用于根据锁关系表判断事务的待操作位置是否有与待授予 锁相冲突的锁, 所述锁关系表用于保存所述事务与锁的关系;  a determining module, configured to determine, according to the lock relationship table, whether the to-be-operated position of the transaction has a lock that conflicts with the lock to be granted, and the lock relationship table is configured to save the relationship between the transaction and the lock;
执行模块, 用于根据判断结果对所述事务授予锁, 并执行所述事务; 释放模块, 用于当所述事务执行结束时, 释放所述事务持有的锁, 并 将释放的所述锁中无需继续等待的锁授予其他并发事务。  An execution module, configured to grant a lock to the transaction according to the judgment result, and execute the transaction; and release a module, when the execution of the transaction ends, release the lock held by the transaction, and release the lock A lock that does not need to wait for further grants other concurrent transactions.
11. 根据权利要求 10所述的并发控制装置, 其特征在于, 所述锁关 系表具体包括:  The concurrency control device according to claim 10, wherein the lock relationship table specifically includes:
事务列表, 用于保存并发执行且未提交的事务; 锁哈希表, 用于跟踪排队等待的锁; A transaction list that holds concurrently executed and uncommitted transactions; a lock hash table for tracking locks waiting in line;
锁链表, 用于关联所述事务与所述锁。  a linked list for associating the transaction with the lock.
12、 根据权利要求 11所述的并发控制装置, 其特征在于,  12. The concurrency control device according to claim 11, wherein
所述执行模块根据判断结果对所述事务授予锁, 并执行所述事务为: 所述事务的所述待操作位置无锁, 则执行模块对所述事务授予锁, 并执行 所述事务。  The execution module grants a lock to the transaction according to the judgment result, and executes the transaction as: the lock operation position of the transaction is unlocked, and the execution module grants a lock to the transaction, and executes the transaction.
13、 根据权利要求 11所述的并发控制装置, 其特征在于,  13. The concurrency control device according to claim 11, wherein
所述执行模块根据判断结果对所述事务授予锁, 并执行所述事务为: 所述事务的所述待操作位置已有锁, 则执行模块检查已有锁与所述待授予 锁是否存在冲突; 根据检查结果对所述事务授予锁, 并执行所述事务。  The execution module grants a lock to the transaction according to the judgment result, and executes the transaction as: the operation at the to-be-operated location of the transaction has a lock, and the execution module checks whether the existing lock conflicts with the to-be-granted lock. ; grant a lock on the transaction based on the result of the check and execute the transaction.
14、 根据权利要求 13所述的并发控制装置, 其特征在于,  14. The concurrency control device according to claim 13, wherein
所述执行模块根据检查结果对所述事务授予锁, 并执行所述事务具体 为: 所述已有锁与所述待授予锁不存在冲突, 则执行模块根对所述事务授 予锁, 并执行所述事务。  The execution module grants a lock to the transaction according to the check result, and executes the transaction as follows: the existing lock does not conflict with the to-be-granted lock, and the execution module root grants a lock to the transaction, and executes The transaction.
15、 根据权利要求 13所述的并发控制装置, 其特征在于,  15. The concurrency control device according to claim 13, wherein
所述执行模块根据检查结果对所述事务授予锁, 并执行所述事务具体 为: 所述已有锁与所述待授予锁存在冲突, 则执行模块设置所述事务排队 等待, 直至重新获得所述待授予锁, 之后执行所述事务。  The execution module grants a lock to the transaction according to the check result, and the executing the transaction is specifically: the existing lock conflicts with the pending grant, and the execution module sets the transaction to wait in a row until the device is regained The lock is granted, and the transaction is executed.
16、 根据权利要求 12、 14或 15所述的并发控制装置, 其特征在于, 所述执行模块执行的事务包括以下至少之一: 进行增加操作、 进行删 除操作、 进行修改操作、 进行读取操作。  The concurrency control apparatus according to claim 12, 14 or 15, wherein the transaction executed by the execution module comprises at least one of: performing an adding operation, performing a deleting operation, performing a modifying operation, and performing a reading operation. .
17、 根据权利要求 10或 11所述的并发控制装置, 其特征在于, 所述释放模块将释放的所述锁中无需继续等待的锁授予其他并发事务 具体包括: 对释放的所述锁所在锁链表中的每个锁, 检测是否有等待标志; 当有等待标志, 且被检测的所述锁与所述其他并发事务的同一操作位置上 其他锁不存在锁类型冲突时, 将被检测的所述锁授予所述其他并发事务, 唤醒所述其他并发事务继续执行, 所述锁类型包括共享锁和排它锁。 The concurrency control device according to claim 10 or 11, wherein the releasing module grants the released locks without waiting for the lock to other concurrent transactions, and specifically includes: the chain of the locks released Each lock in the table detects whether there is a wait flag; when there is a wait flag, and the detected lock is at the same operational position as the other concurrent transaction When other locks do not have a lock type conflict, the lock to be detected is granted to the other concurrent transaction, and the other concurrent transaction is awakened to continue execution. The lock type includes a shared lock and an exclusive lock.
PCT/CN2009/076082 2009-07-23 2009-12-25 Method and apparatus of concurrency control WO2011009274A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN2009101608047A CN101615203B (en) 2009-07-23 2009-07-23 Concurrency control method and device
CN200910160804.7 2009-07-23

Publications (1)

Publication Number Publication Date
WO2011009274A1 true WO2011009274A1 (en) 2011-01-27

Family

ID=41494843

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2009/076082 WO2011009274A1 (en) 2009-07-23 2009-12-25 Method and apparatus of concurrency control

Country Status (2)

Country Link
CN (1) CN101615203B (en)
WO (1) WO2011009274A1 (en)

Families Citing this family (21)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9104715B2 (en) * 2010-06-23 2015-08-11 Microsoft Technology Licensing, Llc Shared data collections
CN102103642B (en) * 2011-03-25 2016-08-03 北京世纪互联宽带数据中心有限公司 Data-erasure method based on OLTP, system and graphic data base server
CN104252386B (en) * 2013-06-26 2017-11-21 阿里巴巴集团控股有限公司 The locking method and equipment of data renewal
JP6397053B2 (en) * 2014-04-30 2018-09-26 オラクル・インターナショナル・コーポレイション System and method for providing distributed transaction locks in a transaction middleware machine environment
US20160092488A1 (en) * 2014-09-26 2016-03-31 Futurewei Technologies, Inc. Concurrency control in a shared storage architecture supporting on-page implicit locks
CN104252545B (en) * 2014-10-11 2017-05-31 南京国电南自维美德自动化有限公司 A kind of implementation method of the object type attributes type lock of real-time internal memory database
CN104657237A (en) * 2015-03-12 2015-05-27 浪潮集团有限公司 Method for detecting disk array
CN104679881B (en) * 2015-03-13 2019-03-08 华为技术有限公司 A kind of concurrency control method and device
CN106156126B (en) * 2015-04-08 2019-10-11 阿里巴巴集团控股有限公司 Handle the data collision detection method and server in data task
CN107291371B (en) * 2016-03-31 2019-11-19 华为技术有限公司 A kind of implementation method and device of Read-Write Locks
CN106250487B (en) * 2016-07-29 2020-07-03 新华三技术有限公司 Database concurrency control method and device
CN107016041B (en) * 2017-01-19 2020-05-05 阿里巴巴集团控股有限公司 Method and device for controlling single data to be exported
CN109388645B (en) * 2017-08-11 2023-02-24 腾讯科技(深圳)有限公司 Instruction execution method, instruction execution device, and storage medium
CN109376165A (en) * 2018-11-14 2019-02-22 深圳市金证科技股份有限公司 The implementation method and device and computer readable storage medium of memory database lock
CN109933606B (en) * 2019-03-19 2021-04-27 上海达梦数据库有限公司 Database modification method, device, equipment and storage medium
CN110750356B (en) * 2019-09-09 2022-03-29 华南师范大学 Multi-core interaction method, system and storage medium suitable for nonvolatile memory
CN110909012B (en) * 2019-12-04 2020-09-04 上海达梦数据库有限公司 Method, device, equipment and storage medium for blocking database object
CN111198872B (en) * 2020-01-06 2021-06-11 中科驭数(北京)科技有限公司 Method and device for processing transactions by database
CN111858626A (en) * 2020-06-04 2020-10-30 武汉达梦数据库有限公司 Data synchronization method and device based on parallel execution
CN111984379B (en) * 2020-07-14 2023-04-07 上海金仕达软件科技股份有限公司 Read-write transaction control method, system, terminal device and storage medium
CN112199391B (en) * 2020-09-30 2024-02-23 深圳前海微众银行股份有限公司 Data locking detection method, equipment and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1808389A (en) * 2006-02-20 2006-07-26 南京联创科技股份有限公司 Autonomous locking method based on shared memory for account background memory database
US20070130142A1 (en) * 2005-12-07 2007-06-07 Daum Andreas W System and method for handling parallel updates of objects requiring time sensitive acknowlegement
CN100353325C (en) * 2004-08-23 2007-12-05 华为技术有限公司 Method for realing sharing internal stored data base and internal stored data base system
CN101196829A (en) * 2007-12-27 2008-06-11 电子科技大学 Method for adding lock to data collision module in cooperating edit

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100353325C (en) * 2004-08-23 2007-12-05 华为技术有限公司 Method for realing sharing internal stored data base and internal stored data base system
US20070130142A1 (en) * 2005-12-07 2007-06-07 Daum Andreas W System and method for handling parallel updates of objects requiring time sensitive acknowlegement
CN1808389A (en) * 2006-02-20 2006-07-26 南京联创科技股份有限公司 Autonomous locking method based on shared memory for account background memory database
CN101196829A (en) * 2007-12-27 2008-06-11 电子科技大学 Method for adding lock to data collision module in cooperating edit

Also Published As

Publication number Publication date
CN101615203A (en) 2009-12-30
CN101615203B (en) 2012-04-04

Similar Documents

Publication Publication Date Title
WO2011009274A1 (en) Method and apparatus of concurrency control
US9396227B2 (en) Controlled lock violation for data transactions
US7644106B2 (en) Avoiding lock contention by using a wait for completion mechanism
US8396831B2 (en) Optimistic serializable snapshot isolation
US11580134B1 (en) Method and apparatus for resolving source database precommitted transactions that are replicated to a target database of a database replication system
US11386065B2 (en) Database concurrency control through hash-bucket latching
US8407195B2 (en) Efficient multi-version locking for main memory databases
Wu et al. Transaction healing: Scaling optimistic concurrency control on multicores
KR20170132873A (en) Method for processing database transactions in a distributed computing system
US20140040220A1 (en) Methods and systems for deadlock detection
Bernstein et al. Relaxed-currency serializability for middle-tier caching and replication
CN111459920B (en) Multi-version concurrency control method and system based on virtual global clock synchronization
CN101556597B (en) Self-adaptive optimistic concurrency control method
US20230081900A1 (en) Methods and systems for transactional schema changes
Chen et al. Plor: General transactions with predictable, low tail latency
CN114282074B (en) Database operation method, device, equipment and storage medium
US20030208489A1 (en) Method for ordering parallel operations in a resource manager
US20140040219A1 (en) Methods and systems for a deadlock resolution engine
WO2024098363A1 (en) Multicore-processor-based concurrent transaction processing method and system
Qin et al. A commit strategy for distributed real-time transaction
CN112612647A (en) Log parallel replay method, device, equipment and storage medium
Arora et al. Dynamic Timestamp Allocation for Reducing Transaction Aborts
CN117348977A (en) Method, device, equipment and medium for controlling transaction concurrency in database
Mehdi Scalability through asynchrony in transactional storage systems
CN117687807A (en) Data processing method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 09847509

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 09847509

Country of ref document: EP

Kind code of ref document: A1