CN108363806A - Multi-version concurrency control method, device, server and the storage medium of database - Google Patents

Multi-version concurrency control method, device, server and the storage medium of database Download PDF

Info

Publication number
CN108363806A
CN108363806A CN201810171319.9A CN201810171319A CN108363806A CN 108363806 A CN108363806 A CN 108363806A CN 201810171319 A CN201810171319 A CN 201810171319A CN 108363806 A CN108363806 A CN 108363806A
Authority
CN
China
Prior art keywords
transaction
current
record
lock
data page
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.)
Granted
Application number
CN201810171319.9A
Other languages
Chinese (zh)
Other versions
CN108363806B (en
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 CN201810171319.9A priority Critical patent/CN108363806B/en
Publication of CN108363806A publication Critical patent/CN108363806A/en
Application granted granted Critical
Publication of CN108363806B publication Critical patent/CN108363806B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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
    • G06F16/2315Optimistic concurrency control
    • G06F16/2329Optimistic concurrency control using versioning

Landscapes

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

Abstract

The present invention discloses a kind of multi-version concurrency control method of database, device, server and storage medium, this method:When Current transaction starts, the transaction number of the Current transaction is blocked by exclusive lock mode;If the current operation of the Current transaction is write operation, affairs savepoint is generated;Target data page corresponding with the write operation is searched, and locks the target data page in a manner of exclusive lock;The current operation is executed according to default rule.Pass through this lock-out facility so that the record quantity that the quantity of lock is changed with affairs can be significantly reduced lock quantity without direct relation, reduce lock conflict and block resource consumption, improve the concurrent efficiency of data base management system.

Description

Multi-version concurrency control method, device, server and the storage medium of database
Technical field
The present invention relates to database technical field more particularly to a kind of multi-version concurrency control method of database, device, Server and storage medium.
Background technology
Multi version concurrency control (Multi-Version Concurrency Control, MVCC) can ensure data one Under the premise of cause property, the read and write access performance of high concurrent is provided, is a kind of important technical for promoting database concurrency performance. Current each mainstream data library management system all realizes MVCC mechanism substantially, but the MVCC realization mechanisms of each product exist obviously Difference.For example, PostgreSQL and SQL Server, which are based on physical record, realizes MVCC, multiple versions are directly preserved in systems Physical record;And Oracle, InnoDB and be based on rollback record up to dream database (DM7) and realize MVCC, system only preserves most The physical record of new version records the historical information for preserving data using rollback.
It is recorded based on rollback and realizes that the basic ideas of MVCC are:Judge whether current record meets consistency when reading record Whether conditions dictate, that is, usually said data are returned as it can be seen that if current record is invisible using previous version is directed toward The pointer of rolling record recalls historical data, and the ultimately constructed consistency that meets reads desired data.Oracle is by modification record Transaction number, affairs submit the SCN (System Change Number) generated and rollback recording address to be stored in data page head ITL (Interest Transaction List) in, for judging record visibility and the visible colophon of construction. The transaction number of modification record and rollback recording address are stored in (DM7 in the two systems field of record by InnoDB and DM7 respectively The two fields are respectively defined as TID (Transaction Identity) and UPA (Undo Page Address), inside A global active transaction chained list is maintained in depositing, and an active transaction view is maintained in transaction structure.
MVCC eliminates data reading and writing conflict, and read operation will not block write operation, and write operation will not block read operation. While one user changes a line record, other users still can correctly read effective edition data of this line record. But it is concurrent write, write operation, still can cause conflict, row grade lock be commonly used to solution write, write conflict.In traditional concept, one Before a affairs TrxA modifications data line, need that exclusive row grade is locked (X locks) in the row data one, if another thing Business TrxB has first blocked this row data, then the system of blocking can block Current transaction TrxA, until TrxB discharges this row grade Lock.Using this row grade locking methods, data line is often changed, is required for generating one row grade lock, if an affairs modification A large amount of records will accordingly generate a large amount of row grade lock.These locks can consume a large amount of memory source, and with lock object Increase, safeguards that the HASH tables collision probability of these locks can also increase therewith, and then influence the concurrency performance of system.The row of InnoDB Whether grade block uses above-mentioned basic ideas, according to the SQL statement type of execution, Transaction service and can utilize The factors such as index, using different locking methods.
In order to reduce the resource consumption of lock object, each database product all takes series of optimum means, such as InnoDB using a position (BIT) come indicate a line on some specific data page record, relative to directly use line identifier (ROWID) it is indicated, the resource of lock object consumption can be greatly decreased.But over all, the block expense and thing of affairs The record number positive correlation of business modification, cannot really reduce the resource consumption of lock object.
Invention content
The present invention provides a kind of multi-version concurrency control method of database, device, server and storage medium, reduces lock Quantity, reduce lock conflict and block resource consumption, improve the concurrent efficiency of data base management system.
In a first aspect, an embodiment of the present invention provides a kind of multi-version concurrency control methods of database, including:
When Current transaction starts, the transaction number of the Current transaction is blocked by exclusive lock mode;
If the current operation of the Current transaction is write operation, affairs savepoint is generated;
Target data page corresponding with the write operation is searched, and locks the target data page in a manner of exclusive lock;
The current operation is executed according to default rule.
Further, after being blocked to the transaction number of the Current transaction by exclusive lock mode, further include:
If the transaction isolation grade of the Current transaction is serialization or repeatable read, collection activity transaction view and divide The maximum transaction number matched;
If the transaction isolation grade of the Current transaction is to read to submit, after generating affairs savepoint, the work is collected Dynamic transaction view and the allocated maximum transaction number.
Further, described that the current operation, packet are executed according to default rule if the current operation is to be inserted into It includes:
Be inserted into the target data page and be inserted into data, by the write-in of the transaction number of the Current transaction with it is described to be inserted Enter the TID field of the corresponding record of data, and discharges the lock of the target data page.
Further, described that the current behaviour is executed according to default rule if the current operation is to delete or update Make, including:
Read the transaction number in the TID field of record to be operated in the target data page;
Sentenced according to transaction number, the active transaction view and the allocated maximum transaction number in the TID field Visibility of the disconnected record to be operated to the Current transaction;
The current operation is executed to the visibility of the Current transaction according to the record to be operated.
Further, described that the current behaviour is executed to the visibility of the Current transaction according to the record to be operated Make, including:
If the record to be operated to the Current transaction as it can be seen that delete or update the data in the target data page, The transaction number of the Current transaction is written to the TID field of the record to be operated, and discharges the lock of the target data page;
If the record to be operated is invisible to the Current transaction, the lock of the target data page is discharged, and to institute The transaction number stated in TID field is blocked in a manner of exclusive lock, when the corresponding affairs of transaction number in the TID field are submitted Or when rollback, the transaction number in the TID field is blocked successfully, re-executes and searches target data page, lock onto target data The step of page and judgement record visibility;If it is described it is to be operated record to the Current transaction as it can be seen that if execute the current behaviour Make, discharges the lock of the target data page;If the record to be operated is invisible to the Current transaction, according to described current The transaction isolation grade of affairs executes corresponding operation.
Further, described that corresponding operation is executed according to the transaction isolation grade of the Current transaction, including:
If the transaction isolation grade of the Current transaction is to read to submit, the Current transaction is rolled back into the affairs and is preserved Point;
If the transaction isolation grade of the Current transaction is serialization or repeatable read, it is determined that the current operation failure, And export error information.
Further, after having executed all operations of the Current transaction, the transaction number of the Current transaction is discharged Lock.
Second aspect, the embodiment of the present invention additionally provide a kind of Multi version concurrency control device of database, the device packet It includes:
Transaction number lockout module is used for when Current transaction starts, by exclusive lock mode to the thing of the Current transaction Business number is blocked;
Savepoint generation module generates affairs savepoint if the current operation for the Current transaction is write operation;
Data page locking module for searching target data page corresponding with the write operation, and is locked in a manner of exclusive lock The fixed target data page;
Operation executing module, for executing the current operation according to default rule.
The third aspect, the embodiment of the present invention additionally provide a kind of server, and the server includes:
One or more processors;
Storage device, for storing one or more programs;
When one or more of programs are executed by one or more of processors so that one or more of processing Device realizes the multi-version concurrency control method of the database as described in any embodiment of the present invention.
Fourth aspect, the embodiment of the present invention additionally provide a kind of a kind of computer readable storage medium of server, deposit thereon Computer program is contained, more editions that the database as described in any embodiment of the present invention is realized when which is executed by processor This concurrency control method.
The present invention provides a kind of multi-version concurrency control method of database, when Current transaction starts, passes through exclusive lock Mode blocks the transaction number of the Current transaction, prevents other affairs from being blocked again to Current transaction and changes number According to.If the current operation of the Current transaction is write operation, affairs savepoint is generated, so as in the processing procedure of affairs, It can be by rolling back to certain part operation of some affairs savepoint revocation to database;Search mesh corresponding with the write operation Data page is marked, and locks the target data page in a manner of exclusive lock, it can be ensured that in data modification operation, other affairs are not It can modify to same data;The behaviour of the affairs is executed after block Current transaction number and target data page according to default rule Make.Pass through this lock-out facility so that the record quantity that the quantity of lock is changed with affairs can be significantly reduced without direct relation Quantity and block resource consumption are locked, the concurrent efficiency of data base management system is improved.
Description of the drawings
Fig. 1 is a kind of flow chart of the multi-version concurrency control method of database in the embodiment of the present invention one.
Fig. 2 is a kind of flow chart of the multi-version concurrency control method of database in the embodiment of the present invention two.
Fig. 3 is the flow chart of the multi-version concurrency control method of another database in the embodiment of the present invention two.
Fig. 4 is a kind of structural schematic diagram of the Multi version concurrency control device of database in the embodiment of the present invention three.
Fig. 5 is a kind of structural schematic diagram of server in the embodiment of the present invention four.
Specific implementation mode
The present invention is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched The specific embodiment stated is used only for explaining the present invention rather than limitation of the invention.It also should be noted that in order to just Only the parts related to the present invention are shown in description, attached drawing rather than entire infrastructure.
Embodiment one
Fig. 1 is a kind of flow chart of the multi-version concurrency control method for database that the embodiment of the present invention one provides, this reality The case where example is applicable to the Multi version concurrency control of database is applied, this method can be filled by the Multi version concurrency control of database It sets to execute, specifically comprises the following steps:
S110, when Current transaction starts, the transaction number of the Current transaction is blocked by exclusive lock mode.
Wherein, affairs refer to accessing and may updating the data a program execution unit of various data item in library (unit).If affairs encounter mistake and are cancelled or rollback, all SQL statements operation of affairs can be all eliminated, data Library is restored to the state before affairs execute.Exclusive lock, also referred to as exclusive lock (Exclusive Locks, abbreviation X lock) write lock, are A kind of basic lock type only allows T to read and change M, other any affairs if affairs T locks data object M plus X All cannot any kind of lock be added to M again, the lock on T releases M.This guarantees other affairs T release M on lock it Before cannot read and change again M.System can increase the incremental TID counters of an overall situation, can be with when each affairs start Obtain a unique ID.It is block object with transaction number TID_A when affairs A starts, creates one and exclusive TID is locked, and Hold affairs to terminate.Since transaction number has globally unique characteristic, TID locks when affairs start not will produce conflict, agree Surely success can be blocked.Affairs are always maintained at this TID and lock, and are discharged when affairs submission or rollback.
If the current operation of S120, the Current transaction is write operation, affairs savepoint is generated.
Wherein, write operation includes:It is inserted into (INSERT), deletes (DELETE) or update (UPDATE) etc..Affairs savepoint It is a logical point in business process, we, without the entire affairs that retract, can be to make to answer transaction rollback to this point With program can encounter it is secondary mistake when rollback partial transaction label.
S130, target data page corresponding with the write operation is searched, and locks the target data in a manner of exclusive lock Page.
Wherein, exclusive latch (LATCH) may be used to the locking of target data page, latch is that a kind of lightweight is other Lock is the concurrent control mechanism that data store internal is used for data access to web page.Wherein, latch obtain and release speed quickly.Show Example property finds the data page for being inserted into record if current operation is to be inserted into, i.e., after target data page, with exclusive Latch mode lock onto target data page, can prevent this data page of other transactions access.
S140, the current operation is executed according to default rule.
Wherein, default rule refers to the strategy how preset current operation executes, illustratively, can basis The visibility principle of affairs and different transaction isolation grades are default corresponding with executing insertion, deleting and updating operation accordingly Strategy, to realize the database mechanisms of high concurrent efficiency and low consumption of resources.
Optionally, after having executed all operations of the Current transaction, the lock of the transaction number of the Current transaction is discharged, Can reduce occupancy to system resource after release lock, the operating efficiency of other affairs can also be accelerated, realize high concurrent efficiency, The database row grade lock-out facility of low consumption of resources.
The present invention is by providing a kind of multi-version concurrency control method of database, when Current transaction starts, by only It accounts for lock mode to block the transaction number of the Current transaction, prevents other affairs from Current transaction is blocked and being changed again Data.If the current operation of the Current transaction is write operation, affairs savepoint is generated, so as in the processing procedure of affairs In, it can be by rolling back to certain part operation of some affairs savepoint revocation to database;It searches corresponding with the write operation Target data page, and the target data page is locked in a manner of exclusive lock, it can be ensured that in data modification operation, other things Business cannot modify to same data;The current operation is executed according to default rule, described in operation after the completion release The lock of the transaction number of Current transaction.Pass through this lock-out facility so that the record quantity that the quantity of lock is changed with affairs is without direct Relationship, only when there is update inconsistency just need carry out explicitly block (i.e. Current transaction number to the transaction number in TID field into Row block), it can be significantly reduced capable grade lock quantity, lock conflict and block resource consumption is reduced, improve data base administration system The concurrent efficiency of system.
Embodiment two
Fig. 2 is a kind of flow chart of the multi-version concurrency control method of database provided by Embodiment 2 of the present invention, this reality It is to execute institute according to default rule in the case of being inserted into apply example and provide current operation on the basis of the various embodiments described above The embodiment of current operation is stated, as shown in Fig. 2, this method specifically includes:
S210, when Current transaction starts, the transaction number of the Current transaction is blocked by exclusive lock mode.
If the current operation of S220, the Current transaction is write operation, affairs savepoint is generated.
S230, target data page corresponding with the write operation (insertion) is searched, and locks the mesh in a manner of exclusive lock Mark data page.
S240, insertion is inserted into data in the target data page, the transaction number write-in by the Current transaction and institute The TID field for being inserted into the corresponding record of data is stated, and discharges the lock of the target data page.
Wherein, when carrying out insertion operation, corresponding data are inserted into the target data page of locking, by Current transaction Transaction number write-in is corresponding to be inserted into the TID field of record, after the lock for discharging the target data page.It is accessed every time in affairs And when changing the record, affairs can read the TRX_ID in the upper TID field of record, and be judged according to the visibility principle of record The record further carries out current operation to the visibility of Current transaction, realizes the Multi version concurrency control of data.
Fig. 3 is the flow chart of the multi-version concurrency control method of another database provided by Embodiment 2 of the present invention, can Choosing, on the basis of the various embodiments described above, it is in the case of deleting or being newer, according to default rule to provide current operation The embodiment of the current operation is executed, as shown in figure 3, this method specifically includes:
S310, when Current transaction starts, the transaction number of the Current transaction is blocked by exclusive lock mode.
If the current operation of S320, the Current transaction is write operation, affairs savepoint is generated.
It optionally, can be according to the transaction isolation grade of Current transaction, collection activity transaction view and allocated most major issue Business number, for when executing deletion or update operation, judging visibility of the record to be operated to the Current transaction.Wherein, living Dynamic transaction view includes active transaction and its corresponding transaction number TID, and allocated maximum transaction number refers in current collection At the time of transaction number, system has been the maximum transaction number that affairs are assigned to.
If specifically, the transaction isolation grade of the Current transaction is serialization or repeatable read, passing through exclusive lock side After formula blocks the transaction number of the Current transaction, collection activity transaction view and allocated maximum transaction number;If The transaction isolation grade of the Current transaction is to read to submit, then after generating affairs savepoint, collects the active transaction view With the allocated maximum transaction number.
S330, target data page corresponding with the write operation (delete or update) is searched, and is locked in a manner of exclusive lock The target data page.
S340, the transaction number in the TID field of record to be operated in the target data page is read;According to the TID words Transaction number, the active transaction view and the allocated maximum transaction number in section judge the record to be operated to described The visibility of Current transaction.
Wherein, current operation is when deleting or updating, to read the transaction number in the TID field of record to be operated, Ke Yishi TRX_ID, the affairs which modifies recently to coping with the record to be operated.That is user accesses a record When, the transaction number in the TID field of the record is first read, further according to the transaction number in this TID field whether in the work being collected into In dynamic transaction view and whether judge the record to Current transaction whether as it can be seen that just may be used more than allocated maximum transaction number Further to execute current operation.
S350, the current operation is executed to the visibility of the Current transaction according to the record to be operated.
Optionally, the transaction number according in the TID field, the active transaction view and it is described it is allocated most Big transaction number judges visibility of the record to be operated to the Current transaction, including:
If meeting one of following situations, it is determined that the record to be operated is invisible to the Current transaction:
Transaction number in the TID field is one of in the active transaction view;
Transaction number in the TID field is more than the allocated maximum transaction number.
I.e. when the transaction number TRX_ID in TID field is less than allocated maximum transaction number and not in active transaction view When, it can be determined that record to be operated is visible Current transaction, remaining situation is invisible.It can't see due to affairs and do not carry Hand over any modification of the affairs to same record, so, if same record to Current transaction as it can be seen that if illustrate to change this record Other affairs certainly it is submitted.When being judged as visible, it may be determined that the affairs for changing this record to be operated recently exist Current transaction is submitted before starting, therefore the record is visible.If the record to Current transaction as it can be seen that if illustrate to change The affairs of this record are submitted, this record can be changed by Current transaction.If record is invisible to Current transaction, Illustrate that other affairs are concurrently changing this record, Current transaction cannot modify to the record.
Optionally, in S350, if it is described it is to be operated record to the Current transaction as it can be seen that being deleted in the target data page It removes or updates the data, the transaction number of the Current transaction is written to the TID field of the record to be operated, and discharge the target The lock of data page.I.e. if as it can be seen that if can directly be deleted or be updated operation, and in the TID words of corresponding modification record The transaction number of Current transaction is written in section, before the lock that Current transaction discharges target data page, other affairs are cannot be right This record is modified.
Optionally, in S350, if the record to be operated is invisible to the Current transaction, the target data is discharged The lock of page, and the transaction number in the TID field is blocked in a manner of exclusive lock, the transaction number in the TID field When corresponding affairs submission or rollback, the transaction number in the TID field is blocked successfully, lookup target data is re-executed The step of page, lock onto target data page and judgement record visibility;If it is described it is to be operated record to the Current transaction as it can be seen that if The current operation is executed, the lock of the target data page is discharged;If the record to be operated is invisible to the Current transaction, Corresponding operation is then executed according to the transaction isolation grade of the Current transaction.
It is i.e. if invisible, illustrate that Current transaction cannot directly execute current update or delete operation, Ke Yi at this time After release is to the lock of target data page, the transaction number in TID field is blocked using exclusive lock.Due in TID field Transaction number an exclusive lock, therefore lock conflict are generated when affairs start, the block of Current transaction can be blocked, at this time Block can be waited for.When the corresponding affairs of transaction number in TID field are submitted or after rollback, block just can be at Work(, will wake up Current transaction at this time can continue current operation.It re-executes and searches target data page, lock onto target number The step of according to page and judging record visibility (i.e. S330 and S340) is said if it is determined that when record is visible to the Current transaction The rollback of the affairs of this bright modification record can continue to execute deletion or update operation.
If it is determined that when record is still invisible to the Current transaction, the lock of the target data page is discharged, and according to The transaction isolation grade of the Current transaction executes corresponding operation, specifically includes:
If the transaction isolation grade of the Current transaction is to read to submit, the Current transaction is rolled back into the affairs and is preserved Point;
If the transaction isolation grade of the Current transaction is serialization or repeatable read, it is determined that the current operation failure, And export error information.
Wherein, the corresponding affairs of transaction number are submitted in TID field, but record to be operated still can not to Current transaction See, according to the definition for reading submission transaction isolation grade, the affairs savepoint can be rolled back to, the active transaction is collected again and regard Figure and the allocated maximum transaction number re-execute deletion according to S330 to S350 or update operate.
The technical solution of the present embodiment provides a kind of multi-version concurrency control method of database, by being executed in affairs When insertion, update or delete operation, transaction number is written to the TID field of record to be operated, it is primary hidden to treat operation note progress The block of formula.After starting due to affairs, transaction number remains constant, no matter this affairs has modified how many row records, this TID field value on a little records is all identical.Using the TID field and database door bolt on record, a kind of high concurrent effect is realized Rate, low consumption of resources database row grade lock-out facility, solve the problems, such as to write, write concurrency conflict.In the feelings for not generating update inconsistency Under condition, row grade lock is thoroughly eliminated, no matter an affairs have modified how many row records, not will produce capable grade lock object.Multiple Transaction concurrency modification is recorded with a line, in the case of generating update inconsistency, reads the TID field of record, is carried out to the TID read Block blocks transaction number by being converted into for the block of record row.Using this lock-out facility, the quantity and affairs of lock The record quantity of modification just needs explicitly to be blocked without direct relation, only when there is update inconsistency, can greatly subtract Quantity is locked less, is reduced lock conflict and block resource consumption, is improved the concurrent efficiency of data base management system.
Embodiment three
Fig. 4 show a kind of structural representation of the Multi version concurrency control device of database of the offer of the embodiment of the present invention three The case where figure, the present embodiment is applicable to the Multi version concurrency control of database, as shown in figure 4, the multi version of the database is simultaneously Control device is sent out, including:
Transaction number lockout module 410 is used for when Current transaction starts, by exclusive lock mode to the Current transaction Transaction number is blocked;
Savepoint generation module 420 generates affairs preservation if the current operation for the Current transaction is write operation Point;
Data page locking module 430, for searching target data page corresponding with the write operation, and in a manner of exclusive lock Lock the target data page;
Operation executing module 440, for executing the current operation according to default rule.
Optionally, which further includes:
First affairs collection module, for carrying out blocking it to the transaction number of the Current transaction by exclusive lock mode Afterwards, if the transaction isolation grade of the Current transaction is serialization or repeatable read, collection activity transaction view and allocated Maximum transaction number;
Second affairs collection module is generating affairs if the transaction isolation grade for the Current transaction is to read to submit After savepoint, the active transaction view and the allocated maximum transaction number are collected.
Optionally, the operation executing module 440 includes:
Transaction number reading unit reads in the target data page and waits for if being to delete or update for the current operation Transaction number in the TID field of operation note;
Visibility judge unit, for according in the TID field transaction number, the active transaction view and it is described The maximum transaction number of distribution judges visibility of the record to be operated to the Current transaction;
First operation execution unit, described in the visibility execution according to the record to be operated to the Current transaction Current operation.
Optionally, first operation execution unit includes:
First operation executes subelement, if for the record to be operated to the Current transaction as it can be seen that in the target It deletes or updates the data in data page, the transaction number of the Current transaction is written to the TID field of the record to be operated, and release Put the lock of the target data page;
Second operation executes subelement, if invisible to the Current transaction for the record to be operated, discharges institute The lock of target data page is stated, and the transaction number in the TID field is blocked in a manner of exclusive lock, when the TID field In the corresponding affairs of transaction number submit or when rollback, the transaction number in the TID field blocked successfully, lookup is re-executed The step of target data page, lock onto target data page and judgement record visibility;If the record to be operated is to the current thing Business discharges the lock of the target data page as it can be seen that then execute the current operation;If the record to be operated is still worked as to described Preceding affairs are invisible, then execute corresponding operation according to the transaction isolation grade of the Current transaction.
Optionally, the second operation executes subelement and is specifically used for:In the record to be operated still to the Current transaction In the case of sightless, if the transaction isolation grade of the Current transaction is to read to submit, the Current transaction is rolled back to described Affairs savepoint;If the transaction isolation grade of the Current transaction is serialization or repeatable read, it is determined that the current operation loses It loses, and exports error information.
Optionally, operation executing module 440 includes:
Second operation execution unit is inserted into be inserted if being to be inserted into for the current operation in the target data page Enter data, the write-in of the transaction number of the Current transaction is inserted into the TID field of the corresponding record of data with described, and discharge institute State the lock of target data page.
Optionally, which further includes:Release module is locked, is used for after having executed all operations of the Current transaction, Discharge the lock of the transaction number of the Current transaction.
Above-mentioned apparatus can perform the multi-version concurrency control method for the database that any embodiment of the present invention is provided, and have Execute the corresponding function module of multi-version concurrency control method and advantageous effect of the database.
It is worth noting that, in the embodiment of the Multi version concurrency control device of above-mentioned database, included each mould Block is only divided according to function logic, but is not limited to above-mentioned division, as long as corresponding function can be realized i.e. It can;In addition, the specific name of each functional unit is also only to facilitate mutually distinguish, the protection model being not intended to restrict the invention It encloses.
Example IV
The embodiment of the present invention provides a kind of server, which includes:One or more processors;Storage device is used In the one or more programs of storage, when one or more of programs are executed by one or more of processors so that described One or more processors realize the multi-version concurrency control method of the database described in any embodiment of the present invention.
Fig. 5 is the structural schematic diagram for the server that the embodiment of the present invention four provides, and referring to Fig. 5, which includes processing Device 510 and memory 520;The quantity of processor 510 can be one or more in server, with a processor 510 in Fig. 5 For;Processor 510 in server can be connected with memory 520 by bus or other modes, to pass through bus in Fig. 5 For connection.
Memory 520 is used as a kind of computer readable storage medium, can be used for storing software program, computer can perform journey Sequence and module, such as the corresponding program instruction of the multi-version concurrency control method of the database in the embodiment of the present invention/module (example Such as, the transaction number lockout module 410 in the Multi version concurrency control device of database, savepoint generation module 420, data page lock Cover half block 430 and operation executing module 440).Processor 510 is by running the software program being stored in memory 520, instruction And module, the various function application to execute server and data processing, that is, realize the multi version of above-mentioned database Concurrency control method.
Memory 520 can include mainly storing program area and storage data field, wherein storing program area can store operation system Application program needed for system, at least one function;Storage data field can be stored uses created data etc. according to terminal.This Outside, memory 520 may include high-speed random access memory, can also include nonvolatile memory, for example, at least one Disk memory, flush memory device or other non-volatile solid state memory parts.In some instances, memory 520 can be into one Step includes the memory remotely located relative to processor 510, these remote memories can pass through network connection to server. The example of above-mentioned network includes but not limited to internet, intranet, LAN, mobile radio communication and combinations thereof.
Server provided in an embodiment of the present invention can not only execute and realize the data that any embodiment of the present invention provides The multi-version concurrency control method in library can also execute other programs or method according to business specific requirement.
Embodiment five
The present embodiment provides a kind of computer readable storage mediums, are stored thereon with computer program, which is handled The multi-version concurrency control method of the database described in any embodiment of the present invention is realized when device executes.
The computer program of computer-readable recording medium storage provided in this embodiment, it is real when in addition to being executed by processor The multi-version concurrency control method of database described in existing any embodiment of the present invention can also include other programs, with reality Now specific business demand.
By the description above with respect to embodiment, it is apparent to those skilled in the art that, the present invention It can be realized by software and required common hardware, naturally it is also possible to which by hardware realization, but the former is more in many cases Good embodiment.Based on this understanding, technical scheme of the present invention substantially in other words contributes to the prior art Part can be expressed in the form of software products, which can be stored in computer readable storage medium In, such as the floppy disk of computer, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), flash memory (FLASH), hard disk or CD etc., including some instructions are with so that a computer is set Standby (can be personal computer, server or the network equipment etc.) executes the method described in each embodiment of the present invention.
Note that above are only presently preferred embodiments of the present invention and institute's application technology principle.It will be appreciated by those skilled in the art that The present invention is not limited to specific embodiments described here, can carry out for a person skilled in the art it is various it is apparent variation, It readjusts and substitutes without departing from protection scope of the present invention.Therefore, although being carried out to the present invention by above example It is described in further detail, but the present invention is not limited only to above example, without departing from the inventive concept, also May include other more equivalent embodiments, and the scope of the present invention is determined by scope of the appended claims.

Claims (10)

1. a kind of multi-version concurrency control method of database, which is characterized in that including:
When Current transaction starts, the transaction number of the Current transaction is blocked by exclusive lock mode;
If the current operation of the Current transaction is write operation, affairs savepoint is generated;
Target data page corresponding with the write operation is searched, and locks the target data page in a manner of exclusive lock;
The current operation is executed according to default rule.
2. according to the method described in claim 1, it is characterized in that, in the affairs by exclusive lock mode to the Current transaction After number being blocked, further include:
If the transaction isolation grade of the Current transaction is serialization or repeatable read, collection activity transaction view and allocated Maximum transaction number;
If the transaction isolation grade of the Current transaction is to read to submit, after generating affairs savepoint, the activity thing is collected Business view and the allocated maximum transaction number.
If 3. according to the method described in claim 1, it is characterized in that, the current operation be inserted into, it is described according to preset Rule executes the current operation, including:
It is inserted into the target data page and is inserted into data, the transaction number write-in of the Current transaction is inserted into number with described According to the TID field of corresponding record, and discharge the lock of the target data page.
4. if according to the method described in claim 2, it is characterized in that, the current operation is to delete or update, the basis Default rule executes the current operation, including:
Read the transaction number in the TID field of record to be operated in the target data page;
Judge institute according to transaction number, the active transaction view and the allocated maximum transaction number in the TID field State visibility of the record to be operated to the Current transaction;
The current operation is executed to the visibility of the Current transaction according to the record to be operated.
5. according to the method described in claim 4, it is characterized in that, it is described according to it is described it is to be operated record to the Current transaction Visibility execute the current operation, including:
If the record to be operated is to the Current transaction as it can be seen that deleting or updating the data in the target data page, by institute The TID field of the record to be operated is written in the transaction number for stating Current transaction, and discharges the lock of the target data page;
If the record to be operated is invisible to the Current transaction, the lock of the target data page is discharged, and to the TID Transaction number in field is blocked in a manner of exclusive lock, when the corresponding affairs of transaction number in the TID field are submitted or returned When rolling, the transaction number in the TID field is blocked successfully, re-execute search target data page, lock onto target data page and The step of judging record visibility;If it is described it is to be operated record to the Current transaction as it can be seen that if execute the current operation, release Put the lock of the target data page;If the record to be operated is invisible to the Current transaction, according to the Current transaction Transaction isolation grade execute corresponding operation.
6. according to the method described in claim 5, it is characterized in that, described execute according to the transaction isolation grade of the Current transaction Corresponding operation, including:
If the transaction isolation grade of the Current transaction is to read to submit, the Current transaction is rolled back into the affairs savepoint;
If the transaction isolation grade of the Current transaction is serialization or repeatable read, it is determined that the current operation failure, and it is defeated Go out error information.
7. according to the method described in claim 1, it is characterized in that, further including:In all behaviour for having executed the Current transaction After work, the lock of the transaction number of the Current transaction is discharged.
8. a kind of Multi version concurrency control device of database, which is characterized in that including:
Transaction number lockout module is used for when Current transaction starts, by exclusive lock mode to the transaction number of the Current transaction It is blocked;
Savepoint generation module generates affairs savepoint if the current operation for the Current transaction is write operation;
Data page locking module for searching target data page corresponding with the write operation, and locks institute in a manner of exclusive lock State target data page;
Operation executing module, for executing the current operation according to default rule.
9. a kind of server, which is characterized in that the server includes:
One or more processors;
Storage device, for storing one or more programs;
When one or more of programs are executed by one or more of processors so that one or more of processors are real The now multi-version concurrency control method of the database as described in any in claim 1-7.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the program is by processor The multi-version concurrency control method of the database as described in any in claim 1-7 is realized when execution.
CN201810171319.9A 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium Active CN108363806B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810171319.9A CN108363806B (en) 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810171319.9A CN108363806B (en) 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium

Publications (2)

Publication Number Publication Date
CN108363806A true CN108363806A (en) 2018-08-03
CN108363806B CN108363806B (en) 2020-07-31

Family

ID=63003078

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810171319.9A Active CN108363806B (en) 2018-03-01 2018-03-01 Multi-version concurrency control method and device for database, server and storage medium

Country Status (1)

Country Link
CN (1) CN108363806B (en)

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109376026A (en) * 2018-09-14 2019-02-22 上海新炬网络信息技术股份有限公司 A kind of data synchronization check implementation method based on script
CN109710629A (en) * 2019-01-08 2019-05-03 上海达梦数据库有限公司 Data access method, device, server and storage medium
CN109933606A (en) * 2019-03-19 2019-06-25 上海达梦数据库有限公司 A kind of database update method, apparatus, equipment and storage medium
CN109976672A (en) * 2019-03-22 2019-07-05 深信服科技股份有限公司 A kind of read/write conflict optimization method, device, electronic equipment and readable storage medium storing program for executing
CN110825752A (en) * 2019-10-16 2020-02-21 深圳巨杉数据库软件有限公司 Database multi-version concurrency control system based on fragment-free recovery
CN110990377A (en) * 2019-11-21 2020-04-10 上海达梦数据库有限公司 Data loading method and device, server and storage medium
CN111090663A (en) * 2019-12-25 2020-05-01 上海金仕达软件科技有限公司 Transaction concurrency control method, device, terminal equipment and medium
WO2020098682A1 (en) * 2018-11-15 2020-05-22 Huawei Technologies Co., Ltd. Systems and methods for managing shared database
CN111240810A (en) * 2020-01-20 2020-06-05 上海达梦数据库有限公司 Transaction management method, device, equipment and storage medium
CN111259071A (en) * 2020-01-04 2020-06-09 浙江科技学院 Concurrent access control method in distributed database system
CN112883045A (en) * 2021-03-31 2021-06-01 中国工商银行股份有限公司 Database transaction splitting execution method and device
CN113746682A (en) * 2021-09-07 2021-12-03 迈普通信技术股份有限公司 Configuration guarantee method and device
CN115543970A (en) * 2022-11-29 2022-12-30 本原数据(北京)信息技术有限公司 Data page processing method, data page processing device, electronic equipment and storage medium
CN116383209A (en) * 2023-03-30 2023-07-04 深圳计算科学研究院 Concurrency control method and concurrency control device for column-store database
WO2023124421A1 (en) * 2021-12-31 2023-07-06 深圳市兆珑科技有限公司 Transaction concurrency control method and apparatus, electronic device and readable storage medium
US11755558B2 (en) 2021-06-25 2023-09-12 Microsoft Technology Licensing, Llc Transaction identifier locking with data row locks

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101364230A (en) * 2008-09-24 2009-02-11 金蝶软件(中国)有限公司 Concurrent access control method and device
CN101763390A (en) * 2008-12-24 2010-06-30 北京大学深圳研究生院 Database storing system and method based on Berkeley DB
WO2014026611A1 (en) * 2012-08-14 2014-02-20 Huawei Technologies Co., Ltd. Rollback method and apparatus of transaction, relational database management system
CN104793988A (en) * 2014-01-20 2015-07-22 阿里巴巴集团控股有限公司 Cross-database distributed transaction implementation method and device
US20170220619A1 (en) * 2015-03-13 2017-08-03 Huawei Technologies Co., Ltd. Concurrency Control Method and Apparatus

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101364230A (en) * 2008-09-24 2009-02-11 金蝶软件(中国)有限公司 Concurrent access control method and device
CN101763390A (en) * 2008-12-24 2010-06-30 北京大学深圳研究生院 Database storing system and method based on Berkeley DB
WO2014026611A1 (en) * 2012-08-14 2014-02-20 Huawei Technologies Co., Ltd. Rollback method and apparatus of transaction, relational database management system
CN104793988A (en) * 2014-01-20 2015-07-22 阿里巴巴集团控股有限公司 Cross-database distributed transaction implementation method and device
US20170220619A1 (en) * 2015-03-13 2017-08-03 Huawei Technologies Co., Ltd. Concurrency Control Method and Apparatus

Cited By (26)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109376026A (en) * 2018-09-14 2019-02-22 上海新炬网络信息技术股份有限公司 A kind of data synchronization check implementation method based on script
WO2020098682A1 (en) * 2018-11-15 2020-05-22 Huawei Technologies Co., Ltd. Systems and methods for managing shared database
US11640383B2 (en) 2018-11-15 2023-05-02 Huawei Technologies Co., Ltd. Systems and methods for managing a shared database
CN109710629A (en) * 2019-01-08 2019-05-03 上海达梦数据库有限公司 Data access method, device, server and storage medium
CN109710629B (en) * 2019-01-08 2020-12-18 上海达梦数据库有限公司 Data access method, device, server and storage medium
CN109933606A (en) * 2019-03-19 2019-06-25 上海达梦数据库有限公司 A kind of database update method, apparatus, equipment and storage medium
CN109933606B (en) * 2019-03-19 2021-04-27 上海达梦数据库有限公司 Database modification method, device, equipment and storage medium
CN109976672B (en) * 2019-03-22 2022-02-22 深信服科技股份有限公司 Read-write conflict optimization method and device, electronic equipment and readable storage medium
CN109976672A (en) * 2019-03-22 2019-07-05 深信服科技股份有限公司 A kind of read/write conflict optimization method, device, electronic equipment and readable storage medium storing program for executing
CN110825752A (en) * 2019-10-16 2020-02-21 深圳巨杉数据库软件有限公司 Database multi-version concurrency control system based on fragment-free recovery
CN110990377A (en) * 2019-11-21 2020-04-10 上海达梦数据库有限公司 Data loading method and device, server and storage medium
CN110990377B (en) * 2019-11-21 2023-08-22 上海达梦数据库有限公司 Data loading method, device, server and storage medium
CN111090663A (en) * 2019-12-25 2020-05-01 上海金仕达软件科技有限公司 Transaction concurrency control method, device, terminal equipment and medium
CN111090663B (en) * 2019-12-25 2023-07-07 上海金仕达软件科技股份有限公司 Transaction concurrency control method, device, terminal equipment and medium
CN111259071B (en) * 2020-01-04 2022-08-05 浙江科技学院 Concurrent access control method in distributed database system
CN111259071A (en) * 2020-01-04 2020-06-09 浙江科技学院 Concurrent access control method in distributed database system
CN111240810B (en) * 2020-01-20 2024-02-06 上海达梦数据库有限公司 Transaction management method, device, equipment and storage medium
CN111240810A (en) * 2020-01-20 2020-06-05 上海达梦数据库有限公司 Transaction management method, device, equipment and storage medium
CN112883045A (en) * 2021-03-31 2021-06-01 中国工商银行股份有限公司 Database transaction splitting execution method and device
CN112883045B (en) * 2021-03-31 2024-05-17 中国工商银行股份有限公司 Database transaction splitting execution method and device
US11755558B2 (en) 2021-06-25 2023-09-12 Microsoft Technology Licensing, Llc Transaction identifier locking with data row locks
CN113746682A (en) * 2021-09-07 2021-12-03 迈普通信技术股份有限公司 Configuration guarantee method and device
WO2023124421A1 (en) * 2021-12-31 2023-07-06 深圳市兆珑科技有限公司 Transaction concurrency control method and apparatus, electronic device and readable storage medium
CN115543970A (en) * 2022-11-29 2022-12-30 本原数据(北京)信息技术有限公司 Data page processing method, data page processing device, electronic equipment and storage medium
CN115543970B (en) * 2022-11-29 2023-03-03 本原数据(北京)信息技术有限公司 Data page processing method, data page processing device, electronic equipment and storage medium
CN116383209A (en) * 2023-03-30 2023-07-04 深圳计算科学研究院 Concurrency control method and concurrency control device for column-store database

Also Published As

Publication number Publication date
CN108363806B (en) 2020-07-31

Similar Documents

Publication Publication Date Title
CN108363806A (en) Multi-version concurrency control method, device, server and the storage medium of database
EP4254183A1 (en) Transaction processing method and apparatus, computer device, and storage medium
EP3117348B1 (en) Systems and methods to optimize multi-version support in indexes
US6772155B1 (en) Looking data in a database system
CN111143389B (en) Transaction execution method and device, computer equipment and storage medium
US6950834B2 (en) Online database table reorganization
US11442961B2 (en) Active transaction list synchronization method and apparatus
US8010497B2 (en) Database management system with efficient version control
US11386065B2 (en) Database concurrency control through hash-bucket latching
US8364656B2 (en) Method and system for implementing multiuser cached parameterized cells
Wu et al. Transaction healing: Scaling optimistic concurrency control on multicores
US10754854B2 (en) Consistent query of local indexes
US9576038B1 (en) Consistent query of local indexes
EP3800558A1 (en) Database transaction processing method, client, and server
JPH0212460A (en) Parallel accessing to index tree
Taniar et al. A taxonomy of indexing schemes for parallel database systems
CN106354732A (en) Offline data version conflict resolution method for supporting concurrent cooperation
KR102139087B1 (en) Method, server, and computer readable medium for index recovery using index redo log
US7752399B2 (en) Exclusion control method and information processing apparatus
WO2023124242A1 (en) Transaction execution method and apparatus, device, and storage medium
CN113032292B (en) Storage space recovery method, data reading method and device
CN116089359A (en) Database snapshot generation method and device, electronic equipment and medium
US7647296B2 (en) Method for estimating a first access time of transactions accessing a database object
Prinz et al. Operational semantics of transactions
Weikum Enhancing concurrency in layered systems

Legal Events

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