CN106598992B - Database operation method and device - Google Patents

Database operation method and device Download PDF

Info

Publication number
CN106598992B
CN106598992B CN201510675583.2A CN201510675583A CN106598992B CN 106598992 B CN106598992 B CN 106598992B CN 201510675583 A CN201510675583 A CN 201510675583A CN 106598992 B CN106598992 B CN 106598992B
Authority
CN
China
Prior art keywords
transaction
data items
database
current
state
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510675583.2A
Other languages
Chinese (zh)
Other versions
CN106598992A (en
Inventor
徐宜良
贾新华
李�灿
白涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing ZTE New Software Co Ltd
Original Assignee
Nanjing ZTE New Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing ZTE New Software Co Ltd filed Critical Nanjing ZTE New Software Co Ltd
Priority to CN201510675583.2A priority Critical patent/CN106598992B/en
Priority to PCT/CN2016/101464 priority patent/WO2017063520A1/en
Publication of CN106598992A publication Critical patent/CN106598992A/en
Application granted granted Critical
Publication of CN106598992B publication Critical patent/CN106598992B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • 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/2365Ensuring data consistency and integrity

Abstract

The invention provides an operation method and device of a database. The method comprises the following steps: receiving first transaction information and a current transaction snapshot at a first time, the current transaction snapshot including: the identification and the state of the transaction which has started to be executed in the database set at the first moment; judging whether a target transaction exists in the transactions which are indicated by the identification and started to be executed, wherein the state of the target transaction is incomplete to be submitted, and the data items related to the target transaction comprise part or all of the data items related to the first transaction; if the target transaction exists in the transactions which have started to be executed, in the case that the operation indicated by the first transaction includes a delete operation and/or a modify operation, the operation indicated by the first transaction is executed on part or all of the data items involved in the first transaction after the state of the target transaction is converted to be complete for committing. The invention solves the problem that the data in the distributed transaction can not achieve global consistency.

Description

Database operation method and device
Technical Field
The invention relates to the field of communication, in particular to an operation method and device of a database.
Background
As the conventional database technology becomes mature and the internet application is developed at a high speed, the database application has been commonly found on the internet. The traditional centralized database system also shows the following defects: by adopting centralized management, a performance bottleneck is caused, the single improvement of hardware performance cannot meet the requirements of large data volume and concurrent query writing of the current internet, and a large amount of hardware maintenance and upgrading cost is generated. In addition, centralized management of databases often causes multiple database associations, and once a database crashes, the entire system crashes. Distributed database systems will gradually replace traditional centralized database systems.
Transactions are an important feature of relational databases, and as is well known, the ACID principle of a relational database transaction is as follows: atomicity (Atomicity), Consistency (Consistency), Isolation or independence (Isolation), and persistence (durabilly), where read Consistency of data is achieved through mechanisms of multi-version concurrency control (MVCC). With the rapid development of distributed databases, some functions and technologies that are mature and widely applied in centralized database systems have encountered great challenges in distributed environments, such as Transaction (Transaction) functions. To implement transaction functions in distributed databases, a two-phase commit protocol (2 PC) is currently commonly used in the industry.
As the name implies, a two-phase commit protocol consists of two phases. Under normal execution, the execution of these two phases is as follows:
stage 1: request phase (commit-request phase, or voting phase)
In the request phase, the coordinator will inform the transaction participants that the transaction is ready to commit or cancel and then enter the voting process. In the voting process, the participants will inform the coordinator of their own decisions: agree (transaction participant local job execution success) or cancel (local job execution failure).
And (2) stage: commit phase (commit phase)
At this stage, the coordinator will make a decision based on the voting results of the first stage: commit or cancel. All participants are notified by the coordinator to commit the transaction if and only if they agree to commit the transaction, otherwise all participants are notified by the coordinator to cancel the transaction. The participator will execute the responding operation after receiving the message sent by the coordinator.
The current two-phase commit protocol has a great disadvantage that the ACID principle of the transaction cannot be completely obeyed, that is, the Consistency (Consistency) problem of the transaction is not considered, so that the result of the query is not global Consistency. For example, for a node a and a node B of a distributed database system, if a transaction 1 updates data of the node a and the node B, the commit stage of the stage 2 is entered, that is, the state at this time is: if a transaction 2 exists at the moment to inquire the node A and the node B, the inquiry result violates the consistency principle of the transactions, namely the inquiry on the node A is to obtain the modified data, and the inquiry on the node B is to obtain the data before modification. Because the two-phase commit protocol has a time difference of transaction commit in the distributed database system, the two-phase commit protocol cannot avoid the global inconsistency problem of the data.
In summary, in the existing distributed database system, how to solve the global consistency problem of data by using a distributed transaction implemented by a two-phase commit protocol has no effective solution in the related art.
Disclosure of Invention
The invention provides an operation method and device of a database, which at least solve the problem that data in distributed transactions in the related technology cannot achieve global consistency.
According to an aspect of the present invention, there is provided an operation method of a database, including: receiving first transaction information and a current transaction snapshot at a first time, wherein the first transaction information is used for indicating that an operation indicated by a first transaction is executed on at least a first database, and the current transaction snapshot comprises: the method comprises the steps that at a first moment, the identification and the state of a transaction which is started to be executed in a database set are carried out, and the database set comprises one or more databases including a first database; judging whether a target transaction exists in the indicated transactions which are started to be executed or not, wherein the state of the target transaction is incomplete to be submitted, and the data items related to the target transaction comprise part or all of the data items related to the first transaction; if the target transaction exists in the transactions which have started to be executed, in the case that the operation indicated by the first transaction includes a delete operation and/or a modify operation, the operation indicated by the first transaction is executed on part or all of the data items involved in the first transaction after the state of the target transaction is converted to be complete for committing.
Optionally, determining whether the target transaction exists in the indicated transactions that have started to be executed comprises: under the condition that the current affairs in the affairs which are started to be executed execute the operation indicated by the current affairs on the current database in the database set, judging whether the current affairs are completely submitted on each current database, wherein the current database is one or more databases; if the current transaction is judged not to be completed on each current database, setting the state of the current transaction as incomplete submission; determining whether the data items performing the operation indicated by the current transaction that did not complete commit include some or all of the data items performing the operation indicated by the first transaction; and if the part or all of the data items for executing the operation indicated by the first transaction are included, taking the current transaction as one of the target transactions, and judging that the target transaction exists.
Optionally, performing the operation indicated by the first transaction on part or all of the data items involved in the first transaction after the state of the target transaction transitions to complete commit comprises at least one of: when the operation indicated by the first transaction is to execute a deletion operation on a second data item set in the first database, deleting the data items except for part or all of the data items in the second data item set, and deleting the part or all of the data items after the state of the target transaction is converted into the state of being completed and submitted; when the operation indicated by the first transaction is to execute deletion operation on a second data item set in the first database, deleting the data items except part or all of the data items in the second data item set, judging whether the part or all of the data items meet deletion conditions which are carried in the first transaction information and correspond to the deletion operation after the state of the target transaction is converted into the state of being submitted, and deleting the data items which meet the deletion conditions in the part or all of the data items; when the operation indicated by the first transaction is to execute a modification operation on a third data item set in the first database, executing the modification operation on the data items except for part or all of the data items in the third data item set, and executing the modification operation on the part or all of the data items after the state of the target transaction is converted into the completed commit; when the operation indicated by the first transaction is to perform modification operation on a third data item set in the first database, performing modification operation on the data items except for part or all of the data items in the third data item set, judging whether the part or all of the data items meet modification conditions corresponding to the modification operation and carried in the first transaction information after the state of the target transaction is converted into complete submission, and performing modification operation on the data items meeting the modification conditions in the part or all of the data items.
Optionally, if there is a target transaction in the transactions that have started to be executed, the method further includes: when the operation indicated by the first transaction is to execute a query operation on the first data item set in the first database, returning the current information of the data items except part or all of the data items in the first data item set, and returning the historical information of the part or all of the data items in the first data item set.
Optionally, returning the current information of the data items in the first data item set except for part or all of the data items comprises: after the state of the target transaction transitions to complete commit, current information for some or all of the data items is returned.
Optionally, returning history information of some or all of the data items in the first set of data items comprises: after the state of the target transaction transitions to complete commit, some or all of the historical information for the data item is returned.
Optionally, the databases in the database collection are distributed databases.
According to another aspect of the present invention, there is provided an operating apparatus of a database, including: the data processing device comprises a receiving unit, a processing unit and a processing unit, wherein the receiving unit is used for receiving first transaction information and a current transaction snapshot at a first time, the first transaction information is used for indicating that an operation indicated by a first transaction is executed at least on a first database, and the current transaction snapshot comprises: the method comprises the steps that at a first moment, the identification and the state of a transaction which is started to be executed in a database set are carried out, and the database set comprises one or more databases including a first database; the judging unit is used for judging whether a target transaction exists in the transactions which are indicated by the identification and started to be executed, wherein the state of the target transaction is incomplete to be submitted, and the data items related to the target transaction comprise part or all of the data items related to the first transaction; and the processing unit is used for executing the operation indicated by the first transaction to part or all of the data items related to the first transaction after the state of the target transaction is converted into the completed submission when the target transaction exists in the transactions which have started to be executed and the operation indicated by the first transaction comprises a deleting operation and/or a modifying operation.
Optionally, the judging unit includes: the first judging module is used for judging whether the current affairs are completely submitted on each current database or not under the condition that the current affairs in the started affairs execute the operation indicated by the current affairs on the current databases in the database set, wherein the current databases are one or more databases; the setting module is used for setting the state of the current transaction as incomplete submission when judging that the current transaction is not completed on each current database; the second judging module is used for judging whether the data items for executing the operation indicated by the incomplete submitted current transaction comprise part or all of the data items for executing the operation indicated by the first transaction; and the determining module is used for taking the current transaction as one of the target transactions and judging that the target transaction exists when judging that part or all of the data items including the operation indicated by the first transaction are executed.
Optionally, the processing unit comprises at least one of: the first processing module is used for deleting some or all of the data items in the second data item set when the operation indicated by the first transaction is to execute deletion operation on the second data item set in the first database, and deleting some or all of the data items after the state of the target transaction is converted into complete commit; or when the operation indicated by the first transaction is to execute deletion operation on a second data item set in the first database, deleting the data items except for part or all of the data items in the second data item set, judging whether the part or all of the data items meet deletion conditions corresponding to the deletion operation carried in the first transaction information after the state of the target transaction is converted into the state of being submitted, and deleting the data items meeting the deletion conditions in the part or all of the data items; the second processing module is used for executing modification operation on the data items except for part or all of the data items in the third data item set when the operation indicated by the first transaction is to execute modification operation on the third data item set in the first database, and executing modification operation on part or all of the data items after the state of the target transaction is converted into complete commit; or when the operation indicated by the first transaction is to perform a modification operation on a third data item set in the first database, performing the modification operation on the data items except for part or all of the data items in the third data item set, judging whether part or all of the data items meet the modification condition corresponding to the modification operation carried in the first transaction information after the state of the target transaction is converted into the complete commit, and performing the modification operation on the data items meeting the modification condition in part or all of the data items.
Optionally, the method further comprises: and the third processing module is used for returning the current information of the data items except part or all of the first data item set and returning the historical information of part or all of the data items in the first data item set when the target transaction exists in the transactions which have started to be executed and the operation indicated by the first transaction is the query operation performed on the first data item set in the first database.
Optionally, the third processing module comprises: and the first processing submodule is used for returning partial or all current information of the data item after the state of the target transaction is converted into the completed submission.
Optionally, the third processing module comprises: and the second processing submodule is used for returning the history information of part or all of the data items after the state of the target transaction is converted into the completed submission.
Optionally, the databases in the database collection are distributed databases.
According to the invention, first transaction information and a current transaction snapshot are received at a first moment, wherein the current transaction snapshot comprises the identification and the state of the transaction which is started to be executed in the database set at the first moment. By judging whether the target transaction with the state of incomplete commit exists in the transactions which are started to be executed or not, if the target transaction exists in the transactions which are started to be executed, the operation indicated by the first transaction is executed on part or all of the data items related to the first transaction after the state of the target transaction is converted into the state of complete commit, so that the operation of global consistency of all the transactions at the first moment is realized.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
FIG. 1 is a flow chart of an alternative method of operation of a database in accordance with an embodiment of the present invention;
FIG. 2 is a schematic diagram illustrating an application of an alternative database operation method according to an embodiment of the present invention;
FIG. 3 is a flow chart of an alternative method of operation of a database in accordance with an embodiment of the present invention;
FIG. 4 is a flow chart of yet another alternative method of operation of a database in accordance with an embodiment of the present invention; and
fig. 5 is a schematic diagram of an alternative database operating apparatus according to an embodiment of the present invention.
Detailed Description
The invention will be described in detail hereinafter with reference to the accompanying drawings in conjunction with embodiments. It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
Example 1
In this embodiment, an operation method of a database is provided, and fig. 1 is a flowchart of an operation method of a database according to an embodiment of the present invention, as shown in fig. 1, the flowchart includes the following steps:
step S102, receiving first transaction information and a current transaction snapshot at a first time, wherein the first transaction information is used for indicating that an operation indicated by a first transaction is executed at least on a first database, and the current transaction snapshot comprises: the method comprises the steps that at a first moment, the identification and the state of a transaction which is started to be executed in a database set are carried out, and the database set comprises one or more databases including a first database;
step S104, judging whether the indicated transactions which have started to be executed have target transactions or not, wherein the state of the target transactions is incomplete submission, and the data items related to the target transactions comprise part or all of the data items related to the first transactions;
step S106, if there is a target transaction in the transactions that have started to be executed, if the operation indicated by the first transaction includes a delete operation and/or a modify operation, the operation indicated by the first transaction is executed on part or all of the data items involved in the first transaction after the state of the target transaction is converted to be complete for commit.
Optionally, in this embodiment, fig. 2 is an application schematic diagram of an optional database operation method according to an embodiment of the present invention, and the database operation method may be, but is not limited to, applied in an application environment as shown in fig. 2, where the client 202 implements link communication between the coordinator 204, the global transaction manager 206, and the database service 208 through a communication Protocol such as a Transmission Control Protocol (TCP) or a User Datagram Protocol (UDP). Database server 208 may include, but is not limited to, a database service node a and a database server node B. Each database service node in the database service 208 continuously reports the latest state of all the transactions therein to the global transaction manager 206, and meanwhile, a transaction snapshot of all the transactions of the distributed database system at the current time is obtained from the global transaction manager 206, so that whether a target transaction in an incomplete commit state is included in the transactions that have started to be executed is judged through the transaction snapshot, thereby achieving the purpose of completing the operation processing of the global consistency of the database data according to the state of the transaction, avoiding the problem that the global consistency of the data cannot be achieved when the transactions in different states in the distributed database system are operated, and further ensuring the global consistency of the data.
It should be noted that, in this embodiment, the functions of the coordinator 204, the global transaction manager 206, and the database service 208 in the application environment may be as follows:
1) the coordinator 204 may be, but is not limited to, configured to receive a request of a block of Structured Query Language (SQL) statements sent by the client 202; then applies for GXID (a unique and ordered transaction ID, abbreviated as GXID) from the global transaction manager 206; reporting the transaction snapshot of the current transaction to the global transaction manager 206; and sends SQL to multiple database server nodes (e.g., database service node a and database server node B) for execution, and summarizes the results of the SQL execution and returns the results to client 202.
2) The global transaction manager 206 is configured to generate a unique and ordered GXID for each transaction; the system is also used for monitoring and tracking the states of all transactions in the distributed database system, and receiving and storing the reported transaction state report; and responding to the transaction state request of the data service node, and sending the transaction snapshot at the current moment to the data service node.
3) The database service nodes in the database service 208 are used for executing SQL commands in parallel; and acquiring all transaction snapshot information in the distributed database system at the current moment from the global transaction manager 206, and performing processing operation of global consistency of data according to the transaction snapshots.
Optionally, in this embodiment, the state of the transaction that has started to be executed may include, but is not limited to, at least one of the following: running (running), committed (committed), aborted (aborted), where the data items involved in the target transaction in the incomplete commit state may include one or more.
Optionally, in this embodiment, the operation indicated by the first transaction may include, but is not limited to, at least one of the following: modify, delete, and query.
It should be noted that, in this embodiment, when there is a target transaction in the transactions that have started to be executed, if the operation indicated by the first transaction is to perform a delete operation and/or a modify operation on the data item, the delete operation and/or the modify operation indicated by the first transaction is executed on part or all of the data items related to the first transaction after the state of the target transaction is converted to complete commit; if the operation indicated by the first transaction is a query operation on the data item, current information obtained by querying the data item involved in the first transaction after the state of the target transaction is converted to complete commit may be returned, or history information obtained by querying the data item involved in the first transaction in the case that the state of the target transaction is not yet committed may be returned, where the history information obtained by querying may include, but is not limited to, result information of a last operation completed by the data item involved in the first transaction before the target transaction is executed.
Optionally, in this embodiment, the database in the database set may include, but is not limited to, a distributed database.
Optionally, in this embodiment, the transactions that have started to be executed may include, but are not limited to: a current transaction, wherein the current transaction is a transaction executed in the distributed database before a first transaction is executed.
Specifically, as described with reference to fig. 2, the operation method of the database may be as follows:
s1, a Global Transaction Manager (GTM) generates a unique and ordered Transaction ID for each Transaction in the distributed database system, which is called GXID; collecting and storing all transaction states in the distributed database system;
s2, when the GTM receives a new transaction request obtained by the coordinator node, a unique and ordered GXID is generated to the coordinator node;
s3, when the GTM receives a request that the database service node acquires the system transaction snapshot at the current moment, the GTM sends all collected and stored transaction states to the database service node;
and S4, the database service node receives the SQL statement, analyzes and executes the SQL statement, and returns an execution result.
Optionally, in this embodiment, in the preparation phase of the transaction start, transaction end, and two-phase commit protocol, the database service node sends a status report of the current transaction to the GTM.
Optionally, in this embodiment, when the query operation indicated by the first transaction is performed, the returning of the queried data item may include, but is not limited to, at least one of the following:
1) when the transaction isolation level is read committed, the database service node firstly requests the GTM for state snapshots of all transactions of the whole distributed database system at the current time when executing each SQL statement of the first transaction;
2) when the transaction isolation level is repeatable read (readable) and serialization (serializable), the database service node requests the GTM for a state snapshot of all transactions of the whole distributed database system at the current time when the current transaction starts.
By the embodiment provided by the application, the first transaction information and the current transaction snapshot are received at the first time, wherein the current transaction snapshot comprises the identification and the state of the transaction which is started to be executed in the database set at the first time. By judging whether the target transaction with the state of incomplete commit exists in the transactions which are started to be executed or not, if the target transaction exists in the transactions which are started to be executed, the operation indicated by the first transaction is executed on part or all of the data items related to the first transaction after the state of the target transaction is converted into the state of complete commit, so that the operation of global consistency of all the transactions at the first moment is realized.
As an alternative, determining whether the target transaction exists in the indicated transactions that have begun execution includes:
s1, under the condition that the current affair in the affairs which have started to be executed executes the operation indicated by the current affair on the current database in the database set, judging whether the current affair is completely submitted on each current database, wherein the current database is one or more databases;
s2, if the current affair is judged not to be completed on each current database, the state of the current affair is set as incomplete submission;
s3, judging whether the data item for executing the operation indicated by the incomplete committed current transaction comprises part or all of the data item for executing the operation indicated by the first transaction;
s4, if some or all of the data items indicated by the execution of the operation indicated by the first transaction are included, the current transaction is regarded as one of the target transactions, and it is determined that the target transaction exists.
Optionally, in this embodiment, the current database executing the current transaction may include, but is not limited to, one or more databases. When the current database is a plurality of databases, if at least one database does not complete the operation indicated by the current transaction, the current transaction is identified to be in an incomplete state, otherwise, the current transaction is identified to be in a complete state.
Optionally, in this embodiment, after determining that the current transaction is in an incomplete commit state, it is determined whether the data item involved in the current transaction includes part or all of the data item involved in the operation indicated by the first transaction, and if the determination result is yes, it is determined that the current transaction is the target transaction. Further, the above judgment is repeatedly executed on other transactions in the transactions which have started to be executed, so as to obtain all target transactions in the transactions which have started to be executed, and thus, after the state of the data item in the target transaction is converted into the state which is completed to be submitted, the operation indicated by the first transaction is executed again.
According to the embodiment provided by the application, the target transaction in the transactions which are started to be executed is obtained, so that the waiting operation is executed on the target transaction when the operation indicated by the first transaction is executed until the state of the target transaction is converted into the state of being completed and submitted, the global consistency of the distributed database is controlled, and the problem of data inconsistency caused by the fact that different data are obtained from the distributed database is solved.
As an alternative, performing the operation indicated by the first transaction on part or all of the data items involved in the first transaction after the state of the target transaction transitions to complete commit comprises at least one of:
s1, when the operation indicated by the first transaction is to execute deletion operation on the second data item set in the first database, deleting the data items except part or all of the data items in the second data item set, and deleting the part or all of the data items after the state of the target transaction is converted into complete submission;
s2, when the operation indicated by the first transaction is to execute deletion operation on the second data item set in the first database, deleting the data items except part or all of the data items in the second data item set, judging whether the part or all of the data items meet deletion conditions corresponding to the deletion operation carried in the first transaction information after the state of the target transaction is converted into complete submission, and deleting the data items meeting the deletion conditions in the part or all of the data items;
s3, when the operation indicated by the first transaction is to execute modification operation on the third data item set in the first database, executing modification operation on the data items except part or all of the data items in the third data item set, and executing modification operation on part or all of the data items after the state of the target transaction is converted to be complete to commit;
s4, when the operation indicated by the first transaction is to execute modification operation on the third data item set in the first database, the modification operation is executed on the data items except for part or all of the data items in the third data item set, after the state of the target transaction is converted into complete submission, whether the part or all of the data items meet the modification condition corresponding to the modification operation carried in the first transaction information is judged, and the modification operation is executed on the data items meeting the modification condition in the part or all of the data items.
Optionally, in this embodiment, the operation indicated by the first transaction may include, but is not limited to, at least one of the following: delete operation, modify operation. In order to achieve the control operation of performing consistency on the data in the distributed database when part or all of the data items of the operation indicated by the first transaction are the data items involved in the target transaction, in the embodiment, after the state of the target transaction is converted into the complete commit, the operation indicated by the first transaction is performed on part or all of the data items involved in the operation indicated by the first transaction.
That is, when the operation indicated by the first transaction is to perform an operation on the second data item set in the first database, the operation indicated by the first transaction is directly performed on the data items in the second data item set except for part or all of the data items involved in the target transaction; and after the state of the target transaction is converted into committed, performing the operation indicated by the first transaction on part or all of the data items related to the target transaction in the second data item set. It should be noted that before performing the operation indicated by the first transaction on part or all of the data items involved in the target transaction in the second data item set, the method further includes: and judging whether part or all of the data items meet the operation conditions corresponding to the operation carried in the first transaction information, and executing the operation indicated by the first transaction on the data items meeting the operation conditions in the part or all of the data items after judging that the operation conditions are met.
For example, a transaction that has currently begun execution includes: transactions 1, 2 and 3, where the transactions 1 and 2 are target transactions, the data items involved in the transaction 1 include D1, D2, D3, D4 and D5, the data items involved in the transaction 2 include D2, D4, D5 and D6, the first transaction received at the first time is transaction 4, where the data items involved in the transaction 4 include D1, D2, D4 and D7, that is, the data items involved in the first transaction include partial data items in the target transaction, that is: d1, D2, D4, therefore, when performing the operation (e.g., modification) indicated by the first transaction on the data item, the modification operation is performed after waiting for the state of the target transaction to transition to the completed committed state.
As another example, the data items still involved in the first transaction include partial data items in the target transaction, namely: for example, D1, D2, and D4, before performing an operation (e.g., deletion) indicated by the first transaction on the data items D1, D2, and D4, it is further determined whether the data items satisfy a deletion condition corresponding to the deletion operation carried in the first transaction information, for example, the deletion condition is to delete the data items whose space occupied by the data is greater than 2M. Assuming that the data items D1, D2 are judged to satisfy the above-described deletion condition, the deletion operation indicated by the first transaction is performed on the data items D1, D2 satisfying the deletion condition.
According to the embodiment provided by the application, when the operation indicated by the first transaction includes the modification operation and the deletion operation of part or all of the data items in the target transaction, the modification operation or the deletion operation needs to be performed on the part or all of the data items after the state of the target transaction is converted into the state of being completed and submitted, so that the problem of inconsistency caused by acquiring data with different data item contents in the first transaction is avoided.
As an optional scheme, if there is a target transaction in the transactions that have started to be executed, the method further includes:
s1, when the operation indicated by the first transaction is to execute the query operation on the first data item set in the first database, returning the current information of the data items except part or all of the data items in the first data item set, and returning the history information of the part or all of the data items in the first data item set.
It should be noted that, when the operation indicated by the first transaction is a query operation, current information of the data items, except for part or all of the data items, obtained by query in the first data item set may be returned, and historical information of the part or all of the data items obtained by query in the first data item set may also be returned. The history information obtained by the query may include, but is not limited to, result information of a last operation completed by the data item involved in the first transaction before the target transaction is executed.
By the embodiment provided by the application, when the operation indicated by the first transaction comprises the query operation on part or all of the data items in the target transaction, if the operation of the current transaction is completed, the current information is returned, and if the operation of the current transaction is not completed, the historical information before the operation is returned.
As an optional scheme, returning current information of data items in the first data item set except for part or all of the data items, and returning history information of part or all of the data items in the first data item set includes:
s1, after the state of the target transaction transitions to complete commit, current information for some or all of the data items is returned.
Specifically, the following example is used for explanation, fig. 3 is a flowchart of an operation method of a database according to an embodiment of the present invention, and as shown in fig. 3, when the distributed transaction isolation level is repeatable (read repeatable) and serialization (serializable), the specific process is as follows:
step S301, a coordinator node receives an SQL statement block request sent by a client;
step S302, the coordinator node requests GXID and snapshots of all transactions at the current moment from the global transaction manager;
step S303, the global transaction manager sends the newly generated GXID and the transaction snapshot to the coordinator node;
and after receiving a new GXID request acquired by the coordinator node, the global transaction manager generates a unique and ordered GXID and sends the unique and ordered GXID to the coordinator node. While the global transaction manager saves the state information of this newly generated transaction.
The transaction snapshot refers to all transactions and state information in the whole distributed database system at the current time, and the states include: running (running), committed (committed), aborted (abort).
Step S304, the coordinator node sends the SQL statement block, the GXID and the transaction snapshot to a plurality of database service nodes;
the coordinator sends the SQL statement to a plurality of related database service nodes so that the plurality of database service nodes can execute the SQL query in parallel.
Step S305, the database service node executes a first SQL and carries out global consistency read operation according to the transaction snapshot;
and the database service node judges and realizes the global consistency reading of the data according to the snapshot information of all the transactions at the current moment.
Step S306, the coordinator node collects all database service node execution results and sends the results to the client;
step S307, the database service node continues to execute the next SQL, and performs global consistency read operation according to the transaction snapshot;
when the transaction isolation level is repeatable read (readable) and serialized (serialized), according to the ACID characteristics of the transaction, the global consistency judgment of the data is carried out only by using the transaction snapshot at the starting moment of the transaction, and the transaction snapshot is applied to the global transaction manager through the coordinator node and is acquired and transmitted to the database service node.
Step S308, the coordinator node collects all database service node execution results and sends the results to the client;
according to the embodiment provided by the application, the data global consistency reading is realized by acquiring the snapshots of all the transactions at the current time, namely the database service node judges and realizes the data global consistency reading by comparing and analyzing the transaction state of the database service node with all other transaction snapshots in the distributed database system at the current time.
As an optional scheme, returning current information of data items in the first data item set except for part or all of the data items, and returning history information of part or all of the data items in the first data item set includes:
s1, after the state of the target transaction is converted to complete commit, some or all of the history information of the data item is returned.
Specifically, the following example is used for explanation, fig. 4 is a flowchart of an operation method of a database according to an embodiment of the present invention, and as shown in fig. 4, a distributed transaction isolation level is a committed read (read committed), and a specific process is as follows:
step S401, a coordinator node receives an SQL statement block request sent by a client;
step S402, the coordinator node requests GXID and snapshots of all transactions at the current moment from the global transaction manager;
step S403, the global transaction manager sends the newly generated GXID and the transaction snapshot to the coordinator node;
and after receiving a new GXID request acquired by the coordinator node, the global transaction manager generates a unique and ordered GXID and sends the unique and ordered GXID to the coordinator node. While the global transaction manager saves the state information of this newly generated transaction.
The transaction snapshot refers to all transactions and state information in the whole distributed database system at the current time, and the states include: running (running), committed (committed), aborted (abort).
Step S404, the coordinator node sends the SQL statement block, the GXID and the transaction snapshot to a plurality of database service nodes;
the coordinator sends the SQL statement to a plurality of related database service nodes so that the plurality of database service nodes can execute the SQL query in parallel.
Step S405, the database service node executes a first SQL and carries out global consistency read operation according to the transaction snapshot;
and the database service node judges and realizes the global consistency reading of the data according to the snapshot information of all the transactions at the current moment.
Step S406, the coordinator node collects all database service node execution results and sends the results to the client;
step S407, before executing the next SQL, the database service node requests the snapshot of all the transactions at the current moment from the global transaction manager;
when the transaction isolation level is a committed read (read committed), according to the ACID characteristics of the transaction, the database service node first requests the global transaction manager for a state snapshot of all transactions of the whole distributed database system at the current time when executing each SQL statement of the current transaction.
Step S408, the global transaction manager sends the current transaction snapshot to the database service node;
step S409, the database service node executes the next SQL according to the transaction snapshot and carries out global consistency read operation;
and the database service node judges and realizes the global consistency reading of the data according to the snapshot information of all the transactions at the current moment.
And step S410, the coordinator node collects all database service node execution results and sends the results to the client.
In the embodiment, when the transaction isolation level is a committed read (read committed), the data global consistency read is realized by acquiring snapshots of all transactions at the current time, that is, the database service node judges that the data global consistency read is realized by comparing and analyzing the transaction state of the database service node with all other transaction snapshots in the distributed database system at the current time.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
Example 2
In this embodiment, an operation device of a database is further provided, and the device is used to implement the foregoing embodiments and preferred embodiments, and the description of the device that has been already made is omitted. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
FIG. 5 is a schematic diagram of an apparatus for operating a database according to an embodiment of the present invention, as shown in FIG. 5, the apparatus including
1) A receiving unit 502, configured to receive, at a first time, first transaction information and a current transaction snapshot, where the first transaction information is used to indicate that an operation indicated by a first transaction is performed on at least a first database, and the current transaction snapshot includes: the method comprises the steps that at a first moment, the identification and the state of a transaction which is started to be executed in a database set are carried out, and the database set comprises one or more databases including a first database;
2) a determining unit 504, configured to determine whether a target transaction exists in the transactions that have started to be executed and are indicated by the identifier, where a state of the target transaction is an incomplete commit, and the data items related to the target transaction include part or all of the data items related to the first transaction;
3) a processing unit 506, configured to, when there is a target transaction in the transactions that have started to be executed, execute the operation indicated by the first transaction on part or all of the data items involved in the first transaction after the state of the target transaction transitions to complete commit in a case where the operation indicated by the first transaction includes a delete operation and/or a modify operation.
Optionally, in this embodiment, fig. 2 is an application schematic diagram of an optional database operation method according to an embodiment of the present invention, and the database operation device may be applied to an application environment shown in fig. 2, but not limited to, the client 202 implements link communication among the coordinator 204, the global transaction manager 206, and the database service 208 through a communication Protocol such as a Transmission Control Protocol (TCP) or a User Datagram Protocol (UDP). Database server 208 may include, but is not limited to, a database service node a and a database server node B. Each database service node in the database service 208 continuously reports the latest state of all the transactions therein to the global transaction manager 206, and meanwhile, a transaction snapshot of all the transactions of the distributed database system at the current time is obtained from the global transaction manager 206, so that whether a target transaction in an incomplete commit state is included in the transactions that have started to be executed is judged through the transaction snapshot, thereby achieving the purpose of completing the operation processing of the global consistency of the database data according to the state of the transaction, avoiding the problem that the global consistency of the data cannot be achieved when the transactions in different states in the distributed database system are operated, and further ensuring the global consistency of the data.
It should be noted that, in this embodiment, the functions of the coordinator 204, the global transaction manager 206, and the database service 208 in the application environment may be as follows:
1) the coordinator 204 may be, but is not limited to, configured to receive a request of a block of Structured Query Language (SQL) statements sent by the client 202; then applies for GXID (a unique and ordered transaction ID, abbreviated as GXID) from the global transaction manager 206; reporting the transaction snapshot of the current transaction to the global transaction manager 206; and sends SQL to multiple database server nodes (e.g., database service node a and database server node B) for execution, and summarizes the results of the SQL execution and returns the results to client 202.
2) The global transaction manager 206 is configured to generate a unique and ordered GXID for each transaction; the system is also used for monitoring and tracking the states of all transactions in the distributed database system, and receiving and storing the reported transaction state report; and responding to the transaction state request of the data service node, and sending the transaction snapshot at the current moment to the data service node.
3) The database service nodes in the database service 208 are used for executing SQL commands in parallel; and acquiring all transaction snapshot information in the distributed database system at the current moment from the global transaction manager 206, and performing processing operation of global consistency of data according to the transaction snapshots.
Optionally, in this embodiment, the state of the transaction that has started to be executed may include, but is not limited to, at least one of the following: running (running), committed (committed), aborted (aborted), where the data items involved in the target transaction in the incomplete commit state may include one or more.
Optionally, in this embodiment, the operation indicated by the first transaction may include, but is not limited to, at least one of the following: modify, delete, and query.
It should be noted that, in this embodiment, when there is a target transaction in the transactions that have started to be executed, if the operation indicated by the first transaction is to perform a delete operation and/or a modify operation on the data item, the delete operation and/or the modify operation indicated by the first transaction is executed on part or all of the data items related to the first transaction after the state of the target transaction is converted to complete commit; if the operation indicated by the first transaction is a query operation on the data item, current information obtained by querying the data item involved in the first transaction after the state of the target transaction is converted to complete commit may be returned, or history information obtained by querying the data item involved in the first transaction in the case that the state of the target transaction is not yet committed may be returned, where the history information obtained by querying may include, but is not limited to, result information of a last operation completed by the data item involved in the first transaction before the target transaction is executed.
Optionally, in this embodiment, the database in the database set may include, but is not limited to, a distributed database.
Optionally, in this embodiment, the transactions that have started to be executed may include, but are not limited to: a current transaction, wherein the current transaction is a transaction executed in the distributed database before a first transaction is executed.
Specifically, as described with reference to fig. 2, the database operating device may be as follows:
s1, a Global Transaction Manager (GTM) generates a unique and ordered Transaction ID for each Transaction in the distributed database system, which is called GXID; collecting and storing all transaction states in the distributed database system;
s2, when the GTM receives a new transaction request obtained by the coordinator node, a unique and ordered GXID is generated to the coordinator node;
s3, when the GTM receives a request that the database service node acquires the system transaction snapshot at the current moment, the GTM sends all collected and stored transaction states to the database service node;
and S4, the database service node receives the SQL statement, analyzes and executes the SQL statement, and returns an execution result.
Optionally, in this embodiment, in the preparation phase of the transaction start, transaction end, and two-phase commit protocol, the database service node sends a status report of the current transaction to the GTM.
Optionally, in this embodiment, when the query operation indicated by the first transaction is performed, the returning of the queried data item may include, but is not limited to, at least one of the following:
1) when the transaction isolation level is read committed, the database service node firstly requests the GTM for state snapshots of all transactions of the whole distributed database system at the current time when executing each SQL statement of the first transaction;
2) when the transaction isolation level is repeatable read (readable) and serialization (serializable), the database service node requests the GTM for a state snapshot of all transactions of the whole distributed database system at the current time when the current transaction starts.
By the embodiment provided by the application, the first transaction information and the current transaction snapshot are received at the first time, wherein the current transaction snapshot comprises the identification and the state of the transaction which is started to be executed in the database set at the first time. By judging whether the target transaction with the state of incomplete commit exists in the transactions which are started to be executed or not, if the target transaction exists in the transactions which are started to be executed, the operation indicated by the first transaction is executed on part or all of the data items related to the first transaction after the state of the target transaction is converted into the state of complete commit, so that the operation of global consistency of all the transactions at the first moment is realized.
As an optional scheme, the determining unit includes:
1) the first judging module is used for judging whether the current affairs are completely submitted on each current database or not under the condition that the current affairs in the started affairs execute the operation indicated by the current affairs on the current databases in the database set, wherein the current databases are one or more databases;
2) the setting module is used for setting the state of the current transaction as incomplete submission when judging that the current transaction is not completed on each current database;
3) the second judging module is used for judging whether the data items for executing the operation indicated by the incomplete submitted current transaction comprise part or all of the data items for executing the operation indicated by the first transaction;
4) and the determining module is used for taking the current transaction as one of the target transactions and judging that the target transaction exists when judging that part or all of the data items including the operation indicated by the first transaction are executed.
Optionally, in this embodiment, the current database executing the current transaction may include, but is not limited to, one or more databases. When the current database is a plurality of databases, if at least one database does not complete the operation indicated by the current transaction, the current transaction is identified to be in an incomplete state, otherwise, the current transaction is identified to be in a complete state.
Optionally, in this embodiment, after determining that the current transaction is in an incomplete commit state, it is determined whether the data item involved in the current transaction includes part or all of the data item involved in the operation indicated by the first transaction, and if the determination result is yes, it is determined that the current transaction is the target transaction. Further, the above judgment is repeatedly executed on other transactions in the transactions which have started to be executed, so as to obtain all target transactions in the transactions which have started to be executed, and thus, after the state of the data item in the target transaction is converted into the state which is completed to be submitted, the operation indicated by the first transaction is executed again.
According to the embodiment provided by the application, the target transaction in the transactions which are started to be executed is obtained, so that the waiting operation is executed on the target transaction when the operation indicated by the first transaction is executed until the state of the target transaction is converted into the state of being completed and submitted, the global consistency of the distributed database is controlled, and the problem of data inconsistency caused by the fact that different data are obtained from the distributed database is solved.
As an alternative, the processing unit comprises at least one of:
1) the first processing module is used for deleting some or all of the data items in the second data item set when the operation indicated by the first transaction is to execute deletion operation on the second data item set in the first database, and deleting some or all of the data items after the state of the target transaction is converted into complete commit; or, when the operation indicated by the first transaction is to execute the deletion operation on a second data item set in the first database, deleting the data items except the part or all of the data items in the second data item set, judging whether the part or all of the data items satisfy a deletion condition corresponding to the deletion operation carried in the first transaction information after the state of the target transaction is converted into the complete commit, and deleting the data items satisfying the deletion condition in the part or all of the data items;
2) the second processing module is used for executing modification operation on the data items except for part or all of the data items in the third data item set when the operation indicated by the first transaction is to execute modification operation on the third data item set in the first database, and executing modification operation on part or all of the data items after the state of the target transaction is converted into complete commit; or, when the operation indicated by the first transaction is to perform the modification operation on a third data item set in the first database, performing the modification operation on the data items in the third data item set except for the part or all of the data items, judging whether the part or all of the data items satisfy a modification condition corresponding to the modification operation carried in the first transaction information after the state of the target transaction is converted into the complete commit, and performing the modification operation on the data items satisfying the modification condition in the part or all of the data items.
Optionally, in this embodiment, the operation indicated by the first transaction may include, but is not limited to, at least one of the following: delete operation, modify operation. In order to achieve the control operation of performing consistency on the data in the distributed database when part or all of the data items of the operation indicated by the first transaction are the data items involved in the target transaction, in the embodiment, after the state of the target transaction is converted into the complete commit, the operation indicated by the first transaction is performed on part or all of the data items involved in the operation indicated by the first transaction.
That is, when the operation indicated by the first transaction is to perform an operation on the second data item set in the first database, the operation indicated by the first transaction is directly performed on the data items in the second data item set except for part or all of the data items involved in the target transaction; and after the state of the target transaction is converted into committed, performing the operation indicated by the first transaction on part or all of the data items related to the target transaction in the second data item set. It should be noted that before performing the operation indicated by the first transaction on part or all of the data items involved in the target transaction in the second data item set, the method further includes: and judging whether part or all of the data items meet the operation conditions corresponding to the operation carried in the first transaction information, and executing the operation indicated by the first transaction on the data items meeting the operation conditions in the part or all of the data items after judging that the operation conditions are met.
For example, a transaction that has currently begun execution includes: transactions 1, 2 and 3, where the transactions 1 and 2 are target transactions, the data items involved in the transaction 1 include D1, D2, D3, D4 and D5, the data items involved in the transaction 2 include D2, D4, D5 and D6, the first transaction received at the first time is transaction 4, where the data items involved in the transaction 4 include D1, D2, D4 and D7, that is, the data items involved in the first transaction include partial data items in the target transaction, that is: d1, D2, D4, therefore, when performing the operation (e.g., modification) indicated by the first transaction on the data item, the modification operation is performed after waiting for the state of the target transaction to transition to the completed committed state.
As another example, the data items still involved in the first transaction include partial data items in the target transaction, namely: for example, D1, D2, and D4, before performing an operation (e.g., deletion) indicated by the first transaction on the data items D1, D2, and D4, it is further determined whether the data items satisfy a deletion condition corresponding to the deletion operation carried in the first transaction information, for example, the deletion condition is to delete the data items whose space occupied by the data is greater than 2M. Assuming that the data items D1, D2 are judged to satisfy the above-described deletion condition, the deletion operation indicated by the first transaction is performed on the data items D1, D2 satisfying the deletion condition.
According to the embodiment provided by the application, when the operation indicated by the first transaction includes the modification operation and the deletion operation of part or all of the data items in the target transaction, the modification operation or the deletion operation needs to be performed on the part or all of the data items after the state of the target transaction is converted into the state of being completed and submitted, so that the problem of inconsistency caused by acquiring data with different data item contents in the first transaction is avoided.
As an optional scheme, the method further comprises the following steps:
1) and the third processing module is used for returning the current information of the data items except part or all of the first data item set and returning the historical information of part or all of the data items in the first data item set when the target transaction exists in the transactions which have started to be executed and the operation indicated by the first transaction is the query operation on the first data item set in the first database.
It should be noted that, when the operation indicated by the first transaction is a query operation, current information of the data items, except for part or all of the data items, obtained by query in the first data item set may be returned, and historical information of the part or all of the data items obtained by query in the first data item set may also be returned. The history information obtained by the query may include, but is not limited to, result information of a last operation completed by the data item involved in the first transaction before the target transaction is executed.
By the embodiment provided by the application, when the operation indicated by the first transaction comprises the query operation on part or all of the data items in the target transaction, if the operation of the current transaction is completed, the current information is returned, and if the operation of the current transaction is not completed, the historical information before the operation is returned.
As an optional solution, the third processing module includes:
1) and the first processing submodule is used for returning partial or all current information of the data item after the state of the target transaction is converted into the completed submission.
Specifically, the following example is used for explanation, fig. 3 is a flowchart of an operation method of a database according to an embodiment of the present invention, and as shown in fig. 3, when the distributed transaction isolation level is repeatable (read repeatable) and serialization (serializable), the specific process is as follows:
step S301, a coordinator node receives an SQL statement block request sent by a client;
step S302, the coordinator node requests GXID and snapshots of all transactions at the current moment from the global transaction manager;
step S303, the global transaction manager sends the newly generated GXID and the transaction snapshot to the coordinator node;
and after receiving a new GXID request acquired by the coordinator node, the global transaction manager generates a unique and ordered GXID and sends the unique and ordered GXID to the coordinator node. While the global transaction manager saves the state information of this newly generated transaction.
The transaction snapshot refers to all transactions and state information in the whole distributed database system at the current time, and the states include: running (running), committed (committed), aborted (abort).
Step S304, the coordinator node sends the SQL statement block, the GXID and the transaction snapshot to a plurality of database service nodes;
the coordinator sends the SQL statement to a plurality of related database service nodes so that the plurality of database service nodes can execute the SQL query in parallel.
Step S305, the database service node executes a first SQL and carries out global consistency read operation according to the transaction snapshot;
and the database service node judges and realizes the global consistency reading of the data according to the snapshot information of all the transactions at the current moment.
Step S306, the coordinator node collects all database service node execution results and sends the results to the client;
step S307, the database service node continues to execute the next SQL, and performs global consistency read operation according to the transaction snapshot;
when the transaction isolation level is repeatable read (readable) and serialized (serialized), according to the ACID characteristics of the transaction, the global consistency judgment of the data is carried out only by using the transaction snapshot at the starting moment of the transaction, and the transaction snapshot is applied to the global transaction manager through the coordinator node and is acquired and transmitted to the database service node.
Step S308, the coordinator node collects all database service node execution results and sends the results to the client;
according to the embodiment provided by the application, the data global consistency reading is realized by acquiring the snapshots of all the transactions at the current time, namely the database service node judges and realizes the data global consistency reading by comparing and analyzing the transaction state of the database service node with all other transaction snapshots in the distributed database system at the current time.
As an optional solution, the third processing module includes:
1) and the second processing submodule is used for returning the history information of part or all of the data items after the state of the target transaction is converted into the completed submission.
Specifically, the following example is used for explanation, fig. 4 is a flowchart of an operation method of a database according to an embodiment of the present invention, and as shown in fig. 4, a distributed transaction isolation level is a committed read (read committed), and a specific process is as follows:
step S401, a coordinator node receives an SQL statement block request sent by a client;
step S402, the coordinator node requests GXID and snapshots of all transactions at the current moment from the global transaction manager;
step S403, the global transaction manager sends the newly generated GXID and the transaction snapshot to the coordinator node;
and after receiving a new GXID request acquired by the coordinator node, the global transaction manager generates a unique and ordered GXID and sends the unique and ordered GXID to the coordinator node. While the global transaction manager saves the state information of this newly generated transaction.
The transaction snapshot refers to all transactions and state information in the whole distributed database system at the current time, and the states include: running (running), committed (committed), aborted (abort).
Step S404, the coordinator node sends the SQL statement block, the GXID and the transaction snapshot to a plurality of database service nodes;
the coordinator sends the SQL statement to a plurality of related database service nodes so that the plurality of database service nodes can execute the SQL query in parallel.
Step S405, the database service node executes a first SQL and carries out global consistency read operation according to the transaction snapshot;
and the database service node judges and realizes the global consistency reading of the data according to the snapshot information of all the transactions at the current moment.
Step S406, the coordinator node collects all database service node execution results and sends the results to the client;
step S407, before executing the next SQL, the database service node requests the snapshot of all the transactions at the current moment from the global transaction manager;
when the transaction isolation level is a committed read (read committed), according to the ACID characteristics of the transaction, the database service node first requests the global transaction manager for a state snapshot of all transactions of the whole distributed database system at the current time when executing each SQL statement of the current transaction.
Step S408, the global transaction manager sends the current transaction snapshot to the database service node;
step S409, the database service node executes the next SQL according to the transaction snapshot and carries out global consistency read operation;
and the database service node judges and realizes the global consistency reading of the data according to the snapshot information of all the transactions at the current moment.
And step S410, the coordinator node collects all database service node execution results and sends the results to the client.
In the embodiment, when the transaction isolation level is a committed read (read committed), the data global consistency read is realized by acquiring snapshots of all transactions at the current time, that is, the database service node judges that the data global consistency read is realized by comparing and analyzing the transaction state of the database service node with all other transaction snapshots in the distributed database system at the current time.
It should be noted that, the above modules may be implemented by software or hardware, and for the latter, the following may be implemented, but not limited to: the modules are all positioned in the same processor; alternatively, the modules are respectively located in a plurality of processors.
Example 3
The embodiment of the invention also provides a storage medium. Alternatively, in the present embodiment, the storage medium may be configured to store program codes for performing the following steps:
s1, receiving first transaction information and a current transaction snapshot at a first time, wherein the first transaction information is used for indicating that an operation indicated by the first transaction is executed at least on the first database, and the current transaction snapshot comprises: the method comprises the steps that at a first moment, the identification and the state of a transaction which is started to be executed in a database set are carried out, and the database set comprises one or more databases including a first database;
s2, judging whether the indicated transactions which have started to be executed have target transactions or not, wherein the state of the target transactions is incomplete submission, and the data items related to the target transactions comprise part or all of the data items related to the first transactions;
s3, if there is a target transaction in the transactions that have started to be executed, in the case that the operation indicated by the first transaction includes a delete operation and/or a modify operation, the operation indicated by the first transaction is executed on part or all of the data items involved in the first transaction after the state of the target transaction has transitioned to be committed.
Optionally, in this embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation manners, and this embodiment is not described herein again.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (12)

1. A method of operating a database, comprising:
receiving first transaction information and a current transaction snapshot at a first time, wherein the first transaction information is used for indicating that an operation indicated by a first transaction is executed on at least a first database, and the current transaction snapshot comprises: the identification and the state of the transaction which is started to be executed in a database set at the first moment, wherein the database set comprises one or more databases including the first database, and the databases in the database set are distributed databases;
judging whether a target transaction exists in the started transactions indicated by the identification, wherein the state of the target transaction is incomplete submission, and the data items related to the target transaction comprise part or all of the data items related to the first transaction;
if the target transaction exists in the transactions which have started to be executed, in the case that the operation indicated by the first transaction includes a delete operation and/or a modify operation, the operation indicated by the first transaction is executed on the part or all of the data items involved in the first transaction after the state of the target transaction is converted to be complete for committing.
2. The method of claim 1, wherein the determining whether a target transaction exists in the started transactions indicated by the identification comprises:
under the condition that a current transaction in the started transactions executes the operation indicated by the current transaction on a current database in the database set, judging whether the current transaction is completely submitted on each current database, wherein the current database is one or more databases;
if the current transaction is judged not to be completed on each current database, setting the state of the current transaction as incomplete commit;
determining whether the data items performing the operation indicated by the current transaction that is not complete to commit include some or all of the data items performing the operation indicated by the first transaction;
and if the part or all of the data items for executing the operation indicated by the first transaction are included, taking the current transaction as one of the target transactions, and judging that the target transaction exists.
3. The method of claim 1, wherein performing the operation indicated by the first transaction on the portion or all of the data items involved in the first transaction after the state of the target transaction transitions to complete commit comprises at least one of:
when the operation indicated by the first transaction is to execute the deletion operation on a second data item set in the first database, deleting the data items except the part or all of the data items in the second data item set, and deleting the part or all of the data items after the state of the target transaction is converted into the complete commit;
when the operation indicated by the first transaction is to execute the deletion operation on a second data item set in the first database, deleting the data items except the part or all of the data items in the second data item set, judging whether the part or all of the data items meet a deletion condition which is carried in the first transaction information and corresponds to the deletion operation after the state of the target transaction is converted into the complete submission, and deleting the data items which meet the deletion condition in the part or all of the data items;
when the operation indicated by the first transaction is to perform the modification operation on a third set of data items in the first database, performing the modification operation on the data items in the third set of data items except for the partial or all data items, and performing the modification operation on the partial or all data items after the state of the target transaction is converted to be complete for commit;
when the operation indicated by the first transaction is to perform the modification operation on a third data item set in the first database, performing the modification operation on the data items in the third data item set except the partial or all data items, judging whether the partial or all data items meet the modification condition corresponding to the modification operation carried in the first transaction information after the state of the target transaction is converted into the complete commit, and performing the modification operation on the data items meeting the modification condition in the partial or all data items.
4. The method of claim 1, wherein if the target transaction exists in the started transactions, the method further comprises:
when the operation indicated by the first transaction is to execute a query operation on a first data item set in the first database, returning current information of data items in the first data item set except the part or all of the data items, and returning historical information of the part or all of the data items in the first data item set.
5. The method of claim 4, wherein returning current information for data items in the first set of data items other than the portion or all of the data items comprises:
returning current information of the partial or all data items after the state of the target transaction transitions to completed commit.
6. The method of claim 4, wherein returning historical information for the portion or all of the data items in the first set of data items comprises:
returning the history information for the partial or all data items after the state transition of the target transaction has completed committing.
7. An apparatus for operating a database, the apparatus comprising:
a receiving unit, configured to receive, at a first time, first transaction information and a current transaction snapshot, where the first transaction information is used to indicate that an operation indicated by a first transaction is performed on at least a first database, and the current transaction snapshot includes: the identification and status of transactions that have begun execution in a database set at the first time, the database set being one or more databases including the first database;
a determining unit, configured to determine whether a target transaction exists in the transactions that have started to be executed and are indicated by the identifier, where a state of the target transaction is an incomplete commit, a data item related to the target transaction includes part or all of data items related to the first transaction, and a database in the database set is a distributed database;
and the processing unit is used for executing the operation indicated by the first transaction on the part or all of the data items related to the first transaction after the state of the target transaction is converted into the complete commit under the condition that the operation indicated by the first transaction comprises a deletion operation and/or a modification operation when the target transaction exists in the transactions which have started to be executed.
8. The apparatus according to claim 7, wherein the judging unit includes:
a first judging module, configured to, when a current transaction in the started executed transactions performs an operation indicated by the current transaction on a current database in the database set, judge whether the current transaction has completed commit on each of the current databases, where the current databases are one or more databases;
the setting module is used for setting the state of the current transaction as incomplete commit when judging that the current transaction is not completed in each current database;
the second judging module is used for judging whether the data items for executing the operation indicated by the incomplete submitted current transaction comprise part or all of the data items for executing the operation indicated by the first transaction;
and the determining module is used for taking the current transaction as one of the target transactions and judging that the target transaction exists when judging that part or all of the data items including the operation indicated by the first transaction are executed.
9. The apparatus of claim 7, wherein the processing unit comprises at least one of:
a first processing module, configured to delete, when an operation indicated by the first transaction is to perform the deletion operation on a second set of data items in the first database, data items in the second set of data items except for the part or all of the data items, and delete, after the state of the target transaction is converted to have been committed, the part or all of the data items; or, when the operation indicated by the first transaction is to execute the deletion operation on a second data item set in the first database, deleting the data items except the part or all of the data items in the second data item set, judging whether the part or all of the data items satisfy a deletion condition corresponding to the deletion operation carried in the first transaction information after the state of the target transaction is converted into the complete commit, and deleting the data items satisfying the deletion condition in the part or all of the data items;
a second processing module, configured to, when the operation indicated by the first transaction is to perform the modification operation on a third set of data items in the first database, perform the modification operation on the data items in the third set of data items except for the part or all of the data items, and perform the modification operation on the part or all of the data items after the state of the target transaction is changed to complete commit; or, when the operation indicated by the first transaction is to perform the modification operation on a third data item set in the first database, performing the modification operation on the data items in the third data item set except for the part or all of the data items, judging whether the part or all of the data items satisfy a modification condition corresponding to the modification operation carried in the first transaction information after the state of the target transaction is converted into the complete commit, and performing the modification operation on the data items satisfying the modification condition in the part or all of the data items.
10. The apparatus of claim 7, further comprising:
and a third processing module, configured to, when the target transaction exists in the transactions that have started to be executed, and an operation indicated by the first transaction is a query operation performed on a first data item set in the first database, return current information of data items in the first data item set, except for the part or all of the data items, and return history information of the part or all of the data items in the first data item set.
11. The apparatus of claim 10, wherein the third processing module comprises:
and the first processing submodule is used for returning the current information of the partial or all data items after the state of the target transaction is converted into the completed submission.
12. The apparatus of claim 10, wherein the third processing module comprises:
and the second processing submodule is used for returning the history information of the partial or all data items after the state of the target transaction is converted into the completed submission.
CN201510675583.2A 2015-10-15 2015-10-15 Database operation method and device Active CN106598992B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201510675583.2A CN106598992B (en) 2015-10-15 2015-10-15 Database operation method and device
PCT/CN2016/101464 WO2017063520A1 (en) 2015-10-15 2016-10-08 Method and apparatus for operating database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510675583.2A CN106598992B (en) 2015-10-15 2015-10-15 Database operation method and device

Publications (2)

Publication Number Publication Date
CN106598992A CN106598992A (en) 2017-04-26
CN106598992B true CN106598992B (en) 2020-10-23

Family

ID=58517765

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510675583.2A Active CN106598992B (en) 2015-10-15 2015-10-15 Database operation method and device

Country Status (2)

Country Link
CN (1) CN106598992B (en)
WO (1) WO2017063520A1 (en)

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP6924898B2 (en) * 2017-06-05 2021-08-25 華為技術有限公司Huawei Technologies Co.,Ltd. Transaction processing methods, devices and devices
CN109408201B (en) * 2017-08-18 2022-07-12 中国银联股份有限公司 Transaction management method based on distributed database
US10810268B2 (en) * 2017-12-06 2020-10-20 Futurewei Technologies, Inc. High-throughput distributed transaction management for globally consistent sharded OLTP system and method of implementing
CN108628666B (en) * 2018-05-08 2023-11-14 腾讯科技(上海)有限公司 Transaction processing method and device, storage medium and electronic device
CN109271398B (en) * 2018-10-29 2020-06-23 东软集团股份有限公司 Database transaction processing method, device, equipment and computer readable storage medium
CN111159585B (en) * 2018-11-07 2023-09-22 中国移动通信集团重庆有限公司 Method, device, equipment and medium for automatically submitting data
CN109710388B (en) * 2019-01-09 2022-10-21 腾讯科技(深圳)有限公司 Data reading method and device, electronic equipment and storage medium
CN111190935B (en) 2019-08-27 2022-10-14 中国人民大学 Data reading method and device, computer equipment and storage medium
CN110765178B (en) * 2019-10-18 2021-03-05 京东数字科技控股有限公司 Distributed transaction processing method and device and computer storage medium
CN112988883B (en) * 2019-12-16 2023-03-10 金篆信科有限责任公司 Database data synchronization method and device and storage medium
CN111143389B (en) * 2019-12-27 2022-08-05 腾讯科技(深圳)有限公司 Transaction execution method and device, computer equipment and storage medium
CN112100208A (en) * 2020-09-08 2020-12-18 北京金山云网络技术有限公司 Operation request forwarding method and device
CN112231144A (en) * 2020-09-29 2021-01-15 上海艾融软件股份有限公司 Data processing method and device and electronic equipment
CN113868278B (en) * 2021-09-29 2023-08-01 北京有竹居网络技术有限公司 Data processing method, device and equipment
CN113821382B (en) * 2021-11-24 2022-03-01 西安热工研究院有限公司 Real-time database data processing method, system and equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102317913A (en) * 2011-07-30 2012-01-11 华为技术有限公司 Transaction recovery method and apparatus
CN103559245A (en) * 2013-10-29 2014-02-05 华为技术有限公司 Distributed transaction committing failure handling method, device and system
CN104885054A (en) * 2013-03-13 2015-09-02 华为技术有限公司 System and method for performing a transaction in a massively parallel processing database

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130036089A1 (en) * 2011-08-01 2013-02-07 Tagged, Inc. Systems and methods for asynchronous distributed database management
CN103036717B (en) * 2012-12-12 2015-11-04 北京邮电大学 The consistency maintenance system and method for distributed data
US9569122B2 (en) * 2013-06-12 2017-02-14 Infinidat Ltd. System, method and a non-transitory computer readable medium for transaction aware snapshot
CN103995868B (en) * 2014-05-20 2017-07-21 科大国创软件股份有限公司 The global transaction manager and transaction methods of Based on Distributed system
CN104504130A (en) * 2014-12-31 2015-04-08 天津南大通用数据技术股份有限公司 Method for solving 2PC model single point failure problem and applied to distributive database

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102317913A (en) * 2011-07-30 2012-01-11 华为技术有限公司 Transaction recovery method and apparatus
CN104885054A (en) * 2013-03-13 2015-09-02 华为技术有限公司 System and method for performing a transaction in a massively parallel processing database
CN103559245A (en) * 2013-10-29 2014-02-05 华为技术有限公司 Distributed transaction committing failure handling method, device and system

Also Published As

Publication number Publication date
WO2017063520A1 (en) 2017-04-20
CN106598992A (en) 2017-04-26

Similar Documents

Publication Publication Date Title
CN106598992B (en) Database operation method and device
US8938421B2 (en) Method and a system for synchronizing data
US10019536B2 (en) Snapshot-consistent, in-memory graph instances in a multi-user database
KR102072726B1 (en) Systems and methods for supporting inline delegation of middle-tier transaction logs to database
US6553369B1 (en) Approach for performing administrative functions in information systems
US20130117307A1 (en) Snapshot isolation support for distributed query processing in a shared disk database cluster
US20110161281A1 (en) Distributed Transaction Management in a Distributed Shared Disk Cluster Environment
CN104793988A (en) Cross-database distributed transaction implementation method and device
EP2380090B1 (en) Data integrity in a database environment through background synchronization
US11899648B2 (en) Concurrency control for transactions in database systems
CN110019469B (en) Distributed database data processing method and device, storage medium and electronic device
EP4276651A1 (en) Log execution method and apparatus, and computer device and storage medium
US11243820B1 (en) Distributed deadlock detection and resolution in distributed databases
CN110580293A (en) Entity relationship storage method and device
JP5518950B2 (en) Virtual machine management system and management method
US8996484B2 (en) Recursive lock-and-propagate operation
CN109271869B (en) Face feature value extraction method and device, computer equipment and storage medium
CN111125213A (en) Data acquisition method, device and system
CN107247784B (en) Distributed transaction control method and transaction manager
KR20140047448A (en) Client and database server for resumable transaction and method thereof
CN110839064A (en) Method and device for executing script by distributed system
Pankowski Consistency and availability of Data in replicated NoSQL databases
CN116010441A (en) Data query method, device and storage medium
CN109901933B (en) Operation method and device of business system, storage medium and electronic device
US11809394B1 (en) Amendments for transactional index

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20200904

Address after: 210012 Nanjing, Yuhuatai District, South Street, Bauhinia Road, No. 68

Applicant after: Nanjing Zhongxing Software Co.,Ltd.

Address before: 518057 Nanshan District science and technology, Guangdong Province, South Road, No. 55, No.

Applicant before: ZTE Corp.

GR01 Patent grant
GR01 Patent grant