Database transaction processing method, apparatus, device, and storage medium

By introducing reserved locks and logging mechanisms into database transaction processing, the problems of poor concurrency and high overhead caused by implicit locks under the RC isolation level are solved, thereby improving the concurrency of transaction processing.

CN116860768BActive Publication Date: 2025-11-28SHENZHEN KINGDOM TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310777414.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2025-11-28
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

In existing technologies, the multi-version concurrency control mechanism at the RC isolation level requires mutual exclusion when searching for and adding/deleting nodes in historical snapshots, which involves implicit locks, resulting in poor concurrency and high overhead.

Method used

The database transaction process manages the objects to be processed by using reserved locks, allocates update resources by logging operations, and uses redo logs and rollback logs for updates.

Benefits of technology

By introducing more locking modes, the time that concurrent transactions hold locks is shortened, thereby improving the concurrency of transaction processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116860768B_ABST
    Figure CN116860768B_ABST
Patent Text Reader

Abstract

The application relates to the field of databases and discloses a database transaction method, device, equipment and storage medium. The method processes a to-be-processed object according to a data processing instruction in a database transaction, retains a lock for the to-be-processed object, the retained lock is used for representing that the database transaction will modify the to-be-processed object, records an operation of processing the to-be-processed object, saves the generated record through a log, allocates a resource for updating the to-be-processed object, and updates the database according to the log. Since the application manages the modification of the to-be-processed object through the retained lock and updates the database through the record in the log, the problem that the RC isolation level in the prior art usually adopts a multi-version concurrent control mechanism, the method needs mutual exclusion in the program and exists implicit locks, and the concurrent transactions cannot be concurrent is solved, more lock modes are introduced, the time for which a lock is held by a concurrent transaction is shortened, and the concurrency of transaction processing is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database, and particularly relates to a database transaction processing method, device and equipment and storage medium. BACKGROUND

[0002] Transaction processing is the core function of a database. In order to improve the concurrent processing performance of the database, the SQL standard specifies four transaction isolation levels: Read Uncommitted, Read Committed, Repeatable Read and Serializable. Among them, the most commonly used isolation level is Read Committed (RC), and the default isolation levels of commercial databases such as SQL Server, Oracle and open source databases such as PostgreSQL are RC.

[0003] In the prior art, the RC isolation level is usually implemented by using a multi-version concurrency control (MVCC) mechanism. The multi-version concurrency control makes the read and write of the same data not need to be explicitly locked by keeping a historical version snapshot, but has many limitations. For example, the search and addition and deletion of nodes in the historical snapshot (generally a version chain table formed by transaction UndoLog) need mutual exclusion in the program, and there is an implicit lock, which cannot be concurrent; each update and deletion needs to write the data before the update to UndoLog, which has a large overhead.

[0004] The above content is only used to assist in understanding the technical solutions of the present application, and does not represent the acknowledgement of the above content as prior art. SUMMARY

[0005] The main purpose of the present application is to provide a database transaction processing method, device, equipment and storage medium, which aims to solve the technical problem that the RC isolation level in the prior art usually uses a multi-version concurrency control mechanism, but the method needs mutual exclusion in the program for searching and adding and deleting nodes in the historical snapshot, and there is an implicit lock, which cannot be concurrent; and each update and deletion needs to write the data before the update to UndoLog, which has a large overhead.

[0006] To achieve the above purpose, the present application provides a database transaction processing method, which comprises the following steps:

[0007] According to the data processing instruction in the database transaction, the processing object is processed, and a reserved lock is set for the processing object, wherein the reserved lock is used to indicate that the database transaction will modify the processing object;

[0008] record the operation of processing the to-be-processed object, and save the generated record through a log;

[0009] allocate resources for updating the to-be-processed object, and update the database according to the log.

[0010] Optionally, the step of processing the to-be-processed object according to the data processing instruction in the database transaction and reserving a lock for the to-be-processed object comprises:

[0011] processing the identifier of the to-be-processed object according to the data processing instruction in the database transaction, and adding a reserved lock to the slot corresponding to the to-be-processed object index;

[0012] determining the identifier of the to-be-processed object data based on the slot corresponding to the to-be-processed object index, and adding a reserved lock to the identifier of the to-be-processed object data.

[0013] Optionally, the data processing instruction comprises a data insertion instruction, a data deletion instruction and a data update instruction; and the step of processing the identifier of the to-be-processed object according to the data processing instruction in the database transaction comprises:

[0014] allocating a row identifier space of the to-be-processed object according to the data insertion instruction in the database transaction;

[0015] or, adding a deletion state to the identifier of the to-be-processed object according to the data deletion instruction in the database transaction.

[0016] Optionally, the step of recording the operation of processing the to-be-processed object and saving the generated record through a log comprises:

[0017] recording the operation of processing the to-be-processed object, the slot corresponding to the to-be-processed object index and the identifier of the to-be-processed object data, and writing the record into a redo log;

[0018] obtaining the locked data in the to-be-processed object, and writing the locked data into a rollback log.

[0019] Optionally, the step of allocating resources for updating the to-be-processed object, and updating the database according to the log comprises:

[0020] allocating resources required for updating the to-be-processed object index;

[0021] obtaining the identifier of the to-be-processed object data in the redo log, and performing an exclusive lock operation on each of the identifiers of the to-be-processed object data;

[0022] According to the operation record in the redo log, the database is updated, and when each to-be-processed object update is completed, the exclusive lock corresponding to the to-be-processed object is released.

[0023] Optionally, after the step of allocating resources required for updating the to-be-processed object index, the method further comprises:

[0024] If the resource allocation fails, the lock is released based on the data saved in the rollback log, so as to perform a rollback operation of the database transaction.

[0025] Optionally, after the step of obtaining the identifier of the to-be-processed object data in the redo log and performing the exclusive lock operation on each identifier of the to-be-processed object data, the method further comprises:

[0026] If the exclusive lock operation on each identifier of the to-be-processed object data is unsuccessful, the lock is released based on the data saved in the rollback log, so as to perform a rollback operation of the database transaction.

[0027] In addition, to achieve the above object, the application further provides a database transaction processing device, which comprises:

[0028] An object processing module is configured to process a to-be-processed object according to a data processing instruction in a database transaction, and set a reserved lock on the to-be-processed object, wherein the reserved lock is used to indicate that the database transaction will modify the to-be-processed object;

[0029] A log generation module is configured to record an operation of processing the to-be-processed object, and save the generated record through a log;

[0030] A data update module is configured to allocate resources for updating the to-be-processed object, update the database according to the log, and release the exclusive lock when the update is completed.

[0031] In addition, to achieve the above object, the application further provides a database transaction device, which comprises a memory, a processor, and a database transaction processing program stored in the memory and executable on the processor, wherein the database transaction processing program is configured to implement the steps of the above-mentioned database transaction processing method.

[0032] In addition, to achieve the above object, the application further provides a storage medium, wherein the storage medium stores a database transaction processing program, and when the database transaction processing program is executed by a processor, the steps of the above-mentioned database transaction processing method are implemented.

[0033] The application processes the to-be-processed object according to the data processing instruction in the database transaction, and reserves a lock for the to-be-processed object, the reserved lock is used to represent that the database transaction will modify the to-be-processed object; records the operation of processing the to-be-processed object, and saves the generated record through a log; allocates resources for updating the to-be-processed object, and updates the database according to the log. Since the application manages the modification of the to-be-processed object through the reserved lock, and updates the database through the record in the log, the problem that the RC isolation level in the prior art usually adopts a multi-version concurrency control mechanism, but the method needs mutual exclusion in the program and exists implicit lock, and cannot be concurrent is solved, and meanwhile, more lock modes are introduced, the time of holding the lock by the concurrent transaction is shortened, and the concurrency of transaction processing is improved. BRIEF DESCRIPTION OF DRAWINGS

[0034] Figure 1 is a structural schematic diagram of a database transaction processing device of a hardware running environment related to the embodiment scheme of the application.

[0035] Figure 2 is a flowchart of a first embodiment of a database transaction processing method of the application.

[0036] Figure 3 is a flowchart of a second embodiment of a database transaction processing method of the application.

[0037] Figure 4 is a flowchart of an application scenario of a database transaction processing method of the application.

[0038] Figure 5 is a structural block diagram of a first embodiment of a database transaction processing device of the application.

[0039] The implementation, functional features and advantages of the application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0040] It should be understood that the specific embodiments described herein are only used to explain the application, and are not used to limit the application.

[0041] Reference Figure 1 , Figure 1 is a structural schematic diagram of a database transaction processing device of a hardware running environment related to the embodiment scheme of the application.

[0042] As Figure 1As shown in the figure, the database transaction processing device can include a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection communication between the components. The user interface 1003 can include a display, an input unit such as a keyboard, and can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a wireless fidelity (Wi-Fi) interface). The memory 1005 can be a high-speed random access memory (RAM), and can also be a stable non-volatile memory (NVM), such as a disk memory. The memory 1005 can also be a storage device independent of the aforementioned processor 1001.

[0043] Those skilled in the art can understand that Figure 1 The structure shown in the figure does not constitute a limitation on the database transaction processing device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.

[0044] As Figure 1 As shown in the figure, the memory 1005 as a storage medium can include an operating system, a network communication module, a user interface module, and a database transaction processing program.

[0045] In Figure 1 In the database transaction processing device shown in the figure, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 in the database transaction processing device of the present application can be arranged in the database transaction processing device, and the database transaction processing device calls the database transaction processing program stored in the memory 1005 through the processor 1001, and executes the database transaction processing method provided by the embodiments of the present application.

[0046] The embodiment of the present application provides a database transaction processing method, which refers to Figure 2 , Figure 2 The flowchart of the first embodiment of the database transaction processing method of the present application.

[0047] In this embodiment, the database transaction processing method includes the following steps:

[0048] According to the data processing instruction in the database transaction, the to-be-processed object is processed, and a reserved lock is placed on the to-be-processed object, and the reserved lock is used to represent that the database transaction will modify the to-be-processed object.

[0049] It should be noted that the execution subject of the method of the embodiment can be a terminal device with data processing and program running functions, such as a personal computer, a server, etc., or an electronic device with the same or similar functions, such as the above-mentioned database transaction processing device. The following will take the database transaction processing device (hereinafter referred to as processing device) as an example to describe the embodiment and each of the following embodiments.

[0050] It can be understood that the above-mentioned database transaction refers to regarding a group of database operations (or database statements) as an indivisible unit, which is either all executed successfully or all rolled back, so as to ensure the consistency and integrity of the database. In the database, the transaction is managed through the following steps:

[0051] A1: Begin transaction (BEGIN): identify the beginning of the transaction, start recording the operations in the transaction;

[0052] A2: Perform operations: execute a series of database operation statements, such as insertion, update, deletion, query, etc.;

[0053] A3: Commit transaction (COMMIT): permanently save all operations in the transaction to the database;

[0054] A4: Rollback transaction (ROLLBACK): cancel all operations in the transaction, and restore the database to the state before the transaction starts.

[0055] The use of transactions can ensure the consistency and integrity of database operations, especially when multiple users access the database concurrently, which can avoid data conflicts and data inconsistency problems.

[0056] It should be understood that the above-mentioned data processing instruction is a database operation statement, such as a data insertion instruction, a data update instruction, a data deletion instruction, etc.

[0057] It should be noted that the to-be-processed object is an object stored in the database, which can be data, a table, a row, a column, a view, an index, a trigger, etc. The above-mentioned data can be the values of each field in the actually stored row and column objects in the database.

[0058] It should be understood that the lock is a mechanism for managing concurrent access, used to control access rights to database resources. By using the lock, it can be ensured that multiple transactions do not produce data inconsistency or conflict problems when concurrently executed. In the present embodiment, the lock can include a shared (Share, S) lock, a pending (Pending, P) lock, a reserved (Reserved, R) lock, and an exclusive (Exclusive, X) lock.

[0059] It should be explained that the shared lock means that the to-be-processed object can be obtained by multiple transactions at the same time, used for concurrent reading of the database, and the shared lock is released immediately after reading; the pending lock is used when a transaction acquires an exclusive lock for modification, if the exclusive lock is not acquired, the lock of the object can be set as a pending lock, so that subsequent other transactions cannot perform concurrent reading on the object, thereby preventing write lock death, and the transaction can add an exclusive lock to the object.

[0060] It should be noted that the object of the lock can be a row, a slot in a Hash index, a table, a node in a T-tree or B-tree index, a Page object, etc., which is not limited in the present embodiment.

[0061] In particular, in the in-memory database, the storage space of the above-mentioned lock can be continuously matched with the actual data storage space, for example, a row, a block of space (i.e., a lock area) is allocated at the head of the row, used for saving and processing the lock.

[0062] In the present embodiment and each of the following embodiments, the above-mentioned to-be-processed object can be identified by an id, referred to as an oid, which can include a lock area space, and the objects in the above-mentioned database can include to-be-processed object data, to-be-processed object indexes, to-be-processed object index corresponding slots, etc. The specific object can be directly accessed by the oid, and the locking state on the object is obtained. Generally, the oid is a 64-bit non-conforming integer.

[0063] It should be explained that after a resource in the database is added with a reserved lock, the transaction will modify the object in the subsequent. That is, the reserved lock is used to represent that the database transaction will modify the to-be-processed object. When the database transaction adds a reserved lock to the to-be-processed object, other transactions can only add a shared lock to read it, and cannot add other locks. However, the transaction can add a pending lock or an exclusive lock to the to-be-processed object.

[0064] Specifically, in order to more accurately process the to-be-processed object, the step of processing the to-be-processed object according to the data processing instruction in the database transaction and setting a reserved lock on the to-be-processed object, comprises:

[0065] The identifier of the to-be-processed object is processed according to the data processing instruction in the database transaction, and a reserved lock is added to the slot corresponding to the index of the to-be-processed object.

[0066] It should be explained that the index is a data structure in the database, which can be used to improve the speed and efficiency of data retrieval. The index is usually composed of one or more key values and corresponding slots. The index slot is used to point to the actual storage location of the data in the database, that is, the index identifier.

[0067] It can be understood that the reserved lock is added to the slot corresponding to the index of the to-be-processed object, that is, the slot corresponding to the index of the to-be-processed object is processed subsequently.

[0068] Specifically, the step of processing the identifier of the to-be-processed object according to the data processing instruction in the database transaction comprises:

[0069] According to the data insertion instruction in the database transaction, the row identifier space of the to-be-processed object is allocated;

[0070] Or, according to the data deletion instruction in the database transaction, the deletion state is added to the identifier of the to-be-processed object.

[0071] It should be noted that when the data processing instruction is a data insertion instruction, the processing device can allocate a processing space for the row data of the to-be-processed object; when the data processing instruction is a data deletion instruction, the identifier of the to-be-processed object can be changed to a deletion state, and the reserved lock operation can be performed subsequently.

[0072] It should be explained that when the data processing instruction is a data update instruction, the subsequent reserved lock operation is directly executed.

[0073] The identifier of the to-be-processed object data is determined based on the slot corresponding to the index of the to-be-processed object, and a reserved lock is added to the identifier of the to-be-processed object data.

[0074] It should be noted that the identifier of the to-be-processed object data is the data corresponding to the to-be-processed object.

[0075] In a specific implementation, the processing device processes the to-be-processed object according to the data processing instruction in the database transaction, and adds a reserved lock to the to-be-processed object.

[0076] The operation of processing the to-be-processed object is recorded, and the generated record is saved through a log.

[0077] It can be understood that the operation in the database transaction can be recorded when the database transaction starts, and the operation of processing the object in the database can be recorded when the data processing instruction in the database transaction is executed, and the generated record can be saved through a log.

[0078] It should be noted that in the embodiment, the data processing instruction in the database transaction does not actually update the to-be-processed object data and the to-be-processed object index, but records the operation through a log record operation, and locks the object to be processed. In the transaction submission stage, the to-be-processed object data and the to-be-processed object index can be updated according to the operation record in the log and the lock.

[0079] Specifically, the step of recording the operation of processing the to-be-processed object and saving the generated record through a log includes:

[0080] The operation of processing the to-be-processed object, the to-be-processed object index corresponding slot, and the identifier of the to-be-processed object data are recorded, and the record is written into a redo log.

[0081] It should be noted that the above-mentioned redo log (Redo Log) is a mechanism used in a database system to ensure data persistence and transaction consistency. It records all modification operations occurring in the database system, so as to restore and replay data when the system crashes or fails to recover. In the embodiment, the redo log stores the operation type (such as delete, insert, update, query, etc.) of the data processing instruction in the database transaction, the identifier of the to-be-processed object data, the updated data, and the data required by the data processing instruction, such as the slot corresponding to the to-be-processed object.

[0082] The locked data in the to-be-processed object is obtained, and the locked data is written into an undo log.

[0083] It should be noted that the above-mentioned undo log (Undo Log) is a mechanism used in a database to implement transaction rollback operation and data consistency. It records modification operations and reverse operations on the database, and is used to undo the modifications made by the committed transaction or rollback the uncommitted transaction. In the embodiment, the undo log only saves the locked object. When the to-be-processed object corresponding slot or the to-be-processed object data is locked, the locked oid can be recorded in the undo log.

[0084] When the database needs to undo the modifications made by the committed transaction or rollback the uncommitted transaction, it only needs to release the lock according to the saved oid in the UndoLog, so as to realize the rollback operation of the database transaction.

[0085] In actual application, the present application UndoLog does not need to save the actual data in update and delete, but only needs to save the locked object oid, thereby reducing UndoLog data copying, saving memory, shortening transaction processing delay, introducing more lock states, shortening the lock holding time of each operation in the transaction, and improving the transaction processing concurrency.

[0086] In a specific implementation, the processing device records the operation of processing the processing object, and saves the generated record through the log.

[0087] Step S300: allocating resources for updating the processing object, and updating the database according to the log.

[0088] It should be noted that this step corresponds to the commit transaction step of the database transaction. When the data processing instruction in the database transaction is processed, the resources required for updating the processing object can be allocated, and the database can be updated according to the record in the log.

[0089] In a specific implementation, the processing device allocates resources for updating the processing object, and updates the database according to the log.

[0090] In this embodiment, the processing object is processed according to the data processing instruction in the database transaction, and a reserved lock is set for the processing object, which is used to indicate that the database transaction will modify the processing object; the operation of processing the processing object is recorded, and the generated record is saved through the log; resources for updating the processing object are allocated, and the database is updated according to the log. Since the modification of the processing object is managed through the reserved lock, and the database is updated through the record in the log, the problem that the RC isolation level in the prior art generally adopts a multi-version concurrency control mechanism, but this method needs mutual exclusion in the program and exists implicit lock, and cannot be concurrent is solved, and by introducing more lock modes, the time for which a lock is held by a concurrent transaction is shortened, and the concurrency of transaction processing is improved.

[0091] Further, when the data processing instruction is executed, a data query instruction can also be executed.

[0092] Specifically, when the data query is performed using the index, that is, when the reserved lock exists on the index slot of the query object, the processing device can find the query object according to the data query instruction in the database transaction, and add a shared lock to the index slot of the query object, so as to find the identifier of the query object, and release the S lock on the index slot of the query object and add an S lock to the data of the query object, so as to realize reading of the data of the query object, and release the S lock on the data of the query object when the reading is completed.

[0093] When there is no lock on the index slot of the query object, a shared lock can be added to the index slot of the query object, so as to find the data of the query object, release the S lock on the index slot of the query object, and add an S lock to the data of the query object, so as to realize copying of the data of the query object, and release the S lock on the data of the query object when the reading is completed.

[0094] Based on the first embodiment of the database transaction processing method, a second embodiment of the database transaction processing method is provided.

[0095] As shown in Figure 3 , Figure 3 is a flowchart of the second embodiment of the database transaction processing method.

[0096] Referring to Figure 3 , in order to update the to-be-processed object, the processing device allocates resources for updating the to-be-processed object, and updates the database according to the log to acquire an update lock, including:

[0097] Step S310: allocating resources required for updating the index of the to-be-processed object.

[0098] It should be noted that when the data processing instruction and the data query instruction in the database transaction are executed, the processing device can allocate all the resources to be updated (in the in-memory database, the storage space allocated to the object).

[0099] It should be explained that when the resource allocation fails, the processing device can perform a rollback operation. Specifically, when the resource allocation fails, the processing device releases the lock based on the lock object oid saved in the rollback log to perform the rollback operation of the database transaction.

[0100] In a specific implementation, the processing device allocates resources required for updating the index of the to-be-processed object.

[0101] Step S320: obtaining the identifier of the to-be-processed object data in the redo log, and performing an exclusive lock operation on each identifier of the to-be-processed object data.

[0102] It should be noted that before processing the identifier of the to-be-processed object data, an exclusive lock (including a possible pending lock) needs to be obtained to ensure exclusive access to the to-be-processed object data. After obtaining the exclusive lock, other transactions cannot simultaneously read or write the data.

[0103] It should be explained that when the exclusive lock fails, the processing device can lock the to-be-processed object as a pending lock to prevent subsequent transactions from concurrently reading the object, thereby preventing write lock.

[0104] Further, when the exclusive lock fails, the processing device can perform a rollback operation, and the steps of the rollback operation are as described above, and this embodiment will not be described in detail.

[0105] Step S330: updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to the to-be-processed object when each to-be-processed object is updated.

[0106] It should be noted that database update operations can be performed once the exclusive lock is set. Specifically, the processing device can perform data update, data insertion, and data deletion operations according to the order in the redo log. The data update may include updating the data of the object to be processed and updating the index of the object to be processed; the data insertion may include updating the index of the object to be processed; and the data deletion may include deleting the data of the object to be processed and deleting the index of the object to be processed.

[0107] It should be explained that the successful execution of steps S310 and S320 can guarantee the successful execution of each step in step S330. Therefore, the X lock can be released immediately after any pending object is updated, maximizing concurrency.

[0108] This embodiment allocates the resources required to update the index of the objects to be processed; obtains the identifiers of the data to be processed in the redo log, and performs an exclusive lock operation on the identifiers of each data to be processed; updates the database according to the operation records in the redo log, and releases the exclusive lock corresponding to each object to be processed when the update is completed. Because database transaction processing is performed using reserved locks, exclusive locks, and redo logs, it reduces UndoLog data copying, saves memory, shortens transaction processing latency, introduces more lock states, shortens the time each operation holds locks within a transaction, and improves transaction processing concurrency.

[0109] like Figure 4 As shown, Figure 4 This is a schematic diagram of an application scenario of the database transaction processing method of the present invention.

[0110] Reference Figure 4 When a transaction begins, the processing device can read the data processing instructions in the transaction, set R locks (reserved locks) on the data and objects that may be updated, and write redo logs and rollback logs according to the operations performed. The data processing instructions include data deletion instructions, data update instructions, and data insertion instructions.

[0111] Furthermore, the processing device can read the data query instruction in the transaction to obtain the data identifier, and set the data identifier to a shared lock. The shared lock can be released when the copy is completed. If an index is used, the index identifier (i.e., the slot corresponding to the index mentioned above) is assigned to a shared lock. After obtaining the data identifier, the shared lock on the index identifier is released, and then the data identifier is set to a shared lock. The shared lock can be released when the copy is completed.

[0112] Furthermore, upon transaction commit, the processing device allocates the resources needed to update the index. If the update fails, a rollback operation can be performed. The rollback operation involves releasing the locks (including held locks, pending locks, and shared locks) of the current transaction sequentially based on the identifiers in the rollback log.

[0113] Further, the processing device can add exclusive locks to each identifier in the redo log and update the index and data, and release the exclusive locks when the update is completed.

[0114] In addition, the embodiment of the present application further provides a storage medium, wherein the storage medium stores a database transaction processing program, and the database transaction processing program is executed by a processor to implement the steps of the database transaction processing method.

[0115] Based on the first embodiment of the database transaction processing method, the first embodiment of the database transaction processing device is provided, which is described with reference to Figure 5 , Figure 5 The structure block diagram of the first embodiment of the database transaction processing device is shown in the figure.

[0116] As Figure 5 shown, the database transaction processing device provided by the embodiment of the present application comprises:

[0117] The object processing module 501 is configured to process the to-be-processed object according to the data processing instruction in the database transaction, and add a reserved lock to the to-be-processed object, wherein the reserved lock is used to indicate that the database transaction will modify the to-be-processed object.

[0118] The log generation module 502 is configured to record the operation of processing the to-be-processed object, and save the generated record through a log.

[0119] The data updating module 503 is configured to allocate a resource for updating the to-be-processed object, update the database according to the log, and release the exclusive lock when the update is completed.

[0120] Further, the object processing module 501 is further configured to process the identifier of the to-be-processed object according to the data processing instruction in the database transaction, and add a reserved lock to the slot corresponding to the index of the to-be-processed object; determine the identifier of the to-be-processed object data based on the slot corresponding to the index of the to-be-processed object, and add a reserved lock to the identifier of the to-be-processed object data.

[0121] Further, the object processing module 501 is further configured to allocate a row identifier space of the to-be-processed object according to the data insertion instruction in the database transaction; or add a deletion state to the identifier of the to-be-processed object according to the data deletion instruction in the database transaction.

[0122] Further, the log generation module 502 is further configured to record the operation of processing the to-be-processed object, the slot corresponding to the index of the to-be-processed object, and the identifier of the to-be-processed object data, and write the record into a redo log; acquire the locked data in the to-be-processed object, and write the locked data into a rollback log.

[0123] The embodiment processes the to-be-processed object according to the data processing instruction in the database transaction, and reserves a lock for the to-be-processed object, the lock being used to represent that the database transaction will modify the to-be-processed object; records the operation of processing the to-be-processed object, and saves the generated record through a log; allocates a resource for updating the to-be-processed object, and updates the database according to the log. Since the application manages the modification of the to-be-processed object through the reserved lock, and updates the database through the record in the log, the problem that the RC isolation level in the prior art generally adopts a multi-version concurrency control mechanism, but the method needs mutual exclusion in the program and exists implicit lock and cannot be concurrent is solved, and the time for which a lock is held by a concurrent transaction is shortened by introducing more lock modes, and the concurrency of transaction processing is improved.

[0124] Referring to the first embodiment of the database transaction processing apparatus of the application as described above, a second embodiment of the database transaction processing apparatus of the application is provided.

[0125] In the embodiment, the data updating module 503 is further configured to allocate a resource required for updating the index of the to-be-processed object, acquire the identifiers of the to-be-processed object data in the redo log, perform an exclusive lock operation on each of the identifiers of the to-be-processed object data, update the database according to the operation record in the redo log, and release the exclusive lock corresponding to the to-be-processed object when the update of each to-be-processed object is completed.

[0126] Further, the data updating module 503 is further configured to, if the resource allocation fails, release the lock based on the data saved in the rollback log, so as to perform a rollback operation of the database transaction.

[0127] Further, the data updating module 503 is further configured to, if the exclusive lock operation on each of the identifiers of the to-be-processed object data is unsuccessful, release the lock based on the data saved in the rollback log, so as to perform a rollback operation of the database transaction.

[0128] The embodiment allocates a resource required for updating the index of the to-be-processed object, acquires the identifiers of the to-be-processed object data in the redo log, performs an exclusive lock operation on each of the identifiers of the to-be-processed object data, updates the database according to the operation record in the redo log, and releases the exclusive lock corresponding to the to-be-processed object when the update of each to-be-processed object is completed. Since the database transaction is processed through the reserved lock, the exclusive lock and the redo log, the UndoLog data copying is reduced, the memory is saved, the transaction processing delay is shortened, more lock states are introduced, the time for which each operation in the transaction occupies the lock is shortened, and the transaction processing concurrency is improved.

[0129] Other embodiments or specific implementations of the database transaction processing apparatus of the present application can refer to the above-mentioned method embodiments, and will not be described here.

[0130] It should be noted that in this document, the terms "comprising", "including", or any other variant thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not only include those elements, but can also include other elements not expressly listed or inherent to such process, method, article, or system. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article, or system that includes the element.

[0131] The above-mentioned embodiment numbers of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.

[0132] From the above description of the embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be realized by means of software and the necessary general hardware platform, of course, they can also be realized by hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solutions of the present application or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, an optical disk) and includes a number of instructions for making a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute the methods described in the various embodiments of the present application.

[0133] The above is only the preferred embodiment of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent process transformation made by using the content of the present application specification and drawings, or directly or indirectly applied to other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method of database transaction processing, characterized by, The method comprises: processing a to-be-processed object according to a data processing instruction in a database transaction, and reserving a lock for the to-be-processed object, the reserved lock being used to indicate that the database transaction will modify the to-be-processed object; recording an operation of processing the to-be-processed object, and saving a generated record through a log; allocating a resource for updating the to-be-processed object, and updating a database according to the log; the step of recording the operation of processing the to-be-processed object and saving the generated record through the log comprises: recording an operation of processing the to-be-processed object, a to-be-processed object index corresponding slot and an identifier of to-be-processed object data, and writing the record into a redo log; obtaining locked data in the to-be-processed object, and writing the locked data into a rollback log; the step of allocating the resource for updating the to-be-processed object and updating the database according to the log comprises: allocating a resource required for updating the to-be-processed object index; obtaining the identifier of the to-be-processed object data in the redo log, and performing an exclusive lock operation on each of the identifiers of the to-be-processed object data; updating the database according to the operation record in the redo log, and releasing an exclusive lock corresponding to the to-be-processed object when each to-be-processed object update is completed; after the step of allocating the resource required for updating the to-be-processed object index, the method further comprises: if the resource allocation fails, releasing the lock based on the data saved in the rollback log to perform a rollback operation of the database transaction.

2. The database transaction processing method of claim 1, wherein, the step of processing the to-be-processed object according to the data processing instruction in the database transaction and reserving the lock for the to-be-processed object comprises: processing an identifier of a to-be-processed object according to a data processing instruction in a database transaction, and adding a reserved lock to a to-be-processed object index corresponding slot; determining an identifier of to-be-processed object data based on the to-be-processed object index corresponding slot, and adding a reserved lock to the identifier of the to-be-processed object data.

3. The database transaction processing method of claim 2, wherein, the data processing instruction comprises a data insertion instruction, a data deletion instruction and a data update instruction; the step of processing the identifier of the to-be-processed object according to the data processing instruction in the database transaction comprises: allocating a row identifier space of the to-be-processed object according to the data insertion instruction in the database transaction; or, adding a deletion state to the identifier of the to-be-processed object according to the data deletion instruction in the database transaction.

4. The database transaction processing method of claim 1, wherein, after the step of obtaining the identifier of the to-be-processed object data in the redo log and performing the exclusive lock operation on each of the identifiers of the to-be-processed object data, the method further comprises: if the exclusive lock operation on each of the identifiers of the to-be-processed object data is unsuccessful, releasing the lock based on the data saved in the rollback log to perform a rollback operation of the database transaction.

5. A database transaction processing apparatus characterized by comprising: the apparatus comprises: an object processing module, configured to process a to-be-processed object according to a data processing instruction in a database transaction, and reserve a lock for the to-be-processed object, the reserved lock being used to indicate that the database transaction will modify the to-be-processed object; The log generation module is configured to record the operation of processing the to-be-processed object, and save the generated record in a log; The data update module is configured to allocate resources for updating the to-be-processed object, update the database according to the log, and release the exclusive lock when the update is completed; The log generation module is further configured to record the operation of processing the to-be-processed object, the slot corresponding to the to-be-processed object index, and the identifier of the to-be-processed object data, and write the record into a redo log; acquire the locked data in the to-be-processed object, and write the locked data into a rollback log; The data update module is further configured to allocate resources required for updating the to-be-processed object index; acquire the identifier of the to-be-processed object data in the redo log, and perform an exclusive lock operation on each of the identifiers of the to-be-processed object data; update the database according to the operation record in the redo log, and release the exclusive lock corresponding to the to-be-processed object when the update of each to-be-processed object is completed; The data update module is further configured to, if the resource allocation fails, release the lock based on the data saved in the rollback log, so as to perform a rollback operation of the database transaction.

6. A database transaction processing apparatus characterized by comprising: The device comprises a memory, a processor, and a database transaction processing program stored on the memory and executable on the processor, and the database transaction processing program is configured to implement the steps of the database transaction processing method according to any one of claims 1-4.

7. A storage medium, characterized by The storage medium stores a database transaction processing program, and the database transaction processing program implements the steps of the database transaction processing method according to any one of claims 1-4 when executed by the processor.