Database transaction concurrency control method and device, equipment, medium and product
By releasing the lock in advance before the database transaction is committed, the transaction blocking problem caused by the traditional lock protocol is solved, the system's throughput capability during hot data competition is improved, and the ACID attributes of the transaction are ensured.
Patent Information
- Application Number
- CN202411921583.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-15
AI Technical Summary
In relational databases, when hotspot data is frequently updated by a large number of concurrent transactions, the traditional strict two-stage locking protocol causes transaction blockage, resulting in unused parallelism and reducing the overall throughput of the system.
By releasing the lock in advance before the transaction is committed, a second transaction that has a transaction dependency with the transaction allows the update operation in advance, thereby improving the overall throughput of the system when there is hot data competition.
It improves the parallelism of concurrent updates of hotspot data, improves the overall throughput capability of the system, and strictly ensures the ACID attributes of the transaction.
Smart Images

Figure CN119829594A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a database transaction concurrency control method, device, equipment, medium and product. Background Art
[0002] In relational databases, a concurrency control technology called strict two-phase locking protocol is often used to ensure transaction isolation. However, in scenarios where hot data is frequently updated by a large number of concurrent transactions, the traditional strict two-phase locking protocol requires that the lock cannot be released before the transaction is completed. This causes the data update operations of other transactions to be blocked until the former transaction is committed and the corresponding lock is released. This results in significant parallelism not being utilized, reducing the overall throughput of the system. Summary of the invention
[0003] The present invention provides a database transaction concurrency control method, device, equipment, medium and product, which can release locks in advance before transaction submission, improve the overall throughput of the system when hot spot data is frequently updated by a large number of concurrent transactions and compete, improve the parallelism of concurrent updates of hot spot data, and strictly guarantee the ACID properties of transactions.
[0004] According to one aspect of the present invention, a database transaction concurrency control method is provided, the method comprising:
[0005] Based on the received business request, start a first transaction;
[0006] According to the transaction change request of the first transaction, perform a corresponding transaction change operation on the first transaction;
[0007] According to the early lock release request of the first transaction, the early lock release is performed on the first transaction, and the second transaction having a transaction dependency relationship with the first transaction is awakened, so that the second transaction performs a corresponding transaction update operation.
[0008] According to another aspect of the present invention, a database transaction concurrency control device is provided, the device comprising:
[0009] A first transaction opening module, configured to open a first transaction based on a received service request;
[0010] A first transaction change module, configured to perform a corresponding transaction change operation on the first transaction according to a transaction change request of the first transaction;
[0011] The early lock release module is used to execute early lock release on the first transaction according to the early lock release request of the first transaction, and wake up the second transaction that has a transaction dependency relationship with the first transaction, so that the second transaction executes the corresponding transaction update operation.
[0012] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0013] at least one processor; and
[0014] a memory communicatively connected to the at least one processor; wherein,
[0015] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the database transaction concurrency control method described in any embodiment of the present invention.
[0016] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database transaction concurrency control method described in any embodiment of the present invention when executed.
[0017] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the database transaction concurrency control method according to any embodiment of the present invention is implemented.
[0018] The technical solution of the embodiment of the present invention is to start a first transaction based on a received business request; perform a corresponding transaction change operation on the first transaction according to a transaction change request of the first transaction; perform an early lock release on the first transaction according to an early lock release request of the first transaction, and wake up a second transaction that has a transaction dependency relationship with the first transaction, so that the second transaction performs a corresponding transaction update operation. This technical solution improves the overall throughput of the system when hot data is frequently updated by a large number of concurrent transactions and competes, improves the parallelism of concurrent updates of hot data, and can strictly guarantee the ACID properties of transactions by releasing locks in advance before transactions are committed.
[0019] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1is a flowchart of a database transaction concurrency control method provided according to Embodiment 1 of the present invention;
[0022] Figure 2 is a schematic diagram of a transaction update process provided according to Embodiment 1 of the present invention;
[0023] Figure 3 is a schematic diagram of a process for releasing a lock in advance according to Embodiment 1 of the present invention;
[0024] Figure 4 is a schematic diagram of a transaction wake-up operation process provided according to Embodiment 1 of the present invention;
[0025] Figure 5 is a schematic diagram of a transaction submission process provided according to Embodiment 1 of the present invention;
[0026] Figure 6 is a schematic diagram of a transaction rollback process provided according to Embodiment 1 of the present invention;
[0027] Figure 7 is a schematic diagram of a process for releasing a transaction lock according to Embodiment 1 of the present invention;
[0028] Figure 8 is a schematic diagram of a transaction rollback process provided according to Embodiment 1 of the present invention;
[0029] Fig. 9 It is a structural diagram of a database transaction concurrency control device provided according to Embodiment 2 of the present invention;
[0030] Fig.10 It is a structural schematic diagram of an electronic device for implementing the database transaction concurrency control method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] Embodiment 1
[0034] Figure 1 This is a flowchart of a database transaction concurrency control method provided in Embodiment 1 of the present invention. This embodiment is applicable to the case of supporting database transaction concurrency control for early release of locks. The method can be executed by a database transaction concurrency control device. The database transaction concurrency control device can be implemented in the form of hardware and / or software. The database transaction concurrency control device can be configured in an electronic device. Figure 1 As shown, a database transaction concurrency control method provided in this embodiment includes the following steps:
[0035] S110: Start a first transaction based on the received service request.
[0036] The service request may refer to a connection establishment request initiated by a client. The first transaction may refer to a database transaction corresponding to the current service request, and the database transaction has ACID properties, namely, atomicity, consistency, isolation, and durability.
[0037] In an embodiment of the present invention, the database can establish a corresponding session with the client based on the received business request, and after receiving the client's transaction start request in the session, start the corresponding first transaction and initialize various attribute parameters of the first transaction.
[0038] S120: Execute a corresponding transaction change operation on the first transaction according to the transaction change request of the first transaction.
[0039] The transaction change request may refer to a database transaction request initiated by a client. Exemplarily, the transaction change request may include a transaction update request, a transaction commit request, a transaction rollback request, and the like.
[0040] In an embodiment of the present invention, the database may receive a transaction change request for a first transaction sent by a client, and perform a corresponding transaction change operation on the first transaction based on the transaction change request. In a specific embodiment, the database may receive a structured query language (SQL) statement for data reading and writing sent by a client in a session established with the client, i.e., a transaction update request, and then perform a data update operation on a target data row in a target database table according to the transaction update request.
[0041] S130: According to the early lock release request of the first transaction, early lock release is performed on the first transaction, and a second transaction having a transaction dependency relationship with the first transaction is awakened, so that the second transaction performs a corresponding transaction update operation.
[0042] Among them, the early lock release request can refer to a request initiated by the client to instruct the early release of the row lock corresponding to the specified target data row involved in the first transaction. The release of the row lock corresponding to the specified target data row here can be understood as releasing all online row lock instances created by the first transaction.
[0043] The second transaction may refer to other transactions that have a transaction dependency relationship with the first transaction. The transaction dependency relationship can be understood as the execution of one transaction depending on the completion or certain status of another transaction during the database transaction processing. For example, when a transaction locks and modifies a data row, other transactions that need to access the record (the aforementioned data row) must wait for the lock to be released before they can be executed.
[0044] In an embodiment of the present invention, before the first transaction commits the transaction, the database may receive an early lock release request for the first transaction sent by the client, so as to perform an early lock release operation on the first transaction, that is, to release in advance the online row lock instance corresponding to each target data row involved in the first transaction, and after all the above online row lock instances are released, the second transaction that is currently in a waiting state and depends on the first transaction may be awakened, so that the second transaction can start executing the corresponding transaction update operation without waiting for the first transaction to be committed.
[0045] The technical solution of the embodiment of the present invention is to start a first transaction based on a received business request; perform a corresponding transaction change operation on the first transaction according to a transaction change request of the first transaction; perform an early lock release on the first transaction according to an early lock release request of the first transaction, and wake up a second transaction that has a transaction dependency relationship with the first transaction, so that the second transaction performs a corresponding transaction update operation. This technical solution improves the overall throughput of the system when hot data is frequently updated by a large number of concurrent transactions and competes, improves the parallelism of concurrent updates of hot data, and can strictly guarantee the ACID properties of transactions by releasing locks in advance before transactions are committed.
[0046] Further, based on the above-mentioned embodiment of the invention, starting a first transaction based on the received service request specifically includes the following steps:
[0047] Receive business requests from clients, establish database connections and current sessions;
[0048] In response to a transaction opening request in the current session, a first transaction is opened and initialized.
[0049] In an embodiment of the present invention, after receiving a service request initiated by a client, the database may establish a database connection and a corresponding current session (cur_session) for the client, and after receiving a transaction start request initiated by the client in the current session, start a first transaction (cur_trx), and initialize various attribute parameters of the first transaction; wherein the initialization process of the first transaction includes: initializing a commit flag (commit_flag) attribute of the first transaction to 0, initializing a rollback flag (rollback_flag) attribute of the first transaction to 0, initializing a rollback transaction list (rollback_trx_list) attribute of the first transaction to empty, initializing a passive rollback (force_rollback) attribute of the first transaction to false, initializing a row lock instance queue (row_lock_list) attribute of the first transaction to empty, and allocating a globally unique and increasing transaction identifier (trx_id) to the first transaction.
[0050] Further, based on the above-mentioned embodiment of the invention, when the transaction change request is a transaction update request, according to the transaction change request of the first transaction, performing a corresponding transaction change operation on the first transaction includes:
[0051] In response to the transaction update request, determining a target row lock type and row lock instance creation status of each target data row involved in the first transaction;
[0052] When the target row lock type and the row lock instance creation condition meet the first preset condition, an update operation is performed on the target data row; wherein the first preset condition includes: the first transaction has created a row lock instance of the target data row, and the row lock type level of the row lock instance is higher than or equal to the level of the target row lock type;
[0053] When the target row lock type and the row lock instance creation status do not meet the first preset condition but meet the second preset condition, perform a transaction rollback operation on the first transaction; wherein the second preset condition includes: there is another transaction that has created a row lock instance of the target data row, and the row lock type of the row lock instance conflicts with the target row lock type, and the transaction identifier of the other transaction is greater than the transaction identifier of the first transaction;
[0054] When the target row lock type and the row lock instance creation status do not meet the first preset condition and the second preset condition but meet the third preset condition, the first transaction is added to the global row lock waiting queue of the target data row, and the waiting lock type and waiting transaction attribute of the first transaction are set; wherein the third preset condition includes: there are other transactions that have created a row lock instance of the target data row, and the row lock instance is online and the row lock type of the row lock instance conflicts with the target row lock type, or there are other transactions waiting for the row lock of the target data row and the row lock type of the row lock conflicts with the target row lock type;
[0055] When the target row lock type and the row lock instance creation situation do not meet the first preset condition, the second preset condition and the third preset condition, a row lock instance of the target data row is created and initialized, the row lock instance is added to the row lock instance queue of the first transaction, and the row lock instance is inserted after the last offline row lock instance in the global row lock instance list of the target data row.
[0056] Further, based on the above-mentioned embodiment of the invention, when the target row lock type and the row lock instance creation condition do not meet the first preset condition, the second preset condition and the third preset condition, it also includes:
[0057] If the first target conflicting row lock instance exists in the global row lock instance list, the commit flag of the first transaction is incremented;
[0058] If the second target conflicting row lock instance exists in the global row lock instance list, the rollback flag of the creation transaction corresponding to the second target conflicting row lock instance is incremented, and the rollback transaction list of the creation transaction is updated;
[0059] Perform an update operation on the target data row.
[0060] Among them, the target data row may refer to the data row to be updated in the first transaction. The target row lock type may refer to the type of row lock corresponding to the target data row. This embodiment does not limit the row lock type. For example, it may be a read lock, a write lock, etc. At the same time, there are different levels between different row lock types, and the levels are divided into high and low levels. The specific definition rules are not limited in this embodiment. Generally, the level of the write lock is higher than the level of the read lock. Furthermore, the conflict of row lock types determines that different transactions can apply for the specific row lock type of the same data row at the same time. The specific logic is not limited in this embodiment. Generally, there is no conflict when different transactions apply for read locks, and there is a conflict when different transactions apply for write locks or one transaction applies for a write lock and another transaction applies for a read lock.
[0061] The row lock instance creation status can be understood as the creation status of the row lock instance corresponding to the target data row, for example, it may include but is not limited to the following information: whether the target data row already has a created row lock instance, whether the row lock instance corresponding to the target data row is created by the first transaction or other transactions, the row lock type and level of the row lock instance corresponding to the target data row (if it is created by other transactions), etc.
[0062] In this embodiment, each transaction maintains a row lock instance queue (row_lock_list), which contains row lock instances of all data rows created by the transaction, and the row lock instances contain type attributes (row lock type), which may include read lock, write lock, etc.
[0063] Each data row maintains a global row lock instance list, which contains the row lock instances created by each transaction for the data row, and the row lock instances contain state attributes, which can include online and offline. In addition, each data row also maintains a global row lock waiting queue, which contains all waiting transactions to apply for row locks for the data row.
[0064] In the embodiment of the present invention, Figure 2 As shown, the transaction update process specifically includes:
[0065] S21. In response to a transaction update request, determine a target row lock type and row lock instance creation status for each target data row involved in the first transaction.
[0066] Specifically, after the database receives the transaction update request initiated by the client in the current session, it determines each target data row to be updated in the first transaction and the target row lock type (req_lock_type) for applying for a row lock for each target data row by parsing the corresponding SQL statement, and at the same time determines the creation status of the row lock instance corresponding to the target data row by traversing the row lock instance queue of the first transaction and the global row lock instance list of the target data row.
[0067] S22: Determine whether the target row lock type and row lock instance creation status meet a first preset condition.
[0068] Specifically, it can be determined whether the first transaction (cur_trx) has created a row lock instance for the target data row, and the row lock type level of the row lock instance is higher than or equal to the level of the target row lock type. If so, execute S212, otherwise execute S23.
[0069] S23: Determine whether the target row lock type and row lock instance creation status meet the second preset condition.
[0070] Specifically, it can be determined whether there is another transaction (other_trx) that has created a row lock instance for the target data row, and the row lock type of the row lock instance conflicts with the target row lock type, and the transaction identifier of the other transaction is greater than the transaction identifier of the first transaction. If so, exit the transaction update process and execute S213, otherwise execute S24.
[0071] S24. Determine whether the target row lock type and row lock instance creation status meet the third preset condition.
[0072] Specifically, it can be determined whether other transactions have created a row lock instance for the target data row, and the row lock instance is online and the row lock type of the row lock instance conflicts with the target row lock type, or whether other transactions are waiting for the row lock of the target data row and the row lock type of the row lock conflicts with the target row lock type. If so, execute S210, otherwise execute S25.
[0073] S25. Create a row lock instance for the target data row, add the initialized row lock instance to the row lock instance queue of the first transaction, and insert the row lock instance after the last offline row lock instance in the global row lock instance list of the target data row.
[0074] Specifically, a row lock instance (new_lock) for the current target data row can be created for the first transaction, and the row lock instance can be initialized, that is, its type attribute is set to the target row lock type (req_lock_type), its status attribute is set to online, and its creation transaction attribute is set to the first transaction (cur_trx); at the same time, the row lock instance is added to the row lock instance queue of the first transaction, and the row lock instance is inserted after the last offline row lock instance in the global row lock instance list of the target data row, that is, inserted after all offline row lock instances in the global row lock instance list.
[0075] S26. Determine whether there is a first target conflicting row lock instance in the global row lock instance list.
[0076] Specifically, it can be determined whether there is a first target conflicting row lock instance in the global row lock instance list of the target data row that meets the following conditions: there is a row lock instance in all offline row lock instances that conflicts with the target row lock type (req_lock_type); if so, execute S27, otherwise execute S28.
[0077] S27: Increment the commit flag of the first transaction.
[0078] Specifically, if there is a first target conflicting row lock instance, the commit flag (commit_flag) of the first transaction is set to be plus 1, and S28 is executed.
[0079] S28. Determine whether there is a second target conflicting row lock instance in the global row lock instance list.
[0080] Specifically, you can continue to determine whether there is a second target conflicting row lock instance in the global row lock instance list of the target data row that meets the following conditions: the row lock instance of the target data row is created by other transactions (other_trx), and the row lock type of the row lock instance conflicts with the target row lock type, and the row lock instance is offline. If it exists, execute S29, otherwise execute S212.
[0081] S29. Increment the rollback flag of the creation transaction corresponding to the second target conflicting row lock instance, and update the rollback transaction list of the creation transaction.
[0082] Specifically, if there is a second target conflicting row lock instance, the rollback flag (rollback_flag) of the creation transaction corresponding to the second target conflicting row lock instance is set to be plus 1, and the rollback transaction list (rollback_trx_list) of the creation transaction is set to add the first transaction, and S212 is executed.
[0083] S210: Add the first transaction to the global row lock waiting queue of the target data row, and set the waiting lock type and waiting transaction attributes of the first transaction.
[0084] Specifically, the first transaction can be added to the global row lock wait queue of the target data row, and the wait lock type attribute of the first transaction is set to the target row lock type (req_lock_type), and the wait transaction attribute of the first transaction is set to the first transaction found that has a lock conflict with the first transaction.
[0085] S211. The current session enters a sleep state.
[0086] Specifically, after the current session enters the sleep state, if it is awakened by the session of other transactions, S212 is executed; if it is detected that the passive rollback (force_rollback) attribute of the first transaction is true, the transaction update process is exited and S213 is executed; if the sleep timeout is exceeded (the timeout period can be configured through system parameters), S214 is executed.
[0087] S212: Execute a data update operation on the target data row.
[0088] S213: Perform a transaction rollback operation on the first transaction.
[0089] S214: Return a lock timeout error message to the client.
[0090] Specifically, if the sleep timeout occurs, a lock timeout error message is returned to the client, and the transaction update process ends.
[0091] Furthermore, after executing the data update operation on each target data row, the database may return the number of updated target data rows to the client.
[0092] Further, based on the above-mentioned embodiment of the invention, according to the early lock release request of the first transaction, the first transaction is released early, and the second transaction having a transaction dependency relationship with the first transaction is awakened, including:
[0093] In response to the early release lock request, traverse the row lock instance queue of the first transaction to determine each target data row;
[0094] For each row lock instance in the online state of each target data row, set the row lock instance to the offline state, determine the last offline row lock instance in the global row lock instance list of the target data row, and move the row lock instance to the back of the last offline row lock instance;
[0095] The global row lock waiting queue of each target data row is traversed to find out all second transactions waiting for the first transaction, and a transaction wake-up operation is performed on each second transaction.
[0096] In the embodiment of the present invention, Figure 3 As shown in the figure, the process of releasing the lock in advance specifically includes:
[0097] S31. In response to an early lock release request, traverse the row lock instance queue of the first transaction to determine each target data row and an online row lock instance.
[0098] Specifically, after receiving the early lock release request initiated by the client in the current session, the database can traverse the row lock instance queue of the first transaction to find each target data row and the row lock instance in the corresponding online state.
[0099] S32. For each row lock instance in the online state of the target data row, set the row lock instance to the offline state, and move the row lock instance to behind the last offline row lock instance in the global row lock instance list of the target data row.
[0100] Specifically, for each online row lock instance of the target data row, its status can be set to offline, and the row lock instance can be moved behind the last offline row lock instance in the global row lock instance list of the target data row, that is, moved behind all offline row lock instances in the global row lock instance list.
[0101] S33, traverse the global row lock waiting queue of each target data row, find out all second transactions waiting for the first transaction, and perform a transaction wake-up operation on each second transaction.
[0102] Further, based on the above-mentioned embodiments of the invention, Figure 4 As shown in the figure, the transaction wake-up operation process specifically includes:
[0103] S41. Obtain the waiting lock type of the second transaction by querying the global row lock waiting queue of the target data row.
[0104] Specifically, the waiting lock type (waiting_lock_type) of the second transaction (waiting transaction waiting_trx) may be acquired by querying the global row lock waiting queue of the target data row.
[0105] S42: Determine whether the row lock instance creation status of the target data row meets the fifth preset condition.
[0106] Specifically, it can be determined whether other transactions (not the second transaction) have created a row lock instance for the target data row, and the row lock instance is online and the row lock type of the row lock instance conflicts with the waiting lock type of the second transaction. If so, the transaction wake-up operation process of the second transaction is terminated, otherwise S43 is executed.
[0107] S43. Create a row lock instance for the target data row corresponding to the second transaction, add the row lock instance to the row lock instance queue of the second transaction, and insert the row lock instance after the last offline row lock instance in the global row lock instance list of the target data row.
[0108] Specifically, a row lock instance for the current target data row can be created for the second transaction, and its type attribute can be set to the waiting lock type (waiting_lock_type), its status attribute can be set to online, and its creation transaction attribute can be set to the second transaction (waiting_trx); at the same time, the row lock instance can be added to the row lock instance queue of the second transaction, and the row lock instance can be inserted after the last offline row lock instance in the global row lock instance list of the target data row, that is, after all offline row lock instances in the global row lock instance list.
[0109] S44. Determine whether there is a third target conflicting row lock instance in the global row lock instance list of the target data row.
[0110] Specifically, it can be determined whether there is a third target conflicting row lock instance that meets the following conditions in the global row lock instance list of the target data row: there is a row lock instance that conflicts with the waiting lock type (waiting_lock_type) among all offline row lock instances. If so, execute S45, otherwise execute S46.
[0111] S45: Increment the commit flag of the second transaction.
[0112] Specifically, if there is a third target conflicting row lock instance, the commit flag (commit_flag) of the second transaction is set to be plus 1, and S46 is executed.
[0113] S46. Determine whether there is a fourth target conflicting row lock instance in the global row lock instance list.
[0114] Specifically, it can be determined whether there is a fourth target conflicting row lock instance in the global row lock instance list of the target data row that meets the following conditions: the row lock instance of the target data row is created by other transactions, and the row lock type of the row lock instance conflicts with the waiting lock type, and the row lock instance is offline. If so, execute S47, otherwise execute S48.
[0115] S47. Increment the rollback flag of the creation transaction corresponding to the fourth target conflicting row lock instance, and update the rollback transaction list of the creation transaction.
[0116] Specifically, if there is a fourth target conflict row lock instance, the rollback flag (rollback_flag) of the creation transaction corresponding to the fourth target conflict row lock instance is set to be plus 1, and the rollback transaction list (rollback_trx_list) of the creation transaction is set to add the second transaction (waiting_trx), and S48 is executed.
[0117] S48: Delete the second transaction from the global row lock waiting queue, and wake up the session where the second transaction is located.
[0118] Among them, session awakening is a communication mechanism between threads, and this embodiment does not limit the specific awakening method.
[0119] Further, based on the above-mentioned embodiment of the invention, when the transaction change request is a transaction commit request, according to the transaction change request of the first transaction, performing a corresponding transaction change operation on the first transaction includes:
[0120] In response to the transaction commit request, determining whether the commit flag of the first transaction is an initial preset value;
[0121] If yes, release the transaction lock corresponding to the first transaction;
[0122] If not, when it is detected that the passive rollback attribute of the first transaction is true, a transaction rollback operation is performed on the first transaction.
[0123] In the embodiment of the present invention, Figure 5 As shown in the figure, the transaction submission process specifically includes:
[0124] S51. In response to a transaction commit request, obtain a commit identifier of a first transaction.
[0125] Specifically, after receiving a transaction commit request initiated by a client in the current session, the database may obtain a commit flag (commit_flag) corresponding to the first transaction.
[0126] S52: Determine whether the submission flag is an initial preset value.
[0127] Specifically, if the commit flag of the first transaction is an initial preset value (eg, 0), S53 is executed; otherwise, S54 is executed.
[0128] S53: Execute a transaction lock release operation on the first transaction.
[0129] S54: Determine whether the passive rollback attribute of the first transaction is true.
[0130] Specifically, if it is detected that the passive rollback (force_rollback) attribute of the first transaction is true, S55 is executed, otherwise the process returns to execute S52.
[0131] S55: Perform a transaction rollback operation on the first transaction.
[0132] Further, based on the above-mentioned embodiment of the invention, when the transaction change request is a transaction rollback request, according to the transaction change request of the first transaction, performing a corresponding transaction change operation on the first transaction includes:
[0133] In response to a transaction rollback request, traverse the rollback transaction list of the first transaction, and set the passive rollback attribute of each to-be-rolled-back transaction in the rollback transaction list to true;
[0134] When the rollback flag of the first transaction is an initial preset value, the first transaction is rolled back to a target rollback point, and a transaction lock corresponding to the first transaction is released; wherein the target rollback point is a corresponding time point when the first transaction is opened.
[0135] In the embodiment of the present invention, Figure 6 As shown in the figure, the transaction rollback process specifically includes:
[0136] S61. In response to a transaction rollback request, traverse the rollback transaction list of the first transaction, and set the passive rollback attribute of each transaction to be rolled back in the rollback transaction list to true.
[0137] Specifically, after receiving the transaction rollback request initiated by the client in the current session, the database can traverse the rollback transaction list (rollback_trx_list) of the first transaction, find all transactions to be rolled back, and set the passive rollback (force_rollback) attribute corresponding to each transaction to be rolled back to true.
[0138] Furthermore, in this embodiment, in addition to the transaction rollback request actively initiated by the client triggering the transaction rollback process, the transaction rollback process is also triggered when the transaction needs to be passively rolled back, such as steps S213 and S55 in the above embodiment.
[0139] S62: Determine whether the rollback flag of the first transaction is an initial preset value.
[0140] Specifically, if the rollback flag (rollback_flag) of the first transaction is an initial preset value (for example, 0), S63 is executed, otherwise S62 is repeatedly executed.
[0141] S63: Roll back the first transaction to the target rollback point.
[0142] Specifically, if it is detected that the rollback flag of the first transaction is the initial preset value, the first transaction is rolled back to the target rollback point, where the target rollback point is the corresponding time point when the first transaction is started, that is, the target data row involved in the transaction update operation of the first transaction is restored to the data state before the transaction started. The specific data rollback method is not limited in this embodiment.
[0143] S64: Execute a release transaction lock operation on the first transaction.
[0144] Further, based on the above-mentioned embodiment of the invention, releasing the transaction lock corresponding to the first transaction includes:
[0145] Traverse the row lock instance queue of the first transaction, determine the row lock instance corresponding to each target data row involved in the first transaction, delete the row lock instance from the global row lock instance list corresponding to the target data row, and execute the following process for each deleted row lock instance:
[0146] Determine whether the first row lock instance in the global row lock instance list satisfies a fourth preset condition; wherein the fourth preset condition includes: the first row lock instance is in an offline state, and the row lock type of the first row lock instance conflicts with the target row lock type of the deleted row lock instance;
[0147] If so, the commit identifier of the transaction created corresponding to the first row lock instance is decremented, and the traversal starts from the second row lock instance in the global row lock instance list. When it is determined that the row lock type of the first target row lock instance currently traversed does not conflict with that of the first row lock instance, the commit identifier of the transaction created corresponding to the first target row lock instance is decremented;
[0148] Start traversing in reverse order from the position of the deleted row lock instance in the global row lock instance list, and when it is determined that the row lock type of the second target row lock instance currently traversed conflicts with the deleted row lock instance, and the second target row lock instance is offline, decrement the rollback flag of the creation transaction corresponding to the second target row lock instance, and update the rollback transaction list of the creation transaction;
[0149] The global row lock waiting queue of the target data row is traversed to find out all waiting transactions that are waiting for the first transaction, and a transaction wake-up operation is performed on each waiting transaction.
[0150] In the embodiment of the present invention, Figure 7 As shown in the figure, the process of releasing transaction locks specifically includes:
[0151] S71. Traverse the row lock instance queue of the first transaction, determine the row lock instance corresponding to each target data row involved in the first transaction, and delete the row lock instance from the global row lock instance list corresponding to the target data row.
[0152] Specifically, when it is necessary to release the transaction lock corresponding to the first transaction, the row lock instance queue (row_lock_list) corresponding to the first transaction can be traversed to determine the row lock instance corresponding to each target data row, and each row lock instance can be deleted from the global row lock instance list of the corresponding target data row. At the same time, the deletion position (del_pos) of the deleted row lock instance in the corresponding global row lock instance list is recorded, and S72 is executed for the deleted row lock instance corresponding to each target data row.
[0153] S72: Determine whether the first row lock instance in the global row lock instance list satisfies a fourth preset condition.
[0154] Specifically, it can be determined whether the first row lock instance in the global row lock instance list meets the following conditions: the first row lock instance is offline, and the row lock type of the first row lock instance conflicts with the target row lock type of the deleted row lock instance. If so, execute S73, otherwise execute S78.
[0155] S73. Decrement the commit flag of the transaction that creates the first row lock instance.
[0156] Specifically, if the first row lock instance satisfies the fourth preset condition, the commit flag (commit_flag) of the creation transaction corresponding to the first row lock instance is set to be minus 1.
[0157] S74. Start traversing from the second row lock instance in the global row lock instance list.
[0158] Specifically, the traversal may be started from the second row lock instance in the global row lock instance list (positive order traversal), and S75 to S77 may be executed in sequence for the traversed row lock instances.
[0159] S75. Determine whether the row lock types of the first target row lock instance currently traversed conflict with the first row lock instance.
[0160] Specifically, it can be determined whether the row lock type of the first target row lock instance currently traversed conflicts with the row lock type of the first row lock instance in the aforementioned global row lock instance list. If so, execute S76, otherwise execute S77.
[0161] S76. End the current traversal.
[0162] Specifically, if the row lock type of the first target row lock instance currently traversed conflicts with the row lock type of the aforementioned first row lock instance, the current traversal is terminated and S78 is executed.
[0163] S77. Decrement the commit flag of the creation transaction corresponding to the first target row lock instance.
[0164] Specifically, if the row lock type of the first target row lock instance currently traversed does not conflict with the row lock type of the aforementioned first row lock instance, the commit flag (commit_flag) of the creation transaction corresponding to the first target row lock instance is set to minus 1, and S78 is executed.
[0165] S78. Start traversing in reverse order from the deletion position of the deleted row lock instance in the global row lock instance list.
[0166] Specifically, if the first row lock instance does not meet the fourth preset condition, reverse traversal is performed starting from the deletion position (del_pos) of the deleted row lock instance in the global row lock instance list corresponding to the target data row, and S79 to S711 are executed in sequence for the traversed row lock instances.
[0167] S79: Determine whether the second target row lock instance currently traversed conflicts with the row lock type of the deleted row lock instance, and whether the second target row lock instance is offline.
[0168] Specifically, it can be determined whether the second target row lock instance currently traversed satisfies the following conditions at the same time: the row lock type conflicts with the deleted row lock instance and is in an offline state. If so, execute S710.
[0169] S710: Decrement the rollback flag of the creation transaction corresponding to the second target row lock instance, and update the rollback transaction list of the creation transaction.
[0170] Specifically, if the second target row lock instance currently traversed meets the above conditions, the rollback flag (rollback_flag) of the creation transaction corresponding to the second target row lock instance is set to be plus 1, and the rollback transaction list (rollback_trx_list) of the creation transaction is set to remove the first transaction (waiting_trx), and S711 is executed.
[0171] S711. End the current traversal.
[0172] S712: traverse the global row lock waiting queue of the target data row.
[0173] Specifically, the global row lock waiting queue corresponding to the target data row may be traversed to find out each waiting transaction, and S713 to S714 are executed in sequence for each waiting transaction.
[0174] S713: Determine whether the transaction being waited for by the traversed waiting transaction is the first transaction.
[0175] Specifically, it may be determined whether the transaction being waited for by the currently traversed waiting transaction (waiting_trx) is the first transaction. If so, S714 is executed.
[0176] S714: Execute a transaction wake-up operation on the currently traversed waiting transaction.
[0177] Further, based on the above-mentioned embodiments of the invention, Figure 8 Flow chart of another database transaction concurrency control method provided in Embodiment 1 of the present invention. Figure 8 As shown, the database transaction concurrency control method specifically includes:
[0178] S81. The database receives a connection establishment request initiated by the user and establishes a database connection and a corresponding current session for the user.
[0179] S82: The database receives an SQL statement for starting a transaction sent by the user in the current session, starts a first transaction, and initializes various attribute parameters of the first transaction.
[0180] S83. Periodically determine whether the passive rollback attribute of the first transaction is true.
[0181] Specifically, while waiting to receive the SQL statement sent by the user, the database will periodically (for example, every 1 second) determine whether the passive rollback attribute (force_rollback) of the first transaction (cur_trx) is true. If so, S84 is executed, otherwise S85 is executed.
[0182] S84: Disconnect the database connection with the user, and perform a transaction rollback operation on the first transaction.
[0183] S85. The database sequentially receives SQL statements for reading and writing data sent by one or more users in the current session, and executes corresponding transaction update operations on the first transaction.
[0184] S86: The database receives an SQL statement for releasing the lock in advance sent by the user in the current session, and executes a process for releasing the lock in advance for the first transaction.
[0185] S87: The database receives an SQL statement for committing a transaction or rolling back a transaction sent by the user in the current session, and executes a transaction commit operation or a transaction rollback operation on the first transaction.
[0186] The embodiment of the present invention designs a new concurrency control method for a relational database that supports transaction consistency, which significantly improves the overall throughput when hot spot data is frequently updated by a large number of concurrent transactions and competes, while strictly ensuring the ACID properties of the transaction; by releasing the lock before the transaction is committed, the parallelism of concurrent updates to the hot spot data is improved, and the overall throughput is improved; it realizes efficient submission of transactions in the order of transaction dependencies and reverse rollback of transactions, ensuring transaction isolation.
[0187] Embodiment 2
[0188] Fig. 9 This is a schematic diagram of the structure of a database transaction concurrency control device provided in Embodiment 2 of the present invention. Fig. 9 As shown, the device comprises:
[0189] A first transaction opening module 91, configured to open a first transaction based on a received service request;
[0190] A first transaction change module 92, configured to perform a corresponding transaction change operation on the first transaction according to a transaction change request of the first transaction;
[0191] The early lock release module 93 is used to execute early lock release on the first transaction according to the early lock release request of the first transaction, and wake up the second transaction that has a transaction dependency relationship with the first transaction, so that the second transaction executes the corresponding transaction update operation.
[0192] The technical solution of the embodiment of the present invention is to start the first transaction based on the received business request through the first transaction start module; the first transaction change module performs the corresponding transaction change operation on the first transaction according to the transaction change request of the first transaction; the early lock release module performs early lock release on the first transaction according to the early lock release request of the first transaction, and wakes up the second transaction that has a transaction dependency relationship with the first transaction, so that the second transaction performs the corresponding transaction update operation. This technical solution improves the overall throughput of the system when there is hot data being frequently updated by a large number of concurrent transactions and competing, and improves the parallelism of concurrent updates of hot data, while being able to strictly guarantee the ACID properties of transactions by releasing locks in advance before transaction submission.
[0193] Further, based on the above-mentioned embodiment of the invention, the early release lock module 93 includes:
[0194] A row lock instance queue traversal unit, configured to traverse the row lock instance queue of the first transaction in response to the early release lock request to determine each target data row;
[0195] A row lock instance setting unit, for setting the row lock instance in the online state of each target data row to the offline state, and determining the last offline row lock instance in the global row lock instance list of the target data row, and moving the row lock instance to the back of the last offline row lock instance;
[0196] The transaction wake-up unit is used to traverse the global row lock waiting queue of each target data row, find out all second transactions waiting for the first transaction, and perform a transaction wake-up operation on each second transaction.
[0197] Further, based on the above-mentioned embodiment of the invention, when the transaction change request is a transaction update request, the first transaction change module 92 includes:
[0198] A transaction update request response unit, configured to determine, in response to the transaction update request, a target row lock type and a row lock instance creation status for each target data row involved in the first transaction;
[0199] A first execution unit, configured to execute an update operation on a target data row when a target row lock type and a row lock instance creation condition satisfy a first preset condition; wherein the first preset condition comprises: a row lock instance of the target data row has been created by the first transaction, and a row lock type level of the row lock instance is higher than or equal to a level of the target row lock type;
[0200] A second execution unit is used to perform a transaction rollback operation on the first transaction when the target row lock type and the row lock instance creation status do not meet the first preset condition but meet the second preset condition; wherein the second preset condition includes: there is another transaction that has created a row lock instance of the target data row, and the row lock type of the row lock instance conflicts with the target row lock type, and the transaction identifier of the other transaction is greater than the transaction identifier of the first transaction;
[0201] A third execution unit is used to add the first transaction to the global row lock waiting queue of the target data row, and set the waiting lock type and waiting transaction attribute of the first transaction when the target row lock type and the row lock instance creation status do not meet the first preset condition and the second preset condition but meet the third preset condition; wherein the third preset condition includes: there are other transactions that have created a row lock instance of the target data row, and the row lock instance is online and the row lock type of the row lock instance conflicts with the target row lock type, or there are other transactions waiting for the row lock of the target data row and the row lock type of the row lock conflicts with the target row lock type;
[0202] The fourth execution unit is used to create a row lock instance for the target data row and initialize the row lock instance when the target row lock type and the row lock instance creation status do not meet the first preset condition, the second preset condition and the third preset condition, and add the row lock instance to the row lock instance queue of the first transaction, and insert the row lock instance after the last offline row lock instance in the global row lock instance list of the target data row.
[0203] Further, based on the above-mentioned embodiment of the invention, the first transaction change module 92 further includes:
[0204] a fifth execution unit, configured to, when the target row lock type and the row lock instance creation condition do not satisfy the first preset condition, the second preset condition and the third preset condition, if the first target conflicting row lock instance exists in the global row lock instance list, increment the commit flag of the first transaction;
[0205] The sixth execution unit is used to increment the rollback identifier of the creation transaction corresponding to the second target conflicting row lock instance if there is a second target conflicting row lock instance in the global row lock instance list, and update the rollback transaction list of the creation transaction;
[0206] The seventh execution unit is used to perform an update operation on the target data row.
[0207] Further, based on the above-mentioned embodiment of the invention, when the transaction change request is a transaction commit request, the first transaction change module 92 includes:
[0208] A transaction commit request response unit, configured to respond to the transaction commit request and determine whether the commit flag of the first transaction is an initial preset value;
[0209] A first transaction submission request execution unit, configured to release a transaction lock corresponding to the first transaction if yes;
[0210] The second transaction submission request execution unit is configured to, if not, execute a transaction rollback operation on the first transaction when it is detected that the passive rollback attribute of the first transaction is true.
[0211] Further, based on the above-mentioned embodiment of the invention, when the transaction change request is a transaction rollback request, the first transaction change module 92 includes:
[0212] a transaction rollback request response unit, configured to respond to the transaction rollback request, traverse the rollback transaction list of the first transaction, and set the passive rollback attribute of each to-be-rolled transaction in the rollback transaction list to true;
[0213] The transaction rollback request execution unit is used to roll back the first transaction to a target rollback point and release the transaction lock corresponding to the first transaction when the rollback identifier of the first transaction is an initial preset value; wherein the target rollback point is a corresponding time point when the first transaction is opened.
[0214] Further, based on the above-mentioned embodiment of the invention, releasing the transaction lock corresponding to the first transaction includes:
[0215] Traverse the row lock instance queue of the first transaction, determine the row lock instance corresponding to each target data row involved in the first transaction, delete the row lock instance from the global row lock instance list corresponding to the target data row, and execute the following process for each deleted row lock instance:
[0216] Determine whether the first row lock instance in the global row lock instance list satisfies a fourth preset condition; wherein the fourth preset condition includes: the first row lock instance is in an offline state, and the row lock type of the first row lock instance conflicts with the target row lock type of the deleted row lock instance;
[0217] If so, the commit identifier of the transaction created corresponding to the first row lock instance is decremented, and the traversal starts from the second row lock instance in the global row lock instance list. When it is determined that the row lock type of the first target row lock instance currently traversed does not conflict with that of the first row lock instance, the commit identifier of the transaction created corresponding to the first target row lock instance is decremented;
[0218] Start traversing in reverse order from the position of the deleted row lock instance in the global row lock instance list, and when it is determined that the row lock type of the second target row lock instance currently traversed conflicts with the deleted row lock instance, and the second target row lock instance is offline, decrement the rollback flag of the creation transaction corresponding to the second target row lock instance, and update the rollback transaction list of the creation transaction;
[0219] The global row lock waiting queue of the target data row is traversed to find out all waiting transactions that are waiting for the first transaction, and a transaction wake-up operation is performed on each waiting transaction.
[0220] Further, based on the above-mentioned embodiment of the invention, the first transaction start module 91 includes:
[0221] The database connection and session establishment module is used to receive the client's business request, establish the database connection and the current session;
[0222] The first transaction opening and initialization module is used to respond to a transaction opening request in the current session, open a first transaction, and initialize the first transaction.
[0223] Furthermore, based on the above-mentioned embodiment of the invention, the database transaction concurrency control device further includes:
[0224] The passive rollback detection module is used to periodically detect the passive rollback attribute of the first transaction in the process of waiting to receive the transaction change request, and execute a transaction rollback operation on the first transaction when the passive rollback attribute is detected to be true.
[0225] The database transaction concurrency control device provided in the embodiment of the present invention can execute the database transaction concurrency control method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0226] Embodiment 3
[0227] Fig.10 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0228] like Fig.10As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0229] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0230] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a database transaction concurrency control method.
[0231] In some embodiments, the database transaction concurrency control method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps in the database transaction concurrency control method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the database transaction concurrency control method in any other appropriate manner (e.g., by means of firmware).
[0232] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0233] In some embodiments, the database transaction concurrency control method can be implemented as a computer program, which is invisibly included in a computer program product. When the computer program is executed by a processor, the database transaction concurrency control method of the present invention is implemented. The computer program product can be understood as a software product that mainly implements its solution through a computer program. The computer program for implementing the method of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program can be executed entirely on the machine, partially on the machine, as an independent software package, partially on the machine and partially on a remote machine, or completely on a remote machine or server.
[0234] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0235] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0236] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0237] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0238] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0239] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A database transaction concurrency control method, characterized in that: The method comprises: Based on the received business request, start a first transaction; According to the transaction change request of the first transaction, perform a corresponding transaction change operation on the first transaction; According to the early lock release request of the first transaction, the first transaction is early locked, and a second transaction having a transaction dependency relationship with the first transaction is awakened, so that the second transaction executes a corresponding transaction update operation.
2. The method according to claim 1, characterized in that The method of releasing the lock in advance for the first transaction according to the early lock release request of the first transaction and waking up the second transaction that has a transaction dependency relationship with the first transaction includes: In response to the early lock release request, traverse the row lock instance queue of the first transaction to determine each target data row; For each row lock instance in the online state of the target data row, set the row lock instance to an offline state, determine the last offline row lock instance in the global row lock instance list of the target data row, and move the row lock instance to behind the last offline row lock instance; The global row lock waiting queue of each target data row is traversed to find out all the second transactions that are waiting for the first transaction, and a transaction wake-up operation is performed on each of the second transactions.
3. The method according to claim 1, characterized in that When the transaction change request is a transaction update request, performing a corresponding transaction change operation on the first transaction according to the transaction change request of the first transaction includes: In response to the transaction update request, determining a target row lock type and row lock instance creation status of each target data row involved in the first transaction; When the target row lock type and the row lock instance creation condition meet a first preset condition, an update operation is performed on the target data row; wherein the first preset condition includes: the first transaction has created a row lock instance for the target data row, and the row lock type level of the row lock instance is higher than or equal to the level of the target row lock type; When the target row lock type and the row lock instance creation condition do not meet the first preset condition but meet the second preset condition, perform a transaction rollback operation on the first transaction; wherein the second preset condition includes: there is another transaction that has created a row lock instance of the target data row, and the row lock type of the row lock instance conflicts with the target row lock type, and the transaction identifier of the other transaction is greater than the transaction identifier of the first transaction; When the target row lock type and the row lock instance creation situation do not meet the first preset condition and the second preset condition but meet the third preset condition, the first transaction is added to the global row lock waiting queue of the target data row, and the waiting lock type and waiting transaction attribute of the first transaction are set; wherein the third preset condition includes: there are other transactions that have created a row lock instance of the target data row, and the row lock instance is online and the row lock type of the row lock instance conflicts with the target row lock type, or there are other transactions waiting for the row lock of the target data row and the row lock type of the row lock conflicts with the target row lock type; When the target row lock type and the row lock instance creation situation do not satisfy the first preset condition, the second preset condition and the third preset condition, a row lock instance for the target data row is created and initialized, the row lock instance is added to the row lock instance queue of the first transaction, and the row lock instance is inserted after the last offline row lock instance in the global row lock instance list of the target data row.
4. The method according to claim 3, characterized in that When the target row lock type and the row lock instance creation condition do not satisfy the first preset condition, the second preset condition and the third preset condition, the method further includes: If the first target conflicting row lock instance exists in the global row lock instance list, the commit flag of the first transaction is incremented; If there is a second target conflicting row lock instance in the global row lock instance list, the rollback identifier of the creation transaction corresponding to the second target conflicting row lock instance is incremented, and the rollback transaction list of the creation transaction is updated; An update operation is performed on the target data row.
5. The method according to claim 1, characterized in that When the transaction change request is a transaction commit request, performing a corresponding transaction change operation on the first transaction according to the transaction change request of the first transaction includes: In response to the transaction commit request, determining whether the commit flag of the first transaction is an initial preset value; If yes, releasing the transaction lock corresponding to the first transaction; If not, when it is detected that the passive rollback attribute of the first transaction is true, a transaction rollback operation is performed on the first transaction.
6. The method according to claim 1, characterized in that When the transaction change request is a transaction rollback request, performing a corresponding transaction change operation on the first transaction according to the transaction change request of the first transaction includes: In response to the transaction rollback request, traverse the rollback transaction list of the first transaction, and set the passive rollback attribute of each to-be-rolled transaction in the rollback transaction list to true; When the rollback flag of the first transaction is an initial preset value, the first transaction is rolled back to a target rollback point, and a transaction lock corresponding to the first transaction is released; wherein the target rollback point is a corresponding time point when the first transaction is opened.
7. The method according to claim 5 or 6, characterized in that: The releasing the transaction lock corresponding to the first transaction includes: Traverse the row lock instance queue of the first transaction, determine the row lock instance corresponding to each target data row involved in the first transaction, delete the row lock instance from the global row lock instance list corresponding to the target data row, and execute the following process for each deleted row lock instance: Determine whether the first row lock instance in the global row lock instance list satisfies a fourth preset condition; wherein the fourth preset condition includes: the first row lock instance is in an offline state, and the row lock type of the first row lock instance conflicts with the target row lock type of the deleted row lock instance; If so, the commit identifier of the transaction created corresponding to the first row lock instance is decremented, and the traversal starts from the second row lock instance in the global row lock instance list. When it is determined that the row lock type of the first target row lock instance currently traversed does not conflict with that of the first row lock instance, the commit identifier of the transaction created corresponding to the first target row lock instance is decremented; Starting from the position of the deleted row lock instance in the global row lock instance list, traversing in reverse order, and when it is determined that the row lock type of the second target row lock instance currently traversed conflicts with that of the deleted row lock instance, and the second target row lock instance is offline, decrementing the rollback identifier of the creation transaction corresponding to the second target row lock instance, and updating the rollback transaction list of the creation transaction; The global row lock waiting queue of the target data row is traversed to find out all waiting transactions that are waiting for the first transaction, and a transaction wake-up operation is performed on each of the waiting transactions.
8. The method according to claim 1, characterized in that: The starting of the first transaction based on the received service request includes: Receive the service request from the client, establish a database connection and a current session; In response to the transaction opening request in the current session, the first transaction is opened and initialized.
9. The method according to claim 1, characterized in that: Also includes: In the process of waiting to receive the transaction change request, the passive rollback attribute of the first transaction is periodically detected, and when it is detected that the passive rollback attribute is true, a transaction rollback operation is performed on the first transaction.
10. A database transaction concurrency control device, characterized in that: The device comprises: A first transaction opening module, configured to open a first transaction based on a received service request; A first transaction change module, configured to perform a corresponding transaction change operation on the first transaction according to a transaction change request of the first transaction; The early lock release module is used to execute early lock release on the first transaction according to the early lock release request of the first transaction, and wake up the second transaction that has a transaction dependency relationship with the first transaction, so that the second transaction executes the corresponding transaction update operation.
11. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the database transaction concurrency control method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database transaction concurrency control method according to any one of claims 1 to 9 when executed.
13. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the computer program implements the database transaction concurrency control method according to any one of claims 1 to 9.