WO2017041637A1 - Database operating method and device - Google Patents

Database operating method and device Download PDF

Info

Publication number
WO2017041637A1
WO2017041637A1 PCT/CN2016/097266 CN2016097266W WO2017041637A1 WO 2017041637 A1 WO2017041637 A1 WO 2017041637A1 CN 2016097266 W CN2016097266 W CN 2016097266W WO 2017041637 A1 WO2017041637 A1 WO 2017041637A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
operation instruction
instruction
database operation
execution
Prior art date
Application number
PCT/CN2016/097266
Other languages
French (fr)
Chinese (zh)
Inventor
王晶昱
Original Assignee
阿里巴巴集团控股有限公司
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 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2017041637A1 publication Critical patent/WO2017041637A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2315Optimistic concurrency control

Definitions

  • the present application relates to the field of database technologies, and in particular, to a database operation method and apparatus.
  • Database Transaction refers to a series of operations performed as a single logical unit of work, either completely or completely.
  • a transaction consists of a series of database operation instructions, such as Structured Query Language (SQL) statements. There are splitting conditions and jumps between these database operation instructions, meaning that the transaction is in one transaction. There may be some database operation instructions that are skipped and not executed.
  • SQL Structured Query Language
  • the execution judgment can only be performed according to the execution logic, and the statement in the transaction is sequentially executed to implement the operation on the database. This type of transaction execution is less efficient, especially when the transaction settings read committed isolation level is less efficient and has lower transaction throughput.
  • aspects of the present application provide a database operation method and apparatus for improving transaction execution efficiency and increasing transaction throughput.
  • An aspect of the present application provides a database operation method, including:
  • the operation instruction belongs to the prediction execution data generated by the prediction execution when the database type instruction is modified
  • the database corresponding to the application server is controlled to actually execute the target transaction according to the database operation instruction recorded locally and the predicted execution data.
  • a database operating device including:
  • An obtaining module configured to acquire the application service in sequence during execution of a target transaction by the application server a database operation instruction in the target transaction to which the device executes;
  • a predictive execution module configured to perform predictive execution on the database operation instruction, return a predicted execution result to the application server, for the application server to determine a next database operation instruction to be executed, and locally record the database operation And predicting execution data generated by the prediction execution when the database operation instruction belongs to modifying a database class instruction;
  • control execution module configured to: when the transaction commit instruction in the target transaction is obtained, control the database corresponding to the application server to actually execute the target transaction according to the database operation instruction recorded locally and the predicted execution data .
  • the database operating device cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and obtains and records all the database operation instructions that need to be executed in the target transaction in advance, and only for the instructions belonging to the modified database class.
  • the database operation instruction records the predicted execution data generated by the prediction execution to adapt to the read committed isolation level, provides conditions for the real execution of the transaction, and then controls the database corresponding to the application server to actually execute the target according to the recorded database operation instruction and the predicted execution data. Transactions help improve execution efficiency and increase transaction throughput.
  • FIG. 1 is a deployment diagram of a database application system in the prior art
  • FIG. 2 is a deployment diagram of a database application system according to an embodiment of the present application.
  • FIG. 3 is a schematic flowchart of a database operation method according to an embodiment of the present application.
  • FIG. 4 is a schematic structural diagram of a database operating device according to an embodiment of the present application.
  • FIG. 1 is a deployment diagram of a database application system in the prior art.
  • the system includes an application server 10 and a database 20.
  • the database 20 may be one or multiple. Only one database 20 is shown by way of example in FIG.
  • the application server 10 executes transaction logic to sequentially apply database operation instructions in the transaction to the database 20. Because the database operation instructions that need to be executed in the transaction cannot be known in advance, the transaction execution efficiency is low, especially when the configuration read commit isolation level is configured, the execution efficiency is lower and the transaction throughput is lower.
  • the present application provides a new database application system, as shown in FIG. 2 .
  • the system adds a database operating device 30 between the application server 10 and the database 20.
  • the database operating device 30 is configured to execute the database operation method provided by the present application, and implement a new transaction execution logic under the isolation level of the read commit, that is, the prediction execution is performed on the transaction, and the database operation to be performed in the transaction is obtained in advance.
  • the instruction, the prediction of the execution path is implemented, and the read execution level is submitted only for the database execution instruction record of the database operation instruction record belonging to the modified database class instruction, and the database operation instruction generated based on the prediction execution is executed.
  • predicting execution data actually executing transactions on the database 20 which is beneficial to improve transaction execution efficiency and increase transaction throughput.
  • Transaction throughput is the number of transactions processed per unit of time.
  • the database operating device 30 is actually a logical processing device, which can be deployed separately, between the application server 10 and the database 20, or deployed at one end of the application server 10, or can be deployed in the database 20. Implemented at one end.
  • FIG. 3 is a schematic flowchart diagram of a database operation method according to an embodiment of the present application. As shown in FIG. 3, the method includes:
  • the present embodiment refers to a transaction that the application server needs to perform as a target transaction.
  • the target transaction mainly includes operation instructions for operating on the database, and in addition to the database operation instructions, some control instructions for controlling the execution state of the target transaction, such as a transaction start instruction, a transaction commit instruction, a transaction rollback instruction, and the like.
  • These instructions are actually statements written in the database language. Depending on the database language, these instructions can be statements written in different languages. For example, if SQL is used, the above database operation instructions and control instructions are actually a series of SQL statements.
  • the method provided in this embodiment is applicable to operating a database whose isolation level is read and submitted.
  • Some databases default to reading the isolation level that has been submitted.
  • the Oracle database defaults to read the isolation level that has been submitted.
  • Some databases do not read the isolation level by default.
  • the MySQL database is repeatable by default.
  • An isolation level Based on this, before performing the method provided in this embodiment, it can be determined whether the isolation level of the database is a read commit, and if not, the database needs to be pre-configured to read the isolation level. For example, you can configure the database to read this isolation level before the target server performs the target transaction.
  • the method provided in this embodiment can be executed to execute the target transaction in the database.
  • the specific process is as follows:
  • the application server controls the execution logic of the entire target transaction, and the target transaction can be executed in the existing manner.
  • the database operating device sequentially acquires database operation instructions in the target transaction executed by the application server during the execution of the target transaction by the application server.
  • the application server sends database operation instructions to the database in an existing manner to enable access to the database.
  • the database operating device can monitor the communication between the application server and the database to intercept the database operation instructions sent by the application server to the database.
  • the processing logic of the application server is slightly modified to change the processing logic that originally sent the database operation instructions to the database to the database operating device. Based on this, the database operating device can receive the database operation instruction actively issued by the application server.
  • the first instruction in the target transaction is a transaction start instruction, such as a begin transaction, based on which the database operation device obtains the database operation instruction executed by the application server.
  • the database operating device may receive a transaction start instruction in the target transaction actively issued by the application server before acquiring the database operation instruction executed by the application server, and according to the transaction start instruction, learn that the target transaction needs to be executed.
  • the first instruction of the target transaction is the database operation instruction, and does not include the step of obtaining the transaction start instruction.
  • the database operation device After acquiring the database operation instruction executed by the application server, the database operation device performs predictive execution on the acquired database operation instruction, returns the predicted execution result to the application server, and uses the server to determine the next database operation instruction to be executed.
  • the predicted execution result determines the execution path of the target transaction, where the execution path refers to the jump logic between the database operation instructions.
  • the purpose of controlling the execution logic of the entire target transaction by the application server is achieved by returning the predicted execution result to the application server.
  • the database operating device also needs to locally record the acquired database operation instruction, and record the predicted execution data generated by predictive execution of the database operation instruction when the database operation instruction belongs to the modified database type instruction.
  • the modified database class instruction refers to a database operation instruction that has a modification to the database, for example, an instruction starting with update, insert, etc.; generally, the instruction beginning with select is not a modified database type instruction.
  • the predicted execution data mainly refers to some data in the process of predictive execution of database operation instructions.
  • the database operating device can locally create a memory library, and store the acquired database operation instructions and predicted execution data into the memory library. Further, if the predicted execution data does not include the predicted execution result, the predicted execution result may also be stored in the memory bank.
  • reading the committed isolation level only guarantees that writing multiple data is atomic, and does not lock when reading, which can improve the concurrency of the system and improve the efficiency of transaction execution.
  • this embodiment only records the prediction execution data generated by the prediction execution for the database operation instruction belonging to the modified database class instruction, but does not Record the predicted execution data corresponding to the database operation instruction that does not modify the database class instruction. It can be seen that in the case that the reading has been submitted to the isolation level, the amount of recorded data is relatively small, so that in the subsequent process of executing the target transaction in the database in the database operation instruction and the prediction execution data based on the local record. The amount of data to be processed is relatively small, which is beneficial to further improve execution efficiency and performance, and increase transaction throughput.
  • the operation of the database operation instruction on the database is mainly to access the data in the database, then the data environment of the database operation instruction can be simulated, and the database operation instruction is predicted and executed based on the simulated data environment. Further, considering that the database operation instruction that is not a modification of the database class instruction does not cause a change of the database, the database operation instruction can be directly predicted and executed in the database, which can save the operation of the simulation data environment, and is relatively simple to implement. Conducive to saving resources and improving execution efficiency. However, For database operation instructions belonging to the modified database class instructions, since it will cause changes in the database (mainly refers to the data in the database is changed), it is necessary to simulate the data environment and perform prediction execution in the simulated data environment.
  • the data environment of the database operation instruction is simulated in the locally created memory library, and the database operation instruction is predicted and executed based on the simulated data environment;
  • the database operation instruction is executed in the database to perform prediction execution on the database operation instruction.
  • a data environment simulating a database operation instruction in a locally created memory library, and an implementation manner of predicting execution of the database operation instruction based on the simulated data environment includes:
  • the obtained database operation instruction is split into a read instruction and a write instruction, and the read instruction is run on a real database, that is, the read instruction is executed in the database to obtain a read data set (ReadSet), and the read data set is stored.
  • the read instruction is executed in the database to obtain a read data set (ReadSet), and the read data set is stored.
  • the write instruction is applied to the memory library to implement predictive execution of the database operation instruction, that is, the write instruction is executed in the memory library to modify the read data set, for example, to update or query the related data in the read data set.
  • executing a write instruction to modify the read data set may generate a result data set (affectRowInMemdb), the result data set including a predicted execution result.
  • the database operation device may locally record the read data set read by the read instruction and the result data set generated by executing the write instruction.
  • the predicted execution data may include a read data set and a result data set, or may also include partial data in the read data set and the result data set, such as some data that can have a beneficial effect on actually executing the target transaction in the database. For example, various indexes of some values, such as a primary index, a secondary index, a primary key value, and the like.
  • the database operation device acquires the transaction commit instruction in the target transaction (that is, the application server executes to the transaction commit instruction)
  • the database corresponding to the locally recorded database operation instruction and the predicted execution data may be used to control the database corresponding to the application server to actually execute the target transaction.
  • an optional implementation manner of controlling the database corresponding to the actual execution target transaction of the application server includes:
  • the database operating device sends the locally recorded database operation instruction to the database to indicate the database Executing a database operation instruction, and receiving an actual execution result of the database operation instruction returned by the database; then, comparing the actual execution result of the database operation instruction with the predicted execution result, and if the actual execution result is the same as the predicted execution result, sending a transaction to the database
  • the instruction is submitted for the database to submit the target transaction; if the actual execution result is different from the predicted execution result, a transaction rollback instruction is sent to the database for the database to roll back the target transaction.
  • the database operation instruction can be executed sequentially according to the execution logic of the transaction, which causes frequent interaction between the application server and the database, which is A lot of network resources will be consumed in the remote application scenario.
  • all the database operation instructions that need to be executed by the target transaction that is, the database operation instructions of the local record
  • the database operation instruction of the local record has been obtained in advance by the prediction execution process, so the database operation instruction of the local record is sent to the database to instruct the database to execute the database.
  • the database operation instruction of the local record can be simultaneously and/or sent to the database, which is conducive to saving network resources.
  • the database can also operate in parallel, which is beneficial to further improve transaction execution efficiency and increase transaction throughput.
  • all the database operation instructions of the local record can be sent to the database together with the locally recorded predicted execution data.
  • the database operation device may determine whether the target transaction is based on the locally recorded database operation instruction. For a stand-alone transaction; if the result of the determination is yes, according to the locally recorded database operation instruction and the predicted execution data, the single-machine transaction logic is used to control the database to actually execute the target transaction; if the judgment result is no, the database operation instruction according to the local record and Predictive execution data, with distributed transaction processing logic to control the database to actually execute the target transaction.
  • the database operation instruction obtained during the prediction execution process can identify whether the target transaction is a stand-alone transaction or a distributed transaction. For example, it can be determined whether the operation object of the database operation instruction recorded locally acts on the same physical device. If the determination result is yes, the target transaction can be determined to be a stand-alone transaction; if the determination result is no, the target transaction can be determined as Distributed transactions.
  • the processing logic of distributed transactions is different from the processing logic of stand-alone transactions, the processing logic of single-machine transactions is relatively simple, for example, it does not involve problems such as read-write and lock, so the resources consumed are relatively small. based on Therefore, in this embodiment, by identifying whether the target transaction is a stand-alone transaction, the processing logic of the single-machine transaction is processed when it is recognized as a stand-alone transaction, instead of uniformly processing the distributed transaction processing logic as in the prior art, which is advantageous for improving processing. Efficiency, saving processing costs.
  • the database operation device acquires a transaction rollback instruction in the target transaction (that is, the application server performs a transaction rollback instruction)
  • the database operation instruction of the local record and the prediction execution data may be deleted, for example, Clear the local memory library directly to implement the rollback operation.
  • the target transaction since the target transaction is not actually executed in the database, the database does not need to perform a rollback operation. It can be seen that in the case of transaction rollback, the transaction efficiency can be improved by using the method of this embodiment.
  • the database operating device cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and the execution path of the target transaction can be obtained in advance during the predictive execution process. That is, the database operation instruction that really needs to be executed, and only the prediction execution data generated by the prediction execution of the database operation instruction belonging to the modified database class instruction is adapted to read the submitted isolation level, and the condition for the real execution transaction is provided, and then the record is based on the record.
  • the database operation instruction and the prediction execution data actually execute the target transaction, for example, based on the prediction execution data, related data information can be acquired in advance and jumps between instructions can be reduced, etc., thereby improving execution efficiency and increasing transaction throughput.
  • the isolation level of the database is the isolation level that the read has been submitted.
  • the SQL code for the inventory reduction transaction is as follows, the text in parentheses is a comment:
  • the application server is responsible for the entire logic of the inventory reduction transaction, and the database operation device (or may also be referred to as an execution server) only obtains the start transaction executed by the application server, and needs to be executed. SQL statements, as well as commit/rollback instructions.
  • the database operating device creates a memory library locally
  • the database operation device will get the rollback statement.
  • the application server executes the commit command at this time.
  • the inventory reduction transaction is executed in the database based on the SQL statement in the local memory library and the predicted execution data, and the transaction execution process is actually performed.
  • the locally recorded SQL statement and the predicted execution data are as follows:
  • the database operating device can submit all the SQL statements in the local memory library to the database at one time, and the database performs the execution based on this, which is beneficial to save network resources consumed by the transmission of the SQL statement.
  • This real execution will also return the execution result.
  • FIG. 4 is a schematic structural diagram of a database operating device according to an embodiment of the present application. As shown in FIG. 4, the apparatus includes an acquisition module 41, a prediction execution module 42, and a control execution module 43.
  • the obtaining module 41 is configured to sequentially acquire a database operation instruction in the target transaction executed by the application server during the execution of the target transaction by the application server.
  • the prediction execution module 42 is configured to perform predictive execution on the database operation instruction, return the predicted execution result to the application server to supply the server to determine the next database operation instruction to be executed, and locally record the database operation instruction and the database operation instruction belongs to The predicted execution data generated by the prediction execution is recorded when the database class instruction is modified.
  • the control execution module 43 is configured to, when acquiring the transaction commit instruction in the target transaction, control the database corresponding to the application server to actually execute the target transaction according to the locally recorded database operation instruction and the predicted execution data.
  • the database operating device further includes: a configuration module, configured to configure the database to read the submitted isolation level before the application server performs the target transaction.
  • the obtaining module 41 is specifically configured to: intercept a database operation instruction sent by the application server to the database; or receive a database operation instruction that is actively sent by the application server.
  • the obtaining module 41 is further configured to: before acquiring the database operation instruction in the target transaction executed by the application server, intercepting a transaction start instruction in the target transaction sent by the application server to the database; or receiving the application The transaction start instruction in the target transaction that the server actively delivers.
  • the prediction execution module 42 is specifically configured to:
  • the database operation instruction acquired by the obtaining module 41 belongs to the modified database class instruction, the data environment of the database operation instruction is simulated in the locally created memory library, and the database operation instruction is predicted and executed based on the simulated data environment;
  • the database operation instruction acquired by the obtaining module 41 does not belong to the modified database class instruction, the database operation instruction is executed in the database to perform prediction execution on the database operation instruction.
  • the prediction execution module 42 simulates the data environment of the database operation instruction in the locally created memory library, and operates the database based on the simulated data environment.
  • the instruction performs the operation of predictive execution it is specifically used to:
  • a write instruction is executed in the memory bank to modify the read data set.
  • control execution module 43 is specifically configured to:
  • the database operation instruction of the local record is sent to the database to instruct the database to execute the database operation instruction, and receives the actual execution result of the database operation instruction returned by the database;
  • the transaction commit instruction is sent to the database for the database to submit the target transaction
  • control execution module 43 can avoid the error of the transaction execution process by comparing the actual execution result with the predicted execution result, and is beneficial to improving the success probability of the transaction execution.
  • control execution module 43 can be used to: simultaneously send the database operation instruction of the local record to the database, which is beneficial to save network resources.
  • control execution module 43 can send all the database operation instructions recorded locally together with the locally recorded predicted execution data to the database, which is beneficial to save network resources.
  • control execution module 43 is specifically configured to:
  • the single-machine transaction logic is used to control the database to actually execute the target transaction
  • the database actually controls the target transaction by the distributed transaction logic according to the locally recorded database operation instruction and the predicted execution data. Because the processing logic of distributed transactions is different from the processing logic of stand-alone transactions, the processing logic of single-machine transactions is relatively simple, for example, it does not involve problems such as read-write and lock, so the resources consumed are relatively small. Based on this, the control execution module 43 performs processing by using the processing logic of the single-machine transaction when identifying the target transaction as a stand-alone transaction, which is beneficial to improve processing efficiency and save processing cost.
  • the predictive execution module 42 is further configured to: delete the locally recorded database operation instruction and the predicted execution data when the transaction rollback instruction in the target transaction is acquired.
  • the database operating device provided in this embodiment may be deployed separately, and may be located between the application server and the database, or may be deployed on one end of the application server, or may be deployed on one end of the database.
  • the database operating device cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and obtains and records all the data that the target transaction needs to execute in advance.
  • the library operates on instructions and records the predicted execution data generated by the prediction execution only for the database operation instructions belonging to the modified database class instruction to adapt to the read committed isolation level, providing conditions for the real execution of the transaction, and then based on the recorded database operation instructions and predictions. Executing data and controlling the database corresponding to the application server to actually execute the target transaction is beneficial to improve execution efficiency and increase transaction throughput.
  • the disclosed system, apparatus, and method may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
  • the above-described integrated unit implemented in the form of a software functional unit can be stored in a computer readable storage medium.
  • the software functional unit described above is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform the methods described in various embodiments of the present application. Part of the steps.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program codes. .

Abstract

A database operating method and device. The method comprises: in a process of executing a target transaction of an application server, acquiring sequentially database operation instructions in the target transaction executed by the application server (301); performing a speculative execution of the database operation instructions and returning the result of the speculative execution to the application server for the application server to determine a next database operation instruction to execute, and locally recording the database operation instruction and, if the database operation instruction belongs to a modification type of database instructions, recording speculative execution data generated by the speculative execution (302); and when a transaction commit instruction in the target transaction is acquired, controlling a database corresponding to the application server to actually execute the target transaction according to the locally recorded database operation instruction and the speculative execution data (303).

Description

数据库操作方法及装置Database operation method and device
本申请要求2015年09月08日递交的申请号为201510568369.7、发明名称为“数据库操作方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application Serial No. No. No. No. No. No. No. No. No. No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No
技术领域Technical field
本申请涉及数据库技术领域,尤其涉及一种数据库操作方法及装置。The present application relates to the field of database technologies, and in particular, to a database operation method and apparatus.
背景技术Background technique
数据库事务(Database Transaction),是指作为单个逻辑工作单元执行的一系列操作,要么完全地执行,要么完全地不执行。一个事务由一系列数据库操作指令构成,例如结构化查询语言(Structured Query Language,SQL)语句,这些数据库操作指令之间存在切分条件以及跳转等逻辑,意味着在一次执行过程中该事务中可能有部分数据库操作指令被跳过不执行。但在现有技术中,由于无法预先获知事务中需要执行的数据库操作指令,因此只能按照执行逻辑边执行边判断,依次执行事务中的语句,以实现对数据库的操作。这种事务执行方式效率较低,尤其是在事务设置读已提交隔离级别的情况下,其执行效率会更低,事务吞吐量较低。Database Transaction refers to a series of operations performed as a single logical unit of work, either completely or completely. A transaction consists of a series of database operation instructions, such as Structured Query Language (SQL) statements. There are splitting conditions and jumps between these database operation instructions, meaning that the transaction is in one transaction. There may be some database operation instructions that are skipped and not executed. However, in the prior art, since the database operation instruction that needs to be executed in the transaction cannot be known in advance, the execution judgment can only be performed according to the execution logic, and the statement in the transaction is sequentially executed to implement the operation on the database. This type of transaction execution is less efficient, especially when the transaction settings read committed isolation level is less efficient and has lower transaction throughput.
发明内容Summary of the invention
本申请的多个方面提供一种数据库操作方法及装置,用以提高事务执行效率并增大事务吞吐量。Aspects of the present application provide a database operation method and apparatus for improving transaction execution efficiency and increasing transaction throughput.
本申请的一方面,提供一种数据库操作方法,包括:An aspect of the present application provides a database operation method, including:
在应用服务器执行目标事务的过程中,依次获取所述应用服务器执行到的所述目标事务中的数据库操作指令;And acquiring, in the process of executing the target transaction by the application server, the database operation instruction in the target transaction executed by the application server;
对所述数据库操作指令进行预测执行,将预测执行结果返回给所述应用服务器以供所述应用服务器确定下一个需要执行的数据库操作指令,并在本地记录所述数据库操作指令以及在所述数据库操作指令属于修改数据库类指令时记录所述预测执行产生的预测执行数据;Performing predictive execution on the database operation instruction, returning the predicted execution result to the application server for the application server to determine the next database operation instruction to be executed, and locally recording the database operation instruction and the database The operation instruction belongs to the prediction execution data generated by the prediction execution when the database type instruction is modified;
当获取到所述目标事务中的事务提交指令时,根据本地记录的所述数据库操作指令以及所述预测执行数据,控制所述应用服务器对应的数据库实际执行所述目标事务。When the transaction commit instruction in the target transaction is obtained, the database corresponding to the application server is controlled to actually execute the target transaction according to the database operation instruction recorded locally and the predicted execution data.
本申请的另一方面,提供一种数据库操作装置,包括:In another aspect of the present application, a database operating device is provided, including:
获取模块,用于在应用服务器执行目标事务的过程中,依次获取所述应用服务 器执行到的所述目标事务中的数据库操作指令;An obtaining module, configured to acquire the application service in sequence during execution of a target transaction by the application server a database operation instruction in the target transaction to which the device executes;
预测执行模块,用于对所述数据库操作指令进行预测执行,将预测执行结果返回给所述应用服务器以供所述应用服务器确定下一个需要执行的数据库操作指令,并在本地记录所述数据库操作指令以及在所述数据库操作指令属于修改数据库类指令时记录所述预测执行产生的预测执行数据;a predictive execution module, configured to perform predictive execution on the database operation instruction, return a predicted execution result to the application server, for the application server to determine a next database operation instruction to be executed, and locally record the database operation And predicting execution data generated by the prediction execution when the database operation instruction belongs to modifying a database class instruction;
控制执行模块,用于当获取到所述目标事务中的事务提交指令时,根据本地记录的所述数据库操作指令以及所述预测执行数据,控制所述应用服务器对应的数据库实际执行所述目标事务。a control execution module, configured to: when the transaction commit instruction in the target transaction is obtained, control the database corresponding to the application server to actually execute the target transaction according to the database operation instruction recorded locally and the predicted execution data .
在本申请中,数据库操作装置与应用服务器相互配合,在应用服务器执行目标事务的过程加入预测执行过程,预先获得并记录目标事务需要执行的全部数据库操作指令,并仅针对属于修改数据库类指令的数据库操作指令记录预测执行产生的预测执行数据以适应于读已提交隔离级别,为真实执行事务提供了条件,之后根据记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行该目标事务,有利于提高执行效率,进而增大事务吞吐量。In the present application, the database operating device cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and obtains and records all the database operation instructions that need to be executed in the target transaction in advance, and only for the instructions belonging to the modified database class. The database operation instruction records the predicted execution data generated by the prediction execution to adapt to the read committed isolation level, provides conditions for the real execution of the transaction, and then controls the database corresponding to the application server to actually execute the target according to the recorded database operation instruction and the predicted execution data. Transactions help improve execution efficiency and increase transaction throughput.
附图说明DRAWINGS
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description are the present application. For some embodiments, other drawings may be obtained from those of ordinary skill in the art in light of the inventive workability.
图1为现有技术中数据库应用系统的部署图;1 is a deployment diagram of a database application system in the prior art;
图2为本申请一实施例提供的数据库应用系统的部署图;2 is a deployment diagram of a database application system according to an embodiment of the present application;
图3为本申请一实施例提供的数据库操作方法的流程示意图;FIG. 3 is a schematic flowchart of a database operation method according to an embodiment of the present application;
图4为本申请一实施例提供的数据库操作装置的结构示意图。FIG. 4 is a schematic structural diagram of a database operating device according to an embodiment of the present application.
具体实施方式detailed description
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属 于本申请保护的范围。The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present application. It is a part of the embodiments of the present application, and not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts are Within the scope of this application.
图1为现有技术中数据库应用系统的部署图。如图1所示,该系统包括:应用服务器10和数据库20。其中,数据库20可以为一个,也可以为多个。图1中仅示例性的示出一个数据库20。当需要以事务方式对数据库20进行访问时,应用服务器10执行事务逻辑,依次将事务中的数据库操作指令作用于数据库20上。由于无法预先获知事务中需要执行的数据库操作指令,导致事务执行效率较低,尤其是在配置读已提交隔离级别的情况下,其执行效率会更低,事务吞吐量较低。FIG. 1 is a deployment diagram of a database application system in the prior art. As shown in FIG. 1, the system includes an application server 10 and a database 20. The database 20 may be one or multiple. Only one database 20 is shown by way of example in FIG. When it is desired to access the database 20 in a transactional manner, the application server 10 executes transaction logic to sequentially apply database operation instructions in the transaction to the database 20. Because the database operation instructions that need to be executed in the transaction cannot be known in advance, the transaction execution efficiency is low, especially when the configuration read commit isolation level is configured, the execution efficiency is lower and the transaction throughput is lower.
针对现有技术存在的缺陷,本申请提供一种新的数据库应用系统,如图2所示。该系统在应用服务器10和数据库20之间增加数据库操作装置30。数据库操作装置30用以执行本申请提供的数据库操作方法,在读已提交这一隔离级别下实现一种新的事务执行逻辑,即先对事务进行预测执行,提前获得该事务中需要执行的数据库操作指令,实现执行路径的预测,并且结合读已提交这一隔离级别仅仅针对属于修改数据库类指令的数据库操作指令记录对其进行预测执行所产生的预测执行数据,进而基于预测执行得到的数据库操作指令以及预测执行数据在数据库20上实际执行事务,有利于提高事务执行效率,增大事务吞吐量。事务吞吐量是指单位时间内处理事务的数量。In view of the deficiencies of the prior art, the present application provides a new database application system, as shown in FIG. 2 . The system adds a database operating device 30 between the application server 10 and the database 20. The database operating device 30 is configured to execute the database operation method provided by the present application, and implement a new transaction execution logic under the isolation level of the read commit, that is, the prediction execution is performed on the transaction, and the database operation to be performed in the transaction is obtained in advance. The instruction, the prediction of the execution path is implemented, and the read execution level is submitted only for the database execution instruction record of the database operation instruction record belonging to the modified database class instruction, and the database operation instruction generated based on the prediction execution is executed. And predicting execution data actually executing transactions on the database 20, which is beneficial to improve transaction execution efficiency and increase transaction throughput. Transaction throughput is the number of transactions processed per unit of time.
值得说明的是,数据库操作装置30实际上是一种逻辑处理装置,其可以单独部署,位于应用服务器10和数据库20之间,也可以部署于应用服务器10一端实现,或者也可以部署于数据库20一端实现。It should be noted that the database operating device 30 is actually a logical processing device, which can be deployed separately, between the application server 10 and the database 20, or deployed at one end of the application server 10, or can be deployed in the database 20. Implemented at one end.
下面实施例将具体说明本申请技术方案的方法流程。The following embodiment will specifically describe the method flow of the technical solution of the present application.
图3为本申请一实施例提供的数据库操作方法的流程示意图。如图3所示,该方法包括:FIG. 3 is a schematic flowchart diagram of a database operation method according to an embodiment of the present application. As shown in FIG. 3, the method includes:
301、在应用服务器执行目标事务的过程中,依次获取应用服务器执行到的目标事务中的数据库操作指令。301. In the process of executing the target transaction by the application server, sequentially acquiring the database operation instruction in the target transaction executed by the application server.
302、对数据库操作指令进行预测执行,将预测执行结果返回给应用服务器以供应用服务器确定下一个需要执行的数据库操作指令,并在本地记录数据库操作指令以及在数据库操作指令属于修改数据库类指令时记录预测执行产生的预测执行数据。302. Perform predictive execution on the database operation instruction, return the predicted execution result to the application server to supply the server to determine the next database operation instruction to be executed, and record the database operation instruction locally and when the database operation instruction belongs to the modified database type instruction The predicted execution data generated by the prediction execution is recorded.
303、当获取到目标事务中的事务提交指令时,根据本地记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行目标事务。 303. When the transaction commit instruction in the target transaction is obtained, according to the locally recorded database operation instruction and the predicted execution data, the database corresponding to the application server is controlled to actually execute the target transaction.
首先说明,为便于描述,本实施例将应用服务器需要执行的事务称为目标事务。目标事务主要包括用于对数据库进行操作的操作指令,除数据库操作指令之外还包括一些用于控制目标事务执行状态的控制指令,例如事务开始指令、事务提交指令、事务回滚指令等。这些指令实际上是由数据库语言编写的语句。根据数据库语言的不同,这些指令可以是不同语言编写的语句。举例说明,若采用SQL,则上述数据库操作指令和控制指令实际上是一系列的SQL语句。First, for convenience of description, the present embodiment refers to a transaction that the application server needs to perform as a target transaction. The target transaction mainly includes operation instructions for operating on the database, and in addition to the database operation instructions, some control instructions for controlling the execution state of the target transaction, such as a transaction start instruction, a transaction commit instruction, a transaction rollback instruction, and the like. These instructions are actually statements written in the database language. Depending on the database language, these instructions can be statements written in different languages. For example, if SQL is used, the above database operation instructions and control instructions are actually a series of SQL statements.
本实施例提供的方法适用于对隔离级别为读已提交的数据库进行操作。其中,有些数据库默认是读已提交这一隔离级别,例如,Oracle数据库默认是读已提交这一隔离级别的,有些数据库默认不是读已提交这一隔离级别,例如MySQL数据库默认是可重复读这一隔离级别。基于此,在执行本实施例提供的方法之前,可以确定数据库的隔离级别是否是读已提交,若不是,则需要预先配置数据库为读已提交这一隔离级别。例如,可以在应用服务器执行目标事务之前,配置数据库为读已提交这一隔离级别。The method provided in this embodiment is applicable to operating a database whose isolation level is read and submitted. Some databases default to reading the isolation level that has been submitted. For example, the Oracle database defaults to read the isolation level that has been submitted. Some databases do not read the isolation level by default. For example, the MySQL database is repeatable by default. An isolation level. Based on this, before performing the method provided in this embodiment, it can be determined whether the isolation level of the database is a read commit, and if not, the database needs to be pre-configured to read the isolation level. For example, you can configure the database to read this isolation level before the target server performs the target transaction.
在数据库的隔离级别为读已提交的前提下,可以执行本实施例提供的方法以在数据库中执行目标事务。具体流程如下:Under the premise that the isolation level of the database is read and committed, the method provided in this embodiment can be executed to execute the target transaction in the database. The specific process is as follows:
应用服务器控制整个目标事务的执行逻辑,可以按照现有方式执行目标事务。数据库操作装置在应用服务器执行目标事务的过程中,依次获取应用服务器执行到的目标事务中的数据库操作指令。The application server controls the execution logic of the entire target transaction, and the target transaction can be executed in the existing manner. The database operating device sequentially acquires database operation instructions in the target transaction executed by the application server during the execution of the target transaction by the application server.
在一可选实施方式中,应用服务器按照现有方式向数据库发送数据库操作指令,以实现对数据库的访问。数据库操作装置可以对应用服务器与数据库之间的通信进行监控,以拦截应用服务器发往数据库的数据库操作指令。In an alternative embodiment, the application server sends database operation instructions to the database in an existing manner to enable access to the database. The database operating device can monitor the communication between the application server and the database to intercept the database operation instructions sent by the application server to the database.
在另一可选实施方式中,对应用服务器的处理逻辑进行稍微修改,将原来向数据库发送数据库操作指令的处理逻辑改为向数据库操作装置发送。基于此,数据库操作装置可以接收应用服务器主动下发的数据库操作指令。In another alternative embodiment, the processing logic of the application server is slightly modified to change the processing logic that originally sent the database operation instructions to the database to the database operating device. Based on this, the database operating device can receive the database operation instruction actively issued by the application server.
在此说明,若目标事务是显式事务,则目标事务中的首个指令是事务开始指令,如开始事务(begin transaction),基于此,数据库操作装置在获取应用服务器执行到的数据库操作指令之前,可以拦截应用服务器发往数据库的目标事务中的事务开始指令,根据该事务开始指令,获知需要执行目标事务。或者,数据库操作装置在获取应用服务器执行到的数据库操作指令之前,可以接收应用服务器主动下发的目标事务中的事务开始指令,根据该事务开始指令,获知需要执行目标事务。若目标事 务是隐式事务,则目标事务的首个指令就是数据库操作指令,不包括获取事务开始指令的步骤。Herein, if the target transaction is an explicit transaction, the first instruction in the target transaction is a transaction start instruction, such as a begin transaction, based on which the database operation device obtains the database operation instruction executed by the application server. , can intercept the transaction start instruction in the target transaction sent by the application server to the database, and according to the transaction start instruction, know that the target transaction needs to be executed. Alternatively, the database operating device may receive a transaction start instruction in the target transaction actively issued by the application server before acquiring the database operation instruction executed by the application server, and according to the transaction start instruction, learn that the target transaction needs to be executed. If the target For an implicit transaction, the first instruction of the target transaction is the database operation instruction, and does not include the step of obtaining the transaction start instruction.
数据库操作装置在获取应用服务器执行到的数据库操作指令后,对获取到的数据库操作指令进行预测执行,将预测执行结果返回给应用服务器,以供应用服务器确定下一个需要执行的数据库操作指令。其中,预测执行结果决定着目标事务的执行路径,这里的执行路径是指数据库操作指令之间的跳转逻辑。通过将预测执行结果返回给应用服务器,从而达到由应用服务器控制整个目标事务的执行逻辑的目的。After acquiring the database operation instruction executed by the application server, the database operation device performs predictive execution on the acquired database operation instruction, returns the predicted execution result to the application server, and uses the server to determine the next database operation instruction to be executed. The predicted execution result determines the execution path of the target transaction, where the execution path refers to the jump logic between the database operation instructions. The purpose of controlling the execution logic of the entire target transaction by the application server is achieved by returning the predicted execution result to the application server.
另外,数据库操作装置还需要在本地记录所获取到的数据库操作指令,以及在该数据库操作指令属于修改数据库类指令时记录对该数据库操作指令进行预测执行产生的预测执行数据。所述修改数据库类指令是指对数据库有修改的数据库操作指令,例如以update、insert等开头的指令;一般以select开头的指令不属于修改数据库类指令。所述预测执行数据主要是指对数据库操作指令进行预测执行过程中的一些数据。In addition, the database operating device also needs to locally record the acquired database operation instruction, and record the predicted execution data generated by predictive execution of the database operation instruction when the database operation instruction belongs to the modified database type instruction. The modified database class instruction refers to a database operation instruction that has a modification to the database, for example, an instruction starting with update, insert, etc.; generally, the instruction beginning with select is not a modified database type instruction. The predicted execution data mainly refers to some data in the process of predictive execution of database operation instructions.
例如,数据库操作装置可以在本地创建内存库,将所获取到的数据库操作指令以及预测执行数据存入内存库中。进一步,若预测执行数据不包括预测执行结果,则也可以将预测执行结果存入内存库中。For example, the database operating device can locally create a memory library, and store the acquired database operation instructions and predicted execution data into the memory library. Further, if the predicted execution data does not include the predicted execution result, the predicted execution result may also be stored in the memory bank.
从本质而言,读已提交隔离级别只保证写入多个数据是原子的,不在读取的时候加锁,这样可以提升系统的并发度,提高事务执行效率。为了在预测执行这一核心思想的基础上实现对读已提交这一隔离级别的模拟,本实施例仅仅针对属于修改数据库类指令的数据库操作指令,记录其预测执行产生的预测执行数据,却不记录不属于修改数据库类指令的数据库操作指令对应的预测执行数据。由此可见,在实现读已提交这一隔离级别的情况下,所记录的数据量相对较少,这样在后续基于本地记录的数据库操作指令和预测执行数据在数据库中真实执行目标事务的过程中,所需处理的数据量相对较少,有利于进一步提高执行效率和性能,增大事务吞吐量。In essence, reading the committed isolation level only guarantees that writing multiple data is atomic, and does not lock when reading, which can improve the concurrency of the system and improve the efficiency of transaction execution. In order to implement the simulation of the isolation level that has been submitted for reading on the basis of the core idea of predictive execution, this embodiment only records the prediction execution data generated by the prediction execution for the database operation instruction belonging to the modified database class instruction, but does not Record the predicted execution data corresponding to the database operation instruction that does not modify the database class instruction. It can be seen that in the case that the reading has been submitted to the isolation level, the amount of recorded data is relatively small, so that in the subsequent process of executing the target transaction in the database in the database operation instruction and the prediction execution data based on the local record. The amount of data to be processed is relatively small, which is beneficial to further improve execution efficiency and performance, and increase transaction throughput.
其中,数据库操作指令对数据库的操作主要是访问数据库中的数据,则可以模拟数据库操作指令的数据环境,基于所模拟的数据环境对数据库操作指令进行预测执行。进一步,考虑到不属于修改数据库类指令的数据库操作指令不会引起数据库的变化,因此可以直接在数据库中对该数据库操作指令进行预测执行,这样可以节约模拟数据环境的操作,实现相对简单,有利于节约资源,提高执行效率。但是, 对于属于修改数据库类指令的数据库操作指令,由于其会引起数据库的变化(主要是指数据库中的数据被改变),因此需要模拟数据环境,在所模拟的数据环境中进行预测执行。Among them, the operation of the database operation instruction on the database is mainly to access the data in the database, then the data environment of the database operation instruction can be simulated, and the database operation instruction is predicted and executed based on the simulated data environment. Further, considering that the database operation instruction that is not a modification of the database class instruction does not cause a change of the database, the database operation instruction can be directly predicted and executed in the database, which can save the operation of the simulation data environment, and is relatively simple to implement. Conducive to saving resources and improving execution efficiency. However, For database operation instructions belonging to the modified database class instructions, since it will cause changes in the database (mainly refers to the data in the database is changed), it is necessary to simulate the data environment and perform prediction execution in the simulated data environment.
基于上述分析,一种对数据库操作指令进行预测执行的方式可以是:Based on the above analysis, a way to predict execution of database operation instructions can be:
对获取到的数据库操作指令的类别进行识别;Identify the category of the obtained database operation instruction;
若数据库操作指令属于修改数据库类指令,则在本地创建的内存库中模拟数据库操作指令的数据环境,基于所模拟的数据环境对数据库操作指令进行预测执行;If the database operation instruction belongs to the modification database class instruction, the data environment of the database operation instruction is simulated in the locally created memory library, and the database operation instruction is predicted and executed based on the simulated data environment;
若数据库操作指令不属于修改数据库类指令,在数据库中执行该数据库操作指令,以对该数据库操作指令进行预测执行。If the database operation instruction is not a modification database class instruction, the database operation instruction is executed in the database to perform prediction execution on the database operation instruction.
进一步,一种在本地创建的内存库中模拟数据库操作指令的数据环境,基于所模拟的数据环境对数据库操作指令进行预测执行的实施方式包括:Further, a data environment simulating a database operation instruction in a locally created memory library, and an implementation manner of predicting execution of the database operation instruction based on the simulated data environment includes:
将获取到的数据库操作指令拆分为一个读指令和一个写指令,将读指令运行于真正的数据库上,即在数据库中执行该读指令以获取读数据集(ReadSet),将读数据集存入本地内存库中,以模拟数据库操作指令所需的数据环境。然后,将写指令作用于内存库上,以实现对数据库操作指令的预测执行,即在内存库中执行写指令以修改读数据集,例如对读数据集中的有关数据进行更新或查询处理等。其中,执行写指令以修改读数据集可以产生结果数据集(affectRowInMemdb),该结果数据集包括预测执行结果。The obtained database operation instruction is split into a read instruction and a write instruction, and the read instruction is run on a real database, that is, the read instruction is executed in the database to obtain a read data set (ReadSet), and the read data set is stored. Into the local memory library to simulate the data environment required for database operation instructions. Then, the write instruction is applied to the memory library to implement predictive execution of the database operation instruction, that is, the write instruction is executed in the memory library to modify the read data set, for example, to update or query the related data in the read data set. Wherein, executing a write instruction to modify the read data set may generate a result data set (affectRowInMemdb), the result data set including a predicted execution result.
在上述预测执行过程中,若数据库操作指令属于修改数据库类指令,则数据库操作装置可以在本地记录读指令所读取的读数据集以及执行写指令产生的结果数据集。由此可见,所述预测执行数据可以包括读数据集和结果数据集,或者也可以包括读数据集和结果数据集中的部分数据,例如能够对在数据库中实际执行目标事务产生有益效果的一些数据,例如一些数值的各种索引,例如一级索引、二级索引、主键值等。In the above prediction execution process, if the database operation instruction belongs to the modification database class instruction, the database operation device may locally record the read data set read by the read instruction and the result data set generated by executing the write instruction. As can be seen, the predicted execution data may include a read data set and a result data set, or may also include partial data in the read data set and the result data set, such as some data that can have a beneficial effect on actually executing the target transaction in the database. For example, various indexes of some values, such as a primary index, a secondary index, a primary key value, and the like.
当数据库操作装置获取到目标事务中的事务提交指令(即应用服务器执行到事务提交指令)时,则可以根据本地记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行目标事务。When the database operation device acquires the transaction commit instruction in the target transaction (that is, the application server executes to the transaction commit instruction), the database corresponding to the locally recorded database operation instruction and the predicted execution data may be used to control the database corresponding to the application server to actually execute the target transaction.
上述根据本地记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行目标事务的一种可选实施方式包括:In the foregoing, according to the locally recorded database operation instruction and the predicted execution data, an optional implementation manner of controlling the database corresponding to the actual execution target transaction of the application server includes:
数据库操作装置向数据库下发本地记录的所述数据库操作指令,以指示数据库 执行数据库操作指令,并接收数据库返回的数据库操作指令的实际执行结果;然后,将数据库操作指令的实际执行结果与预测执行结果进行比较,若实际执行结果与预测执行结果相同,向数据库下发事务提交指令,以供数据库提交该目标事务;若实际执行结果与预测执行结果不相同,向数据库下发事务回滚指令,以供数据库回滚该目标事务。The database operating device sends the locally recorded database operation instruction to the database to indicate the database Executing a database operation instruction, and receiving an actual execution result of the database operation instruction returned by the database; then, comparing the actual execution result of the database operation instruction with the predicted execution result, and if the actual execution result is the same as the predicted execution result, sending a transaction to the database The instruction is submitted for the database to submit the target transaction; if the actual execution result is different from the predicted execution result, a transaction rollback instruction is sent to the database for the database to roll back the target transaction.
在上述实施方式中,考虑到事务的原子性,通过将实际执行结果与预测执行结果进行比较,可以避免事务执行过程出错,有利于提高事务执行的成功概率。In the above embodiment, considering the atomicity of the transaction, by comparing the actual execution result with the predicted execution result, the transaction execution process error can be avoided, which is advantageous for improving the success probability of the transaction execution.
进一步,在现有技术中,由于无法预先知道事务需要执行的全部数据库操作指令,所以只能按照事务的执行逻辑依次执行数据库操作指令,这会导致应用服务器与数据库之间的频繁交互,这在远程应用场景中将会消耗大量网络资源。但在本实施例中,通过预测执行过程已经预先获得目标事务需要执行的全部数据库操作指令,即本地记录的数据库操作指令,因此在向数据库下发本地记录的数据库操作指令,以指示数据库执行数据库操作指令的过程中,可以将本地记录的数据库操作指令同时(或者一并)下发到数据库,有利于节约网络资源。另外,对于一些并行的数据库操作指令,数据库还可以并行操作,有利于进一步提高事务执行效率,增大事务吞吐量。Further, in the prior art, since all the database operation instructions that the transaction needs to execute cannot be known in advance, the database operation instruction can be executed sequentially according to the execution logic of the transaction, which causes frequent interaction between the application server and the database, which is A lot of network resources will be consumed in the remote application scenario. However, in this embodiment, all the database operation instructions that need to be executed by the target transaction, that is, the database operation instructions of the local record, have been obtained in advance by the prediction execution process, so the database operation instruction of the local record is sent to the database to instruct the database to execute the database. During the operation of the instruction, the database operation instruction of the local record can be simultaneously and/or sent to the database, which is conducive to saving network resources. In addition, for some parallel database operation instructions, the database can also operate in parallel, which is beneficial to further improve transaction execution efficiency and increase transaction throughput.
进一步,还可以将本地记录的所有数据库操作指令连同本地记录的预测执行数据一并下发给数据库。Further, all the database operation instructions of the local record can be sent to the database together with the locally recorded predicted execution data.
进一步,在一种根据本地记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行目标事务的可选实施方式中,数据库操作装置可以根据本地记录的数据库操作指令,判断目标事务是否为单机事务;若判断结果为是,则根据本地记录的数据库操作指令以及预测执行数据,以单机事务处理逻辑控制数据库实际执行目标事务;若判断结果为否,则根据本地记录的数据库操作指令以及预测执行数据,以分布式事务处理逻辑控制数据库实际执行目标事务。Further, in an optional implementation manner of controlling the actual execution target transaction of the database corresponding to the application server according to the locally recorded database operation instruction and the predicted execution data, the database operation device may determine whether the target transaction is based on the locally recorded database operation instruction. For a stand-alone transaction; if the result of the determination is yes, according to the locally recorded database operation instruction and the predicted execution data, the single-machine transaction logic is used to control the database to actually execute the target transaction; if the judgment result is no, the database operation instruction according to the local record and Predictive execution data, with distributed transaction processing logic to control the database to actually execute the target transaction.
其中,基于预测执行过程中获得的数据库操作指令可以识别出目标事务是单机事务还是分布式事务。例如,可以判断本地记录的数据库操作指令的操作对象是否作用于同一物理设备上,若判断结果为是,则可以确定该目标事务为单机事务;若判断结果为否,则可以确定该目标事务为分布式事务。The database operation instruction obtained during the prediction execution process can identify whether the target transaction is a stand-alone transaction or a distributed transaction. For example, it can be determined whether the operation object of the database operation instruction recorded locally acts on the same physical device. If the determination result is yes, the target transaction can be determined to be a stand-alone transaction; if the determination result is no, the target transaction can be determined as Distributed transactions.
由于分布式事务的处理逻辑和单机事务的处理逻辑有所不同,单机事务的处理逻辑相对简单,例如不涉及读写加锁等问题,所以所消耗的资源也相对较少。基于 此,本实施例通过识别目标事务是否为单机事务,在识别为单机事务时采用单机事务的处理逻辑进行处理,而不是像现有技术那样统一采用分布式事务处理逻辑进行处理,有利于提高处理效率,节约处理成本。Because the processing logic of distributed transactions is different from the processing logic of stand-alone transactions, the processing logic of single-machine transactions is relatively simple, for example, it does not involve problems such as read-write and lock, so the resources consumed are relatively small. based on Therefore, in this embodiment, by identifying whether the target transaction is a stand-alone transaction, the processing logic of the single-machine transaction is processed when it is recognized as a stand-alone transaction, instead of uniformly processing the distributed transaction processing logic as in the prior art, which is advantageous for improving processing. Efficiency, saving processing costs.
在一可选实施方式中,若数据库操作装置获取到目标事务中的事务回滚指令(即应用服务器执行到事务回滚指令)时,可以删除本地记录的数据库操作指令以及预测执行数据,例如可以直接清空本地内存库,实现回滚操作。在该情况下,由于目标事务并未在数据库中真正执行,所以数据库无需执行回滚操作,可见,在事务回滚这种情况下,采用本实施例方法也可以提高事务执行效率。In an optional implementation manner, if the database operation device acquires a transaction rollback instruction in the target transaction (that is, the application server performs a transaction rollback instruction), the database operation instruction of the local record and the prediction execution data may be deleted, for example, Clear the local memory library directly to implement the rollback operation. In this case, since the target transaction is not actually executed in the database, the database does not need to perform a rollback operation. It can be seen that in the case of transaction rollback, the transaction efficiency can be improved by using the method of this embodiment.
由上述可见,在本实施例提供的方法中,数据库操作装置与应用服务器相互配合,在应用服务器执行目标事务的过程加入预测执行过程,在预测执行过程中,可以提前获得目标事务的执行路径,即真正需要执行的数据库操作指令,并仅针对属于修改数据库类指令的数据库操作指令记录预测执行产生的预测执行数据以适应于读已提交隔离级别,为真实执行事务提供了条件,之后在根据记录的数据库操作指令以及预测执行数据实际执行该目标事务时,例如基于预测执行数据可以提前获取有关数据信息并且可以减少指令之间的跳转等,因此可以提高执行效率,增大事务吞吐量。It can be seen from the above that in the method provided by the embodiment, the database operating device cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and the execution path of the target transaction can be obtained in advance during the predictive execution process. That is, the database operation instruction that really needs to be executed, and only the prediction execution data generated by the prediction execution of the database operation instruction belonging to the modified database class instruction is adapted to read the submitted isolation level, and the condition for the real execution transaction is provided, and then the record is based on the record. When the database operation instruction and the prediction execution data actually execute the target transaction, for example, based on the prediction execution data, related data information can be acquired in advance and jumps between instructions can be reduced, etc., thereby improving execution efficiency and increasing transaction throughput.
下面以减库存事务为例,详细说明本申请技术方案的工作流程。其中,数据库的隔离级别为读已提交这一隔离级别。In the following, taking the inventory reduction transaction as an example, the workflow of the technical solution of the present application will be described in detail. The isolation level of the database is the isolation level that the read has been submitted.
减库存事务的SQL代码如下,括号内的文字为注释:The SQL code for the inventory reduction transaction is as follows, the text in parentheses is a comment:
begin transaction(开始事务)Begin transaction
select*from inventory where itemId=?(用商品id查看当前库存,注意这里没有for update外部显示加锁)Select*from inventory where itemId=? (Use the product id to view the current inventory, note that there is no for update external display lock)
if(item.inventory>0)If(item.inventory>0)
item.inventory--;Item.inventory--;
update inventory set item.inventory=$item.inventory where itemId=?Update inventory set item.inventory=$item.inventory where itemId=?
commit;Commit;
elseElse
rollback;(如果当前库存大于0,则减少、更新商品库存并提交,否则回滚)Rollback; (If the current inventory is greater than 0, reduce, update the commodity inventory and submit, otherwise roll back)
在实际执行过程中,应用服务器负责该减库存事务的整个逻辑,数据库操作装置(或者也可称为执行服务器)只会获取应用服务器执行到的开始事务,需要执行 的SQL语句,以及提交/回滚指令。In the actual execution process, the application server is responsible for the entire logic of the inventory reduction transaction, and the database operation device (or may also be referred to as an execution server) only obtains the start transaction executed by the application server, and needs to be executed. SQL statements, as well as commit/rollback instructions.
首先,开始事务后,数据库操作装置在本地创建内存库;First, after starting the transaction, the database operating device creates a memory library locally;
当数据库操作装置获取到select*from inventory where itemId=?for update这条SQL语句时,识别出这条SQL语句不会修改数据库,因此将这条SQL语句直接作用在实际数据库中,即在数据库中执行该条SQL语句以获得查询结果,即读数据集,将全部查询结果返回给应用服务器,以供应用服务器确定下一个需要执行的SQL语句,并在本地内存库中记录这条SQL语句。由于是读已隔离级别,故不需要记录任何与执行该条SQL语句有关的数据。When the database operating device gets select*from inventory where itemId=? For update this SQL statement, recognize that this SQL statement will not modify the database, so this SQL statement directly in the actual database, that is, execute the SQL statement in the database to obtain the query result, that is, read the data set , return all the query results to the application server, to supply the server to determine the next SQL statement to be executed, and record the SQL statement in the local memory. Since it is a read isolation level, there is no need to record any data related to executing the SQL statement.
应用服务器收到数据库操作装置返回的查询结果后,判断查询结果中当前库存量是否大于0,若判断结果为是,则将当前库存量减少,并执行更新语句,即update inventory set item.inventory=$item.inventory where itemId=?;若判断结果为否,则执行rollback语句。After receiving the query result returned by the database operation device, the application server determines whether the current inventory quantity in the query result is greater than 0. If the determination result is yes, the current inventory quantity is reduced, and the update statement is executed, that is, update inventory set item.inventory= $item.inventory where itemId=? If the result of the judgment is no, the rollback statement is executed.
第一种情况,假设应用服务器执行了rollback语句,则数据库操作装置会获取到rollback语句。一旦数据库存储装置获取到rollback语句,则清空本地内存库,主要是指清空之前记录的select*from inventory where itemId=?for update这条SQL语句。在这种情况下,因为事务并没有在数据库中执行,所以无需数据库执行回滚操作。In the first case, if the application server executes the rollback statement, the database operation device will get the rollback statement. Once the database storage device obtains the rollback statement, the local memory library is cleared, mainly referring to the select*from inventory where itemId=? For update this SQL statement. In this case, because the transaction is not executed in the database, there is no need for the database to perform a rollback operation.
第二种情况,假设应用服务器执行了update inventory set item.inventory=$item.inventory where itemId=?这条语句,则数据库操作装置会获取到update inventory set item.inventory=$item.inventory where itemId=?这条语句。则数据库操作装置获取到update inventory set item.inventory=?where itemId=?这条SQL语句时,识别出该SQL语句会修改数据库,于是将这条SQL语句拆解为一个读指令,即select*from inventory where itemId=?和一个写指令,即update inventory set item.inventory=?where itemId=?;接着,将select*from inventory where itemId=?这个语句下发到数据库中,获得读数据集,将读数据集中的数据写入本地内存库中;其中,读数据集中包括主键列表(itemId)和该主键对应的版本号信息(version)。然后,根据update inventory set item.inventory=?where itemId=?这个语句在本地内存库中进行更新操作,以获得结果数据集,并将结果数据集返回给应用服务器。该结果数据集可以是类似修改了几条记录这样的修改记录信息,例如,affectRow=1表示修改了一条记录;或者,结果数据集也可以是记录修改详细信息的修改详情信息。 其中,结果数据集和读数据集构成预测执行数据。In the second case, suppose the application server executes update inventory set item.inventory=$item.inventory where itemId=? In this statement, the database operating device will get update inventory set item.inventory=$item.inventory where itemId=? This statement. Then the database operating device obtains update inventory set item.inventory=? Where itemId=? In this SQL statement, it is recognized that the SQL statement will modify the database, so the SQL statement is disassembled into a read instruction, ie select*from inventory where itemId=? And a write command, ie update inventory set item.inventory=? Where itemId=? Then, select*from inventory where itemId=? The statement is sent to the database, and the read data set is obtained, and the data in the read data set is written into the local memory library; wherein the read data set includes a primary key list (itemId) and a version number information (version) corresponding to the primary key. Then, according to update inventory set item.inventory=? Where itemId=? This statement is updated in the local memory library to obtain the resulting data set and return the resulting data set to the application server. The result data set may be modified record information similar to the modification of several records. For example, affectRow=1 indicates that a record is modified; or the result data set may also be modification details of the record modification detailed information. Among them, the result data set and the read data set constitute prediction execution data.
应用服务器此时执行commit指令。The application server executes the commit command at this time.
当数据库操作装置获取到commit指令后,基于本地内存库中的SQL语句以及预测执行数据,在数据库中执行该减库存事务,这次事务执行过程是真实执行的。例如,本地记录的SQL语句以及预测执行数据如下所示:After the database operating device obtains the commit command, the inventory reduction transaction is executed in the database based on the SQL statement in the local memory library and the predicted execution data, and the transaction execution process is actually performed. For example, the locally recorded SQL statement and the predicted execution data are as follows:
{{
      select*from inventory where itemId=?Select*from inventory where itemId=?
      update inventory set item.inventory=?where itemId=?【readVersion:itemId=xxx and version=xxx/affectRow=1】Update inventory set item.inventory=? Where itemId=? [readVersion:itemId=xxx and version=xxx/affectRow=1]
commit()Commit()
}}
优选的,数据库操作装置可以一次性将本地内存库中的SQL语句全部提交到数据库中,数据库基于此进行执行,有利于节约传输SQL语句所消耗的网络资源。Preferably, the database operating device can submit all the SQL statements in the local memory library to the database at one time, and the database performs the execution based on this, which is beneficial to save network resources consumed by the transmission of the SQL statement.
这次真实执行也会返回执行结果,可以将预测执行结果与实际执行结果进行比较,例如可以先比较两个结果中的itemId和version,然后再比较两个结果中的affectRow;如果比较结果为相同,则可以在数据库中提交这次事务,而如果比较结果为不相同,则认为提交是失败的,由于在这种情况下,事务本身其实一直都没有真正的在数据库中执行提交,所以可以简单地回滚整个请求,让应用服务器重新提交即可。This real execution will also return the execution result. You can compare the predicted execution result with the actual execution result. For example, you can compare the itemId and version of the two results first, and then compare the affectRow of the two results; if the comparison result is the same , you can submit this transaction in the database, and if the comparison result is not the same, then the submission is considered to be a failure, because in this case, the transaction itself has not actually executed the submission in the database, so it can be simple Roll back the entire request and let the application server resubmit.
其中,经过上述预测执行,已经获得了所有的需要执行的SQL语句,以及相应的预测执行数据,例如全部切分条件,数值的索引等,而这些数据足以让我们提前对事务是否是单机事务做出判断。基于此,可以采用相应的事务处理逻辑进行处理,有利于节约资源。Among them, after the above prediction execution, all the SQL statements that need to be executed, and the corresponding predicted execution data, such as all the segmentation conditions, the index of the values, etc., have been obtained, and the data is sufficient for us to advance whether the transaction is a stand-alone transaction. Make a judgment. Based on this, the corresponding transaction logic can be used for processing, which is conducive to saving resources.
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本申请所必须的。It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the present application is not limited by the described action sequence. Because certain steps may be performed in other sequences or concurrently in accordance with the present application. In the following, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。 In the above embodiments, the descriptions of the various embodiments are different, and the details that are not detailed in a certain embodiment can be referred to the related descriptions of other embodiments.
图4为本申请一实施例提供的数据库操作装置的结构示意图。如图4所示,该装置包括:获取模块41、预测执行模块42和控制执行模块43。FIG. 4 is a schematic structural diagram of a database operating device according to an embodiment of the present application. As shown in FIG. 4, the apparatus includes an acquisition module 41, a prediction execution module 42, and a control execution module 43.
获取模块41,用于在应用服务器执行目标事务的过程中,依次获取应用服务器执行到的目标事务中的数据库操作指令。The obtaining module 41 is configured to sequentially acquire a database operation instruction in the target transaction executed by the application server during the execution of the target transaction by the application server.
预测执行模块42,用于对数据库操作指令进行预测执行,将预测执行结果返回给应用服务器以供应用服务器确定下一个需要执行的数据库操作指令,并在本地记录数据库操作指令以及在数据库操作指令属于修改数据库类指令时记录预测执行产生的预测执行数据。The prediction execution module 42 is configured to perform predictive execution on the database operation instruction, return the predicted execution result to the application server to supply the server to determine the next database operation instruction to be executed, and locally record the database operation instruction and the database operation instruction belongs to The predicted execution data generated by the prediction execution is recorded when the database class instruction is modified.
控制执行模块43,用于当获取到目标事务中的事务提交指令时,根据本地记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行目标事务。The control execution module 43 is configured to, when acquiring the transaction commit instruction in the target transaction, control the database corresponding to the application server to actually execute the target transaction according to the locally recorded database operation instruction and the predicted execution data.
在一可选实施方式中,该数据库操作装置还包括:配置模块,用于在应用服务器执行目标事务之前,配置数据库为读已提交隔离级别。In an optional implementation, the database operating device further includes: a configuration module, configured to configure the database to read the submitted isolation level before the application server performs the target transaction.
在一可选实施方式中,获取模块41具体可用于:拦截应用服务器发往数据库的数据库操作指令;或者,接收应用服务器主动下发的数据库操作指令。In an optional implementation, the obtaining module 41 is specifically configured to: intercept a database operation instruction sent by the application server to the database; or receive a database operation instruction that is actively sent by the application server.
在一可选实施方式中,获取模块41还用于:在获取应用服务器执行到的目标事务中的数据库操作指令之前,拦截应用服务器发往数据库的目标事务中的事务开始指令;或者,接收应用服务器主动下发的目标事务中的事务开始指令。In an optional implementation, the obtaining module 41 is further configured to: before acquiring the database operation instruction in the target transaction executed by the application server, intercepting a transaction start instruction in the target transaction sent by the application server to the database; or receiving the application The transaction start instruction in the target transaction that the server actively delivers.
在一可选实施方式中,预测执行模块42具体可用于:In an optional implementation, the prediction execution module 42 is specifically configured to:
若获取模块41获取到的数据库操作指令属于修改数据库类指令,在本地创建的内存库中模拟数据库操作指令的数据环境,基于模拟的数据环境对数据库操作指令进行预测执行;If the database operation instruction acquired by the obtaining module 41 belongs to the modified database class instruction, the data environment of the database operation instruction is simulated in the locally created memory library, and the database operation instruction is predicted and executed based on the simulated data environment;
若获取模块41获取到的数据库操作指令不属于修改数据库类指令,在数据库中执行数据库操作指令,以对数据库操作指令进行预测执行。If the database operation instruction acquired by the obtaining module 41 does not belong to the modified database class instruction, the database operation instruction is executed in the database to perform prediction execution on the database operation instruction.
进一步,在获取模块41获取到的数据库操作指令属于修改数据库类指令的情况下,预测执行模块42在执行在本地创建的内存库中模拟数据库操作指令的数据环境,基于模拟的数据环境对数据库操作指令进行预测执行的操作时,具体用于:Further, in the case that the database operation instruction acquired by the obtaining module 41 belongs to the modified database class instruction, the prediction execution module 42 simulates the data environment of the database operation instruction in the locally created memory library, and operates the database based on the simulated data environment. When the instruction performs the operation of predictive execution, it is specifically used to:
将数据库操作指令拆分为读指令和写指令;Splitting database operation instructions into read instructions and write instructions;
在数据库中执行读指令以获取读数据集,将读数据集存入内存库中以模拟数据库操作指令的数据环境; Executing a read instruction in the database to obtain a read data set, and storing the read data set in a memory library to simulate a data environment of the database operation instruction;
在内存库中执行写指令以修改读数据集。A write instruction is executed in the memory bank to modify the read data set.
在一可选实施方式中,控制执行模块43具体可用于:In an optional implementation, the control execution module 43 is specifically configured to:
向数据库下发本地记录的数据库操作指令,以指示数据库执行数据库操作指令,并接收数据库返回的数据库操作指令的实际执行结果;The database operation instruction of the local record is sent to the database to instruct the database to execute the database operation instruction, and receives the actual execution result of the database operation instruction returned by the database;
若实际执行结果与预测执行结果相同,向数据库下发事务提交指令,以供数据库提交目标事务;If the actual execution result is the same as the predicted execution result, the transaction commit instruction is sent to the database for the database to submit the target transaction;
若实际执行结果与预测执行结果不相同,向数据库下发事务回滚指令,以供数据库回滚目标事务。考虑到事务的原子性,控制执行模块43通过将实际执行结果与预测执行结果进行比较,可以避免事务执行过程出错,有利于提高事务执行的成功概率。If the actual execution result is different from the predicted execution result, a transaction rollback instruction is issued to the database for the database to roll back the target transaction. Considering the atomicity of the transaction, the control execution module 43 can avoid the error of the transaction execution process by comparing the actual execution result with the predicted execution result, and is beneficial to improving the success probability of the transaction execution.
进一步,控制执行模块43在向数据库下发本地记录的数据库操作指令时,具体可用于:将本地记录的数据库操作指令同时下发给数据库,有利于节约网络资源。Further, when the database execution instruction of the local record is sent to the database, the control execution module 43 can be used to: simultaneously send the database operation instruction of the local record to the database, which is beneficial to save network resources.
进一步,控制执行模块43可以将本地记录的所有数据库操作指令连同本地记录的预测执行数据一并下发给数据库,有利于节约网络资源。Further, the control execution module 43 can send all the database operation instructions recorded locally together with the locally recorded predicted execution data to the database, which is beneficial to save network resources.
在一可选实施方式中,控制执行模块43具体用于:In an optional implementation, the control execution module 43 is specifically configured to:
根据本地记录的数据库操作指令,判断目标事务是否为单机事务;Determining whether the target transaction is a stand-alone transaction according to a locally recorded database operation instruction;
若判断结果为是,则根据本地记录的数据库操作指令以及预测执行数据,以单机事务处理逻辑控制数据库实际执行目标事务;If the result of the determination is yes, according to the locally recorded database operation instruction and the predicted execution data, the single-machine transaction logic is used to control the database to actually execute the target transaction;
若判断结果为否,则根据本地记录的数据库操作指令以及预测执行数据,以分布式事务处理逻辑控制数据库实际执行目标事务。由于分布式事务的处理逻辑和单机事务的处理逻辑有所不同,单机事务的处理逻辑相对简单,例如不涉及读写加锁等问题,所以所消耗的资源也相对较少。基于此,控制执行模块43通过识别目标事务是否为单机事务,在识别为单机事务时采用单机事务的处理逻辑进行处理,有利于提高处理效率,节约处理成本。If the result of the determination is no, the database actually controls the target transaction by the distributed transaction logic according to the locally recorded database operation instruction and the predicted execution data. Because the processing logic of distributed transactions is different from the processing logic of stand-alone transactions, the processing logic of single-machine transactions is relatively simple, for example, it does not involve problems such as read-write and lock, so the resources consumed are relatively small. Based on this, the control execution module 43 performs processing by using the processing logic of the single-machine transaction when identifying the target transaction as a stand-alone transaction, which is beneficial to improve processing efficiency and save processing cost.
在一可选实施方式中,预测执行模块42还用于:在获取到目标事务中的事务回滚指令时,删除本地记录的数据库操作指令以及预测执行数据。In an optional implementation, the predictive execution module 42 is further configured to: delete the locally recorded database operation instruction and the predicted execution data when the transaction rollback instruction in the target transaction is acquired.
本实施例提供的数据库操作装置,其可以单独部署,位于应用服务器和数据库之间,也可以部署于应用服务器一端实现,或者也可以部署于数据库一端实现。The database operating device provided in this embodiment may be deployed separately, and may be located between the application server and the database, or may be deployed on one end of the application server, or may be deployed on one end of the database.
本实施例提供的数据库操作装置,与应用服务器相互配合,在应用服务器执行目标事务的过程加入预测执行过程,预先获得并记录目标事务需要执行的全部数据 库操作指令,并仅针对属于修改数据库类指令的数据库操作指令记录预测执行产生的预测执行数据以适应于读已提交隔离级别,为真实执行事务提供了条件,之后根据记录的数据库操作指令以及预测执行数据,控制应用服务器对应的数据库实际执行该目标事务,有利于提高执行效率,增大事务吞吐量。The database operating device provided in this embodiment cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and obtains and records all the data that the target transaction needs to execute in advance. The library operates on instructions and records the predicted execution data generated by the prediction execution only for the database operation instructions belonging to the modified database class instruction to adapt to the read committed isolation level, providing conditions for the real execution of the transaction, and then based on the recorded database operation instructions and predictions. Executing data and controlling the database corresponding to the application server to actually execute the target transaction is beneficial to improve execution efficiency and increase transaction throughput.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the system, the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present application, it should be understood that the disclosed system, apparatus, and method may be implemented in other manners. For example, the device embodiments described above are merely illustrative. For example, the division of the unit is only a logical function division. In actual implementation, there may be another division manner, for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
上述以软件功能单元的形式实现的集成的单元,可以存储在一个计算机可读取存储介质中。上述软件功能单元存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器(processor)执行本申请各个实施例所述方法的部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The above-described integrated unit implemented in the form of a software functional unit can be stored in a computer readable storage medium. The software functional unit described above is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform the methods described in various embodiments of the present application. Part of the steps. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program codes. .
最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理 解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。 Finally, it should be noted that the above embodiments are only used to explain the technical solutions of the present application, and are not limited thereto; although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should Solution: The technical solutions described in the foregoing embodiments may be modified, or some of the technical features may be equivalently replaced; and the modifications or replacements do not deviate from the technical solutions of the embodiments of the present application. Spirit and scope.

Claims (12)

  1. 一种数据库操作方法,其特征在于,包括:A database operation method, comprising:
    在应用服务器执行目标事务的过程中,依次获取所述应用服务器执行到的所述目标事务中的数据库操作指令;And acquiring, in the process of executing the target transaction by the application server, the database operation instruction in the target transaction executed by the application server;
    对所述数据库操作指令进行预测执行,将预测执行结果返回给所述应用服务器以供所述应用服务器确定下一个需要执行的数据库操作指令,并在本地记录所述数据库操作指令以及在所述数据库操作指令属于修改数据库类指令时记录所述预测执行产生的预测执行数据;Performing predictive execution on the database operation instruction, returning the predicted execution result to the application server for the application server to determine the next database operation instruction to be executed, and locally recording the database operation instruction and the database The operation instruction belongs to the prediction execution data generated by the prediction execution when the database type instruction is modified;
    当获取到所述目标事务中的事务提交指令时,根据本地记录的所述数据库操作指令以及所述预测执行数据,控制所述应用服务器对应的数据库实际执行所述目标事务。When the transaction commit instruction in the target transaction is obtained, the database corresponding to the application server is controlled to actually execute the target transaction according to the database operation instruction recorded locally and the predicted execution data.
  2. 根据权利要求1所述的方法,其特征在于,还包括:The method of claim 1 further comprising:
    在所述应用服务器执行所述目标事务之前,配置所述数据库为读已提交隔离级别。The database is configured to read the committed isolation level before the application server executes the target transaction.
  3. 根据权利要求1所述的方法,其特征在于,所述对所述数据库操作指令进行预测执行,包括:The method according to claim 1, wherein said predicting execution of said database operation instruction comprises:
    若所述数据库操作指令属于修改数据库类指令,在本地创建的内存库中模拟所述数据库操作指令的数据环境,基于所述模拟的数据环境对所述数据库操作指令进行预测执行;If the database operation instruction belongs to a modification database class instruction, simulate a data environment of the database operation instruction in a locally created memory library, and perform prediction execution on the database operation instruction based on the simulated data environment;
    若所述数据库操作指令不属于修改数据库类指令,在所述数据库中执行所述数据库操作指令,以对所述数据库操作指令进行预测执行。If the database operation instruction does not belong to a modification database class instruction, the database operation instruction is executed in the database to perform prediction execution on the database operation instruction.
  4. 根据权利要求3所述的方法,其特征在于,所述在本地创建的内存库中模拟所述数据库操作指令所需的数据环境,基于所述模拟的数据环境对所述数据库操作指令进行预测执行,包括:The method according to claim 3, wherein said data environment required for said database operation instruction is simulated in a locally created memory library, and said database operation instruction is predicted to be executed based on said simulated data environment ,include:
    将所述数据库操作指令拆分为读指令和写指令;Splitting the database operation instruction into a read instruction and a write instruction;
    在所述数据库中执行所述读指令以获取读数据集,将所述读数据集存入所述内存库中以模拟所述数据库操作指令的数据环境;Executing the read instruction in the database to obtain a read data set, and storing the read data set in the memory library to simulate a data environment of the database operation instruction;
    在所述内存库中执行所述写指令以修改所述读数据集。The write instruction is executed in the memory bank to modify the read data set.
  5. 根据权利要求1-4任一项所述的方法,其特征在于,所述根据本地记录的所述数据库操作指令以及所述预测执行数据,控制所述应用服务器对应的数据库实际 执行所述目标事务,包括:The method according to any one of claims 1 to 4, wherein the controlling the actual database corresponding to the application server according to the locally recorded database operation instruction and the predicted execution data Perform the target transaction, including:
    向所述数据库下发本地记录的所述数据库操作指令,以指示所述数据库执行所述数据库操作指令,并接收所述数据库返回的所述数据库操作指令的实际执行结果;And sending the locally recorded database operation instruction to the database to instruct the database to execute the database operation instruction, and receiving an actual execution result of the database operation instruction returned by the database;
    若所述实际执行结果与所述预测执行结果相同,向所述数据库下发所述事务提交指令,以供所述数据库提交所述目标事务;And if the actual execution result is the same as the predicted execution result, the transaction commit instruction is sent to the database for the database to submit the target transaction;
    若所述实际执行结果与所述预测执行结果不相同,向所述数据库下发事务回滚指令,以供所述数据库回滚所述目标事务。If the actual execution result is different from the predicted execution result, a transaction rollback instruction is sent to the database for the database to roll back the target transaction.
  6. 根据权利要求5所述的方法,其特征在于,所述向所述数据库下发本地记录的所述数据库操作指令,包括:The method according to claim 5, wherein the issuing the database operation instruction of the local record to the database comprises:
    将本地记录的所述数据库操作指令同时下发给所述数据库。The database operation instruction of the local record is simultaneously sent to the database.
  7. 一种数据库操作装置,其特征在于,包括:A database operating device, comprising:
    获取模块,用于在应用服务器执行目标事务的过程中,依次获取所述应用服务器执行到的所述目标事务中的数据库操作指令;An obtaining module, configured to sequentially acquire a database operation instruction in the target transaction executed by the application server during a process of executing a target transaction by the application server;
    预测执行模块,用于对所述数据库操作指令进行预测执行,将预测执行结果返回给所述应用服务器以供所述应用服务器确定下一个需要执行的数据库操作指令,并在本地记录所述数据库操作指令以及在所述数据库操作指令属于修改数据库类指令时记录所述预测执行产生的预测执行数据;a predictive execution module, configured to perform predictive execution on the database operation instruction, return a predicted execution result to the application server, for the application server to determine a next database operation instruction to be executed, and locally record the database operation And predicting execution data generated by the prediction execution when the database operation instruction belongs to modifying a database class instruction;
    控制执行模块,用于当获取到所述目标事务中的事务提交指令时,根据本地记录的所述数据库操作指令以及所述预测执行数据,控制所述应用服务器对应的数据库实际执行所述目标事务。a control execution module, configured to: when the transaction commit instruction in the target transaction is obtained, control the database corresponding to the application server to actually execute the target transaction according to the database operation instruction recorded locally and the predicted execution data .
  8. 根据权利要求7所述的装置,其特征在于,还包括:The device according to claim 7, further comprising:
    配置模块,用于在所述应用服务器执行所述目标事务之前,配置所述数据库为读已提交隔离级别。And a configuration module, configured to configure the database to read the submitted isolation level before the application server executes the target transaction.
  9. 根据权利要求7所述的装置,其特征在于,所述预测执行模块具体用于:The apparatus according to claim 7, wherein the prediction execution module is specifically configured to:
    若所述数据库操作指令属于修改数据库类指令,在本地创建的内存库中模拟所述数据库操作指令的数据环境,基于所述模拟的数据环境对所述数据库操作指令进行预测执行;If the database operation instruction belongs to a modification database class instruction, simulate a data environment of the database operation instruction in a locally created memory library, and perform prediction execution on the database operation instruction based on the simulated data environment;
    若所述数据库操作指令不属于修改数据库类指令,在所述数据库中执行所述数据库操作指令,以对所述数据库操作指令进行预测执行。 If the database operation instruction does not belong to a modification database class instruction, the database operation instruction is executed in the database to perform prediction execution on the database operation instruction.
  10. 根据权利要求9所述的装置,其特征在于,所述预测执行模块具体用于:The apparatus according to claim 9, wherein the prediction execution module is specifically configured to:
    将所述数据库操作指令拆分为读指令和写指令;Splitting the database operation instruction into a read instruction and a write instruction;
    在所述数据库中执行所述读指令以获取读数据集,将所述读数据集存入所述内存库中以模拟所述数据库操作指令的数据环境;Executing the read instruction in the database to obtain a read data set, and storing the read data set in the memory library to simulate a data environment of the database operation instruction;
    在所述内存库中执行所述写指令以修改所述读数据集。The write instruction is executed in the memory bank to modify the read data set.
  11. 根据权利要求7-10任一项所述的装置,其特征在于,所述控制执行模块具体用于:The device according to any one of claims 7 to 10, wherein the control execution module is specifically configured to:
    向所述数据库下发本地记录的所述数据库操作指令,以指示所述数据库执行所述数据库操作指令,并接收所述数据库返回的所述数据库操作指令的实际执行结果;And sending the locally recorded database operation instruction to the database to instruct the database to execute the database operation instruction, and receiving an actual execution result of the database operation instruction returned by the database;
    若所述实际执行结果与所述预测执行结果相同,向所述数据库下发所述事务提交指令,以供所述数据库提交所述目标事务;And if the actual execution result is the same as the predicted execution result, the transaction commit instruction is sent to the database for the database to submit the target transaction;
    若所述实际执行结果与所述预测执行结果不相同,向所述数据库下发事务回滚指令,以供所述数据库回滚所述目标事务。If the actual execution result is different from the predicted execution result, a transaction rollback instruction is sent to the database for the database to roll back the target transaction.
  12. 根据权利要求11所述的装置,其特征在于,所述控制执行模块具体用于:The device according to claim 11, wherein the control execution module is specifically configured to:
    将本地记录的所述数据库操作指令同时下发给所述数据库。 The database operation instruction of the local record is simultaneously sent to the database.
PCT/CN2016/097266 2015-09-08 2016-08-30 Database operating method and device WO2017041637A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510568369.7 2015-09-08
CN201510568369.7A CN106503027B (en) 2015-09-08 2015-09-08 Database operation method and device

Publications (1)

Publication Number Publication Date
WO2017041637A1 true WO2017041637A1 (en) 2017-03-16

Family

ID=58240569

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/097266 WO2017041637A1 (en) 2015-09-08 2016-08-30 Database operating method and device

Country Status (2)

Country Link
CN (1) CN106503027B (en)
WO (1) WO2017041637A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111930830A (en) * 2020-06-22 2020-11-13 心有灵犀科技股份有限公司 Distributed transaction data processing method and system based on shared database

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111198872B (en) * 2020-01-06 2021-06-11 中科驭数(北京)科技有限公司 Method and device for processing transactions by database
CN111580938B (en) * 2020-03-27 2023-04-14 浪潮通用软件有限公司 Transaction processing method, device, equipment and medium for work unit

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090187534A1 (en) * 2008-01-21 2009-07-23 International Business Machines Corporation Transaction prediction modeling method
CN101587447A (en) * 2008-05-23 2009-11-25 国际商业机器公司 System supporting transaction storage and prediction-based transaction execution method
CN102203779A (en) * 2011-05-03 2011-09-28 华为技术有限公司 Method for updating data and control apparatus thereof
US20140214880A1 (en) * 2013-01-29 2014-07-31 Nec Laboratories America, Inc. System and methods for Predicting Query Execution Time for Concurrent and Dynamic Database Workloads

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB0318196D0 (en) * 2003-08-02 2003-09-03 Ibm A method apparatus and computer program for processing a queue of messages
CN106503007B (en) * 2015-09-08 2019-07-23 阿里巴巴集团控股有限公司 Database operation method and device
CN106897306B (en) * 2015-12-21 2019-04-30 阿里巴巴集团控股有限公司 Database operation method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090187534A1 (en) * 2008-01-21 2009-07-23 International Business Machines Corporation Transaction prediction modeling method
CN101587447A (en) * 2008-05-23 2009-11-25 国际商业机器公司 System supporting transaction storage and prediction-based transaction execution method
CN102203779A (en) * 2011-05-03 2011-09-28 华为技术有限公司 Method for updating data and control apparatus thereof
US20140214880A1 (en) * 2013-01-29 2014-07-31 Nec Laboratories America, Inc. System and methods for Predicting Query Execution Time for Concurrent and Dynamic Database Workloads

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111930830A (en) * 2020-06-22 2020-11-13 心有灵犀科技股份有限公司 Distributed transaction data processing method and system based on shared database

Also Published As

Publication number Publication date
CN106503027A (en) 2017-03-15
CN106503027B (en) 2020-02-21

Similar Documents

Publication Publication Date Title
WO2017041639A1 (en) Database operating method and device
EP3446242B1 (en) Query plan generation and execution in a relational database management system with a temporal-relational database
US11429584B2 (en) Automatic determination of table distribution for multinode, distributed database systems
WO2017107811A1 (en) Database operating method and device
US9256643B2 (en) Technique for factoring uncertainty into cost-based query optimization
CN106897123B (en) Database operation method and device
TWI774643B (en) Database operation method and device
WO2017041637A1 (en) Database operating method and device
CN103377292B (en) Database result set caching method and device
KR102244887B1 (en) Method and system for recommending SQL query
US11294906B2 (en) Database record searching with multi-tier queries
TWI805544B (en) Database operation method and device
TWI725110B (en) Database operation method and device
TWI735512B (en) Database operation method and device
US20160048559A1 (en) Data modification in hypothetical planning
US20160004747A1 (en) Join query execution method and device, and storage medium
TWI790991B (en) Database operation method and device
US20200175402A1 (en) In-database predictive pipeline incremental engine
US20240086387A1 (en) Delta transition table for database triggers

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16843575

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16843575

Country of ref document: EP

Kind code of ref document: A1