Database transaction processing method and device, equipment and storage medium

By dividing distributed transactions into sub-transactions and executing them in each partition, combining the two-stage submission mechanism, the ACID attributes and efficiency problems of distributed databases in cross-partition transaction processing are solved, and efficient and reliable distributed transaction processing is achieved.

CN118916122APending Publication Date: 2024-11-08BEIJING OCEANBASE TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411047628.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

When a distributed database handles distributed transactions across partitions, it is difficult to ensure the atomicity, consistency, isolation and persistence of transactions (ACID attributes), and it is insufficient in efficiency and speed.

Method used

Divide pending transactions into multiple sub-transactions, and perform update operations separately in the corresponding partitions of each sub-transaction. Through the two-stage submission mechanism, ensure successful recording and submission of update operations, and ensure the reliability of distributed transactions between multiple partitions and Execute sequentially.

Benefits of technology

Improve the efficiency and speed of distributed databases when processing cross-partition distributed transactions, ensure the ACID attributes of transactions, and reduce processing delays.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916122A_ABST
    Figure CN118916122A_ABST
Patent Text Reader

Abstract

One or more embodiments of the invention provide a database transaction processing method and device, equipment and a storage medium. According to the method, the to-be-processed transaction is divided into a plurality of sub-transactions according to the data record to be operated by the to-be-processed transaction, so that the corresponding updating operation is recorded in the partition to which the data record to be operated by each sub-transaction belongs according to the corresponding sub-transaction, and the preparation work of transaction submission is completed; and under the condition that the update operations of all the sub-transactions are successfully recorded to the corresponding partitions, submitting the recorded update operations to a database, so as to ensure that the distributed transaction can be reliably and sequentially executed among a plurality of partitions by utilizing a two-stage submission mode. And the efficiency and speed of the database in processing cross-partition distributed transactions are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a method, apparatus, device, and storage medium for processing database transactions. Background Art

[0002] Distributed database technology can not only effectively process big data and cope with high-concurrency access, but also provide high availability and flexible scalability, and can meet the challenging requirements of modern applications for database performance, fault tolerance and data processing capabilities.

[0003] In a distributed database, large data tables can be horizontally split into multiple partitions distributed on different servers through database partitioning technology to enhance the data management efficiency and data query speed of the distributed database. Therefore, in order to ensure that database operations can be performed on multiple partitions, the distributed database must also support cross-partition distributed transactions and ensure the atomicity, consistency, isolation, and durability (ACID) properties of cross-partition distributed transactions. Summary of the invention

[0004] In view of this, one or more embodiments of the present specification provide a method, apparatus, device, and storage medium for processing a database transaction.

[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:

[0006] According to a first aspect of one or more embodiments of this specification, a method for processing a database transaction is proposed, the method comprising:

[0007] According to the data records to be operated by the pending transaction, the pending transaction is divided into a plurality of sub-transactions, and different sub-transactions are used to operate different data records;

[0008] In the partition corresponding to each subtransaction, the corresponding update operation is recorded in accordance with the corresponding subtransaction. For any subtransaction, the partition corresponding to the subtransaction is the partition described by the data record to be operated by the subtransaction;

[0009] When the update operations of all subtransactions are successfully recorded in the corresponding partitions, the recorded update operations are submitted to the database.

[0010] According to a second aspect of one or more embodiments of this specification, a database transaction processing device is provided, the device comprising:

[0011] A generating module, used to divide the pending transaction into a plurality of sub-transactions according to the data records to be operated by the pending transaction, and different sub-transactions are used to operate different data records;

[0012] A recording module, used for recording corresponding update operations in the partition corresponding to each subtransaction respectively according to the corresponding subtransaction. For any subtransaction, the partition corresponding to the subtransaction is the partition recorded with the data to be operated by the subtransaction;

[0013] The commit module is used to commit the recorded update operations to the database when all the update operations of the subtransactions are successfully recorded in the corresponding partitions.

[0014] According to a third aspect of one or more embodiments of this specification, a computing device is provided, including:

[0015] processor;

[0016] a memory for storing processor-executable instructions;

[0017] The processor implements the method as described in the first aspect by running the executable instructions.

[0018] According to a fourth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the method described in the first aspect is implemented.

[0019] According to a fifth aspect of one or more embodiments of this specification, a computer program product is proposed, including a computer program, and when the computer program is executed by a processor, the method described in the first aspect above is implemented.

[0020] This specification divides a pending transaction into multiple sub-transactions according to the data records to be operated by the pending transaction, so that in the partition to which the data records to be operated by each sub-transaction belong, the corresponding update operations are recorded according to the corresponding sub-transaction records to complete the preparation work for transaction submission, and then when the update operations of all sub-transactions are successfully recorded in the corresponding partition, the recorded update operations are submitted to the database, so as to ensure that distributed transactions can be reliably and sequentially executed between multiple partitions by utilizing a two-phase commit method, thereby enhancing the efficiency and speed of the database in processing cross-partition distributed transactions. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is a schematic diagram of an application environment of a method for processing database transactions provided by an exemplary embodiment.

[0022] Figure 2It is a flowchart of a method for processing a database transaction provided by an exemplary embodiment.

[0023] Figure 3 It is a flowchart of a method for processing a database transaction provided by an exemplary embodiment.

[0024] Figure 4 It is a schematic diagram of a processing result of a database transaction provided by an exemplary embodiment.

[0025] Figure 5 It is a schematic structural diagram of a computing device provided by an exemplary embodiment.

[0026] Figure 6 It is a schematic block diagram of a database transaction processing device provided by an exemplary embodiment. DETAILED DESCRIPTION

[0027] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0028] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0029] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0030] This specification provides a database transaction processing method, which can be used to implement cross-partition distributed transaction processing in a distributed database using partitioning technology, so that database operations can be performed on multiple partitions while maintaining the ACID properties of the transaction.

[0031] See also Figure 1 , Figure 1 FIG. 1 is a schematic diagram of an application environment of a method for processing a database transaction provided by an exemplary embodiment. Figure 1 As shown, the database transaction processing method provided in this specification can be applied to Figure 1 In the distributed database system shown in Figure 1 In the distributed database system shown, two servers (Server) can be deployed in zone 1 (i.e., ZONE_1), zone 2 (i.e., ZONE_2), and zone 3 (i.e., ZONE_3), respectively. Among them, Server1_1 and Server1_2 can be deployed in ZONE_1, Server2_1 and Server2_2 can be deployed in ZONE_2, and Server3_1 and Server3_2 can be deployed in ZONE_3.

[0032] In some embodiments, tenant 1 (i.e., Tenant_1), tenant 2 (i.e., Tenant_2), and system tenant (i.e., Tenant_SYS) can all access and operate the distributed databases deployed in ZONE_1, ZONE_2, and ZONE_3, and operations between different tenants are isolated from each other. Figure 1 As shown, Tenant_1 can access and operate the services deployed in Server1_1, Server1_2, Server2_1, Server2_2, Server3_1, and Server3_2; Tenant_2 can access and operate the services deployed in Server1_2, Server2_2, and Server3_2; and Tenant_SYS can access and operate the services deployed in Server1_1, Server2_1, and Server3_1.

[0033] In some embodiments, the portion of Server1_1 accessible to Tenant_1 may include replica P1 and replica P2, wherein P1 is a primary replica; the portion of Server1_1 accessible to Tenant_SYS may include replica RS and replica P1. The portion of Server1_2 accessible to Tenant_1 may include replica P3 and replica P4; the portion of Server1_2 accessible to Tenant_2 may include replica P1 and replica P2, wherein P2 is a primary replica. The portion of Server2_1 accessible to Tenant_1 may include replica P1 and replica P2, wherein P2 is a primary replica; the portion of Server2_1 accessible to Tenant_SYS may include replica RS and replica P1, wherein RS is a primary replica. The portion of Server2_2 accessible to Tenant_1 may include replica P3 and replica P4, wherein P3 is a primary replica; the portion of Server2_2 accessible to Tenant_2 may include replica P1 and replica P2, wherein P1 is a primary replica. The portion of Server3_1 that Tenant_1 can access may include replicas P1 and P2; the portion of Server3_1 that Tenant_SYS can access may include replicas RS and P1, where P1 is the primary replica. The portion of Server3_2 that Tenant_1 can access may include replicas P3 and P4, where P4 is the primary replica; the portion of Server3_2 that Tenant_2 can access may include replicas P1 and P2.

[0034] In some embodiments, a database operation request can be initiated through application 1 and application 2, and the initiated database operation request can be routed to a database proxy. For example, the initiated database operation request can be routed to any one of Proxy1, Proxy2 and Proxy3, so that the tenant can access and operate the corresponding copy in the distributed database through the database proxy.

[0035] It should be noted that Figure 1 This is only an illustrative description of the application scenarios of the database transaction processing method provided in this specification, and does not constitute a limitation on the application scenarios of the data anomaly detection method provided in this specification. In more possible implementations, the database transaction processing method provided in this specification can also realize cross-partition distributed transaction processing for other distributed systems. In addition, the database transaction processing method provided in this specification can also realize cross-partition distributed transaction processing for non-distributed (such as centralized) systems, and this specification does not limit this.

[0036] Optionally, the database transaction processing method provided in this specification may be executed by a computing device, and the computing device may be a server, such as one server, multiple servers, a server cluster, a cloud computing platform, etc., but is not limited thereto.

[0037] After introducing the application scenarios of the database transaction processing method provided in this specification, the implementation method of the database transaction processing method provided in this specification is introduced below.

[0038] join Figure 2 , Figure 2 is a flowchart of a method for processing a database transaction provided by an exemplary embodiment. Figure 2 As shown, the method includes:

[0039] Step 201: Divide the pending transaction into multiple sub-transactions according to the data records to be operated by the pending transaction, and different sub-transactions are used to operate different data records.

[0040] In some embodiments, the pending transaction is a distributed transaction executed across multiple partitions, but is not limited thereto.

[0041] It should be noted that in the construction of distributed transactions, any database operation covering multiple records in different partitions can be regarded as part of a distributed transaction. Therefore, the pending transaction can be further subdivided into several sub-transactions, each of which can focus on the reading and writing activities of a single record and be executed on the partition where the record is located.

[0042] Optionally, different subtransactions are used to operate on different data records. However, the partitions to which the data records to be operated by different subtransactions belong may be the same or different, and this specification does not limit this.

[0043] It should be noted that, for a pending transaction, the multiple sub-transactions obtained by dividing it can be executed in a serialized manner step by step. The processing order of these multiple sub-transactions can be determined according to the association relationship (such as call relationship) between data records, but is not limited to this.

[0044] Step 202: Record corresponding update operations in the partitions corresponding to each subtransaction. For any subtransaction, the partition corresponding to the subtransaction is the partition to which the data record to be operated by the subtransaction belongs.

[0045] It should be noted that, for any sub-transaction, the partition to which the data record to be operated by the sub-transaction belongs can be used as the partition to be operated by the sub-transaction (or the partition corresponding to the sub-transaction).

[0046] In some embodiments, corresponding log data may be generated in the partition corresponding to each sub-transaction according to the corresponding sub-transaction, so as to record the update operation of the corresponding sub-transaction in the partition corresponding to each sub-transaction.

[0047] Step 203: When the update operations of all subtransactions are successfully recorded in the corresponding partitions, the recorded update operations are submitted to the database.

[0048] In some embodiments, when all sub-transactions obtained by dividing the pending transaction have been successfully recorded in the corresponding partitions, the recorded update operations can be submitted to the database according to the log data of each partition to achieve the purpose of persisting the update operations in the database.

[0049] The above embodiment divides the pending transaction into multiple sub-transactions according to the data records to be operated by the pending transaction, so that in the partition to which the data records to be operated by each sub-transaction belong, the corresponding update operations are recorded according to the corresponding sub-transaction records to complete the preparation work for transaction submission, and then when the update operations of all sub-transactions are successfully recorded in the corresponding partition, the recorded update operations are submitted to the database, so as to ensure that the distributed transaction can be reliably and sequentially executed between multiple partitions by utilizing the two-phase commit method, thereby enhancing the efficiency and speed of the database in processing cross-partition distributed transactions.

[0050] After introducing the basic implementation process of this specification, various optional implementations of the database transaction processing method provided in this specification are introduced below.

[0051] In some embodiments, for step 201, when dividing the pending transaction into multiple sub-transactions according to the data records to be operated by the pending transaction, it can be implemented by the following steps:

[0052] Step 2011: In response to receiving a database operation request, generate a pending transaction based on the database operation request.

[0053] In one possible implementation, a database operation request can be triggered by database application software, and a computing device equipped with a database management system can receive the database operation request from the database application software, thereby parsing the received database operation request to obtain a series of operations to be executed corresponding to the database operation request, and then encapsulating the series of operations to be executed to obtain transactions to be processed.

[0054] Step 2022: Based on the data records to be operated by the pending transaction, divide some transactions with the same data records to be operated in the pending transaction into a sub-transaction to obtain multiple sub-transactions.

[0055] It should be noted that each pending operation in the pending transaction can be used to operate on a data record, and the data records to be operated on by different pending operations can be the same or different.

[0056] In one possible implementation, based on the execution order of each to-be-executed operation in the to-be-executed transaction and the data records to be operated by each to-be-executed operation, the to-be-executed operations with adjacent execution orders and the same data records to be operated can be divided into one sub-transaction, so as to divide the to-be-executed transaction into multiple sub-transactions.

[0057] For example, if a pending transaction simultaneously involves data read and write operations on records X, Y, and Z located in three different partitions (such as partitions P1, P2, and P3), the pending transaction can be divided into three related sub-transactions.

[0058] After the generation of multiple sub-transactions is implemented through the above embodiment, step 202 can be performed to record corresponding update operations in the partition corresponding to each sub-transaction according to the corresponding sub-transaction.

[0059] In some embodiments, for step 202, when recording corresponding update operations in the partition corresponding to each subtransaction respectively, the corresponding update operations can be recorded in the partition corresponding to each subtransaction in turn according to the processing order of multiple subtransactions.

[0060] In some embodiments, when the corresponding update operation is recorded in the partition corresponding to each sub-transaction in accordance with the processing order of multiple sub-transactions, it can be implemented by the following steps:

[0061] Step 2021: For any sub-transaction, the partition corresponding to the sub-transaction records the corresponding update operation according to the sub-transaction.

[0062] In a possible implementation, for any subtransaction, log data matching the to-be-executed operations included in the subtransaction may be generated in the partition corresponding to the subtransaction, so as to record the update operation corresponding to the subtransaction in the partition corresponding to the subtransaction.

[0063] In a possible implementation, for any subtransaction, if the update operation of the subtransaction is successfully recorded in the partition corresponding to the subtransaction, a row lock may be added to the row where the update operation of the subtransaction is located.

[0064] By adopting a row lock strategy, it is ensured that the data record of this operation will not be operated by other transactions, so as to maintain the data consistency of each data record during the transaction processing.

[0065] Step 2022: When the update operation of the subtransaction is successfully recorded in the partition corresponding to the subtransaction, a transaction request message is sent to the partition corresponding to the target subtransaction. The target subtransaction is a subtransaction that is processed after the subtransaction in the order of processing. The transaction request message is used to start the processing of the subtransaction in the partition corresponding to the target subtransaction.

[0066] In one possible implementation, when the update operation of the subtransaction is successfully recorded in the partition corresponding to the subtransaction, the partition corresponding to the subtransaction may send a transaction request message to the partition corresponding to the target subtransaction that is processed after the subtransaction, so as to start processing the target subtransaction in the partition corresponding to the target subtransaction.

[0067] Taking a pending transaction that simultaneously involves data read and write operations on records X, Y, and Z located in partitions P1, P2, and P3 as an example, the update operation on data record X can be recorded in partition P1 first, and then partition P1 sends a transaction request message to partition P2 to record the update operation on data record Y in partition P2. Finally, partition P2 sends a transaction request message to partition P3 to record the update operation on data record Z in partition P3. At this point, the preparation stage of cross-partition database transaction processing can be completed.

[0068] It should be noted that after recording the update operation on the corresponding data records in partitions P1, partition P2, and partition P3, row locks can also be added to the operated data records (i.e., data record X, data record Y, data record Z) to lock the rows where data records X, data record Y, and data record Z are located.

[0069] In some embodiments, when the update operation of the subtransaction that is last in the processing order is successfully recorded in the corresponding partition, a transaction response message can be sent to the partition corresponding to each subtransaction in turn in the reverse order of the processing order of multiple subtransactions. When the partition corresponding to the subtransaction that is first in the processing order receives the transaction response message, it can be determined whether the update operations of all subtransactions have been successfully recorded in the corresponding partitions.

[0070] It should be noted that, for any sub-transaction, the transaction response message is used to indicate whether the update operation of the sub-transaction that is processed after the sub-transaction has been successfully recorded in the corresponding partition, so that the partition corresponding to the sub-transaction that is processed first in the order can determine whether the update operations of all sub-transactions have been successfully recorded in the corresponding partition based on the received transaction response message.

[0071] For example, the transaction response message may include the transaction result and the generated log information, wherein the transaction result can be used to indicate whether the update operation of the subtransaction that is processed after the subtransaction is successfully recorded in the corresponding partition.

[0072] After determining whether the update operations of all subtransactions have been successfully recorded in the corresponding partitions, if the update operations of all subtransactions have been successfully recorded in the corresponding partitions, the recorded update operations can be submitted to the database through step 203 when the update operations of all subtransactions have been successfully recorded in the corresponding partitions.

[0073] In some embodiments, for step 203, when the update operations of all sub-transactions are successfully recorded in the corresponding partitions, submitting the recorded update operations to the database can be implemented in the following manner:

[0074] When the update operations of all subtransactions are successfully recorded in the corresponding partitions, a commit message is sent to the partition corresponding to each subtransaction. The commit message is used to indicate that the update operations recorded in the partition are committed to the database, so that the partition that receives the commit message can persist the update operations recorded in the partition in the database.

[0075] In some embodiments, after the recorded update operation is submitted to the database, the transaction status of the pending transaction may be updated to a completed status, so that the processing of other transactions may continue based on the updated transaction status.

[0076] Furthermore, in some embodiments, after the recorded update operation is submitted to the database, the row locks added in each partition where the update operation is recorded may be released to ensure that other transactions can continue to read and write these data records.

[0077] For ease of understanding, the following is an example to introduce the method for processing database transactions provided in this specification.

[0078] See also Figure 3 , Figure 3 is a flowchart of a method for processing a database transaction provided by an exemplary embodiment. Figure 3 As shown in the figure, taking the data read and write operations of data records X, Y, and Z located in different partitions P1, P2, and P3 as an example, when a distributed transaction is started, cross-partition distributed transaction processing can be implemented through the following steps:

[0079] Step 301 , locate the partition P1 where the data record X is located, record the update operation on the data record X in the partition P1 , and set a row lock on the row where the data record X is located after the update operation record is completed, so as to lock the row where the data record X is located.

[0080] Step 302: Partition P1 acts as a message sender and sends a transaction request message to partition P2 to trigger transaction processing in partition P2.

[0081] Step 303: After receiving the transaction request message from partition P1, partition P2 records the update operation on data record Y in partition P2, and sets a row lock on the row where data record Y is located after the update operation record is completed, so as to lock the row where data record Y is located.

[0082] Step 304: Partition P2, as a message sender, sends a transaction request message to partition P3 to trigger transaction processing in partition P3.

[0083] Step 305: After receiving the transaction request message from partition P2, partition P3 records the update operation on data record Z in partition P3, and sets a row lock on the row where data record Z is located after the update operation record is completed, so as to lock the row where data record Z is located.

[0084] Step 306: After recording the update operation on the data record Z in partition P3, partition P3 returns a transaction response message including the transaction result and the generated log information to partition P2.

[0085] Step 307: Partition P2 receives the transaction response message sent back by partition P3, and sends back its own transaction response message and the transaction response message from partition P3 to partition P1.

[0086] Step 308: Partition P1 receives the transaction response message sent back by partition P2, determines that the transaction preparation is complete according to the transaction response message, and then sends a commit message to partition P2 to commit the changes made in partition P2.

[0087] Step 309: Partition P2 sends a commit message to partition P3, committing the changes made in partition P3.

[0088] At this point, the distributed transaction across multiple partitions has been successfully processed, so that the transaction status of the transaction can be marked as completed, and the row locks added during the transaction processing can be released.

[0089] See also Figure 4 , Figure 4 is a schematic diagram of a processing result of a database transaction provided by an exemplary embodiment. Figure 4 Shown according to Figure 3 The changes in account balance after the transaction execution process shown in Figure 4As shown, the modification record of the balance of account A1 can be realized through step 301, that is, record A1=A1-30=90, and a row lock can be set for the row where account A1 is located; through step 302, partition P1 sends a transaction request message to partition P2; through step 303, the modification record of the balance of account B1 can be realized, that is, record B1=B1+30=180, B1=B1-160=20, and a row lock can be set for the row where account B1 is located; through step 304, partition P2 sends a transaction request message to partition P3 Request message; through step 305, the modification record of the balance of account C1 can be realized, that is, the record C1=C1+160=370, and a row lock can be set for the row where account C1 is located; through step 306, partition P3 sends a transaction response message to partition P2; through step 307, partition P2 sends a transaction response message to partition P1; through step 308, partition P1 sends a commit message to partition P2; through step 309, partition P2 sends a commit message to partition P3 to persist the operation in the database.

[0090] The above embodiment is described by taking the successful completion of the preparation phase as an example. In more possible implementations, if the update operation of any subtransaction is not successfully recorded, the recorded update operation can be undone.

[0091] In some embodiments, when the update operation of any sub-transaction is not successfully recorded, when undoing the recorded update operation, a cancellation message can be sent to the partition corresponding to each sub-transaction if the update operation of the sub-transaction is not successfully recorded in the corresponding partition. The cancellation message is used to instruct to roll back the recorded update operation in the partition, so that each partition that receives the cancellation message can independently perform a rollback operation to undo the recorded transaction operation.

[0092] Through the database transaction processing method provided in this specification, a two-phase commit mechanism and a row lock mechanism can be combined in the cross-partition distributed transaction processing process, so as to ensure that distributed transactions can be reliably and sequentially executed between multiple partitions through the two-phase commit mechanism, and maintain the data consistency of each record in the transaction reading process through the row lock mechanism, thereby enhancing the efficiency and speed of the distributed database in processing cross-partition distributed transactions, and can also effectively reduce the processing delay of distributed transactions.

[0093] Corresponding to the aforementioned method embodiments, this specification also provides corresponding equipment embodiments and device embodiments.

[0094] Figure 5 is a schematic structural diagram of a computing device provided by an exemplary embodiment. Figure 5At the hardware level, the computing device includes a processor 502, an internal bus 504, a network interface 506, a memory 508, and a non-volatile memory 510, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 502 reading the corresponding computer program from the non-volatile memory 510 into the memory 508 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but may also be hardware or logic devices.

[0095] Please refer to Figure 6 , Figure 6 is a schematic block diagram of a database transaction processing device provided by an exemplary embodiment. The database transaction processing device can be applied to Figure 5 The computing device shown is used to implement the technical solution of this specification.

[0096] The database transaction processing device may include:

[0097] A generating module 601 is used to divide the pending transaction into a plurality of sub-transactions according to the data records to be operated by the pending transaction, and different sub-transactions are used to operate on different data records;

[0098] Recording module 602, used for recording corresponding update operations in the partition corresponding to each subtransaction respectively according to the corresponding subtransaction. For any subtransaction, the partition corresponding to the subtransaction is the partition recorded with the data to be operated by the subtransaction;

[0099] The commit module 603 is used to commit the recorded update operations to the database when the update operations of all sub-transactions are successfully recorded in the corresponding partitions.

[0100] In some embodiments, the recording module 602, when used to record corresponding update operations in the partition corresponding to each sub-transaction respectively according to the corresponding sub-transaction, is used to:

[0101] According to the processing order of the multiple sub-transactions, corresponding update operations are recorded in the partition corresponding to each sub-transaction in turn.

[0102] In some embodiments, the recording module 602, when used to record the corresponding update operation in the partition corresponding to each sub-transaction in accordance with the processing order of the multiple sub-transactions, is used to:

[0103] For any sub-transaction, the partition corresponding to the sub-transaction records the corresponding update operation according to the sub-transaction;

[0104] In the case where the update operation of the subtransaction is successfully recorded in the partition corresponding to the subtransaction, a transaction request message is sent to the partition corresponding to the target subtransaction, the target subtransaction being a subtransaction that is processed after the subtransaction, and the transaction request message is used to start processing of the subtransaction in the partition corresponding to the target subtransaction.

[0105] In some embodiments, the database transaction processing device further includes:

[0106] The adding module is used to add a row lock to the row where the update operation of any sub-transaction is located when the update operation of the sub-transaction is successfully recorded in the partition corresponding to the sub-transaction.

[0107] In some embodiments, the database transaction processing device further includes:

[0108] The release module is used to release the row locks added in each partition that records the update operation.

[0109] In some embodiments, the database transaction processing device further includes:

[0110] a sending module, configured to, when an update operation of a subtransaction whose processing order is last is successfully recorded in a corresponding partition, send a transaction response message to a partition corresponding to each subtransaction in sequence in a reverse order to the processing order of the multiple subtransactions, wherein for any subtransaction, the transaction response message is used to indicate whether an update operation of a subtransaction whose processing order is subsequent to the subtransaction is successfully recorded in the corresponding partition;

[0111] The determination module is used to determine whether the update operations of all sub-transactions have been successfully recorded in the corresponding partition when the partition corresponding to the sub-transaction ranked first in the processing order receives the transaction response message.

[0112] In some embodiments, the commit module 603, when committing the recorded update operations to the database when the update operations of all sub-transactions are successfully recorded to the corresponding partitions, is configured to:

[0113] When the update operations of all subtransactions are successfully recorded in the corresponding partitions, a commit message is sent to the partition corresponding to each subtransaction, where the commit message is used to indicate that the update operations recorded in the partition are committed to the database.

[0114] In some embodiments, the database transaction processing device further includes:

[0115] The updating module is used to update the transaction status of the pending transaction to a completed status.

[0116] In some embodiments, the generating module 601, when used to divide the pending transaction into a plurality of sub-transactions according to the data records to be operated by the pending transaction, is used to:

[0117] In response to receiving a database operation request, generating a pending transaction based on the database operation request;

[0118] Based on the data records to be operated by the pending transactions, part of the transactions with the same data records to be operated in the pending transactions are divided into a sub-transaction to obtain the multiple sub-transactions.

[0119] In some embodiments, the database transaction processing device further includes:

[0120] The undo module is used to undo the recorded update operation if the update operation of any sub-transaction is not successfully recorded.

[0121] In some embodiments, the undo module, when used to undo the recorded update operation when the update operation of any sub-transaction is not successfully recorded, is used to:

[0122] In the case where the update operation of a subtransaction is not successfully recorded in the corresponding partition, a cancellation message is sent to the partition corresponding to each subtransaction, where the cancellation message is used to instruct to roll back the update operation recorded in the partition.

[0123] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0124] In a typical configuration, a computer includes one or more processors (Central Processing Unit, CPU), input / output interface, network interface and memory.

[0125] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0126] Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0127] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0128] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0129] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0130] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0131] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.

Claims

1. A method for processing a database transaction, the method comprising: According to the data records to be operated by the pending transaction, the pending transaction is divided into a plurality of sub-transactions, and different sub-transactions are used to operate different data records; In the partition corresponding to each subtransaction, the corresponding update operation is recorded in accordance with the corresponding subtransaction. For any subtransaction, the partition corresponding to the subtransaction is the partition described by the data record to be operated by the subtransaction; When the update operations of all subtransactions are successfully recorded in the corresponding partitions, the recorded update operations are submitted to the database.

2. The method according to claim 1, wherein in each partition corresponding to each subtransaction, recording corresponding update operations according to the corresponding subtransactions comprises: According to the processing order of the multiple sub-transactions, corresponding update operations are recorded in the partition corresponding to each sub-transaction in turn.

3. The method according to claim 2, wherein the updating operation corresponding to each sub-transaction record in the partition corresponding to each sub-transaction in accordance with the processing order of the multiple sub-transactions comprises: For any sub-transaction, the partition corresponding to the sub-transaction records the corresponding update operation according to the sub-transaction; In the case where the update operation of the subtransaction is successfully recorded in the partition corresponding to the subtransaction, a transaction request message is sent to the partition corresponding to the target subtransaction, the target subtransaction being a subtransaction that is processed after the subtransaction, and the transaction request message is used to start processing of the subtransaction in the partition corresponding to the target subtransaction.

4. The method according to claim 1, after recording the corresponding update operation in the partition corresponding to each sub-transaction respectively according to the corresponding sub-transaction, the method further comprises: For any subtransaction, when the update operation of the subtransaction is successfully recorded in the partition corresponding to the subtransaction, a row lock is added to the row where the update operation of the subtransaction is located.

5. According to the method of claim 4, when the update operations of all subtransactions are successfully recorded in the corresponding partitions, after the recorded update operations are submitted to the database, the method further comprises: Release the row locks added in each partition where the update operation was recorded.

6. The method according to claim 1, wherein when the update operations of all subtransactions are successfully recorded in the corresponding partitions, before submitting the recorded update operations to the database, the method further comprises: In the case where the update operation of the subtransaction whose processing order is the last is successfully recorded in the corresponding partition, a transaction response message is sent to the partition corresponding to each subtransaction in sequence in the reverse order of the processing order of the multiple subtransactions. For any subtransaction, the transaction response message is used to indicate whether the update operation of the subtransaction whose processing order is after the subtransaction is successfully recorded in the corresponding partition; When the partition corresponding to the subtransaction ranked first in the processing order receives the transaction response message, it is determined whether the update operations of all subtransactions have been successfully recorded in the corresponding partition.

7. The method according to claim 1, wherein when the update operations of all subtransactions are successfully recorded in the corresponding partitions, submitting the recorded update operations to the database comprises: When the update operations of all subtransactions are successfully recorded in the corresponding partitions, a commit message is sent to the partition corresponding to each subtransaction, where the commit message is used to indicate that the update operations recorded in the partition are committed to the database.

8. The method according to claim 1, wherein when the update operations of all subtransactions are successfully recorded in the corresponding partitions, after the recorded update operations are submitted to the database, the method further comprises: The transaction status of the pending transaction is updated to a completed status.

9. The method according to claim 1, wherein the step of dividing the pending transaction into a plurality of sub-transactions according to the data records to be operated by the pending transaction comprises: In response to receiving a database operation request, generating a pending transaction based on the database operation request; Based on the data records to be operated by the pending transactions, part of the transactions with the same data records to be operated in the pending transactions are divided into a sub-transaction to obtain the multiple sub-transactions.

10. The method according to claim 1, after recording corresponding update operations in the partitions to be operated by each sub-transaction respectively according to the corresponding sub-transaction, the method further comprises: If the update operation of any subtransaction is not successfully recorded, the recorded update operation is undone.

11. The method according to claim 10, wherein when an update operation of any sub-transaction is not successfully recorded, undoing the recorded update operation comprises: In the case where the update operation of a subtransaction is not successfully recorded in the corresponding partition, a cancellation message is sent to the partition corresponding to each subtransaction, where the cancellation message is used to instruct to roll back the update operation recorded in the partition.

12. A database transaction processing device, the device comprising: A generating module, used to divide the pending transaction into a plurality of sub-transactions according to the data records to be operated by the pending transaction, and different sub-transactions are used to operate different data records; A recording module, used for recording corresponding update operations in the partition corresponding to each subtransaction respectively according to the corresponding subtransaction. For any subtransaction, the partition corresponding to the subtransaction is the partition recorded with the data to be operated by the subtransaction; The commit module is used to commit the recorded update operations to the database when all the update operations of the subtransactions are successfully recorded in the corresponding partitions.

13. The apparatus according to claim 12, wherein the recording module, when used to record corresponding update operations in the partition corresponding to each subtransaction respectively according to the corresponding subtransaction, is used to: According to the processing order of the multiple sub-transactions, corresponding update operations are recorded in the partition corresponding to each sub-transaction in turn.

14. The apparatus according to claim 12, further comprising: The adding module is used to add a row lock to the row where the update operation of any sub-transaction is located when the update operation of the sub-transaction is successfully recorded in the partition corresponding to the sub-transaction.

15. The apparatus according to claim 12, further comprising: a sending module, configured to, when an update operation of a subtransaction whose processing order is last is successfully recorded in a corresponding partition, send a transaction response message to a partition corresponding to each subtransaction in sequence in a reverse order to the processing order of the multiple subtransactions, wherein for any subtransaction, the transaction response message is used to indicate whether an update operation of a subtransaction whose processing order is subsequent to the subtransaction is successfully recorded in the corresponding partition; The determination module is used to determine whether the update operations of all sub-transactions have been successfully recorded in the corresponding partition when the partition corresponding to the sub-transaction ranked first in the processing order receives the transaction response message.

16. The apparatus according to claim 12, wherein the submitting module, when submitting the recorded update operations to the database when the update operations of all sub-transactions are successfully recorded to the corresponding partitions, is configured to: When the update operations of all subtransactions are successfully recorded in the corresponding partitions, a commit message is sent to the partition corresponding to each subtransaction, where the commit message is used to indicate that the update operations recorded in the partition are committed to the database.

17. The apparatus according to claim 12, further comprising: The undo module is used to undo the recorded update operation if the update operation of any sub-transaction is not successfully recorded.

18. A computing device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 11 by running the executable instructions.

19. A computer-readable storage medium having computer instructions stored thereon, wherein the instructions are executed by a processor to implement the method according to any one of claims 1 to 11.

Citation Information

Cited By

  • Big data processing method and system based on distributed micro-service architecture

    CN119621847A