[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN116860768A - Database transaction processing method, device, equipment and storage medium - Google Patents

Database transaction processing method, device, equipment and storage medium Download PDF

Info

Publication number
CN116860768A
CN116860768A CN202310777414.4A CN202310777414A CN116860768A CN 116860768 A CN116860768 A CN 116860768A CN 202310777414 A CN202310777414 A CN 202310777414A CN 116860768 A CN116860768 A CN 116860768A
Authority
CN
China
Prior art keywords
processed
data
lock
database transaction
processing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310777414.4A
Other languages
Chinese (zh)
Inventor
易其亮
蔡林山
胡龙
张晗
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Kingdom Technology Co ltd
Original Assignee
Shenzhen Kingdom Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Kingdom Technology Co ltd filed Critical Shenzhen Kingdom Technology Co ltd
Priority to CN202310777414.4A priority Critical patent/CN116860768A/en
Publication of CN116860768A publication Critical patent/CN116860768A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing

Landscapes

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

Abstract

The application relates to the field of databases and discloses a database transaction method, a device, equipment and a storage medium. Processing an object to be processed according to a data processing instruction in a database transaction, reserving a lock on the object to be processed, wherein the reserved lock is used for representing the database transaction to modify the object to be processed; recording the operation of processing the object to be processed, and storing the generated record through a log; and distributing resources for updating the object to be processed, and updating the database according to the log. The application manages the modification of the object to be processed by reserving the lock and updates the database by recording in the log, thus solving the problem that the RC isolation level in the prior art usually adopts a multi-version concurrency control mechanism, but the method searches, adds and deletes nodes in the history snapshot, needs mutual exclusion in the program, has the hidden lock and cannot be concurrent, and shortens the time of holding the lock by concurrent transactions by introducing more lock modes, thereby improving the concurrency of the transaction.

Description

Database transaction processing method, device, equipment and storage medium
Technical Field
The present application relates to the field of database technologies, and in particular, to a method, an apparatus, a device, and a storage medium for processing database transactions.
Background
The transaction processing is a core function of the database, and in order to improve the concurrent processing performance of the database, four transaction isolation levels are specified by the SQL standard: read Uncommitted, read Committed, repeatable Read, serizable. The most used isolation level is Read Committed (RC for short), and the default isolation level of the commercial database SQL Server, oracle and the open source database PostgreSQL is RC.
In the prior art, RC isolation level implementations typically employ a Multi-version concurrency control (Multi-Version Concurrency Control, MVCC) mechanism. The multi-version concurrency control is realized by maintaining a historical version snapshot mode, so that display locking is not needed between reading and writing of the same data, but a plurality of limitations exist. For example: searching, adding and deleting nodes in a history snapshot (generally a version linked list formed by transaction UndoLog), wherein mutual exclusion is needed in a program, and an implicit lock exists and cannot be concurrent; the data before update is written into UndoLog every time of update and deletion, and large cost and the like exist.
The foregoing is provided merely for the purpose of facilitating understanding of the technical solutions of the present application and is not intended to represent an admission that the foregoing is prior art.
Disclosure of Invention
The application mainly aims to provide a database transaction processing method, a device, equipment and a storage medium, which aim to solve the problems that in the prior art, RC isolation level usually adopts a multi-version concurrency control mechanism, but the method searches, adds and deletes nodes in a history snapshot, needs mutual exclusion in a program, has an implicit lock and cannot be concurrency; and the data before update is written into UndoLog for each update and deletion, so that the technical problem of high cost exists.
To achieve the above object, the present application provides a database transaction processing method, including the steps of:
processing an object to be processed according to a data processing instruction in a database transaction, and setting a reserved lock for the object to be processed, wherein the reserved lock is used for representing that the database transaction is to modify the object to be processed;
recording the operation of processing the object to be processed, and storing the generated record through a log;
and distributing and updating the resources of the object to be processed, and updating a database according to the log.
Optionally, the step of processing the object to be processed according to the data processing instruction in the database transaction and reserving a lock for the object to be processed includes:
processing the identification of the object to be processed according to the data processing instruction in the database transaction, and adding a reserved lock to the corresponding slot of the index of the object to be processed;
and determining the identification of the object data to be processed based on the corresponding slot position of the index of the object to be processed, and adding a reserved lock to the identification of the object data to be processed.
Optionally, the data processing instruction includes a data insertion instruction, a data deletion instruction, and a data update instruction; the step of processing the identification of the object to be processed according to the data processing instruction in the database transaction comprises the following steps:
distributing a row identification space of an object to be processed according to a data insertion instruction in a database transaction;
or adding a deletion state for the identification of the object to be processed according to the data deletion instruction in the database transaction.
Optionally, the step of recording an operation of processing the object to be processed and saving the generated record through a log includes:
recording the operation of processing the object to be processed, the corresponding slot position of the index of the object to be processed and the identification of the data of the object to be processed, and writing the record into a redo log;
and acquiring the locked data in the object to be processed, and writing the locked data into a rollback log.
Optionally, the step of allocating and updating the resource of the object to be processed and updating the database according to the log includes:
distributing resources required for updating the index of the object to be processed;
acquiring the identification of the object data to be processed in the redo log, and executing exclusive lock setting operation on the identification of each object data to be processed;
and updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to each object to be processed when the update of each object to be processed is completed.
Optionally, after the step of allocating resources required for updating the index of the object to be processed, the method further includes:
and if the resource allocation fails, releasing the lock based on the data stored in the rollback log so as to execute the rollback operation of the database transaction.
Optionally, after the step of obtaining the identifier of the object data to be processed in the redo log and performing the exclusive lock setting operation on the identifier of each object data to be processed, the method further includes:
and if the executing the exclusive locking operation on the identification of each object data to be processed is unsuccessful, releasing the lock based on the data stored in the rollback log so as to execute the rollback operation of the database transaction.
In addition, to achieve the above object, the present application also proposes a database transaction processing apparatus, the apparatus comprising:
the object processing module is used for processing an object to be processed according to a data processing instruction in a database transaction, and placing a reserved lock on the object to be processed, wherein the reserved lock is used for representing that the database transaction is to modify the object to be processed;
the log generation module is used for recording the operation of processing the object to be processed and storing the generated record through a log;
and the data updating module is used for distributing and updating the resources of the object to be processed, updating the database according to the log and releasing the exclusive lock when the updating is completed.
In addition, to achieve the above object, the present application also proposes a database transaction device, the device comprising: a memory, a processor, and a database transaction program stored on the memory and executable on the processor, the database transaction program configured to implement the steps of the database transaction method as described above.
In addition, to achieve the above object, the present application also proposes a storage medium having stored thereon a database transaction program which, when executed by a processor, implements the steps of the database transaction method as described above.
According to the method, an object to be processed is processed according to a data processing instruction in a database transaction, a lock is reserved for the object to be processed, and the reserved lock is used for representing the database transaction to modify the object to be processed; recording the operation of processing the object to be processed, and storing the generated record through a log; and distributing resources for updating the object to be processed, and updating the database according to the log. The application manages the modification of the object to be processed by reserving the lock and updates the database by recording in the log, thus solving the problem that the RC isolation level in the prior art usually adopts a multi-version concurrency control mechanism, but the method searches, adds and deletes nodes in the history snapshot, needs mutual exclusion in the program, has the hidden lock and cannot be concurrent, and shortens the time of holding the lock by concurrent transactions by introducing more lock modes, thereby improving the concurrency of the transaction.
Drawings
FIG. 1 is a schematic diagram of a database transaction device of a hardware runtime environment in which embodiments of the present application are implemented;
FIG. 2 is a flowchart of a database transaction method according to a first embodiment of the present application;
FIG. 3 is a flowchart illustrating a database transaction processing method according to a second embodiment of the present application;
FIG. 4 is a schematic flow chart of an application scenario of the database transaction method of the present application;
fig. 5 is a block diagram of a first embodiment of a database transaction processing apparatus according to the present application.
The achievement of the objects, functional features and advantages of the present application will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
Referring to fig. 1, fig. 1 is a schematic diagram of a database transaction processing device in a hardware running environment according to an embodiment of the present application.
As shown in fig. 1, the database transaction device may include: a processor 1001, such as a central processing unit (Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, a memory 1005. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a Wireless interface (e.g., a Wireless-Fidelity (Wi-Fi) interface). The Memory 1005 may be a high-speed random access Memory (Random Access Memory, RAM) or a stable nonvolatile Memory (NVM), such as a disk Memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
Those skilled in the art will appreciate that the architecture shown in fig. 1 is not limiting of a database transaction device and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, a user interface module, and a database transaction handler may be included in the memory 1005 as one type of storage medium.
In the database transaction device shown in fig. 1, 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 device of the present application may be disposed in the database transaction device, and the database transaction device calls the database transaction program stored in the memory 1005 through the processor 1001 and executes the database transaction method provided by the embodiment of the present application.
An embodiment of the present application provides a database transaction processing method, and referring to fig. 2, fig. 2 is a schematic flow chart of a first embodiment of the database transaction processing method of the present application.
In this embodiment, the database transaction processing method includes the following steps:
processing an object to be processed according to a data processing instruction in a database transaction, and setting a reserved lock for the object to be processed, wherein the reserved lock is used for representing that the database transaction is to modify the object to be processed.
It should be noted that, the execution body of the method of this embodiment may be a terminal device having functions of data processing and program running, such as a personal computer, a server, etc., or may be an electronic device having the same or similar functions, such as the database transaction device described above. The present embodiment and the following embodiments will be described below with reference to a database transaction processing device (hereinafter referred to as processing device).
It will be appreciated that the above database transaction refers to treating a set of database operations (or database statements) as an indivisible unit, either all executing successfully or all rolling back, thereby ensuring the consistency and integrity of the database. In the database, transactions are managed by:
a1: start transaction (BEGIN): identifying the beginning of the transaction, beginning to record operations in the transaction;
a2: the operation is performed: executing a series of database operation statements, such as insert, update, delete, query, etc.;
a3: COMMIT transaction (COMMIT): permanently saving all operations in the transaction to a database;
a4: ROLLBACK transaction (ROLLBACK): all operations in the transaction are canceled and the database is restored to the state prior to the start of the transaction.
The use of transactions can ensure the consistency and integrity of database operations, and can avoid the problems of data collision and data inconsistency, particularly when multiple users access the database concurrently.
It should be appreciated that the above data processing instructions are database operation statements, such as data insertion instructions, data update instructions, data deletion instructions, and the like.
The object to be processed is an object stored in the database, and may be data, a table, a row, a column, a view, an index, a trigger, and the like. The data may be values of fields in row and column objects actually stored in the database.
It should be appreciated that a lock is a mechanism for managing concurrent access to control access rights to database resources. By using locks, it can be ensured that multiple transactions do not create problems of data inconsistency or conflict when concurrently executing. In this embodiment, the lock may include: shared (S) locks, pending (P) locks, reserved (R) locks, and Exclusive (X) locks.
It should be explained that the shared lock indicates that the object to be processed can be obtained by a plurality of transactions at the same time, and is used for carrying out concurrent reading of the database, and the shared lock can be released immediately after reading; when the transaction acquires the exclusive lock and modifies the exclusive lock, if the exclusive lock is not acquired, the lock of the object can be set as the pending lock, so that subsequent other transactions cannot concurrently read the object, the write lock is prevented from being dead, and the transaction can add the exclusive lock to the object; an exclusive lock is used to indicate that a write is being made to this object and no lock can be added to other transactions.
It should be noted that, the object of the lock may be a row, a slot in the Hash index, a table, a node in an index such as a T-tree or B-tree, a Page, or the like, which is not limited in this embodiment.
In particular, in a memory database, the lock's memory space may be continuously matched to the actual data memory space, e.g., a row, with a block of space (i.e., lock area) allocated at the head of the row for lock preservation and processing.
In this embodiment and the embodiments described below, the object to be processed may be identified by an id, which is called oid, oid may include a lock space, and the object in the database may include data of the object to be processed, an index of the object to be processed, a slot corresponding to the index of the object to be processed, and the like. The specific object can be directly accessed through oid, and the locking state on the object is obtained. Generally oid is a 64-bit non-conforming integer.
It should be explained that after a reservation lock is added to a resource in the database, the transaction will subsequently modify the object. That is, the reservation lock is used to characterize that the database transaction is to modify the pending object. When the database transaction adds a reserved lock to the object to be processed, other transactions can only read the shared lock and cannot add other locks. While the transaction may add a pending lock or an exclusive lock to the pending object.
Specifically, in order to perform more accurate processing on the object to be processed, the step of processing the object to be processed according to a data processing instruction in a database transaction and reserving a lock on the object to be processed includes:
and processing the identification of the object to be processed according to the data processing instruction in the database transaction, and adding a reserved lock to the corresponding slot of the index of the object to be processed.
It should be explained that an index is a data structure within a database that can be used to increase the speed and efficiency of data retrieval. An index is typically made up of one or more key values and corresponding slots for pointing to the location where the data is actually stored in the database, i.e., the index identity.
It can be understood that a reserved lock is added to the corresponding slot of the index of the object to be processed, that is, the corresponding slot of the index of the object to be processed is processed subsequently.
Specifically, the step of processing the identification of the object to be processed according to the data processing instruction in the database transaction includes:
distributing a row identification space of an object to be processed according to a data insertion instruction in a database transaction;
or adding a deletion state for the identification of the object to be processed according to the data deletion instruction in the database transaction.
When the data processing instruction is a data insertion instruction, the processing device may allocate a processing space for data to be processed; when the data processing instruction is a data deleting instruction, the processing device can change the identification of the object to be processed into a deleting state, and then the operation of adding the reserved lock can be performed.
It should be explained that, when the data processing instruction is a data update instruction, the operation of adding the retention lock is directly performed.
And determining the identification of the object data to be processed based on the corresponding slot position of the index of the object to be processed, and adding a reserved lock to the identification of the object data to be processed.
It should be noted that, the identification of the data of the object to be processed is the data corresponding to the object to be processed.
In a specific implementation, the processing device processes the object to be processed according to the data processing instruction in the database transaction, and reserves a lock for the object to be processed.
And recording the operation of processing the object to be processed, and storing the generated record through a log.
It will be appreciated that operations in the transaction may be recorded at the beginning of the database transaction, and operations to process objects in the database may be recorded when data processing instructions in the database transaction are executed, and the generated records may be saved by a log.
It should be noted that, in this embodiment, the data processing instruction in the execution database transaction does not actually update the data of the object to be processed and the index of the object to be processed, but locks the object to be processed through the log record operation, and in the transaction submitting stage, the update of the data of the object to be processed and the index of the object to be processed can be realized according to the operation record and the lock in the log.
Specifically, the step of recording the operation of processing the object to be processed and saving the generated record through a log includes:
and recording the operation of processing the object to be processed, the corresponding slot position of the index of the object to be processed and the identification of the data of the object to be processed, and writing the record into a redo log.
It should be noted that the Redo Log (redox Log) is a mechanism for ensuring data persistence and transaction consistency in a database system. It records all modification operations that occur in the database system for recovery and replay of data in the event of a system crash or failure recovery. In this embodiment, the operation type (such as deletion, insertion, update, query, etc.) of the data processing instruction in the database transaction, the identification of the data of the object to be processed, the update data, the data required by the data processing instruction such as the corresponding slot of the object to be processed, and the like are stored through the redo log.
And acquiring the locked data in the object to be processed, and writing the locked data into a rollback log.
It should be noted that the rollback Log (Undo Log) is a mechanism for implementing rollback operations and data consistency of transactions in a database. It records the modification and reverse operations performed on the database to undo committed transactions or rollback modifications made to uncommitted transactions. In this embodiment, only the locked object is stored in the rollback log, and when the object to be processed is locked corresponding to the slot or the identifier of the object data to be processed, the locked oid may be recorded to the rollback log.
When the database needs to cancel the submitted transaction or rollback the modification made by the uncommitted transaction, the rollback operation on the database transaction can be realized by releasing the lock according to the saved oid in the UndoLog.
In practical application, the UndoLog does not need to store the actual data in update, delete, only needs to store the locking object oid, reduces copy of the UndoLog data, saves memory, shortens the time delay of transaction processing, introduces more lock states, shortens the time occupied by each operation in the transaction to the lock, and improves the concurrency of the transaction processing.
In a specific implementation, the processing device records the operation of processing the processing object, and stores the generated record through a log.
Step S300: and distributing and updating the resources of the object to be processed, and updating a database according to the log.
It should be noted that this step corresponds to a step of submitting a database transaction, and when the processing of the data processing instruction in the database transaction is completed, resources required for updating the processing object may be allocated, and the database update may be performed according to the record in the log.
In a specific implementation, the processing device allocates resources for updating the object to be processed, and updates the database according to the log.
According to the embodiment, an object to be processed is processed according to a data processing instruction in a database transaction, a lock is reserved for the object to be processed, and the reserved lock is used for representing that the database transaction is to modify the object to be processed; recording the operation of processing the object to be processed, and storing the generated record through a log; and distributing resources for updating the object to be processed, and updating the database according to the log. The application manages the modification of the object to be processed by reserving the lock and updates the database by recording in the log, thus solving the problem that the RC isolation level in the prior art usually adopts a multi-version concurrency control mechanism, but the method searches, adds and deletes nodes in the history snapshot, needs mutual exclusion in the program, has the hidden lock and cannot be concurrent, and shortens the time of holding the lock by concurrent transactions by introducing more lock modes, thereby improving the concurrency of the transaction.
Further, the data query instruction may also be executed upon completion of execution of the data processing instruction.
Specifically, when the index is used for data query, that is, when a reserved lock exists on the index slot of the object to be queried, the processing device can find the object to be queried according to the data query instruction in the database transaction, and add the shared lock on the index slot of the object to be queried, so that the identification of the object to be queried is found, and simultaneously release the S lock on the index slot of the object to be queried and add the S lock on the data of the object to be queried, thereby realizing the reading of the data of the object to be queried, and releasing the S lock on the data of the object to be queried when the reading is completed.
When no lock exists on the index slot of the object to be queried, a shared lock can be added on the index slot of the object to be queried, so that the data of the object to be queried is searched, meanwhile, the S lock on the index slot of the object to be queried is released, the data of the object to be queried is added with the S lock, copying of the data of the object to be queried is realized, and when reading is completed, the S lock on the data of the object to be queried is released.
Based on the above-described first embodiment of the database transaction method of the present application, a second embodiment of the database transaction method of the present application is presented.
Fig. 3 is a flowchart of a second embodiment of the database transaction processing method according to the present application.
Referring to fig. 3, in order to update an object to be processed, the step of allocating resources for updating the object to be processed and updating a database according to the log includes:
step S310: and allocating resources required for updating the index of the object to be processed.
It should be noted that, when the execution of the data processing instruction and the data query instruction in the database transaction is completed, the processing device may allocate all the resources to be updated (the storage space of the allocation object in the memory database).
It should be explained that the processing device may perform a rollback operation when the resource allocation fails. Specifically, when the resource allocation fails, the processing apparatus performs lock release based on the lock object oid held in the rollback log to perform a rollback operation of the database transaction.
In a specific implementation, the processing device allocates resources required to update the index of objects to be processed.
Step S320: and acquiring the identification of the object data to be processed in the redo log, and executing exclusive lock setting operation on the identification of each object data to be processed.
It should be noted that, before the identification of the object data to be processed is processed, an exclusive lock (including a possible pending lock) needs to be acquired to ensure exclusive access to the object data to be processed. After the exclusive lock is acquired, other transactions cannot read or write data at the same time.
It should be explained that when the exclusive lock fails, the processing device may lock the pending object to the pending lock to prevent subsequent transactions from concurrently reading the object, thereby preventing the write lock from dying.
Further, when the exclusive lock fails, the processing device may perform a rollback operation, where the steps of the rollback operation are as described above, which is not described in detail in this embodiment.
Step S330: and updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to each object to be processed when the update of each object to be processed is completed.
It should be noted that, when the exclusive lock is set, the database update operation may be performed. Specifically, the processing device may perform operations such as data update, data insertion, data deletion, and the like according to the order in the redo log. The data update may include an object to be processed data update, an object to be processed index update; the data insertion may include an object index update to be processed; the data deletion may include a pending object data deletion, a pending object index deletion.
It should be explained that, the successful execution of the steps S310 and S320 can ensure that each step pair in the step S330 can be successfully executed, so that the X lock can be released immediately when any object to be processed is updated, and concurrency is guaranteed to the greatest extent.
In the embodiment, resources required for updating the index of the object to be processed are allocated; acquiring the identification of the object data to be processed in the redo log, and executing exclusive lock setting operation on the identification of each object data to be processed; and updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to the object to be processed when the update of each object to be processed is completed. The database transaction is performed by reserving the lock, the exclusive lock and the redo log, so that the UndoLog data copy is reduced, the memory is saved, the transaction processing time delay is shortened, more lock states are introduced, the lock occupation time of each operation in the transaction is shortened, and the transaction processing concurrency is improved.
Fig. 4 is a schematic flow chart of an application scenario of the database transaction processing method according to the present application, as shown in fig. 4.
Referring to FIG. 4, at the beginning of a transaction, a processing device may read data processing instructions in the transaction, including data deletion instructions, data update instructions, data insertion instructions, concatenate data and possibly updated object R locks (reservation locks), and write a redo log and a rollback log according to the performed operations.
Further, the processing device can read the data query instruction in the transaction to obtain the identification of the data, and place the identification of the data in the shared lock, and the shared lock can be released when the copying is completed; if the index is used, the index identifier (i.e. the corresponding slot position of the index) is sent to the shared lock, the shared lock of the index identifier is released after the data identifier is obtained, the data identifier is placed in the shared lock, and the shared lock can be released when copying is completed.
Further, at transaction commit, the processing device allocates resources required to update the index, and if the update is unsuccessful, a rollback operation may be performed. The rollback operation releases the locks (including reserved lock/pending lock/shared lock) of the transaction above in sequence, based on the identification in the rollback log.
Further, the processing device may add an exclusive lock to each identifier in the redo log and update the index and data, and release the exclusive lock when the update is completed.
In addition, the embodiment of the application also provides a storage medium, wherein the storage medium is stored with a database transaction processing program, and the database transaction processing program realizes the steps of the database transaction processing method when being executed by a processor.
Based on the first embodiment of the database transaction processing method of the present application, a first embodiment of the database transaction processing device of the present application is provided, and referring to fig. 5, fig. 5 is a block diagram of the first embodiment of the database transaction processing device of the present application.
As shown in fig. 5, a database transaction processing apparatus according to an embodiment of the present application includes:
the object processing module 501 is configured to process an object to be processed according to a data processing instruction in a database transaction, and set a reserved lock for the object to be processed, where the reserved lock is used to characterize that the database transaction will modify the object to be processed;
the log generating module 502 is configured to record an operation of processing the object to be processed, and store the generated record through a log;
and the data updating module 503 is configured to allocate resources for updating the object to be processed, update the database according to the log, and release the exclusive lock when the update is completed.
Further, the object processing module 501 is further configured to process, according to a data processing instruction in a database transaction, an identifier of an object to be processed, and add a reserved lock to a slot corresponding to an index of the object to be processed; and determining the identification of the object data to be processed based on the corresponding slot position of the index of the object to be processed, and adding a reserved lock to the identification of the object data to be processed.
Further, the object processing module 501 is further configured to allocate a line identification space of an object to be processed according to a data insertion instruction in a database transaction; or adding a deletion state for the identification of the object to be processed according to the data deletion instruction in the database transaction.
Further, the log generating module 502 is further configured to record an operation of processing the object to be processed, a slot corresponding to the index of the object to be processed, and an identifier of the data of the object to be processed, and write the record into a redo log; and acquiring the locked data in the object to be processed, and writing the locked data into a rollback log.
According to the embodiment, an object to be processed is processed according to a data processing instruction in a database transaction, a lock is reserved for the object to be processed, and the reserved lock is used for representing that the database transaction is to modify the object to be processed; recording the operation of processing the object to be processed, and storing the generated record through a log; and distributing resources for updating the object to be processed, and updating the database according to the log. The application manages the modification of the object to be processed by reserving the lock and updates the database by recording in the log, thus solving the problem that the RC isolation level in the prior art usually adopts a multi-version concurrency control mechanism, but the method searches, adds and deletes nodes in the history snapshot, needs mutual exclusion in the program, has the hidden lock and cannot be concurrent, and shortens the time of holding the lock by concurrent transactions by introducing more lock modes, thereby improving the concurrency of the transaction.
With reference to the first embodiment of the database transaction device of the present application as described above, a second embodiment of the database transaction device of the present application is presented.
In this embodiment, the data updating module 503 is further configured to allocate resources required for updating the index of the object to be processed; acquiring the identification of the object data to be processed in the redo log, and executing exclusive lock setting operation on the identification of each object data to be processed; and updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to each object to be processed when the update of each object to be processed is completed.
Further, the data updating module 503 is further configured to perform a lock release based on the data stored in the rollback log to perform a rollback operation of the database transaction if the resource allocation fails.
Further, the data updating module 503 is further configured to perform a rollback operation of the database transaction based on the data stored in the rollback log if the performing of the exclusive lock operation on the identifier of each object data to be processed is unsuccessful.
In the embodiment, resources required for updating the index of the object to be processed are allocated; acquiring the identification of the object data to be processed in the redo log, and executing exclusive lock setting operation on the identification of each object data to be processed; and updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to the object to be processed when the update of each object to be processed is completed. The database transaction is performed by reserving the lock, the exclusive lock and the redo log, so that the UndoLog data copy is reduced, the memory is saved, the transaction processing time delay is shortened, more lock states are introduced, the lock occupation time of each operation in the transaction is shortened, and the transaction processing concurrency is improved.
Other embodiments or specific implementations of the database transaction processing device of the present application may refer to the above method embodiments, and will not be described herein.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation 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 include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present application are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. read-only memory/random-access memory, magnetic disk, optical disk), comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present application.
The foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the application, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.

Claims (10)

1. A method of database transaction processing, the method comprising:
processing an object to be processed according to a data processing instruction in a database transaction, and setting a reserved lock for the object to be processed, wherein the reserved lock is used for representing that the database transaction is to modify the object to be processed;
recording the operation of processing the object to be processed, and storing the generated record through a log;
and distributing and updating the resources of the object to be processed, and updating a database according to the log.
2. The database transaction processing method according to claim 1, wherein the steps of processing an object to be processed according to a data processing instruction in a database transaction and setting a reserved lock for the object to be processed include:
processing the identification of the object to be processed according to the data processing instruction in the database transaction, and adding a reserved lock to the corresponding slot of the index of the object to be processed;
and determining the identification of the object data to be processed based on the corresponding slot position of the index of the object to be processed, and adding a reserved lock to the identification of the object data to be processed.
3. The database transaction processing method of claim 2, wherein the data processing instructions include a data insertion instruction, a data deletion instruction, and a data update instruction; the step of processing the identification of the object to be processed according to the data processing instruction in the database transaction comprises the following steps:
distributing a row identification space of an object to be processed according to a data insertion instruction in a database transaction;
or adding a deletion state for the identification of the object to be processed according to the data deletion instruction in the database transaction.
4. A database transaction method according to claim 3, wherein the step of recording the operation of processing the object to be processed and saving the generated record through a log comprises:
recording the operation of processing the object to be processed, the corresponding slot position of the index of the object to be processed and the identification of the data of the object to be processed, and writing the record into a redo log;
and acquiring the locked data in the object to be processed, and writing the locked data into a rollback log.
5. The database transaction processing method according to claim 4, wherein the step of allocating resources for updating the object to be processed, and updating the database based on the log comprises:
distributing resources required for updating the index of the object to be processed;
acquiring the identification of the object data to be processed in the redo log, and executing exclusive lock setting operation on the identification of each object data to be processed;
and updating the database according to the operation record in the redo log, and releasing the exclusive lock corresponding to each object to be processed when the update of each object to be processed is completed.
6. The database transaction method of claim 5, wherein after the step of allocating resources required to update the index of the object to be processed, further comprising:
and if the resource allocation fails, releasing the lock based on the data stored in the rollback log so as to execute the rollback operation of the database transaction.
7. The database transaction processing method according to claim 5, wherein the step of acquiring the identification of the object data to be processed in the redo log, after performing the exclusive lock setting operation on each of the identifications of the object data to be processed, further comprises:
and if the executing the exclusive locking operation on the identification of each object data to be processed is unsuccessful, releasing the lock based on the data stored in the rollback log so as to execute the rollback operation of the database transaction.
8. A database transaction processing device, the device comprising:
the object processing module is used for processing an object to be processed according to a data processing instruction in a database transaction, and placing a reserved lock on the object to be processed, wherein the reserved lock is used for representing that the database transaction is to modify the object to be processed;
the log generation module is used for recording the operation of processing the object to be processed and storing the generated record through a log;
and the data updating module is used for distributing and updating the resources of the object to be processed, updating the database according to the log and releasing the exclusive lock when the updating is completed.
9. A database transaction device, the device comprising: memory, a processor and a database transaction program stored on the memory and executable on the processor, the database transaction program being configured to implement the steps of the database transaction method according to any of claims 1-7.
10. A storage medium having stored thereon a database transaction program which when executed by a processor performs the steps of the database transaction method according to any of claims 1 to 7.
CN202310777414.4A 2023-06-28 2023-06-28 Database transaction processing method, device, equipment and storage medium Pending CN116860768A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310777414.4A CN116860768A (en) 2023-06-28 2023-06-28 Database transaction processing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310777414.4A CN116860768A (en) 2023-06-28 2023-06-28 Database transaction processing method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116860768A true CN116860768A (en) 2023-10-10

Family

ID=88220931

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310777414.4A Pending CN116860768A (en) 2023-06-28 2023-06-28 Database transaction processing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116860768A (en)

Similar Documents

Publication Publication Date Title
US11314716B2 (en) Atomic processing of compound database transactions that modify a metadata entity
JP4603546B2 (en) Database management system with efficient version control
CN108363806B (en) Multi-version concurrency control method and device for database, server and storage medium
US7376674B2 (en) Storage of multiple pre-modification short duration copies of database information in short term memory
US8868577B2 (en) Generic database manipulator
US6772155B1 (en) Looking data in a database system
JP2505040B2 (en) Data access method and data processing system for parallel access to index tree
US20190129894A1 (en) Database Transaction Processing Method, Client, and Server
JP3441807B2 (en) B-tree index management method and system
US20170220617A1 (en) Scalable conflict detection in transaction management
US7958149B2 (en) Computer program and product for append mode insertion of rows into tables in database management systems
CN106354732B (en) A kind of off-line data version conflict solution for supporting concurrently to cooperate with
CN114282074A (en) Database operation method, device, equipment and storage medium
CN110377614B (en) Order processing lock system under distributed environment
JP2001282599A (en) Method and device for managing data and recording medium with data management program stored therein
CN116860768A (en) Database transaction processing method, device, equipment and storage medium
CN114328591A (en) Transaction execution method, device, equipment and storage medium
US10303680B2 (en) Data processing apparatus and data processing method
CN117076147B (en) Deadlock detection method, device, equipment and storage medium
WO2024198010A1 (en) Concurrency control method and apparatus for column-oriented storage database
CN117348977A (en) Method, device, equipment and medium for controlling transaction concurrency in database
CN117687807A (en) Data processing method, device, electronic equipment and storage medium
CN116501812A (en) DDL statement execution method and device
CN118606009A (en) Concurrency control method, device, equipment and medium for transactions

Legal Events

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