CN110019468B - Database system and database access method - Google Patents

Database system and database access method Download PDF

Info

Publication number
CN110019468B
CN110019468B CN201711271123.9A CN201711271123A CN110019468B CN 110019468 B CN110019468 B CN 110019468B CN 201711271123 A CN201711271123 A CN 201711271123A CN 110019468 B CN110019468 B CN 110019468B
Authority
CN
China
Prior art keywords
transaction
data
data segment
segment
concurrency control
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.)
Active
Application number
CN201711271123.9A
Other languages
Chinese (zh)
Other versions
CN110019468A (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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies 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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201711271123.9A priority Critical patent/CN110019468B/en
Publication of CN110019468A publication Critical patent/CN110019468A/en
Application granted granted Critical
Publication of CN110019468B publication Critical patent/CN110019468B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/25Integrating or interfacing systems involving database management systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing

Landscapes

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

Abstract

The embodiment of the invention discloses a database system and a database access method, wherein the database system comprises: the SQL engine is used for receiving a first transaction, and the first transaction comprises corresponding first data; the switching unit is used for determining the heat degree of the first data segment; the first data segment is a database data segment in which the first data falls when the first transaction is executed, and the heat degree of the first data segment is the proportion of the number of the cancelled transactions in the first data segment in unit time in history to the number of the transactions of all operations; a concurrency control selection unit which selects the first concurrency control unit when the heat degree of the first data segment is larger than a first threshold value; a first concurrency control unit for determining whether a second transaction exists, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the data writing time of the second transaction is later than the data reading time of the first transaction.

Description

Database system and database access method
Technical Field
The invention relates to the technical field of databases, in particular to a database system and a database access method.
Background
A Database (Database) is a repository built on computer storage devices that organizes, stores, and manages data according to a data structure, and is an organized, sharable collection of data that is stored long term within a computer. A Transaction (Transaction) is a program execution unit (unit) that accesses and possibly updates various data items in a database, is the basic unit of recovery and concurrency control, and has 4 attributes: atomicity, consistency, isolation, durability. These four attributes are generally referred to as ACID characteristics, and in order to guarantee the attributes of the ACID of the database, a concurrency control mechanism is required to guarantee the correct execution of the transaction during the concurrent execution of the transaction. The concurrency control is mainly used for ensuring data consistency when a plurality of transactions operate on the same data at the same time.
However, when a plurality of transactions operate on the same data at the same time, the conflict rate of the system is increased, which results in a large number of cancelled transactions (aborts), and a part of the aborts are unnecessary, which results in a large number of erroneous aborts in the system, thereby affecting the system performance.
Disclosure of Invention
The embodiment of the invention provides a database system and a database access method, and aims to solve the problems that under the condition of high transaction concurrency conflict, a large number of transactions can be cancelled (abort) by mistake, so that the system throughput is reduced, and the number of executable transactions per second (tps) is reduced.
In a first aspect, an embodiment of the present invention provides a database system, where the database system may include: a Structured Query Language (SQL) engine, an adaptation module, and a transaction management module; the self-adaptive module comprises a switching unit and a concurrency control selection unit; the transaction management module comprises a first concurrency control unit; the SQL engine is used for receiving a first transaction, and the first transaction comprises corresponding first data; the switching unit is used for determining the heat degree of the first data segment; the first data segment is a database data segment in which the first data falls when the first transaction is executed, and the heat degree of the first data segment is the proportion of the number of the cancelled transactions in the first data segment in unit time in history to the number of the transactions of all operations; a concurrency control selection unit which selects the first concurrency control unit when the heat degree of the first data segment is larger than a first threshold value; a first concurrency control unit for determining whether a second transaction exists, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the data writing time of the second transaction is later than the data reading time of the first transaction.
The embodiment of the invention provides a database system, which calculates the heat of data of an operation transaction through a switching unit in a self-adaptive module and selects a corresponding parallel control unit according to the heat, so that the problem of tps reduction of the whole executable transaction caused by high cancellation rate is solved, and meanwhile, the low concurrent and low conflict throughput is not influenced.
In one example, the first concurrency control unit is further configured to: and when the second transaction exists and the third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data written by the third transaction is earlier than the data read by the first transaction. When there is a second transaction that is anti-sequentially dependent from the first transaction and there is a third transaction that is sequentially dependent from the first transaction, the first transaction is executed using the first parallel control unit. Compared with the prior art, the abort is further reduced.
In one example, the first concurrency control unit is further configured to: and when the second transaction and the third transaction exist, canceling the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data written by the third transaction is earlier than the data read by the first transaction. When there is a second transaction that is anti-sequentially dependent from the first transaction and there is a third transaction that is sequentially dependent from the first transaction, the first transaction is cancelled using the first parallel control unit.
In one example, the transaction management module further comprises a second concurrency control unit; the concurrency control selection unit is also used for selecting a second concurrency control unit when the heat degree of the first data segment is greater than a second threshold value; a second concurrency control unit which executes the first transaction by adopting an optimistic concurrency control method; wherein the second threshold is less than or equal to the first threshold.
In one example, the first transaction further includes second data corresponding to the first transaction, the second data segment being a database data segment into which the second data falls when the first transaction is executed, the first data segment being different from the second data segment; the switching unit is specifically configured to: the heat of the second data segment is determined. When the first transaction operates a plurality of data, and the data segments corresponding to the plurality of data are independent of each other, the corresponding concurrency control unit can be selected by the heat degree of a certain data segment in the plurality of data segments to operate the first transaction.
In one example, the first transaction further includes third data corresponding to the first transaction, the third data segment being a database data segment into which the third data falls when the first transaction is executed; the switching unit is specifically configured to: and determining the heat of the whole of the first data segment and the third data segment. Various concurrency controls are selected, and the selection can also be performed according to the overall heat of a plurality of data segments.
In one example, the switching unit is further configured to: the heat of the first data segment is updated. And after the first transaction is continuously executed or abort, the switching unit transmits the state of the first transaction and the data of the operation into the self-adaptive module, adds the information into the corresponding data segment structure, and selects which concurrency control is to be selected for the subsequent database system to operate the first transaction, thereby providing the heat of the first transaction.
In one example, the data system further comprises a custom data set module: and the user-defined data set module is used for determining whether the first data falls into a preset first data set.
In one example, the custom data set module is further to: when the first data does not fall into a preset first data set and the heat degree of the first data segment is larger than a first threshold value, whether the first data falls into a preset second data set or not is determined.
In a second aspect, an embodiment of the present invention provides a database system, where the database system may include: the system comprises an SQL engine, a user-defined data set module and a transaction management module; the transaction management module comprises a first concurrency control unit; an SQL engine to receive a first transaction, the first transaction including first data; the user-defined data set module is used for determining whether the first data falls into a preset first data set or not; when the first data falls into a preset first data set, a first concurrency control unit is used for determining whether a second transaction exists or not, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the data writing time of the second transaction is later than the data reading time of the first transaction.
The embodiment of the invention provides a database system, which is characterized in that hot data or cold data are customized in a customized data set module, and the data customized by a user are taken as a basis for selecting various concurrency controls, so that the problem that tps of an overall executable transaction is reduced due to high cancellation rate is solved, and meanwhile, the throughput of low concurrency and low conflict is not influenced.
In one example, the first concurrency control unit is further configured to: and when the first data falls into a preset first data set, a second transaction exists and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data writing time of the third transaction is earlier than the data reading time of the first transaction.
In one example, the first concurrency control unit is further configured to: and when the first data falls into a preset first data set and a second transaction and a third transaction exist, canceling the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data writing time of the third transaction is earlier than the data reading time of the first transaction.
In one example, the transaction management module further comprises: a second concurrency control unit;
and the second concurrency control unit is used for executing the first transaction by adopting an optimistic concurrency control method when the first data does not fall into a preset first data set.
In a third aspect, an embodiment of the present invention provides a database access method, where the database access method may include: receiving a first transaction, the first transaction comprising first data; determining a heat of the first data segment; the first data segment is a database data segment in which the first data falls when the first transaction is executed, and the heat degree of the first data segment is the proportion of the number of the cancelled transactions in the first data segment in unit time in history to the number of the transactions of all operations; when the heat degree of the first data segment is larger than a first threshold value, determining whether a second transaction exists, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the data writing time of the second transaction is later than the data reading time of the first transaction.
The embodiment of the invention provides a database access method, which selects various concurrent control operations for a first transaction through the heat of a first data segment, wherein the first data segment is a database data segment in which first data falls when the first transaction is executed, so that the problem that the tps of the whole executable transaction is reduced due to high cancellation rate is solved, and meanwhile, the throughput of low concurrency and low conflict is not influenced.
In one example, the database access method further comprises: and when the heat of the first data segment is greater than the first threshold, a second transaction exists, and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data writing time of the third transaction is earlier than the data reading time of the first transaction. The first transaction is executed when there is a second transaction that is anti-sequentially dependent from the first transaction and there is a third transaction that is sequentially dependent from the first transaction. Compared with the prior art, the abort is further reduced.
In one example, the database access method further comprises: and when the heat degree of the first data segment is greater than a first threshold value and a second transaction and a third transaction exist, canceling the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data writing time of the third transaction is earlier than the data reading time of the first transaction.
In one example, the database access method further comprises: when the heat degree of the first data segment is larger than a second threshold value, executing a first transaction by adopting an optimistic concurrency control method; wherein the second threshold is less than or equal to the first threshold.
In one example, the first transaction further includes second data corresponding to the first transaction, the second data segment being a database data segment into which the second data falls when the first transaction is executed, the first data segment being different from the second data segment; determining a heat of the first data segment, comprising: the heat of the second data segment is determined. When the first transaction operates a plurality of data, and the data segments corresponding to the plurality of data are independent of each other, the corresponding concurrency control unit can be selected by the heat degree of a certain data segment in the plurality of data segments to operate the first transaction.
In one example, the first transaction further includes third data corresponding to the first transaction, the third data segment being a database data segment into which the third data falls when the first transaction is executed; determining a heat of the first data segment, comprising: and determining the heat of the whole of the first data segment and the third data segment. Various concurrency controls are selected, and the selection can also be performed according to the overall heat of a plurality of data segments.
In one example, the database access method further comprises: the heat of the first data segment is updated. After the first transaction continues to execute or abort, the state of the first transaction and the data of the operation are transmitted into the self-adapting module, and the information is added into the corresponding data segment structure, so that the concurrency control of the first transaction is selected for the subsequent database system to operate the first transaction, and the data support of the heat degree of the first transaction is provided.
In one example, prior to determining the heat of the first data segment, the database access method further comprises: it is determined whether the first data falls within a preset first data set.
In one example, the database access method further comprises: when the first data does not fall into a preset first data set and the heat degree of the first data segment is larger than a first threshold value, whether the first data falls into a preset second data set or not is determined.
In a fourth aspect, an embodiment of the present invention provides a database access method, where the database access method may include: receiving a first transaction, the first transaction comprising first data; determining whether the first data falls into a preset first data set; when the first data falls into a preset first data set, determining whether a second transaction exists, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the data writing time of the second transaction is later than the data reading time of the first transaction.
The embodiment of the invention provides a database access method, which judges and selects various concurrent control operation first transactions through user-defined data, further solves the problem that tps of the overall executable transaction is reduced due to high cancellation rate, and meanwhile, does not affect throughput of low concurrency and low conflict.
In one example, the database access method further comprises: and when the first data falls into a preset first data set, a second transaction exists and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data writing time of the third transaction is earlier than the data reading time of the first transaction.
In one example, the database access method further comprises: and when the first data falls into a preset first data set and a second transaction and a third transaction exist, canceling the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data writing time of the third transaction is earlier than the data reading time of the first transaction.
In one example, the database access method further comprises: and when the first data does not fall into the preset first data set, executing the first transaction by adopting an optimistic concurrency control method.
In a fifth aspect, an embodiment of the present invention provides a computer-readable storage medium storing a program, where the program includes instructions for the database access method.
In a fifth aspect, an embodiment of the present invention provides a computer program, where the program includes instructions for the above database access method.
The embodiment of the invention provides a database system and a database access method, wherein the database system is provided with a self-adaptive module on the existing basis, the self-adaptive module selects a corresponding parallel control method to execute and operate the current transaction according to the conflict rate of the transaction, so that the problem of tps reduction of the overall executable transaction caused by high cancellation rate is solved, and meanwhile, the throughput of low concurrency and low conflict is not influenced.
Drawings
FIG. 1 is a diagram illustrating a conventional transaction sequence and data relationship;
FIG. 2 is a schematic diagram of a database system of the prior art;
FIG. 3 is a first diagram of a database system according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of an adaptive module according to an embodiment of the present invention;
FIG. 5 provides a data segment update diagram for an embodiment of the present invention;
FIG. 6 is a schematic diagram of data segment splitting/merging according to an embodiment of the present invention;
FIG. 7 is a first flowchart of a database access method according to an embodiment of the present invention;
FIG. 8 is a flow chart of a flexible optimistic concurrency control method according to an embodiment of the invention;
FIG. 9 is a sequence dependency diagram;
FIG. 10 is an inverse order dependency diagram;
FIG. 11 is a flowchart of a transaction state update and data segment switch according to an embodiment of the present invention;
FIG. 12 is a second schematic diagram of a database system according to an embodiment of the present invention;
FIG. 13 is a flowchart of a database access method according to an embodiment of the present invention;
FIG. 14 is a third schematic diagram of a database system according to an embodiment of the present invention;
FIG. 15 is a flowchart of a database access method according to an embodiment of the present invention;
FIG. 16 is a fourth schematic diagram of a database system according to an embodiment of the present invention;
FIG. 17 is a fourth flowchart of a database access method according to an embodiment of the present invention;
FIG. 18 is a fifth schematic diagram of a database system according to an embodiment of the present invention;
fig. 19 is a flowchart of a database access method according to an embodiment of the present invention.
Detailed Description
The technical solution of the present invention is further described in detail by the accompanying drawings and embodiments.
Fig. 2 is a schematic structural diagram of a database system in the prior art, and as shown in fig. 2, the database system includes a Structured Query Language (SQL) engine 210, a transaction management module 220, a storage engine 230, a log management 240, a buffer 250, and a recovery management module 260.
The SQL engine 210 is configured to parse SQL statements corresponding to operations of adding, deleting, modifying, and searching, wherein syntax analysis and semantic analysis of the SQL statements are completed in the SQL engine 210, and an execution plan is generated finally.
The transaction management module 210 is configured to determine conflicts and ACID attribute guarantees of different transactions in the process of executing the plan.
A storage engine 230 for storing user data information.
The log management 240, the buffer 250 and the recovery management module 260 are mainly responsible for the functions of consistency of operation, efficiency improvement, downtime restart recovery and the like.
The entire database operation flow is described below by way of a simple example "create order, inventory minus 2 operations".
User A, B, C is the subject of initiating add, delete, change, and check operations on the database. The user A, B, C initiates a request for generating a new order, the database determines whether the stock is greater than 0 after receiving the request, when the stock is greater than 0, a record is inserted into the new order table, and the stock is subtracted by 2. The method specifically comprises the following steps:
the first step is as follows: the user executes the start transaction;
the second step is as follows: the user issues a generate new order (the generate new order corresponds to three operations of judging warehouse allowance, inserting a new order and subtracting 2 from the stock, and the SQL statements corresponding to the three operations need to be parsed in the SQL engine 220).
The third step: acquiring whether the warehouse allowance is larger than 0;
the fourth step: when the warehouse allowance is larger than 0, inserting a new record into the order table;
the fifth step: 2, stock reduction operation is carried out;
the transaction management module 220 is configured to determine whether the 3 operations meet the ACID attribute requirement of the transaction; when the 3 operations meet the ACID attribute requirements of the transaction, the transaction is submitted; when the 3 operations do not meet the ACID attribute requirements of the transaction, rolling back the transaction; the data stored in the storage engine 230 is permanently valid.
The embodiment of the invention provides a database system and a database access method on the basis of the existing database system, wherein the database system is provided with an adaptive module, the adaptive module selects a corresponding parallel control method to execute and operate the current transaction according to the conflict rate of the transaction, and further solves the problem that the number/second (tps) of the whole executable transaction is reduced due to high cancellation rate, and meanwhile, the throughput of low concurrency and low conflict is not influenced.
Fig. 3, 12, 14, 16, and 18 are used as examples to describe the database system according to the embodiment of the present invention.
Fig. 3 is a schematic diagram of a database system according to an embodiment of the present invention. As shown in fig. 3, the database system may include: SQL engine 310, adaptation module 320, transaction management module 330, and storage engine 340.
Fig. 3 is different from fig. 2 in that an adaptive module 320 is included in the database system according to an embodiment of the present invention. The transaction management module 330 may include a plurality of concurrency control units, e.g., a first concurrency control unit and a second concurrency control unit. And the adaptive module 320 is configured to select the transaction of the first concurrency control unit or the second concurrency control unit according to the statistics, the data of the summary operation, the transaction state, and other information.
In fig. 4, the adaptation module may include a switching unit 410 and a concurrency control selection unit 420. The adaptation module, after receiving a transaction, e.g., a first transaction, the first transaction may include first data, e.g., data a; the selection unit 420 is concurrently controlled. A switching unit 410 for determining a heat of the first data segment; a concurrency control selection unit 420, configured to select the first concurrency control unit or the second concurrency control unit to operate the first transaction according to the heat; when the database system executes a first transaction, the first data and the corresponding data segment in the database are first data segments; the heat is the ratio of the number of transactions cancelled in the first data segment per unit time to the number of transactions for all operations historically.
In one example, the switching unit 410 may determine the heat degree by a collision rate of a data segment corresponding to a certain data. The first transaction also comprises second data corresponding to the first transaction, the second data segment is a database data segment in which the second data falls when the first transaction is executed, and the first data segment is different from the second data segment; determining a heat of the first data segment, comprising: determining a heat of the second data segment.
For example, a corresponding second data segment DataSeg [ j ] is found according to second data of the first transaction operation, a conflict rate is calculated by per ═ DataSeg [ j ]. abort/(DataSeg [ j ]. abort + DataSeg [ j ]. commit), when per is greater than threshold da, the first concurrency control unit is selected to operate the first transaction, and when per is less than or equal to threshold da, the second concurrency control unit is selected to operate the first transaction.
In one example, the switching unit 410 may determine the degree of hotness by the overall collision rate of each data segment. The first transaction also comprises third data corresponding to the first transaction, and the third data segment is a database data segment in which the third data falls when the first transaction is executed; the data segment heat determination unit is specifically configured to: and determining the heat of the whole of the first data segment and the third data segment.
For example, when a first transaction operates on a plurality of data, a plurality of DataSeg [ M ] (0< M) corresponding to the data, for example, a first data segment and a third data segment, are acquired. All data segment collision rates per are calculated as (DataSeg [ j ]. abort + … + DataSeg [ z ]. abort)/(DataSeg [ j ]. abort + DataSeg [ j ]. commit + … + DataSeg [ z ]. abort + DataSeg [ z ]. commit). Judging the ratio per of cancelled transactions in all the data segments DataSeg [ j ] … DataSeg [ z ] to all the transactions (including cancelled and executed transactions) is the heat of the data operated by the current transaction, and when the conflict rate per of all the data segments is greater than threshold dA, selecting a first concurrency control unit to operate a first transaction; when per is less than or equal to threshold dA, then the second concurrency control unit is selected to operate on the first transaction.
Wherein threshold da represents a threshold value of what concurrency control is adopted and configured by a user. When the heat degree of the data segment (DataSeg [ j ]) is greater than a first threshold value, judging that the data segment (DataSeg [ j ]) is a hot data segment, and adopting a concurrent control selection unit 420 to operate a first transaction by adopting a first concurrent control unit; otherwise, when the heat degree of the data segment (DataSeg [ j ]) is less than or equal to the first threshold, the data segment (DataSeg [ j ]) is determined to be a cold data segment, and the concurrency control selection unit 420 is configured to operate the first transaction using the second concurrency control unit. Wherein if any one of the data is determined to be in the hot data segment, the whole transaction selects the first concurrent control unit to operate the transaction.
The cold and hot data segments are relatively distinguished, and can be more finely distinguished according to the heat of the data segments; the hot degree is that the number of the cancelled transactions in the unit time of the first data segment historically accounts for the number of the transactions of all the operations. A threshold such as approximately 60% of the heat of a data segment is considered a hot data segment; accordingly, the concurrency control selection module may employ multiple concurrency control strategies. Embodiments of the invention are described below, still in terms of hot and cold concepts. However, those skilled in the art will appreciate that embodiments may naturally extend to different concurrency control strategies at different hotness.
In one example, when the heat of the first data segment is greater than a first threshold, the concurrency control selection unit 420 selects the first concurrency control unit; the first concurrency control unit is used for determining whether a second transaction which is in anti-sequence dependence with the first transaction exists or not, and when the second transaction which is in anti-sequence dependence with the first transaction exists, executing the first transaction; the anti-order depends on the data read for the first transaction being the data written by the second transaction, which writes the data later than the time the first transaction reads the data.
In one embodiment, when the heat of the first data segment is greater than a first threshold, the concurrency control selection unit 420 selects the first concurrency control unit; the first concurrency control unit is used for executing the first transaction when a second transaction which is in reverse order dependence with the first transaction does not exist and a third transaction which is in order dependence with the first transaction does not exist; the data read by the first transaction is the data written by the third transaction, and the data is written by the third transaction earlier than the data read by the first transaction.
In one embodiment, when the heat of the first data segment is greater than the first threshold, the concurrency control selection unit 420 selects the first concurrency control unit; the first concurrency control unit is used for canceling abort first transaction when a second transaction which is in reverse order dependence with the first transaction exists and a third transaction which is in order dependence with the first transaction exists; the data read by the first transaction is the data written by the third transaction, and the data written by the second transaction is earlier than the data read by the first transaction.
For convenience of description, the heat of a certain data segment corresponding to a certain data of the first transaction operation will be described as an example.
In one example, the switching unit 410 is further configured to dynamically switch the cold data and the hot data in the background according to the transaction end state and the data of the operation. For example, the switching unit 410 is configured to dynamically switch the cold data and the hot data in the background according to the first transaction ending status and the first data of the operation. After the first transaction executes (commit)/abort, the state and operation data of the first transaction are input into the adaptive module, and the information is added into the corresponding data segment structure.
Specifically, the first transaction state update means that the transaction state and the operation data are transmitted to the adaptive module, and the information is added into the corresponding data segment structure, so as to update the heat degree of the first data segment, and make a basis for selecting concurrency control according to the heat degree of the first data segment next time. The first transaction status update is described in detail below by the data segment structure. The first transaction status update is described herein only in terms of a data segment structure, and other ways of updating the first transaction status are not described herein.
Figure GDA0001543120510000071
Figure GDA0001543120510000081
As indicated above, start, end mark the beginning, end position of the data segment, all data segments are unique and non-overlapping, and all data segments are concatenated to be [ "", FF), representing the entire data interval. abort represents the transaction count cancelled on the current data segment. commit represents the transaction count cancelled on the current data segment. Conflict [ N ] exists in the data segment DataSeg structure and is used for recording conflicting transaction information, and Conflict [ N ] is ordered by key. The key represents the key value of the transaction conflict. abort represents the transaction count of conflicts from the key0- > keyN range. commit represents the successful transaction count from the key0- > keyN range. As shown in fig. 5, the data set of the first transaction end state and the operation is finally returned to the data segment structure, so as to update the transaction state and the heat of the first data segment.
In one example, the database system further includes splitting/merging the data segments after the transaction status update. As shown in fig. 6, immediately after the database is started, the entire data segment is a cold data segment. As transaction concurrency increases, portions of hot data may appear. The adaptation module splits the hot data segment into a hot data segment and a cold data segment. After the hot data segment becomes a cold data segment, it is merged with the adjacent cold data segment. At the same time, the hot data segment is also merged with the adjacent hot data segment.
Specifically, the data segment splitting includes the following steps:
the first step is as follows: circulating all the DataSeg [ M ], and if the conflict rate is more than threshold dB, splitting the DataSeg;
the second step is as follows: circulating all DataSeg [ i ]. Conflict [ N ], finding out Conflict in which all DataSeg [ i ]. Conflict [ i ] > threshold dB, and splitting the DataSeg [ i ] into a plurality of cold and hot DataSegs;
the third step: circulating all DataSeg [ M ], and temporarily not processing the data in response to the conflict rate being less than or equal to threshold dB;
the data segment merging comprises the following steps:
the first step is as follows: cycling through two consecutive DataSeg [ i ] and DataSeg [ j ], in response to both collision rates being < threshold dB, considering that the 3 DataSegs can be merged into one;
the second step is as follows: merging DataSeg [ i ] start, end, abort, commit data with DataSeg [ j ];
the third step: merging the DataSeg [ i ]. Conflict [ i ] with the data with DataSeg [ j ]. Conflict [ ], wherein each of the 3 Conflict arrays is reduced by 50%;
the fourth step: cycling through two consecutive DataSeg [ i ] and DataSeg [ j ], in response to a collision rate > threshold dB, considering that the 3 DataSegs can be merged into one;
fifth, the method comprises the following steps: and in response to the collision rates of two continuous DataSeg [ i ] and DataSeg [ j ] being one greater than threshold dB and one less than or equal to threshold dB, the data are not processed for the time being.
In one example, threshold dB is a user-configured DataSeg [ i ] that can be split into multiple DataSegs when a specified collision rate is reached. Based on the splitting/merging and cold and hot state change of the data segments, the method is mainly used for recording the relation between the state of the transaction and the data segments of the operation, and further dynamically switching the whole database/a certain data segment/a certain key and the like to adopt different concurrency control methods.
In one example, a data segment (DataSeg) refers to detailed information including the number of cancellations, the number of executions (commit), and the conflicting data to operate on the data segment transaction.
It should be noted that the adaptive module 320 is a background module, and is configured to provide a concurrency control selection interface to the outside, receive transaction information transmitted from the outside to update an internal state, and refresh cold and hot information of a data segment at regular time inside.
In an embodiment of the present invention, the first concurrency control unit may be configured to implement an optimistic concurrency control method. The second optimistic concurrency control unit can be used for realizing the flexible optimistic concurrency control method, and logic judgment is added on the basis of the first optimistic concurrency control unit by the second optimistic concurrency control unit, so that the transaction is prevented from being cancelled by mistake. The second concurrency control unit is a flexible transformation of the first concurrency control unit, still adopts the transaction detection flow of the first concurrency control unit, and is different from the following steps: in the transaction judgment stage, more methods such as condition limitation/model calculation are adopted to determine whether the transaction needs to be cancelled, so that the error cancellation of the transaction is reduced, and the performance is improved. For convenience of description, the first concurrency control unit is abbreviated as Flexible OCC, and the second concurrency control unit is abbreviated as OCC.
Fig. 7 is a flowchart of a database access method according to an embodiment of the present invention. As shown in fig. 7, the database access method may include the steps of:
s710: the user initiates a transaction initiation, e.g., a first transaction T1;
s720: completing operations (addition, deletion, modification and check) on the first data (assuming that the data a is operated) in the first transaction;
s730: when a first transaction enters a transaction confirmation stage, judging and selecting an OCC or a Flexible OCC by an adaptive module according to first data a operated by the first transaction to operate the first transaction;
the transaction confirmation phase in S730 may include the following steps
The first step is as follows: circulating all data of the first transaction operation, and judging whether the data are in a hot section or not; when the data is not in the hot data segment, continuing to circularly process the next piece of data; when the data is in the hot data segment, executing a second step;
the second step is as follows: determining whether a collision rate of the hot data segments exceeds a user-set threshold, e.g., a first threshold; when the conflict rate of the hot data segment exceeds a first threshold value, a loop is skipped, and a Flexible OCC method is used for the first transaction; when the first threshold value is not exceeded, turning to the first step, and starting to process the next piece of data;
the third step: at the end of the cycle, all data for the first transaction operation, not in the hot section, the OCC method is used.
It should be noted that, if the OCC is required to be adopted to acquire the transaction from the adaptive module, OCC determination is required.
In one example, the first transaction further includes second data corresponding to the first transaction, the second data segment being a database data segment into which the second data falls when the first transaction is executed, the first data segment being different from the second data segment; determining a heat of the first data segment, comprising: the heat of the second data segment is determined.
Specifically, among a plurality of data of the first transaction operation, the heat is judged by the collision rate of the data segment corresponding to a certain data. Since the first data segment and the second data segment are independent data segments, the heat can be judged according to the collision rate of the first data segment or the second data segment. For example, a corresponding first data segment DataSeg [ j ] is found according to first data of a first transaction operation, a conflict rate is calculated by per ═ DataSeg [ j ]. abort/(DataSeg [ j ]. abort + DataSeg [ j ]. commit), when per is greater than threshold da, the Flexible OCC is selected to operate the first transaction, and when per is less than or equal to threshold da, the OCC is selected to operate the first transaction.
In one example, the heat may be determined by a collision rate of data segments corresponding to a certain data. The first transaction also comprises second data corresponding to the first transaction, the second data segment is a database data segment in which the second data falls when the first transaction is executed, and the first data segment is different from the second data segment; determining a heat of the first data segment, comprising: determining a heat of the second data segment.
For example, a corresponding second data segment DataSeg [ j ] is found according to second data of the first transaction operation, a conflict rate is calculated by per ═ DataSeg [ j ]. abort/(DataSeg [ j ]. abort + DataSeg [ j ]. commit), when per is greater than threshold da, the first concurrency control unit is selected to operate the first transaction, and when per is less than or equal to threshold da, the second concurrency control unit is selected to operate the first transaction.
In one example, the heat may be determined by the overall collision rate of the data segments. The first transaction also comprises third data corresponding to the first transaction, and the third data segment is a database data segment in which the third data falls when the first transaction is executed; the data segment heat determination unit is specifically configured to: and determining the heat of the whole of the first data segment and the third data segment.
For example, when a first transaction operates on a plurality of data, a plurality of DataSeg [ M ] (0< M) corresponding to the data, for example, a first data segment and a third data segment, are acquired. All data segment collision rates per are calculated as (DataSeg [ j ]. abort + … + DataSeg [ z ]. abort)/(DataSeg [ j ]. abort + DataSeg [ j ]. commit + … + DataSeg [ z ]. abort + DataSeg [ z ]. commit). Judging the ratio per of cancelled transactions in all the data segments DataSeg [ j ] … DataSeg [ z ] to all the transactions (including cancelled and executed transactions) is the heat of the data operated by the current transaction, and when the conflict rate per of all the data segments is greater than threshold dA, selecting a first concurrency control unit to operate a first transaction; when per is less than or equal to threshold dA, then the second concurrency control unit is selected to operate on the first transaction.
Wherein threshold da represents a threshold value of what concurrency control is adopted and configured by a user. When the heat degree of the data segment (DataSeg [ j ]) is greater than a first threshold value, judging that the data segment (DataSeg [ j ]) is a hot data segment, and adopting a concurrent control selection unit 310 to operate a first transaction by adopting a first concurrent control unit; otherwise, when the heat degree of the data segment (DataSeg [ j ]) is less than or equal to the first threshold, the data segment (DataSeg [ j ]) is determined to be a cold data segment, and the concurrency control selection unit 310 is configured to operate the first transaction using the second concurrency control unit. Wherein if any one of the data is determined to be in the hot data segment, the whole transaction selects the first concurrent control unit to operate the transaction.
The cold and hot data segments are relatively distinguished, and can be more finely distinguished according to the heat of the data segments; the hot degree is that the number of the cancelled transactions in the unit time of the first data segment historically accounts for the number of the transactions of all the operations. A threshold such as approximately 60% of the heat of a data segment is considered a hot data segment; accordingly, the concurrency control selection module may employ multiple concurrency control strategies. Embodiments of the invention are described below, still in terms of hot and cold concepts. However, those skilled in the art will appreciate that embodiments may naturally extend to different concurrency control strategies at different hotness.
In fig. 8, the Flexible OCC method may include the steps of:
s810: judging whether a second transaction which is in anti-sequence dependence with the first transaction exists; when present, S820 is performed, and when not present, S840 is performed.
S820: judging whether a third transaction which is sequentially dependent on the first transaction exists; when present, S830 is performed, and when not present, S840 is performed.
S830: abort first transaction.
S840: the first transaction continues to be executed.
The data read by the first transaction is the data written by the second transaction, and the data written by the second transaction is later than the data read by the first transaction.
The OCC process may include the steps of: judging whether a third transaction which is sequentially dependent on the first transaction exists; when present, abort executes the first transaction; when not present, the first transaction is executed.
As can be seen from the above, the Flexible OCC is an OCC Flexible transformation, and it still adopts the transaction detection process of the OCC, and the differences are as follows: in the transaction judgment stage, more methods such as condition limitation/model calculation (the increased resource consumption needs to be controlled within a certain range) are adopted to determine whether the transaction really needs to be aborted, so that the error abort of the transaction is reduced, and the performance is improved.
Wherein, in S810, the first transaction is involved in being sequentially dependent on the second transaction, and the step includes performing wr or ww or rw on the data operated by the first transaction, where wr indicates that the data read by the first transaction is the data that has been written by other transactions before; ww indicates that the data of the first transaction operation is the data written by other transactions before; rw indicates that the data of the first transaction operation is the data read by other previous transactions.
The sequential dependency and the anti-sequential dependency in fig. 8 will be described in detail below with reference to fig. 9 and 10.
Fig. 9 is a sequence dependency diagram. As shown in FIG. 9, a sequential dependency (read-after-write) refers to transaction 1 writing A, transaction 2 reading A writing B, and transaction 3 reading B writing C, then transaction 2 is considered dependent on transaction 1 and transaction 3 is dependent on transaction 2.
Fig. 10 is an inverse order dependency diagram. An anti-order dependency (write-after-read) means that transaction 1 writes B first, transaction 2 reads B, and transaction 3 writes B again, then transaction 2 depends anti-order on transaction 3, as in FIG. 1 with transaction T1 relying anti-order on transaction T2.
S740: and if the determination is passed in the transaction confirmation phase, submitting the first transaction, otherwise, returning the state of the end of the first transaction and the data of the operation to the self-adaptive module.
Specifically, the transaction status update means that the transaction status and the operation data are input into the adaptive module, and the information is added into the corresponding data segment structure, so as to update the heat of the first data segment. The first transaction status update is described in detail below by the data segment structure.
DataSeg [ ] ds; // all data segments comprising the entire database, each data segment reflecting a collision rate
struct DataSeg {// denotes current data segment information
Start,// denotes the current data segment start position
end,// denotes the current data segment end position
abort,// denotes the transaction count of the current data segment abort
commit,// denotes the transaction count of the current data segment commit
Conflict [ N ],// where N is a constant
struct Conflict {// exists in DataSeg structure for recording conflicting transaction information, Conflict [ N ] is ordered by key
key,// key value of transaction conflict
Transaction count for conflicts in the abort,// keyI- > keyJ range
Commit,// keyI- > keyJ range conflict transaction count
}
As indicated above, start, end mark the beginning, end position of the data segment, all data segments are unique and non-overlapping, and all data segments are concatenated to be [ "", FF), representing the entire data interval. abort represents the transaction count cancelled on the current data segment. commit represents the transaction count cancelled on the current data segment. Conflict [ N ] exists in the data segment DataSeg structure and is used for recording conflicting transaction information, and Conflict [ N ] is ordered by key. The key represents the key value of the transaction conflict. abort represents the transaction count of conflicts from the key0- > keyN range. commit represents the successful transaction count from the key0- > keyN range. As shown in FIG. 5, the transaction end state and the data set of the operation are finally returned to the data segment structure, so as to update the transaction state and the heat of the first data segment.
In addition, the transaction state update also comprises splitting/merging the data segments. Fig. 6 is a schematic diagram of data segment splitting/merging according to an embodiment of the present invention. As shown in fig. 6, immediately after the database is started, the entire data segment is a cold data segment. As transaction concurrency increases, portions of hot data may appear. In an example, the data segment heat determination module may split a hot data segment into a hot data segment and a cold data segment. After the hot data segment becomes a cold data segment, it is merged with the adjacent cold data segment. Meanwhile, the hot data is merged with the adjacent hot data segment.
The splitting/merging S1142 of the data segment in fig. 11 will be described in detail below. S1110, S1120, and S1130 in fig. 11 refer to descriptions of S710, S720, and S730 in fig. 7, and the content of the portion S1141 refers to the description of fig. 5, which is not repeated herein.
The data segment splitting comprises the following steps:
the first step is as follows: circulating all the DataSeg [ M ], and if the conflict rate is more than threshold dB, splitting the DataSeg;
the second step is as follows: circulating all DataSeg [ i ]. Conflict [ N ], finding out Conflict in which all DataSeg [ i ]. Conflict [ i ] > threshold dB, and splitting the DataSeg [ i ] into a plurality of cold and hot DataSegs;
the third step: circulating all DataSeg [ M ], and temporarily not processing the data in response to the conflict rate being less than or equal to threshold dB;
the data segment merging comprises the following steps:
the first step is as follows: cycling through two consecutive DataSeg [ i ] and DataSeg [ j ], in response to both collision rates being < threshold dB, considering that the 2 DataSegs can be merged into one;
the second step is as follows: merging DataSeg [ i ] start, end, abort, commit data with DataSeg [ j ];
the third step: merging the DataSeg [ i ]. Conflict [ i ] with the data and DataSeg [ j ]. Conflict [ ], wherein each of the 2 Conflict arrays is reduced by 50%;
the fourth step: cycling through two consecutive DataSeg [ i ] and DataSeg [ j ], in response to a collision rate > threshold dB, considering that the 2 DataSegs can be merged into one;
the fifth step: and in response to the collision rates of two continuous DataSeg [ i ] and DataSeg [ j ] being one greater than threshold dB and one less than or equal to threshold dB, the data are not processed for the time being.
In one example, threshold dB is a user-configured DataSeg [ i ] that can be split into multiple DataSegs when a specified collision rate is reached. Based on the splitting/merging and cold and hot state change of the data segments, the method is mainly used for recording the relation between the state of the transaction and the data segments of the operation, and further dynamically switching the whole database/a certain data segment/a certain key and the like to adopt different concurrency control methods. In one example, a data segment (DataSeg) refers to detailed information including the number of cancellations, the number of executions (commit), and the conflicting data to operate on the data segment transaction.
In the embodiment of the invention, an optimistic concurrency control method OCC is improved, a Flexible optimistic concurrency control method OCC is provided, and the problems that a system error is high to cancel and the number of integral executable transactions per second (tps) is reduced when the optimistic concurrency control method is high in concurrency and data hotspots are concentrated are solved. Fig. 12 is a schematic structural diagram of a database system according to an embodiment of the present invention. The database system can configure the process starting command configuration of the database system according to the deployment requirement of the service, for example:
--disable-adaptive-module=true--concurrent-control=FOCC;
through the configuration, the adaptive module only adopts the Flexible OCC 1232 to perform conflict detection and judgment on the transaction. As shown in fig. 12, namely: closing the path (1), and only using the path (2) as transaction conflict detection, which is equivalent to that the current database system only uses the Flexible OCC 1232 for concurrent control.
--disable-adaptive-module=true--concurrent-control=OCC;
Through the configuration, the adaptive module is closed, and only OCC 1231 is adopted to perform conflict detection and judgment on the transaction. As shown in fig. 12, namely: closing the path (1), and only using the path (3) as transaction conflict detection, which is equivalent to that the current database system only uses the OCC 1231 for concurrent control.
The database system shown in fig. 12 will be described in detail below with reference to fig. 13.
Fig. 13 is a flowchart of a database access method according to an embodiment of the present invention. As shown in fig. 13, the method comprises the following steps:
the first step is as follows: initiating transaction starting by a user;
the second step is as follows: executing SQL sentences to complete the operations of reading, changing and writing data in the earlier stage;
the third step: when the transaction enters a confirmation stage, acquiring a corresponding conflict rate from the self-adaptive module according to a data set of transaction operation;
the fourth step: and according to the acquired conflict rate and a threshold value threshold (the flexible optimistic concurrency control method is used when the conflict rate exceeds the threshold value, otherwise, the optimistic concurrency control method is used), judging whether the transaction adopts the flexible optimistic concurrency control method or the optimistic concurrency control method.
When the transaction enters the confirmation phase, the method can comprise the following steps:
s1310: all data segments of the round robin transaction;
s1320: judging whether the heat degree of the data segment is greater than threshold dA or not; when greater than threshold da, then S1340 is performed; when the data is not greater than threshold dA, go to S1310 to continue processing the next piece of data;
s1330: when the circulation is ended and all data are not judged to be hot data, an OCC method is used;
s1340: the loop is popped out and the entire transaction uses the flexile OCC method.
The embodiment of the invention is self-adaptive according to the data hot spot, and the transaction detection is more flexible. The adaptive internal logic may be dynamically transformed. And multiple optimistic concurrency control methods are adopted, so that performance reduction caused by a single method is avoided.
Fig. 14 is a schematic diagram of a database system according to an embodiment of the present invention, where the database system may further use a user-defined dataset, where the user-defined dataset may be preset by a user, and the user-defined dataset may be a hot dataset or a cold dataset. Fig. 14 differs from fig. 3 in that the database system in fig. 14 further includes a custom data set module 1450, and the adaptation module 1420 can support user-defined pre-configuration to implement user-specified hot data set and cold data set.
In FIG. 14, both adaptation module 1420 and user-customized data sets may be used to select OCC 1431 or Flexible OCC 1432 to operate on the first transaction. For example, the following configuration is adopted:
-adaptive 1-user _ data _ filter 1// even if adaptation is used, also user-defined data sets are used.
The adaptive module 1420, through the pre-configuration, enables the database system to make reference to the user-defined data set when selecting the concurrency control method.
Specifically, before the data of the first transaction operation enters the adaptive module 1420, it is determined whether there is a user-defined hotspot data set; if the user-defined hotspot data set exists, judging whether the data of the first transaction operation is the hotspot data in the user-defined data set, otherwise, transferring the data of the first transaction operation to the self-adaptive module 1420 for detection; if the data of the first transaction operation is the hot spot data in the user-defined data set, the first transaction is operated by adopting a Flexible OCC 1432, otherwise, the data of the first transaction operation is transferred to the self-adapting module 1420 for detection; detecting the data of the first transaction operation by the adaptive module 1420, determining whether the data of the first transaction operation is data in a hot spot data set, if the data of the first transaction operation is data in the hot spot data set, determining whether the heat of the hot spot data set is greater than a first threshold, if the heat is greater than the first threshold, determining whether the data of the first transaction operation is user-defined cold data, otherwise, detecting the data of the first transaction operation by the adaptive module 1420; if the cold data is not user-defined cold data, a Flexible OCC 1432 is adopted to operate the first transaction, otherwise, the data operated by the first transaction is transferred to the self-adaptive module 1420 to be detected; if the heat degree is less than or equal to the first threshold value, the data of the first transaction operation is transferred to the self-adapting module 1420 for detection, and whether all the data of the first transaction operation is the data in the hot spot data set is determined in a loop, and if all the data of the first transaction operation is not the data in the hot spot data set in the database, the first transaction is operated by using the OCC 1431.
The adaptation module 1420 may implement user-specified hot and cold data sets by configuring the files referenced to this custom data set in the concurrent control selection.
data.filter
Filter represents a user-defined dataset
# Format
##type,database,tablename,columname,columntype,startkey,endkey
Type # indicates whether hot data, 0: hot spot, 1: a non-hotspot; database represents a database name; tablename represents a table name; column name represents the column name; column type, determining data range; startkey represents a start key; endkey represents an end key;
0, db1, stock, s _ quality, int # # such as: corresponding to the table data column when the warehouse-1 operates, as long as the key prefix is encountered, the data is regarded as hot data; db1 denotes the database name; stock represents a table name; s _ quality represents a column name;
1 db1, warthouse, item, id # # this data is excluded from the hot data; db1 denotes the database name; wartouse represents a table name; item denotes a column name.
Next, the operation of the database system in fig. 14 will be described with reference to fig. 15. Fig. 15 is a flowchart of a database access method according to the third embodiment of the present invention. FIG. 14 differs from FIG. 12 only in that the data for the transaction operation is determined from the custom data set before the adaptive module determines the heat of the data segment. Please refer to fig. 12 for the content related to the heat judgment of the data segment. As shown in fig. 15, the method comprises the following steps:
s1510: before data of the transaction operation enters the self-adaptive module, judging whether a user-defined data set exists, for example, judging whether a user-defined hot data set exists; when a user-defined hot data set exists, executing S1520; when there is no user-defined hot data, S1530 is executed;
s1520: when a user-defined hot data set exists, judging by using the user-defined hot data set, and judging whether the data of the transaction operation is the user-defined hot data; when the operated data is the self-defined hot data, executing S1570; when the operated data is not the custom hot data, S1530 is performed;
s1530: when the data of the transaction operation is not the user-defined hot data, the self-adaptive module is switched to detect again;
s1540: judging whether the heat degree of a data segment corresponding to the data of the transaction operation exceeds a threshold value A or not; when the heat of the data segment exceeds the threshold value A, executing S1560; when the heat of the data segment does not exceed the threshold value A, go to S1530;
s1550: operating the transaction with the OCC;
s1560: judging whether the data of the transaction operation is user-defined cold data or not; when the data is not the user-defined cold data, S1530 is performed; when the data is user-defined cold data, executing S1570;
s1570: the transaction is operated on with a flexile OCC.
Fig. 16 is a schematic structural diagram of a database system according to an embodiment of the present invention. As shown in fig. 16, the database system is only in accordance with user-customized data sets. FIG. 16 differs from FIG. 14 in that the adaptive module is not provided in FIG. 16, but rather the first transaction is handled by the custom data set module 1620, discriminative selection OCC 1631 or Flexible OCC 1632. For example, the custom data set module 1620 is set with the following configuration: .
-adaptive 0-user _ data _ filter 1// using only user-defined data sets.
Specifically, whether a user-defined hotspot data set exists is judged, if the user-defined hotspot data set exists, all data of the first transaction operation are circulated, otherwise, the OCC 1631 is adopted to operate the first transaction; if the data operated by the first transaction is the user-defined hot spot data, operating the first transaction by adopting a Flexible OCC 1632; if all the data operated on by the first transaction is not user-defined data, the first transaction is operated on with OCC 1631.
The flow corresponding to the multi-threshold database system shown in fig. 16 will be described in detail with reference to fig. 17.
FIG. 17 provides a fourth flow chart of database access for an embodiment of the present invention. As shown in fig. 17, the method comprises the following steps:
s1710: judging whether a user-defined hot data set is configured or not;
when the user only configures the user-defined data set, turning to S1720;
s1720: in the transaction confirmation judging stage, circulating all data of the transaction operation;
s1730: is the data determined to be user-defined hot data? When the data is the user-defined hot data, go to S1740; when the data is not the user-defined hot data, turning to S1720 to cycle the next piece of data;
s1740: adopting a flexible optimistic concurrency control method to judge the affairs, and turning to S1760 after the affairs are judged;
s1750: adopting an optimistic concurrency control method to judge the affairs, and turning to S1760 after the affairs are judged;
s1760: the transaction is ended.
Finally, the embodiment of the invention provides a database access method and a database system in which two/multiple concurrent controls exist and operate simultaneously, and N concurrent control methods can be allowed to exist in the system simultaneously, so that a user can select which concurrent control is used for determining the ACID of a transaction through a threshold control method, and the problem that the whole system adopts single concurrent control to cause more extra overhead due to local hot data is avoided (for example, an optimistic concurrent control method can be still adopted for a transaction without operating hot data).
Fig. 18 is a schematic structural diagram of a database system according to an embodiment of the present invention. In comparison with fig. 3, fig. 18 shows that the transaction management module 1830 includes multiple concurrency control units. In an example, the transaction management module 1830 includes a variety of concurrency control units, such as OCC, concurrency control (a), and concurrency control (B). The adaptation module 1820 of embodiments of the present invention is adapted such that the transaction management module 1830 includes a variety of concurrency control units.
In an example, a plurality of threshold intervals are configured by a user to correspond to different optimistic concurrency controls, wherein a threshold 1 is used for an optimistic concurrency control unit, a threshold 2 is used for a concurrency control unit (a), and a threshold 3 is used for a concurrency control unit (B). In an example, N concurrent controls are run simultaneously according to an implementation that configures multiple threshold intervals.
A user can configure a detection threshold value of the self-adaptive module 1820 to control which concurrent control is used under what conditions, internal logic of the self-adaptive module 1820 can be dynamically changed, self-adaptation is made according to data hot spots, and transaction detection is more flexible. The adaptive threshold (data segment splitting/merging control parameter) can also be customized by a user, so that the user can customize the adaptive threshold. The flexible optimistic concurrency control unit does not cause a large number of false cancellations when determining hot data.
The database system shown in fig. 18 will be described in detail below with reference to fig. 19.
Fig. 19 is a flowchart of a database access method according to an embodiment of the present invention. Taking the concurrency control N, the concurrency control M, and the concurrency control P as an example, as shown in fig. 19, when the adaptive module performs the selection of the concurrency control method, the determination according to the current collision rate may include the following steps:
s1910, the conflict rate determination module judges whether the conflict rate is greater than a threshold value N? The concurrency control selection module responds to the fact that the conflict rate is larger than a threshold value N, and uses a concurrency control method N; the concurrency control selection module responds to the fact that the conflict rate is not larger than the threshold value N, and then the step S1920 is carried out;
s1920, is the collision rate determination module determine whether the collision rate is greater than the threshold M? The concurrency control selection module responds to the fact that the conflict rate is larger than a threshold value M, and uses a concurrency control method M; the concurrency control selection module responds to the condition that the conflict rate is not greater than the threshold value M, and then S1930 is carried out;
s1930 is the collision rate determination module determining whether the collision rate is greater than a threshold value P? The concurrency control selection module responds to the fact that the conflict rate is larger than a threshold value P, and uses a concurrency control method P; and the concurrency control selection module adopts an optimistic concurrency control method in response to the conflict rate not being greater than the threshold value P.
The database system and the database access method provided by the embodiment of the invention improve the transaction management module, solve the problem that when the transaction runs concurrently and conflicts are high, dynamically adopt various optimistic concurrency control algorithms to ensure the correctness of the transaction, avoid the performance reduction caused by a single method and improve the throughput of the whole system.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
Those of skill would further appreciate that the various illustrative components and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the components and combinations of the examples have been described above generally in terms of their functionality in order to clearly illustrate their interchangeability. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The methods or algorithms described in connection with the embodiments disclosed herein may be embodied in hardware, a software module executed by a processor module, or a combination of both. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above embodiments are provided to further explain the objects, technical solutions and advantages of the present invention in detail, it should be understood that the above embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalents, improvements, etc. made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (27)

1. A database system, comprising: the system comprises a Structured Query Language (SQL) engine, a self-adaptive module and a transaction management module; the self-adaptive module comprises a switching unit and a concurrency control selection unit; the transaction management module comprises a first concurrency control unit;
the SQL engine is used for receiving a first transaction, and the first transaction comprises corresponding first data;
the switching unit is used for determining the heat degree of the first data segment; the first data segment is a database data segment in which first data falls when a first transaction is executed, and the heat degree of the first data segment is the proportion of the number of cancelled transactions in unit time of the first data segment in history to the number of transactions of all operations;
the concurrency control selection unit selects the first concurrency control unit when the heat degree of the first data segment is greater than a first threshold value; the first concurrency control unit is used for determining whether a second transaction exists or not, and executing the first transaction when the second transaction does not exist; the data read by the first transaction is the data written by the second transaction, and the time for writing the data by the second transaction is later than the time for reading the data by the first transaction.
2. The system of claim 1, wherein the first concurrent control unit is further configured to:
when the second transaction exists and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data is written by the third transaction earlier than the data read by the first transaction.
3. The system of claim 1, wherein the first concurrent control unit is further configured to:
and canceling the first transaction when the second transaction and a third transaction exist, wherein the data read by the first transaction is the data written by the third transaction, and the time for writing the data by the third transaction is earlier than the time for reading the data by the first transaction.
4. The system of claim 1, wherein the transaction management module further comprises a second concurrency control unit;
the concurrency control selection unit is further used for selecting a second concurrency control unit when the heat degree of the first data segment is larger than a second threshold value; the second concurrency control unit executes the first transaction by adopting an optimistic concurrency control method; wherein the second threshold is less than or equal to the first threshold.
5. The system of claim 1, wherein the first transaction further comprises second data corresponding to the first transaction, the second data segment being a database data segment into which the second data falls when the first transaction is executed, the first data segment being different from the second data segment;
the switching unit is specifically configured to: determining a heat of the second data segment.
6. The system of claim 1, wherein the first transaction further comprises third data corresponding to the first transaction, and the third data segment is a database data segment into which the third data falls when the first transaction is executed;
the switching unit is specifically configured to: and determining the heat of the whole of the first data segment and the third data segment.
7. The system according to any of claims 1-6, wherein the switching unit is further configured to:
and updating the heat degree of the first data segment.
8. The system of claim 1, further comprising a custom data set module: and the user-defined data set module is used for determining whether the first data falls into a preset first data set.
9. The system of claim 8, wherein the custom data set module is further configured to:
when the first data does not fall into the preset first data set and the heat degree of the first data segment is larger than the first threshold value, determining whether the first data falls into a preset second data set.
10. A database system, comprising: the system comprises an SQL engine, a user-defined data set module and a transaction management module; wherein the transaction management module comprises a first concurrency control unit;
an SQL engine to receive a first transaction, the first transaction including first data;
the user-defined data set module is used for determining whether the first data falls into a preset first data set;
when the first data falls into the preset first data set, the first concurrency control unit is used for determining whether a second transaction exists or not, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the time for writing the data by the second transaction is later than the time for reading the data by the first transaction.
11. The system of claim 10, wherein the first concurrent control unit is further configured to:
and when the first data falls into the preset first data set, the second transaction exists and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the time for writing the data by the third transaction is earlier than the time for reading the data by the first transaction.
12. The system of claim 10, wherein the first concurrent control unit is further configured to:
and when the first data falls into the preset first data set and the second transaction and the third transaction exist, canceling the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the time for writing the data by the third transaction is earlier than the time for reading the data by the first transaction.
13. The system of claim 10, wherein the transaction management module further comprises: a second concurrency control unit;
and the second concurrency control unit is used for executing the first transaction by adopting an optimistic concurrency control method when the first data does not fall into the preset first data set.
14. A database access method, comprising:
receiving a first transaction, the first transaction comprising first data;
determining a heat of the first data segment; the first data segment is a database data segment in which first data falls when a first transaction is executed, and the heat degree of the first data segment is the proportion of the number of cancelled transactions in unit time of the first data segment in history to the number of transactions of all operations;
when the heat degree of the first data segment is larger than a first threshold value, determining whether a second transaction exists, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the time for writing the data by the second transaction is later than the time for reading the data by the first transaction.
15. The method of claim 14, further comprising:
and when the heat of a first data segment is greater than a first threshold, the second transaction exists, and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the data is written by the third transaction earlier than the data read by the first transaction.
16. The method of claim 14, further comprising:
and canceling the first transaction when the heat of the first data segment is greater than a first threshold value and the second transaction and a third transaction exist, wherein the data read by the first transaction is the data written by the third transaction, and the data written by the third transaction is earlier than the data read by the first transaction.
17. The method of claim 14, further comprising:
when the heat degree of the first data segment is larger than a second threshold value, executing a first transaction by adopting an optimistic concurrency control method; wherein the second threshold is less than or equal to the first threshold.
18. The method of claim 14, wherein the first transaction further comprises second data corresponding to the first transaction, wherein the second data segment is a database data segment into which the second data falls when the first transaction is executed, and wherein the first data segment is different from the second data segment;
determining a heat of the first data segment, comprising:
determining a heat of the second data segment.
19. The method of claim 14, wherein the first transaction further comprises third data corresponding to the first transaction, and wherein the third data segment is a database data segment into which the third data falls when the first transaction is executed;
determining a heat of the first data segment, comprising:
and determining the heat of the whole of the first data segment and the third data segment.
20. The method according to any one of claims 14-19, further comprising: and updating the heat degree of the first data segment.
21. The method of claim 14, wherein prior to said determining the heat of the first data segment, the method further comprises:
it is determined whether the first data falls within a preset first data set.
22. The method of claim 21, further comprising:
when the first data does not fall into the preset first data set and the heat degree of the first data segment is larger than the first threshold value, determining whether the first data falls into a preset second data set.
23. A database access method, comprising:
receiving a first transaction, the first transaction comprising first data;
determining whether the first data falls into a preset first data set;
when the first data falls into the preset first data set, determining whether a second transaction exists, and when the second transaction does not exist, executing the first transaction; the data read by the first transaction is the data written by the second transaction, and the time for writing the data by the second transaction is later than the time for reading the data by the first transaction.
24. The method of claim 23, further comprising:
and when the first data falls into the preset first data set, the second transaction exists and a third transaction does not exist, executing the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the time for writing the data by the third transaction is earlier than the time for reading the data by the first transaction.
25. The method of claim 23, further comprising:
and when the first data falls into the preset first data set and the second transaction and the third transaction exist, canceling the first transaction, wherein the data read by the first transaction is the data written by the third transaction, and the time for writing the data by the third transaction is earlier than the time for reading the data by the first transaction.
26. The method of claim 23, further comprising:
and when the first data does not fall into the preset first data set, executing a first transaction by adopting an optimistic concurrency control method.
27. A computer-readable storage medium storing a program, the program comprising instructions for performing the method of any of claims 14-26.
CN201711271123.9A 2017-12-05 2017-12-05 Database system and database access method Active CN110019468B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711271123.9A CN110019468B (en) 2017-12-05 2017-12-05 Database system and database access method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711271123.9A CN110019468B (en) 2017-12-05 2017-12-05 Database system and database access method

Publications (2)

Publication Number Publication Date
CN110019468A CN110019468A (en) 2019-07-16
CN110019468B true CN110019468B (en) 2021-07-16

Family

ID=67186525

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711271123.9A Active CN110019468B (en) 2017-12-05 2017-12-05 Database system and database access method

Country Status (1)

Country Link
CN (1) CN110019468B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112749004B (en) * 2019-10-30 2023-09-05 中国移动通信集团安徽有限公司 Data storage method and device based on node access heat
CN110955672B (en) * 2019-11-25 2023-03-24 上海交通大学 Multi-version support method and system for optimistic concurrency control
CN111736964B (en) * 2020-07-02 2021-08-06 腾讯科技(深圳)有限公司 Transaction processing method and device, computer equipment and storage medium
CN116755847B (en) * 2023-08-17 2023-11-14 北京遥感设备研究所 Log pre-analysis and transaction management method for relieving lock conflict
CN117667319B (en) * 2024-02-02 2024-05-03 建信金融科技有限责任公司 Transaction processing method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8103714B2 (en) * 2008-08-15 2012-01-24 International Business Machines Corporation Transactional quality of service in event stream processing middleware
CN102595446A (en) * 2012-02-17 2012-07-18 南京邮电大学 Wireless sensor network transaction coordination method
US8386421B2 (en) * 2010-06-28 2013-02-26 Microsoft Corporation Concurrency control for confluent trees
CN104487946A (en) * 2011-10-14 2015-04-01 英特尔公司 Method, apparatus, and system for adaptive thread scheduling in transactional memory systems

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8103714B2 (en) * 2008-08-15 2012-01-24 International Business Machines Corporation Transactional quality of service in event stream processing middleware
US8386421B2 (en) * 2010-06-28 2013-02-26 Microsoft Corporation Concurrency control for confluent trees
CN104487946A (en) * 2011-10-14 2015-04-01 英特尔公司 Method, apparatus, and system for adaptive thread scheduling in transactional memory systems
CN102595446A (en) * 2012-02-17 2012-07-18 南京邮电大学 Wireless sensor network transaction coordination method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Sybase SQL Server并发控制探讨;赵伟;《太原师范学院学报(自然科学版)》;20050830(第03期);第33-35页 *
安全的乐观实时并发控制策略;刘云生等;《微计算机应用》;20060715(第04期);第503-506页 *

Also Published As

Publication number Publication date
CN110019468A (en) 2019-07-16

Similar Documents

Publication Publication Date Title
CN110019468B (en) Database system and database access method
EP3111325B1 (en) Automatically retrying transactions with split procedure execution
CN109241093B (en) Data query method, related device and database system
EP3413215B1 (en) Dynamic snapshot isolation protocol selection
US8046354B2 (en) Method and apparatus for re-evaluating execution strategy for a database query
US8510316B2 (en) Database processing system and method
US20070156736A1 (en) Method and apparatus for automatically detecting a latent referential integrity relationship between different tables of a database
US20180181618A1 (en) Method and apparatus for optimizing database transactions
US20180300146A1 (en) Database operating method and apparatus
JP2018538634A (en) Database operating method and apparatus
US20170161353A1 (en) System, method and device for optimizing database operations
CN114282074B (en) Database operation method, device, equipment and storage medium
CN114003657A (en) Data processing method, system, device and storage medium for distributed database
CN105988899B (en) The method and apparatus for realizing data buffer storage
CN111930692B (en) Transaction merging execution method and device based on log analysis synchronization
CN106503027B (en) Database operation method and device
CN112612647A (en) Log parallel replay method, device, equipment and storage medium
CN107239474B (en) Data recording method and device
CN111930693B (en) Transaction merging execution method and device based on log analysis synchronization
US10754839B2 (en) Apparatus for data loading and data loading method
JPH0738165B2 (en) Database management method
US20150234656A1 (en) Vector processor, information processing apparatus, and overtaking control method
Zhu et al. CATS: A Computation-Aware Transaction Processing System with Proactive Unlocking
TW201828164A (en) Database operation method and device capable of improving transaction execution efficiency of database transaction with higher delivery amount of transactions
JPH10187523A (en) Method and system for sharing terminal information for loosely coupled system

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
GR01 Patent grant
GR01 Patent grant