WO2023134614A1 - 事务的处理 - Google Patents
事务的处理 Download PDFInfo
- Publication number
- WO2023134614A1 WO2023134614A1 PCT/CN2023/071213 CN2023071213W WO2023134614A1 WO 2023134614 A1 WO2023134614 A1 WO 2023134614A1 CN 2023071213 W CN2023071213 W CN 2023071213W WO 2023134614 A1 WO2023134614 A1 WO 2023134614A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- database
- transaction
- statement
- node
- connection
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/242—Query formulation
- G06F16/2433—Query languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/466—Transaction processing
Definitions
- the present disclosure relates to the field of distributed databases, and more particularly, to a method and device for processing transactions.
- Distributed data includes multiple database nodes.
- the existing technology will first establish a database connection with one of the database nodes, and then the database node will forward the transaction to other database nodes within the database, so that other database nodes Perform remote transaction execution. Excessive remote transaction execution will reduce the processing efficiency of non-read-only transactions.
- the disclosure provides a transaction processing method and device to improve the processing efficiency of non-read-only transactions in a distributed database.
- a method for processing transactions including: receiving a first transaction, the first transaction is a non-read-only transaction, the first transaction includes a first database statement and a second database statement, and the first The database statement and the second database statement are respectively used to operate the first database node and the second database node in the distributed database; establish a first database connection with the first database node; connect through the first database Sending the first database statement to the first database node; establishing a second database connection with the second database node; sending the second database statement to the second database node through the second database connection.
- the method further includes: receiving feedback information from the first database for the first database statement, the feedback information including control information of the first transaction;
- the database node sends the control information.
- control information of the first transaction includes an execution result of the first database statement and/or a status of the first transaction.
- the database statement in the first transaction is an SQL statement.
- an apparatus for processing transactions including: a receiving unit configured to receive a first transaction, the first transaction is a non-read-only transaction, and the first transaction includes a first database statement and a second database statement statement, the first database statement and the second database statement are respectively used to operate the first database node and the second database node in the distributed database; the first connection unit is configured to communicate with the first database A node establishes a first database connection; a first sending unit is configured to send the first database statement to the first database node through the first database connection; a second connection unit is configured to communicate with the second The database node establishes a second database connection; the second sending unit is configured to send the second database statement to the second database node through the second database connection.
- the receiving unit is further configured to: receive feedback information from the first database for the first database statement, where the feedback information includes control information of the first transaction; the second sending unit It is also configured to: send the control information to the database node corresponding to the second database statement.
- the first connection unit is further configured to: disconnect the first database connection.
- the database statement in the first transaction is an SQL statement.
- an apparatus for processing transactions including a memory and a processor, wherein executable codes are stored in the memory, and the processor is configured to execute the executable codes, so as to implement the above described in the first aspect Methods.
- a computer-readable storage medium on which executable code is stored, and when the executable code is executed, the method as described in the first aspect can be implemented.
- a computer program product including executable code, and when the executable code is executed, the method as described in the first aspect can be realized.
- a connection is often only established with one of the database nodes.
- the embodiments of the present disclosure can establish multiple database connections with multiple database nodes when processing non-read-only transactions, and directly transmit transaction-related database statements to the multiple database nodes through the multiple database connections . In this way, a large number of remote transaction executions caused by establishing only one database connection can be avoided, thereby improving the processing efficiency of non-read-only transactions.
- control information of the first transaction returned by the first database can be received, and the control information can be forwarded to the database node corresponding to the second database statement, so that the database node corresponding to the second database statement can know the first transaction
- the control information of the first transaction avoids the need for the database node corresponding to the second database statement to obtain the control information of the first transaction through remote execution in the traditional solution, which is beneficial to reduce the overhead occupied by remote execution in the database.
- FIG. 1 is a schematic flow chart of transaction processing provided by related technologies.
- Fig. 2 is a schematic flowchart of a method for processing transactions provided by an embodiment of the present disclosure.
- Fig. 3 is a schematic flowchart of a method for processing a transaction provided by another embodiment of the present disclosure.
- Fig. 4 is a schematic flowchart of a method for processing a transaction provided by another embodiment of the present disclosure.
- Fig. 5 is a schematic structural diagram of an apparatus for processing transactions provided by an embodiment of the present disclosure.
- Fig. 6 is a schematic structural diagram of an apparatus for processing transactions provided by yet another embodiment of the present disclosure.
- Structured query language (structured query language, SQL) is a special programming language. Structured query language is used to access data and query, update and manage database systems.
- Structured Query Language is a high-level non-procedural programming language that allows users to work on high-level data structures. It does not require the user to specify the data storage method, nor does it require the user to understand the specific data storage method. Therefore, different database systems with completely different underlying structures can use the same structured query language as an interface for data entry and management. Statements in Structured Query Language can be nested, which makes it extremely flexible and powerful.
- a transaction is a set of operations on a database.
- a transaction can consist of one or more database statements.
- a transaction is an indivisible unit of execution in a database.
- Transaction-related statements include start transaction, end transaction, commit transaction, rollback transaction, etc.
- ACID atomicity
- consistency consistency
- isolation isolation
- durability durability
- Atomicity means that the statements in a transaction need to be committed or rolled back together.
- a transaction in which user A transfers 100 yuan to user B includes two operations: deduction of 100 yuan from user A's account balance and increase of 100 yuan from user B's account balance. Both of the above operations need to be executed successfully or neither.
- Consistency means that the integrity constraints of the database are not violated before and after a transaction begins. For example, in the transaction of the above transfer, the total balance of the accounts of user A and user B is 2,000 yuan before the transfer starts. Consistency means that when the transfer transaction ends, the total account balance of user A and user B is still 2,000 yuan.
- Isolation means that when multiple transactions are executed concurrently, they will not interfere with each other, that is, the data inside a transaction is isolated from other transactions.
- Persistence means that after a transaction is completed (for example, committed), the operations performed by the transaction on the database are persistently stored in the database and will not be rolled back.
- the transaction can also be called a distributed transaction.
- data located in different database nodes may need to be manipulated.
- the database management system (such as a database client or database agent) can directly send the read-only transaction request to the corresponding database node.
- non-read-only transactions have their particularities. The following briefly introduces the processing process of non-read-only transactions with reference to FIG. 1 .
- FIG. 1 is a schematic flow chart of transaction processing provided by related technologies.
- FIG. 1 includes a database management system 110 and a distributed database 120 .
- the distributed database 120 includes three database nodes (database node 121, database node 122 and database node 123).
- FIG. 1 exemplarily shows a distributed database 120 with three database nodes.
- a distributed database can include any number of database nodes.
- the database management system 110 After the database management system 110 receives the transaction 1, it first needs to establish a database connection (or session) with the database nodes in the distributed database 120 .
- a database connection can also be called a database session.
- all generated information can be recorded in the database connection.
- Transaction 1 may include 3 database statements (a first database statement, a second database statement and a third database statement).
- the database management system 110 analyzes that the execution node of the first database statement is the database node 122 . Therefore, in step S101, the database management system 110 may establish a first database connection with the database node 122, and send the database statement in transaction 1 to the database node 122 through the first database connection. The database management system 110 may send all database statements (eg, the first database statement to the third database statement) in transaction 1 to the database node 122 at the same time. It is also possible to send the next database statement to the database node 122 after each database statement is executed.
- Remote execution refers to the operation that the database statement to be executed cannot be executed on the current database node and needs to be forwarded to other database nodes for execution.
- the operation of the database node 122 forwarding the second database statement to the database node 121 is a remote execution.
- the database node 122 may execute step S104 to send the execution result to the database management system 110 through the first database connection.
- the database management system 110 can determine the execution node of the next database statement according to the execution result of the database statement.
- the database node 122 After receiving the execution result of the second database statement, the database node 122 analyzes that the execution node of the third database statement is the database node 123 . In step S105, the database node 122 sends the third database statement to the database node 123 through remote execution.
- step S107 the database node 122 sends the execution result of the third database statement to the database management system 110 through the first database connection.
- the database node (such as database node 122) that establishes a database connection with the management system 110 needs to receive all database statements, and needs to pass all database statements that are not executed by this node through the remote Execution is sent to the corresponding execution node.
- the pressure on the database node may be too high. Excessive pressure on the database node may cause performance degradation or abnormality of the database node, thereby affecting the stability of the database system. That is, a stressed database node (eg, database node 122) may become a performance bottleneck of the database system due to centralization.
- the embodiment of the present disclosure provides a method for processing transactions, so as to improve the processing efficiency of non-read-only transactions.
- the method in FIG. 2 can be used in a database management system.
- the database management system is used to manage the database.
- the database management system may refer to, for example, a database application program (such as a database client) or a database agent.
- the method in FIG. 2 may include steps S210 to S250.
- a first transaction is received.
- the first transaction may be a non-read-only transaction.
- the so-called non-read-only transaction means that the execution of the transaction will cause some or some data in the database to be modified.
- the first transaction may include multiple database statements.
- a first transaction may include a first database statement and a second database statement. It can be understood that the first transaction may include a greater number of database statements, and the following descriptions will mainly be made by taking the first database statement and the second database statement as examples.
- database statements can be implemented using Structured Query Language (SQL).
- SQL Structured Query Language
- the first transaction refers to buying a leather bag on Taobao Mall.
- the first transaction may include two operations: an operation of increasing the order quantity by one and an operation of decreasing the inventory quantity by one.
- the two operations may respectively correspond to the first database statement and the second database statement.
- the first database statement may be used to perform the operation of adding one to the order quantity
- the second database statement may be used to perform the operation of reducing the inventory quantity by one.
- order data may be stored on a first database node (eg, an order database), and inventory data may be stored on a second database node (eg, an inventory database).
- first database node eg, an order database
- second database node eg, an inventory database
- the first database statement and the second data statement can operate on the first database node and the second database node, respectively.
- the data on the first database node and the second database node are respectively operated.
- the database management system may determine the database nodes for executing the first database statement and the second database statement, and establish database connections with corresponding database nodes respectively.
- a database connection can refer to a physical database connection or a session connection to a database.
- the operation of the database management system on the database needs to be completed through the database connection.
- the first database node can store first data.
- the first database statement can be used to operate on the first data. For example, a first database statement may delete a record in the first data. As another example, the first database statement may query records in the first data. As another example, the first database statement may add a record in the first data.
- the first database node when the first database node determines that the received first database statement needs to be executed on other database nodes, the first database node may forward the first database statement to the corresponding database node.
- the forwarding of database statements within the database nodes can improve the fault tolerance of the database, ensure the correct execution of database statements, and further ensure the correct execution of transactions.
- the first data is originally stored on the first database node, but when the database management system sends the first database statement to the first database node, the first data is just relocated to the second database node.
- the first database node may forward the first database statement to the second database node to ensure the execution of the first database statement.
- the first database statement may be a compound sentence.
- the first database statement needs to be executed in multiple database nodes, and the first database node is one of the multiple database nodes executing the first database statement. After the first database node receives the first database statement, it can forward the first database statement to all nodes that need to execute the first database, so that the first database statement can be executed correctly.
- step S250 From step S240 to step S250, establish a second database connection with the second database node, and send a second database statement to the second database node through the second database connection.
- the interaction between the database management system and the second database node is similar to the interaction between the database management system and the first database node.
- step S220 the part from step S220 to step S230, which will not be described in detail here.
- a distributed database can contain any number of database nodes.
- the first database node and the second database node may refer to any nodes in the distributed database.
- the first database node and the second database node may be two different database nodes, or may be the same database node.
- the transaction processing method provided by the present disclosure can establish connections with multiple database nodes when processing non-read-only transactions. During the execution of the database statements of the transaction, all of them do not need to be sent to the same database node. Therefore, the method reduces the number of remote executions inside the database, and effectively improves the processing efficiency of non-read-only transactions.
- the database statement does not need to be forwarded through a specific database node (for example, the database node that establishes a connection with the database management system)
- a specific database node for example, the database node that establishes a connection with the database management system
- the transaction processing method provided by the embodiment of the present disclosure may further include step S310 and step S320.
- the feedback information may include control information of the first transaction.
- the control information of the first transaction is used to control the execution process of the first transaction.
- the control information for the first transaction may include the status of the first transaction.
- the state of a transaction may refer to the current execution state of the transaction, such as an active state, a partially committed state, a failed state, a committed state, or an aborted state.
- the active state refers to the state of a transaction at the time of execution.
- the partially committed state refers to the state after the execution of the last database statement in the transaction is completed.
- the failure state refers to the state in which the transaction cannot be executed normally.
- the commit status refers to the state after the transaction is partially committed and the last piece of information is written into the database. Once the commit status is complete, a transaction completes successfully.
- the aborted state means that the transaction has been rolled back and the database has been restored to the state it was in before the transaction started.
- the status information of the transaction may also refer to the status information generated during the execution of the database statement in the transaction.
- a database statement may generate a lot of status information during execution.
- Status information may include time zone information, encoding information, and the like.
- State information can also include variables defined during execution of the database statement.
- the status information generated by the execution of a database statement may affect the execution of the next database statement.
- the generated state information includes time zone information.
- the time zone information is used to determine the specific time zone used during the execution of the first transaction (for example, China standard time (China standard time, CST) is used as the execution time zone).
- the time zone (such as CST) determined after the execution of the previous database statement is required as the execution time zone to complete the corresponding operation of the database statement.
- the generated status information includes encoding information, and the encoding information determines that the first transaction uses UTF-8 encoding. All subsequent database statements of the first transaction (for example, the second database statement) need to use UTF-8 encoding.
- the control information of the first transaction may also include the execution result of the first database statement.
- the database management system may determine the current state of the first transaction according to the execution result of the first database statement, and determine the next operation to be performed according to the current state of the first transaction.
- the first transaction needs to enter the suspension state. After the first transaction enters the suspended state, operations related to the suspension can be performed, such as rollback.
- the database management system can normally analyze the next database statement to be executed (for example, the second database statement), determine the database node for executing the database statement, and directly send the statement to the database node.
- the control information of the first transaction may also include connection information of the first transaction.
- the connection information of the first transaction may refer to information of all established connections during the execution of the first transaction.
- a first database connection is established with the first database node, and a second database connection is established with the second database node.
- the above-mentioned information about the first database connection and the second database connection may be recorded in the connection information.
- Recording the connection information of the transaction can help the transaction quickly locate all the database nodes that need to be executed when the state changes.
- the connection information of the first transaction records all connection information established during the execution of the first transaction.
- the database management system can quickly locate all database nodes that have executed the first transaction, so that all database nodes that have executed the first transaction can perform the same operation (for example, submit or rollback), so as to Guarantee the atomicity of the first transaction.
- the database management system may receive the control information of the first transaction returned by the first database, and forward the control information to the database node corresponding to the second database statement, so that the database node corresponding to the second database statement
- the control information of the first transaction can be obtained, which avoids the need for the database node corresponding to the second database statement to obtain the control information of the first transaction through remote execution in the traditional solution, which is beneficial to reduce the overhead occupied by remote execution in the database.
- control information for the first transaction may be stored in a first database node local or temporary table.
- the control information of the first transaction can be obtained from the first database node through remote access.
- control information of the first transaction When the data volume of the control information of the first transaction is very large (for example, the control information of the first transaction has 1G), saving the control information of the first transaction in a database node or a temporary table can effectively save the cost of transmitting the first transaction Control the time required for information to further improve the efficiency of transaction processing.
- the first database node and the first database statement in this embodiment are only for convenience of description.
- the first database node may be any node in the database.
- the first database statement may refer to any database statement in the first transaction.
- the database management system disconnects the connection with the database node after completing the interaction with the database node, which can improve the utilization rate of database connection resources.
- Fig. 4 is a schematic diagram of a method for processing transactions provided by an embodiment of the present disclosure. The method for processing transactions provided by the present disclosure will be described in a specific embodiment below with reference to FIG. 4 .
- FIG. 4 includes a database management system 410 and a distributed database 420 .
- the distributed database 420 includes n database nodes (database node 421 to database node 42n).
- the database management system 410 may receive a first transaction, and the first transaction may be used to process data stored in the distributed database 420 .
- the first transaction may include n database statements, for example, the first through nth database statements.
- Database statements can use SQL language.
- the first database statement to the nth database statement are referred to as sql1 to sqln.
- each database statement can be selected according to actual needs. For example, sql1 to sqln can all be executed on the same database node (such as database node 421). As another example, sql1 to sqln can be executed on different database nodes respectively. For another example, sql1 and sql3 are executed on the same database node, and the remaining database statements are executed on different database nodes.
- the database management system 410 After receiving the first transaction, the database management system 410 analyzes the database nodes on which the database statements in the first transaction should be executed. For example, the database management system 410 analyzes that sql1 should be executed on the database node 422 .
- step S401 the database management system 410 establishes a first database connection with the database node 422 and sends sql1 to the database node 422 .
- the database management system 410 when the database management system 410 sends sql1 to the database node 422, it may simultaneously send the control information of the first transaction to the database node 422.
- control information of the first transaction may be stored in a certain database node (such as database node 421) or a temporary table.
- database node 422 needs the control information of the first transaction, it can obtain it remotely.
- the database node 422 may send first feedback information to the database management system 410 after executing sql1.
- the first feedback information may include control information of the first transaction.
- the control information of the first transaction may include the execution result of sql1 and the status of the first transaction.
- the control information of the first transaction in the first feedback information may be incremental or full control information based on the control information of the first transaction obtained before the database node 422 executes sql1.
- step S403 after receiving the first feedback information from the database node 422, the database management system 410 may disconnect the first database connection, so as to improve the utilization efficiency of the database connection.
- the database management system 410 determines that the database node corresponding to sql2 is the database node 421 according to the first feedback information.
- step S404 the database management system 410 establishes a second database connection with the database node 421 , and sends sql2 to the database node 421 .
- step S405 the database node 421 sends second feedback information to the database management system 410 .
- the database node 421 After the database node 421 executes sql2, it may judge the data volume of the state data volume of the first transaction generated locally. When it is judged that the amount of status data of the first transaction is large (for example, greater than a certain threshold), the status of the first transaction may not be sent in the second feedback information, but only the execution result of sql2 is sent. At this time, the database node 421 saves the state of the first transaction locally.
- step S406 after receiving the second feedback information, the database management system 410 disconnects the second database connection.
- Fig. 5 is a schematic structural diagram of an apparatus for processing transactions provided by an embodiment of the present disclosure.
- the apparatus for processing transactions shown in FIG. 5 may include a receiving unit 510 , a first connecting unit 520 , a first sending unit 530 , a second connecting unit 540 and a second sending unit 550 .
- the receiving unit 510 may be configured to receive a first transaction, the first transaction is a non-read-only transaction, the first transaction includes a first database statement and a second database statement, the first database statement and the second The database statements are respectively used to operate the first database node and the second database node in the distributed database;
- the first connection unit 520 can be configured to establish a first database connection with the first database node;
- the first sending unit 530 may be configured to send the first database statement to the first database node through the first database connection;
- the second connection unit 540 may be configured to establish a second database connection with the second database node;
- the second The sending unit 550 may be configured to send the second database statement to the second database node through the second database connection.
- the receiving unit 510 is further configured to: receive feedback information from the first database for the first database statement, the feedback information includes control information of the first transaction; the second sending Unit 550: further configured to send the control information to the database node corresponding to the second database statement.
- control information of the first transaction includes an execution result of the first database statement and/or a status of the first transaction.
- the first connection unit is further configured to: disconnect the first database connection.
- the database statement in the first transaction is an SQL statement.
- Fig. 6 is a schematic structural diagram of an apparatus for processing transactions provided by yet another embodiment of the present disclosure.
- the transaction processing apparatus 600 may be a user terminal or a database proxy server.
- the apparatus 600 may include a memory 610 and a processor 620 .
- Memory 610 may be used to store executable code.
- the processor 620 can be used to execute the executable code stored in the memory 610, so as to realize the steps in the various methods described above.
- the apparatus 600 may further include a network interface 630 through which data exchange between the processor 620 and external devices may be implemented.
- sequence numbers of the above-mentioned processes do not mean the order of execution, and the execution order of the processes should be determined by their functions and internal logic, rather than by the embodiments of the present disclosure.
- the implementation process constitutes any limitation.
- all or part may be implemented by software, hardware, firmware or other arbitrary combinations.
- software When implemented using software, it may be implemented in whole or in part in the form of a computer program product.
- the computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present disclosure will be generated in whole or in part.
- the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices.
- the computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website, computer, server or data center Transmission to another website site, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.).
- the computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or a data center integrated with one or more available media.
- the available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital video disc (digital video disc, DVD)), or a semiconductor medium (such as a solid state disk (solid state disk, SSD)), etc. .
- a magnetic medium such as a floppy disk, a hard disk, a magnetic tape
- an optical medium such as a digital video disc (digital video disc, DVD)
- a semiconductor medium such as a solid state disk (solid state disk, SSD)
- the disclosed systems and devices may be implemented in other ways.
- the device embodiments described above are only illustrative.
- the division of the units is only a logical function division. In actual implementation, there may be other division methods.
- multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented.
- the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
- the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
- each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Software Systems (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Computational Linguistics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
一种处理事务的方法和装置,方法包括:接收第一事务,第一事务为非只读事务,第一事务包括第一数据库语句和第二数据库语句,第一数据库语句和第二数据库语句分别用于对分布式数据库中的第一数据库节点和第二数据库节点进行操作;与第一数据库节点建立第一数据库连接;通过第一数据库连接向第一数据库节点发送第一数据库语句;与第二数据库节点建立第二数据库连接;通过第二数据库连接向第二数据库节点发送第二数据库语句;接收第一数据库节点针对第一数据库语句的反馈信息,反馈信息包括第一事务的控制信息;向第二数据库语句对应的数据库节点发送控制信息。
Description
本公开涉及分布式数据库领域,并且更为具体地,涉及一种处理事务的方法和装置。
分布式数据包括多个数据库节点。在处理涉及多个数据库节点的非只读事务时,现有技术会先与其中一个数据库节点建立数据库连接,然后由该数据库节点在数据库内部将该事务转发至其他数据库节点,从而在其他数据库节点进行远程事务执行。过多的远程事务执行会降低非只读事务的处理效率。
发明内容
本公开提供一种事务处理方法和装置,以提高分布式数据库中的非只读事务的处理效率。
第一方面,提供一种处理事务的方法,包括:接收第一事务,所述第一事务为非只读事务,所述第一事务包括第一数据库语句和第二数据库语句,所述第一数据库语句和所述第二数据库语句分别用于对分布式数据库中的第一数据库节点和第二数据库节点进行操作;与所述第一数据库节点建立第一数据库连接;通过所述第一数据库连接向所述第一数据库节点发送所述第一数据库语句;与所述第二数据库节点建立第二数据库连接;通过所述第二数据库连接向所述第二数据库节点发送所述第二数据库语句。
可选地,所述方法还包括:接收所述第一数据库针对所述第一数据库语句的反馈信息,所述反馈信息包括所述第一事务的控制信息;向所述第二数据库语句对应的数据库节点发送所述控制信息。
可选地,所述第一事务的控制信息包括所述第一数据库语句的执行结果和/或所述第一事务的状态。
可选地,在所述与所述第二数据库节点建立第二数据库连接之前,所述方法还包括:断开所述第一数据库连接。
可选地,所述第一事务中的数据库语句为SQL语句。
第二方面,提供一种处理事务的装置,包括:接收单元,被配置为接收第一事务, 所述第一事务为非只读事务,所述第一事务包括第一数据库语句和第二数据库语句,所述第一数据库语句和所述第二数据库语句分别用于对分布式数据库中的第一数据库节点和第二数据库节点进行操作;第一连接单元,被配置为与所述第一数据库节点建立第一数据库连接;第一发送单元,被配置为通过所述第一数据库连接向所述第一数据库节点发送所述第一数据库语句;第二连接单元,被配置为与所述第二数据库节点建立第二数据库连接;第二发送单元,被配置为通过所述第二数据库连接向所述第二数据库节点发送所述第二数据库语句。
可选地,所述接收单元还被配置为:接收所述第一数据库针对所述第一数据库语句的反馈信息,所述反馈信息包括所述第一事务的控制信息;所述第二发送单元还被配置为:向所述第二数据库语句对应的数据库节点发送所述控制信息。
可选地,所述第一事务的控制信息包括所述第一数据库语句的执行结果和/或所述第一事务的状态。
可选地,在所述与所述第二数据库节点建立第二数据库连接之前,所述第一连接单元还被配置为:断开所述第一数据库连接。
可选地,所述第一事务中的数据库语句为SQL语句。
第三方面,提供一种处理事务的装置,包括存储器和处理器,所述存储器中存储有可执行代码,所述处理器被配置为执行所述可执行代码,以实现如第一方面所述的方法。
第四方面,提供一种计算机可读存储介质,其上存储有可执行代码,当所述可执行代码被执行时,能够实现如第一方面所述的方法。
第五方面,提供一种计算机程序产品,包括可执行代码,当所述可执行代码被执行时,能够实现如第一方面所述的方法。
相关技术中,如果非只读事务涉及多个数据库节点,往往只会与其中一个数据库节点建立连接。不同于相关技术,本公开实施例在处理非只读事务时,可以与多个数据库节点建立多个数据库连接,并通过该多个数据库连接将事务相关的数据库语句直接传输至该多个数据库节点。这样可以避免仅建立一个数据库连接而引起大量的远程事务执行,从而提高了非只读事务的处理效率。
另外,在本公开中可以接收第一数据库返回的第一事务的控制信息,并将该控制信息转发至第二数据库语句对应的数据库节点,以便第二数据库语句对应的数据库节点可以获知第一事务的控制信息,避免了传统的方案中,第二数据库语句对应的数据库节点 需要通过远程执行的方式来获得第一事务的控制信息,有利于降低数据库中远程执行占用的开销。
图1是相关技术提供的处理事务的流程示意图。
图2是本公开一实施例提供的处理事务的方法的流程示意图。
图3是本公开又一实施例提供的处理事务的方法的流程示意图。
图4是本公开又一实施例提供的处理事务的方法的流程示意图。
图5是本公开一实施例提供的处理事务的装置的结构示意图。
图6是本公开又一实施例提供的处理事务的装置的结构示意图。
下面将结合附图,对本公开中的技术方案进行描述。为了便于理解本公开,下文先介绍本公开实施例涉及的术语。
分布式数据库
数据库是按照数据结构来组织、存储和管理数据的仓库。数据库是一个长期存储在计算机内的、有组织的、可共享的、统一管理的大量数据的集合。分布式数据库是一种结合了数据库与分布式的技术。分布式数据库将地理意义上分散,但计算机***逻辑上属于同一个***的各个数据库节点结合起来。
结构化查询语言
结构化查询语言(structured query language,SQL)是一种特殊的的编程语言。结构化查询语言用于存取数据以及查询、更新和管理数据库***。
结构化查询语言是高级的非过程化编程语言,允许用户在高层数据结构上工作。它不要求用户指定对数据的存放方法,也不需要用户了解具体的数据存放方式。因此,具有完全不同底层结构的不同数据库***,可以使用相同的结构化查询语言作为数据输入与管理的接口。结构化查询语言的语句可以嵌套,这使它具有极大的灵活性和强大的功能。
事务
事务(transaction)是针对数据库的一组操作。一个事务可以由一条或多条数据库语句组成。事务是数据库中一个不可分割的执行单元。和事务相关的语句包括开启事务(start transaction)、结束事务(end transaction)、提交事务(commit transaction)、回滚事务(rollback transaction)等。
事务需要具备ACID,即原子性(Atomicity)、一致性(consistency)、隔离性(isolation)和持久性(durability)。
原子性指一个事务中的语句需要一起提交或回滚。例如,一个用户A向用户B转账100元的事务,包括用户A的账户余额扣除100元和用户B的账户余额增加100元两个操作。上述两个操作需要都成功执行或者都不执行。
一致性指一个事务开始之前和结束之后,数据库的完整性约束没有被破坏。例如,上述转账的事务,在转账开始前用户A和用户B的账户总余额为2000元。一致性指,当该转账事务结束后,用户A和用户B的账户总余额仍然为2000元。
隔离性指多个事务并发执行的时候不会互相干扰,即一个事务内部的数据对于其他事务来说是隔离的。
持久性指一个事务完成(例如提交)后,该事务对数据库所做的操作持久地保存在数据库中,不会被回滚。
当事务需要在分布式数据库***中完成时,该事务也可以称为分布式事务。分布式事务在处理过程中,可能需要操作位于不同数据库节点中的数据。
对于只读事务,由于事务执行过程中无需修改数据库的状态,因此,数据库的管理***(例如数据库客户端或数据库代理)可以把只读事务的请求直接发送给对应的数据库节点。
然而,非只读事务在执行过程中,存在对数据库的数据或状态等的修改。因此,非只读事务有其特殊性。下面结合图1对非只读事务的处理过程进行简单的介绍。
图1是相关技术提供的处理事务的流程示意图。图1包括数据库管理***110和分布式数据库120。分布式数据库120中包括3个数据库节点(数据库节点121、数据库节点122和数据库节点123)。图1示例性地示出具有三个数据库节点的分布式数据库120。实际中一个分布式数据库可以包括任意数量的数据库节点。
如图1所示,数据库管理***110接收到事务1后,需要首先与分布式数据库120 中的数据库节点建立数据库连接(或称session)。数据库连接也可以称为数据库会话。事务执行过程中,所有生成的信息都可以记录在数据库连接中。
事务1可以包括3条数据库语句(第一数据库语句、第二数据库语句和第三数据库语句)。
数据库管理***110分析第一数据库语句的执行节点为数据库节点122。因此,在步骤S101,数据库管理***110可以与数据库节点122建立第一数据库连接,并将事务1中的数据库语句经过第一数据库连接发送给数据库节点122。数据库管理***110可以将事务1中的所有数据库语句(例如,第一数据库语句至第三数据库语句)同时发送给数据库节点122。也可以每执行完一条数据库语句后,再将下一条数据库语句发送给数据库节点122。
数据库节点122执行完第一数据库语句后,确定第二数据库语句应该在数据库节点121上执行。因此,在步骤S102,数据库节点122通过远程执行将第二数据库语句发送到数据库节点121上。数据库节点121执行完第二数据库语句后,还可以执行步骤S103,将第二数据库语句的执行结果,通过远程执行发送到数据库节点122上。
远程执行指待执行的数据库语句不能在当前数据库节点执行,需要转发到其他数据库节点执行的操作。例如,数据库节点122向数据库节点121转发第二数据库语句的操作,即为一次远程执行。
数据库节点122接收到第二数据库语句的执行结果后,可以执行步骤S104,通过第一数据库连接将该执行结果发送给数据库管理***110。数据库管理***110可以根据数据库语句的执行结果,决定下一条数据库语句的执行节点。
数据库节点122接收到第二数据库语句的执行结果后,分析第三数据库语句的执行节点为数据库节点123。在步骤S105,数据库节点122通过远程执行,将第三数据库语句发送给数据库节点123。
在步骤S106,数据库节点123通过远程执行,将第三数据库语句的执行结果发送给数据库节点122。
在步骤S107,数据库节点122将第三数据库语句的执行结果通过第一数据库连接发送给数据库管理***110。
根据上述介绍可以看出,数据库管理***110在管理非只读事务时,一个事务中的所有数据库语句,都需要经由与数据库管理***110建立连接的数据库节点(例如,数 据库节点122)发送给对应的执行节点(执行节点包括数据库节点122自身)。
当一个非只读事务中包含大量的数据库语句时,与管理***110建立数据库连接的数据库节点(例如数据库节点122)需要接收所有的数据库语句,并且需要将所有非本节点执行的数据库语句通过远程执行发送给对应的执行节点。
因此,可能导致该数据库节点(例如数据库节点122)的压力过大。数据库节点承受的压力过大,可能引起数据库节点性能下降或异常,从而影响数据库***的稳定性。即,承受压力的数据库节点(例如数据库节点122)可能由于中心化现象而成为数据库***的性能瓶颈。
此外,分布式事务通常涉及多个数据库节点,所有需要在数据库节点122之外的节点上执行的数据库语句,都需要经过数据库节点122转发,导致远程执行。远程执行会加大数据库的开销,增加事务执行耗时,降低数据库性能。
综上所述,分布式数据库处理非只读事务时,处理效率较低。
有鉴于此,本公开实施例提供一种处理事务的方法,以提高对非只读事务的处理效率。
下面结合附图2,对本公开实施例提供的处理事务的方法进行详细描述。
图2的方法可以用于数据库的管理***。数据库的管理***用于管理数据库。数据库的管理***例如可以指数据库的应用程序(例如数据库客户端)或数据库代理。图2的方法可以包括步骤S210至步骤S250。
在步骤S210,接收第一事务。第一事务可以是非只读事务。所谓非只读事务,指的是该事务的执行会导致数据库中的某个或某些数据被修改。第一事务可以包括多个数据库语句。例如,第一事务可以包括第一数据库语句和第二数据库语句。可以理解,第一事务可以包括更多数量的数据库语句,后文主要以第一数据库语句和第二数据库语句为例进行举例说明。
数据库语句是用于对数据库进行操作的一种程序语言,一般具有存取数据以及查询、更新和管理数据库的功能。每条数据库语句可以是简单语句,也可以是复合语句。
数据库语句使用的具体语言类型可以根据业务需要确定。例如,数据库语句可以使用结构化查询语言(SQL)实现。
分布式数据库中,不同的数据可能存储在不同的数据库节点上。例如,第一事务指 在淘宝商城上购买一个皮包。第一事务可以包括两个操作:订单数量加一的操作和库存数量减一的操作。两个操作可以分别对应第一数据库语句和第二数据库语句。第一数据库语句可以用于执行订单数量加一的操作,第二数据库语句可以用于执行库存数量减一的操作。
对于淘宝商城,订单数据可能存储在第一数据库节点(例如,订单数据库)上,库存数据可能存储在第二数据库节点(例如,库存数据库)上。
第一数据库语句和第二数据语句可以分别对第一数据库节点和第二数据库节点进行操作。例如,分别操作第一数据库节点和第二数据库节点上的数据。
数据库管理***接收到第一事务后,可以确定用于执行第一数据库语句和第二数据库语句的数据库节点,并分别与对应的数据库节点建立数据库连接。
数据库连接可以指物理数据库连接,也可以指数据库的会话连接。数据库管理***对数据库的操作,都需要通过数据库连接完成。
数据库管理***确定第一数据库语句应该在第一数据库节点上执行。因此,在步骤S220和步骤S230,与第一数据库节点建立第一数据库连接,并通过第一数据库连接向第一数据库节点发送第一数据库语句。
第一数据库节点可以存储第一数据。第一数据库语句可以用于对第一数据进行操作。例如,第一数据库语句可以删除第一数据中的记录。又如,第一数据库语句可以查询第一数据中的记录。又如,第一数据库语句可以在第一数据中增加记录。
在一些实施例中,当第一数据库节点确定接收到的第一数据库语句需要在其他数据库节点执行时,第一数据库节点可以将第一数据库语句转发给对应的数据库节点。
由于分布式数据库的数据可能产生搬迁,数据库节点内部进行数据库语句的转发,可以提升数据库的容错能力,保证数据库语句正确执行,进一步保证事务的正确执行。
例如,第一数据原本存储在第一数据库节点上,但是,数据库管理***向第一数据库节点发送第一数据库语句时,第一数据正好被搬迁到第二数据库节点中。此时,第一数据库节点可以将第一数据库语句转发给第二数据库节点,保证第一数据库语句的执行。
在另一些实施例中,第一数据库语句可以是复合句。第一数据库语句需要在多个数据库节点中执行,第一数据库节点是多个执行第一数据库语句的数据库节点中的一个。第一数据库节点在接收到第一数据库语句后,可以将第一数据库语句转发给所有需要执 行第一数据库的节点,使第一数据库语句可以正确执行。
在步骤S240至步骤S250,与第二数据库节点建立第二数据库连接,并通过第二数据库连接向第二数据库节点发送第二数据库语句。
数据库管理***与第二数据库节点的交互,与数据库管理***与第一数据库节点的交互相似,具体描述参见步骤S220指步骤S230部分,此处不再详述。
应理解,本实施例中使用第一数据库节点和第二数据库节点,仅为了使方案更加清楚。分布式数据库中可以包含任意数量的数据库节点。第一数据库节点和第二数据库节点可以指分布式数据库中的任意节点。第一数据库节点和第二数据库节点可以是两个不同的数据库节点,也可以是同一个数据库节点。
本公开提供的处理事务的方法,在处理非只读事务时,可以与多个数据库节点建立连接。事务的数据库语句在执行过程中,无需全部发送给同一个数据库节点。因此,该方法减少了数据库内部远程执行的次数,有效地提升了对非只读事务的处理效率。
此外,由于数据库语句无需经过某一个特定的数据库节点(例如,与数据库管理***建立连接的数据库节点)转发,因此,缓解了由于某个数据库节点压力过大,使整个数据库产生性能瓶颈的问题。
在一些实施例中,在步骤S240之前,如图3所示,本公开实施例提供的处理事务的方法还可以包括步骤S310和步骤S320。
在步骤S310和步骤S320,接收第一数据库针对第一数据库语句的反馈信息,反馈信息包括所述第一事务的控制信息。向第二数据库语句对应的数据库节点发送控制信息。
反馈信息可以包括第一事务的控制信息。第一事务的控制信息用于控制第一事务的执行过程。第一事务的控制信息可以包括第一事务的状态。
事务的状态可以指事务当前的执行状态,例如活动状态、部分提交状态、失败状态、提交状态或中止状态。
活动状态指事务在执行时的状态。部分提交状态指事务中最后一条数据库语句执行完成后的状态。失败状态指事务不能正常执行的状态。提交状态指事务在部分提交后,最后一条信息写入到数据库中后的状态。提交状态完成后,一个事务即成功完成。中止状态指事务回滚,并且数据库已经恢复到事务开始执行前的状态。
事务的状态信息还可以指事务中的数据库语句在执行过程中产生的状态信息。数据 库语句在执行过程中可能产生很多的状态信息。状态信息可以包括时区信息、编码信息等。状态信息还可以包括数据库语句在执行过程中定义的变量。
一条数据库语句执行产生的状态信息可能会影响下一条数据库语句的执行。例如,第一数据库语句执行后,生成的状态信息包括时区信息。该时区信息用于确定第一事务执行过程中使用的具体时区(例如使用中国标准时间(china standard time,CST)作为执行时区)。第一事务中后续的数据库语句,在执行的过程中,都需要根据前面的数据库语句执行后确定的时区(例如CST)作为执行时区,完成数据库语句的对应操作。
又如,第一数据库语句执行完成后,产生的状态信息包括编码信息,该编码信息确定第一事务使用UTF-8编码。第一事务后续的数据库语句(例如第二数据库语句)都需要使用UTF-8编码。
第一事务的控制信息还可以包括第一数据库语句的执行结果。数据库管理***可以根据第一数据库语句的执行结果确定第一事务的当前状态,并根据第一事务的当前状态确定下一步应执行的操作。
例如,当第一数据库语句执行失败后,第一事务需要进入中止状态。第一事务进入中止状态后,可以执行中止相关的操作,例如回滚。
又如,当第一数据库语句执行成功后,第一事务继续正常执行。数据库管理***可以正常分析下一条待执行的数据库语句(例如第二数据库语句),确定执行该数据库语句的数据库节点,并将该语句直接发送给该数据库节点。
第一事务的控制信息还可以包括第一事务的连接信息。第一事务的连接信息可以指第一事务执行过程中,所有建立过的连接的信息。
例如,第一事务执行过程中,分别与第一数据库节点建立了第一数据库连接,与第二数据库节点建立了第二数据库连接。此时,连接信息中可以记录上述第一数据库连接和第二数据库连接的信息。
记录事务的连接信息,可以帮助事务在进行状态更改时,快速定位到需要执行的所有数据库节点。
例如,当第一事务需要回滚或提交时,第一事务的连接信息中记录了第一事务执行过程中建立的所有连接信息。数据库管理***根据第一事务的连接信息,可以快速定位到所有执行过第一事务的数据库节点,使所有执行过第一事务的数据库节点可以执行相同的操作(例如,提交或回滚),以保证第一事务的原子性。
在本公开实施例中,数据库的管理***可以接收第一数据库返回的第一事务的控制 信息,并将该控制信息转发至第二数据库语句对应的数据库节点,以便第二数据库语句对应的数据库节点可以获知第一事务的控制信息,避免了传统的方案中,第二数据库语句对应的数据库节点需要通过远程执行的方式来获得第一事务的控制信息,有利于降低数据库中远程执行占用的开销。
在一些实施例中,可以将第一事务的控制信息存储在第一数据库节点本地或临时表中。当数据库管理***或其他数据库节点需要第一事务的控制信息时,可以通过远程访问的方式从第一数据库节点中获取第一事务的控制信息。
当第一事务的控制信息的数据量非常大(例如,第一事务的控制信息有1G)时,将第一事务的控制信息保存在数据库节点或临时表中,可以有效节约传输第一事务的控制信息所需的时间,从而进一步提升处理事务的效率。
本实施例中的第一数据库节点和第一数据库语句仅为了描述方便。第一数据库节点可以是数据库中任意一个节点。第一数据库语句可以指第一事务中的任意一条数据库语句。
在一些实施例中,在与第二数据库节点建立第二数据库连接之前,可以先断开第一数据库连接。
在数据库中,由于数据库管理***与数据库进行交互,都需要经过数据库连接完成。因此,数据库连接是非常重要的资源。
本公开实施例在第一事务执行的过程中,数据库管理***与据库节点完成交互后,即断开与该数据库节点的连接,可以提高数据库连接资源的利用率。
图4是本公开一实施例提供的处理事务的方法示意图。下面结合图4,以一个具体的实施例介绍本公开提供的处理事务的方法。
图4包括数据库管理***410和分布式数据库420。分布式数据库420包括n个数据库节点(数据库节点421至数据库节点42n)。
在本实施例中,数据库管理***410可以接收第一事务,第一事务可以用于处理分布式数据库420中存储的数据。
第一事务可以包括n个数据库语句,例如,第一数据库语句至第n数据库语句。数据库语句可以使用SQL语言。为了便于描述,本实施例中,将第一数据库语句至第n数据库语句称为sql1至sqln。
每条数据库语句的具体执行节点可以根据实际需要选择。例如,sql1至sqln都可以在同一个数据库节点(例如数据库节点421)上执行。又如,sql1至sqln可以分别在不同的数据库节点上执行。又如,sql1和sql3在同一个数据库节点上执行,剩下的数据库 语句在不同的数据库节点上执行。
数据库管理***410接收到第一事务后,分析第一事务中的数据库语句应该执行的数据库节点。例如,数据库管理***410分析到sql1应该在数据库节点422上执行。
在步骤S401,数据库管理***410与数据库节点422建立第一数据库连接,并将sql1发送给数据库节点422。
在一些实施例中,数据库节点422在执行sql1时,可能需要第一事务的控制信息。数据库节点422可以通过多种方式获取当前第一事务的控制信息。
例如,数据库管理***410在向数据库节点422发送sql1时,可以同时将第一事务的控制信息发送给数据库节点422。
又如,第一事务的控制信息可以存储在某个数据库节点(例如数据库节点421)或临时表中。数据库节点422需要第一事务的控制信息时,可以远程获取。
在步骤S402,数据库节点422执行完sql1后,可以向数据库管理***410发送第一反馈信息。第一反馈信息可以包括第一事务的控制信息。第一事务的控制信息可以包括sql1的执行结果和第一事务的状态。
第一反馈信息中第一事务的控制信息,可以是在数据库节点422执行sql1前获取的第一事务的控制信息的基础上的增量或全量控制信息。
在步骤S403,数据库管理***410收到数据库节点422的第一反馈信息后,可以断开第一数据库连接,以提高数据库连接的利用效率。
数据库管理***410根据第一反馈信息,判断sql2对应的数据库节点为数据库节点421。
在步骤S404,数据库管理***410与数据库节点421建立第二数据库连接,并将sql2发送给数据库节点421。
在步骤S405,数据库节点421向数据库管理***410发送第二反馈信息。
数据库节点421执行sql2后,可以对本地生成的第一事务的状态数据量的数据量进行判断。当判断出第一事务的状态数据的数据量较大(例如大于某一阈值)时,第二反馈信息中可以不再发送第一事务的状态,而仅发送sql2的执行结果。此时,数据库节点421将第一事务的状态保存在本地。
在步骤S406,数据库管理***410收到第二反馈信息后,断开第二数据库连接。
第一事务的其余数据库语句的执行过程与前述步骤相似,不再赘述。
前面结合图1至图4介绍了本公开的方法实施例。下面结合图5至图6介绍本公开的装置实施例。应理解,方法实施例的描述与装置实施例的描述相互对应。因此,装置 实施例中未详述的部分,可以参见前文中方法实施例中的介绍。
图5是本公开一实施例提供的处理事务的装置的示意性结构图。图5所示的处理事务的装置可以包括接收单元510、第一连接单元520、第一发送单元530、第二连接单元540和第二发送单元550。
接收单元510可以被配置为接收第一事务,所述第一事务为非只读事务,所述第一事务包括第一数据库语句和第二数据库语句,所述第一数据库语句和所述第二数据库语句分别用于对分布式数据库中的第一数据库节点和第二数据库节点进行操作;第一连接单元520可以被配置为与所述第一数据库节点建立第一数据库连接;第一发送单元530可以被配置为通过所述第一数据库连接向所述第一数据库节点发送所述第一数据库语句;第二连接单元540可以被配置为与所述第二数据库节点建立第二数据库连接;第二发送单元550可以被配置为通过所述第二数据库连接向所述第二数据库节点发送所述第二数据库语句。
可选地,所述接收单元510还被配置为:接收所述第一数据库针对所述第一数据库语句的反馈信息,所述反馈信息包括所述第一事务的控制信息;所述第二发送单元550:还被配置为向所述第二数据库语句对应的数据库节点发送所述控制信息。
可选地,所述第一事务的控制信息包括所述第一数据库语句的执行结果和/或所述第一事务的状态。
可选地,在所述与所述第二数据库节点建立第二数据库连接之前,所述第一连接单元还被配置为:断开所述第一数据库连接。
可选地,所述第一事务中的数据库语句为SQL语句。
图6是本公开又一实施例提供的处理事务的装置的结构示意图。该处理事务的装置600可以是用户终端或数据库代理服务器。装置600可以包括存储器610和处理器620。存储器610可用于存储可执行代码。处理器620可用于执行所述存储器610中存储的可执行代码,以实现前文描述的各个方法中的步骤。在一些实施例中,该装置600还可以包括网络接口630,处理器620与外部设备的数据交换可以通过该网络接口630实现。
应理解,在本公开的各种实施例中,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本公开实施例的实施过程构成任何限定。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其他任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时, 全部或部分地产生按照本公开实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带)、光介质(例如数字视频光盘(digital video disc,DVD))、或者半导体介质(例如固态硬盘(solid state disk,SSD))等。
在本公开所提供的几个实施例中,应该理解到,所揭露的***和装置,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个***,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
以上所述,仅为本公开的具体实施方式,但本公开的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应以所述权利要求的保护范围为准。
Claims (9)
- 一种处理事务的方法,包括:接收第一事务,所述第一事务为非只读事务,所述第一事务包括第一数据库语句和第二数据库语句,所述第一数据库语句和所述第二数据库语句分别用于对分布式数据库中的第一数据库节点和第二数据库节点进行操作;与所述第一数据库节点建立第一数据库连接;通过所述第一数据库连接向所述第一数据库节点发送所述第一数据库语句;与所述第二数据库节点建立第二数据库连接;通过所述第二数据库连接向所述第二数据库节点发送所述第二数据库语句;接收所述第一数据库针对所述第一数据库语句的反馈信息,所述反馈信息包括所述第一事务的控制信息;向所述第二数据库语句对应的数据库节点发送所述控制信息。
- 根据权利要求1所述的方法,所述第一事务的控制信息包括所述第一数据库语句的执行结果和/或所述第一事务的状态。
- 根据权利要求1所述的方法,在所述与所述第二数据库节点建立第二数据库连接之前,所述方法还包括:断开所述第一数据库连接。
- 根据权利要求1所述的方法,所述第一事务中的数据库语句为结构化查询语言SQL语句。
- 一种处理事务的装置,包括:接收单元,被配置为接收第一事务,所述第一事务为非只读事务,所述第一事务包括第一数据库语句和第二数据库语句,所述第一数据库语句和所述第二数据库语句分别用于对分布式数据库中的第一数据库节点和第二数据库节点进行操作;第一连接单元,被配置为与所述第一数据库节点建立第一数据库连接;第一发送单元,被配置为通过所述第一数据库连接向所述第一数据库节点发送所述第一数据库语句;第二连接单元,被配置为与所述第二数据库节点建立第二数据库连接;第二发送单元,被配置为通过所述第二数据库连接向所述第二数据库节点发送所述第二数据库语句;所述接收单元,还被配置为接收所述第一数据库针对所述第一数据库语句的反馈信息,所述反馈信息包括所述第一事务的控制信息;所述第二发送单元,还被配置为向所述第二数据库语句对应的数据库节点发送所述控制信息。
- 根据权利要求5所述的装置,所述第一事务的控制信息包括所述第一数据库语句的执行结果和/或所述第一事务的状态。
- 根据权利要求5所述的装置,在所述与所述第二数据库节点建立第二数据库连接之前,所述第一连接单元还被配置为:断开所述第一数据库连接。
- 根据权利要求5所述的装置,所述第一事务中的数据库语句为结构化查询语言SQL语句。
- 一种处理事务的装置,包括存储器和处理器,所述存储器中存储有可执行代码,所述处理器被配置为执行所述可执行代码,以实现权利要求1-4中任一项所述的方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210049251.3A CN114064810B (zh) | 2022-01-17 | 2022-01-17 | 处理事务的方法和装置 |
CN202210049251.3 | 2022-01-17 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023134614A1 true WO2023134614A1 (zh) | 2023-07-20 |
Family
ID=80231165
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2023/071213 WO2023134614A1 (zh) | 2022-01-17 | 2023-01-09 | 事务的处理 |
Country Status (2)
Country | Link |
---|---|
CN (2) | CN114880401A (zh) |
WO (1) | WO2023134614A1 (zh) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114880401A (zh) * | 2022-01-17 | 2022-08-09 | 北京奥星贝斯科技有限公司 | 处理事务的方法和装置 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106325978A (zh) * | 2015-06-19 | 2017-01-11 | 阿里巴巴集团控股有限公司 | 分布式事务的处理方法及装置 |
EP3185143A1 (en) * | 2015-12-21 | 2017-06-28 | Sap Se | Decentralized transaction commit protocol |
CN113220710A (zh) * | 2021-05-11 | 2021-08-06 | 北京百度网讯科技有限公司 | 数据查询方法、装置、电子设备以及存储介质 |
CN114064810A (zh) * | 2022-01-17 | 2022-02-18 | 北京奥星贝斯科技有限公司 | 处理事务的方法和装置 |
Family Cites Families (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103377236B (zh) * | 2012-04-26 | 2018-02-16 | 中兴通讯股份有限公司 | 一种用于分布式数据库的连接查询方法及*** |
US10496640B2 (en) * | 2012-12-19 | 2019-12-03 | Salesforce.Com, Inc. | Querying a not only structured query language (NoSQL) database using structured query language (SQL) commands |
US20140214886A1 (en) * | 2013-01-29 | 2014-07-31 | ParElastic Corporation | Adaptive multi-client saas database |
EA027808B1 (ru) * | 2015-01-22 | 2017-09-29 | Кирилл Андреевич Сурков | Система управления базой данных |
CN104657483B (zh) * | 2015-02-28 | 2018-06-15 | 华为技术有限公司 | 处理事务的方法、处理节点、中心节点和集群 |
CN106547781B (zh) * | 2015-09-21 | 2021-06-11 | 南京中兴新软件有限责任公司 | 一种实现分布式事务的方法、装置及数据库服务器 |
CN106021544B (zh) * | 2016-05-27 | 2020-02-07 | 北京京东尚科信息技术有限公司 | 数据库分布式连接池管理方法和*** |
US11115212B1 (en) * | 2016-11-15 | 2021-09-07 | Teradata Us, Inc. | Multi-processing node connection in a data store system via encrypted password |
CN113420041A (zh) * | 2020-07-27 | 2021-09-21 | 阿里巴巴集团控股有限公司 | 分布式数据库中的数据处理方法、装置、设备及介质 |
-
2022
- 2022-01-17 CN CN202210575633.XA patent/CN114880401A/zh active Pending
- 2022-01-17 CN CN202210049251.3A patent/CN114064810B/zh active Active
-
2023
- 2023-01-09 WO PCT/CN2023/071213 patent/WO2023134614A1/zh unknown
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106325978A (zh) * | 2015-06-19 | 2017-01-11 | 阿里巴巴集团控股有限公司 | 分布式事务的处理方法及装置 |
EP3185143A1 (en) * | 2015-12-21 | 2017-06-28 | Sap Se | Decentralized transaction commit protocol |
CN113220710A (zh) * | 2021-05-11 | 2021-08-06 | 北京百度网讯科技有限公司 | 数据查询方法、装置、电子设备以及存储介质 |
CN114064810A (zh) * | 2022-01-17 | 2022-02-18 | 北京奥星贝斯科技有限公司 | 处理事务的方法和装置 |
CN114880401A (zh) * | 2022-01-17 | 2022-08-09 | 北京奥星贝斯科技有限公司 | 处理事务的方法和装置 |
Also Published As
Publication number | Publication date |
---|---|
CN114064810B (zh) | 2022-05-03 |
CN114064810A (zh) | 2022-02-18 |
CN114880401A (zh) | 2022-08-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP2928160B1 (en) | Idempotence for database transactions | |
US11829349B2 (en) | Direct-connect functionality in a distributed database grid | |
US8484166B2 (en) | Oracle rewind: metadata-driven undo | |
US20180075086A1 (en) | Asynchronous Shared Application Upgrade | |
US7366738B2 (en) | Method and system for object cache synchronization | |
US9009104B2 (en) | Checkpoint-free in log mining for distributed information sharing | |
US7634512B2 (en) | Migrating temporary data of a session | |
US7917651B2 (en) | Apparatus, system, and method for asynchronous complex inbound transactions from SAP applications using service oriented architecture | |
JP2012014502A (ja) | トランザクションを集約して処理する方法、システム、およびプログラム | |
US11210277B2 (en) | Distributing and processing streams over one or more networks for on-the-fly schema evolution | |
CN111522631A (zh) | 分布式事务处理方法、装置、服务器及介质 | |
WO2019109854A1 (zh) | 分布式数据库数据处理方法、装置、存储介质及电子装置 | |
US7636873B2 (en) | Enhancement of assured event delivery mechanism to eliminate external XA store requirement | |
WO2023134614A1 (zh) | 事务的处理 | |
WO2024041022A1 (zh) | 数据库表变更方法、装置、设备和存储介质 | |
US9069632B2 (en) | Message processing | |
CN110427427B (zh) | 一种通过引脚桥接实现全局事务分布式处理方法 | |
CN108090056B (zh) | 数据查询方法、装置及*** | |
CN112182082B (zh) | 一种实现跨不同数据库引擎事务强一致性的***及方法 | |
WO2021109777A1 (zh) | 一种数据文件的导入方法及装置 | |
JP7392131B2 (ja) | 最終的に一貫性のあるデータベース複製への切り替え | |
US8621085B2 (en) | Methods, systems, and computer program products for managing and utilizing connections between an application server and an enterprise information system based on a daytona architecture | |
US7162492B2 (en) | Apparatus and method for managing state of external apparatus | |
US6725213B1 (en) | Method and mechanism for providing external procedures to a database system | |
CN109710629A (zh) | 数据访问方法、装置、服务器和存储介质 |
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: 23739956 Country of ref document: EP Kind code of ref document: A1 |