WO2023124431A1 - Database processing method and related device - Google Patents

Database processing method and related device Download PDF

Info

Publication number
WO2023124431A1
WO2023124431A1 PCT/CN2022/126150 CN2022126150W WO2023124431A1 WO 2023124431 A1 WO2023124431 A1 WO 2023124431A1 CN 2022126150 W CN2022126150 W CN 2022126150W WO 2023124431 A1 WO2023124431 A1 WO 2023124431A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
transaction
database
information
operation set
Prior art date
Application number
PCT/CN2022/126150
Other languages
French (fr)
Chinese (zh)
Inventor
张子杰
任阳
李思昊
张岩峰
付国
周慰星
Original Assignee
华为技术有限公司
东北大学
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司, 东北大学 filed Critical 华为技术有限公司
Publication of WO2023124431A1 publication Critical patent/WO2023124431A1/en

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

Definitions

  • the present application relates to the technical field of databases, in particular to a database processing method and related equipment.
  • a distributed system will split an application system into multiple services that can be deployed independently, so remote collaboration between services is required to complete transaction operations.
  • different services collaborate remotely through the network Completing a transaction is called a distributed transaction, such as user registration to send points, create an order to reduce inventory, and bank transfer transactions are all distributed transactions.
  • each node is physically independent from each other and communicates and coordinates through the network. Due to the existence of the transaction mechanism, it can be guaranteed that the data operation on each independent node can satisfy ACID.
  • the conventional solution is to introduce a "coordinator" component to uniformly schedule the execution of all distributed nodes, which can also be called a two-phase commit method.
  • the idea of the two-phase commit method can be summarized as follows: the coordinator sends preparation information (prepare) to each participant. Each participant notifies the coordinator of the success or failure of the operation, and enters the state of locking transaction resources to wait for the coordinator to reply. The coordinator decides whether each participant performs a commit operation (commit) or a rollback operation (rollback) based on the feedback information of all participants, and replies to each participant with the decision of the coordinator, and each participant then releases transaction resources in response to the decision, thus Ensure that the databases of all participants are consistent.
  • Embodiments of the present application provide a database processing method and related equipment. Multiple nodes in the database system send transactions to each other. The update of the database on the node takes into account the transactions submitted by other databases, so as to ensure the synchronization of updates among multiple databases.
  • the first aspect of the embodiment of the present application provides a database processing method, 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 the first database, and the second node is deployed with the second database , 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 components of the first node (such as a processor, a chip, or a chip system, etc.).
  • the method includes: the first node obtains a first operation set, and the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period; the first node sends the first operation set to the second node ; The first node receives the second operation set sent by the second node, the second operation set is the write operation or read-write operation of the second transaction set in the second database within the target time period, the first operation set and the second operation set Used for the second node to update the second database; the first node to update the first database based on the first operation set and the second operation set.
  • multiple nodes in the database system send transaction operation sets to each other, and the update of the database on the node takes into account the transactions submitted by other databases, so as to ensure the update synchronization among multiple databases.
  • transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small.
  • it compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
  • the first node acquires the first operation set includes: the first node responds to and executes the first user's operation instruction on the first database; the first During the process of executing the operation instruction, the node records the operation of the first user on the data items in the first database to obtain the first operation set.
  • the node records the first user's operation on the data items in the database to obtain an operation set. Therefore, the user's operations on the database can be restored according to the operation set, thereby providing a basis for subsequent database synchronization.
  • the above-mentioned operation instruction is a write instruction, and the first operation set is a write operation set; or, the operation instruction is a read and write instruction, and the first operation set is a read and write A collection of operations or a collection of write operations.
  • the operation set corresponding to the write command is the write operation set
  • the operation set corresponding to the read and write commands is the read and write operation set or the write operation set, which can be set according to business needs, and is not limited here.
  • the user's operation on the database can be recorded through the operation set, and the replay of the user's operation can be realized.
  • the above steps further include: the first node acquires the first information of the first transaction set, each transaction in the first transaction set corresponds to a first information, and the first A message includes a first identifier and/or a first timestamp; the first node sends the first message to the second node; the first node receives the second message sent by the second node, and each transaction in the second transaction set corresponds to a
  • the second information, the second information includes the second identification, and/or the second time stamp; the first information and the second information are used for the second node to update the second database; the first node is based on the first operation set and the second operation set
  • Updating the first database includes: the first node updating the first database based on the first operation set, the first information, the second operation set, and the second information.
  • the nodes in addition to the operation set of the interactive transaction, can also interact with the timestamp or identification of the transaction, so that when the database is updated using the first transaction set and the second transaction set, it can be passed Timestamps or identifiers identify which transactions need to be committed, and the order in which they are committed. Conflicting transactions can be quickly determined through the first information and the second information, thereby increasing the speed of subsequent database updates.
  • the first node updates the first database based on the first operation set, the first information, the second operation set, and the second information includes: first The node determines the 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 first node submits the transaction to be committed in the first database, and obtains Updated first database.
  • the node when the node uses the first transaction set and the second transaction set to update the first database, it can use the first timestamp or the first identification to determine the transactions to be submitted and the order of submitting the transactions. Conflicting transactions can be quickly determined through the first information and the second information, thereby increasing the speed of subsequent updating of the first database.
  • the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp
  • the second information of the second sub-transaction in the second transaction set The information is a second timestamp
  • the first sub-transaction and the second sub-transaction include at least one overlapping data item
  • the first timestamp is smaller than the second timestamp
  • the second sub-transaction is a transaction that cannot be committed.
  • a transaction with a larger timestamp is determined as a transaction that cannot be committed. It is understandable that a transaction with a smaller timestamp can also be determined as a transaction that cannot be committed.
  • the specific rules can be set according to actual needs, and there is no limitation here.
  • this rule can determine which transactions in the first transaction set and the second transaction set can be committed or cannot be committed, and compare all transactions After the end, you can submit the transaction to be submitted, roll back the transaction that cannot be submitted, and then realize the update of the database.
  • the second aspect of the embodiment of the present application provides a database processing method.
  • 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 the first database
  • the second node is deployed with the second database.
  • the first database and the second database store the same data
  • the method may be executed by the second node, or may be executed by components of the second node (such as a processor, a chip, or a chip system, etc.).
  • the method includes: the second node obtains a second operation set, and the second operation set is a write operation or a read-write operation of a second transaction set in the second database within a target time period; the second node sends the second operation set to the first node ; The second node receives the first operation set sent by the first node, the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period, the first operation set and the second operation set The first node updates the second database; the second node updates the second database based on the first operation set and the second operation set.
  • the second node acquires the second operation set includes: the second node responds to and executes the second user's operation instruction on the second database; the second During the process of executing the operation instruction, the node records the second user's operation on the data item in the second database, and obtains the second operation set.
  • the above-mentioned operation instruction is a write instruction, and the second operation set is a write operation set; or, the operation instruction is a read and write instruction, and the second operation set is a read and write operation A collection of operations or a collection of write operations.
  • the above steps further include: the second node acquires second information of a second transaction set, each transaction in the second transaction set corresponds to a second information, and the second The second information includes the second identification, and/or the second timestamp; the second node sends the second information to the first node; the second node receives the first information sent by the first node, and each transaction in the first transaction set corresponds to a
  • the first information, the first information includes the first identification, and/or the first time stamp; the first information and the second information are used for the first node to update the second database; the second node is based on the first operation set and the second operation set
  • Updating the second database includes: updating the second database by the second node based on the first operation set, the first information, the second operation set, and the second information.
  • the second node updates the second database based on the first operation set, the first information, the second operation set, and the second information includes: the second The node determines the 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 second node submits the transaction to be committed in the second database, and obtains Updated second database.
  • the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp
  • the second information of the second sub-transaction in the second transaction set The information is a second timestamp
  • the first sub-transaction and the second sub-transaction include at least one overlapping data item
  • the first timestamp is smaller than the second timestamp
  • the second sub-transaction is a transaction that cannot be committed.
  • the third aspect of the embodiment of the present application provides a first node, 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, and the second node is deployed with a second database,
  • the first database and the second database store the same data
  • the first node includes: an acquisition unit configured to acquire a first operation set, where the first operation set is a write operation of a first transaction set in the first database within a target time period Or read and write operations; the sending unit is used to send the first operation set to the second node; the receiving unit is used to receive the second operation set sent by the second node, and the second operation set is in the second database within the target time period
  • the write operation or read-write operation of the second transaction set, the first operation set and the second operation set are used for the second node to update the second database; the update unit is used for updating the first database based on the first operation set and the second operation set .
  • the above-mentioned obtaining unit is specifically configured to respond to and execute an operation instruction of the first user on the first database; the obtaining unit is specifically configured to During the process, the first user's operations on the data items in the first database are recorded to obtain a first operation set.
  • the above-mentioned operation instruction is a write instruction, and the first operation set is a write operation set; or, the operation instruction is a read and write instruction, and the first operation set is a read and write operation set A collection of operations or a collection of write operations.
  • the above-mentioned acquisition unit is further configured to acquire first information of a first transaction set, each transaction in the first transaction set corresponds to a first information, and the first A piece of information includes a first identifier and/or a first time stamp; a sending unit is also used to send the first information to the second node; a receiving unit is also used to receive the second information sent by the second node, and the second transaction set Each transaction corresponds to a 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 the second node to update the second database; the update unit is specifically used for The first set of operations, the first information, the second set of operations, and the second information update the first database.
  • the above update unit is specifically configured to determine 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. Two transactions to be submitted in the transaction set; an updating unit, specifically configured to submit the transactions to be submitted in the first database to obtain an updated first database.
  • the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp
  • the second information of the second sub-transaction in the second transaction set The information is a second timestamp
  • the first sub-transaction and the second sub-transaction include at least one overlapping data item
  • the first timestamp is smaller than the second timestamp
  • the second sub-transaction is a transaction that cannot be committed.
  • the fourth aspect of the embodiment of the present application provides a second node, 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, and the second node is deployed with a second database,
  • the first database and the second database store the same data
  • the second node includes: an acquisition unit, configured to acquire a second operation set, where the second operation set is a write operation of a second transaction set in the second database within a target time period Or read and write operations;
  • the sending unit is used to send the second operation set to the first node;
  • the receiving unit is used to receive the first operation set sent by the first node, the first operation set is in the first database within the target time period
  • the write operation or read-write operation of the first transaction set, the first operation set and the second operation set are used for the first node to update the first database;
  • the update unit is used for updating the second database based on the first operation set and the second operation set .
  • the above-mentioned 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 During the process, the second user's operations on the data items in the second database are recorded to obtain a second operation set.
  • the above-mentioned operation instruction is a write instruction, and the second operation set is a write operation set; or, the operation instruction is a read and write instruction, and the second operation set is a read and write operation A collection of operations or a collection of write operations.
  • the above-mentioned acquiring unit is further configured to acquire second information of a second transaction set, each transaction in the second transaction set corresponds to a second information, and the first The second information includes the second identification, and/or the second timestamp; the sending unit is also used to send the second information to the first node; the receiving unit is also used to receive the first information sent by the first node, the first transaction set Each transaction corresponds to a first information, the first information includes the first identification, and/or the first timestamp; the first information and the second information are used for the first node to update the first database; the update unit is specifically used for The first set of operations, the first information, the second set of operations, and the second information update the second database.
  • the above update unit is specifically configured to determine 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. Transactions to be submitted in the transaction set; an updating unit, specifically configured to submit the transactions to be submitted in the second database to obtain an updated second database.
  • the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp
  • the second information of the second sub-transaction in the second transaction set The information is a second timestamp
  • the first sub-transaction and the second sub-transaction include at least one overlapping data item
  • the first timestamp is smaller than the second timestamp
  • the second sub-transaction is a transaction that cannot be committed.
  • a fifth aspect of the embodiments of the present application provides a first node, where the first node is configured to execute the method in 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, where the second node is configured to execute the method in the foregoing second aspect or any possible implementation manner of the second aspect.
  • the seventh aspect of the embodiment of the present application provides a database system, including the first node of the aforementioned third aspect or the fifth aspect, and/or the second node of the aforementioned fourth aspect or the sixth aspect.
  • the eighth aspect of the embodiment of the present application provides a chip, the chip includes a processor and a data interface, wherein the processor reads the instructions stored in the memory through the data interface to execute any one of the first aspect or the first aspect. or to execute the method in the second aspect or any possible implementation manner of the second aspect.
  • the chip can be based on a central processing unit (CPU), a microcontroller (micro controller unit, MCU), a microprocessor (micro processing unit, MPU), a 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) in the form of realization.
  • CPU central processing unit
  • MCU microcontroller
  • MPU microprocessor
  • DSP digital signal processor
  • SoC system on chip
  • ASIC application-specific integrated circuit
  • FPGA field programmable gate array
  • PLD programmable logic device
  • the ninth aspect of the embodiment of the present application provides a computer-readable medium, the computer-readable medium stores program codes, and when the computer program codes run on the computer, the computer executes the above-mentioned first aspect or any of the first aspects.
  • a possible execution method causing a computer to execute the above second aspect or any possible execution method of the second aspect.
  • These computer-readable storages include, but are not limited to, one or more of the following: read-only memory (read-only memory, ROM), programmable ROM (programmable ROM, PROM), erasable PROM (erasable PROM, EPROM), Flash memory, electrical EPROM (electrically EPROM, EEPROM) and hard drive (hard drive).
  • the tenth aspect of the embodiments of the present application provides a computer program product.
  • the computer program product When the computer program product is executed on a computer, it causes the computer to execute the method in the aforementioned first aspect or any possible implementation of the first aspect; or causes the computer to execute The aforementioned second aspect or the method in any possible implementation of the second aspect.
  • the technical effects brought about by the second aspect to the tenth aspect or any one of the possible implementations can refer to the first aspect or the technical effects brought about by different possible implementations of the first aspect, and will not be repeated here.
  • the first node obtains the first operation set related to the first transaction set in the first database, and receives the second transaction in the second database sent by the second node. Collect the related second operation set, and update the first database based on the first operation set and the second operation set, so that the update of the first database takes into account the transactions submitted by other databases, thereby ensuring the update synchronization between multiple databases.
  • transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small.
  • it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
  • FIG. 1 is a schematic diagram of a database system architecture provided by an embodiment of the present invention
  • FIG. 2 is a schematic flow diagram of a database processing method provided in an embodiment of the present application.
  • FIG. 3 is an example diagram of the first database and the second database provided by the embodiment of the present application.
  • FIG. 4 is a schematic flow diagram of updating the first database and the second database provided by the embodiment of the present application.
  • FIG. 5 is a schematic structural diagram of the first node provided by the embodiment of the present application.
  • FIG. 6 is a schematic structural diagram of a second node provided by an embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a communication device provided by an embodiment of the present application.
  • Embodiments of the present application provide a database processing method and related equipment. Multiple nodes in the database system send transactions to each other. The update of the database on the node takes into account the transactions submitted by other databases, so as to ensure the synchronization of updates among multiple databases.
  • At least one means one or more, and “multiple” means two or more.
  • “And/or” describes the association relationship of associated objects, indicating that there can be three types of relationships, for example, A and/or B, which can mean: including the existence of A alone, the existence of A and B, and the existence of B alone, where A , B can be singular or plural.
  • the character “/” generally indicates that the contextual objects are an “or” relationship.
  • “At least one of the following” or similar expressions refer to any combination of these items, including any combination of single or plural items.
  • At least one item (piece) of a, b, or c can represent: a, b, c, a-b, a-c, b-c, or a-b-c, where a, b, c can be single or multiple .
  • a database which can also be called a data management system, is an electronic filing system that stores data in a structured manner.
  • the main storage structure in a database is a table.
  • the database system can be understood as a distributed database system, and the database system includes multiple nodes, and databases are respectively deployed on the multiple nodes. In one case, some of the multiple nodes can process read and write requests, and the other part of the nodes can only process read requests. In another case, multiple nodes can handle write requests, and the overall resource utilization in this case is high.
  • a node among multiple nodes refers to a computer or a software instance in a network involving multiple computers or a distributed system.
  • the database management system is a large-scale computer software management system designed for object database management.
  • the database processing method provided in the embodiment of the present application can be applied to MySQL, Oracle, open Gauss (openGauss), etc., and is not specifically limited here.
  • a transaction is a logical unit in the execution process of a database management system, consisting of a limited sequence of database operations.
  • An example is a transfer from a bank: a complete transaction involves debiting an amount from one account and adding an amount to another.
  • Atomicity All operations in a transaction are indivisible as a whole, either all succeed or all fail.
  • Consistency The execution result of the transaction must bring the database from one consistent state to another consistent state.
  • the consistent state refers to: 1.
  • the state of the system satisfies the data integrity constraints (master code, referential integrity, check constraints, etc.). 2.
  • the state of the system reflects the real state of the real world that the database should describe. For example, the sum of the two accounts before and after the transfer should remain unchanged.
  • Isolation Concurrently executing transactions do not affect each other and have the same impact on the database as they do serially. For example, if multiple users transfer funds to an account at the same time, the result of the final account should be the same as the result of their transfers in sequence.
  • the transaction set mentioned in the embodiment of the present application includes one transaction or multiple transactions, and one transaction includes one operation or multiple operations. Furthermore, a transaction corresponds to a timestamp or an identifier.
  • OCC Optimistic concurrency control
  • OCC is a concurrency control method applied to database management systems. OCC assumes that multiple transactions can be completed in parallel without interfering with each other. At runtime, transactions use data resources without acquiring locks on those resources. Before committing, each transaction verifies that no other transaction has modified the data it has read or modified. If the check reveals conflicting modifications, the transaction will need to be rolled back.
  • Two-phase commit refers to an algorithm designed in the field of computer networks and databases to make all nodes based on the distributed system architecture maintain consistency when committing transactions. Often, two-phase commit is also referred to as a protocol. In a distributed system, although each node can know the success or failure of its own operation, it cannot know the success or failure of other nodes' operations. When a transaction spans multiple nodes, in order to maintain the four characteristics of the transaction, it is necessary to introduce a component as a coordinator to uniformly control the operation results of all nodes (called participants) and finally instruct these nodes whether to perform the operation results The actual commit (such as writing the updated data to disk, etc.).
  • the coordinator sends preparation information (prepare) to each participant.
  • Each participant notifies the coordinator of the success or failure of the operation, and enters the state of locking transaction resources to wait for the coordinator to reply.
  • the coordinator decides whether each participant performs a commit operation (commit) or a rollback operation (rollback) based on the feedback information of all participants, and replies to each participant with the decision of the coordinator, and each participant then releases transaction resources in response to the decision, thus Ensure that the databases of all participants are consistent.
  • the embodiment of the present application provides a database processing method, through the operation set of sending transactions between multiple nodes in the database system, so that the update of the database on the node takes into account the transactions submitted by other databases, thereby ensuring Synchronization of updates between multiple 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 .
  • a node 101 is deployed with an A database, and a user of the A database is an A user.
  • the B node 102 is deployed with a B database, and a user of the B database is a B user.
  • the C database is deployed on the C node 103, 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.
  • each database stores the same data.
  • the A node 101 , the B node 102 , the C node 103 and the D node 104 communicate with each other.
  • the above-mentioned nodes can transmit the operation sets of their own nodes (also called local operation sets) to each other, and update the database of their own nodes according to the operation sets of transaction sets in other databases and the operation sets of local transaction sets received (also can be called the local database).
  • operation sets of their own nodes also called local operation sets
  • the database of their own nodes according to the operation sets of transaction sets in other databases and the operation sets of local transaction sets received (also can be called the local database).
  • the operation set in the embodiment of the present application refers to the data items modified by the node during the process of responding to user operation instructions (such as write instructions, read and write instructions, etc.), or the modified data items and the read data items.
  • the 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, thereby ensuring the synchronization between the databases.
  • each of the above nodes can provide read and write services for users.
  • each node after sending the operation set to other nodes, receives a message of successful reception sent by other nodes, and then uses the local operation set and the operation set of other nodes to update the database.
  • the four nodes shown in FIG. 1 are taken as an example. If node A sends A operation set to node B, node C and node D respectively, but only receives the successful reception message sent by node B and node C, but does not receive the successful reception message sent by node D. Node A can also use the local operation set and the operation set of other nodes to update the A database.
  • the sending node updates the local database after receiving the successful reception message sent by the receiving node, so as to ensure that the data stored in the databases of each node in the database system is consistent.
  • user A sends read and write requests to the nearest node (such as node A) for processing.
  • the nearest node such as node A
  • write requests wait for node A to complete the processing and synchronize to other nodes, and combine the operation sets of other nodes (such as transaction read and write sets) for conflict detection and conflict processing, and then return the results to the client (you can also It is understood that the result is returned after the database synchronization is successful).
  • Node A can receive user A's operation instruction for A database, and node A records user A's read in the process of executing the operation instruction. Get or modify the data item to get the A operation set of A node. After the A node obtains the A operation set, it can send the A operation set to the B node. The A node can also receive the B operation set sent by the B node (that is, the data items read and modified by the B node during the execution of the B user's operation instruction on the B database). Further, the A node can update the A database based on the A operation set and the B operation set.
  • Node B can update the B database based on the A operation set and the B operation set. And then realize the consistency between A database and B database.
  • an interaction cycle can also be set, that is, in each interaction cycle, the two nodes will exchange their own data sets, thereby realizing the synchronization between the A database and the B database.
  • the operation set in the embodiment of the present application refers to the integration of the user's operations in the process of operating the database.
  • the operation set is a read-write set or a write set, etc., which are not limited here.
  • any two users among the A user, the B user, the C user, and the D user in the embodiment of the present application may be the same user or different users, which are not specifically limited here.
  • the database system in the embodiment of the present application may include more or fewer nodes and users, and the embodiment of the present application does not limit the number of nodes and users.
  • a node in this embodiment of the present application refers to a computer or a software instance in a network involving multiple computers or a distributed system.
  • the node can be a server or a terminal device.
  • the terminal device is a device with wireless/wired transceiver functions, which can be deployed on land, including indoor or outdoor, handheld, wearable or vehicle-mounted; it can also be deployed on water ( Such as ships, etc.); can also be deployed in the air (such as aircraft, balloons and satellites, etc.).
  • the terminal device can be a mobile phone, a tablet computer (pad), a computer with a wireless transceiver function, a virtual reality (virtual reality, VR) terminal device, an augmented reality (augmented reality, AR) terminal device, an industrial control (industrial control), wireless terminals in vehicle, wireless terminals in self driving, wireless terminals in remote medical, wireless terminals in smart grid, transportation safety ), wireless terminals in a smart city, wireless terminals in a smart home, wearable terminal devices, etc.
  • the embodiments of the present application do not limit the application scenarios.
  • Terminal equipment may sometimes be called terminal, user equipment (UE), access terminal equipment, vehicle-mounted terminal, industrial control terminal, UE unit, UE station, mobile station, mobile station, remote station, remote terminal equipment, mobile device, UE proxy or UE device, etc. Terminal equipment can also be fixed or mobile.
  • the terminal device may also be a chip system for implementing UE functions.
  • an embodiment of the database processing method provided by the embodiment of the present application includes steps 201 to 206 .
  • the first node and the second node may be any two nodes in the aforementioned FIG. 1 , which are not specifically limited here.
  • the method may be executed by a communication device (such as a server or a terminal device), or may be executed by components of the communication device (such as a processor, a chip, or a chip system, etc.). It can be understood that the communication device may be a chip or a unit with a sending and receiving function or a physical device.
  • the database processing method provided in the embodiment of the present application may be applied to MySQL, Oracle, openGauss (openGauss), etc., which are not specifically limited here.
  • Step 201 the first node acquires a first operation set.
  • the first node and the second node in the embodiment of the present application can be any two nodes in the database system, the first node is deployed with the first database, the second node is deployed with the second database, and the first database and the second database Store the same data.
  • an operation set may be used to record the execution process of the database transaction. No matter how complicated the execution process of a database transaction is, the execution process of the transaction can be replayed by using the operation set, and the same execution result can be produced. Furthermore, multiple nodes can realize database synchronization by sending local operation sets to each other.
  • the operation set (including the first operation set and the second operation set) in the embodiment of the present application may include one or more transactions, and one transaction may correspond to one or more operations (eg, read, write, etc.).
  • the write operation may include adding, deleting, modifying and other operations.
  • first transaction set may be committable transactions in the first database (it can also be understood that when the number of transactions in the first transaction set is multiple, there is no conflict between multiple transactions),
  • the second transaction set may be committable transactions in the second database (it can also be understood that when the number of transactions in the second transaction set is multiple, the multiple transactions do not conflict).
  • first transaction set is all transactions in the first database
  • second transaction set is all transactions in the second database.
  • the way for the first node to obtain the first operation set is only based on the operation instructions of the first user. It can be understood that other devices can also send the first operation set to obtain the first operation set.
  • the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period.
  • 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, which is not specifically limited here.
  • the aforementioned target time period may refer to a time period.
  • the target time period in this case can be understood as the time period between the time of the last synchronization and the target time.
  • the first node may obtain the first operation set in each preset period, and periodically send the operation set to the second node.
  • the number of cycles is not limited here. For example, if one period is 10 milliseconds, the target time period may be 10 milliseconds, that is, the first node will obtain the first operation set every 10 milliseconds, and send the first operation set to the second node once.
  • the target time period may also refer to the time period from the creation time of the first database to the target time, that is, the first operation set is the write operation or the first transaction set in the first database before the target time. read and write operations.
  • the first operation set is the write operation or the first transaction set in the first database before the target time. read and write operations.
  • all the first operation sets before the target time may be sent at one time.
  • the first database may provide write services or read-write services for the first user, that is, the first user may perform a series of operations on entries in the first database in the first node, for example: write (for example: add, delete, modify), read (e.g. query), etc.
  • write for example: add, delete, modify
  • read e.g. query
  • the first node records the operations of the first user on the data items in the first database to obtain a first operation set.
  • the first node receives the first user's read and write instructions for the first database, the first node responds to the read and write instructions, performs read and write operations on entries in the first database, and executes the read and write operations During the process, the data items read and modified by the first user are recorded to obtain the first read-write set. That is, in this example, the first operation set is the read and write operation set or the write operation set of the first transaction set, which is set according to actual needs and is not limited here.
  • the first node receives a first user's write instruction to the first database, and the first node responds to the write instruction to perform a write operation on an entry in the first database, and during the process of performing the write operation, records The data item modified by the first user obtains the first write set. That is, in this example, the first operation set is the write operation set of the first transaction set.
  • the first transaction set executed by the first user in the first database includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu”.
  • Transaction 2 Change the "delivery address" of "Li Liu” to "Room 801, Hotel F, E Street, Nanshan District, Shenzhen, Guangdong province”.
  • the first operation set of the first transaction set includes: delete operation and modification operation.
  • At least one item of the first time stamp, the first identifier, or the first cycle identifier of each transaction in the first transaction set mentioned later may be referred to as first information.
  • a transaction in the first transaction set corresponds to a first timestamp or a first identifier. That is, the first timestamp and the first identifier can be used to locate a unique transaction in the first transaction set.
  • the first time stamp or the first identifier may also be used to sort the multiple transactions in the first transaction set, so as to determine the transaction to be committed or the order in which multiple transactions are committed.
  • the first node may also record the end time (which may be called the first timestamp) or the first identifier of the last operation of each transaction, which
  • the first timestamp can be the local timestamp of the first node at the end of the last operation, it can also be the logical time in the database system, or it can be the timestamp assigned by a specific central node, etc., which will not be done here limited.
  • the first identifier may be a globally unique auto-incremented transaction identifier of the database system.
  • the first node may also obtain the period identifier of each transaction.
  • the cycle number determines the order of the transactions corresponding to the commit operation set, thereby ensuring the synchronization between multiple databases.
  • the order of the transactions corresponding to the small-scale operation set can be determined first according to the period identifier, and then the order of submitting the transactions can be determined according to the timestamp or the identifier.
  • the first database connector receives the user's operation request, and after the user's operation request passes the authentication, it transmits the structured query language (structured query language, SQL) statement of the operation request to the SQL parser, Components such as the optimizer perform lexical analysis, syntax analysis, and query optimization on SQL statements.
  • SQL structured query language
  • Components such as the optimizer perform lexical analysis, syntax analysis, and query optimization on SQL statements.
  • identify the keywords and identifiers supported by the system from the query statement then define the grammar rules according to the SQL language standard, and use the words generated in the lexical analysis to match the grammar rules.
  • the query optimizer optimizes SQL through query rewriting, uses existing statement features and relational algebra operations to generate more efficient equivalent statements, and generates the final query plan based on cost estimation.
  • the first node can perform conflict detection and processing (it can also be understood as updating the database) after collecting all the operations of all nodes in the database system in the current period in each period.
  • the first information includes a first period identifier and a first time stamp.
  • the preset cycle is 50 milliseconds (ms), that is, a new synchronization cycle is generated every 50 ms.
  • Step 202 the first node sends the first operation set to the second node.
  • the second node receives the first operation set sent by the first node.
  • the first node After the first node acquires the first operation set, it may send the first operation set to the second node. Correspondingly, the second node receives the first operation set sent by the first node.
  • the number of times the first node sends the first operation set to the second node may be one or more times, that is, it may be sent in full or in batches, which is not limited here.
  • the first node may also send the first timestamp, At least one of the first identifier or the first periodic identifier.
  • the second node receives at least one of the first timestamp, the first identifier, or the first period identifier sent by the first node.
  • the first node when the end of a cycle is reached, the first node will send the first set of operations to other nodes in the database system, and eventually each node will have all transactions in the cycle
  • the collection is operated, and concurrency control can be performed according to the same rules (for example: "write first wins"), so as to ensure that the data of all nodes is consistent. It can be understood that the operation of the subsequent second node is similar to that of the first node, and will not be repeated hereafter.
  • Step 203 the second node acquires a second operation set.
  • the way the second node acquires the second operation set is similar to the way the first node acquires the first operation set. It can be obtained by means of operating a set, etc., and the details are not limited here.
  • the second operation set is the write operation or read-write operation of the second transaction set in the second database within the target time period.
  • 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, which is not specifically limited here.
  • the target time period in this step is similar to the description of the target time period in step 201 above.
  • the second node may obtain the second operation set in each preset period, and periodically send the operation set to the first node.
  • the number of cycles is not limited here. For example, if one period is 10 milliseconds, the target time period may be 10 milliseconds, that is, the second node will obtain the second operation set every 10 milliseconds, and send the second operation set to the first node once.
  • the second database is similar to the first database, and can provide write services or read-write services for the second user, that is, the second user can perform a series of operations on the entries of the second database in the second node, for example: Add, delete, modify, query, etc.
  • the second node records the second user's operations on the data items in the second database to obtain a second operation set.
  • the second node receives the second user's read and write instructions for the second database, and the second node responds to the read and write instructions, performs read and write operations on entries in the second database, and executes the read and write operations During the process, the data items read and modified by the second user are recorded to obtain the 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 here.
  • the second node receives a second user's write instruction for the second database, and the second node responds to the write instruction to perform a write operation on the entry in the second database, and during the process of performing the write operation, records The data item modified by the second user obtains the second write set. That is, in this example, the second operation set is a set of write operations of the second transaction set.
  • the second transaction set executed by the second user in the second database includes: transaction 3 .
  • Transaction 3 Add "Sunday”, “15789012345”, “No. W Primary School, Luohu District, Shenzhen City, Guangdong province”.
  • the second operation set includes: adding operation.
  • At least one of the second timestamp, the second identifier, or the second period identifier mentioned later may be referred to as second information.
  • one transaction in the second transaction set corresponds to a second timestamp or a second identifier. That is, the second timestamp and the second identifier can be used to locate a unique transaction. Further, the second time stamp or the second identifier can also be used to sort multiple transactions, so as to determine the transaction to be committed or the order in which multiple transactions are committed.
  • the second node may also record the end time (which may be called the second timestamp) or the second identifier of the last operation of each transaction, which
  • the second timestamp can be the local timestamp of the second node at the end of the last operation, it can also be the logical time in the database system, or it can be the timestamp assigned by a specific central node, etc., which will not be done here. limited.
  • the second identifier may be a globally unique auto-incremented transaction identifier of the database system.
  • the second node may also obtain the period identifier of the transaction.
  • the cycle number determines the order of the transactions corresponding to the commit operation set, thereby ensuring the synchronization between multiple databases.
  • the order of the transactions corresponding to the small-scale operation set can be determined first according to the period identifier, and then the order of submitting the transactions can be determined according to the timestamp or the identifier of the transaction.
  • Step 204 the second node sends the second operation set to the first node.
  • the first node receives the second operation set sent by the second node.
  • the second node After the second node obtains the second operation set, it may send the second operation set to the first node. Correspondingly, the first node receives the second operation set sent by the second node.
  • the number of times the first node sends the first operation set to the second node may be one or more times, that is, it may be sent in full or in batches, which is not limited here.
  • the second node may also send the second timestamp, At least one of the second identification or the second periodic identification.
  • the first node receives at least one of the second timestamp, the second identifier, or the second period identifier sent by the second node.
  • Step 205 the first node updates the first database based on 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 first determine the transaction to be submitted in the first database based on the first operation set and the second operation set, and submit the transaction to be submitted in the first database. In other words, the first node can determine the operations performed in the second database in the second node based on the second operation set, and then can execute the operations in the second operation set, so that the update of the first database has considered the modification of the second database , so as to ensure data synchronization between databases.
  • the second transaction set is committable transactions in the second database. Then when the first node updates the first database, it only needs to determine whether there is a transaction conflict between the first transaction set and the second transaction set, because between the transactions in the first transaction set or between the transactions in the second transaction set Whether there is a conflict between them has been judged locally at the respective nodes.
  • the determination of whether transactions conflict in the embodiment of the present application can be understood as determining whether each transaction is a transaction to be committed or a transaction to be rolled back.
  • the second transaction set is the transactions owned by the second database. Then, when the first node subsequently updates the first database, in addition to determining whether there is a transaction conflict between the first transaction set and the second transaction set, it is also necessary to determine whether there is a conflict between multiple transactions in the first transaction set, and whether the second transaction Whether there are conflicts between multiple transactions in the collection.
  • the first node may merge the first operation set with the second operation set, and determine which operations in the first operation set conflict with the second operation set, determine the transaction to be committed and the transaction to be rolled back, And then promote the consistency point of the database.
  • the first node obtains at least one of the first time stamp, the first identifier, or the first cycle identifier (or called first information) of each transaction in the first transaction set, and receives the information sent by the second node. At least one of the second timestamp, the second identifier, or the second periodic identifier (or referred to as second information) of the.
  • the first node may determine the 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 submit the transaction to be committed in the first database , to get the updated first database.
  • the transactions in the first transaction set and the second transaction set can be used as transactions to be committed. If there is a conflict between the transactions in the first transaction set and the second transaction set (these conflicting transactions can be called conflicting transactions), the transaction to be committed and the transaction to be rolled back in the conflicting transaction can be determined according to preset rules , and commit the transaction to be committed, and roll back the transaction to be rolled back.
  • the preset rule can be set according to actual needs, which is not specifically limited here. For example: the default rule is that the transaction with the smaller timestamp in the conflicting transactions is the transaction to be committed, or the transaction with the larger timestamp is the transaction to be committed.
  • the target sub-transaction needs to be used for conflict detection with all other remaining transactions, and the target can only be determined when it does not conflict with all other transactions Subtransactions are transactions to be committed.
  • the first transaction set includes multiple first sub-transactions
  • the second transaction set includes multiple second sub-transactions
  • if judging whether a sub-transaction 11 conflicts with a sub-transaction 12, and the sub-transaction The timestamp of 11 is greater than the timestamp of subtransaction 12.
  • the sub-transaction 11 with a larger timestamp is a transaction to be rolled back
  • the sub-transaction 12 with a smaller timestamp is not rolled back
  • the sub-transaction 12 is not necessarily a transaction to be committed.
  • whether the subtransaction 12 is a transaction to be committed can only be determined after the subtransaction 12 has been checked for conflicts with other transactions. After all transactions are compared, the transactions that are determined not to be rolled back can be committed. It can be understood that the identifications of subtransaction 11 and subtransaction 12 (ie 11 and 12 ) are just examples.
  • the first information of the first sub-transaction in the first transaction set is the first timestamp
  • the second information of the second sub-transaction in the second transaction set is the second timestamp.
  • the first sub-transaction and the second sub-transaction include at least one overlapping data item, and the first timestamp of the first sub-transaction is less than the second timestamp of the second sub-transaction, then it can be determined that the first sub-transaction does not need to be rolled back transaction, the second sub-transaction is a rollback transaction. After comparing the timestamps of the first sub-transaction with the timestamps of all other transactions, it is determined that the transaction that does not need to be rolled back is the transaction to be committed. Of course, it may also be that a transaction with a larger timestamp is a transaction that does not need to be rolled back, and a transaction with a smaller timestamp is a transaction to be rolled back.
  • the first node may also determine a commit order of transactions to be committed according to the first information and the second information. Specifically, if multiple nodes in the database system periodically send local operation sets to each other, this step may be periodic. In addition, if there are operation sets that cross cycles in multiple operation sets, for example, one operation set in the multiple operation sets is in the first cycle, and the other operation set is in the second cycle, then you can determine the commit operation through the cycle number The collection corresponds to the order of transactions, thereby ensuring synchronization between multiple databases. Certainly, if there are operation sets across periods in the multiple operation sets, there are also operation sets with the same period. In the process of updating the database, the order of the transactions corresponding to the small-scale operation set can be determined first according to the period identifier, and then the order of submitting the transactions can be determined according to the timestamp or the identifier of the transaction.
  • the first node may record a log or update a snapshot.
  • the first transaction set executed by the first user in the first database includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu”.
  • Transaction 2 Change the "delivery address" of "Li Liu” to "Room 801, Hotel F, E Street, Nanshan District, Shenzhen, Guangdong province”.
  • the first operation set of the first transaction set includes: delete operation and modification operation.
  • the second transaction set executed by the second user in the second database includes: transaction 3 .
  • Transaction 3 Add "Sunday”, "15789012345”, "No. W Primary School, Luohu District, Shenzhen City, Guangdong province”.
  • the second operation set includes: adding operation.
  • the process 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
  • the updated first database is shown in Table 2 in FIG. 4 .
  • the first node parses out the relevant data of the transaction after receiving the operation set of the transaction sent by other nodes in the current period, and uses the same rule to implement concurrency control (or It is understood as determining the transaction to be committed and the transaction to be rolled back). Commit the transaction to be committed and roll back the transaction to be rolled back. It can be understood that the operation of the subsequent second node is similar to that of the first node, and will not be repeated hereafter.
  • Step 206 the second node updates the second database based on the first operation set and the second operation set.
  • the second node may update the second database based on the first operation set and the second operation set. Specifically, the second node may first determine the transaction to be submitted in the second database based on the first operation set and the second operation set, and submit the transaction to be submitted in the second database. In other words, the second node can determine the operations performed in the first database in the first node based on the first operation set, and then can execute the operations in the first operation set, so that the update of the second database has considered the modification of the first database , so as to ensure data synchronization between databases.
  • the second node acquires at least one of the second time stamp, the second identifier, or the second periodic identifier (or called second information) of each transaction in the second transaction set, and receives the information sent by the first node. At least one of the first timestamp, the first identification, or the second period identification (or referred to as the first information) of .
  • the second node may determine the 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 submit the transaction to be committed in the second database , to obtain the updated second database.
  • the second node may record a log or update a snapshot.
  • the first transaction set includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu”.
  • Transaction 2 Change the "delivery address" of "Li Liu” to "Room 801, Hotel F, E Street, Nanshan District, Shenzhen, Guangdong province”.
  • the first operation set of the first transaction set includes: delete operation and modification operation.
  • the second set of operations includes: increment processing.
  • the second transaction includes: adding "Sunday”, “15789012345”, “No. W Primary School, Luohu District, Shenzhen City, Guangdong province”.
  • FIG. 4 the flow of updating the second database by the second node based on the first operation set and the second operation set is shown in FIG. 4
  • the updated second database is shown in Table 2 in FIG. 4 .
  • step 203 may be before step 202 or step 201 .
  • step 206 may be after step 205, etc., which is not limited here.
  • steps 201 to 206 in this step may be executed periodically, and the number of executions of steps 201 to 206 in this embodiment of the present application may be one time or multiple times, which is not specifically limited here.
  • the transactions in the new cycle cannot be committed before the synchronization of the previous cycle is completed.
  • the first node obtains the first operation set related to the first transaction set in the first database, receives the second operation set related to the second transaction set in the second database sent by the second node, and based on The first operation set and the second operation set update the first database, so that the update of the first database takes into account the transactions submitted by other databases, thereby ensuring the update synchronization between multiple databases.
  • transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small.
  • it compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
  • an embodiment of the first node in the embodiment of the present application includes:
  • An acquisition unit 501 configured to acquire a first operation set, where the first operation set is a write operation or a read-write operation of a first transaction set in the first database within a target time period;
  • a sending unit 502 configured to send the first operation set to the second node
  • the receiving unit 503 is configured to receive the second operation set sent by the second node, the second operation set is the write operation or read-write operation of the second transaction set in the second database within the target time period, the first operation set and the second The set of operations is 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.
  • each unit in the first node is similar to those described in the foregoing embodiments shown in FIG. 1 to FIG. 4 , and will not be repeated here.
  • multiple nodes in the database system send transaction operation sets to each other, and database updates on nodes take into account transactions submitted by other databases, thereby ensuring synchronization of updates between multiple databases.
  • transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small.
  • it compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
  • an embodiment of the second node in the embodiment of the present application includes:
  • An acquisition unit 601 configured to acquire a second operation set, where the second operation set is a write operation or a read-write operation of a second transaction set in the second database within a target time period;
  • a sending unit 602 configured to send the second operation set to the first node
  • the receiving unit 603 is configured to receive the first operation set sent by the first node, the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period, the first operation set and the second The operation set is used for the first node to update the first database;
  • An updating unit 604 configured to update the second database based on the first operation set and the second operation set.
  • each unit in the second node is similar to those described in the foregoing embodiments shown in FIG. 1 to FIG. 4 , and will not be repeated here.
  • multiple nodes in the database system send transaction operation sets to each other, and database updates on nodes take into account transactions submitted by other databases, thereby ensuring synchronization of updates between multiple databases.
  • transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small.
  • it compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
  • the communication device may be the first node or the second node in the foregoing embodiments shown in FIG. 1 to FIG. 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 the memory 702 .
  • the memory 702 stores program instructions and data corresponding to the steps executed by the first node in the foregoing implementations corresponding to FIG. 1 to FIG. 4 .
  • the processor 701 is configured to execute the steps performed by the first node shown in any one of the embodiments shown in FIGS. 1 to 4 .
  • the communication interface 703 may be used to execute steps related to acquiring, sending, and receiving performed by the first node in any of the embodiments shown in FIGS. 1 to 4 .
  • the communication interface 703 may be used to send a first operation set and first information, and receive a second operation set and second information.
  • the memory 702 stores program instructions and data corresponding to the steps executed by the second node in the aforementioned implementation manners corresponding to FIG. 1 to FIG. 4 .
  • the processor 701 is configured to execute the steps executed by the second node shown in any one of the embodiments shown in FIGS. 1 to 4 .
  • the communication interface 703 may be used to execute steps related to acquiring, sending, and receiving performed by the second node in any of the embodiments shown in FIGS. 1 to 4 .
  • the communication interface 703 may be used to send the second operation set and the second information, and receive the first operation set and the first information.
  • the communication device may include more or less components than those shown in FIG. 7 , and this application is only illustrative and not limiting.
  • an embodiment of the present application provides a database system, and the database system includes the first node as shown in FIG. 5 and/or the second node as shown in FIG. 6 .
  • the database system includes the communication device as shown in FIG. 7 above.
  • the disclosed system, device and method can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units may be fully or partially realized by software, hardware, firmware or any combination thereof.
  • the integrated units When the integrated units are implemented using software, they may be implemented in whole or in part in the form of a computer program product.
  • the computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, all or part of the processes or functions according to the embodiments of the present invention will be generated.
  • the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website, computer, server or data center Transmission to another website site, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.).
  • the computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or a data center integrated with one or more available media.
  • the available medium may be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (solid state disk, SSD)), etc.

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

Disclosed in the embodiments of the present application is a database processing method. The method is applied to a database system. The database system comprises a first node and a second node, wherein the first node and the second node are respectively deployed with a first database and a second database, which store the same data. The method comprises: acquiring a first operation set; sending the first operation set to a second node; receiving a second operation set, which is sent by the second node, wherein the first operation set and the second operation set are used for the second node to update a second database; and updating the first database on the basis of the first operation set and the second operation set. Operation sets of transactions are mutually sent between a plurality of nodes in a database system, such that the transactions, which are submitted by other databases, are taken into consideration during the update of databases on the nodes, thereby ensuring the update synchronization between a plurality of databases.

Description

一种数据库处理方法及相关设备A database processing method and related equipment
本申请要求于2021年12月31日提交中国专利局、申请号为202111679433.0、发明名称为“一种数据库处理方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202111679433.0 and the title of the invention "a database processing method and related equipment" submitted to the China Patent Office on December 31, 2021, the entire contents of which are incorporated by reference in this application middle.
技术领域technical field
本申请涉及数据库技术领域,尤其涉及一种数据库处理方法及相关设备。The present application relates to the technical field of databases, in particular to a database processing method and related equipment.
背景技术Background technique
随着互联网的快速发展,软件系统由原来的单体应用转变为分布式应用。分布式系统会把一个应用系统拆分为可独立部署的多个服务,因此需要服务与服务之间远程协作才能完成事务操作,这种分布式系统环境下由不同的服务之间通过网络远程协作完成事务称之为分布式事务,例如用户注册送积分事务、创建订单减库存事务,银行转账事务等都是分布式事务。在分布式系统中,各个节点之间在物理上相互独立,通过网络进行沟通和协调。由于存在事务机制,可以保证每个独立节点上的数据操作可以满足ACID。但是,如果想让分布式部署的多台机器中的数据保持一致性,那么就要保证在所有节点的数据写操作,要不全部都执行,要么全部的都不执行。但是,一台机器在执行本地事务的时候无法知道其他机器中的本地事务的执行结果。所以他也就不知道本次事务到底应该commit还是roolback。With the rapid development of the Internet, the software system has changed from the original single application to distributed application. A distributed system will split an application system into multiple services that can be deployed independently, so remote collaboration between services is required to complete transaction operations. In this distributed system environment, different services collaborate remotely through the network Completing a transaction is called a distributed transaction, such as user registration to send points, create an order to reduce inventory, and bank transfer transactions are all distributed transactions. In a distributed system, each node is physically independent from each other and communicates and coordinates through the network. Due to the existence of the transaction mechanism, it can be guaranteed that the data operation on each independent node can satisfy ACID. However, if you want to keep the data in multiple machines in a distributed deployment consistent, then you must ensure that all data write operations on all nodes are executed, or all of them are executed, or none of them are executed. However, when a machine executes a local transaction, it cannot know the execution result of the local transaction in other machines. So he doesn't know whether this transaction should be committed or roolbacked.
目前,常规的解决办法就是引入一个“协调者”的组件来统一调度所有分布式节点的执行,也可以称为二阶段提交方法。二阶段提交方法的思路可以概括为:协调者向各参与者发送准备信息(prepare)。各参与者将操作成败通知协调者,并进入锁定事务资源的状态中等待协调者回复。协调者根据所有参与者的反馈情报决定各参与者执行提交操作(commit)还是回滚操作(rollback),并向各参与者回复协调者的决定,各参与者再释放事务资源响应该决定,从而保证各参与者的数据库一致。At present, the conventional solution is to introduce a "coordinator" component to uniformly schedule the execution of all distributed nodes, which can also be called a two-phase commit method. The idea of the two-phase commit method can be summarized as follows: the coordinator sends preparation information (prepare) to each participant. Each participant notifies the coordinator of the success or failure of the operation, and enters the state of locking transaction resources to wait for the coordinator to reply. The coordinator decides whether each participant performs a commit operation (commit) or a rollback operation (rollback) based on the feedback information of all participants, and replies to each participant with the decision of the coordinator, and each participant then releases transaction resources in response to the decision, thus Ensure that the databases of all participants are consistent.
然而,一方面,协调者与各参与者之间有三次交互,通信开销较大。另一方面,由于协调者的重要性,一旦协调者发生故障。所有的参与者还都处于锁定事务资源的状态中,而无法继续完成事务操作。However, on the 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 still in the state of locking transaction resources, and cannot continue to complete transaction operations.
发明内容Contents of the invention
本申请实施例提供了一种数据库处理方法及相关设备。数据库系统中的多个节点之间互相发送事务的操作集合,节点上数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。Embodiments of the present application provide a database processing method and related equipment. Multiple nodes in the database system send transactions to each other. The update of the database on the node takes into account the transactions submitted by other databases, so as to ensure the synchronization of updates among multiple databases.
本申请实施例第一方面提供了一种数据库处理方法,该方法应用于数据库系统,数据库系统包括第一节点与第二节点,第一节点部署有第一数据库,第二节点部署有第二数据库,第一数据库与第二数据库存储有相同的数据,该方法可以由第一节点执行,也可以由第一节点的部件(例如处理器、芯片、或芯片系统等)执行。方法包括:第一节点获取第一操作集合,第一操作集合为在目标时间段内第一数据库中第一事务集合的写操作或读写操作;第一 节点向第二节点发送第一操作集合;第一节点接收第二节点发送的第二操作集合,第二操作集合为在目标时间段内第二数据库中第二事务集合的写操作或读写操作,第一操作集合与第二操作集合用于第二节点更新第二数据库;第一节点基于第一操作集合与第二操作集合更新第一数据库。The first aspect of the embodiment of the present application provides a database processing method, 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 the first database, and the second node is deployed with the second database , 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 components of the first node (such as a processor, a chip, or a chip system, etc.). The method includes: the first node obtains a first operation set, and the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period; the first node sends the first operation set to the second node ; The first node receives the second operation set sent by the second node, the second operation set is the write operation or read-write operation of the second transaction set in the second database within the target time period, the first operation set and the second operation set Used for the second node to update the second database; the first node to update the first database based on the first operation set and the second operation set.
本申请实施例中,数据库系统中的多个节点之间互相发送事务的操作集合,节点上数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。一方面,事务修改通过传输操作集合的方式在节点之间互相通知,不涉及节点之间的多次交互,通信开销小。另一方面,相较于二阶段提交方法,避免了协调者由于单点故障导致的事务无法操作。In the embodiment of the present application, multiple nodes in the database system send transaction operation sets to each other, and the update of the database on the node takes into account the transactions submitted by other databases, so as to ensure the update synchronization among multiple databases. On the one hand, transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small. On the other hand, compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
可选地,在第一方面的一种可能的实现方式中,上述步骤:第一节点获取第一操作集合,包括:第一节点响应并执行第一用户对于第一数据库的操作指令;第一节点在执行操作指令的过程中记录第一用户对第一数据库中数据项的操作,得到第一操作集合。Optionally, in a possible implementation manner of the first aspect, the above step: the first node acquires the first operation set includes: the first node responds to and executes the first user's operation instruction on the first database; the first During the process of executing the operation instruction, the node records the operation of the first user on the data items in the first database to obtain the first operation set.
该种可能的实现方式中,节点在执行用户对于数据库的操作指令的过程中,记录第一用户对于数据库中数据项的操作,得到操作集合。从而可以根据该操作集合还原出用户对于数据库的操作,进而为后续数据库同步提供依据。In this possible implementation manner, during the process of executing the user's operation instruction on the database, the node records the first user's operation on the data items in the database to obtain an operation set. Therefore, the user's operations on the database can be restored according to the operation set, thereby providing a basis for subsequent database synchronization.
可选地,在第一方面的一种可能的实现方式中,上述的操作指令为写指令,第一操作集合为写操作集合;或者,操作指令为读写指令,第一操作集合为读写操作集合或写操作集合。Optionally, in a possible implementation of the first aspect, the above-mentioned operation instruction is a write instruction, and the first operation set is a write operation set; or, the operation instruction is a read and write instruction, and the first operation set is a read and write A collection of operations or a collection of write operations.
该种可能的实现方式中,写指令对应的操作集合为写操作集合,读写指令对应的操作集合为读写操作集合或写操作集合,具体可以根据业务需要设置,此处不做限定。通过操作集合可以记录用户对于数据库的操作,实现用户操作的重演。In this possible implementation, the operation set corresponding to the write command is the write operation set, and the operation set corresponding to the read and write commands is the read and write operation set or the write operation set, which can be set according to business needs, and is not limited here. The user's operation on the database can be recorded through the operation set, and the replay of the user's operation can be realized.
可选地,在第一方面的一种可能的实现方式中,上述步骤还包括:第一节点获取第一事务集合的第一信息,第一事务集合中每一个事务对应一个第一信息,第一信息包括第一标识,和/或第一时间戳;第一节点向第二节点发送第一信息;第一节点接收第二节点发送的第二信息,第二事务集合中每一个事务对应一个第二信息,第二信息包括第二标识,和/或第二时间戳;第一信息与第二信息用于第二节点更新第二数据库;第一节点基于第一操作集合与第二操作集合更新第一数据库,包括:第一节点基于第一操作集合、第一信息、第二操作集合以及第二信息更新第一数据库。Optionally, in a possible implementation manner of the first aspect, the above steps further include: the first node acquires the first information of the first transaction set, each transaction in the first transaction set corresponds to a first information, and the first A message includes a first identifier and/or a first timestamp; the first node sends the first message to the second node; the first node receives the second message sent by the second node, and each transaction in the second transaction set corresponds to a The second information, the second information includes the second identification, and/or the second time stamp; the first information and the second information are used for the second node to update the second database; the first node is based on the first operation set and the second operation set Updating the first database includes: the first node updating the first database based on the first operation set, the first information, the second operation set, and the second information.
该种可能的实现方式中,节点之间除了交互事务的操作集合之外,还可以交互事务的时间戳或标识,可以使得后续使用第一事务集合与第二事务集合更新数据库的时候,可以通过时间戳或标识确定需要提交的事务,以及提交事务的顺序。通过第一信息与第二信息可以快速确定冲突的事务,进而提升后续更新数据库的速度。In this possible implementation, in addition to the operation set of the interactive transaction, the nodes can also interact with the timestamp or identification of the transaction, so that when the database is updated using the first transaction set and the second transaction set, it can be passed Timestamps or identifiers identify which transactions need to be committed, and the order in which they are committed. Conflicting transactions can be quickly determined through the first information and the second information, thereby increasing the speed of subsequent database updates.
可选地,在第一方面的一种可能的实现方式中,上述步骤:第一节点基于第一操作集合、第一信息、第二操作集合以及第二信息更新第一数据库,包括:第一节点基于第一操作集合、第一信息、第二操作集合以及第二信息确定第一事务集合与第二事务集合中待提交的事务;第一节点在第一数据库中提交待提交的事务,得到更新后的第一数据库。Optionally, in a possible implementation manner of the first aspect, the above step: the first node updates the first database based on the first operation set, the first information, the second operation set, and the second information includes: first The node determines the 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 first node submits the transaction to be committed in the first database, and obtains Updated first database.
该种可能的实现方式中,节点在使用第一事务集合与第二事务集合更新第一数据库的时候,可以通过第一时间戳或第一标识确定需要提交的事务,以及提交事务的顺序。通过第一信息与第二信息可以快速确定冲突的事务,进而提升后续更新第一数据库的速度。In this possible implementation, when the node uses the first transaction set and the second transaction set to update the first database, it can use the first timestamp or the first identification to determine the transactions to be submitted and the order of submitting the transactions. Conflicting transactions can be quickly determined through the first information and the second information, thereby increasing the speed of subsequent updating of the first database.
可选地,在第一方面的一种可能的实现方式中,上述的第一事务集合中第一子事务的第一信息为第一时间戳,第二事务集合中第二子事务的第二信息为第二时间戳,第一子事务与第二子事务至少包括重叠的一个数据项,第一时间戳小于第二时间戳,第二子事务为不能提交的事务。这里确定时间戳较大的事务为不能提交的事务,可以理解的是,也可以确定时间戳较小的事务为不能提交的事务,具体规则可以根据实际需要设置,此处不做限定。Optionally, in a possible implementation of the first aspect, the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp, and the second information of the second sub-transaction in the second transaction set The information is a second timestamp, the first sub-transaction and the second sub-transaction include at least 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. Here, a transaction with a larger timestamp is determined as a transaction that cannot be committed. It is understandable that a transaction with a smaller timestamp can also be determined as a transaction that cannot be committed. The specific rules can be set according to actual needs, and there is no limitation here.
该种可能的实现方式中,通过确定时间戳较大的事务为不能提交的事务,通过该规则可以确定第一事务集合与第二事务集合中哪些事务可以提交或不能提交,在所有事务比对结束后,可以提交待提交的事务,回滚不能提交的事务,进而实现数据库的更新。In this possible implementation, by determining the transaction with a larger timestamp as a transaction that cannot be committed, this rule can determine which transactions in the first transaction set and the second transaction set can be committed or cannot be committed, and compare all transactions After the end, you can submit the transaction to be submitted, roll back the transaction that cannot be submitted, and then realize the update of the database.
本申请实施例第二方面提供了一种数据库处理方法,该方法应用于数据库系统,数据库系统包括第一节点与第二节点,第一节点部署有第一数据库,第二节点部署有第二数据库,第一数据库与第二数据库存储有相同的数据,该方法可以由第二节点执行,也可以由第二节点的部件(例如处理器、芯片、或芯片系统等)执行。方法包括:第二节点获取第二操作集合,第二操作集合为在目标时间段内第二数据库中第二事务集合的写操作或读写操作;第二节点向第一节点发送第二操作集合;第二节点接收第一节点发送的第一操作集合,第一操作集合为在目标时间段内第一数据库中第一事务集合的写操作或读写操作,第一操作集合与第二操作集合用于第一节点更新第二数据库;第二节点基于第一操作集合与第二操作集合更新第二数据库。The second aspect of the embodiment of the present application provides a database processing method. 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 the first database, and the second node is deployed with the second database. , 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 components of the second node (such as a processor, a chip, or a chip system, etc.). The method includes: the second node obtains a second operation set, and the second operation set is a write operation or a read-write operation of a second transaction set in the second database within a target time period; the second node sends the second operation set to the first node ; The second node receives the first operation set sent by the first node, the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period, the first operation set and the second operation set The first node updates the second database; the second node updates the second database based on the first operation set and the second operation set.
可选地,在第二方面的一种可能的实现方式中,上述步骤:第二节点获取第二操作集合,包括:第二节点响应并执行第二用户对于第二数据库的操作指令;第二节点在执行操作指令的过程中记录第二用户对第二数据库中数据项的操作,得到第二操作集合。Optionally, in a possible implementation of the second aspect, the above step: the second node acquires the second operation set includes: the second node responds to and executes the second user's operation instruction on the second database; the second During the process of executing the operation instruction, the node records the second user's operation on the data item in the second database, and obtains the second operation set.
可选地,在第二方面的一种可能的实现方式中,上述的操作指令为写指令,第二操作集合为写操作集合;或者,操作指令为读写指令,第二操作集合为读写操作集合或写操作集合。Optionally, in a possible implementation of the second aspect, the above-mentioned operation instruction is a write instruction, and the second operation set is a write operation set; or, the operation instruction is a read and write instruction, and the second operation set is a read and write operation A collection of operations or a collection of write operations.
可选地,在第二方面的一种可能的实现方式中,上述步骤还包括:第二节点获取第二事务集合的第二信息,第二事务集合中每一个事务对应一个第二信息,第二信息包括第二标识,和/或第二时间戳;第二节点向第一节点发送第二信息;第二节点接收第一节点发送的第一信息,第一事务集合中每一个事务对应一个第一信息,第一信息包括第一标识,和/或第一时间戳;第一信息与第二信息用于第一节点更新第二数据库;第二节点基于第一操作集合与第二操作集合更新第二数据库,包括:第二节点基于第一操作集合、第一信息、第二操作集合以及第二信息更新第二数据库。Optionally, in a possible implementation manner of the second aspect, the above steps further include: the second node acquires second information of a second transaction set, each transaction in the second transaction set corresponds to a second information, and the second The second information includes the second identification, and/or the second timestamp; the second node sends the second information to the first node; the second node receives the first information sent by the first node, and each transaction in the first transaction set corresponds to a The first information, the first information includes the first identification, and/or the first time stamp; the first information and the second information are used for the first node to update the second database; the second node is based on the first operation set and the second operation set Updating the second database includes: updating the second database by the second node 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 second aspect, the above step: the second node updates the second database based on the first operation set, the first information, the second operation set, and the second information includes: the second The node determines the 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 second node submits the transaction to be committed in the second database, and obtains Updated second database.
可选地,在第二方面的一种可能的实现方式中,上述的第一事务集合中第一子事务的第一信息为第一时间戳,第二事务集合中第二子事务的第二信息为第二时间戳,第一子事务与第二子事务至少包括重叠的一个数据项,第一时间戳小于第二时间戳,第二子事务为不能提交的事务。Optionally, in a possible implementation of the second aspect, the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp, and the second information of the second sub-transaction in the second transaction set The information is a second timestamp, the first sub-transaction and the second sub-transaction include at least 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 third aspect of the embodiment of the present application provides a first node, 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, and 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: an acquisition unit configured to acquire a first operation set, where the first operation set is a write operation of a first transaction set in the first database within a target time period Or read and write operations; the sending unit is used to send the first operation set to the second node; the receiving unit is used to receive the second operation set sent by the second node, and the second operation set is in the second database within the target time period The write operation or read-write operation of the second transaction set, the first operation set and the second operation set are used for the second node to update the second database; the update 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 above-mentioned obtaining unit is specifically configured to respond to and execute an operation instruction of the first user on the first database; the obtaining unit is specifically configured to During the process, the first user's operations on the data items in the first database are recorded to obtain a first operation set.
可选地,在第三方面的一种可能的实现方式中,上述的操作指令为写指令,第一操作集合为写操作集合;或者,操作指令为读写指令,第一操作集合为读写操作集合或写操作集合。Optionally, in a possible implementation of the third aspect, the above-mentioned operation instruction is a write instruction, and the first operation set is a write operation set; or, the operation instruction is a read and write instruction, and the first operation set is a read and write operation set A collection of operations or a collection of write operations.
可选地,在第三方面的一种可能的实现方式中,上述的获取单元,还用于获取第一事务集合的第一信息,第一事务集合中每一个事务对应一个第一信息,第一信息包括第一标识,和/或第一时间戳;发送单元,还用于向第二节点发送第一信息;接收单元,还用于接收第二节点发送的第二信息,第二事务集合中每一个事务对应一个第二信息,第二信息包括第二标识,和/或第二时间戳;第一信息与第二信息用于第二节点更新第二数据库;更新单元,具体用于基于第一操作集合、第一信息、第二操作集合以及第二信息更新第一数据库。Optionally, in a possible implementation manner of the third aspect, the above-mentioned acquisition unit is further configured to acquire first information of a first transaction set, each transaction in the first transaction set corresponds to a first information, and the first A piece of information includes a first identifier and/or a first time stamp; a sending unit is also used to send the first information to the second node; a receiving unit is also used to receive the second information sent by the second node, and the second transaction set Each transaction corresponds to a 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 the second node to update the second database; the update unit is specifically used for The first set of operations, the first information, the second set of operations, and the second information update the first database.
可选地,在第三方面的一种可能的实现方式中,上述的更新单元,具体用于基于第一操作集合、第一信息、第二操作集合以及第二信息确定第一事务集合与第二事务集合中待提交的事务;更新单元,具体用于在第一数据库中提交待提交的事务,得到更新后的第一数据库。Optionally, in a possible implementation manner of the third aspect, the above update unit is specifically configured to determine 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. Two transactions to be submitted in the transaction set; an updating unit, specifically configured to submit the transactions to be submitted in the first database to obtain an updated first database.
可选地,在第三方面的一种可能的实现方式中,上述的第一事务集合中第一子事务的第一信息为第一时间戳,第二事务集合中第二子事务的第二信息为第二时间戳,第一子事务与第二子事务至少包括重叠的一个数据项,第一时间戳小于第二时间戳,第二子事务为不能提交的事务。Optionally, in a possible implementation of the third aspect, the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp, and the second information of the second sub-transaction in the second transaction set The information is a second timestamp, the first sub-transaction and the second sub-transaction include at least 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 fourth aspect of the embodiment of the present application provides a second node, 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, and 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: an acquisition unit, configured to acquire a second operation set, where the second operation set is a write operation of a second transaction set in the second database within a target time period Or read and write operations; the sending unit is used to send the second operation set to the first node; the receiving unit is used to receive the first operation set sent by the first node, the first operation set is in the first database within the target time period The write operation or read-write operation of the first transaction set, the first operation set and the second operation set are used for the first node to update the first database; the update 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 above-mentioned 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 During the process, the second user's operations on the data items in the second database are recorded to obtain a second operation set.
可选地,在第四方面的一种可能的实现方式中,上述的操作指令为写指令,第二操作集合为写操作集合;或者,操作指令为读写指令,第二操作集合为读写操作集合或写操作集合。Optionally, in a possible implementation of the fourth aspect, the above-mentioned operation instruction is a write instruction, and the second operation set is a write operation set; or, the operation instruction is a read and write instruction, and the second operation set is a read and write operation A collection of operations or a collection of write operations.
可选地,在第四方面的一种可能的实现方式中,上述的获取单元,还用于获取第二事务集合的第二信息,第二事务集合中每一个事务对应一个第二信息,第二信息包括第二标识,和/或第二时间戳;发送单元,还用于向第一节点发送第二信息;接收单元,还用于接收第一节点发送的第一信息,第一事务集合中每一个事务对应一个第一信息,第一信息包括第一标识,和/或第一时间戳;第一信息与第二信息用于第一节点更新第一数据库;更新单元,具体用于基于第一操作集合、第一信息、第二操作集合以及第二信息更新第二数据库。Optionally, in a possible implementation manner of the fourth aspect, the above-mentioned acquiring unit is further configured to acquire second information of a second transaction set, each transaction in the second transaction set corresponds to a second information, and the first The second information includes the second identification, and/or the second timestamp; the sending unit is also used to send the second information to the first node; the receiving unit is also used to receive the first information sent by the first node, the first transaction set Each transaction corresponds to a first information, the first information includes the first identification, and/or the first timestamp; the first information and the second information are used for the first node to update the first database; the update unit is specifically used for The first set of operations, the first information, the second set of operations, and the second information update the second database.
可选地,在第四方面的一种可能的实现方式中,上述的更新单元,具体用于基于第一操作集合、第一信息、第二操作集合以及第二信息确定第一事务集合与第二事务集合中待提交的事务;更新单元,具体用于在第二数据库中提交待提交的事务,得到更新后的第二数据库。Optionally, in a possible implementation manner of the fourth aspect, the above update unit is specifically configured to determine 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. Transactions to be submitted in the transaction set; an updating unit, specifically configured to submit the transactions to be submitted in the second database to obtain an updated second database.
可选地,在第四方面的一种可能的实现方式中,上述的第一事务集合中第一子事务的第一信息为第一时间戳,第二事务集合中第二子事务的第二信息为第二时间戳,第一子事务与第二子事务至少包括重叠的一个数据项,第一时间戳小于第二时间戳,第二子事务为不能提交的事务。Optionally, in a possible implementation of the fourth aspect, the first information of the first sub-transaction in the above-mentioned first transaction set is the first timestamp, and the second information of the second sub-transaction in the second transaction set The information is a second timestamp, the first sub-transaction and the second sub-transaction include at least 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 the embodiments of the present application provides a first node, where the first node is configured to execute the method in 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, where the second node is configured to execute the method in the foregoing second aspect or any possible implementation manner of the second aspect.
本申请实施例第七方面提供了一种数据库系统,包括前述第三方面或第五方面的第一节点,和/或前述第四方面或第六方面的第二节点。The seventh aspect of the embodiment of the present application provides a database system, including the first node of the aforementioned third aspect or the fifth aspect, and/or the second node of the aforementioned fourth aspect or the sixth aspect.
本申请实施例第八方面提供一种芯片,该芯片包括处理器与数据接口,其中,处理器通过该数据接口读取存储器上存储的指令,以执行第一方面或第一方面任意一种可能的实现方式中的方法;或者以执行第二方面或第二方面任意一种可能的实现方式中的方法。在具体实现过程中,该芯片可以以中央处理器(central processing unit,CPU)、微控制器(micro controller unit,MCU)、微处理器(micro processing unit,MPU)、数字信号处理器(digital signal processing,DSP)、片上系统(system on chip,SoC)、专用集成电路(application-specific integrated circuit,ASIC)、现场可编程门阵列(field programmable gate array,FPGA)或可编辑逻辑器件(programmable logic device,PLD)的形式实现。The eighth aspect of the embodiment of the present application provides a chip, the chip includes a processor and a data interface, wherein the processor reads the instructions stored in the memory through the data interface to execute any one of the first aspect or the first aspect. or to execute the method in the second aspect or any possible implementation manner of the second aspect. In the specific implementation process, the chip can be based on a central processing unit (CPU), a microcontroller (micro controller unit, MCU), a microprocessor (micro processing unit, MPU), a 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) in the form of realization.
本申请实施例第九方面提供了一种计算机可读介质,该计算机可读介质存储有程序代码,当该计算机程序代码在计算机上运行时,使得计算机执行上述第一方面或第一方面的任一种可能执行的方法;使得计算机执行上述第二方面或第二方面的任一种可能执行的方法。这些计算机可读存储包括但不限于如下的一个或者多个:只读存储器(read-only memory,ROM)、可编程ROM(programmable ROM,PROM)、可擦除的PROM(erasable PROM,EPROM)、Flash存储器、电EPROM(electrically EPROM,EEPROM)以及硬盘驱动器(hard drive)。The ninth aspect of the embodiment of the present application provides a computer-readable medium, the computer-readable medium stores program codes, and when the computer program codes run on the computer, the computer executes the above-mentioned first aspect or any of the first aspects. A possible execution method; causing a computer to execute the above second aspect or any possible execution method of the second aspect. These computer-readable storages include, but are not limited to, one or more of the following: read-only memory (read-only memory, ROM), programmable ROM (programmable ROM, PROM), erasable PROM (erasable PROM, EPROM), Flash memory, electrical EPROM (electrically EPROM, EEPROM) and hard drive (hard drive).
本申请实施例第十方面提供了一种计算机程序产品,该计算机程序产品在计算机上执行时,使得计算机执行前述第一方面或第一方面的任意可能的实现方式中的方法;或者使得计算机执行前述第二方面或第二方面的任意可能的实现方式中的方法。The tenth aspect of the embodiments of the present application provides a computer program product. When the computer program product is executed on a computer, it causes the computer to execute the method in the aforementioned first aspect or any possible implementation of the first aspect; or causes the computer to execute The aforementioned second aspect or the method in any possible implementation of the second aspect.
其中,第二方面至第十方面或者其中任一种可能实现方式所带来的技术效果可参见第一 方面或第一方面不同可能实现方式所带来的技术效果,此处不再赘述。Wherein, the technical effects brought about by the second aspect to the tenth aspect or any one of the possible implementations can refer to the first aspect or the technical effects brought about by different possible implementations of the first aspect, and will not be repeated here.
从以上技术方案可以看出,本申请实施例具有以下优点:第一节点获取与第一数据库中第一事务集合相关的第一操作集合,接收第二节点发送的第二数据库中与第二事务集合相关的第二操作集合,并基于第一操作集合与第二操作集合更新第一数据库,使得第一数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。一方面,事务修改通过传输操作集合的方式在节点之间互相通知,不涉及节点之间的多次交互,通信开销小。另一方面,相较于二阶段提交方法,避免了协调者由于单点故障导致的事务无法操作。It can be seen from the above technical solutions that the embodiment of the present application has the following advantages: the first node obtains the first operation set related to the first transaction set in the first database, and receives the second transaction in the second database sent by the second node. Collect the related second operation set, and update the first database based on the first operation set and the second operation set, so that the update of the first database takes into account the transactions submitted by other databases, thereby ensuring the update synchronization between multiple databases. On the one hand, transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small. On the other hand, compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
附图说明Description of drawings
图1为本发明实施例提供的一种数据库系统架构示意图;FIG. 1 is a schematic diagram of a database system architecture provided by an embodiment of the present invention;
图2为本申请实施例提供的数据库处理方法的流程示意图;FIG. 2 is a schematic flow diagram of a database processing method provided in an embodiment of the present application;
图3为本申请实施例提供的第一数据库与第二数据库的一种示例图;FIG. 3 is an example diagram of the first database and the second database provided by the embodiment of the present application;
图4为本申请实施例提供的一种更新第一数据库与第二数据库的流程示意图;FIG. 4 is a schematic flow diagram of updating the first database and the second database provided by the embodiment of the present application;
图5为本申请实施例提供的第一节点的一个结构示意图;FIG. 5 is a schematic structural diagram of the first node provided by the embodiment of the present application;
图6为本申请实施例提供的第二节点的一个结构示意图;FIG. 6 is a schematic structural diagram of a second node provided by an embodiment of the present application;
图7为本申请实施例提供的通信设备的一个结构示意图。FIG. 7 is a schematic structural diagram of a communication device provided by an embodiment of the present application.
具体实施方式Detailed ways
本申请实施例提供了一种数据库处理方法及相关设备。数据库系统中的多个节点之间互相发送事务的操作集合,节点上数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。Embodiments of the present application provide a database processing method and related equipment. Multiple nodes in the database system send transactions to each other. The update of the database on the node takes into account the transactions submitted by other databases, so as to ensure the synchronization of updates among multiple databases.
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获取的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
另外,在本申请实施例中,“示例的”、“例如”等词用于表示作例子、例证或说明。本申请中被描述为“示例”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更优选或更具优势。确切而言,使用示例的一词旨在以具体方式呈现概念。In addition, in the embodiments of the present application, words such as "exemplary" and "for example" are used as examples, illustrations or explanations. Any embodiment or design described herein as "example" is not to be construed as preferred or advantageous over other embodiments or designs. Rather, the use of the word example is intended to present concepts in a concrete manner.
本申请中,“至少一个”是指一个或者多个,“多个”是指两个或两个以上。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:包括单独存在A,存在A和B,以及单独存在B的情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指的这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b,或c中的至少一项(个),可以表示:a,b,c,a-b,a-c,b-c,或a-b-c,其中a,b,c可以是单个,也可以是多个。In this application, "at least one" means one or more, and "multiple" means two or more. "And/or" describes the association relationship of associated objects, indicating that there can be three types of relationships, for example, A and/or B, which can mean: including the existence of A alone, the existence of A and B, and the existence of B alone, where A , B can be singular or plural. The character "/" generally indicates that the contextual objects are an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one item (piece) of a, b, or c can represent: a, b, c, a-b, a-c, b-c, or a-b-c, where a, b, c can be single or multiple .
为了便于理解,下面先对本申请实施例主要涉及的相关术语和概念进行介绍。For ease of understanding, the relevant terms and concepts mainly involved in the embodiments of the present application are firstly introduced below.
1、数据库1. Database
数据库,也可以称为数据管理系统,是以结构化的方式存储数据的电子归档系统。数据库中主要的存储结构是一个表。A database, which can also be called a data management system, is an electronic filing system that stores data in a structured manner. The main storage structure in a database is a table.
2、数据库系统2. Database system
数据库系统可以理解为是分布式数据库系统,该数据库系统包括多个节点,多个节点上分别部署有数据库。一种情况,多个节点中的一部分节点可以处理读写请求,另一部分节点只能处理读请求。另一种情况,多个节点都能处理写请求,该种情况下的整体资源利用率高。其中,多个节点中的节点是指涉及多台计算机的网络或者分布式系统中的一台计算机或者软件实例。The database system can be understood as a distributed database system, and the database system includes multiple nodes, and databases are respectively deployed on the multiple nodes. In one case, some of the multiple nodes can process read and write requests, and the other part of the nodes can only process read requests. In another case, multiple nodes can handle write requests, and the overall resource utilization in this case is high. Wherein, a node among multiple nodes refers to a computer or a software instance in a network involving multiple computers or a distributed system.
3、数据库管理系统(database management system,DBMS)3. Database management system (DBMS)
数据库管理系统是一种针对对象数据库,为管理数据库而设计的大型电脑软件管理系统。本申请实施例提供的数据库处理方法可以应用于MySQL、Oracle、开源高斯(openGauss)等,具体此处不做限定。The database management system is a large-scale computer software management system designed for object database management. The database processing method provided in the embodiment of the present application can be applied to MySQL, Oracle, open Gauss (openGauss), etc., and is not specifically limited here.
4、数据库事务(或简称为事务)4. Database transactions (or transactions for short)
事务是数据库管理系统执行过程中的一个逻辑单位,由一个有限的数据库操作序列构成。例如从银行转账:完整的事务需要从一个账户扣除金额,并向另一个账户增加金额。A transaction is a logical unit in the execution process of a database management system, consisting of a limited sequence of database operations. An example is a transfer from a bank: a complete transaction involves debiting an amount from one account and adding an amount to another.
事务执行成功后需要“提交”(commit),提交成功后修改就会生效并且不能丢失。事务执行失败(abort)则需要“回滚”(rollback),其修改都不会生效。After the transaction is successfully executed, a "commit" is required. After the commit is successful, the modification will take effect and cannot be lost. If the transaction execution fails (abort), it needs to be "rolled back" (rollback), and its modification will not take effect.
事务具备以下四个特性:Transactions have the following four characteristics:
原子性(atomicity):事务中的所有操作作为一个整体像原子一样不可分割,要么全部成功,要么全部失败。Atomicity: All operations in a transaction are indivisible as a whole, either all succeed or all fail.
一致性(consistency):事务的执行结果必须使数据库从一个一致性状态到另一个一致性状态。一致性状态是指:1、系统的状态满足数据的完整性约束(主码,参照完整性,check约束等)。2、系统的状态反应数据库本应描述的现实世界的真实状态,比如转账前后两个账户的金额总和应该保持不变。Consistency: The execution result of the transaction must bring the database from one consistent state to another consistent state. The consistent state refers to: 1. The state of the system satisfies the data integrity constraints (master code, referential integrity, check constraints, etc.). 2. The state of the system reflects the real state of the real world that the database should describe. For example, the sum of the two accounts before and after the transfer should remain unchanged.
隔离性(isolation):并发执行的事务不会相互影响,其对数据库的影响和它们串行执行时一样。比如多个用户同时往一个账户转账,最后账户的结果应该和他们按先后次序转账的结果一样。Isolation: Concurrently executing transactions do not affect each other and have the same impact on the database as they do serially. For example, if multiple users transfer funds to an account at the same time, the result of the final account should be the same as the result of their transfers in sequence.
持久性(durability):事务一旦提交,其对数据库的更新就是持久的。任何事务或系统故障都不会导致数据丢失。Durability: Once a transaction is committed, its updates to the database are durable. No transaction or system failure will result in data loss.
5、事务集合5. Transaction collection
本申请实施例所提的事务集合包括一个事务或多个事务,一个事务包括一个操作或多个操作。进一步的,一个事务对应一个时间戳或一个标识。The transaction set mentioned in the embodiment of the present application includes one transaction or multiple transactions, and one transaction includes one operation or multiple operations. Furthermore, a transaction corresponds to a timestamp or an identifier.
6、乐观并发控制(optimistic concurrency control,OCC)6. Optimistic concurrency control (OCC)
OCC是一种应用于数据库管理系统的并发控制方法。OCC假设多个事务可以并行完成而不会相互干扰。在运行时,事务使用数据资源而不获取这些资源的锁。在提交之前,每个事务都会验证没有其他事务修改了它所读取或修改的数据。如果检查显示有冲突的修改,事务将需要回滚。OCC is a concurrency control method applied to database management systems. OCC assumes that multiple transactions can be completed in parallel without interfering with each other. At runtime, transactions use data resources without acquiring locks on those resources. Before committing, each transaction verifies that no other transaction has modified the data it has read or modified. If the check reveals conflicting modifications, the transaction will need to be rolled back.
7、二阶段提交7. Two-phase submission
二阶段提交(two-phase commit)是指,在计算机网络以及数据库领域内,为了使基于分布式系统架构下的所有节点在进行事务提交时保持一致性而设计的一种算法。通常,二阶段提交也被称为是一种协议。在分布式系统中,每个节点虽然可以知晓自己的操作时成功或者失败,却无法知道其他节点的操作的成功或失败。当一个事务跨越多个节点时,为了保持事务的四个特性,需要引入一个作为协调者的组件来统一掌控所有节点(称作参与者)的操作结果并最终指示这些节点是否要把操作结果进行真正的提交(比如将更新后的数据写入磁盘等等)。因此,二阶段提交的算法思路可以概括为:协调者向各参与者发送准备信息(prepare)。各参与者将操作成败通知协调者,并进入锁定事务资源的状态中等待协调者回复。协调者根据所有参与者的反馈情报决定各参与者执行提交操作(commit)还是回滚操作(rollback),并向各参与者回复协调者的决定,各参与者再释放事务资源响应该决定,从而保证各参与者的数据库一致。Two-phase commit (two-phase commit) refers to an algorithm designed in the field of computer networks and databases to make all nodes based on the distributed system architecture maintain consistency when committing transactions. Often, two-phase commit is also referred to as a protocol. In a distributed system, although each node can know the success or failure of its own operation, it cannot know the success or failure of other nodes' operations. When a transaction spans multiple nodes, in order to maintain the four characteristics of the transaction, it is necessary to introduce a component as a coordinator to uniformly control the operation results of all nodes (called participants) and finally instruct these nodes whether to perform the operation results The actual commit (such as writing the updated data to disk, etc.). Therefore, the algorithm idea of the two-phase commit can be summarized as: the coordinator sends preparation information (prepare) to each participant. Each participant notifies the coordinator of the success or failure of the operation, and enters the state of locking transaction resources to wait for the coordinator to reply. The coordinator decides whether each participant performs a commit operation (commit) or a rollback operation (rollback) based on the feedback information of all participants, and replies to each participant with the decision of the coordinator, and each participant then releases transaction resources in response to the decision, thus Ensure that the databases of all participants are consistent.
然而,一方面,协调者与各参与者之间有三次交互,通信开销较大。另一方面,由于协调者的重要性,一旦协调者发生故障。所有的参与者还都处于锁定事务资源的状态中,而无法继续完成事务操作。However, on the 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 still in the state of locking transaction resources, and cannot continue to complete transaction operations.
为了解决上述问题,本申请实施例提供一种数据库处理方法,通过数据库系统中的多个节点之间互相发送事务的操作集合,使得节点上数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。In order to solve the above problems, the embodiment of the present application provides a database processing method, through the operation set of sending transactions between multiple nodes in the database system, so that the update of the database on the node takes into account the transactions submitted by other databases, thereby ensuring Synchronization of updates between multiple databases.
图1给出了一种数据库系统示意图。该数据库系统可以包括:A节点101、B节点102、C节点103以及D节点104。其中,A节点101部署有A数据库,且A数据库的使用者为A用户。B节点102部署有B数据库,且B数据库的使用者为B用户。C节点103部署有C数据库,且C数据库的使用者为C用户。D节点104部署有D数据库,且D数据库的使用者为D用户。其中,各数据库都存储着相同的数据。A节点101、B节点102、C节点103以及D节点104之间互相通信。Figure 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, A node 101 is deployed with an A database, and a user of the A database is an A user. The B node 102 is deployed with a B database, and a user of the B database is a B user. The C database is deployed on the C node 103, 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. The A node 101 , the B node 102 , the C node 103 and the D node 104 communicate with each other.
上述各节点之间可以相互传输自身节点的操作集合(也可以称为本地操作集合),并根据接收到其他数据库中事务集合的操作集合与本地事务集合的操作集合更新自身节点的数据库(也可以称为本地数据库)。The above-mentioned nodes can transmit the operation sets of their own nodes (also called local operation sets) to each other, and update the database of their own nodes according to the operation sets of transaction sets in other databases and the operation sets of local transaction sets received (also can be called the local database).
本申请实施例中的操作集合是指节点在响应用户操作指令(例如写指令、读写指令等)的过程中修改过的数据项,或者修改过的数据项与读取的数据项。该操作集合也可以称为写集或读写集。接收节点可以通过发送节点发送的操作集合更新本地数据库,使得更新后的本地数据库与发送节点的数据库中存储的数据一致,进而保证数据库之间的同步。The operation set in the embodiment of the present application refers to the data items modified by the node during the process of responding to user operation instructions (such as write instructions, read and write instructions, etc.), or the modified data items and the read data items. The 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, thereby ensuring the synchronization between the databases.
在一种可能实现的方式中,上述各节点都可以为用户提供读写服务。当然,上述各节点中也可以存在只向用户提供读服务的节点或者存在转发节点,或者理解为,本申请实施例提供的方法可以应用于多主复制场景或主从复制场景,具体此处不做限定。In a possible implementation manner, each of the above nodes can provide read and write services for users. Of course, there may also be nodes that only provide read services to users or forwarding nodes among the above nodes, or it can be understood that the method provided in this embodiment of the application can be applied to multi-master replication scenarios or master-slave replication scenarios. Do limited.
可选地,为了保证各数据库的同步,各节点在向其他节点发送操作集合之后,接收到其他节点发送的接收成功消息,再使用本地操作集合与其他节点的操作集合更新数据库。另外,需要说明的是,在多个节点之间交互操作集合的场景下,以图1所示的4个节点为例。若A节点分别向B节点、C节点以及D节点发送A操作集合,但只接收到B节点与C节点发送的 接收成功消息,并没有收到D节点发送的接收成功消息。A节点也可以使用本地操作集合与其他节点的操作集合更新A数据库。换句话说,数据库系统中的大部分节点都已经成功接收到了操作集合并更新本地数据库,可以保证数据库系统中大部分节点的数据库同步即可。当然,最好的情况下是:发送节点收到接收节点发送的接收成功消息后,再更新本地数据库,这样可以保证数据库系统中各个节点的数据库存储的数据一致。Optionally, in order to ensure the synchronization of the databases, each node, after sending the operation set to other nodes, receives a message of successful reception sent by other nodes, and then uses the local operation set and the operation set of other nodes to update the database. In addition, it should be noted that, in the scenario where multiple nodes interact with each other to operate a set, the four nodes shown in FIG. 1 are taken as an example. If node A sends A operation set to node B, node C and node D respectively, but only receives the successful reception message sent by node B and node C, but does not receive the successful reception message sent by node D. Node A can also use the local operation set and the operation set of other nodes to update the A database. In other words, most of the nodes in the database system have successfully received the operation set and updated the local database, which can ensure that the databases of most of the nodes in the database system are synchronized. Of course, the best situation is: the sending node updates the local database after receiving the successful reception message sent by the receiving node, so as to ensure that the data stored in the databases of each node in the database system is consistent.
以A用户为例,一般而言,A用户将读写请求发送到最近的节点(例如A节点)进行处理。涉及到写请求的情况下,等待A节点处理完成后同步到其他节点,并结合其他节点的操作集合(例如事务读写集)进行冲突检测和冲突处理成功后再将结果返回给客户(也可以理解为是数据库同步成功后再返回结果)。Taking user A as an example, generally speaking, user A sends read and write requests to the nearest node (such as node A) for processing. In the case of write requests, wait for node A to complete the processing and synchronize to other nodes, and combine the operation sets of other nodes (such as transaction read and write sets) for conflict detection and conflict processing, and then return the results to the client (you can also It is understood that the result is returned after the database synchronization is successful).
示例性的,以上述节点中的A节点与B节点之间的交互为例进行描述,A节点可以接收A用户对于A数据库的操作指令,A节点在执行该操作指令的过程中记录A用户读取或修改过的数据项,得到A节点的A操作集合。A节点获取A操作集合之后,可以向B节点发送A操作集合。A节点还可以接收B节点发送的B操作集合(即B节点在执行B用户对于B数据库的操作指令的过程中读取和修改过的数据项)。进而,A节点可以基于A操作集合与B操作集合更新A数据库。B节点可以基于A操作集合与B操作集合更新B数据库。进而实现A数据库与B数据库的一致。当然,也可以设置一个交互周期,即在每一个交互周期内,两个节点都会交互自身的数据集合,进而实现A数据库与B数据库的同步。Exemplarily, the interaction between node A and node B among the above-mentioned nodes is described as an example. Node A can receive user A's operation instruction for A database, and node A records user A's read in the process of executing the operation instruction. Get or modify the data item to get the A operation set of A node. After the A node obtains the A operation set, it can send the A operation set to the B node. The A node can also receive the B operation set sent by the B node (that is, the data items read and modified by the B node during the execution of the B user's operation instruction on the B database). Further, the A node can update the A database based on the A operation set and the B operation set. Node B can update the B database based on the A operation set and the B operation set. And then realize the consistency between A database and B database. Of course, an interaction cycle can also be set, that is, in each interaction cycle, the two nodes will exchange their own data sets, thereby realizing the synchronization between the A database and the B database.
本申请实施例中的操作集合是指用户在操作数据库过程中的操作的整合。例如:该操作集合为读写集合或写集合等,具体此处不做限定。The operation set in the embodiment of the present application refers to the integration of the user's operations in the process of operating the database. For example: the operation set is a read-write set or a write set, etc., which are not limited here.
另外,本申请实施例中的A用户、B用户、C用户以及D用户中的任意两个用户可以是同一用户,也可以是不同用户,具体此处不做限定。In addition, any two users among the A user, the B user, the C user, and the D user in the embodiment of the present application may be the same user or different users, which are not specifically limited here.
本申请实施例中,仅以四个节点、四个用户为例进行示意性说明。在实际应用中,本申请实施例中的数据库系统可以包括更多或更少的节点与用户,本申请实施例对节点以及用户的数目不进行限定。In the embodiment of the present application, only four nodes and four users are taken as an example for schematic illustration. In practical applications, the database system in the embodiment of the present application may include more or fewer nodes and users, and the embodiment of the present application does not limit the number of nodes and users.
本申请实施例中的节点是指涉及多台计算机的网络或者分布式系统中的一台计算机或者软件实例。例如:该节点可以是服务器或终端设备,该终端设备是一种具有无线/有线收发功能的设备,可以部署在陆地上,包括室内或室外、手持、穿戴或车载;也可以部署在水面上(如轮船等);还可以部署在空中(例如飞机、气球和卫星上等)。该终端设备可以是手机(mobile phone)、平板电脑(pad)、带无线收发功能的电脑、虚拟现实(virtual reality,VR)终端设备、增强现实(augmented reality,AR)终端设备、工业控制(industrial control)中的无线终端、车载终端设备、无人驾驶(self driving)中的无线终端、远程医疗(remote medical)中的无线终端、智能电网(smart grid)中的无线终端、运输安全(transportation safety)中的无线终端、智慧城市(smart city)中的无线终端、智慧家庭(smart home)中的无线终端、可穿戴终端设备等等。本申请的实施例对应用场景不做限定。终端设备有时也可以称为终端、用户设备(user equipment,UE)、接入终端设备、车载终端、工业控制终端、UE单元、UE站、移动站、移动台、远方站、远程终端设备、移动设备、UE代理或UE装置等。终端设备也可以是固定的或者移动的。另外,终端设备也可以是用于实现UE功能的芯片系统。A node in this embodiment of the present application refers to a computer or a software instance in a network involving multiple computers or a distributed system. For example: the node can be a server or a terminal device. The terminal device is a device with wireless/wired transceiver functions, which can be deployed on land, including indoor or outdoor, handheld, wearable or vehicle-mounted; it can also be deployed on water ( Such as ships, etc.); can also be deployed in the air (such as aircraft, balloons and satellites, etc.). The terminal device can be a mobile phone, a tablet computer (pad), a computer with a wireless transceiver function, a virtual reality (virtual reality, VR) terminal device, an augmented reality (augmented reality, AR) terminal device, an industrial control (industrial control), wireless terminals in vehicle, wireless terminals in self driving, wireless terminals in remote medical, wireless terminals in smart grid, transportation safety ), wireless terminals in a smart city, wireless terminals in a smart home, wearable terminal devices, etc. The embodiments of the present application do not limit the application scenarios. Terminal equipment may sometimes be called terminal, user equipment (UE), access terminal equipment, vehicle-mounted terminal, industrial control terminal, UE unit, UE station, mobile station, mobile station, remote station, remote terminal equipment, mobile device, UE proxy or UE device, etc. Terminal equipment can also be fixed or mobile. In addition, the terminal device may also be a chip system for implementing UE functions.
下面结合图1所示的数据库系统中的任意两个节点之间的交互流程对本申请实施例中的数据库处理方法进行描述。请参阅图2,本申请实施例提供的数据库处理方法的一个实施例包括步骤201至步骤206。其中,第一节点与第二节点可以是前述图1中的任意两个节点,具体此处不做限定。另外,该方法可以由通信设备(例如:服务器或终端设备)执行,也可以由通信设备的部件(例如处理器、芯片、或芯片系统等)执行。可以理解的是,通信设备可以是芯片或具有收发功能的单元或实体设备。此外,本申请实施例提供的数据库处理方法可以应用于MySQL、Oracle、开源高斯(openGauss)等,具体此处不做限定。The database processing method in the embodiment of the present application will be described below in conjunction with the interaction flow between any two nodes in the database system shown in FIG. 1 . Referring to FIG. 2 , an embodiment of the database processing method provided by the embodiment of the present application includes steps 201 to 206 . Wherein, the first node and the second node may be any two nodes in the aforementioned FIG. 1 , which are not specifically limited here. In addition, the method may be executed by a communication device (such as a server or a terminal device), or may be executed by components of the communication device (such as a processor, a chip, or a chip system, etc.). It can be understood that the communication device may be a chip or a unit with a sending and receiving function or a physical device. In addition, the database processing method provided in the embodiment of the present application may be applied to MySQL, Oracle, openGauss (openGauss), etc., which are not specifically limited here.
步骤201,第一节点获取第一操作集合。Step 201, the first node acquires a first operation set.
本申请实施例中的第一节点与第二节点可以是数据库系统中的任意两个节点,第一节点部署有第一数据库,第二节点部署有第二数据库,且第一数据库与第二数据库存储有相同的数据。The first node and the second node in the embodiment of the present application can be any two nodes in the database system, the first node is deployed with the first database, the second node is deployed with the second database, and the first database and the second database Store the same data.
本申请实施例中,可以利用操作集合记录数据库事务的执行过程。不管数据库事务的执行过程多么复杂,都可以利用操作集合重演该事务的执行过程,并产生相同的执行结果。进而多个节点之间可以通过互相发送本地的操作集合实现数据库的同步。In the embodiment of the present application, an operation set may be used to record the execution process of the database transaction. No matter how complicated the execution process of a database transaction is, the execution process of the transaction can be replayed by using the operation set, and the same execution result can be produced. Furthermore, multiple nodes can realize database synchronization by sending local operation sets to each other.
本申请实施例中的操作集合(包括第一操作集合与第二操作集合)中可以包括一个或多个事务,一个事务可以对应一个或多个操作(例如:读、写等)。其中,写操作可以包括增加、删除、修改等操作。The operation set (including the first operation set and the second operation set) in the embodiment of the present application may include one or more transactions, and one transaction may correspond to one or more operations (eg, read, write, etc.). Wherein, the write operation may include adding, deleting, modifying and other operations.
另外,需要说明的是,第一事务集合可以是第一数据库中可提交的事务(也可以理解为,在第一事务集合中的事务数量为多个时,多个事务之间不冲突),第二事务集合可以是第二数据库中可提交的事务(也可以理解为,在第二事务集合中的事务数量为多个时,多个事务之间不冲突)。或者,第一事务集合是第一数据库中所有的事务,第二事务集合是第二数据库中所有的事务。In addition, it should be noted that the first transaction set may be committable transactions in the first database (it can also be understood that when the number of transactions in the first transaction set is multiple, there is no conflict between multiple transactions), The second transaction set may be committable transactions in the second database (it can also be understood that when the number of transactions in the second transaction set is multiple, the multiple transactions do not conflict). Alternatively, the first transaction set is all transactions in the first database, and the second transaction set is all transactions in the second database.
本申请实施例中第一节点获取第一操作集合的方式仅以是基于第一用户的操作指令的方式获取,可以理解的是,也可以是其他设备发送第一操作集合等方式获取,具体此处不做限定。其中,第一操作集合为在目标时间段内第一数据库中第一事务集合的写操作或读写操作。另外,第一事务集合中的事务数量可以是一个或多个,第一操作集合中写操作或读写操作的数量不做限定。该目标时间段可以根据实际需要设置,具体此处不做限定。In the embodiment of the present application, the way for the first node to obtain the first operation set is only based on the operation instructions of the first user. It can be understood that other devices can also send the first operation set to obtain the first operation set. Specifically, There is no limit. Wherein, the first operation set is the write operation or read-write operation of the first transaction set in the first database within 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, which is not specifically limited here.
上述的目标时间段可以是指一个时间周期。该种情况下的目标时间段可以理解为是上一次同步的时刻至目标时刻之间的时间段。可选地,第一节点可以在预设周期的每个周期都获取第一操作集合,并周期性的向第二节点发送操作集合。这里对周期次数不做限定。例如:一个周期是10毫秒,则目标时间段可以是10毫秒,即第一节点每10毫秒会获取一次第一操作集合,并向第二节点发送一次第一操作集合。The aforementioned target time period may refer to a time period. The target time period in this case can be understood as the time period between the time of the last synchronization and the target time. Optionally, the first node may obtain the first operation set in each preset period, and periodically send the operation set to the second node. The number of cycles is not limited here. For example, if one period is 10 milliseconds, the target time period may be 10 milliseconds, that is, the first node will obtain the first operation set every 10 milliseconds, and send the first operation set to the second node once.
可以理解的是,目标时间段也可以是指从第一数据库的创建时刻到目标时刻之间的时间段,即第一操作集合是在目标时刻之前第一数据库中第一事务集合的写操作或读写操作。该种情况下,可以理解为是,为了保证第一节点的第一数据库与第二节点的数据库在目标时刻的数据同步,可以一次性发送目标时刻之前的所有第一操作集合。It can be understood that the target time period may also refer to the time period from the creation time of the first database to the target time, that is, the first operation set is the write operation or the first transaction set in the first database before the target time. read and write operations. In this case, it can be understood that, in order to ensure data synchronization between the first database of the first node and the database of the second node at the target time, all the first operation sets before the target time may be sent at one time.
可选地,第一数据库可以为第一用户提供写服务或读写服务等,即第一用户可以对第一 节点中第一数据库的表项进行一系列操作,例如:写(例如:增加、删除、修改)、读(例如查询)等。第一节点在执行该一系列操作的过程中记录第一用户对第一数据库中数据项的操作,得到第一操作集合。Optionally, the first database may provide write services or read-write services for the first user, that is, the first user may perform a series of operations on entries in the first database in the first node, for example: write (for example: add, delete, modify), read (e.g. query), etc. During the process of executing the series of operations, the first node records the operations of the first user on the data items in the first database to obtain a first operation set.
示例性的,第一节点接收第一用户对于第一数据库的读写指令,第一节点响应该读写指令,对第一数据库中的表项进行读写操作,并在执行该读写操作的过程中,记录第一用户读取与修改过的数据项,得到第一读写集。即该示例下,第一操作集合为第一事务集合的读写操作集合或写操作集合,具体根据实际需要设置,此处不做限定。Exemplarily, the first node receives the first user's read and write instructions for the first database, the first node responds to the read and write instructions, performs read and write operations on entries in the first database, and executes the read and write operations During the process, the data items read and modified by the first user are recorded to obtain the first read-write set. That is, in this example, the first operation set is the read and write operation set or the write operation set of the first transaction set, which is set according to actual needs and is not limited here.
示例性的,第一节点接收第一用户对于第一数据库的写指令,第一节点响应该写指令,对第一数据库中的表项进行写操作,并在执行该写操作的过程中,记录第一用户修改过的数据项,得到第一写集。即该示例下,第一操作集合为第一事务集合的写操作集合。Exemplarily, the first node receives a first user's write instruction to the first database, and the first node responds to the write instruction to perform a write operation on an entry in the first database, and during the process of performing the write operation, records The data item modified by the first user obtains the first write set. That is, in this example, the first operation set is the write operation set of the first transaction set.
示例性的,为了更好理解后续第一数据库与第二数据库的同步过程,下面以第一数据库与第二数据库存储有如图3中表1所示的数据为例进行示例性描述。第一用户在第一数据库中执行的第一事务集合包括:事务1与事务2,事务1:删除“孙五”。事务2:将“李六”的“收货地址”修改为“广东省深圳市南山区E街道F酒店801房”。则第一事务集合的第一操作集合包括:删除操作与修改操作。Exemplarily, in order to better understand the subsequent synchronization process of the first database and the second database, the data shown in Table 1 in FIG. 3 is stored in the first database and the second database as an example for exemplary description below. The first transaction set executed by the first user in the first database includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu". Transaction 2: Change the "delivery address" of "Li Liu" to "Room 801, Hotel F, E Street, Nanshan District, Shenzhen, Guangdong Province". Then the first operation set of the first transaction set includes: delete operation and modification operation.
为了方便后续描述,后续所提的第一事务集合中每个事务的第一时间戳、第一标识或第一周期标识中的至少一项可以称为第一信息。其中,第一事务集合中的一个事务对应一个第一时间戳或第一标识。即第一时间戳与第一标识可以用于定位唯一的一个第一事务集合中的事务。进一步的,第一时间戳或第一标识还可以用于对第一事务集合中的多个事务进行排序,以确定待提交的事务或者提交多个事务的顺序。For the convenience of subsequent description, at least one item of the first time stamp, the first identifier, or the first cycle identifier of each transaction in the first transaction set mentioned later may be referred to as first information. Wherein, a transaction in the first transaction set corresponds to a first timestamp or a first identifier. That is, the first timestamp and the first identifier can be used to locate a unique transaction in the first transaction set. Further, the first time stamp or the first identifier may also be used to sort the multiple transactions in the first transaction set, so as to determine the transaction to be committed or the order in which multiple transactions are committed.
可选地,第一节点在获取第一事务集合的第一操作集合的过程中,还可以记录每个事务的最后一个操作的结束时刻(可以称为第一时间戳)或第一标识,该第一时间戳可以是最后一个操作结束时刻时第一节点本地的时间戳,也可以是数据库系统中的逻辑时间,还可以是某个特定中心节点所分配的时间戳等,具体此处不做限定。该第一标识可以是数据库系统全局唯一自增的事务标识。Optionally, in the process of obtaining the first operation set of the first transaction set, the first node may also record the end time (which may be called the first timestamp) or the first identifier of the last operation of each transaction, which The first timestamp can be the local timestamp of the first node at the end of the last operation, it can also be the logical time in the database system, or it can be the timestamp assigned by a specific central node, etc., which will not be done here limited. The first identifier may be a globally unique auto-incremented transaction identifier of the database system.
进一步的,若数据库系统中的多个节点是周期性的相互发送本地操作集合,则第一节点还可以获取每个事务的周期标识。在更新数据库的过程中,若多个操作集合中存在跨周期的操作集合,例如多个操作集合中有一个操作集合是第一周期的,另一个操作集合是第二周期的,后续则可以通过周期号确定提交操作集合对应事务的顺序,进而保证多个数据库之间的同步。当然,若多个操作集合中存在跨周期的操作集合,也存在相同周期的操作集合。在更新数据库的过程中,可以先根据周期标识确定小范围的操作集合对应事务的顺序,再根据时间戳或标识确定提交事务的顺序。Further, if multiple nodes in the database system periodically send local operation sets to each other, the first node may also obtain the period identifier of each transaction. In the process of updating the database, if there are operation sets that cross cycles in multiple operation sets, for example, one of the multiple operation sets is in the first cycle and the other is in the second cycle, then you can use The cycle number determines the order of the transactions corresponding to the commit operation set, thereby ensuring the synchronization between multiple databases. Certainly, if there are operation sets across periods in the multiple operation sets, there are also operation sets with the same period. In the process of updating the database, the order of the transactions corresponding to the small-scale operation set can be determined first according to the period identifier, and then the order of submitting the transactions can be determined according to the timestamp or the identifier.
示例性的,若应用于openGauss场景,且图1所示的四个节点分别位于不同的区域,每个节点所在的区域所有用户提交的事务都可以由该节点处理。具体的,第一数据库连接器在收到用户的操作请求,且该用户的操作请求通过身份验证之后,将该操作请求的结构化查询语言(structured query language,SQL)语句传给SQL解析器、优化器等组件对SQL语句进行词法分析、语法分析和查询优化。首先从查询语句中识别出系统支持的关键字、标识符等,再根据SQL语言的标准定义语法规则,使用词法分析中产生的词去匹配语法规则,如果 一个SQL语句能够匹配一个语法规则,则生成对应的抽象语法树。最后由查询优化器通过查询重写来对SQL进行优化,利用已有语句特征和关系代数运算来生成更高效的等价语句,基于代价估计生成最终的查询计划。预先设置有预设周期,第一节点在每个周期需要集齐数据库系统中所有节点在当前周期的操作集合之后,才可以进行冲突检测和处理(也可以理解为更新数据库)。例如,第一信息包括第一周期标识与第一时间戳。且预设周期为50毫秒(ms),即每隔50ms产生一个新的同步周期。需要注意的是,第一节点执行成功的事务并不能立刻写入第一数据库中,需要与当前周期内其他节点发送的操作集合对应的事务进行合并验证,并进行数据库同步。在同一个周期内的两个事务发生冲突时,依照“先写胜利”的原则进行并发控制。具体的,当两个事务尝试修改同一个数据项时,根据两个事务的时间戳大小确定待提交的事务与待回滚的事务(后续步骤205中有相关描述,此处不再展开)。可以理解的是,后续第二节点的操作与第一节点类似,后续不再赘述。Exemplarily, if it is applied to an openGauss scenario, and the four nodes shown in FIG. 1 are located in different areas, all transactions submitted by users in the area where each node is located can be processed by the node. Specifically, after the first database connector receives the user's operation request, and after the user's operation request passes the authentication, it transmits the structured query language (structured query language, SQL) statement of the operation request to the SQL parser, Components such as the optimizer perform lexical analysis, syntax analysis, and query optimization on SQL statements. First identify the keywords and identifiers supported by the system from the query statement, then define the grammar rules according to the SQL language standard, and use the words generated in the lexical analysis to match the grammar rules. If an SQL statement can match a grammar rule, then Generate the corresponding abstract syntax tree. Finally, the query optimizer optimizes SQL through query rewriting, uses existing statement features and relational algebra operations to generate more efficient equivalent statements, and generates the final query plan based on cost estimation. There is a preset period in advance, and the first node can perform conflict detection and processing (it can also be understood as updating the database) after collecting all the operations of all nodes in the database system in the current period in each period. For example, the first information includes a first period identifier and a first time stamp. And the preset cycle is 50 milliseconds (ms), that is, a new synchronization cycle is generated every 50 ms. It should be noted that the successful execution of the transaction 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 cycle needs to be merged and verified, and the database should be synchronized. When two transactions in the same cycle conflict, concurrency control is performed according to the principle of "write first wins". Specifically, when two transactions try to modify the same data item, the transaction to be committed and the transaction to be rolled back are determined according to the timestamps of the two transactions (relevant descriptions are provided in subsequent step 205 and will not be expanded here). It can be understood that the operation of the subsequent second node is similar to that of the first node, and will not be repeated hereafter.
步骤202,第一节点向第二节点发送第一操作集合。相应的,第二节点接收第一节点发送的第一操作集合。Step 202, the first node sends the first operation set to the second node. Correspondingly, the second node receives the first operation set sent by the first node.
第一节点获取第一操作集合之后,可以向第二节点发送该第一操作集合。相应的,第二节点接收第一节点发送的第一操作集合。After the first node acquires the first operation set, it may send the first operation set to the second node. Correspondingly, the second node receives the first operation set sent by the first node.
可以理解的是,第一节点向第二节点发送第一操作集合的次数可以是一次或多次,即可以是全量发送,也可以是分批次发送,具体此处不做限定。It can be understood that the number of times the first node sends the first operation set to the second node may be one or more times, that is, it may be sent in full or in batches, which is not limited here.
可选地,若前述步骤201中,第一节点还获取有第一时间戳、第一标识或第一周期标识中的至少一种,第一节点还可以向第二节点发送第一时间戳、第一标识或第一周期标识中的至少一种。相应的,第二节点接收第一节点发送的第一时间戳、第一标识或第一周期标识中的至少一种。Optionally, if in the foregoing step 201, the first node also obtains at least one of the first timestamp, the first identifier, or the first period identifier, the first node may also send the first timestamp, At least one of the first identifier or the first periodic identifier. Correspondingly, the second node receives at least one of the first timestamp, the first identifier, or the first period identifier sent by the first node.
示例性的,延续上述应用于openGauss场景的举例,当到达一个周期的结束时刻,第一节点会向数据库系统中的其他节点发送第一操作集合,最终每个节点都会拥有该周期内所有事务的操作集合,进而可以根据相同的规则(例如:“先写胜利”)进行并发控制,从而保证所有节点的数据一致。可以理解的是,后续第二节点的操作与第一节点类似,后续不再赘述。Exemplarily, continuing the above example applied to the openGauss scenario, when the end of a cycle is reached, the first node will send the first set of operations to other nodes in the database system, and eventually each node will have all transactions in the cycle The collection is operated, and concurrency control can be performed according to the same rules (for example: "write first wins"), so as to ensure that the data of all nodes is consistent. It can be understood that the operation of the subsequent second node is similar to that of the first node, and will not be repeated hereafter.
步骤203,第二节点获取第二操作集合。Step 203, the second node acquires a second operation set.
本申请实施例中,第二节点获取第二操作集合的方式与第一节点获取第一操作集合的方式类似,可以是基于第二用户的操作指令的方式获取,也可以是其他设备发送第二操作集合等方式获取,具体此处不做限定。其中,第二操作集合为在目标时间段内第二数据库中第二事务集合的写操作或读写操作。另外,第二事务集合中的事务数量可以是一个或多个,第二操作集合中写操作或读写操作的数量不做限定。该目标时间段可以根据实际需要设置,具体此处不做限定。In this embodiment of the application, the way the second node acquires the second operation set is similar to the way the first node acquires the first operation set. It can be obtained by means of operating a set, etc., and the details are not limited here. Wherein, the second operation set is the write operation or read-write operation of the second transaction set in the second database within 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, which is not specifically limited here.
本步骤中的目标时间段与前述步骤201中的目标时间段的描述类似。可选地,第二节点可以在预设周期的每个周期都获取第二操作集合,并周期性的向第一节点发送操作集合。这里对周期次数不做限定。例如:一个周期是10毫秒,则目标时间段可以是10毫秒,即第二节点每10毫秒会获取一次第二操作集合,并向第一节点发送一次第二操作集合。其中,对于目标时间段的可以参考之前的描述,此处不再赘述。The target time period in this step is similar to the description of the target time period in step 201 above. Optionally, the second node may obtain the second operation set in each preset period, and periodically send the operation set to the first node. The number of cycles is not limited here. For example, if one period is 10 milliseconds, the target time period may be 10 milliseconds, that is, the second node will obtain the second operation set every 10 milliseconds, and send the second operation set to the first node once. Wherein, for the target time period, reference may be made to the previous description, which will not be repeated here.
可选地,第二数据库与第一数据库类似,可以为第二用户提供写服务或读写服务等,即 第二用户可以对第二节点中第二数据库的表项进行一系列操作,例如:增加、删除、修改、查询等。第二节点在执行该一系列操作的过程中记录第二用户对第二数据库中数据项的操作,得到第二操作集合。Optionally, the second database is similar to the first database, and can provide write services or read-write services for the second user, that is, the second user can perform a series of operations on the entries of the second database in the second node, for example: Add, delete, modify, query, etc. During the process of executing the series of operations, the second node records the second user's operations on the data items in the second database to obtain a second operation set.
示例性的,第二节点接收第二用户对于第二数据库的读写指令,第二节点响应该读写指令,对第二数据库中的表项进行读写操作,并在执行该读写操作的过程中,记录第二用户读取与修改过的数据项,得到第二读写集。即该示例下,第二操作集合为第二事务集合的读写操作的集合或写操作集合,具体根据实际需要设置,此处不做限定。Exemplarily, the second node receives the second user's read and write instructions for the second database, and the second node responds to the read and write instructions, performs read and write operations on entries in the second database, and executes the read and write operations During the process, the data items read and modified by the second user are recorded to obtain the 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 here.
示例性的,第二节点接收第二用户对于第二数据库的写指令,第二节点响应该写指令,对第二数据库中的表项进行写操作,并在执行该写操作的过程中,记录第二用户修改过的数据项,得到第二写集。即该示例下,第二操作集合为第二事务集合的写操作的集合。Exemplarily, the second node receives a second user's write instruction for the second database, and the second node responds to the write instruction to perform a write operation on the entry in the second database, and during the process of performing the write operation, records The data item modified by the second user obtains the second write set. That is, in this example, the second operation set is a set of write operations of the second transaction set.
示例性的,延续第二数据库如图3中表1的举例,假设,第二用户在第二数据库中执行的第二事务集合包括:事务3。事务3:增加“周七”,“15789012345”,“广东省深圳市罗湖区第W小学”。则第二操作集合包括:增加操作。Exemplarily, continuing the example of Table 1 in FIG. 3 for the second database, it is assumed that the second transaction set executed by the second user in the second database includes: transaction 3 . Transaction 3: Add "Sunday", "15789012345", "No. W Primary School, Luohu District, Shenzhen City, Guangdong Province". Then the second operation set includes: adding operation.
与前述第一信息类似,为了方便后续描述,后续所提的第二时间戳、第二标识或第二周期标识中的至少一项可以称为第二信息。其中,第二事务集合中的一个事务对应一个第二时间戳或第二标识。即第二时间戳与第二标识可以用于定位唯一的一个事务。进一步的,第二时间戳或第二标识还可以用于对多个事务进行排序,以确定待提交的事务或者提交多个事务的顺序。Similar to the foregoing first information, for the convenience of subsequent descriptions, at least one of the second timestamp, the second identifier, or the second period identifier mentioned later may be referred to as second information. Wherein, one transaction in the second transaction set corresponds to a second timestamp or a second identifier. That is, the second timestamp and the second identifier can be used to locate a unique transaction. Further, the second time stamp or the second identifier can also be used to sort multiple transactions, so as to determine the transaction to be committed or the order in which multiple transactions are committed.
可选地,第二节点在获取第二事务集合的第二操作集合的过程中,还可以记录每个事务的最后一个操作的结束时刻(可以称为第二时间戳)或第二标识,该第二时间戳可以是最后一个操作结束时刻时第二节点本地的时间戳,也可以是数据库系统中的逻辑时间,还可以是某个特定中心节点所分配的时间戳等,具体此处不做限定。该第二标识可以是数据库系统全局唯一自增的事务标识。Optionally, during the process of obtaining the second operation set of the second transaction set, the second node may also record the end time (which may be called the second timestamp) or the second identifier of the last operation of each transaction, which The second timestamp can be the local timestamp of the second node at the end of the last operation, it can also be the logical time in the database system, or it can be the timestamp assigned by a specific central node, etc., which will not be done here. limited. The second identifier may be a globally unique auto-incremented transaction identifier of the database system.
进一步的,若数据库系统中的多个节点是周期性的相互发送本地操作集合,则第二节点还可以获取事务的周期标识。在更新数据库的过程中,若多个操作集合中存在跨周期的操作集合,例如多个操作集合中有一个操作集合是第一周期的,另一个操作集合是第二周期的,后续则可以通过周期号确定提交操作集合对应事务的顺序,进而保证多个数据库之间的同步。当然,若多个操作集合中存在跨周期的操作集合,也存在相同周期的操作集合。在更新数据库的过程中,可以先根据周期标识确定小范围的操作集合对应事务的顺序,再根据时间戳或事务的标识确定提交事务的顺序。Further, if multiple nodes in the database system periodically send local operation sets to each other, the second node may also obtain the period identifier of the transaction. In the process of updating the database, if there are operation sets that cross cycles in multiple operation sets, for example, one of the multiple operation sets is in the first cycle and the other is in the second cycle, then you can use The cycle number determines the order of the transactions corresponding to the commit operation set, thereby ensuring the synchronization between multiple databases. Certainly, if there are operation sets across periods in the multiple operation sets, there are also operation sets with the same period. In the process of updating the database, the order of the transactions corresponding to the small-scale operation set can be determined first according to the period identifier, and then the order of submitting the transactions can be determined according to the timestamp or the identifier of the transaction.
步骤204,第二节点向第一节点发送第二操作集合。相应的,第一节点接收第二节点发送的第二操作集合。Step 204, the second node sends the second operation set to the first node. Correspondingly, the first node receives the second operation set sent by the second node.
第二节点获取第二操作集合之后,可以向第一节点发送该第二操作集合。相应的,第一节点接收第二节点发送的第二操作集合。After the second node obtains the second operation set, it may send the second operation set to the first node. Correspondingly, the first node receives the second operation set sent by the second node.
可以理解的是,第一节点向第二节点发送第一操作集合的次数可以是一次或多次,即可以是全量发送,也可以是分批次发送,具体此处不做限定。It can be understood that the number of times the first node sends the first operation set to the second node may be one or more times, that is, it may be sent in full or in batches, which is not limited here.
可选地,若前述步骤203中,第二节点还获取有第二时间戳、第二标识或第二周期标识中的至少一种,第二节点还可以向第一节点发送第二时间戳、第二标识或第二周期标识中的 至少一种。相应的,第一节点接收第二节点发送的第二时间戳、第二标识或第二周期标识中的至少一种。Optionally, if in the foregoing step 203, the second node also obtains at least one of the second timestamp, the second identifier, or the second periodic identifier, the second node may also send the second timestamp, At least one of the second identification or the second periodic identification. Correspondingly, the first node receives at least one of the second timestamp, the second identifier, or the second period identifier sent by the second node.
步骤205,第一节点基于第一操作集合与第二操作集合更新第一数据库。Step 205, the first node updates the first database based on the first operation set and the second operation set.
第一节点在获取第一操作集合与第二操作集合之后,第一节点可以基于第一操作集合与第二操作集合更新第一数据库。具体的,第一节点可以基于第一操作集合与第二操作集合先确定第一数据库待提交的事务,并在第一数据库中提交该待提交的事务。换句话说,第一节点可以基于第二操作集合确定第二节点中第二数据库中执行的操作,进而可以执行第二操作集合中的操作,使得第一数据库的更新已经考虑第二数据库的修改,从而保证数据库之间的数据同步。After the first node acquires 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 first determine the transaction to be submitted in the first database based on the first operation set and the second operation set, and submit the transaction to be submitted in the first database. In other words, the first node can determine the operations performed in the second database in the second node based on the second operation set, and then can execute the operations in the second operation set, so that the update of the first database has considered the modification of the second database , so as to ensure data synchronization between databases.
在一种可能实现的方式中,若第一事务集合是第一数据库中可提交的事务,第二事务集合是第二数据库中可提交的事务。则第一节点在更新第一数据库时,只用确定第一事务集合与第二事务集合之间是否有事务冲突即可,因为第一事务集合中各事务之间或第二事务集合中各事务之间是否冲突已经在各自节点的本地进行了判断。本申请实施例所提的确定事务是否冲突,可以理解为是确定各个事务是待提交的事务还是待回滚的事务。In a possible implementation manner, if the first transaction set is committable transactions in the first database, the second transaction set is committable transactions in the second database. Then when the first node updates the first database, it only needs to determine whether there is a transaction conflict between the first transaction set and the second transaction set, because between the transactions in the first transaction set or between the transactions in the second transaction set Whether there is a conflict between them has been judged locally at the respective nodes. The determination of whether transactions conflict in the embodiment of the present application can be understood as determining whether each transaction is a transaction to be committed or a transaction to be rolled back.
在另一种可能实现的方式中,若第一事务集合是第一数据库所有的事务,第二事务集合是第二数据库所有的事务。则后续第一节点在更新第一数据库时,除了需要确定第一事务集合与第二事务集合之间是否有事务冲突,还需要确定第一事务集合中多个事务之间是否冲突,第二事务集合中多个事务之间是否冲突。In another possible implementation manner, if the first transaction set is the transactions owned by the first database, the second transaction set is the transactions owned by the second database. Then, when the first node subsequently updates the first database, in addition to determining whether there is a transaction conflict between the first transaction set and the second transaction set, it is also necessary to determine whether there is a conflict between multiple transactions in the first transaction set, and whether the second transaction Whether there are conflicts between multiple transactions in the collection.
可选地,第一节点可以将第一操作集合与第二操作集合合并,并判断第一操作集合与第二操作集合中的哪些操作冲突,确定出待提交的事务与待回滚的事务,进而推进数据库的一致性点。Optionally, the first node may merge the first operation set with the second operation set, and determine which operations in the first operation set conflict with the second operation set, determine the transaction to be committed and the transaction to be rolled back, And then promote the consistency point of the database.
可选地,第一节点获取第一事务集合中每个事务的第一时间戳、第一标识或第一周期标识中的至少一项(或称为第一信息),并接收第二节点发送的第二时间戳、第二标识或第二周期标识中的至少一项(或称为第二信息)。第一节点可以基于第一操作集合、第一信息、第二操作集合以及第二信息确定第一事务集合与第二事务集合中待提交的事务,并在第一数据库中提交该待提交的事务,得到更新后的第一数据库。Optionally, the first node obtains at least one of the first time stamp, the first identifier, or the first cycle identifier (or called first information) of each transaction in the first transaction set, and receives the information sent by the second node. At least one of the second timestamp, the second identifier, or the second periodic identifier (or referred to as second information) of the. The first node may determine the 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 submit the transaction to be committed in the first database , to get the updated first database.
进一步的,若第一事务集合与第二事务集合中的各个事务没有冲突,则第一事务集合与第二事务集合中的事务都可以作为待提交的事务。若第一事务集合与第二事务集合中的事务之间有冲突(这些冲突的事务可以称为冲突事务),则可以根据预设规则确定冲突事务中的待提交的事务与待回滚的事务,并提交待提交的事务,回滚待回滚的事务。该预设规则可以根据实际需要设置,具体此处不做限定。例如:预设规则是冲突事务中时间戳较小的事务为待提交的事务,或者时间戳较大的事务为待提交的事务。Further, if there is no conflict between the transactions in the first transaction set and the second transaction set, then the transactions in the first transaction set and the second transaction set can be used as transactions to be committed. If there is a conflict between the transactions in the first transaction set and the second transaction set (these conflicting transactions can be called conflicting transactions), the transaction to be committed and the transaction to be rolled back in the conflicting transaction can be determined according to preset rules , and commit the transaction to be committed, and roll back the transaction to be rolled back. The preset rule can be set according to actual needs, which is not specifically limited here. For example: the default rule is that the transaction with the smaller timestamp in the conflicting transactions is the transaction to be committed, or the transaction with the larger timestamp is the transaction to be committed.
可以理解的是,对于第一事务集合包括多个第一子事务,且第二事务集合包括多个第二子事务的情况,判断多个第一子事务与多个第二子事务是否冲突的情况,假设多个第一子事务中存在一个目标子事务,需要用该目标子事务与其他剩余的所有事务进行冲突检测,只有在与其他所有事务都不冲突的情况下,才可以确定该目标子事务为待提交的事务。It can be understood that, 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, judging whether the plurality of first sub-transactions conflict with the plurality of second sub-transactions Assuming that there is a target sub-transaction in multiple first sub-transactions, the target sub-transaction needs to be used for conflict detection with all other remaining transactions, and the target can only be determined when it does not conflict with all other transactions Subtransactions are transactions to be committed.
示例性的,对于第一事务集合包括多个第一子事务,且第二事务集合包括多个第二子事务的情况,如果在判断一个子事务11与一个子事务12是否冲突,且子事务11的时间戳大于 子事务12的时间戳。则时间戳较大的子事务11为待回滚事务,时间戳较小的子事务12不回滚,但子事务12不一定是待提交的事务。因为,该子事务12还要和其他事务都进行冲突检测后,才能确定该子事务12是否为待提交事务。所有事务都比对结束后,确定不回滚的事务可以提交。可以理解的是,这里子事务11与子事务12的标识(即11与12)只是举例。Exemplarily, for the case where the first transaction set includes multiple first sub-transactions, and the second transaction set includes multiple second sub-transactions, if judging whether a sub-transaction 11 conflicts with a sub-transaction 12, and the sub-transaction The timestamp of 11 is greater than the timestamp of subtransaction 12. Then the sub-transaction 11 with a larger timestamp is a transaction to be rolled back, and the sub-transaction 12 with a smaller timestamp is not rolled back, but the sub-transaction 12 is not necessarily a transaction to be committed. Because, whether the subtransaction 12 is a transaction to be committed can only be determined after the subtransaction 12 has been checked for conflicts with other transactions. After all transactions are compared, the transactions that are determined not to be rolled back can be committed. It can be understood that the identifications of subtransaction 11 and subtransaction 12 (ie 11 and 12 ) are just examples.
需要注意的是,本申请实施例的方法可以适用于OCC场景,该场景下提交事务中的“提交”,相当于将写操作更新的数据真正写入的数据库。It should be noted that the method in the embodiment of the present application can be applied to the OCC scenario, and the "commit" in the commit transaction in this scenario is equivalent to actually writing the data updated by the write operation into the database.
示例性的,第一事务集合中第一子事务的第一信息为第一时间戳,第二事务集合中第二子事务的第二信息为第二时间戳。第一子事务与第二子事务至少包括重叠的一个数据项,且第一子事务的第一时间戳小于第二子事务的第二时间戳,则可以确定第一子事务为不需要回滚的事务,第二子事务为回滚事务。在将第一子事务与其余所有事务的时间戳进行一一对比之后,确定不需要回滚的事务为待提交事务。当然,也可以是时间戳较大的事务为不需要回滚的事务,时间戳较小的事务为待回滚的事务。Exemplarily, the first information of the first sub-transaction in the first transaction set is the first timestamp, and the second information of the second sub-transaction in the second transaction set is the second timestamp. The first sub-transaction and the second sub-transaction include at least one overlapping data item, and the first timestamp of the first sub-transaction is less than the second timestamp of the second sub-transaction, then it can be determined that the first sub-transaction does not need to be rolled back transaction, the second sub-transaction is a rollback transaction. After comparing the timestamps of the first sub-transaction with the timestamps of all other transactions, it is determined that the transaction that does not need to be rolled back is the transaction to be committed. Of course, it may also be that a transaction with a larger timestamp is a transaction that does not need to be rolled back, and a transaction with a smaller timestamp is a transaction to be rolled back.
另外,第一节点还可以根据第一信息与第二信息确定待提交的事务的提交顺序。具体的,若数据库系统中的多个节点是周期性的相互发送本地操作集合,则本步骤可以是周期性的。另外,若多个操作集合中存在跨周期的操作集合,例如多个操作集合中有一个操作集合是第一周期的,另一个操作集合是第二周期的,后续则可以通过周期号确定提交操作集合对应事务的顺序,进而保证多个数据库之间的同步。当然,若多个操作集合中存在跨周期的操作集合,也存在相同周期的操作集合。在更新数据库的过程中,可以先根据周期标识确定小范围的操作集合对应事务的顺序,再根据时间戳或事务的标识确定提交事务的顺序。In addition, the first node may also determine a commit order of transactions to be committed according to the first information and the second information. Specifically, if multiple nodes in the database system periodically send local operation sets to each other, this step may be periodic. In addition, if there are operation sets that cross cycles in multiple operation sets, for example, one operation set in the multiple operation sets is in the first cycle, and the other operation set is in the second cycle, then you can determine the commit operation through the cycle number The collection corresponds to the order of transactions, thereby ensuring synchronization between multiple databases. Certainly, if there are operation sets across periods in the multiple operation sets, there are also operation sets with the same period. In the process of updating the database, the order of the transactions corresponding to the small-scale operation set can be determined first according to the period identifier, and then the order of submitting the transactions can be determined according to the timestamp or the identifier of the transaction.
可选地,第一节点在更新第一数据库之后,可以记录日志或更新快照。Optionally, after updating the first database, the first node may record a log or update a snapshot.
示例性的,延续之前的举例,第一用户在第一数据库中执行的第一事务集合包括:事务1与事务2,事务1:删除“孙五”。事务2:将“李六”的“收货地址”修改为“广东省深圳市南山区E街道F酒店801房”。第一事务集合的第一操作集合包括:删除操作与修改操作。第二用户在第二数据库中执行的第二事务集合包括:事务3。事务3:增加“周七”,“15789012345”,“广东省深圳市罗湖区第W小学”。则第二操作集合包括:增加操作。则第一节点基于第一操作集合与第二操作集合更新第一数据库的流程如图4所示,更新后的第一数据库如图4中的表2所示。Exemplarily, continuing the previous example, the first transaction set executed by the first user in the first database includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu". Transaction 2: Change the "delivery address" of "Li Liu" to "Room 801, Hotel F, E Street, Nanshan District, Shenzhen, Guangdong Province". The first operation set of the first transaction set includes: delete operation and modification operation. The second transaction set executed by the second user in the second database includes: transaction 3 . Transaction 3: Add "Sunday", "15789012345", "No. W Primary School, Luohu District, Shenzhen City, Guangdong Province". Then the second operation set includes: adding operation. Then, the process 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 .
示例性的,延续上述应用于openGauss场景的举例,第一节点在收到当前周期内其他节点发送的事务的操作集合之后,解析出事务的相关数据,并采用相同的规则实现并发控制(也可以理解为是确定待提交的事务与待回滚的事务)。提交待提交的事务,回滚待回滚的事务。可以理解的是,后续第二节点的操作与第一节点类似,后续不再赘述。Exemplarily, continuing the above-mentioned example applied to the openGauss scenario, the first node parses out the relevant data of the transaction after receiving the operation set of the transaction sent by other nodes in the current period, and uses the same rule to implement concurrency control (or It is understood as determining the transaction to be committed and the transaction to be rolled back). Commit the transaction to be committed and roll back the transaction to be rolled back. It can be understood that the operation of the subsequent second node is similar to that of the first node, and will not be repeated hereafter.
步骤206,第二节点基于第一操作集合与第二操作集合更新第二数据库。Step 206, the second node updates the second database based on the first operation set and the second operation set.
第二节点在获取第一操作集合与第二操作集合之后,第二节点可以基于第一操作集合与第二操作集合更新第二数据库。具体的,第二节点可以基于第一操作集合与第二操作集合先确定第二数据库待提交的事务,并在第二数据库中提交该待提交的事务。换句话说,第二节点可以基于第一操作集合确定第一节点中第一数据库中执行的操作,进而可以执行第一操作集合中的操作,使得第二数据库的更新已经考虑第一数据库的修改,从而保证数据库之间的数据同步。After the second node acquires the first operation set and the second operation set, the second node may update the second database based on the first operation set and the second operation set. Specifically, the second node may first determine the transaction to be submitted in the second database based on the first operation set and the second operation set, and submit the transaction to be submitted in the second database. In other words, the second node can determine the operations performed in the first database in the first node based on the first operation set, and then can execute the operations in the first operation set, so that the update of the second database has considered the modification of the first database , so as to ensure data synchronization between databases.
可选地,第二节点获取第二事务集合中每个事务的第二时间戳、第二标识或第二周期标识中的至少一项(或称为第二信息),并接收第一节点发送的第一时间戳、第一标识或第二周期标识中的至少一项(或称为第一信息)。第二节点可以基于第一操作集合、第一信息、第二操作集合以及第二信息确定第一事务集合与第二事务集合中待提交的事务,并在第二数据库中提交该待提交的事务,得到更新后的第二数据库。Optionally, the second node acquires at least one of the second time stamp, the second identifier, or the second periodic identifier (or called second information) of each transaction in the second transaction set, and receives the information sent by the first node. At least one of the first timestamp, the first identification, or the second period identification (or referred to as the first information) of . The second node may determine the 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 submit the transaction to be committed in the second database , to obtain the updated second database.
对于第一事务集合与第二事务集合中的事务存在重叠数据项、确定待提交的事务以及待回滚的事务等相关描述,可以参考前述步骤205中的描述,此处不再赘述。For descriptions about overlapping data items in 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, you can refer to the description in the aforementioned step 205 , which will not be repeated here.
可选地,第二节点在更新第二数据库之后,可以记录日志或更新快照。Optionally, after updating the second database, the second node may record a log or update a snapshot.
示例性的,延续之前的举例,第一事务集合包括:事务1与事务2,事务1:删除“孙五”。事务2:将“李六”的“收货地址”修改为“广东省深圳市南山区E街道F酒店801房”。第一事务集合的第一操作集合包括:删除操作与修改操作。第二操作集合包括:增加处理。第二事务包括:增加“周七”,“15789012345”,“广东省深圳市罗湖区第W小学”。则第二节点基于第一操作集合与第二操作集合更新第二数据库的流程如图4所示,更新后的第二数据库如图4中的表2所示。Exemplarily, continuing the previous example, the first transaction set includes: transaction 1 and transaction 2, transaction 1: delete "Sun Wu". Transaction 2: Change the "delivery address" of "Li Liu" to "Room 801, Hotel F, E Street, Nanshan District, Shenzhen, Guangdong Province". The first operation set of the first transaction set includes: delete operation and modification operation. The second set of operations includes: increment processing. The second transaction includes: adding "Sunday", "15789012345", "No. W Primary School, Luohu District, Shenzhen City, Guangdong Province". Then, the flow of updating the second database by the second node based on the first operation set and the second operation set is shown in FIG. 4 , and the updated second database is shown in Table 2 in FIG. 4 .
可以理解的是,本申请实施例并不限定上述各个步骤之间的时序。例如:步骤203可以在步骤202或步骤201之前。又例如:步骤206可以在步骤205之后等,具体此处不做限定。It can be understood that, the embodiment of the present application does not limit the time sequence between the above steps. For example: step 203 may be before step 202 or step 201 . Another example: step 206 may be after step 205, etc., which is not limited here.
另外,本步骤中的步骤201至步骤206可以周期性的执行,本申请实施例对步骤201至步骤206的执行次数可以是一次也可以是多次,具体此处不做限定。当然,若是周期性的执行,在上一个周期同步完成之前,新周期内的事务不能提交。In addition, steps 201 to 206 in this step may be executed periodically, and the number of executions of steps 201 to 206 in this embodiment of the present application may be one time or multiple times, which is not specifically limited here. Of course, if it is executed periodically, the transactions in the new cycle cannot be committed before the synchronization of the previous cycle is completed.
本申请实施例中,第一节点获取与第一数据库中第一事务集合相关的第一操作集合,接收第二节点发送的第二数据库中与第二事务集合相关的第二操作集合,并基于第一操作集合与第二操作集合更新第一数据库,使得第一数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。一方面,事务修改通过传输操作集合的方式在节点之间互相通知,不涉及节点之间的多次交互,通信开销小。另一方面,相较于二阶段提交方法,避免了协调者由于单点故障导致的事务无法操作。In the embodiment of the present application, the first node obtains the first operation set related to the first transaction set in the first database, receives the second operation set related to the second transaction set in the second database sent by the second node, and based on The first operation set and the second operation set update the first database, so that the update of the first database takes into account the transactions submitted by other databases, thereby ensuring the update synchronization between multiple databases. On the one hand, transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small. On the other hand, compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
上面对本申请实施例中的数据库处理方法进行了描述,下面对本申请实施例中的第一节点与第二节点进行描述,第一节点与第二节点应用于数据库系统,第一节点部署有第一数据库,第二节点部署有第二数据库,第一数据库与第二数据库存储有相同的数据。请参阅图5,本申请实施例中第一节点的一个实施例包括:The database processing method in the embodiment of the application is described above, and the first node and the second node in the embodiment of the application are described below. The first node and the second node are applied to the database system, and the first node is deployed with the first A database, the second node is deployed with a second database, and the first database and the second database store the same data. Please refer to Figure 5, an embodiment of the first node in the embodiment of the present application includes:
获取单元501,用于获取第一操作集合,第一操作集合为在目标时间段内第一数据库中第一事务集合的写操作或读写操作;An acquisition unit 501, configured to acquire a first operation set, where the first operation set is a write operation or a read-write operation of a first transaction set in the first database within a target time period;
发送单元502,用于向第二节点发送第一操作集合;a sending unit 502, configured to send the first operation set to the second node;
接收单元503,用于接收第二节点发送的第二操作集合,第二操作集合为在目标时间段内第二数据库中第二事务集合的写操作或读写操作,第一操作集合与第二操作集合用于第二节点更新第二数据库;The receiving unit 503 is configured to receive the second operation set sent by the second node, the second operation set is the write operation or read-write operation of the second transaction set in the second database within the target time period, the first operation set and the second The set of operations is used by the second node to update the second database;
更新单元504,用于基于第一操作集合与第二操作集合更新第一数据库。An updating unit 504, configured to update the first database based on the first operation set and the second operation set.
本实施例中,第一节点中各单元所执行的操作与前述图1至图4所示实施例中描述的类似,此处不再赘述。In this embodiment, the operations performed by each unit in the first node are similar to those described in the foregoing embodiments shown in FIG. 1 to FIG. 4 , and will not be repeated here.
本实施例中,数据库系统中的多个节点之间互相发送事务的操作集合,节点上数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。一方面,事务修改通过传输操作集合的方式在节点之间互相通知,不涉及节点之间的多次交互,通信开销小。另一方面,相较于二阶段提交方法,避免了协调者由于单点故障导致的事务无法操作。In this embodiment, multiple nodes in the database system send transaction operation sets to each other, and database updates on nodes take into account transactions submitted by other databases, thereby ensuring synchronization of updates between multiple databases. On the one hand, transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small. On the other hand, compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
请参阅图6,本申请实施例中第二节点的一个实施例包括:Please refer to Figure 6, an embodiment of the second node in the embodiment of the present application includes:
获取单元601,用于获取第二操作集合,第二操作集合为在目标时间段内第二数据库中第二事务集合的写操作或读写操作;An acquisition unit 601, configured to acquire a second operation set, where the second operation set is a write operation or a read-write operation of a second transaction set in the second database within a target time period;
发送单元602,用于向第一节点发送第二操作集合;a sending unit 602, configured to send the second operation set to the first node;
接收单元603,用于接收第一节点发送的第一操作集合,第一操作集合为在目标时间段内第一数据库中第一事务集合的写操作或读写操作,第一操作集合与第二操作集合用于第一节点更新第一数据库;The receiving unit 603 is configured to receive the first operation set sent by the first node, the first operation set is the write operation or read-write operation of the first transaction set in the first database within the target time period, the first operation set and the second The operation set is used for the first node to update the first database;
更新单元604,用于基于第一操作集合与第二操作集合更新第二数据库。An updating unit 604, configured to update the second database based on the first operation set and the second operation set.
本实施例中,第二节点中各单元所执行的操作与前述图1至图4所示实施例中描述的类似,此处不再赘述。In this embodiment, the operations performed by each unit in the second node are similar to those described in the foregoing embodiments shown in FIG. 1 to FIG. 4 , and will not be repeated here.
本实施例中,数据库系统中的多个节点之间互相发送事务的操作集合,节点上数据库的更新考虑到其他数据库所提交的事务,从而保证多个数据库之间的更新同步。一方面,事务修改通过传输操作集合的方式在节点之间互相通知,不涉及节点之间的多次交互,通信开销小。另一方面,相较于二阶段提交方法,避免了协调者由于单点故障导致的事务无法操作。In this embodiment, multiple nodes in the database system send transaction operation sets to each other, and database updates on nodes take into account transactions submitted by other databases, thereby ensuring synchronization of updates between multiple databases. On the one hand, transaction modification is notified between nodes through the transmission operation set, which does not involve multiple interactions between nodes, and the communication overhead is small. On the other hand, compared with the two-phase commit method, it avoids the inoperability of the transaction caused by the coordinator due to a single point of failure.
参阅图7,本申请提供的一种通信设备的结构示意图。该通信设备可以是前述图1至图4所示实施例中的第一节点或第二节点。该通信设备可以包括处理器701、存储器702和通信接口703。该处理器701、存储器702和通信接口703通过线路互联。其中,存储器702中存储有程序指令和数据。Referring to FIG. 7 , it is a schematic structural diagram of a communication device provided in this application. The communication device may be the first node or the second node in the foregoing embodiments shown in FIG. 1 to FIG. 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 the memory 702 .
一种可能实现的方式中,存储器702中存储了前述图1至图4对应的实施方式中,由第一节点执行的步骤对应的程序指令以及数据。处理器701,用于执行前述图1至图4所示实施例中任一实施例所示的由第一节点执行的步骤。通信接口703可以用于执行前述图1至图4所示实施例中任一实施例中第一节点执行的与获取、发送、接收相关的步骤。例如,通信接口703可以用于发送第一操作集合与第一信息、接收第二操作集合与第二信息。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 implementations corresponding to FIG. 1 to FIG. 4 . The processor 701 is configured to execute the steps performed by the first node shown in any one of the embodiments shown in FIGS. 1 to 4 . The communication interface 703 may be used to execute steps related to acquiring, sending, and receiving performed by the first node in any of the embodiments shown in FIGS. 1 to 4 . For example, the communication interface 703 may be used to send a first operation set and first information, and receive a second operation set and second information.
另一种可能实现的方式中,存储器702中存储了前述图1至图4对应的实施方式中,由第二节点执行的步骤对应的程序指令以及数据。处理器701,用于执行前述图1至图4所示实施例中任一实施例所示的由第二节点执行的步骤。通信接口703可以用于执行前述图1至图4所示实施例中任一实施例中第二节点执行的与获取、发送、接收相关的步骤。例如,通信接口703可以用于发送第二操作集合与第二信息、接收第一操作集合与第一信息。In another possible implementation manner, the memory 702 stores program instructions and data corresponding to the steps executed by the second node in the aforementioned implementation manners corresponding to FIG. 1 to FIG. 4 . The processor 701 is configured to execute the steps executed by the second node shown in any one of the embodiments shown in FIGS. 1 to 4 . The communication interface 703 may be used to execute steps related to acquiring, sending, and receiving performed by the second node in any of the embodiments shown in FIGS. 1 to 4 . For example, the communication interface 703 may be used to send the second operation set and the second information, and receive the first operation set and the first information.
可以理解的是,通信设备可以包括相对于图7更多或更少的部件,本申请对此仅仅是示例性说明,并不作限定。It can be understood that the communication device may include more or less components than those shown in FIG. 7 , and this application is only illustrative and not limiting.
另外,本申请实施例提供一种数据库系统,该数据库系统包括如前述图5所示的第一节点,和/或如前述图6所示的第二节点。或者该数据库系统包括如前述图7所示的通信设备。In addition, an embodiment of the present application provides a database system, and the database system includes the first node as shown in FIG. 5 and/or the second node as shown in FIG. 6 . Or the database system includes the communication device as shown in FIG. 7 above.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅 仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units may be fully or partially realized by software, hardware, firmware or any combination thereof.
当使用软件实现所述集成的单元时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(solid state disk,SSD))等。When the integrated units are implemented using software, they may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, all or part of the processes or functions according to the embodiments of the present invention will be generated. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website, computer, server or data center Transmission to another website site, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or a data center integrated with one or more available media. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (solid state disk, SSD)), etc.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,这仅仅是描述本申请的实施例中对相同属性的对象在描述时所采用的区分方式。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,以便包含一系列单元的过程、方法、系统、产品或设备不必限于那些单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它单元。The terms "first", "second" and the like in the specification and claims of the present application and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific sequence or sequence. It should be understood that the terms used in this way can be interchanged under appropriate circumstances, and this is merely a description of the manner in which objects with the same attribute are described in the embodiments of the present application. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, product, or apparatus comprising a series of elements is not necessarily limited to those elements, but may include elements not expressly included. Other elements listed explicitly or inherent to the process, method, product, or apparatus.

Claims (15)

  1. 一种数据库处理方法,其特征在于,所述方法应用于数据库系统,所述数据库系统包括第一节点与第二节点,所述第一节点部署有第一数据库,所述第二节点部署有第二数据库,所述第一数据库与所述第二数据库存储有相同的数据,所述方法包括:A database processing method, characterized in that 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, and the second node is deployed with a second node Two databases, the first database and the second database store the same data, and the method includes:
    所述第一节点获取第一操作集合,所述第一操作集合为在目标时间段内所述第一数据库中第一事务集合的写操作或读写操作;The first node acquires a first operation set, where the first operation set is a write operation or a read-write operation of a first transaction set in the first database within a target time period;
    所述第一节点向所述第二节点发送所述第一操作集合;the first node sends the first set of operations to the second node;
    所述第一节点接收所述第二节点发送的第二操作集合,所述第二操作集合为在所述目标时间段内所述第二数据库中第二事务集合的写操作或读写操作,所述第一操作集合与所述第二操作集合用于所述第二节点更新所述第二数据库;The first node receives a second operation set sent by the second node, the second operation set is a write operation or a read-write operation of a second transaction set in the second database within the target time period, The first operation set and the second operation set are used by the second node to update the second database;
    所述第一节点基于所述第一操作集合与所述第二操作集合更新所述第一数据库。The first node updates the first database based on the first set of operations and the second set of operations.
  2. 根据权利要求1所述的方法,其特征在于,所述第一节点获取第一操作集合,包括:The method according to claim 1, wherein said first node acquiring a first set of operations comprises:
    所述第一节点响应并执行第一用户对于所述第一数据库的操作指令;The first node responds to and executes an operation instruction of the first user on the first database;
    所述第一节点在执行所述操作指令的过程中记录所述第一用户对所述第一数据库中数据项的操作,得到所述第一操作集合。The first node records operations performed by the first user on data items in the first database during execution of the operation instructions to obtain the first operation set.
  3. 根据权利要求2所述的方法,其特征在于,所述操作指令为写指令,所述第一操作集合为写操作集合;或者,所述操作指令为读写指令,所述第一操作集合为读写操作集合或写操作集合。The method according to claim 2, wherein the operation instruction is a write instruction, and the first operation set is a write operation set; or, the operation instruction is a read and write instruction, and the first operation set is A collection of read and write operations or a collection of write operations.
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1 to 3, wherein the method further comprises:
    所述第一节点获取所述第一事务集合的第一信息,所述第一事务集合中每一个事务对应一个第一信息,所述第一信息包括第一标识,和/或第一时间戳;The first node obtains first information of the first transaction set, each transaction in the first transaction set corresponds to a first information, and the first information includes a first identifier, and/or a first timestamp ;
    所述第一节点向所述第二节点发送所述第一信息;the first node sends the first information to the second node;
    所述第一节点接收所述第二节点发送的第二信息,所述第二事务集合中每一个事务对应一个第二信息,所述第二信息包括第二标识,和/或第二时间戳;所述第一信息与所述第二信息用于所述第二节点更新所述第二数据库;The first node receives the second information sent by the second node, each transaction in the second transaction set corresponds to a second information, and the second information includes a second identifier and/or a second timestamp ; The first information and the second information are used by the second node to update the second database;
    所述第一节点基于所述第一操作集合与所述第二操作集合更新所述第一数据库,包括:The first node updating the first database based on the first operation set and the second operation set includes:
    所述第一节点基于所述第一操作集合、所述第一信息、所述第二操作集合以及所述第二信息更新所述第一数据库。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. 根据权利要求4所述的方法,其特征在于,所述第一节点基于所述第一操作集合、所述第一信息、所述第二操作集合以及所述第二信息更新所述第一数据库,包括:The method according to claim 4, wherein 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 ,include:
    所述第一节点基于所述第一操作集合、所述第一信息、所述第二操作集合以及所述第二信息确定所述第一事务集合与所述第二事务集合中待提交的事务;The first node determines the 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 ;
    所述第一节点在所述第一数据库中提交所述待提交的事务,得到更新后的第一数据库。The first node submits the transaction to be submitted in the first database to obtain an updated first database.
  6. 根据权利要求5所述的方法,其特征在于,所述第一事务集合中第一子事务的所述第一信息为所述第一时间戳,所述第二事务集合中第二子事务的所述第二信息为所述第二时间戳,所述第一子事务与所述第二子事务至少包括重叠的一个数据项,所述第一时间戳小于所述第二时间戳,所述第二子事务为不能提交的事务。The method according to claim 5, wherein the first information of the first sub-transaction in the first transaction set is the first timestamp, and the information of the second sub-transaction in the second transaction set The second information is the second timestamp, the first sub-transaction and the second sub-transaction include at least one overlapping data item, the first timestamp is smaller than the second timestamp, the The second subtransaction is a transaction that cannot be committed.
  7. 一种第一节点,其特征在于,所述第一节点应用于数据库系统,所述数据库系统还包 括第二节点,所述第一节点部署有第一数据库,所述第二节点部署有第二数据库,所述第一数据库与所述第二数据库存储有相同的数据,所述第一节点包括:A first node, wherein the first node is applied to a database system, and the database system further includes a second node, the first node is deployed with a first database, and the second node is deployed with a second A database, the first database and the second database store the same data, and the first node includes:
    获取单元,用于获取第一操作集合,所述第一操作集合为在目标时间段内所述第一数据库中第一事务集合的写操作或读写操作;An acquisition unit, configured to acquire a first operation set, where the first operation set is a write operation or a read-write operation of a first transaction set in the first database within a target time period;
    发送单元,用于向所述第二节点发送所述第一操作集合;a sending unit, configured to send the first operation set to the second node;
    接收单元,用于接收所述第二节点发送的第二操作集合,所述第二操作集合为在所述目标时间段内所述第二数据库中第二事务集合的写操作或读写操作,所述第一操作集合与所述第二操作集合用于所述第二节点更新所述第二数据库;a receiving unit, configured to receive a second operation set sent by the second node, the second operation set is a write operation or a read-write operation of a second transaction set in the second database within the target time period, The first operation set and the second operation set are used by the second node to update the second database;
    更新单元,用于基于所述第一操作集合与所述第二操作集合更新所述第一数据库。An updating unit, configured to update the first database based on the first operation set and the second operation set.
  8. 根据权利要求7所述的第一节点,其特征在于,所述获取单元,具体用于响应并执行第一用户对于所述第一数据库的操作指令;The first node according to claim 7, wherein the acquiring unit is specifically configured to respond to and execute an operation instruction of the first user on the first database;
    所述获取单元,具体用于在执行所述操作指令的过程中记录所述第一用户对所述第一数据库中数据项的操作,得到所述第一操作集合。The obtaining unit is specifically configured to record operations performed by the first user on data items in the first database during execution of the operation instructions, to obtain the first operation set.
  9. 根据权利要求8所述的第一节点,其特征在于,所述操作指令为写指令,所述第一操作集合为写操作集合;或者,所述操作指令为读写指令,所述第一操作集合为读写操作集合或写操作集合。The first node according to claim 8, wherein the operation instruction is a write instruction, and the first operation set is a write operation set; or, the operation instruction is a read and write instruction, and the first operation A collection is a collection of read and write operations or a collection of write operations.
  10. 根据权利要求7至9中任一项所述的第一节点,其特征在于,所述获取单元,还用于获取所述第一事务集合的第一信息,所述第一事务集合中每一个事务对应一个第一信息,所述第一信息包括第一标识,和/或第一时间戳;The first node according to any one of claims 7 to 9, wherein the obtaining unit is further configured to obtain the first information of the first transaction set, each of the first transaction set The transaction corresponds to a first piece of information, and the first piece of information includes a first identifier and/or a first time stamp;
    所述发送单元,还用于向所述第二节点发送所述第一信息;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, each transaction in the second transaction set corresponds to a second information, the second information includes a second identifier, and/or the second Two timestamps; the first information and the second information are used by the second node to update the second database;
    所述更新单元,具体用于基于所述第一操作集合、所述第一信息、所述第二操作集合以及所述第二信息更新所述第一数据库。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. 根据权利要求10所述的第一节点,其特征在于,所述更新单元,具体用于基于所述第一操作集合、所述第一信息、所述第二操作集合以及所述第二信息确定所述第一事务集合与所述第二事务集合中待提交的事务;The first node according to claim 10, wherein the updating unit is specifically configured to determine based on the first operation set, the first information, the second operation set, and the second information Transactions to be committed in the first transaction set and the second transaction set;
    所述更新单元,具体用于在所述第一数据库中提交所述待提交的事务,得到更新后的第一数据库。The update unit is specifically configured to submit the transaction to be submitted in the first database to obtain an updated first database.
  12. 根据权利要求11所述的第一节点,其特征在于,所述第一事务集合中第一子事务的所述第一信息为所述第一时间戳,所述第二事务集合中第二子事务的所述第二信息为所述第二时间戳,所述第一子事务与所述第二子事务至少包括重叠的一个数据项,所述第一时间戳小于所述第二时间戳,所述第二子事务为不能提交的事务。The first node according to claim 11, wherein the first information of the first sub-transaction in the first transaction set is the first timestamp, and the second sub-transaction in the second transaction set The second information of the transaction is the second timestamp, the first sub-transaction and the second sub-transaction include at least one overlapping data item, the first timestamp is smaller than the second timestamp, The second subtransaction is a transaction that cannot be committed.
  13. 一种第一节点,其特征在于,包括:处理器,所述处理器与存储器耦合,所述存储器用于存储程序或指令,当所述程序或指令被所述处理器执行时,使得所述第一节点执行如权利要求1至6中任一项所述的方法。A first node, characterized by comprising: a processor, the processor is coupled with a memory, and the memory is used to store a program or an instruction, and when the program or instruction is executed by the processor, the The first node executes the method according to any one of claims 1-6.
  14. 一种计算机存储介质,其特征在于,包括计算机指令,当所述计算机指令在电子设备 上运行时,使得所述电子设备执行如权利要求1至6中任一项所述的方法。A computer storage medium, characterized in that it includes computer instructions, and when the computer instructions are run on an electronic device, the electronic device is made to execute the method according to any one of claims 1 to 6.
  15. 一种计算机程序产品,其特征在于,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如权利要求1至6中任一项所述的方法。A computer program product, characterized in that, when the computer program product is run on a computer, the computer is made to execute the method according to any one of claims 1 to 6.
PCT/CN2022/126150 2021-12-31 2022-10-19 Database processing method and related device WO2023124431A1 (en)

Applications Claiming Priority (2)

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

Publications (1)

Publication Number Publication Date
WO2023124431A1 true WO2023124431A1 (en) 2023-07-06

Family

ID=86997473

Family Applications (1)

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

Country Status (2)

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

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080005189A1 (en) * 2006-06-30 2008-01-03 Fujitsu Limited Computer readable recording medium having stored therein database synchronizing process program, and apparatus for and method of performing database synchronizing process
CN106339408A (en) * 2016-08-10 2017-01-18 深圳中兴网信科技有限公司 Data synchronization method, data synchronization device and server
CN111597197A (en) * 2020-06-29 2020-08-28 腾讯科技(深圳)有限公司 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

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080005189A1 (en) * 2006-06-30 2008-01-03 Fujitsu Limited Computer readable recording medium having stored therein database synchronizing process program, and apparatus for and method of performing database synchronizing process
CN106339408A (en) * 2016-08-10 2017-01-18 深圳中兴网信科技有限公司 Data synchronization method, data synchronization device and server
CN111597197A (en) * 2020-06-29 2020-08-28 腾讯科技(深圳)有限公司 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
CN116414844A (en) 2023-07-11

Similar Documents

Publication Publication Date Title
CA3121919C (en) System and method for augmenting database applications with blockchain technology
JP7012158B2 (en) Systems and methods for heterogeneous database replication from remote servers
EP2932370B1 (en) System and method for performing a transaction in a massively parallel processing database
US9009116B2 (en) Systems and methods for synchronizing data in a cache and database
CN111159252B (en) Transaction execution method and device, computer equipment and storage medium
US8892509B2 (en) Systems and methods for a distributed in-memory database
US8117153B2 (en) Systems and methods for a distributed cache
US7693882B2 (en) Replicating data across the nodes in a cluster environment
CN102037463B (en) Log based replication of distributed transactions using globally acknowledged commits
JP2023546249A (en) Transaction processing methods, devices, computer equipment and computer programs
US11822540B2 (en) Data read method and apparatus, computer device, and storage medium
US20070239661A1 (en) Systems and methods for a distributed in-memory database and distributed cache
CN105684377A (en) System and method for creating a distributed transaction manager supporting repeatable read isolation level in a mpp database
CN103473318A (en) Distributed transaction security method for memory data grid
CN109710388A (en) Method for reading data, device, electronic equipment and storage medium
WO2022111188A1 (en) Transaction processing method, system, apparatus, device, storage medium, and program product
CN106569896A (en) Data distribution and parallel processing method and system
US7752225B2 (en) Replication and mapping mechanism for recreating memory durations
CN114157550B (en) Alliance block chain system based on conflict-free transaction merging
CN112104504B (en) Transaction management framework for large-scale resource access, design method and cloud platform
WO2023124431A1 (en) Database processing method and related device
US6772176B1 (en) Coordinating a distributed transaction between participants unable to follow a two-phase commit
WO2024027459A1 (en) Method and apparatus for creating global secondary index in distributed database
JPH07210436A (en) Distributed transaction processing system
Tabassum et al. A simulation of performance of commit protocols in distributed environment

Legal Events

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

Ref document number: 22913694

Country of ref document: EP

Kind code of ref document: A1