CN114443672A - Multi-version concurrency control method, device, equipment and storage medium - Google Patents

Multi-version concurrency control method, device, equipment and storage medium Download PDF

Info

Publication number
CN114443672A
CN114443672A CN202011232924.6A CN202011232924A CN114443672A CN 114443672 A CN114443672 A CN 114443672A CN 202011232924 A CN202011232924 A CN 202011232924A CN 114443672 A CN114443672 A CN 114443672A
Authority
CN
China
Prior art keywords
line
transaction
current
pointer
termination
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
CN202011232924.6A
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.)
Guangzhou Yaxin Technology Co ltd
Original Assignee
Guangzhou Yaxin Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Yaxin Technology Co ltd filed Critical Guangzhou Yaxin Technology Co ltd
Priority to CN202011232924.6A priority Critical patent/CN114443672A/en
Publication of CN114443672A publication Critical patent/CN114443672A/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/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 embodiment of the application provides a multi-version concurrency control method and device, electronic equipment and a computer readable storage medium, and relates to the technical field of databases. The method comprises the following steps: acquiring a current transaction pointer and a line pointer of a current line; acquiring a current transaction start number according to the current transaction pointer; acquiring line state information of a current line, a line effective mark and a line termination mark of the current line according to a line pointer of the current line; and judging the visibility of the current line by using the root transaction state information and at least one of the current transaction starting number, the line effective mark and the line termination mark. The embodiment of the application realizes the visibility judgment only through the hidden field on the row under the condition of not acquiring the current active transaction list.

Description

Multi-version concurrency control method, device, equipment and storage medium
Technical Field
The present application relates to the field of database technologies, and in particular, to a method, an apparatus, a device, and a storage medium for controlling multi-version concurrency.
Background
Multi-version Control (MVCC) refers to a technology for improving Concurrency, and the earliest database system can only block read and write, read and write. After the multi-version is introduced, only the writing is mutually blocked, and other three operations can be parallel, so that the concurrency of the database is greatly improved. In the same transaction, the user can only see the modifications that have been committed before the transaction created the snapshot and the modifications that the transaction itself made. MVCC only works at two isolation levels of Read Committed (Read Committed) and Repeatable Read (Repeatable Read).
The MVCC in PostgreSQL is realized in the principle that when a transaction starts, the whole transaction table at the beginning of a reader is copied, so that the transaction table becomes a hot spot; however, for the transaction in the corresponding history, because the record of the aborted transaction is not physically rolled back, all transaction histories need to store the bitmap until the data batch processing is completed, which often causes performance impact on the system. In the MVCC implementation of another database DB management system, a system submitted transaction identifier and a current log record sequence number are copied from a transaction log at the starting point of a reader, and a whole transaction table can not be acquired; but in some scenarios, the active transaction list is still retrieved.
Therefore, in order to determine the visibility of the data line, the active transaction list is obtained when the first select (read only) statement is executed after the transaction starts, or the active transaction list is obtained again when each select (read only) statement is executed after the transaction starts, or in some scenarios, the active transaction list is obtained. In summary, these MVCC implementations involve obtaining a current active transaction list, which typically blocks the start and commit of other transactions, often resulting in system performance degradation when the concurrency is large.
Disclosure of Invention
The application provides a multi-version concurrency control method and device, electronic equipment and a computer readable storage medium, which can realize visibility judgment without acquiring a current active transaction list, thereby improving system performance in an MVCC scene. The technical scheme adopted by the application is as follows:
in a first aspect, a multi-version concurrency control method is provided, which includes:
acquiring a current transaction pointer and a line pointer of a current line;
acquiring a current transaction start number according to the current transaction pointer;
acquiring line state information of a current line, a line effective mark and a line termination mark of the current line according to a line pointer of the current line;
and judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective mark and the line termination mark.
In this embodiment of the present application, determining the visibility of the current line according to the line pointer of the current line and at least one of the current transaction start number, the line effective flag, and the line termination flag includes:
if the line validation mark corresponds to the line validation transaction pointer and the line termination transaction number corresponding to the line termination mark, judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line validation transaction pointer and the line termination transaction number;
if the line validation mark corresponds to the line validation transaction number and the line termination transaction pointer corresponds to the line termination mark, judging the visibility of the current line according to the current transaction start number, the line validation transaction number and the line termination transaction pointer;
and if the line validation mark corresponds to the line validation transaction number and the line termination mark corresponds to the line termination transaction number, judging the visibility of the current line according to the current transaction start number, the line validation transaction number and the line termination transaction number.
In the embodiment of the present application, determining the visibility of the current line according to the line state information and at least one of the current transaction start number, the line validation transaction pointer, and the line termination transaction number includes:
when the line state information is that the current line is a deleted line, determining that the current line is invisible;
when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is the current transaction pointer, determining that the current line is visible;
and when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is not the current transaction pointer, judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number.
In this embodiment of the present application, determining the visibility of the current line according to at least one of the current transaction start number, the line validation transaction pointer, and the line termination transaction number includes:
acquiring a line effective transaction submission number of a current line according to the line effective transaction pointer;
and judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction submission number and the line termination transaction number.
In this embodiment of the present application, determining the visibility of the current line according to at least one of the current transaction start number, the line effective transaction commit number, and the line end transaction number includes:
if the line validation transaction submission number is equal to zero, determining that the current line is invisible;
and if the current transaction start number is greater than or equal to the line effective transaction commit number and less than or equal to the line termination transaction number, determining that the current line is visible.
In the embodiment of the present application, judging the visibility of the current line according to the current transaction start number, the line-effective transaction number, and the line-termination transaction pointer includes:
acquiring a line termination transaction submission number of a current line according to the line termination transaction pointer;
and judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction submission number.
In the embodiment of the present application, determining the visibility of the current line according to the current transaction start number, the line effective transaction number, and the line termination transaction commit number includes:
if the current transaction start number is greater than or equal to the line effective transaction number and the line termination transaction commit number is equal to zero, determining that the current line is visible;
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction commit number, determining that the current line is visible.
In the embodiment of the present application, determining the visibility of the current line according to the current transaction start number, the line validation transaction number, and the line termination transaction number includes:
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction number, determining that the current line is visible.
In the embodiment of the present application, the method further includes:
when the current line is invisible, acquiring a line pointer of a next line according to the line pointer of the current line;
determining the row state information of the next row, the row effective mark and the row termination mark of the next row according to the row pointer of the next row when the row pointer of the next row is not null;
and judging the visibility of the next line according to the line state information of the next line and at least one of the current transaction start number, the line effective mark of the next line and the line termination mark of the next line.
In a second aspect, the present application provides a device for multi-version concurrent control, the device comprising:
the acquisition module is used for acquiring a current transaction pointer and a current line pointer, acquiring a current transaction starting number based on the current transaction pointer, and acquiring line state information of a current line, a line effective mark and a line termination mark of the current line based on the line pointer of the current line;
and the judging module is used for judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective mark and the line termination mark.
In the embodiment of the present application,
if the line validation mark corresponds to the line validation transaction pointer and the line termination transaction number corresponds to the line termination mark, the judging module is specifically used for judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line validation transaction pointer and the line termination transaction number;
if the line validation mark corresponds to the line validation transaction number and the line termination mark corresponds to the line termination transaction pointer, the judging module is specifically used for judging the visibility of the current line according to the current transaction start number, the line validation transaction number and the line termination transaction pointer;
and if the line validation mark corresponds to the line validation transaction number and the line termination mark corresponds to the line termination transaction number, the judging module is specifically used for judging the visibility of the current line according to the current transaction start number, the line validation transaction number and the line termination transaction number.
In this embodiment of the present application, the determining module is specifically configured to, when determining the visibility of the current line according to at least one of the current transaction start number, the line validation transaction number, and the line termination transaction pointer, specifically include:
when the line state information is that the current line is a deleted line, determining that the current line is invisible;
when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is the current transaction pointer, determining that the current line is visible;
and when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is not the current transaction pointer, judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number.
In this embodiment of the present application, when the determining module is configured to determine the visibility of the current line according to at least one of the current transaction start number, the line validation transaction pointer, and the line termination transaction number, the determining module specifically includes:
acquiring a line effective transaction submission number of a current line according to the line effective transaction pointer;
and judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction submission number and the line termination transaction number.
In this embodiment of the present application, when the determining module is configured to determine the visibility of the current line according to at least one of the current transaction start number, the line validation transaction commit number, and the line termination transaction number, the determining module specifically includes:
if the line validation transaction submission number is equal to zero, determining that the current line is invisible;
and if the current transaction start number is greater than or equal to the line effective transaction commit number and less than or equal to the line termination transaction number, determining that the current line is visible.
In this embodiment of the present application, the determining module, when determining the visibility of the current line according to the current transaction start number, the line effective transaction number, and the line termination transaction pointer, specifically includes:
acquiring a line termination transaction submission number of a current line according to the line termination transaction pointer;
and judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction submission number.
In this embodiment of the present application, the determining module, when determining the visibility of the current line according to the current transaction start number, the line effective transaction number, and the line termination transaction commit number, specifically includes:
if the current transaction start number is greater than or equal to the line effective transaction number and the line termination transaction commit number is equal to zero, determining that the current line is visible;
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction commit number, determining that the current line is visible.
In this embodiment of the present application, the determining module, when determining the visibility of the current line according to the current transaction start number, the line validation transaction number, and the line termination transaction number, specifically includes:
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction number, determining that the current line is visible.
In the embodiment of the application, the obtaining module and the determining module are further configured to:
when the judging module judges that the current line is invisible, the acquiring module is further used for acquiring a line pointer of the next line, and the judging module is further used for judging whether the line pointer of the next line is empty or not;
when the judging module judges that the row pointer of the next row is not empty, the acquiring module is further used for acquiring the row state information of the next row, the row effective mark of the next row and the row termination mark of the next row;
the judging module is further configured to judge the visibility of the next line according to the line state information of the next line, that is, at least one of the current transaction start number, the line enable flag of the next line, and the line end flag of the next line.
In a third aspect, the present application provides an electronic device comprising a processor and a memory:
a memory for storing computer operating instructions;
a processor for executing the method as shown in any embodiment of the first aspect of the present application by invoking computer operational instructions.
In a fourth aspect, the present application provides a computer readable storage medium having stored thereon computer program instructions for causing a computer to execute to implement a method as shown in any of the embodiments of the first aspect of the present application.
The technical scheme provided by the embodiment of the application has the following beneficial effects:
in the embodiment of the application, the visibility of the current line is determined according to hidden field information on the line, specifically line state information, and at least one of a current transaction start number, a line effective flag, and a line end flag. Under the condition that a current active transaction list does not need to be obtained, the current visibility judgment is realized only through hidden fields on the rows, and the system performance under the MVCC scene is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the description of the embodiments of the present application will be briefly described below.
Fig. 1 is a schematic flowchart of a multi-version concurrency control method according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of a multi-version concurrency control method according to another embodiment of the present application;
fig. 3 is a schematic structural diagram of a multi-version concurrency control device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Reference will now be made in detail to embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present invention.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
In the prior art, in order to determine visibility of a data line, when each select (read-only operation) is executed after a transaction begin, an active transaction list is obtained; or when each select (read-only operation) statement is executed after the transaction begin, the active transaction list is obtained again; or in some scenarios, an active transaction list is obtained. In summary, these MVCC implementations involve obtaining a current active transaction list, which typically blocks the start and commit of other transactions, often resulting in performance degradation when concurrency is high.
The application provides a multi-version concurrency control method, a multi-version concurrency control device, electronic equipment and a computer readable storage medium, and aims to solve the technical problems in the prior art.
The following describes the technical solutions of the present application and how to solve the above technical problems with specific embodiments. The following specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
In the embodiment of the present application, the MVCC row data format is shown in table 1 below:
info(1) begin(8) end(8) next(8) recording content
TABLE 1
Wherein, info: 1 byte, representing the state of the row, specifically: deleted, free, or in use, etc.;
begin: 8 bytes, which represent the transaction number when the row takes effect, specifically: a transaction pointer or transaction number;
end: 8 bytes, which represent the transaction number when the line terminates, specifically: a transaction pointer or transaction number;
next: 8 bytes, which represents the next rollback pointed to, specifically: the row _ id of the next rollback row or a pointer to the next rollback row.
In the embodiment of the present application, the transaction-related data structure is shown in table 2 below:
start_trx_id
commit_trx_id
TABLE 2
Wherein, start _ trx _ id: 8 bytes, which represents the number at the beginning of the transaction;
commit _ trx _ id: 8 bytes, which represents the number of the transaction when it commits;
the rows referred to in the embodiments of the present application all have the data structure shown in table 1, but are not limited to the data structure in table 1.
As can be seen from the above, the row status information includes whether a row is free, deleted, or in use, etc. In the embodiment of the present application, visibility of deleted rows and used rows is mainly analyzed. For convenient further analysis, the rows to be analyzed are divided into deleted and non-deleted rows. The transactions involved in the embodiments of the present application all have the data structure shown in table 2, but are not limited to the data structure in table 2.
The embodiment of the present application provides a multi-version concurrency control method, as shown in fig. 1, including:
s101, acquiring a current transaction pointer and a line pointer of a current line.
When the visibility of the current row is judged, firstly, the current transaction object and the row object of the current row need to be acquired, then other information is acquired through the object, and the visibility of the current row is judged based on the acquired information. Acquiring a current transaction object, specifically acquiring a pointer pointing to the current transaction object, namely a current transaction pointer, and acquiring the pointed object through the current transaction pointer so as to acquire the current transaction object; the method includes acquiring a line object of a current line, specifically acquiring a pointer pointing to the current line object, namely a line pointer of the current line, and acquiring the pointed object through the line pointer of the current line, thereby acquiring the line object of the current line.
Wherein, the current transaction opened is a select transaction (read-only transaction) because the current operation is a select (read-only operation).
And S102, acquiring the starting number of the current transaction according to the current transaction pointer.
First, a current transaction object is obtained according to a current transaction pointer. The data structure of the current transaction object is shown in table 2, and includes the number start _ trx _ id of the transaction when it starts.
And acquiring a start number according to the current transaction object, namely the current transaction start number.
S103, according to the line pointer of the current line, the line state information of the current line, the line effective mark and the line termination mark of the current line are obtained.
First, a line object of a current line is obtained according to a line pointer of the current line. The data structure of the line object of the current line is shown in table 1, and includes state information info of the line, a validation flag begin of the line, and an end flag end of the line.
And secondly, acquiring the line state information, the line effective mark and the line termination mark of the current line according to the line object of the current line.
S104, judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective mark and the line termination mark.
When the visibility of the current line is judged, only the starting number of the current transaction, the line state information, the line effective mark and the line termination mark of the current line need to be acquired, and a current active transaction list does not need to be acquired, so that the locking does not exist to block the starting and the submission of other transactions. When the concurrency is large, the method has a good effect of improving the performance.
In another implementation manner of the embodiment of the present application, the line valid flag and the line end flag may be transaction pointers or transaction numbers.
The data type of the transaction pointer is a pointer, specifically, a memory address. When an object is created successfully, the object is saved in heap memory. In actual operation of a computer, direct access to an object in the heap memory is not allowed, and the object can only be operated by a reference of the object, where the reference is specifically a pointer. The object is obtained by pointing to the object by a pointer, in particular by pointing to the first address of the object pointed to by the pointer.
The data type of a transaction number is a numerical value, specifically what is an amount in terms of a number. The length of the memory cell occupied by the memory cell is not fixed and is different due to different value types.
Therefore, according to the line state information and at least one of the current transaction start number, the line effective flag and the line termination flag, the visibility of the current line is judged, which at least includes the following situations:
when the line validation flag is the line validation transaction pointer and the line termination transaction number corresponding to the line termination flag, S104 specifically includes: s1041, according to the line state information and at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number, judging the visibility of the current line.
When the line validation flag is the line validation transaction number and the line termination transaction pointer corresponding to the line termination flag, S104 specifically includes: s1042, according to the current transaction start number, the line effective transaction number and the line termination transaction pointer, judging the visibility of the current line.
When the line validation flag is the line validation transaction number and the line termination transaction number corresponding to the line termination flag, S104 specifically includes: s1043, according to the current affair starting number, the line effective affair number and the line ending affair number, judging the visibility of the current line.
In the embodiment of the application, the line effective mark and the line termination mark are analyzed, and a specific scheme for judging the visibility of the current line can be determined under the condition of a transaction number or a transaction pointer. The determination process does not require the acquisition of the current active transaction list, so there is no locking to block the start and commit of other transactions. When the concurrency is large, the method has a good effect of improving the performance.
In another implementation manner of the embodiment of the present application, when the line validation flag is a line validation transaction pointer, a line termination transaction number corresponding to the line termination flag. Specifically, the current row has a transaction operation, and further analysis may be performed according to the row state information of the current row, and S1041 may include:
s1041-1, when the line state information is that the current line is a deleted line, determining that the current line is invisible.
For example, the operation being executed by the current line is a transaction T, and the specific process of the transaction T is as follows: first, an insert operation is performed once, with the result that one line is inserted S1; next, a deletion operation is performed again, resulting in deletion of S1. That is, the operation transaction T being executed by the current row is specifically to perform an insert and delete operation, with the result that no row is inserted. At this point, the current line is not visible regardless of whether the other transaction or the current transaction is going to read the line. That is, the current row is not visible to the current transaction.
S1041-2, when the line state information is the current line which is not deleted and the line effective transaction pointer is the current transaction pointer, determining that the current line is visible.
For example, when the current row is not a deleted row, and the row valid flag of the current row is a pointer, it indicates that an operation is in progress on the current row. And when the pointer is the current transaction pointer, the current transaction is explained to be subjected to the read-only operation on the current line. That is, the current line is visible to the current transaction.
S1041-3, when the line state information is the current line which is not deleted and the line effective pointer is not the current transaction pointer, judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number.
That is, the row state information indicates that the current row is neither a deleted row nor a current transaction operation, and then the visibility of the current row needs to be further determined according to at least one of the current transaction start number, the row valid transaction pointer, and the row end transaction number.
In the embodiment of the present application, since the current row state information may be a deleted row or a non-deleted row of the current behavior, it is determined whether the current row is a deleted row or a non-deleted row, and then the visibility of the current row is further determined when the row effective flag of the current row is a row effective transaction pointer and the row end flag is a row end transaction number.
In another implementation manner of the embodiment of the present application, when the line validation flag is a line validation transaction pointer, a line termination transaction number corresponding to the line termination flag. Specifically, the current row has transactional operations but is not the current transactional operation, and the current row is not a deleted row. S1041-3 specifically includes:
s1041-31, obtaining the line effective affair submission number of the current line according to the line effective affair pointer;
since the line valid transaction pointer is a memory address, it is specifically used to store the first address of the object pointed to. Therefore, the row effective transaction object needs to be acquired first through the row effective transaction pointer, and then the row effective transaction commit number needs to be acquired through the row effective transaction object.
S1041-32, judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction commit number and the line termination transaction number. The method specifically comprises the following steps:
1. if the line validation transaction submission number is equal to zero, determining that the current line is invisible to the current transaction;
that is, the current line is executing a transactional operation, while the operation is not committed, the current line is in a locked state. Thus, the current row is determined to be invisible to the current transaction.
2. And if the current transaction start number is greater than or equal to the line effective transaction commit number and less than or equal to the line termination transaction number, determining that the current line is visible to the current transaction.
In the embodiment of the application, if the line effective flag of the current line is a transaction pointer, the line effective transaction submission number needs to be acquired according to the line termination transaction pointer, and then the visibility of the current line needs to be further judged according to the current transaction submission number, the line effective transaction submission number and the line termination transaction number.
In another implementation manner of the embodiment of the present application, when the line validation flag is a line validation transaction number and a line termination transaction pointer corresponding to the line termination flag. Specifically, the current row has a transaction operation, and the row state information of the current row is a deleted row. S1042 may include:
s1042-1, acquiring a line termination transaction submission number of the current line according to the line termination transaction pointer;
since the line termination transaction pointer is not a specific value, the line termination transaction object needs to be obtained through the line termination transaction pointer, and the line termination transaction commit number needs to be obtained through the line termination transaction object.
The line termination transaction commit number is 0, indicating infinity. Specifically, it can be said that 0 is a flag at this time, and the current transaction number is compared with the line termination commit number, and the result is smaller than the line termination commit number.
S1042-2, judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction submit number. The method specifically comprises the following steps:
1. if the current transaction start number is greater than or equal to the line effective transaction number and the line termination transaction commit number is equal to zero, determining that the current line is visible to the current transaction;
2. and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction commit number, determining that the current line is visible.
In the embodiment of the application, if the line termination flag of the current line is a transaction pointer, the line termination transaction commit number needs to be acquired according to the line termination transaction pointer, and then the visibility of the current line is further judged according to the current transaction commit number, the line effective transaction number and the line termination transaction commit number.
In another implementation manner of the embodiment of the present application, when the line validation flag corresponds to a line validation transaction number, and the line termination flag corresponds to a line termination transaction number. Specifically, the current row has no transactional operations, and the current row is either a deleted row or a non-deleted row. S1043 includes:
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction number, determining that the current line is visible.
Where, when the line termination transaction number is 0, infinity is indicated. Specifically, it can be said that 0 is a flag at this time, and the current transaction number is compared with the line termination transaction number, and the result is smaller than the line termination transaction number.
In another implementation manner of the embodiment of the present application, when it is determined that the current row is invisible according to any of the above implementation manners, information of a next rollback row needs to be obtained for determination until a visible row is obtained or until all rows are invisible, which is specifically shown in fig. 2:
after S104, further comprising:
s105, when the current line is invisible, acquiring a line pointer of a next line according to the line pointer of the current line;
wherein the next line is actually the next rollback line;
specifically, the row _ id stored in the next in the line data structure shown in table 1 or the line pointer pointing to the next line is obtained according to the line object of the current line. Wherein a line pointer to the next line can be obtained through the row _ id.
S106, if the line pointer of the next line is not null, determining the line state information, the line effective mark and the line termination mark of the next line according to the line pointer of the next line;
s107, judging the visibility of the next line according to the line state information of the next line and at least one of the current transaction start number, the line effective mark of the next line and the line end mark of the next line.
The process of determining the visibility of the next line refers to the process of determining the visibility of the current line, and for brevity of description, details are not repeated herein.
In the embodiment of the application, when the current row is judged to be invisible, the information of the next rolling row needs to be acquired, and whether the next row is visible or not is judged until the visible row or all the visible rows are obtained.
In another embodiment of this embodiment, the process of determining the visibility of the current line will be described in more detail.
The operation transaction of the current row can be a read-only operation, an insert operation, an update operation or a delete operation. Therefore, the operations performed by the current row are described in conjunction with tables 3, 4, and 5 below to determine the visibility of the current row at various stages. In the following cases of judging the visibility of the current line, all the cases are based on the information of the acquired current transaction, and the specific information is the current transaction number.
In one aspect, the insertion operation is described as an example in conjunction with table 3 below.
Figure BDA0002765797230000131
Figure BDA0002765797230000141
TABLE 3
Table 3 records the entire process of the current row being subjected to the insert operation, the current row being a non-deleted row.
Where, time sequence 1, an insert transaction object is created. The system assigns the start number (start _ trx _ id) of the insert transaction object to transaction number A and the commit number (commit _ trx _ id) to 0. The effective flag and the termination flag of the current line are transaction numbers. At this time, the visibility of the current line may be judged according to the current transaction start number, the line active flag, and the line end transaction number.
At timing 2, the insert transaction begins to execute. The line valid flag (begin) is a line valid transaction pointer (pTrx), specifically a pointer to an inserted transaction object, and the line end flag (end) is a line end transaction number, specifically 0. Since the current line is performing the insert operation, the current line is in a locked state, and it can be directly determined that the current line is not visible.
Sequence 3, the pre-commit phase of the insert transaction. At this stage, the system assigns the commit number (commit _ trx _ id) of the insert transaction object to transaction number B. Because the line validation transaction pointer points to the inserted transaction object, the commit number of the inserted transaction object, namely the line validation transaction commit number, specifically the transaction number B, can be obtained through the line validation transaction pointer; the line termination transaction number is 0. At this point, the visibility of the current line may be determined based on the current transaction number, the line-effective transaction commit number, and the line-end transaction number.
Time sequence 4, the formal commit phase. At this stage, the line validate flag (begin) changes from the line validate transaction pointer to the line validate transaction number and is assigned transaction number B, and the line terminate transaction number is 0. After this phase, the data version of the current line becomes [ B,0 ]. At this point, the visibility of the current line may be determined based on the current transaction number, the line effect transaction number, and the line end transaction number.
Time sequence 5, committed phase. The line validation flag is a line validation transaction number, specifically a transaction number B, and the line termination flag is a line termination transaction number, specifically 0. The data version of the current line is still [ D,0 ]. At this point, the visibility of the current line may be determined based on the current transaction number, the line effect transaction number, and the line end transaction number.
On the other hand, the following description will be made by taking the refresh operation as an example, in conjunction with table 4 below.
Figure BDA0002765797230000151
TABLE 4
Table 4 records the entire process of the current row being updated, the current row being a non-deleted row.
Wherein, sequence 1, an update transaction object is created. The system assigns the start number of the update transaction object to transaction number C and the commit number to 0. The effective flag and the termination flag of the current line are transaction numbers. At this time, the visibility of the current line may be determined based on the current transaction start number, the line validation flag, and the line termination transaction number.
At timing 2, the update transaction begins to be executed. The line effective mark is a line effective transaction pointer, specifically a pointer pointing to an update transaction object, and the line termination mark is a line termination transaction number, specifically 0. Since the current row is performing the update operation, the current row is in a locked state, and it can be directly determined that the current row is not visible.
Sequence 3, update the pre-commit phase of the transaction. At this stage, the system assigns the commit number of the update transaction object to transaction number D. Because the row effective transaction pointer points to the update transaction object, the commit number of the update transaction object, namely the row effective transaction commit number, can be obtained through the row effective transaction pointer, specifically D; the line termination transaction number is 0. At this point, the visibility of the current line may be determined based on the current transaction number, the line-effective transaction commit number, and the line-end transaction number.
Time sequence 4, the formal commit phase. At this stage, the row-effective flag changes from the row-effective transaction pointer to the row-effective transaction number and is assigned transaction number D, with the row-end transaction number being 0. After this phase, the data version of the current line becomes [ D,0 ]. At this point, the visibility of the current line may be determined based on the current transaction number, the line effect transaction number, and the line end transaction number.
Time sequence 5, committed phase. The line validation flag is a line validation transaction number, specifically a transaction number D, and the line termination flag is a line termination transaction number, specifically 0. The data version of the current row state is still [ D,0 ]. At this time, the visibility of the current line can be judged by the current transaction number, the line effective transaction number, and the line termination transaction number.
When the updating operation is executed, a piece of rollback row data is generated, the row data before the updating operation is executed is recorded, but the current transaction still judges the visibility of the current row.
On the other hand, the following table 5 is described with a deletion operation as an example.
Figure BDA0002765797230000161
TABLE 5
Table 5 records the entire process of the current row being deleted, the current row.
Wherein, sequence 1, a delete transaction object is created. The system assigns the start number of the delete transaction object to be transaction number C and the commit number to be 0. The line valid flag and the line end flag are transaction numbers. At this point, the visibility of the current line may be determined based on the current transaction start number, the line effect transaction number, and the line end transaction number.
At timing 2, the delete transaction begins to be executed. The line effective mark is a line effective transaction pointer, specifically a pointer pointing to a deleted transaction object, and the line termination mark is a line termination transaction number, specifically storing transaction number 0. Since the current line is performing the delete operation, the current line is in a locked state, which may directly determine that the current line is not visible.
Sequence 3, the pre-commit phase of the transaction is deleted. At this stage, the system assigns the commit number of the delete transaction object to transaction number D. Because the line validation transaction pointer points to the deleted transaction object, the commit number of the deleted transaction object, namely the line validation transaction commit number, which is specifically the transaction number D, can be obtained through the line validation transaction pointer; the line termination transaction number is 0. At this point, the visibility of the current line may be judged based on the current transaction number, the line effective transaction commit number, and the line end transaction number.
Time sequence 4, the formal commit phase. At this stage, the row-effective flag changes from the row-effective transaction pointer to the row-effective transaction number, and is assigned transaction number D, with the row-ending transaction number unchanged. After this stage, the data version of the current line becomes [ D,0 ]. At this point, the visibility of the current line may be determined based on the current transaction number, the line effect transaction number, and the line end transaction number.
Time sequence 5, committed phase. The line validation flag is a line validation transaction number, specifically a transaction number D, and the line termination flag is a line termination transaction number, specifically a transaction number 0. The data version of the current row state is [ D,0 ]. At this time, the visibility of the current line can be judged by the current transaction number, the line effective transaction number, and the line termination transaction number.
It should be noted that the details of the current row are not limited to the situations involved in the embodiments of the present application, but also include many other situations, which are not described herein again.
The embodiment of the present application provides a multi-version concurrent control device 20, a schematic structural diagram of the device is shown in fig. 3, and the device 20 includes:
an obtaining module 201, configured to obtain a current transaction pointer and a current line pointer, further configured to obtain a current transaction start number based on the current transaction pointer, and further configured to obtain line state information of a current line, a line effective flag and a line end flag of the current line based on the line pointer of the current line;
the determining module 202 is configured to determine the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective flag, and the line end flag.
In the embodiment of the present application,
if the line validation flag corresponds to the line validation transaction pointer and the line termination flag corresponds to the line termination transaction number, the determining module 202 is specifically configured to: judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number;
if the line validation flag corresponds to the line validation transaction number and the line termination flag corresponds to the line termination transaction pointer, the determining module 202 is specifically configured to: judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction pointer;
if the line-in-effect transaction number corresponding to the line-in-effect flag and the line-end transaction number corresponding to the line-end flag are determined, the determining module 202 is specifically configured to: and judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction number.
In this embodiment of the application, the determining module 202 is configured to determine the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective transaction pointer, and the line termination transaction number, and specifically includes:
when the line state information is that the current line is a deleted line, determining that the current line is invisible;
when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is the current transaction pointer, determining that the current line is visible;
and when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is not the current transaction pointer, judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number.
In this embodiment of the present application, the determining module 202 is configured to, when determining the visibility of the current line according to at least one of the current transaction start number, the line validation transaction pointer, and the line termination transaction number, specifically include:
acquiring a line-in-effect transaction submission number of a current line according to the line-in-effect transaction pointer;
and judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction submission number and the line termination transaction number.
In this embodiment of the present application, the determining module 202 is configured to, when determining the visibility of the current line according to at least one of the current transaction start number, the line-effective transaction commit number, and the line-end transaction number, specifically include:
if the line validation transaction submission number is equal to zero, determining that the current line is invisible;
and if the current transaction start number is greater than or equal to the line effective transaction commit number and less than or equal to the line termination transaction number, determining that the current line is visible.
In this embodiment of the present application, the determining module 202 is configured to, when determining the visibility of the current line according to the current transaction start number, the line effective transaction number, and the line termination transaction pointer, specifically include:
acquiring a line termination transaction submission number of a current line according to the line termination transaction pointer;
and judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction submit number.
In this embodiment of the present application, when the determining module 202 is configured to determine the visibility of the current line according to the current transaction start number, the line-in-effect transaction number, and the line-out transaction commit number, the method specifically includes:
if the current transaction start number is greater than or equal to the line effective transaction number and the line termination transaction commit number is equal to zero, determining that the current line is visible;
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction commit number, determining that the current line is visible.
In this embodiment of the present application, the determining module 202 is configured to, when determining the visibility of the current line according to the current transaction start number, the line validation transaction number, and the line termination transaction number, specifically include:
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction number, determining that the current line is visible.
In this embodiment of the application, the obtaining module 201 and the determining module 202 are further configured to:
when the judging module 201 judges that the current row is invisible, the obtaining module 202 obtains a row pointer of the next row, and the judging module 201 is further configured to judge whether the row pointer of the next row is empty;
when the determining module 201 determines that the row pointer of the next row is not empty, the obtaining module 202 is further configured to obtain row state information of the next row, a row valid flag of the next row, and a row end flag of the next row;
the determining module 202 is further configured to determine visibility of the next line according to the line state information of the next line, that is, at least one of the current transaction start number, the line enable flag of the next line, and the line end flag of the next line.
The multi-version concurrency control device of this embodiment may execute the multi-version concurrency control method shown in the foregoing embodiments of this application, and the implementation principle and the achievable effect are similar, which are not described herein again.
An embodiment of the present application provides an electronic device, including: a memory and a processor; at least one program stored in the memory. The processor performs the above-described determination regarding the visibility of the lines when executing the program.
Specifically, as shown in fig. 3, the electronic device 30 shown in fig. 3 includes: a processor 301 and a memory 303. Wherein processor 301 is coupled to memory 303, such as via bus 302. The structure of the electronic device 30 is not limited to the embodiment of the present application.
The Processor 301 may be a CPU (Central Processing Unit), a general-purpose Processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other Programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor 301 may also be a combination of computing functions, e.g., comprising one or more microprocessors, a combination of a DSP and a microprocessor, or the like.
Bus 302 may include a path that transfers information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 3002 may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 3, but this does not mean only one bus or one type of bus.
The Memory 303 may be a ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, a RAM (Random Access Memory) or other type of dynamic storage device that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to these.
The memory 303 is used for storing application program codes for executing the scheme of the application, and the processor 301 controls the execution. The processor 301 is configured to execute application program code stored in the memory 303 to implement the aspects illustrated in the foregoing method embodiments.
The present application provides a computer-readable storage medium, on which a computer program is stored, which, when running on a computer, enables the computer to execute the corresponding content in the foregoing method embodiments.
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless explicitly stated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
The foregoing is only a partial embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (12)

1. A multi-version concurrency control method is characterized by comprising the following steps:
acquiring a current transaction pointer and a line pointer of a current line;
acquiring a current transaction start number according to the current transaction pointer;
acquiring the line state information of the current line, the line effective mark and the line termination mark of the current line according to the line pointer of the current line;
and judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective mark and the line termination mark.
2. The multi-version concurrency control method according to claim 1, wherein said determining the visibility of the current line according to the line state information and at least one of the current transaction start number, the line valid flag, and the line end flag comprises:
if the line validation mark corresponds to the line validation transaction pointer and the line termination transaction number corresponds to the line termination mark, judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line validation transaction pointer and the line termination transaction number;
if the line validation mark corresponds to the line validation transaction number and the line termination transaction pointer corresponds to the line termination mark, judging the visibility of the current line according to the current transaction start number, the line validation transaction number and the line termination transaction pointer;
and if the line validation transaction number corresponding to the line validation mark and the line termination transaction number corresponding to the line termination mark, judging the visibility of the current line according to the current transaction start number, the line validation transaction number and the line termination transaction number.
3. The multi-version concurrency control method according to claim 2, wherein said determining the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effect transaction pointer, and the line end transaction number comprises:
when the line state information is that the current line is a deleted line, determining that the current line is invisible;
when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is the current transaction pointer, determining that the current line is visible;
and when the line state information is that the current line is a non-delayed line and the line effective transaction pointer is not the current transaction pointer, judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction pointer and the line termination transaction number.
4. The multi-version concurrency control method according to claim 3, wherein said determining the visibility of the current line according to at least one of the current transaction start number, the line-effective transaction pointer, and the line-end transaction number comprises:
acquiring a line effective transaction submission number of the current line according to the line effective transaction pointer;
and judging the visibility of the current line according to at least one of the current transaction start number, the line effective transaction commit number and the line termination transaction number.
5. The method of claim 4, wherein determining the visibility of the current line based on at least one of the current transaction start number, the line-effective transaction commit number, and the line-end transaction number comprises:
if the line validation transaction commit number is equal to zero, determining that the current line is not visible;
and if the current transaction start number is greater than or equal to the line effective transaction commit number and less than or equal to the line termination transaction number, determining that the current line is visible.
6. The multi-version concurrency control method according to claim 2, wherein said determining the visibility of the current line according to the current transaction start number, the line-effective transaction number, and the line-end transaction pointer comprises:
acquiring a line termination transaction submission number of the current line according to the line termination transaction pointer;
and judging the visibility of the current line according to the current transaction start number, the line effective transaction number and the line termination transaction commit number.
7. The multi-version concurrency control method according to claim 6, wherein the determining the visibility of the current line according to the current transaction start number, the line-effective transaction number, and the line-ending transaction commit number comprises:
if the current transaction start number is greater than or equal to the line-effective transaction number and the line-termination transaction commit number is equal to zero, determining that the current line is visible;
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction commit number, determining that the current line is visible.
8. The multi-version concurrency control method according to claim 2, wherein the determining the visibility of the current line according to the current transaction start number, the line-effective transaction number, and the line-termination transaction number comprises:
and if the current transaction start number is greater than or equal to the line effective transaction number and less than or equal to the line termination transaction number, determining that the current line is visible.
9. The multi-version concurrency control method according to any one of claims 1-8, further comprising:
when the current line is invisible, acquiring a line pointer of a next line according to the line pointer of the current line;
when the line pointer of the next line is not null, determining the line state information of the next line, the line effective mark and the line termination mark of the next line according to the line pointer of the next line;
and judging the visibility of the next line according to the line state information of the next line and at least one of the current transaction start number, the line effective mark of the next line and the line end mark of the next line.
10. A multi-version concurrency control device, comprising:
an obtaining module, configured to obtain a current transaction pointer and a current row pointer, further configured to obtain a current transaction start number based on the current transaction pointer, and further configured to obtain row state information of the current row, a row effective flag of the current row, and a row end flag based on the row pointer of the current row;
and the judging module is used for judging the visibility of the current line according to the line state information and at least one of the current transaction start number, the line effective mark and the line termination mark.
11. An electronic device, comprising:
a processor and a memory;
the memory is used for storing computer operation instructions;
the processor is used for executing the method of any one of the claims 1-9 by calling the computer operation instruction.
12. A computer-readable storage medium having computer program instructions stored thereon for causing a computer to perform the method of any of claims 1-9.
CN202011232924.6A 2020-11-06 2020-11-06 Multi-version concurrency control method, device, equipment and storage medium Pending CN114443672A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011232924.6A CN114443672A (en) 2020-11-06 2020-11-06 Multi-version concurrency control method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011232924.6A CN114443672A (en) 2020-11-06 2020-11-06 Multi-version concurrency control method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114443672A true CN114443672A (en) 2022-05-06

Family

ID=81360949

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011232924.6A Pending CN114443672A (en) 2020-11-06 2020-11-06 Multi-version concurrency control method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114443672A (en)

Similar Documents

Publication Publication Date Title
CN107391628B (en) Data synchronization method and device
CN111090663B (en) Transaction concurrency control method, device, terminal equipment and medium
WO2015144003A1 (en) Systems and methods to optimize multi-version support in indexes
CN111414362B (en) Data reading method, device, equipment and storage medium
CN107665255B (en) Method, device, equipment and storage medium for key value database data change
CN108108486B (en) Data table query method and device, terminal equipment and storage medium
CN111125040A (en) Method, apparatus and storage medium for managing redo log
CN110019063B (en) Method for computing node data disaster recovery playback, terminal device and storage medium
CN115408411A (en) Data writing method and device, electronic equipment and storage medium
CN113220490A (en) Transaction persistence method and system for asynchronous write-back persistent memory
CN114443672A (en) Multi-version concurrency control method, device, equipment and storage medium
CN111797104A (en) Method and device for acquiring data change condition and electronic equipment
CN107609068B (en) Data non-inductive migration method
CN116089394A (en) Data rollback method, storage medium and device of database
CN115774724A (en) Concurrent request processing method and device, electronic equipment and storage medium
CN111984662B (en) Method and device for updating databases in batches
CN114896641A (en) Data verification method and device, electronic equipment and computer readable storage medium
US20230117060A1 (en) Read-write method and apparatus, electronic device, and readable memory medium
CN114297217A (en) Transaction concurrency control method and device, electronic equipment and readable storage medium
CN114579530A (en) Table space migration method and device, electronic equipment and computer readable storage medium
CN116107810A (en) Data recovery method, data recovery device, electronic device and storage medium
CN112612415B (en) Data processing method and device, electronic equipment and storage medium
US20230409608A1 (en) Management device, database system, management method, and computer program product
CN117472647A (en) Database transaction rollback method and device
CN117453849A (en) Content version-based data storage and reading method, device 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