CN116414844A - Database processing method and related equipment - Google Patents

Database processing method and related equipment Download PDF

Info

Publication number
CN116414844A
CN116414844A CN202111679433.0A CN202111679433A CN116414844A CN 116414844 A CN116414844 A CN 116414844A CN 202111679433 A CN202111679433 A CN 202111679433A CN 116414844 A CN116414844 A CN 116414844A
Authority
CN
China
Prior art keywords
node
transaction
database
information
operations
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111679433.0A
Other languages
Chinese (zh)
Inventor
张子杰
任阳
李思昊
张岩峰
付国
周慰星
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202111679433.0A priority Critical patent/CN116414844A/en
Priority to PCT/CN2022/126150 priority patent/WO2023124431A1/en
Publication of CN116414844A publication Critical patent/CN116414844A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • 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
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

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

Abstract

The embodiment of the application discloses a database processing method, which is applied to a database system, wherein the database system comprises a first node and a second node, the first node and the second node are respectively provided with a first database and a second database which store the same data, and the method comprises the following steps: acquiring a first operation set; transmitting the first set of operations to the second node; receiving a second operation set sent by a second node, wherein the first operation set and the second operation set are used for updating a second database by the second node; the first database is updated based on the first set of operations and the second set of operations. The operation set of the transaction is mutually transmitted among a plurality of nodes in the database system, so that the update of the database on the node considers the transaction submitted by other databases, thereby ensuring the update synchronization among the plurality of databases.

Description

Database processing method and related equipment
Technical Field
The embodiment of the application relates to the technical field of databases, in particular to a database processing method and related equipment.
Background
With the rapid development of the internet, the software system is changed from the original single application to the distributed application. The distributed system can split an application system into a plurality of services which can be deployed independently, so that the transaction operation can be completed by remote collaboration between the services, and the transaction completed by remote collaboration between different services through a network in the environment of the distributed system is called a distributed transaction, for example, a user registration credit-sending transaction, an order-creating inventory-subtracting transaction, a bank transfer transaction and the like are all distributed transactions. In a distributed system, each node is physically independent from each other, and communicates and coordinates through a network. Due to the transaction mechanism, the data operation on each independent node can be guaranteed to meet the ACID. However, if it is desired to maintain consistency of data across multiple machines in a distributed deployment, then it is guaranteed that data write operations at all nodes are not performed all, or all. However, one machine cannot know the execution result of a local transaction in another machine when executing the local transaction. He does not know if the transaction should be commit or roolback at all.
Currently, a conventional solution is to introduce a "coordinator" component to uniformly schedule execution of all distributed nodes, which may also be referred to as a two-phase commit method. The idea of the two-stage commit method can be summarized as: the coordinator sends preparation information (preparation) to each participant. Each participant notifies the coordinator of the success or failure of the operation and waits for the coordinator to reply while entering the state of locking the transaction resource. The coordinator decides whether each participant performs a commit operation (commit) or a rollback operation (rollback) according to feedback information of all the participants, and replies the decision of the coordinator to each participant, and each participant releases transaction resources again in response to the decision, thereby ensuring that databases of all the participants are consistent.
However, on one hand, there are three interactions between the coordinator and each participant, and the communication overhead is large. On the other hand, due to the importance of the coordinator, once the coordinator fails. All participants are also in a state of locking the transaction resource and cannot continue to complete the transaction operation.
Disclosure of Invention
The embodiment of the application provides a database processing method and related equipment. The operation sets of the transactions are mutually sent among a plurality of nodes in the database system, and the updating of the databases on the nodes considers the transactions submitted by other databases, thereby ensuring the updating synchronization among the plurality of databases.
The first aspect of the embodiments of the present application provides a database processing method, where the method is applied to a database system, and the database system includes a first node and a second node, where the first node is deployed with a first database, and the second node is deployed with a second database, where the first database and the second database store the same data, and the method may be executed by the first node, or may be executed by a component (such as a processor, a chip, or a chip system) of the first node. The method comprises the following steps: the method comprises the steps that a first node obtains a first operation set, wherein the first operation set is write operation or read-write operation of a first transaction set in a first database in a target time period; the first node sends a first operation set to the second node; the first node receives a second operation set sent by the second node, wherein the second operation set is write operation or read-write operation of a second transaction set in a second database in a target time period, and the first operation set and the second operation set are used for updating the second database by the second node; the first node updates the first database based on the first set of operations and the second set of operations.
In the embodiment of the application, the operation sets of the transactions are mutually sent among the plurality of nodes in the database system, and the update of the database on the node considers the transactions submitted by other databases, so that the update synchronization among the plurality of databases is ensured. On the one hand, transaction modification is mutually notified among nodes in a mode of transmitting operation sets, multiple interactions among the nodes are not involved, and communication overhead is low. On the other hand, compared with the two-stage commit method, the problem that the transaction cannot be operated due to single-point faults of the coordinator is avoided.
Optionally, in a possible implementation manner of the first aspect, the steps are as follows: the first node obtains a first operation set, including: the first node responds to and executes an operation instruction of a first user on a first database; and the first node records the operation of the first user on the data items in the first database in the process of executing the operation instruction, so as to obtain a first operation set.
In this possible implementation manner, during the process of executing the operation instruction of the user on the database, the node records the operation of the first user on the data item in the database, and obtains the operation set. Therefore, the operation of the user on the database can be restored according to the operation set, and further, a basis is provided for the subsequent database synchronization.
Optionally, in a possible implementation manner of the first aspect, the operation instruction is a write instruction, and the first operation set is a write operation set; or the operation instruction is a read-write instruction, and the first operation set is a read-write operation set or a write operation set.
In this possible implementation manner, the operation set corresponding to the write instruction is a write operation set, and the operation set corresponding to the read/write instruction is a read/write operation set or a write operation set, which can be specifically set according to service requirements, and is not limited herein. The operation set can record the operation of the user on the database, and replay of the operation of the user is realized.
Optionally, in a possible implementation manner of the first aspect, the steps further include: the method comprises the steps that a first node obtains first information of a first transaction set, each transaction in the first transaction set corresponds to one piece of first information, and the first information comprises a first identifier and/or a first timestamp; the first node sends first information to the second node; the first node receives second information sent by the second node, each transaction in the second transaction set corresponds to one piece of second information, and the second information comprises a second identifier and/or a second timestamp; the first information and the second information are used for updating a second database by the second node; the first node updates the first database based on the first set of operations and the second set of operations, comprising: the first node updates the first database based on the first set of operations, the first information, the second set of operations, and the second information.
In this possible implementation manner, in addition to the operation set of the interactive transaction, the nodes may also interact with the timestamp or the identifier of the transaction, so that when the database is updated by using the first transaction set and the second transaction set subsequently, the transaction needing to be submitted and the sequence of submitting the transaction can be determined through the timestamp or the identifier. The conflicting transaction can be rapidly determined through the first information and the second information, so that the speed of updating the database subsequently is improved.
Optionally, in a possible implementation manner of the first aspect, the steps are as follows: the first node updates a first database based on the first set of operations, the first information, the second set of operations, and the second information, comprising: the first node determines transactions to be submitted in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set and the second information; and the first node submits the transaction to be submitted in the first database to obtain an updated first database.
In this possible implementation, when the node updates the first database using the first transaction set and the second transaction set, the transaction that needs to be committed, and the order in which the transactions are committed, may be determined by the first timestamp or the first identification. The conflicting transaction can be rapidly determined through the first information and the second information, and further the speed of updating the first database is improved.
Optionally, in a possible implementation manner of the first aspect, the first information of the first sub-transaction in the first transaction set is a first timestamp, the second information of the second sub-transaction in the second transaction set is a second timestamp, the first sub-transaction and the second sub-transaction at least include one overlapping data item, the first timestamp is smaller than the second timestamp, and the second sub-transaction is a transaction that cannot be committed. The transaction with the larger timestamp is determined to be the transaction which cannot be submitted, and it can be understood that the transaction with the smaller timestamp can also be determined to be the transaction which cannot be submitted, and specific rules can be set according to actual needs, and are not limited herein.
In the possible implementation manner, by determining that the transaction with the larger timestamp is the transaction which can not be submitted, determining which transactions in the first transaction set and the second transaction set can be submitted or can not be submitted according to the rule, and after all the transactions are compared, the transaction to be submitted can be submitted, and the transaction which can not be submitted is rolled back, so that the update of the database is realized.
The second aspect of the embodiments of the present application provides a database processing method, where the method is applied to a database system, where the database system includes a first node and a second node, the first node is deployed with a first database, the second node is deployed with a second database, and the first database and the second database store the same data, and the method may be executed by the second node, or may be executed by a component (such as a processor, a chip, or a chip system) of the second node. The method comprises the following steps: the second node acquires a second operation set, wherein the second operation set is write operation or read-write operation of a second transaction set in a second database in a target time period; the second node sending a second set of operations to the first node; the second node receives a first operation set sent by the first node, wherein the first operation set is write operation or read-write operation of a first transaction set in a first database in a target time period, and the first operation set and the second operation set are used for updating a second database by the first node; the second node updates the second database based on the first set of operations and the second set of operations.
Optionally, in a possible implementation manner of the second aspect, the steps are as follows: the second node obtains a second operation set, including: the second node responds to and executes an operation instruction of a second user on a second database; and the second node records the operation of the second user on the data items in the second database in the process of executing the operation instruction, so as to obtain a second operation set.
Optionally, in a possible implementation manner of the second aspect, the operation instruction is a write instruction, and the second operation set is a write operation set; or the operation instruction is a read-write instruction, and the second operation set is a read-write operation set or a write operation set.
Optionally, in a possible implementation manner of the second aspect, the steps further include: the second node acquires second information of a second transaction set, wherein each transaction in the second transaction set corresponds to one piece of second information, and the second information comprises a second identifier and/or a second timestamp; the second node transmits second information to the first node; the second node receives first information sent by the first node, each transaction in the first transaction set corresponds to one piece of first information, and the first information comprises a first identifier and/or a first timestamp; the first information and the second information are used for updating the second database by the first node; the second node updating the second database based on the first set of operations and the second set of operations, comprising: the second node updates the second database based on the first set of operations, the first information, the second set of operations, and the second information.
Optionally, in a possible implementation manner of the second aspect, the steps are as follows: the second node updating the second database based on the first set of operations, the first information, the second set of operations, and the second information, comprising: the second node determines the transaction to be submitted in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set and the second information; and the second node submits the transaction to be submitted in the second database to obtain an updated second database.
Optionally, in a possible implementation manner of the second aspect, the first information of the first sub-transaction in the first transaction set is a first timestamp, the second information of the second sub-transaction in the second transaction set is a second timestamp, the first sub-transaction and the second sub-transaction at least include one overlapping data item, the first timestamp is smaller than the second timestamp, and the second sub-transaction is a transaction that cannot be committed.
A third aspect of the present embodiment provides a first node, where the first node is applied to a database system, the database system further includes a second node, the first node is deployed with a first database, the second node is deployed with a second database, the first database and the second database store the same data, and the first node includes: the acquisition unit is used for acquiring a first operation set, wherein the first operation set is write operation or read-write operation of a first transaction set in a first database in a target time period; a sending unit, configured to send a first operation set to a second node; the receiving unit is used for receiving a second operation set sent by the second node, wherein the second operation set is write operation or read-write operation of a second transaction set in the second database in a target time period, and the first operation set and the second operation set are used for updating the second database by the second node; and the updating unit is used for updating the first database based on the first operation set and the second operation set.
Optionally, in a possible implementation manner of the third aspect, the acquiring unit is specifically configured to respond to and execute an operation instruction of the first user on the first database; the acquisition unit is specifically configured to record an operation of the first user on the data item in the first database in the process of executing the operation instruction, so as to obtain a first operation set.
Optionally, in a possible implementation manner of the third aspect, the operation instruction is a write instruction, and the first operation set is a write operation set; or the operation instruction is a read-write instruction, and the first operation set is a read-write operation set or a write operation set.
Optionally, in a possible implementation manner of the third aspect, the acquiring unit is further configured to acquire first information of a first transaction set, where each transaction in the first transaction set corresponds to one piece of first information, and the first information includes a first identifier and/or a first timestamp; the sending unit is also used for sending the first information to the second node; the receiving unit is further configured to receive second information sent by the second node, where each transaction in the second transaction set corresponds to one piece of second information, and the second information includes a second identifier and/or a second timestamp; the first information and the second information are used for updating a second database by the second node; the updating unit is specifically configured to update the first database based on the first operation set, the first information, the second operation set, and the second information.
Optionally, in a possible implementation manner of the third aspect, the updating unit is specifically configured to determine a transaction to be committed in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set, and the second information; the updating unit is specifically configured to submit a transaction to be submitted in the first database, so as to obtain an updated first database.
Optionally, in a possible implementation manner of the third aspect, the first information of the first sub-transaction in the first transaction set is a first timestamp, the second information of the second sub-transaction in the second transaction set is a second timestamp, the first sub-transaction and the second sub-transaction at least include one overlapping data item, the first timestamp is smaller than the second timestamp, and the second sub-transaction is a transaction that cannot be committed.
A fourth aspect of the present embodiment provides a second node, where the second node is applied to a database system, the database system further includes a first node, the first node is deployed with a first database, the second node is deployed with a second database, the first database and the second database store the same data, and the second node includes: the acquisition unit is used for acquiring a second operation set, wherein the second operation set is write operation or read-write operation of a second transaction set in a second database in a target time period; a transmitting unit configured to transmit the second operation set to the first node; the receiving unit is used for receiving a first operation set sent by the first node, wherein the first operation set is write operation or read-write operation of a first transaction set in the first database in a target time period, and the first operation set and the second operation set are used for updating the first database by the first node; and the updating unit is used for updating the second database based on the first operation set and the second operation set.
Optionally, in a possible implementation manner of the fourth aspect, the acquiring unit is specifically configured to respond to and execute an operation instruction of the second user on the second database; the acquiring unit is specifically configured to record, during execution of the operation instruction, an operation of the second user on the data item in the second database, and obtain a second operation set.
Optionally, in a possible implementation manner of the fourth aspect, the operation instruction is a write instruction, and the second operation set is a write operation set; or the operation instruction is a read-write instruction, and the second operation set is a read-write operation set or a write operation set.
Optionally, in a possible implementation manner of the fourth aspect, the acquiring unit is further configured to acquire second information of a second transaction set, where each transaction in the second transaction set corresponds to one second information, and the second information includes a second identifier and/or a second timestamp; a transmitting unit for transmitting the second information to the first node; the receiving unit is further used for receiving first information sent by the first node, each transaction in the first transaction set corresponds to one piece of first information, and the first information comprises a first identifier and/or a first timestamp; the first information and the second information are used for updating the first database by the first node; the updating unit is specifically configured to update the second database based on the first operation set, the first information, the second operation set, and the second information.
Optionally, in a possible implementation manner of the fourth aspect, the updating unit is specifically configured to determine a transaction to be committed in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set, and the second information; and the updating unit is specifically used for submitting the transaction to be submitted in the second database to obtain an updated second database.
Optionally, in a possible implementation manner of the fourth aspect, the first information of the first sub-transaction in the first transaction set is a first timestamp, the second information of the second sub-transaction in the second transaction set is a second timestamp, the first sub-transaction and the second sub-transaction at least include one overlapping data item, the first timestamp is smaller than the second timestamp, and the second sub-transaction is a transaction that cannot be committed.
A fifth aspect of embodiments of the present application provides a first node for performing the method of the foregoing first aspect or any possible implementation manner of the first aspect.
A sixth aspect of the embodiments of the present application provides a second node for performing the method of the foregoing second aspect or any possible implementation manner of the second aspect.
A seventh aspect of embodiments of the present application provides a database system, including the first node of the foregoing third aspect or the fifth aspect, and/or the second node of the foregoing fourth aspect or the sixth aspect.
An eighth aspect of the embodiments of the present application provides a chip, the chip including a processor and a data interface, wherein the processor reads instructions stored on a memory through the data interface to perform the method of the first aspect or any one of the possible implementation manners of the first aspect; or to perform the method of the second aspect or any one of the possible implementations of the second aspect. In a specific implementation, the chip may be implemented in the form of a central processing unit (central processing unit, CPU), microcontroller (micro controller unit, MCU), microprocessor (micro processing unit, MPU), digital signal processor (digital signal processing, DSP), system on chip (SoC), application-specific integrated circuit (ASIC), field programmable gate array (field programmable gate array, FPGA) or programmable logic device (programmable logic device, PLD).
A ninth aspect of the embodiments of the present application provides a computer readable medium having stored thereon a program code which, when run on a computer, causes the computer to perform the above-described first aspect or any one of the possible methods of the first aspect; causing a computer to perform the second aspect or any one of the possible methods of the second aspect described above. These computer-readable stores include, but are not limited to, one or more of the following: read-only memory (ROM), programmable ROM (PROM), erasable PROM (EPROM), flash memory, electrically EPROM (EEPROM), and hard disk drive (hard drive).
A tenth aspect of the embodiments of the present application provides a computer program product which, when executed on a computer, causes the computer to perform the method of the first aspect or any of the possible implementations of the first aspect; or cause a computer to perform the method of the second aspect or any possible implementation of the second aspect.
The technical effects of the second aspect to the tenth aspect or any one of the possible implementation manners of the second aspect may be referred to technical effects of the first aspect or technical effects of different possible implementation manners of the first aspect, which are not described herein.
From the above technical solutions, the embodiments of the present application have the following advantages: the first node acquires a first operation set related to a first transaction set in the first database, receives a second operation set related to a second transaction set in a second database sent by the second node, and updates the first database based on the first operation set and the second operation set, so that the update of the first database considers transactions submitted by other databases, and update synchronization among a plurality of databases is ensured. On the one hand, transaction modification is mutually notified among nodes in a mode of transmitting operation sets, multiple interactions among the nodes are not involved, and communication overhead is low. On the other hand, compared with the two-stage commit method, the problem that the transaction cannot be operated due to single-point faults of the coordinator is avoided.
Drawings
FIG. 1 is a schematic diagram of a database system architecture according to an embodiment of the present invention;
fig. 2 is a flow chart of a database processing method according to an embodiment of the present application;
FIG. 3 is an exemplary diagram of a first database and a second database according to an embodiment of the present application;
fig. 4 is a schematic flow chart of updating a first database and a second database according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a first node according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a second node according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a communication device according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a database processing method and related equipment. The operation sets of the transactions are mutually sent among a plurality of nodes in the database system, and the updating of the databases on the nodes considers the transactions submitted by other databases, thereby ensuring the updating synchronization among the plurality of databases.
The following description of the technical solutions according to the embodiments of the present invention will be given with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only some embodiments of the present invention, but not all embodiments. All other embodiments, which are derived by a person skilled in the art from the embodiments according to the invention without creative efforts, fall within the protection scope of the invention.
In addition, in the embodiments of the present application, words such as "exemplary," "for example," and the like are used to indicate an example, instance, or illustration. Any embodiment or design described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, the term use of an example is intended to present concepts in a concrete fashion.
In the present application, "at least one" means one or more, and "a plurality" means two or more. "and/or", describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate: including the cases where a alone, a and B together, and B alone, where a, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b, or c may represent: a, b, c, a-b, a-c, b-c, or a-b-c, wherein a, b, c may be single or plural.
For ease of understanding, related terms and concepts primarily related to embodiments of the present application are described below.
1. Database for storing data
Databases, which may also be referred to as data management systems, are electronic archiving systems that store data in a structured manner. The primary storage structure in the database is a table.
2. Database system
A database system may be understood as a distributed database system comprising a plurality of nodes on which a database is deployed, respectively. In this case, some nodes can process read/write requests, and some nodes can only process read requests. In another case, multiple nodes can handle write requests, in which case the overall resource utilization is high. Wherein a node of the plurality of nodes refers to a computer or software instance in a network or distributed system involving multiple computers.
3. Database management system (database management system DBMS)
The database management system is a large computer software management system designed for managing a database aiming at an object database. The database processing method provided by the embodiment of the application can be applied to MySQL, oracle, open Gaussian (openGauss) and the like, and is not limited in particular.
4. Database transactions (or simply transactions)
A transaction is a logical unit in the execution of a database management system and consists of a finite sequence of database operations. Such as transfer from a bank: a complete transaction requires deducting an amount from one account and adding an amount to another account.
A "commit" is required after the transaction is executed successfully, and the modification will take effect and cannot be lost after the commit is successful. A transaction execution failure (abort) then requires a "rollback" (rollback), no modification of which will take effect.
The transaction has four characteristics:
atomicity (atomicity): all operations in a transaction as a whole are atomic-inseparable, either all successful or all failed.
Consistency (consistency): the results of the execution of a transaction must cause the database to go from one coherency state to another. The consistency state refers to: 1. the state of the system satisfies the integrity constraints of the data (primary code, reference integrity, check constraint, etc.). 2. The state of the system reflects the real world real state that the database should describe, such as sum of the two accounts before and after the transfer should remain unchanged.
Isolation (isolation): concurrently executing transactions do not affect each other as do databases when they are executed serially. For example, multiple users may be simultaneously transferring money to one account, and the final account should be the same as they would be transferring money in order.
Durability (durability): once a transaction commits, its updates to the database are durable. Any transaction or system failure does not result in data loss.
5. Transaction aggregation
The transaction set proposed in the embodiments of the present application includes one transaction or a plurality of transactions, and one transaction includes one operation or a plurality of operations. Further, a transaction corresponds to a time stamp or an identification.
6. Optimistic concurrency control (optimistic concurrency control, OCC)
OCC is a concurrency control method applied to a database management system. OCC assumes that multiple transactions can be completed in parallel without interfering with each other. At runtime, transactions use data resources without acquiring locks for those resources. Before commit, each transaction verifies that no other transaction modified the data it read or modified. If the check shows conflicting modifications, the transaction will need to rollback.
7. Two-stage commit
Two-phase commit (two-phase commit) refers to an algorithm designed within the computer network and database arts to maintain consistency in committing transactions based on all nodes under the distributed system architecture. In general, two-phase commit is also known as a protocol. In a distributed system, each node can know the success or failure of its operation, but cannot know the success or failure of the operation of other nodes. When a transaction spans multiple nodes, in order to maintain four characteristics of the transaction, a component is introduced as a coordinator to uniformly handle the operation results of all nodes (called participants) and ultimately indicate whether the nodes are to actually commit the operation results (e.g., write updated data to disk, etc.). Thus, the algorithmic idea of two-phase commit can be summarized as: the coordinator sends preparation information (preparation) to each participant. Each participant notifies the coordinator of the success or failure of the operation and waits for the coordinator to reply while entering the state of locking the transaction resource. The coordinator decides whether each participant performs a commit operation (commit) or a rollback operation (rollback) according to feedback information of all the participants, and replies the decision of the coordinator to each participant, and each participant releases transaction resources again in response to the decision, thereby ensuring that databases of all the participants are consistent.
However, on one hand, there are three interactions between the coordinator and each participant, and the communication overhead is large. On the other hand, due to the importance of the coordinator, once the coordinator fails. All participants are also in a state of locking the transaction resource and cannot continue to complete the transaction operation.
In order to solve the above-mentioned problems, an embodiment of the present application provides a database processing method, which enables updating of a database on a node to consider transactions submitted by other databases by sending operation sets of transactions between a plurality of nodes in a database system, so as to ensure update synchronization between the plurality of databases.
Fig. 1 shows a schematic diagram of a database system. The database system may include: a node 101, B node 102, C node 103, and D node 104. Wherein, the a node 101 is deployed with an a database, and the user of the a database is an a user. Node B102 is deployed with a B database and the users of the B database are B users. The C node 103 is deployed with a C database, and the user of the C database is a C user. The D node 104 is deployed with a D database, and the user of the D database is a D user. Wherein each database stores the same data. Node a 101, node B102, node C103, and node D104 communicate with each other.
The nodes can mutually transmit the operation set of the self node (also called as a local operation set), and update the database of the self node (also called as a local database) according to the operation set of the transaction set and the operation set of the local transaction set received in other databases.
The operation set in the embodiment of the present application refers to a data item that is modified by a node in response to a user operation instruction (e.g., a write instruction, a read-write instruction, etc.), or a modified data item and a read data item. This set of operations may also be referred to as a write set or a read-write set. The receiving node can update the local database through the operation set sent by the sending node, so that the updated local database is consistent with the data stored in the database of the sending node, and the synchronization between the databases is further ensured.
In one possible implementation, each node may provide a read-write service for a user. Of course, there may be nodes that only provide read services to users or forwarding nodes in the above nodes, or it is understood that the method provided in the embodiments of the present application may be applied to a multi-master replication scenario or a master-slave replication scenario, which is not limited herein.
Optionally, in order to ensure synchronization of the databases, after sending the operation set to the other nodes, each node receives a successful receipt message sent by the other nodes, and then updates the databases by using the local operation set and the operation set of the other nodes. In the case of a set of interactions between a plurality of nodes, 4 nodes shown in fig. 1 are taken as an example. If the A node sends the A operation set to the B node, the C node and the D node respectively, but only receives the successful message sent by the B node and the C node, and does not receive the successful message sent by the D node. The a node may also update the a database using the local operation set and the operation set of other nodes. In other words, most nodes in the database system have successfully received the operation set and updated the local database, so that the database synchronization of most nodes in the database system can be ensured. Of course, the best case is: after receiving the successful message sent by the receiving node, the sending node updates the local database, so that the consistency of the data stored in the databases of all the nodes in the database system can be ensured.
Taking the a user as an example, generally, the a user sends a read-write request to the nearest node (e.g., a node) for processing. In the case of a write request, the processing of the node a is waited to be completed and then synchronized to other nodes, and after conflict detection and conflict processing are successful by combining with operation sets (such as transaction read-write sets) of other nodes, the result is returned to the client (which can be understood as the result returned after the database synchronization is successful).
Illustratively, describing the interaction between the a node and the B node in the above nodes as an example, the a node may receive an operation instruction of the a user for the a database, and the a node records a data item read or modified by the a user in a process of executing the operation instruction, so as to obtain an a operation set of the a node. After the a node obtains the a operation set, the a operation set may be sent to the B node. The node a may also receive a set of B operations sent by the node B (i.e., data items that the node B has read and modified in performing the B user's operation instructions for the B database). Further, the a node may update the a database based on the a operation set and the B operation set. The node B may update the B database based on the a-operation set and the B-operation set. And further realizes the consistency of the database A and the database B. Of course, an interaction period may be set, that is, in each interaction period, two nodes will interact their own data sets, so as to realize synchronization of the database a and the database B.
The operation set in the embodiment of the application refers to integration of operations of a user in the process of operating a database. For example: the operation set is a read-write set, a write set, or the like, and is not limited herein.
In addition, any two users among the user a, the user B, the user C and the user D in the embodiment of the present application may be the same user or different users, which is not limited herein.
In the embodiment of the application, only four nodes and four users are taken as examples for schematic description. In practical applications, the database system in the embodiments of the present application may include more or fewer nodes and users, and the embodiments of the present application do not limit the number of nodes and users.
A node in an embodiment of the present application refers to a computer or software instance in a network or distributed system involving multiple computers. For example: the node may be a server or a terminal device, which is a device with wireless/wired transceiver functions, and may be deployed on land, including indoor or outdoor, hand-held, wearable or vehicle-mounted; can also be deployed on the water surface (such as ships, etc.); but may also be deployed in the air (e.g., on aircraft, balloon, satellite, etc.). The terminal device may be a mobile phone (mobile phone), a tablet computer (pad), a computer with a wireless transceiving function, a Virtual Reality (VR) terminal device, an augmented reality (augmented reality, AR) terminal device, a wireless terminal in industrial control (industrial control), a vehicle-mounted terminal device, a wireless terminal in unmanned driving (self driving), a wireless terminal in remote medical (remote medical), a wireless terminal in smart grid (smart grid), a wireless terminal in transportation security (transportation safety), a wireless terminal in smart city (smart city), a wireless terminal in smart home (smart home), a wearable terminal device, or the like. The embodiments of the present application are not limited to application scenarios. A terminal device may also sometimes be referred to as a terminal, user Equipment (UE), access terminal device, vehicle terminal, industrial control terminal, UE unit, UE station, mobile station, remote terminal device, mobile device, UE agent, UE apparatus, or the like. The terminal device may also be fixed or mobile. In addition, the terminal device may also be a chip system for implementing the UE function.
The database processing method in the embodiment of the present application is described below with reference to an interaction flow between any two nodes in the database system shown in fig. 1. Referring to fig. 2, an embodiment of a database processing method provided in the embodiments of the present application includes steps 201 to 206. The first node and the second node may be any two nodes in fig. 1, which is not limited herein. In addition, the method may be performed by a communication device (e.g., a server or a terminal device) or by a component of a communication device (e.g., a processor, a chip, or a system-on-chip, etc.). It is understood that the communication device may be a chip or a unit or physical device with transceiving functionality. In addition, the database processing method provided in the embodiment of the present application may be applied to MySQL, oracle, open gauss (openGauss), and the like, which is not limited herein.
In step 201, a first node obtains a first set of operations.
The first node and the second node in the embodiment of the present application may be any two nodes in a database system, where the first node is deployed with a first database, the second node is deployed with a second database, and the first database and the second database store the same data.
In the embodiment of the application, the execution process of the database transaction can be recorded by utilizing the operation set. Regardless of how complex the execution of a database transaction is, the set of operations may be utilized to replay the execution of the transaction and produce the same execution results. And the nodes can realize the synchronization of the databases by mutually sending local operation sets.
One or more transactions may be included in the operation set (including the first operation set and the second operation set) in the embodiments of the present application, where one transaction may correspond to one or more operations (e.g., read, write, etc.). The write operation may include operations such as adding, deleting, modifying, etc.
In addition, it should be noted that the first transaction set may be a transaction that may be committed in the first database (it may also be understood that there is no conflict between the plurality of transactions when the number of transactions in the first transaction set is plural), and the second transaction set may be a transaction that may be committed in the second database (it may also be understood that there is no conflict between the plurality of transactions when the number of transactions in the second transaction set is plural). Alternatively, the first set of transactions is all transactions in the first database and the second set of transactions is all transactions in the second database.
In this embodiment of the present application, the first node may acquire the first operation set only by acquiring the first operation set based on an operation instruction of the first user, which may be understood that other devices may also acquire the first operation set by transmitting the first operation set, and the method is not limited herein. The first operation set is a write operation or a read-write operation of the first transaction set in the first database in the target time period. In addition, the number of transactions in the first transaction set may be one or more, and the number of write operations or read/write operations in the first operation set is not limited. The target time period may be set according to actual needs, and is not limited herein.
The target period of time described above may refer to a period of time. The target time period in this case can be understood as a time period between the time of the last synchronization and the target time. Alternatively, the first node may acquire the first operation set in each of the preset periods, and periodically send the operation set to the second node. The number of cycles is not limited here. For example: one cycle is 10 milliseconds, then the target time period may be 10 milliseconds, i.e., the first node will acquire the first set of operations once every 10 milliseconds and send the first set of operations once to the second node.
It is understood that the target time period may also refer to a time period from a creation time of the first database to the target time, i.e. the first set of operations is a write operation or a read-write operation of the first set of transactions in the first database before the target time. In this case, it is understood that, in order to ensure that the first database of the first node is synchronized with the database of the second node at the target time, all the first operation sets before the target time may be transmitted at one time.
Alternatively, the first database may provide a write service or a read-write service for the first user, i.e. the first user may perform a series of operations on entries of the first database in the first node, for example: write (e.g., add, delete, modify), read (e.g., query), etc. The first node records the operation of the first user on the data items in the first database in the process of executing the series of operations, and a first operation set is obtained.
The first node receives a read-write instruction of the first user for the first database, responds to the read-write instruction, performs read-write operation on the table items in the first database, records the data items read and modified by the first user in the process of executing the read-write operation, and obtains a first read-write set. That is, in this example, the first operation set is a read-write operation set or a write operation set of the first transaction set, which is specifically set according to actual needs, and is not limited herein.
The first node receives a write instruction of the first user to the first database, responds to the write instruction, performs write operation on an entry in the first database, and records a data item modified by the first user in the process of executing the write operation to obtain a first write set. That is, in this example, the first set of operations is a set of write operations for the first set of transactions.
For a better understanding of the subsequent synchronization process of the first database and the second database, the following description will be given by taking, as an example, an example in which the first database and the second database store data as shown in table 1 in fig. 3. The first set of transactions performed by the first user in the first database includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu". Transaction 2: the "receiving address" of "Li Liu" is modified to "street F hotel 801 house in south mountain area E of shenzhen, guangdong". The first set of operations of the first set of transactions includes: delete operations and modify operations.
For convenience of the following description, at least one of the first timestamp, the first identification, or the first cycle identification of each transaction in the first set of transactions mentioned later may be referred to as first information. Wherein a transaction in the first set of transactions corresponds to a first timestamp or first identification. I.e. the first timestamp and the first identification may be used to locate a transaction in a unique one of the first transaction sets. Further, the first timestamp or first identification may also be used to sort the plurality of transactions in the first set of transactions to determine the transaction to commit or the order in which the plurality of transactions are committed.
Optionally, during the process of obtaining the first operation set of the first transaction set, the first node may also record an end time (may be referred to as a first timestamp) or a first identifier of a last operation of each transaction, where the first timestamp may be a timestamp local to the first node at the end time of the last operation, may also be a logic time in the database system, may also be a timestamp allocated by a specific central node, or the like, and is not limited herein. The first identification may be a globally unique self-increasing transaction identification of the database system.
Further, if the plurality of nodes in the database system periodically send the local operation set to each other, the first node may further obtain a period identifier of each transaction. In the process of updating the database, if a cross-period operation set exists in the operation sets, for example, one operation set in the operation sets is a first period, the other operation set is a second period, and then the sequence of the transaction corresponding to the submitted operation set can be determined through the period number, so that the synchronization among the databases is ensured. Of course, if there are operation sets crossing cycles among the plurality of operation sets, there are operation sets of the same cycle. In the process of updating the database, the sequence of the transactions corresponding to the operation set in the small range can be determined according to the period identification, and then the sequence of submitting the transactions can be determined according to the time stamp or the identification.
For example, if the method is applied to openGauss, and the four nodes shown in fig. 1 are respectively located in different areas, all the transactions submitted by the users in the area where each node is located can be processed by the node. Specifically, after receiving an operation request of a user and the operation request of the user passes identity verification, the first database connector transmits a structured query language (structured query language, SQL) statement of the operation request to components such as an SQL parser, an optimizer and the like to perform lexical analysis, grammatical analysis and query optimization on the SQL statement. Firstly, keywords, identifiers and the like supported by a system are identified from query sentences, then grammar rules are defined according to standards of SQL language, words generated in the grammar analysis are used for matching the grammar rules, and if one SQL sentence can be matched with one grammar rule, a corresponding abstract grammar tree is generated. Finally, the query optimizer optimizes SQL through query rewrite, generates more efficient equivalent sentences by utilizing the existing sentence characteristics and relational algebra operation, and generates a final query plan based on cost estimation. The preset period is preset, and after the operation set of all nodes in the database system in the current period is required to be collected by the first node in each period, the first node can perform conflict detection and processing (can also be understood as updating the database). For example, the first information includes a first period identification and a first timestamp. And the preset period is 50 milliseconds (ms), i.e. a new synchronization period is generated every 50 ms. It should be noted that, the transaction successfully executed by the first node cannot be written into the first database immediately, and the transaction corresponding to the operation set sent by other nodes in the current period needs to be merged and verified, so as to perform database synchronization. When two transactions in the same period conflict, concurrency control is carried out according to the principle of 'write before win'. Specifically, when two transactions attempt to modify the same data item, the transaction to be committed and the transaction to be rolled back are determined according to the timestamp sizes of the two transactions (described in the following step 205, which is not expanded). It will be appreciated that the operation of the subsequent second node is similar to that of the first node, and will not be described in detail.
Step 202, the first node sends a first set of operations to the second node. Correspondingly, the second node receives the first operation set sent by the first node.
After the first node obtains the first set of operations, the first set of operations may be sent to the second node. Correspondingly, the second node receives the first operation set sent by the first node.
It will be appreciated that the number of times the first node transmits the first set of operations to the second node may be one or more, i.e. may be a full-size transmission or may be a batch transmission, and is not limited herein.
Optionally, if in the foregoing step 201, the first node further obtains at least one of the first timestamp, the first identifier, or the first period identifier, and the first node may further send at least one of the first timestamp, the first identifier, or the first period identifier to the second node. Correspondingly, the second node receives at least one of a first timestamp, a first identifier or a first period identifier sent by the first node.
For example, continuing the above example applied to openGauss scenario, when reaching the end time of a period, the first node may send the first operation set to other nodes in the database system, and finally each node may have the operation set of all transactions in the period, so that concurrency control may be performed according to the same rule (e.g. "write before win"), thereby ensuring that the data of all nodes are consistent. It will be appreciated that the operation of the subsequent second node is similar to that of the first node, and will not be described in detail.
In step 203, the second node obtains a second set of operations.
In this embodiment of the present invention, the second node may acquire the second operation set in a manner similar to the manner in which the first node acquires the first operation set, which may be acquired based on an operation instruction of the second user, or may also acquire the second operation set by other devices, which is not limited herein. The second operation set is a write operation or a read-write operation of the second transaction set in the second database in the target time period. In addition, the number of transactions in the second transaction set may be one or more, and the number of write operations or read/write operations in the second operation set is not limited. The target time period may be set according to actual needs, and is not limited herein.
The target period in this step is similar to the description of the target period in step 201 described above. Alternatively, the second node may acquire the second operation set at each of the preset periods, and periodically transmit the operation set to the first node. The number of cycles is not limited here. For example: one cycle is 10 milliseconds, then the target time period may be 10 milliseconds, i.e., the second node will acquire the second set of operations once every 10 milliseconds and send the second set of operations once to the first node. Reference may be made to the foregoing description for the target period, and a detailed description thereof will be omitted.
Optionally, the second database is similar to the first database, and may provide a write service or a read-write service for the second user, i.e. the second user may perform a series of operations on entries of the second database in the second node, for example: add, delete, modify, query, etc. And the second node records the operation of the second user on the data items in the second database in the process of executing the series of operations, so as to obtain a second operation set.
The second node receives a read-write instruction of the second user to the second database, responds to the read-write instruction, performs read-write operation on the table items in the second database, and records the data items read and modified by the second user in the process of executing the read-write operation to obtain a second read-write set. That is, in this example, the second operation set is a set of read and write operations or a set of write operations of the second transaction set, which is specifically set according to actual needs, and is not limited herein.
The second node receives a write instruction of the second user to the second database, responds to the write instruction, performs write operation on the table items in the second database, and records the data items modified by the second user in the process of executing the write operation to obtain a second write set. That is, in this example, the second set of operations is a set of write operations for the second set of transactions.
Illustratively, continuing with the second database as exemplified in table 1 of fig. 3, assume that the second set of transactions performed by the second user in the second database comprises: transaction 3. Transaction 3: "Zhouqi", "15789012345", "Shenzhen Dahu district W primary school in Guangdong province" are added. The second set of operations includes: the operation is increased.
Similar to the aforementioned first information, for convenience of the subsequent description, at least one of the second timestamp, the second flag, or the second period flag mentioned later may be referred to as second information. Wherein a transaction in the second set of transactions corresponds to a second timestamp or second identification. I.e. the second timestamp and the second identification may be used to locate a unique one of the transactions. Further, the second timestamp or second identification may also be used to sort the plurality of transactions to determine the transaction to commit or the order in which the plurality of transactions are committed.
Optionally, during the process of obtaining the second operation set of the second transaction set, the second node may record an end time (may be referred to as a second timestamp) or a second identifier of a last operation of each transaction, where the second timestamp may be a timestamp local to the second node at the end time of the last operation, may also be a logic time in the database system, may also be a timestamp allocated by a specific central node, and is not limited herein. The second identity may be a globally unique self-increasing transaction identity of the database system.
Further, if the plurality of nodes in the database system periodically send the local operation set to each other, the second node may further obtain the period identifier of the transaction. In the process of updating the database, if a cross-period operation set exists in the operation sets, for example, one operation set in the operation sets is a first period, the other operation set is a second period, and then the sequence of the transaction corresponding to the submitted operation set can be determined through the period number, so that the synchronization among the databases is ensured. Of course, if there are operation sets crossing cycles among the plurality of operation sets, there are operation sets of the same cycle. In the process of updating the database, the sequence of the transaction corresponding to the operation set in the small range can be determined according to the period identification, and then the sequence of submitting the transaction can be determined according to the timestamp or the identification of the transaction.
The second node sends a second set of operations to the first node, step 204. Correspondingly, the first node receives a second operation set sent by the second node.
After the second node obtains the second set of operations, the second set of operations may be transmitted to the first node. Correspondingly, the first node receives a second operation set sent by the second node.
It will be appreciated that the number of times the first node transmits the first set of operations to the second node may be one or more, i.e. may be a full-size transmission or may be a batch transmission, and is not limited herein.
Optionally, if in the foregoing step 203, the second node further obtains at least one of a second timestamp, a second identifier, or a second period identifier, the second node may further send at least one of the second timestamp, the second identifier, or the second period identifier to the first node. Correspondingly, the first node receives at least one of a second timestamp, a second identifier or a second period identifier sent by the second node.
In step 205, the first node updates the first database based on the first set of operations and the second set of operations.
After acquiring the first operation set and the second operation set, the first node may update the first database based on the first operation set and the second operation set. Specifically, the first node may determine, based on the first operation set and the second operation set, a transaction to be committed in the first database, and commit the transaction to be committed in the first database. In other words, the first node may determine operations performed in the second database in the second node based on the second set of operations, and may further perform operations in the second set of operations such that the updating of the first database already takes into account modifications of the second database, thereby ensuring data synchronization between the databases.
In one possible implementation, if the first set of transactions is a committable transaction in the first database, the second set of transactions is a committable transaction in the second database. The first node, when updating the first database, need only determine whether there is a transaction conflict between the first transaction set and the second transaction set because whether a conflict between transactions in the first transaction set or between transactions in the second transaction set has been determined locally at the respective node. The determination of whether transactions conflict according to the embodiments of the present application may be understood as determining whether each transaction is a transaction to be committed or a transaction to be rolled back.
In another possible implementation, if the first set of transactions is first database-owned transactions, the second set of transactions is second database-owned transactions. The subsequent first node, when updating the first database, needs to determine whether there is a conflict of transactions between the first set of transactions and the second set of transactions, and whether there is a conflict of transactions between the plurality of transactions in the first set of transactions and the plurality of transactions in the second set of transactions.
Optionally, the first node may combine the first operation set with the second operation set, determine which operations in the first operation set and the second operation set conflict, determine a transaction to be submitted and a transaction to be rolled back, and further advance a consistency point of the database.
Optionally, the first node obtains at least one of a first timestamp, a first identifier, or a first periodic identifier (or referred to as first information) of each transaction in the first transaction set, and receives at least one of a second timestamp, a second identifier, or a second periodic identifier (or referred to as second information) sent by the second node. The first node may determine a transaction to be committed in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set, and the second information, and commit the transaction to be committed in the first database, to obtain an updated first database.
Further, if each transaction in the first transaction set and the second transaction set has no conflict, the transactions in the first transaction set and the second transaction set can be regarded as the transactions to be submitted. If there is a conflict between the transactions in the first transaction set and the second transaction set (these conflicting transactions may be referred to as conflicting transactions), the transaction to be committed and the transaction to be rolled back in the conflicting transactions may be determined according to a preset rule, and the transaction to be committed is committed and the transaction to be rolled back is rolled back. The preset rule may be set according to actual needs, and is not limited herein. For example: the preset rule is that the transaction with smaller timestamp in the conflict transactions is the transaction to be submitted, or the transaction with larger timestamp is the transaction to be submitted.
It may be appreciated that, for the case that the first transaction set includes a plurality of first sub-transactions and the second transaction set includes a plurality of second sub-transactions, it is determined whether the plurality of first sub-transactions collide with the plurality of second sub-transactions, if a target sub-transaction exists in the plurality of first sub-transactions, collision detection needs to be performed between the target sub-transaction and all other remaining transactions, and only if the target sub-transaction does not collide with all other transactions, it may be determined that the target sub-transaction is a transaction to be committed.
Illustratively, for the case where the first transaction set includes a plurality of first sub-transactions and the second transaction set includes a plurality of second sub-transactions, if it is determined whether one sub-transaction 11 conflicts with one sub-transaction 12, and the timestamp of the sub-transaction 11 is greater than the timestamp of the sub-transaction 12. Then the sub-transaction 11 with the larger timestamp is the transaction to be rolled back and the sub-transaction 12 with the smaller timestamp is not rolled back, but the sub-transaction 12 is not necessarily the transaction to be committed. Because the sub-transaction 12 is also subject to conflict detection with other transactions, it is not until it is determined whether the sub-transaction 12 is a transaction to be committed. After all transactions are compared, it is determined that the non-rollback transactions can be committed. It is to be appreciated that the identification of sub-transaction 11 and sub-transaction 12 (i.e., 11 and 12) is merely exemplary herein.
It should be noted that the method of the embodiments of the present application may be applied to OCC scenarios where commit in a commit transaction is equivalent to a database in which data updated by a write operation is actually written.
Illustratively, the first information of the first sub-transaction in the first transaction set is a first timestamp and the second information of the second sub-transaction in the second transaction set is a second timestamp. The first sub-transaction and the second sub-transaction at least comprise one overlapped data item, and the first timestamp of the first sub-transaction is smaller than the second timestamp of the second sub-transaction, so that the first sub-transaction can be determined to be a transaction which does not need rollback, and the second sub-transaction is a rollback transaction. After comparing the first sub-transaction with the timestamps of all the other transactions one-to-one, the transaction that does not need to be rolled back is determined to be the transaction to be committed. Of course, it is also possible that the transaction with the larger timestamp is the transaction that does not need to be rolled back, and the transaction with the smaller timestamp is the transaction to be rolled back.
In addition, the first node may further determine a commit order of the transactions to be committed according to the first information and the second information. Specifically, if multiple nodes in the database system are periodically sending local operation sets to each other, this step may be periodic. In addition, if a cross-period operation set exists in the operation sets, for example, one operation set in the operation sets is a first period, the other operation set is a second period, and then the sequence of the transactions corresponding to the submitted operation set can be determined through the period number, so that synchronization among the databases is ensured. Of course, if there are operation sets crossing cycles among the plurality of operation sets, there are operation sets of the same cycle. In the process of updating the database, the sequence of the transaction corresponding to the operation set in the small range can be determined according to the period identification, and then the sequence of submitting the transaction can be determined according to the timestamp or the identification of the transaction.
Alternatively, the first node may log or update the snapshot after updating the first database.
Illustratively, continuing the previous example, the first set of transactions performed by the first user in the first database includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu". Transaction 2: the "receiving address" of "Li Liu" is modified to "street F hotel 801 house in south mountain area E of shenzhen, guangdong". The first set of operations of the first set of transactions includes: delete operations and modify operations. The second set of transactions performed by the second user in the second database includes: transaction 3. Transaction 3: "Zhouqi", "15789012345", "Shenzhen Dahu district W primary school in Guangdong province" are added. The second set of operations includes: the operation is increased. The flow of updating the first database by the first node based on the first operation set and the second operation set is shown in fig. 4, and the updated first database is shown in table 2 in fig. 4.
Illustratively, continuing the above example applied to openGauss scenario, the first node parses out related data of the transaction after receiving the operation set of the transaction sent by other nodes in the current period, and implements concurrency control by using the same rule (which may also be understood as determining the transaction to be submitted and the transaction to be rolled back). The transaction to be committed is committed, and the transaction to be rolled back is rolled back. It will be appreciated that the operation of the subsequent second node is similar to that of the first node, and will not be described in detail.
At step 206, the second node updates the second database based on the first set of operations and the second set of operations.
After the second node obtains the first set of operations and the second set of operations, the second node may update the second database based on the first set of operations and the second set of operations. Specifically, the second node may determine, based on the first operation set and the second operation set, a transaction to be committed by the second database, and commit the transaction to be committed in the second database. In other words, the second node may determine, based on the first set of operations, operations performed in the first database in the first node, and may further perform operations in the first set of operations such that an update of the second database has considered a modification of the first database, thereby ensuring data synchronization between the databases.
Optionally, the second node obtains at least one of a second timestamp, a second identifier, or a second period identifier (or referred to as second information) of each transaction in the second transaction set, and receives at least one of the first timestamp, the first identifier, or the second period identifier (or referred to as first information) sent by the first node. The second node may determine a transaction to be committed in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set, and the second information, and commit the transaction to be committed in the second database, to obtain an updated second database.
For descriptions of overlapping data items for the transactions in the first transaction set and the second transaction set, determining the transaction to be committed, and the transaction to be rolled back, reference may be made to the description in step 205, which is not repeated here.
Alternatively, the second node may log or update the snapshot after updating the second database.
Illustratively, continuing the previous example, the first set of transactions includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu". Transaction 2: the "receiving address" of "Li Liu" is modified to "street F hotel 801 house in south mountain area E of shenzhen, guangdong". The first set of operations of the first set of transactions includes: delete operations and modify operations. The second set of operations includes: the process is increased. The second transaction includes: "Zhouqi", "15789012345", "Shenzhen Dahu district W primary school in Guangdong province" are added. The flow of updating the second database by the second node based on the first set of operations and the second set of operations is shown in fig. 4, and the updated second database is shown in table 2 in fig. 4.
It will be appreciated that embodiments of the present application are not limited to the timing between the various steps described above. For example: step 203 may precede step 202 or step 201. Also for example: step 206 may follow step 205, etc., and is not specifically limited herein.
In addition, the steps 201 to 206 in this step may be performed periodically, and the number of times of performing the steps 201 to 206 in this embodiment may be one or more, which is not limited herein. Of course, if executed periodically, the transaction in the new cycle cannot commit until the previous cycle is completed synchronously.
In the embodiment of the application, the first node acquires a first operation set related to a first transaction set in the first database, receives a second operation set related to a second transaction set in a second database sent by the second node, and updates the first database based on the first operation set and the second operation set, so that the update of the first database considers transactions submitted by other databases, and update synchronization among a plurality of databases is ensured. On the one hand, transaction modification is mutually notified among nodes in a mode of transmitting operation sets, multiple interactions among the nodes are not involved, and communication overhead is low. On the other hand, compared with the two-stage commit method, the problem that the transaction cannot be operated due to single-point faults of the coordinator is avoided.
The database processing method in the embodiment of the present application is described above, and the first node and the second node in the embodiment of the present application are described below, where the first node and the second node are applied to a database system, the first node is deployed with a first database, the second node is deployed with a second database, and the first database and the second database store the same data. Referring to fig. 5, an embodiment of a first node in the embodiments of the present application includes:
An obtaining unit 501, configured to obtain a first operation set, where the first operation set is a write operation or a read-write operation of a first transaction set in a first database in a target time period;
a sending unit 502, configured to send the first operation set to the second node;
a receiving unit 503, configured to receive a second operation set sent by a second node, where the second operation set is a write operation or a read-write operation of a second transaction set in a second database within a target period of time, and the first operation set and the second operation set are used by the second node to update the second database;
an updating unit 504, configured to update the first database based on the first operation set and the second operation set.
In this embodiment, the operations performed by the units in the first node are similar to those described in the embodiments shown in fig. 1 to 4, and are not repeated here.
In this embodiment, the operation sets of the transactions are sent to each other between the plurality of nodes in the database system, and the update of the database on the node considers the transactions submitted by other databases, so as to ensure update synchronization between the plurality of databases. On the one hand, transaction modification is mutually notified among nodes in a mode of transmitting operation sets, multiple interactions among the nodes are not involved, and communication overhead is low. On the other hand, compared with the two-stage commit method, the problem that the transaction cannot be operated due to single-point faults of the coordinator is avoided.
Referring to fig. 6, an embodiment of the second node in the embodiment of the present application includes:
an obtaining unit 601, configured to obtain a second operation set, where the second operation set is a write operation or a read-write operation of a second transaction set in a second database within a target time period;
a transmitting unit 602, configured to transmit the second operation set to the first node;
the receiving unit 603 is configured to receive a first operation set sent by a first node, where the first operation set is a write operation or a read-write operation of a first transaction set in a first database in a target time period, and the first operation set and the second operation set are used for updating the first database by the first node;
an updating unit 604, configured to update the second database based on the first operation set and the second operation set.
In this embodiment, the operations performed by the units in the second node are similar to those described in the embodiments shown in fig. 1 to 4, and are not repeated here.
In this embodiment, the operation sets of the transactions are sent to each other between the plurality of nodes in the database system, and the update of the database on the node considers the transactions submitted by other databases, so as to ensure update synchronization between the plurality of databases. On the one hand, transaction modification is mutually notified among nodes in a mode of transmitting operation sets, multiple interactions among the nodes are not involved, and communication overhead is low. On the other hand, compared with the two-stage commit method, the problem that the transaction cannot be operated due to single-point faults of the coordinator is avoided.
Referring to fig. 7, a schematic structural diagram of a communication device is provided. The communication device may be the first node or the second node in the embodiments shown in the foregoing figures 1 to 4. The communication device may include a processor 701, a memory 702, and a communication interface 703. The processor 701, the memory 702 and the communication interface 703 are interconnected by wires. Wherein program instructions and data are stored in memory 702.
In a possible implementation manner, the memory 702 stores program instructions and data corresponding to the steps executed by the first node in the foregoing embodiments corresponding to fig. 1 to 4. A processor 701 for executing the steps performed by the first node as described in any of the embodiments shown in the previous figures 1 to 4. The communication interface 703 may be used to perform the steps related to acquiring, transmitting, receiving performed by the first node in any of the embodiments shown in the previous figures 1-4. For example, the communication interface 703 may be used to transmit a first set of operations and first information, and to receive a second set of operations and second information.
In another possible implementation manner, the memory 702 stores program instructions and data corresponding to the steps executed by the second node in the foregoing embodiments corresponding to fig. 1 to 4. A processor 701 for executing the steps executed by the second node as described in any of the embodiments shown in the previous figures 1 to 4. The communication interface 703 may be used to perform the steps related to acquiring, transmitting, receiving performed by the second node in any of the embodiments shown in the previous figures 1-4. For example, the communication interface 703 may be used to transmit the second set of operations and the second information, receive the first set of operations and the first information.
It will be appreciated that the communication device may include more or fewer components than those of fig. 7, which is exemplary only and not limiting.
In addition, embodiments of the present application provide a database system that includes a first node as shown in fig. 5 and/or a second node as shown in fig. 6. Or the database system may include a communication device as shown in fig. 7, described above.
In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of elements is merely a logical functional division, and there may be additional divisions of actual implementation, e.g., multiple elements or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units described above may be implemented in whole or in part by software, hardware, firmware, or any combination thereof.
When the integrated unit is implemented in 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 loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., 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, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a Solid State Disk (SSD)), or the like.
The terms first, second and the like in the description and in the claims of the present application and in the above-described figures, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the terms so used are interchangeable under appropriate circumstances and are merely illustrative of the manner in which the embodiments of the application described herein have been described for objects of the same nature. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of elements is not necessarily limited to those elements, but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.

Claims (15)

1. A database processing method, wherein the method is applied to a database system, the database system includes a first node and a second node, the first node is deployed with a first database, the second node is deployed with a second database, the first database and the second database store the same data, the method includes:
the first node acquires a first operation set, wherein the first operation set is write operation or read-write operation of a first transaction set in the first database in a target time period;
The first node sends the first operation set to the second node;
the first node receives a second operation set sent by the second node, wherein the second operation set is write operation or read-write operation of a second transaction set in the second database in the target time period, and the first operation set and the second operation set are used for updating the second database by the second node;
the first node updates the first database based on the first set of operations and the second set of operations.
2. The method of claim 1, wherein the first node obtains a first set of operations comprising:
the first node responds to and executes an operation instruction of a first user on the first database;
and the first node records the operation of the first user on the data items in the first database in the process of executing the operation instruction, so as to obtain the first operation set.
3. The method of claim 2, wherein the operation instruction is a write instruction and the first set of operations is a set of write operations; or the operation instruction is a read-write instruction, and the first operation set is a read-write operation set or a write operation set.
4. A method according to any one of claims 1 to 3, further comprising:
the first node obtains first information of the first transaction set, wherein each transaction in the first transaction set corresponds to one piece of first information, and the first information comprises a first identifier and/or a first timestamp;
the first node sends the first information to the second node;
the first node receives second information sent by the second node, each transaction in the second transaction set corresponds to one piece of second information, and the second information comprises a second identifier and/or a second timestamp; the first information and the second information are used for updating the second database by the second node;
the first node updating the first database based on the first set of operations and the second set of operations, comprising:
the first node updates the first database based on the first set of operations, the first information, the second set of operations, and the second information.
5. The method of claim 4, wherein the first node updating the first database based on the first set of operations, the first information, the second set of operations, and the second information comprises:
The first node determines transactions to be committed in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set and the second information;
and the first node submits the transaction to be submitted in the first database to obtain an updated first database.
6. The method of claim 5, wherein the first information of a first sub-transaction in the first transaction set is the first timestamp, the second information of a second sub-transaction in the second transaction set is the second timestamp, the first sub-transaction and the second sub-transaction at least comprise one overlapping data item, the first timestamp is less than the second timestamp, and the second sub-transaction is a non-commitable transaction.
7. A first node for use in a database system, the database system further comprising a second node, the first node having a first database disposed therein, the second node having a second database disposed therein, the first database and the second database storing the same data, the first node comprising:
The system comprises an acquisition unit, a first operation set and a second operation set, wherein the acquisition unit is used for acquiring a first operation set, and the first operation set is write operation or read-write operation of a first transaction set in a first database in a target time period;
a sending unit, configured to send the first operation set to the second node;
the receiving unit is used for receiving a second operation set sent by the second node, wherein the second operation set is write operation or read-write operation of a second transaction set in the second database in the target time period, and the first operation set and the second operation set are used for updating the second database by the second node;
and the updating unit is used for updating the first database based on the first operation set and the second operation set.
8. The first node according to claim 7, wherein the obtaining unit is specifically configured to respond to and execute an operation instruction of a first user on the first database;
the obtaining unit is specifically configured to record, during execution of the operation instruction, an operation of the first user on a data item in the first database, so as to obtain the first operation set.
9. The first node of claim 8, wherein the operation instruction is a write instruction and the first set of operations is a set of write operations; or the operation instruction is a read-write instruction, and the first operation set is a read-write operation set or a write operation set.
10. The first node according to any of the claims 7 to 9, wherein the obtaining unit is further configured to obtain first information of the first set of transactions, one first information for each transaction in the first set of transactions, the first information comprising a first identification, and/or a first timestamp;
the sending unit is further configured to send the first information to the second node;
the receiving unit is further configured to receive second information sent by the second node, where each transaction in the second transaction set corresponds to one piece of second information, and the second information includes a second identifier and/or a second timestamp; the first information and the second information are used for updating the second database by the second node;
the updating unit is specifically configured to update the first database based on the first operation set, the first information, the second operation set, and the second information.
11. The first node according to claim 10, wherein the updating unit is specifically configured to determine a transaction to be committed in the first transaction set and the second transaction set based on the first operation set, the first information, the second operation set, and the second information;
The updating unit is specifically configured to submit the transaction to be submitted in the first database, so as to obtain an updated first database.
12. The first node of claim 11, wherein the first information of a first sub-transaction in the first transaction set is the first timestamp, the second information of a second sub-transaction in the second transaction set is the second timestamp, the first sub-transaction and the second sub-transaction at least comprise one overlapping data item, the first timestamp is less than the second timestamp, and the second sub-transaction is a non-commit-capable transaction.
13. A first node, comprising: a processor coupled to a memory for storing a program or instructions that, when executed by the processor, cause the first node to perform the method of any of claims 1 to 6.
14. A computer storage medium comprising computer instructions which, when run on an electronic device, cause the electronic device to perform the method of any one of claims 1 to 6.
15. A computer program product, characterized in that the computer program product, when run on a computer, causes the computer to perform the method according to any of claims 1 to 6.
CN202111679433.0A 2021-12-31 2021-12-31 Database processing method and related equipment Pending CN116414844A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202111679433.0A CN116414844A (en) 2021-12-31 2021-12-31 Database processing method and related equipment
PCT/CN2022/126150 WO2023124431A1 (en) 2021-12-31 2022-10-19 Database processing method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111679433.0A CN116414844A (en) 2021-12-31 2021-12-31 Database processing method and related equipment

Publications (1)

Publication Number Publication Date
CN116414844A true CN116414844A (en) 2023-07-11

Family

ID=86997473

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111679433.0A Pending CN116414844A (en) 2021-12-31 2021-12-31 Database processing method and related equipment

Country Status (2)

Country Link
CN (1) CN116414844A (en)
WO (1) WO2023124431A1 (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP5103807B2 (en) * 2006-06-30 2012-12-19 富士通株式会社 Control program, control method, information processing apparatus, and information processing system
CN106339408B (en) * 2016-08-10 2019-08-23 深圳中兴网信科技有限公司 Method of data synchronization, data synchronization unit and server
CN111597197B (en) * 2020-06-29 2022-02-08 腾讯科技(深圳)有限公司 Data reconciliation method and device between databases, storage medium and electronic equipment
CN114238507A (en) * 2021-12-15 2022-03-25 湖北天融信网络安全技术有限公司 Data synchronization method and device based on multiple databases

Also Published As

Publication number Publication date
WO2023124431A1 (en) 2023-07-06

Similar Documents

Publication Publication Date Title
EP2932370B1 (en) System and method for performing a transaction in a massively parallel processing database
EP3058690B1 (en) System and method for creating a distributed transaction manager supporting repeatable read isolation level in a mpp database
CN102037463B (en) Log based replication of distributed transactions using globally acknowledged commits
EP3120261B1 (en) Dependency-aware transaction batching for data replication
Kemme et al. Database replication: a tale of research across communities
US7693882B2 (en) Replicating data across the nodes in a cluster environment
US20110161281A1 (en) Distributed Transaction Management in a Distributed Shared Disk Cluster Environment
US10871918B2 (en) Writing composite objects to a data store
CN101184106A (en) Associated transaction processing method of mobile database
US11681683B2 (en) Transaction compensation for single phase resources
CN106484321A (en) A kind of date storage method and data center
CN106569896B (en) A kind of data distribution and method for parallel processing and system
CN103399894A (en) Distributed transaction processing method on basis of shared storage pool
EP4276651A1 (en) Log execution method and apparatus, and computer device and storage medium
CN110188114A (en) A kind of optimization method of data manipulation, device, system, equipment and storage medium
US8996484B2 (en) Recursive lock-and-propagate operation
CN114157550B (en) Alliance block chain system based on conflict-free transaction merging
CN106959989A (en) The synchronous method and device in master/slave data storehouse
CN116414844A (en) Database processing method and related equipment
Wang et al. Research and design of distributed database synchronization system based on middleware
Ibrahim Mobile transaction processing for a distributed war environment
CN117573730B (en) Data processing method, apparatus, device, readable storage medium, and program product
CN112988905B (en) Node memory synchronization method and device for cluster deployment
JPH07210436A (en) Distributed transaction processing system
CN117311913A (en) Distributed transaction processing method, device, equipment and storage medium

Legal Events

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