CN114676115A - Database modification method, device, equipment and medium - Google Patents

Database modification method, device, equipment and medium Download PDF

Info

Publication number
CN114676115A
CN114676115A CN202210347585.9A CN202210347585A CN114676115A CN 114676115 A CN114676115 A CN 114676115A CN 202210347585 A CN202210347585 A CN 202210347585A CN 114676115 A CN114676115 A CN 114676115A
Authority
CN
China
Prior art keywords
transaction
waiting
conflict
identification number
blocking
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
CN202210347585.9A
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.)
Shanghai Dameng Database Co Ltd
Original Assignee
Shanghai Dameng Database 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 Shanghai Dameng Database Co Ltd filed Critical Shanghai Dameng Database Co Ltd
Priority to CN202210347585.9A priority Critical patent/CN114676115A/en
Publication of CN114676115A publication Critical patent/CN114676115A/en
Pending legal-status Critical Current

Links

Images

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/21Design, administration or maintenance of databases
    • G06F16/211Schema design and management
    • 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • 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/2358Change logging, detection, and notification
    • 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/24Querying
    • G06F16/245Query processing

Landscapes

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

Abstract

The embodiment of the invention discloses a database modification method, a database modification device and a database modification medium. The method comprises the following steps: when releasing a transaction lock object of a target transaction and awakening a waiting transaction, determining the registration condition of blocking information recorded by the waiting transaction target in a conflict transaction registration table; determining an execution strategy of the waiting transaction according to the registration condition; and controlling the waiting transaction to modify data according to the execution strategy. According to the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, the registration condition of the blocking information of the waiting transaction target record in the conflict transaction registration table is determined, and the execution strategy of the waiting transaction is determined according to the registration condition, so that invalid data query and data modification are prevented from being executed after the conflict transaction is awakened at the same time, and the concurrent execution efficiency of the system is improved.

Description

Database modification method, device, equipment and medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a database modification method, apparatus, device, and medium.
Background
The database system allows a plurality of users to concurrently access and modify data, the concurrent operation of different users is finally embodied as concurrent execution of different transactions, and a situation that a plurality of transactions concurrently access or modify the same row of data may occur.
In the prior art, in order to reduce resource consumption and maintenance cost of a database row lock, one row lock optimization method is to block a Transaction identification number (Transaction Identifier) as a blocking target, so as to replace the conventional row-level blocking. When the transaction is started, the current transaction number is used as a blocking target, the TID of the current transaction number is blocked by adopting an X blocking mode, and in addition, after the operations of insertion, deletion and updating are carried out, the current transaction number is written into the TID field of the record, which is equivalent to that the X blocking is also carried out on the line of record, so that the consumption of line lock resources is reduced. Before the transaction is finished, when another transaction needs to modify the same record, reading a TID value from the record, judging whether the record is visible according to a visibility rule of a multi-version concurrency control technology, wherein the transaction 1 is not submitted yet, so the record is invisible to the transaction 2, the transaction 2 is blocked when performing X blocking on the current TID value in the record, and the transaction 2 is awakened until the transaction 1 is finished, so that the aim of multi-transaction concurrency control is fulfilled.
BRIEF SUMMARY OF THE PRESENT DISCLOSURE
In view of this, the present invention provides a database modification method, apparatus, device and medium, which can avoid performing invalid data query and modification after conflicting transactions are simultaneously awakened, and improve the efficiency of concurrent execution of the system.
According to an aspect of the present invention, an embodiment of the present invention provides a database modification method, where the method includes:
when a transaction lock object of a target transaction is released and a waiting transaction is awakened, determining the registration condition of blocking information of a waiting transaction target record in a conflict transaction registration table;
determining an execution strategy of the waiting transaction according to the registration condition;
and controlling the waiting transaction to modify data according to the execution strategy.
According to another aspect of the present invention, an embodiment of the present invention further provides a database modification method and apparatus, where the apparatus includes:
the system comprises a register determining module, a conflict transaction register table and a data processing module, wherein the register determining module is used for determining the register condition of blocking information of a target record of a waiting transaction in the conflict transaction register table when a transaction lock object of the target transaction is released and the waiting transaction is awakened;
the strategy determining module is used for determining the execution strategy of the waiting transaction according to the registration condition;
and the data modification module is used for controlling the waiting transaction to modify data according to the execution strategy.
According to another aspect of the present invention, an embodiment of the present invention further provides an electronic device, including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the database modification method according to any of the embodiments of the present invention.
According to another aspect of the present invention, an embodiment of the present invention further provides a computer-readable storage medium, which stores computer instructions for causing a processor to implement the database modification method according to any embodiment of the present invention when executed.
According to the technical scheme of the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, the registration condition of the blocking information of the target record of the waiting transaction in the conflict transaction registration table is determined; determining an execution strategy of a waiting transaction according to the registration condition; and controlling to wait for the transaction to modify the data according to the execution strategy. According to the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, the registration condition of the blocking information of the waiting transaction target record in the conflict transaction registration table is determined, and the execution strategy of the waiting transaction is determined according to the registration condition, so that invalid data query and data modification are prevented from being executed after the conflict transaction is awakened at the same time, and the concurrent execution efficiency of the system is improved.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present invention, nor do they necessarily limit the scope of the invention. Other features of the present invention will become apparent from the following description.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a database modification method according to an embodiment of the present invention;
fig. 2 is a flowchart of a database modification method according to a second embodiment of the present invention;
fig. 3 is a flowchart of a database modification method according to a third embodiment of the present invention;
fig. 4 is a block diagram of a database modification apparatus according to a fourth embodiment of the present invention;
FIG. 5 illustrates a schematic diagram of an electronic device that may be used to implement embodiments of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It is to be understood that the terms "target" and the like in the description and claims of the present invention and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in other sequences than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In the prior art, for database modification, data preparation is generally performed first: create table T (id int, val int); insert into T values (1, 1); commit; this line of inserted records is identified with Rec1, and its Rowid value is identified with Rowid 1. TrxA executes Update T set val +1where id is 1; the Rec1 record of the T table is updated. When the TrxA is started, the X mode blocks the transaction number TidA of the TrxA, and the lock object is LockA [ TidA, X ]. After the update operation is performed, TID field of Rec1 has TidA written.
TrxB executes Update T set val +1where id 1; the Rec1 record of the T table is updated. When the TrxB is started, the X mode blocks the transaction number TidB of the TrxB, and the lock object is LockB [ TidB, X ]. When the update operation is executed, the TID field of Rec1 is read to be TidA, and since TrxA is an active transaction, TrxB executes S blocking on the transaction number TidA of TrxA, and generates blocking wait. The lock object with TrxB in wait state is LockB2[ TidA, S, T, Rowid1], which conflicts with LockA [ TidA, X ] of TrxA transaction.
TrxC executes Update T set val +1where id 1; the Rec1 record of the T table is updated. When TrxC starts, the X mode blocks its own transaction number TidC, and the lock object is LockC [ TidC, X ]. When the update operation is executed, the TID field of the Rec1 is read to be TidA, and because TrxA is an active transaction, TrxC executes S blocking on the transaction number TidA of the TrxA, so that blocking waiting is generated. The lock object with TrxC in wait state is LockC2[ TidA, S, T, Rowid1], which conflicts with LockA [ TidA, X ] for TrxA transactions and LockB2[ TidA, S, T, Rowid1] for TrxB transactions.
TrxA transactions commit, release LockA [ TidA, X ], grant LockB2[ TidA, S, T, Rowid1] authority and wake TrxB, TrxC 2[ TidA, S, T, Rowid1] continue waiting due to a conflict with LockB2[ TidA, S, T, Rowid1 ]. After the TrxB is awakened, the query operation needs to be executed again, the updated Rec1 recorded content is obtained, and then the update operation is executed again. After the update operation of TrxB is completed, the TID field of record Rec1 is modified to TidB.
TrxD executes Update T set val +1where id is 1; and a Rec1 for updating the T table records that the X mode blocks the transaction number TidD of the TrxD when the TrxD is started, and the lock object is LockD [ TidD, X ]. When the update operation is executed, reading the TID field of Rec1 to be TidB, and because TrxB is an active transaction, TrxD executes S blocking on the transaction number TidB of TrxB, so that blocking waiting is generated. The lock object of the TrxD in the waiting state is LockD2[ TidB, S, T, Rowid1], which conflicts with the LockB [ TidB, X ] of the TrxB transaction.
TrxB transaction commit, release LockB2[ TidA, S, T, Rowid1], grant LockC2[ TidA, S, T, Rowid1] authority to wake TrxC, release LockB [ TidB, X ], grant LockD2[ TidB, S, T, Rowid1] authority to wake TrxD.
Under the above scenario, LockC2 and LockD2 block different transaction numbers, and therefore do not determine as a blocking conflict, TrxC and TrxD are woken up at the same time, and each re-executes a query to obtain updated record content, and when re-executes an update operation, TrxC and TrxD form a new update conflict because the two transactions modify the same row of records, that is, multiple transactions with data update conflicts may still be woken up at the same time, thereby causing unnecessary concurrent conflicts and reducing the execution efficiency of the system.
In view of this, the present application provides a database modification method, apparatus, device, and medium, which ensure that, when a transaction is submitted or rolled back, although a plurality of conflicting transactions are woken up, only one transaction is really started and executed, and other conflicting transactions are continuously in a blocking waiting state, so as to avoid executing invalid data query and data modification after the conflicting transactions are woken up simultaneously, thereby improving system concurrent execution efficiency.
Example one
In an embodiment, fig. 1 is a flowchart of a database modification method according to an embodiment of the present invention, where the present embodiment is applicable to a situation when data in a database is modified, and the method may be executed by a database modification apparatus, where the database modification apparatus may be implemented in a form of hardware and/or software, and the database modification apparatus may be configured in an electronic device. As shown in fig. 1, the method includes:
s110, when the transaction lock object of the target transaction is released and the waiting transaction is waken up, the registration condition of the blocking information of the waiting transaction target record in the conflict transaction registration table is determined.
Wherein a target transaction may be understood as a transaction released when a transaction commit or a transaction rollback occurs. The transaction lock object can be understood as a blocking object corresponding to a transaction lock for blocking a certain transaction identification number by a target transaction, and the transaction lock can be used for blocking the transaction under the condition that the target transaction and a waiting transaction conflict. The transaction lock object may include an identification number of a blocked transaction of the target transaction, a blocking mode of the target transaction, an identification number of a data table modified by the target transaction, a row identification number of a record of data modified by the target transaction, and the like, which is not limited herein. A wait transaction may be understood as a transaction that has a conflict with a target transaction that needs to be woken up when the target transaction performs a transaction commit or a transaction rollback operation. A target record may be understood as a record to be woken up awaiting a transaction to modify.
In this embodiment, the lockout information may be understood as information recorded in the transaction lock object of the target transaction. The blocking information may include a transaction identification number blocked by the target transaction, a blocking mode of the target transaction, a table identification number modified by the target transaction, a line identification number of a record modified by the target transaction, and a transaction identification number that the target transaction may be blocked again.
It should be noted that the content recorded in the conflict transaction registration table may include a conflict number, a table identification number array of the conflict transaction modification, a row identification number array of the conflict transaction modification, and a blocked transaction identification number array of the conflict transaction. Of course, the conflict transaction registration table may also adopt a hash table manner, and when the conflict transaction table is checked, the speed of blocking information search may be increased to reduce the array scanning cost, which is not limited in this embodiment.
In this embodiment, when the target transaction commits or rolls back, releases the transaction lock object, and wakes up the waiting transaction, it is necessary to check whether there is blocking information in the conflict transaction registration table that has not registered the target record of the waiting transaction. Specifically, when a target transaction is submitted or rolled back, a transaction lock object is released, and a waiting transaction is awakened, whether a modification table identification number and a row identification number where a modification record is located are identical to a waiting transaction target record exist in a conflict transaction registration table or not can be searched in a traversing manner, and if yes, it is indicated that blocking information of the waiting transaction target record is registered; conversely, if not, it indicates that the lockout information of the pending transaction target record has not been registered.
In one embodiment, the lockout information includes at least one of: a lockout transaction identification number, a lockout mode, a modification table identification number, a modification record row identification number, and a re-lockout transaction identification number.
The blocked transaction identification number may be understood as an identification number of a transaction blocked by the target transaction, and exemplarily, the identification number of the transaction blocked by the target transaction may be transaction a, transaction B, or transaction C, which is not limited herein. The lockout mode may be a shared type lockout, i.e., an S lockout; it may also be an exclusive type lockout, i.e., an X lockout, and the embodiment is not limited herein. Modifying a table identification number may be understood as a table identification number that is modified by a target transaction prior to commit or rollback. Modifying a record row identification number may be understood as the row identification number of the modified record before committing or rolling back of the target transaction. The re-blocked transaction identification number may be understood as the transaction identification number that needs to be re-blocked when a blocking request is re-initiated.
In this embodiment, the blocking information of the target record at least includes: the locking transaction identification number, the locking mode, the modification table identification number, the modification record row identification number and the re-locking transaction identification number so as to check whether the locking information of the target record is already registered in the conflict transaction registration table according to the target record.
And S120, determining an execution strategy of the waiting transaction according to the registration condition.
The execution policy can be understood as a policy for waiting for the next step of the transaction, which is determined by the registration of the blocking information recorded by the target of the waiting transaction. The execution policy may be a policy of waiting for the transaction to continue waiting, or a policy of continuing to execute data processing, and this embodiment is not limited herein.
In this embodiment, the registration situation may be divided into two types, one is that when the target transaction is committed or rolled back, after the transaction lock object of the target transaction is released, before the waiting transaction is awakened, the blocking information of the target record of the waiting transaction is checked not to be registered in the conflict transaction registration table; the other is to check the blocking information of the target record of the waiting transaction registered in the conflict transaction register table after releasing the transaction lock object of the target transaction and before waking the waiting transaction when the target transaction commits or rolls back. Of course, the policy implemented is different for the two different registration cases.
In this embodiment, it can be determined whether to continue waiting or to continue executing the policy related to data processing after the waiting transaction is awakened according to the registration condition of the blocking information recorded by the waiting transaction target. Specifically, under the condition that the blocking information recorded by the transaction target is already registered, the blocking information does not need to be repeatedly registered, and after the transaction is awakened, the execution strategy can be a continuous waiting strategy; accordingly, in the case that the blocking information of the waiting transaction target record is not registered, the blocking information needs to be registered in the conflict transaction registration table, and after the waiting transaction is awakened, the execution policy may be a processing policy to continue executing the data processing operation.
S130, controlling and waiting for the transaction modification data according to the execution strategy.
Wherein modifying data may be understood as an operation of causing a waiting transaction to perform data modification according to a corresponding execution policy.
In this embodiment, the waiting transaction may be subjected to data modification according to a corresponding execution policy. It should be noted that the modified data may be, under the condition that the blocking information of the waiting transaction target record is not registered, the blocking information is registered in the conflict transaction registration table, after the waiting transaction is woken up, the content of the data after being updated is re-queried, and the corresponding data modification operation is re-executed, or, under the condition that the blocking information of the waiting transaction target record is registered, after the transaction is woken up, a blocking request is re-initiated according to the blocking information registered in the conflict transaction registration table, a new transaction lock object is determined, and the transaction is re-blocked, so that the transaction is in a continuous waiting state. Therefore, only one transaction is ensured to be in a real starting and executing state, and other transactions with conflicts continue to be in a blocking waiting state.
According to the technical scheme of the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, the registration condition of the blocking information of the target record of the waiting transaction in the conflict transaction registration table is determined; determining an execution strategy of a waiting transaction according to the registration condition; and controlling to wait for the transaction to modify the data according to the execution strategy. According to the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, the registration condition of the blocking information of the waiting transaction target record in the conflict transaction registration table is determined, and the execution strategy of the waiting transaction is determined according to the registration condition, so that invalid data query and data modification are prevented from being executed after the conflict transaction is awakened at the same time, and the concurrent execution efficiency of the system is improved.
In one embodiment, the database modification method further includes:
initializing a conflict transaction registry, wherein initializing the conflict transaction registry comprises: setting the number of conflicts in the conflict transaction registration table to be 0, and setting the number groups of the modification table identification numbers, the modification row identification number groups and the blocking transaction identification number groups in the conflict transaction registration table to be null.
In this embodiment, the conflict transaction registration table needs to perform a corresponding initialization operation first, and initializing the conflict transaction registration table may include: setting the conflict number in the conflict transaction registration table to be 0, and setting the table identification number array of the conflict transaction modification, the row identification number array of the conflict transaction modification and the blocked transaction identification number array of the conflict transaction in the conflict transaction registration table to be null.
Example two
In an embodiment, fig. 2 is a flowchart of a database modification method according to a second embodiment of the present invention, and in this embodiment, based on the foregoing embodiments, further details are performed on the registration condition of blocking information for determining a target transaction in a conflict transaction registration table and the execution policy for determining a waiting transaction according to the registration condition, as shown in fig. 2, the database modification method in this embodiment may specifically include the following steps:
s210, when a transaction lock object of a target transaction is released and a waiting transaction is awakened, traversing and searching whether blocking information of a waiting transaction target record exists in a conflict transaction registration table, if so, executing S220; if not, go to S230.
S220, the registration condition is that the blocking information is registered, and the execution strategy is determined to be a waiting strategy, wherein the waiting strategy comprises the following steps: and setting a re-blocking transaction identification number in the transaction lock object, and waiting for the transaction to be blocked again according to the re-blocking transaction identification number.
The waiting policy may be understood as a policy that, when the blocking information is registered, after the waiting transaction is awakened, blocking is performed again according to the unblocking transaction identification number, so that the waiting transaction continues to be in a waiting state.
In this embodiment, the conflict transaction registration table is checked, and when the lockout information is already registered, the execution policy may be to obtain a lockout transaction identification number of a conflict transaction registered in the conflict transaction registration table, set the identification number as a lockout transaction identification number, then wake up a waiting transaction, and after the waiting transaction is woken up, reconstruct and lockout a new transaction lock object according to the lockout transaction identification number, lockout mode, modification table identification number, and modification line identification number, so that the current transaction continues to be in a waiting state, and is re-woken up again when the waiting transaction commits or rolls back. The lockout mode may be an S lockout or an X lockout, and this embodiment is not limited herein.
In this embodiment, when the transaction lock object of the target transaction is released and the waiting transaction is waken up, the conflict transaction registration table is searched through, whether the blocking information of the waiting transaction target record exists or not, and if the blocking information of the waiting transaction target record exists, the blocking information of the waiting transaction target record is registered, and repeated registration operation is not required.
In one embodiment, waiting for the transaction to be locked again based on the relaocked transaction identification number includes:
acquiring a reclosure request of a waiting transaction, and creating a new transaction lock object of the waiting transaction according to the reclosure request;
waiting for the transaction to re-execute the lock according to the new transaction lock object.
The reclosing request may be understood as a reinitiated lockout request, which may be a shared lockout, i.e., an S lockout mode, or an exclusive lockout, i.e., an X lockout mode, and this embodiment is not limited again. The new transaction lock object may be understood as a new transaction lock object determined according to the new lockout request, and of course, the new transaction lock object includes a lockout transaction identification number, i.e., a set re-lockout transaction identification number, a current lockout mode, a modification table identification number, and a row identification number where the modification record is located.
It should be noted that, when a new transaction lock object of a waiting transaction is created according to a blockade request, the blockade transaction identification number uses the set blockade transaction identification number, before the waiting transaction is awakened, the blockade transaction identification number of the conflicting transaction is obtained from the conflicting transaction registry, and is set as the blockade transaction identification number, and after the waiting transaction is awakened, the blockade is performed again by using the blockade request in the S blockade mode or the X blockade mode.
In this embodiment, when a unblocking request of a waiting transaction is obtained, a new transaction lock object of the waiting transaction may be created according to the unblocking request to unblock the new transaction lock object.
S230, determining that the blocking information is not registered in the registration status, and determining that the execution policy is a processing policy, where the processing policy includes: and registering blocking information in the conflict transaction registration table, waiting for the transaction to inquire the updated record content, and re-executing data updating operation.
The processing policy may be understood as that, in a case where the blocking information is not registered, the blocking information is registered, and a relevant operation of corresponding data processing is performed.
In this embodiment, when a transaction lock object of a target transaction is released and a waiting transaction is waken up, a conflict transaction registration table is traversed to search whether blocking information of a waiting transaction target record exists, if the blocking information is not registered in the registration situation, a registration operation of the blocking information needs to be performed at this time, an execution policy is a processing policy that the blocking information is registered in the conflict transaction registration table, and after the waiting transaction is waken up, the waiting transaction queries updated record content and performs a data update operation again, for example, related operations such as insertion, deletion, and update of data are performed on a table in a database.
Specifically, registering the blocking information in the conflict transaction registration table may include: adding the table identification number of the blocking information to a modification table identification number array in a conflict transaction registration table, adding the row identification number of the blocking information to a row identification number array modified by conflict transactions registered in the conflict transaction registration table, adding the blocking transaction identification number of the blocking information to a blocking transaction identification number array of the conflict transactions registered in the conflict transaction registration table, and adding 1 to the number of conflicts in the conflict transaction registration table.
In one embodiment, registering the lockout information in a conflict transaction registry comprises:
adding the table identification number of the blocking information to a modification table identification number array in the conflict transaction registration table;
adding the row identification number of the blocking information to a modified row identification number array in a conflict transaction registration table;
adding the blocked transaction identification number of the blocking information to a blocked transaction identification number array in a conflict transaction registration table;
and adding 1 to the number of conflicts in the conflict transaction registration table.
Wherein, the modification table identification number array can be composed of modification table identification numbers; the modified row identification number array may consist of modified row identification numbers; the set of blocked transaction identification numbers may consist of blocked transaction identification numbers. Illustratively, the modification table identification number array may be denoted by tabs [ ]; the modified row identification number array may be represented by rowids [ ]; the blocked transaction identification number set may be denoted by tids [ ], and the embodiment is not limited herein.
In this embodiment, registering the blocking information in the conflict transaction registry in the case that the blocking information is not registered may include: adding the table identification number of the blocking information to a modification table identification number array in the conflict transaction registration table; adding the row identification number of the blocking information to a row identification number array modified by the conflict affair registered in a conflict affair registration table; adding the blocked transaction identification number of the blocking information to a blocked transaction identification number array of the conflict transaction registered in the conflict transaction registration table; and adding 1 to the number of conflicts in the conflict transaction registration table.
According to the technical scheme of the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, whether the blocking information of the target record of the waiting transaction exists in the conflict transaction register table is searched in a traversing manner; if yes, indicating that the blocking information is registered; if not, it indicates that the lockout information is not registered. Determining the execution policy as a waiting policy when the lockout information is registered, wherein the waiting policy comprises: setting a re-blocking transaction identification number in the transaction lock object, and waiting for the transaction to be blocked again according to the re-blocking transaction identification number; determining the execution policy as a processing policy under the condition that the blocking information is not registered, wherein the processing policy comprises: and registering locking information in the conflict transaction register table, waiting for the transaction to inquire the updated record content, and executing data updating operation again. In the embodiment of the invention, when the transaction lock object of the target transaction is released and the waiting transaction is awakened, whether the blocking information of the target record of the waiting transaction exists in the conflict transaction register table is searched in a traversing way, under the condition that the blocking information is registered, the execution strategy is determined to be the waiting strategy, under the condition that the blocking information is not registered, the execution strategy is determined to be the processing strategy, so that although a plurality of conflicting transactions are awakened when the transaction is submitted or rolled back, only one transaction is really started and executed, other conflicting transactions are continuously in the blocking waiting state, and invalid data query and data modification are executed after the conflicting transactions are awakened simultaneously, thereby improving the concurrent execution efficiency of the system.
EXAMPLE III
In an embodiment, to facilitate better understanding of a database modification method, fig. 3 is a flowchart of a database modification method provided in a third embodiment of the present invention, where TrxB transaction represents a B transaction, TrxC represents a C transaction, TrxD represents a D transaction, n _ row represents a number of conflicts, lock _ reg represents a conflict transaction registration table, LockB2 represents a lock object in a TrxB wait state, LockC2 represents a lock object in a TrxC wait state, LockD2 represents a lock object in a TrxD wait state, S lockout is a shared lockout, LockD3 represents a new transaction lock object, and relock _ tid represents a transaction identification number of a reclosure. Taking the scenario TrxB transaction commit as an example, the specific execution steps are described as follows:
s310, initializing a conflict transaction registration table.
In this embodiment, a conflict transaction registration table lock _ reg is initialized, n _ row registered in lock _ reg is set to 0, and a table identification number array modified by a conflict transaction, a row identification number array modified by the conflict transaction, and a blocked transaction identification number array of the conflict transaction in the conflict transaction registration table are all set to be empty.
And S320, determining the execution strategy as a processing strategy under the condition that the blocking information is not registered, and modifying the data according to the processing strategy.
In this embodiment, before releasing LockB2[ TidA, S, T, Rowid1], granting LockC2[ TidA, S, T, Rowid1] authority, checking lock _ reg, finding that no blocking information recorded in [ T, Rowid1] is registered in lock _ reg, so that lock _ reg is registered with blocking information of LockB2, waking up TrxC, re-executing query to obtain updated recorded content after TrxC is woken up, and then re-executing update operation.
The specific procedure for registering LockB2 blocking information in lock _ reg is as follows:
a1, setting tab [ n _ row ] registered in lock _ reg as T; wherein T represents a table identification number.
a2, setting rowids [ n _ row ] registered in lock _ reg as Rowid 1; rowid1 indicates a line identification number.
a3, setting tids [ n _ row ] registered in lock _ reg as TidA; TidA denotes the blocking transaction identification number.
a4, setting n _ row registered in lock _ reg to n _ row + 1.
And S330, determining the execution strategy as a waiting strategy when the blocking information is registered, and processing according to the waiting strategy.
In this embodiment, before releasing LockB [ TidB, X ], granting LockD2[ TidB, S, T, Rowid1], lock _ reg is checked to find that the blocking information recorded in [ T, Rowid1] has been registered, so relock _ tid in the LockD2 object is set to be the blocking transaction identification number, i.e., TidA, of the conflicting transaction registered in lock _ reg, and TrxD is woken.
It should be noted that after the TrxD transaction is woken up, according to the information such as relock _ tid registered on LockD2, an S blocking request for relock _ tid is reinitiated, the new transaction lock object is LockD3[ TidA, S, T, Rowid1], and since LockD3 collides with LockC2[ TidA, S, T, Rowid1], the TrxD transaction continues to wait and is woken up when the TrxC transaction commits or rolls back.
The embodiment of the invention checks the conflict transaction registry when the transaction is submitted or rolled back, the lock object is released, and the waiting transaction is awakened, and determines whether to continue to execute or wait again after the waiting transaction is awakened. If the relevant information of the record to be modified of the transaction is not registered in the conflict transaction registration table, registering the relevant information in the conflict transaction registration table, awakening the transaction to be waited, and continuing to execute after the transaction is awakened; if the relevant information of the record to be modified of the waiting transaction is registered on the conflict transaction registration table, the blocked transaction identification number of the conflict transaction registered in the conflict table is blocked again in an S mode or an X mode after the waiting transaction is awakened, and the waiting state is re-entered. Finally, transaction commit or rollback, while waking up multiple transactions that have conflicts, may ensure that only one transaction actually starts and executes, and that other conflicting transactions continue to be in a lock wait state.
The contents recorded in the transaction lock object are as follows: and tid: blocked transaction identification number, mode: lockout mode, tabid: modifying the table identification number, rowid: modifying the line identification number where the record is located, relock _ tid: the blocked transaction identification number needs to be re-blocked. The contents recorded in the conflict transaction registry are as follows: n _ row: number of collisions, tabids [ ]: the table identification number array, rowids [ ] of the conflicting transaction modification: row identification number array, tids [ ] of conflicting transaction modifications: a blocked transaction identification number array for conflicting transactions.
It should be noted that the conflict transaction registration table may also adopt a hash table manner to reduce the cost of array scanning, which is not limited herein.
According to the embodiment of the invention, the blocked object is released by transaction submission or rollback, when waiting for the transaction is awakened, information such as a Table identification number, a Row identification number and a blocked transaction identification number of a transaction lock is registered, whether a new update conflict can be caused after the transaction is awakened is checked according to the registered transaction lock information, only one waiting transaction is awakened when the transaction lock recorded in the same Row is released, invalid data query and data modification are executed after the conflict transaction is awakened at the same time, and the concurrent execution efficiency of the system is improved.
Example four
In an embodiment, fig. 4 is a block diagram of a database modification apparatus according to a fourth embodiment of the present invention, which is suitable for a case when data in a database is modified, and the apparatus may be implemented by hardware/software. The database modification method can be configured in the electronic device to implement the database modification method in the embodiment of the invention. As shown in fig. 4, the apparatus includes: a registration determination module 410, a policy determination module 420, and a data modification module 430.
The system comprises a register determining module, a conflict transaction register table and a data processing module, wherein the register determining module is used for determining the register condition of blocking information recorded by a target waiting transaction in the conflict transaction register table when a transaction lock object of the target transaction is released and the waiting transaction is awakened;
the strategy determining module is used for determining the execution strategy of the waiting affair according to the registration condition;
and the data modification module is used for controlling the waiting transaction to modify data according to the execution strategy.
According to the embodiment of the invention, the registration determining module determines the registration condition of the blocking information of the target record of the waiting transaction in the conflict transaction registration table by releasing the transaction lock object of the target transaction and awakening the waiting transaction, and the strategy determining module determines the execution strategy of the waiting transaction according to the registration condition, so that invalid data query and data modification are prevented from being executed after the conflict transaction is awakened at the same time, and the concurrent execution efficiency of the system is improved.
In one embodiment, the registration determination module 410 includes:
the information searching unit is used for searching whether the conflict transaction register table has blocking information waiting for the transaction target record or not in a traversing manner; if yes, determining that the registration condition is that the blocking information is registered; if not, determining that the registration condition is that the blocking information is not registered.
In one embodiment, the policy determination module 420 includes:
a first policy determining module, configured to determine that the execution policy is a waiting policy when the lockout information is registered, where the waiting policy includes: and setting a re-blocking transaction identification number in the transaction lock object, and re-blocking the waiting transaction according to the re-blocking transaction identification number.
A second policy determining module, configured to determine that the execution policy is a processing policy when the lockout information is not registered, where the processing policy includes: and registering the blocking information in the conflict transaction registration table, inquiring the updated record content by the waiting transaction, and executing data updating operation again.
In one embodiment, the first policy determination module includes:
a new transaction lock object determination module, configured to obtain a reclosure request of the waiting transaction, and create a new transaction lock object of the waiting transaction according to the reclosure request;
and the transaction relocking unit is used for performing locking again on the waiting transaction according to the new transaction lock object.
In one embodiment, said registering said blocking information in said conflict transaction registry comprises:
adding the table identification number of the blocking information to a modification table identification number array in the conflict transaction register table;
adding the row identification number of the blocking information to a row identification number array modified by the conflict transaction registered in the conflict transaction registration table;
adding the blocked transaction identification number of the blocking information to a blocked transaction identification number array of the conflict transaction registered in the conflict transaction registration table;
and adding 1 to the number of conflicts in the conflict transaction registry.
In one embodiment, the lockout information includes at least one of: a lockout transaction identification number, a lockout mode, a modification table identification number, a modification record row identification number, and a re-lockout transaction identification number.
In an embodiment, the database modification apparatus further includes:
an initialization module configured to initialize a conflict transaction registry, wherein the initializing the conflict transaction registry comprises: setting the number of conflicts in the conflict transaction registration table to be 0, and setting the table identification number array of conflict transaction modification, the row identification number array of conflict transaction modification and the blocked transaction identification number array of conflict transaction in the conflict transaction registration table to be null.
The database modification device provided by the embodiment of the invention can execute the database modification method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
In one embodiment, FIG. 5 illustrates a schematic diagram of an electronic device that may be used to implement embodiments of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 5, the electronic device 10 includes at least one processor 11, and a memory communicatively connected to the at least one processor 11, such as a Read Only Memory (ROM)12, a Random Access Memory (RAM)13, and the like, wherein the memory stores a computer program executable by the at least one processor, and the processor 11 can perform various suitable actions and processes according to the computer program stored in the Read Only Memory (ROM)12 or the computer program loaded from a storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data necessary for the operation of the electronic apparatus 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
A number of components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, or the like; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, or the like. The processor 11 performs the various methods and processes described above, such as the database modification method.
In some embodiments, the database modification method may be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the database modification method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the database modification method in any other suitable manner (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
A computer program for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be performed. A computer program can execute entirely on a machine, partly on a machine, as a stand-alone software package partly on a machine and partly on a remote machine or entirely on a remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service are overcome.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present invention may be executed in parallel, sequentially, or in different orders, and are not limited herein as long as the desired results of the technical solution of the present invention can be achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A database modification method, comprising:
when a transaction lock object of a target transaction is released and a waiting transaction is awakened, determining the registration condition of blocking information of a waiting transaction target record in a conflict transaction registration table;
determining an execution strategy of the waiting transaction according to the registration condition;
and controlling the waiting transaction to modify data according to the execution strategy.
2. The method of claim 1, wherein determining the registration of the blocking information awaiting the transaction target record in the conflicting transaction registry comprises:
traversing and searching whether the conflict transaction register table has blocking information waiting for the transaction target record;
if yes, determining that the registration condition is that the blocking information is registered;
if not, determining that the registration condition is that the blocking information is not registered.
3. The method of claim 1 or 2, wherein determining the execution policy of the pending transaction based on the registration condition comprises:
determining the execution policy as a waiting policy if the lockout information is registered, wherein the waiting policy includes: setting a re-blocking transaction identification number in a transaction lock object, and re-blocking the waiting transaction according to the re-blocking transaction identification number;
determining the execution policy as a processing policy if the lockout information is not registered, wherein the processing policy comprises: and registering the blocking information in the conflict transaction register table, inquiring the updated record content by the waiting transaction, and executing data updating operation again.
4. The method of claim 3, wherein said pending transaction is blocked again based on said unblock transaction identification number, comprising:
acquiring a reclosure request of the waiting transaction, and creating a new transaction lock object of the waiting transaction according to the reclosure request;
and the waiting transaction is blocked again according to the new transaction lock object.
5. The method of claim 3, wherein registering the blocking information in the conflict transaction registry comprises:
adding the table identification number of the blocking information to a modification table identification number array in the conflict transaction registration table;
adding the row identification number of the blocking information to a modified row identification number array in the conflict transaction registry;
adding the blocked transaction identification number of the blocking information to a blocked transaction identification number array in the conflict transaction register table;
and adding 1 to the number of conflicts in the conflict transaction registry.
6. The method according to claim 1, wherein said blocking information comprises at least one of: a lockout transaction identification number, a lockout mode, a modification table identification number, a modification record row identification number, and a re-lockout transaction identification number.
7. The method of claim 1, further comprising:
initializing a conflict transaction registry, wherein the initializing the conflict transaction registry comprises: setting the number of conflicts in the conflict transaction registration table to be 0, and setting the number groups of the modification table identification numbers, the number groups of the modification row identification numbers and the number groups of the blocking transaction identification numbers in the conflict transaction registration table to be null.
8. A database modification apparatus, comprising:
the system comprises a register determining module, a conflict transaction register table and a data processing module, wherein the register determining module is used for determining the register condition of blocking information of a target record of a waiting transaction in the conflict transaction register table when a transaction lock object of the target transaction is released and the waiting transaction is awakened;
the strategy determining module is used for determining the execution strategy of the waiting transaction according to the registration condition;
and the data modification module is used for controlling the waiting transaction to modify data according to the execution strategy.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the database modification method of any one of claims 1-7.
10. A computer-readable storage medium, having stored thereon computer instructions for causing a processor, when executed, to implement the database modification method of any one of claims 1-7.
CN202210347585.9A 2022-04-01 2022-04-01 Database modification method, device, equipment and medium Pending CN114676115A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210347585.9A CN114676115A (en) 2022-04-01 2022-04-01 Database modification method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210347585.9A CN114676115A (en) 2022-04-01 2022-04-01 Database modification method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN114676115A true CN114676115A (en) 2022-06-28

Family

ID=82076584

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210347585.9A Pending CN114676115A (en) 2022-04-01 2022-04-01 Database modification method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN114676115A (en)

Similar Documents

Publication Publication Date Title
EP3278239B1 (en) Processing database transactions in a distributed computing system
CN109923534B (en) Multi-version concurrency control for database records with uncommitted transactions
US9501502B2 (en) Locking protocol for partitioned and distributed tables
CN109933606B (en) Database modification method, device, equipment and storage medium
CN101350022B (en) Changing process method based on database logical lock
US10997158B2 (en) Techniques for updating big data tables using snapshot isolation
US20230315721A1 (en) Snapshot isolation query transactions in distributed systems
CN105786595A (en) Transaction control method achieving two-stage submitting
US20130055269A1 (en) Transaction concurrent execution control system, transaction concurrent execution control method and program
WO2022197462A1 (en) Snapshot isolation query transactions in distributed systems
CN115617908A (en) MySQL data synchronization method, device, database terminal, medium and system
CN112559496A (en) Distributed database transaction atomicity realization method and device
CN113051279A (en) Data message storage method, storage device, electronic equipment and storage medium
CN113886403A (en) Data management system and transaction processing method for high-competition e-commerce business
EP3063630B1 (en) Non-blocking registration in distributed transactions
CN114676115A (en) Database modification method, device, equipment and medium
CN114579260A (en) Transaction processing method and system
CN116204508A (en) Multi-version concurrency control method, device, equipment and storage medium
US11113262B2 (en) Time-efficient lock release in database systems
CN115757452A (en) Blocking method, device, equipment and storage medium
Abdul-Mehdi et al. A model for transaction management in mobile databases
JP2001134476A (en) Method for updating data base in a batch
CN117971846A (en) Data processing method, device, equipment and storage medium
CN118113759A (en) Transaction execution method of distributed database, electronic equipment and storage medium
CN116302371A (en) Transaction visibility judging method, device, equipment and storage medium

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