Data visibility judgment method, device, database node and medium
By obtaining and modifying transaction IDs in a distributed database and using locally stored visibility view information and transaction registration information, the accuracy problem of data visibility judgment in a distributed database is solved, and fast and accurate data visibility judgment is achieved.
Patent Information
- Application Number
- CN202210271835.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-18
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-03-18
AI Technical Summary
When the prior art makes data visibility judgment in distributed databases, there are accuracy problems caused by network delay or other failures, and it is impossible to accurately determine whether the transaction has been submitted, which affects the accuracy of data visibility judgment.
By obtaining the modified transaction ID when the target transaction performs a database query operation, and combining the locally stored visibility view information and transaction registration information, the visibility of the target transaction to the query record is determined, and the judgment accuracy is improved.
In a distributed environment, data visibility can be quickly and accurately judged through locally stored information, reducing communication needs for metadata nodes, and improving the accuracy and efficiency of data visibility judgment.
Smart Images

Figure CN114637738B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of data processing, and in particular, to a method, apparatus, database node, and medium for judging data visibility. Background Art
[0002] In a distributed database, in order to ensure the consistency of distributed transactions, the two-phase commit method is usually adopted to commit distributed transactions. Among them, the two-phase commit includes the first-phase commit and the second-phase commit; the first-phase commit is the request phase, which may include preparing to commit or canceling the transaction, and can also be understood as a stage of preparation but not yet execution; the second phase is the commit phase, which may include formally committing or canceling the transaction. The transaction can be considered to be committed only after both phases of the two-phase commit are completed.
[0003] Currently, when judging the data visibility of a transaction, usually only the visibility view information of the transaction is used to judge a certain record. In this way, when transaction X on a certain data node queries this record and finds that transaction Y that modified this record has completed the first-phase commit but has not completed the second-phase commit (that is, transaction Y has not completed the commit), transaction X cannot query this record, that is, transaction X is invisible to this record. However, the above method cannot ensure that transaction Y has not completed the commit. There may be a situation where due to network latency or other failure reasons, the current data node has not received the message that transaction Y has completed the commit, resulting in transaction X not being able to query this record, thus affecting the accuracy of data visibility judgment. Summary of the Invention
[0004] Embodiments of the present invention provide a method, apparatus, database node, and medium for judging data visibility to improve the accuracy of data visibility judgment.
[0005] According to one aspect of the embodiments of the present invention, a method for judging data visibility is provided, including:
[0006] When a target transaction executes a database query operation, obtain a modification transaction identifier (Identity Document, ID) from the record to be queried, where the modification transaction is the transaction that made the last modification to the record to be queried;
[0007] Obtain the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modification transaction in the local storage, where the visibility view information is used to represent the visible information associated with non-target transactions, and the target transaction registration information is used to represent the information on the transaction processing registration of the modification transaction;
[0008] Determine the visibility of the target transaction to the record to be queried according to the visibility view information and / or the target transaction registration information.
[0009] According to another aspect of the embodiments of the present invention, there is provided a data visibility determination device, including:
[0010] A first acquisition module, configured to obtain a modified transaction ID from the records to be queried when a target transaction performs a database query operation, where the modified transaction is the transaction that last modified the records to be queried;
[0011] A second acquisition module, configured to obtain the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modified transaction in local storage, where the visibility view information is used to represent the visible information associated with non-target transactions, and the target transaction registration information is used to represent the information on the transaction processing registration of the modified transaction;
[0012] A determination module, configured to determine the visibility of the target transaction for the records to be queried according to the visibility view information and / or the target transaction registration information.
[0013] According to another aspect of the embodiments of the present invention, there is provided a database node, where the database node includes:
[0014] At least one processor; and
[0015] A memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the data visibility determination method according to any embodiment of the present invention.
[0017] According to another aspect of the embodiments of the present invention, there is provided a computer-readable storage medium, where the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the data visibility determination method according to any embodiment of the present invention is implemented.
[0018] In Embodiment 1 of the present invention, there is provided a data visibility determination method, device, database node and medium. First, when a target transaction performs a database query operation, a modified transaction ID is obtained from the records to be queried; then, the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modified transaction in local storage is obtained; finally, according to the visibility view information and / or the target transaction registration information, the visibility of the target transaction for the records to be queried is determined. Based on obtaining the modified transaction ID, by using the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modified transaction to determine the visibility of the target transaction for the records to be queried, the accuracy of data visibility determination can be effectively improved.
[0019] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present invention, nor is it used to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0021] Figure 1 is a flowchart of a method for judging data visibility according to Embodiment 1 of the present invention;
[0022] Figure 2 is a flowchart of a method for judging data visibility according to Embodiment 2 of the present invention;
[0023] Figure 3 is a schematic structural diagram of a device for judging data visibility according to Embodiment 3 of the present invention;
[0024] Figure 4 shows a schematic structural diagram of the database node 10 that can be used to implement the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] In order to enable those skilled in the art to better understand the solutions of the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0026] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of the present invention are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present invention described here can be implemented in an order other than those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0027] To better understand the embodiments of the present invention, the following introduces relevant terms.
[0028] Calculation Node (CN): Used to receive and process various requests from clients and does not store any data itself. A request can be understood as a request to query, modify, or operate on a database, etc. Specifically, the calculation node can be used to be responsible for receiving requests from clients and processing these requests to generate some corresponding plans or instructions, such as data access instructions, data modification instructions, etc.; on this basis, send these instructions to the corresponding data nodes respectively, so that the data nodes operate according to the received instructions and return the results to the calculation node.
[0029] DataNode (DN): Equivalent to a data storage module for storing tables and data stored by users in the database, etc., and can also be used to provide data for the calculation node and process data modification and access requests (i.e., corresponding instructions) from the calculation node.
[0030] MetadataNode (MN): Equivalent to a metadata storage module, used to provide metadata support for the entire distributed database environment and manage the global transaction visibility view.
[0031] Transaction: In computer terms, it refers to a program execution unit that accesses and may update various data items in a database. A transaction provides a mechanism to incorporate all operations involved in an activity into an indivisible execution unit. All operations that make up a transaction can only be committed if all operations can be executed normally. As long as any one of the operations fails to execute, the entire transaction will be rolled back. Among them, rollback refers to the behavior of restoring a program or data to the previous correct state due to a program or data processing error.
[0032] Distributed Transaction: A distributed transaction means that the participants in the transaction, the servers supporting the transaction, the resource servers, and the transaction manager are located on different nodes of different distributed systems respectively. The transaction of a computing node corresponds to branch transactions of multiple data nodes, and overall constitutes a distributed transaction. That is to say, the computing node will generate a total transaction according to the received request, and this total transaction will include multiple distributed transactions, and the distributed transactions can be allocated to the corresponding data nodes for processing.
[0033] Distributed Transaction Consistency: When the transaction of the computing node is committed or rolled back, the branch transactions (i.e., each distributed transaction) of each data node should also be synchronously committed or rolled back, so as to ensure the transaction consistency between different nodes.
[0034] Two-Phase Commit: To solve the problem of distributed transaction consistency, the transaction commit operation of the computing node can be divided into one-phase commit and two-phase commit. The branch transaction in the data node can still be rolled back after completing the one-phase commit, and the information of the branch transaction will not be lost after a failure restart. Only when all branch transactions have completed the one-phase commit can the data node be notified to execute the two-phase commit.
[0035] Embodiment 1
[0036] Figure 1 is a flowchart of a method for judging data visibility provided according to Embodiment 1 of the present invention. This embodiment is applicable to the situation of judging data visibility. This method can be executed by a data visibility judgment device, and the data visibility judgment device can be implemented in the form of hardware and / or software. The data visibility judgment device can be configured in a database node. As Figure 1 shown, this method can be applied to a data node, and this method is applied to judge the data visibility of a distributed transaction in a distributed environment, including:
[0037] S110. When the target transaction executes a database query operation, obtain the modified transaction ID from the records to be queried.
[0038] In this embodiment, the target transaction can be understood as the transaction currently executing the database query operation, and the target transaction can be a distributed transaction allocated to the data node. The database query operation can be understood as an operation of querying the data recorded in the database. The database may include multiple records as data, and the records to be queried can be understood as the records waiting to be queried in response to the database query operation. The modified transaction can be understood as the transaction that makes the last modification to the records to be queried. The ID can be used as an identity identification number representing the transaction, and each transaction corresponds to a unique ID; the modified transaction ID can be understood as an identity identification number representing the modified transaction.
[0039] When the target transaction performs a database query operation, it is necessary to determine the visibility of the current record to be queried, that is, whether the target transaction can see the modification of the record to be queried by the modifying transaction. If the target transaction can see the modification of the record to be queried by the modifying transaction, then the target transaction can query the record to be queried at this time; if the target transaction cannot see the modification of the record to be queried by the modifying transaction, then the target transaction cannot query the record to be queried at this time. Therefore, the accuracy of the visibility judgment of the record to be queried affects the accuracy of the target transaction performing the database query operation.
[0040] In this embodiment, after a certain transaction modifies a certain record in the database, the transaction ID of this transaction will replace the previously carried transaction ID and be recorded on this record. Therefore, for each record, the transaction corresponding to the transaction ID that modifies itself carried in it is the last transaction that modified itself. On this basis, when the target transaction performs a database query operation, the modifying transaction ID can be obtained from the record to be queried.
[0041] S120. Obtain the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modifying transaction in the local storage.
[0042] In this embodiment, the visibility view information corresponding to the target transaction can be used to represent the visible information associated with non-target transactions. Non-target transactions can be understood as other transactions in the entire distributed database system, and these other transactions can include started transactions and received but not yet started transactions. Visible information can be understood as information that the target transaction can learn or see.
[0043] It should be noted that the global visibility view information of the data node is obtained by the computing node from the metadata node and sent to the data node at the start of the distributed transaction and stored in the local storage of the data node; where the start of the distributed transaction can be understood as the start operation of the distributed transaction. A transaction can include multiple operations. The computing node can obtain and update the corresponding visibility view information from the metadata node before each operation is executed and send the updated visibility view information to the corresponding data node. The global visibility view information can be understood as the visibility view information in the entire distributed database system, and it can contain the visibility view information of each distributed transaction in the system. That is to say, from the global visibility view information, the visibility view information corresponding to each distributed transaction can be obtained according to the ID corresponding to each distributed transaction.
[0044] Visibility view information may include the current minimum active transaction ID, the current transaction ID to be allocated, and the current system sequence value. Among them, the current minimum active transaction may refer to a transaction that has not been committed yet and has the earliest start time; for example, if multiple transactions are started currently, they can be divided into Transaction 1, Transaction 2, Transaction 3, Transaction 4, and Transaction 5 in the order of start time; among them, Transaction 1, 3, and 5 are committed, then among the remaining Transaction 2 and 4, Transaction 2 has the earliest start time and has not been committed yet, so Transaction 2 is the current minimum active transaction. The current transaction to be allocated may refer to the next transaction waiting to be started. The current system sequence value may refer to a sequence value used in a distributed database system to count the transaction commits. The system sequence value is a global variable, that is, no matter which transaction in the system (i.e., the entire distributed database system) is committed, it will be incremented by 1 based on the current system sequence value; the initial value of the system sequence value can be set to 1. For example, if the existing Transaction A is committed, and the current system sequence value obtained at this time is 5, then the commit sequence value of Transaction A can be recorded as 5, and the current system sequence value is incremented by 1 to become 6 at this time; when Transaction B is committed next time, and the current system sequence value obtained at this time is 6, then the commit sequence value of Transaction B is 6, and the current system sequence value is incremented by 1 to become 7; and so on.
[0045] Transaction registration information can be used to represent information about the transaction processing registration of a transaction. The transaction processing registration situation may refer to the situation of registering each processing progress of a transaction, such as the registration situation after the transaction start processing, the registration situation after the first-phase commit processing of the transaction, and the registration situation after the second-phase commit processing of the transaction. When registering, the transaction status information and the commit sequence value of the transaction need to be registered. The transaction status information can be understood as information characterizing the transaction processing progress situation, such as it may include the started but uncommitted state (i.e., the transaction has been started but has not started the first-phase commit yet), the first-phase commit state (i.e., the first-phase commit of the transaction has been completed), and the second-phase commit state (i.e., the second-phase commit has been completed). The commit sequence value may refer to the sequence value when the transaction is committed. The target transaction registration information can be used to represent information about the transaction processing registration of a modified transaction. The target transaction registration information may include the transaction status information of the modified transaction and the commit sequence value of the modified transaction.
[0046] Optionally, obtaining the target transaction registration information corresponding to the modified transaction includes: obtaining the target transaction registration information corresponding to the modified transaction from the global transaction registration information according to the modified transaction ID, and the global transaction registration information includes the transaction status information and the commit sequence value corresponding to each started transaction.
[0047] Among them, the global transaction registration information can be understood as the information containing the transaction processing registration status of the started transactions in the entire distributed database system. That is, the global transaction registration information can include the transaction registration information corresponding to each started information. The global transaction registration information can include the transaction status information and the commit sequence value corresponding to each started transaction. The storage form of the transaction registration information of each started transaction in the global transaction registration information can be: transaction ID (transaction status information, commit sequence value), so that each started transaction can be mapped one by one to its corresponding transaction status information and commit sequence value through the transaction ID. The global transaction registration information is stored in the local storage of the data node, and the target transaction registration information corresponding to the modified transaction can be located and obtained from the global transaction registration information according to the modified transaction ID.
[0048] It should be noted that the global transaction registration information stored in the local storage of the data node can be divided into two parts: one is the transaction registration information generated by the data node for different states of the transaction (such as started but not committed, completed the first-phase commit, completed the second-phase commit, etc.), which can be understood as the transaction status information; the other is the transaction registration information obtained by the computing node from the metadata node when the target transaction starts and the second-phase commit, and this transaction registration information is sent to the data node and stored in the local storage of the data node. The transaction registration information of the metadata node can include the ID at the time of transaction start and the commit sequence value of the transaction. Among them, in the transaction registration information of the metadata node, the commit sequence value of the transaction at the time of transaction start is the initial value, and the commit sequence value of the transaction at the time of the second-phase commit is the current system sequence value. On this basis, the global transaction registration information stored in the local storage of the data node can include the transaction status information and the commit sequence value of the transaction, and each group of transaction status information and commit sequence value corresponds to a transaction ID to form a one-to-one mapping relationship.
[0049] In this embodiment, according to the current requirement for determining visibility, the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modified transaction can be selectively obtained. The local storage can refer to the local memory space of the data node.
[0050] S130. Determine the visibility of the target transaction to the record to be queried according to the visibility view information and / or the target transaction registration information.
[0051] In this embodiment, the visibility of the target transaction to the record to be queried can be understood as whether the target transaction can see the record to be queried, that is, whether the target transaction can see or query the record to be queried. The visibility of the target transaction to the record to be queried can be determined according to the obtained visibility view information and / or the target transaction registration information. If the modified transaction ID is less than the current minimum active transaction ID, or the modified transaction ID is greater than the current to-be-allocated transaction ID, the visibility of the target transaction to the record to be queried can be determined according to the obtained visibility view information. If the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current to-be-allocated transaction ID, at this time, it is necessary to further rely on the target transaction registration information, that is, the visibility of the target transaction to the record to be queried can be determined according to the obtained visibility view information and the target transaction registration information.
[0052] Optionally, the visibility view information includes the current minimum active transaction ID and / or the current to-be-allocated transaction ID; determining the visibility of the target transaction to the record to be queried according to the visibility view information includes: if the modified transaction ID is less than the current minimum active transaction ID, the target transaction is visible to the record to be queried; if the modified transaction ID is greater than the current to-be-allocated transaction ID, the target transaction is not visible to the record to be queried.
[0053] Among them, the visibility of the target transaction to the record to be queried can be determined according to the obtained visibility view information. The visibility view information may include the current minimum active transaction ID and / or the current to-be-allocated transaction ID. Specifically, if the modified transaction ID is less than the current minimum active transaction ID, it can indicate that the modified transaction has been committed before the target transaction executes the database query operation, so the target transaction is visible to the record to be queried. If the modified transaction ID is greater than the current to-be-allocated transaction ID, it can indicate that the current modified transaction has not been committed yet, so the target transaction is not visible to the record to be queried.
[0054] Optionally, the visibility view information includes the current minimum active transaction ID and the current to-be-allocated transaction ID; determining the visibility of the target transaction to the record to be queried according to the visibility view information and / or the target transaction registration information includes: if the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current to-be-allocated transaction ID, the visibility of the target transaction to the record to be queried is determined according to the target transaction registration information and the visibility view information; among them, the target transaction registration information includes the transaction status information of the modified transaction and the commit sequence value of the modified transaction; the transaction status information includes: the started but uncommitted state, the first-phase commit state, and the second-phase commit state.
[0055] Among them, the visibility view information may include the current minimum active transaction ID and the current transaction ID to be allocated; the target transaction registration information may include the transaction status information of the modified transaction and the commit sequence value of the modified transaction; the transaction status information may include: the started but uncommitted status, the first-phase commit status, and the second-phase commit status. When the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current transaction ID to be allocated, it is necessary to jointly determine the visibility of the target transaction to the record to be queried based on the target transaction registration information and the visibility view information. Different transaction status information may correspond to different visibility determination situations.
[0056] Optionally, determining the visibility of the target transaction to the record to be queried based on the target transaction registration information and the visibility view information includes: if the transaction status information of the modified transaction is the started but uncommitted status, the target transaction is invisible to the record to be queried.
[0057] Among them, when the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current transaction ID to be allocated, if the transaction status information of the modified transaction is the started but uncommitted status, it can indicate that although the modified transaction has been started but the first-phase commit has not started (i.e., the commit has not been completed), so the target transaction is invisible to the record to be queried.
[0058] Optionally, the visibility view information further includes the current system sequence value; determining the visibility of the target transaction to the record to be queried based on the target transaction registration information and the visibility view information includes: if the transaction status information of the modified transaction is the second-phase commit status, compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is less than the current system sequence value, the target transaction is visible to the record to be queried; otherwise, the target transaction is invisible to the record to be queried; if the transaction status information of the modified transaction is the first-phase commit status, compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is greater than or equal to the current system sequence value, the target transaction is invisible to the record to be queried; if the commit sequence value of the modified transaction is less than the current system sequence value, obtain the new commit sequence value corresponding to the modified transaction from the transaction registration information of the metadata node, and determine the visibility of the target transaction to the record to be queried based on the new commit sequence value and the current system sequence value.
[0059] Among them, when the transaction status information of the modified transaction is the second-phase commit status or the first-phase commit status, the visibility view information also needs to include the current system sequence value on the basis of originally including the current minimum active transaction ID and the current transaction ID to be allocated, for the determination of visibility.
[0060] If the transaction status information of the modification transaction is in the second-phase commit state, it can indicate that the modification transaction has been completed and committed. Then, the commit sequence value of the modification transaction can be compared with the current system sequence value. If the commit sequence value of the modification transaction is less than the current system sequence value, it can indicate that the modification transaction has been completed and committed before the target transaction executes the database query operation. Therefore, the target transaction can see the records to be queried. Otherwise, the target transaction cannot see the records to be queried.
[0061] If the transaction status information of the modification transaction is in the first-phase commit state, it can indicate that the modification transaction has not completed the second-phase commit. The commit sequence value of the modification transaction can be compared with the current system sequence value. If the commit sequence value of the modification transaction is greater than or equal to the current system sequence value, it can indicate that when the target transaction executes the database query operation, the modification transaction has completed the first-phase commit but has not completed the second-phase commit. Therefore, the target transaction cannot see the records to be queried. If the commit sequence value of the modification transaction is less than the current system sequence value, the new commit sequence value corresponding to the modification transaction can be obtained from the transaction registration information of the metadata node, and the visibility of the records to be queried by the target transaction can be determined based on the new commit sequence value and the current system sequence value.
[0062] Since the transaction registration information of the metadata node always updates and records the commit sequence values corresponding to the start and second-phase commit of each transaction at any time, the latest commit sequence value of the modification transaction, that is, the new commit sequence value, can be obtained from the transaction registration information of the metadata node through the modification transaction ID.
[0063] Optionally, determining the visibility of the records to be queried by the target transaction based on the new commit sequence value and the current system sequence value includes: if the new commit sequence value is the initial value, the target transaction cannot see the records to be queried; if the new commit sequence value is not the initial value, the new commit sequence value and the current system sequence value are compared; if the new commit sequence value is less than the current system sequence value, the target transaction can see the records to be queried; if the new commit sequence value is greater than or equal to the current system sequence value, the target transaction cannot see the records to be queried.
[0064] Among them, the initial value can refer to the commit sequence value registered when the transaction is just started and can be set to 0. After the transaction completes the second-phase commit, it will be updated from the initial value to the corresponding commit sequence value.
[0065] If the newly submitted sequence value is the initial value, it can indicate that although the modification transaction has been started, the second-phase commit has not yet begun. Therefore, the target transaction cannot see the records to be queried. If the newly submitted sequence value is not the initial value, it can indicate that the modification transaction has completed the second-phase commit, and the newly submitted sequence value can be compared with the current system sequence value. If the newly submitted sequence value is less than the current system sequence value, it can indicate that the modification transaction has completed the second-phase commit before the target transaction executes the database query operation. Therefore, the target transaction can see the records to be queried. If the newly submitted sequence value is greater than or equal to the current system sequence value, it can indicate that the modification transaction has not completed the second-phase commit before the target transaction executes the database query operation. Therefore, the target transaction cannot see the records to be queried.
[0066] Embodiment 1 of the present invention provides a method for judging data visibility. First, when a target transaction executes a database query operation, the modification transaction ID is obtained from the records to be queried. Then, the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modification transaction is obtained from local storage. Finally, according to the visibility view information and / or the target transaction registration information, the visibility of the target transaction to the records to be queried is determined. Based on obtaining the modification transaction ID, this method determines the visibility of the target transaction to the records to be queried through the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modification transaction, which can effectively improve the accuracy of data visibility determination.
[0067] Embodiment 2
[0068] Figure 2 is a flowchart of a method for judging data visibility according to Embodiment 2 of the present invention. Embodiment 2 is refined on the basis of the above embodiments. In this embodiment, the registration or update process of the target transaction registration information is specifically described. It should be noted that the technical details not described in detail in this embodiment can be referred to in any of the above embodiments. As Figure 2 shown, the method includes:
[0069] S210. Receive a transaction processing message, where the transaction processing message includes: a transaction start message, a first-phase commit message, and a second-phase commit message.
[0070] In this embodiment, the data node receives the transaction processing message sent by the computing node. The transaction processing message can be understood as a message for processing a transaction. The transaction processing message can include a transaction start message, a first-phase commit message, and a second-phase commit message.
[0071] Among them, the transaction start message may refer to a message containing a transaction start instruction. The first-phase commit message may refer to a message containing a transaction first-phase commit instruction and a first system sequence value. The second-phase commit message may refer to a message containing a transaction second-phase commit instruction and a second system sequence value. The first system sequence value may refer to the current system sequence value after receiving the first-phase commit message. The second system sequence value may refer to the current system sequence value after receiving the second-phase commit message. After receiving the second-phase commit message, it indicates that the corresponding transaction has been completed. Since the second-phase commit occurs after the first-phase commit, the second system sequence value is greater than the first system sequence value.
[0072] S220. Determine whether the transaction processing message is a transaction start message. If so, execute S230; if not, execute S240.
[0073] In this embodiment, determine whether the transaction processing message is a transaction start message. If the transaction processing message is a transaction start message, execute S230; if the transaction processing message is not a transaction start message, execute S240.
[0074] S230. Register the target transaction registration information and store it in the local storage. The registered target transaction registration information includes modifying the transaction status information of the transaction to the started and uncommitted state, and modifying the commit sequence value of the transaction to the initial value.
[0075] In this embodiment, when the transaction processing message is a transaction start message, it can indicate that the corresponding modified transaction has completed the start operation. At this time, it is necessary to register the transaction status information as the started and uncommitted state in the corresponding target transaction registration information, and modify the commit sequence value of the transaction to the initial value. Among them, when the modified transaction is just started, it indicates that the current modified transaction has not been completed and has not obtained the corresponding commit sequence value. At this time, the commit sequence value can be set to the initial value, and the initial value can be set to 0.
[0076] It should be noted that in order to ensure the consistency of distributed transactions, when the transaction processing message is a transaction start message, on the one hand, register the target transaction registration information in the data node and store it in the local storage of the data node. On the other hand, remotely register the ID and commit sequence value (at this time, the commit sequence value is the initial value) of the modified transaction in the transaction registration information of the metadata node and store it.
[0077] S240. Determine whether the transaction processing message is a first-phase commit message. If so, execute S250; if not, execute S260.
[0078] In this embodiment, when the transaction processing message is not a transaction start message, it is determined whether the transaction processing message is a first-phase commit message. If the transaction processing message is a first-phase commit message, S250 can be executed; if the transaction processing message is not a first-phase commit message, S260 can be executed.
[0079] S250: Update the transaction status information and the commit sequence value of the target transaction registration information in the local storage to the first-phase commit status and the first system sequence value, respectively.
[0080] In this embodiment, when the transaction processing message is a first-phase commit message, it can indicate that the corresponding modified transaction has completed the first-phase commit operation. At this time, according to the first system sequence value in the first-phase commit message, the transaction status information and the commit sequence value of the target transaction registration information in the local storage can be updated to the first-phase commit status and the first system sequence value, respectively.
[0081] It should be noted that when the transaction processing message is a first-phase commit message, since the modified transaction has not completed the second-phase commit, the transaction registration information corresponding to the modified transaction in the transaction registration information of the metadata node does not need to be updated.
[0082] S260: Update the transaction status information and the commit sequence value of the target transaction registration information in the local storage to the second-phase commit status and the second system sequence value, respectively.
[0083] In this embodiment, when the transaction processing message is a second-phase commit message, it can indicate that the corresponding modified transaction has completed the second-phase commit operation, that is, it indicates that the modified transaction has been committed. At this time, according to the second system sequence value in the second-phase commit message, the transaction status information and the commit sequence value of the target transaction registration information in the local storage can be updated to the second-phase commit status and the second system sequence value, respectively.
[0084] It should be noted that in order to ensure the consistency of distributed transactions, when the transaction processing message is a second-phase commit message, on the one hand, the transaction status information and the commit sequence value of the target transaction registration information in the data node are updated to the second-phase commit status and the second system sequence value, respectively, and stored in the local storage of the data node; on the other hand, the commit sequence value corresponding to the modified transaction ID (at this time, the commit sequence value is the second system sequence value) is updated and stored in the transaction registration information of the metadata node remotely at the same time.
[0085] It should be noted that the above solution is not only for the registration or update of the target transaction registration information of the modified transaction, but can be applied to the registration or update of the transaction registration information of all transactions.
[0086] Embodiment 2 of the present invention provides a method for judging data visibility. By judging the received transaction processing messages, the transaction status information and the commit sequence value in the corresponding target transaction registration information are updated in real time, so as to accurately judge the data visibility according to the transaction status information and the commit sequence value in the target transaction registration information subsequently.
[0087] The following is an exemplary description of the present invention.
[0088] A counting sequence value (the sequence value can be expressed as cmtseq) is used to sequentially count the transaction commits in the system (the system can be understood as the entire distributed database system): when a transaction commits, the current value of the system cmtseq is obtained as the commit cmtseq of this transaction (that is, the commit sequence value, which can be named r_cmtseq), and the current system cmtseq is incremented by 1.
[0089] In a distributed data environment, to ensure the consistency of transaction data, two-phase commit is a commonly used means. Existing methods for judging visibility only using the relevant information in the local storage of data nodes have loopholes on the data nodes. For example, when transaction X on a certain data node 1 queries a record and finds that transaction Y that modified the record has completed the first-phase commit but not the second-phase commit, transaction X cannot query the record modified by transaction Y. In fact, in this process, it cannot be guaranteed that transaction Y has not committed. It may be due to network latency or other failures, but only that the current data node has not received the relevant message indicating that transaction Y has completed the commit, resulting in the inability to query.
[0090] If the relevant information in the local data node is not used for visibility judgment and all communications are made to the metadata node for judgment based on the relevant information of the remote metadata node, although accurate judgment can be made, multiple communications will seriously affect the performance.
[0091] Therefore, the embodiment of the present invention provides a method. In a distributed environment, based on two-phase commit, the local information of the data node is first used for visibility judgment, and only in a small number of cases where the visibility cannot be judged is the metadata node enabled to assist in the judgment. The embodiment of the present invention can facilitate the quick and accurate judgment of data visibility on the data node.
[0092] 1. On the computing node:
[0093] When transaction C on the compute node starts, it applies to the metadata node for a transaction ID (the transaction ID can be represented as tid, that is, it sends a transaction ID application request to the metadata node) and obtains the current global visibility view information. The global visibility view information (trx_view) includes the current minimum active transaction ID, which can be represented as trx_view.min_tid; the next transaction ID to be allocated currently, which can be represented as trx_view.next_tid; the cmtseq of the current system, which can be represented as trx_view.snap_cmtseq;
[0094] When the compute node needs to perform an operation, it checks whether the corresponding branch transaction has been started on the compute node that needs to perform the operation (the compute node that receives the transaction request is the compute node that needs to perform the operation). (The compute node checks itself. After the compute node receives a total transaction, it generates a plan, which may include multiple branch transactions and distributes them to each data node; after the total transaction starts, the compute node can record which data nodes these branch transactions are assigned to for execution; at this time, when the compute node checks and finds that some branch transactions have no assignment records, then they belong to unstarted branch transactions. It should be noted that the tid of the total transaction and the corresponding branch transaction is the same.) If not, the metadata node sends the tid applied for by the total transaction and the corresponding visibility view information to the compute node, and the compute node starts the unstarted branch transaction according to the received information.
[0095] During the first-phase commit, it sends a first-phase commit message to the data node and sends the snap_cmtseq in the current global visibility view information (which can be represented as cmtseq1, that is, the first system sequence value) together;
[0096] During the second-phase commit, it first sends a second commit request message to the metadata node to obtain the current snap_cmtseq (at this time, compared with the first-phase commit, since the transaction has completed the second-phase commit, that is, the commit is completed, so the value of this snap_cmtseq is larger than the snap_cmtseq during the first-phase commit); then it sends a second-phase commit message to the corresponding data node and sends this snap_cmtseq (which can be represented as cmtseq2, that is, the second system sequence value) together;
[0097] The compute node only performs calculations and does not perform data visibility judgment, so there is no need to register relevant information in the transaction module of the compute node.
[0098] II. On the metadata node:
[0099] The metadata node manages the global transaction visibility view of the entire distributed system. The visibility view of the data node is obtained from the metadata node when the distributed transaction starts and stored in the local storage of the data node.
[0100] When the computing node applies for a newly started transaction ID (that is, the computing node sends a transaction ID application request to the metadata node), after the metadata node allocates the ID, it registers it in the local transaction registration information of the metadata node (the transaction registration information can be represented by a long array cmt_arr): Initially, fill 0 in the position corresponding to tid in cmt_arr. When a certain transaction C starts, assume the transaction ID of transaction C is tid_C, so the transaction registration information can be expressed as (tid_C, 0), where the format of (tid_C, 0) is (transaction ID, commit sequence value).
[0101] When the computing node applies for the two-phase commit of tid_C to obtain the commit cmtseq (assume it is C_cmtseq), write the obtained commit sequence value into the transaction registration information corresponding to the transaction of tid_C in cmt_arr, that is, the transaction registration information is (tid_C, C_cmtseq). It should be noted that since transaction C has not completed the commit during the first-phase commit, the corresponding transaction registration information on the metadata node will not be updated during the first-phase commit.
[0102] III. On the data node:
[0103] Supplement the transaction registration information in the local transaction module of the data node and add transaction status information. For the steps of the two-phase commit, the following transaction statuses are provided: ACTIVE, PREPARED, COMMITED, which can represent started but not committed, completed the first-phase commit, and completed the second-phase commit respectively. When modifying the transaction status information, register or update the transaction registration information in the form of tid(stat, r_cmtseq), that is, transaction ID (transaction status, commit sequence value).
[0104] When starting a branch transaction according to the start message of the computing node, register the transaction status information in the transaction registration information of the data node, which can be expressed as tid(ACTIVE, 0);
[0105] When processing the first-phase commit operation of the computing node, according to the cmtseq1 provided by the first-phase commit message sent by the computing node, update the transaction registration information corresponding to this transaction in the global transaction registration information to tid(PREPARED, cmtseq1); The global transaction registration information can be understood as the global information containing the transaction registration information of all transactions.
[0106] When processing the second-phase commit operation of a transaction for a computing node, update the transaction registration information of the transaction to tid(COMMITED, cmtseq2) according to cmtseq2 provided in the message sent by the computing node;
[0107] When transaction X executes a database query operation, obtain the transaction id of the last modification of the record to be queried: rtid, and make the following judgments according to its own visibility view information trx_view:
[0108] 1. If rtid < trx_view.min_tid, then transaction X is visible to the record to be queried, that is, transaction X can see the record to be queried.
[0109] 2. If rtid > trx_view.next_tid, then transaction X is not visible to the record to be queried, that is, transaction X cannot see the record to be queried.
[0110] 3. For the case where rtid is between [trx_view.min_tid, trx_view_next_tid], it needs to be judged according to the following method:
[0111] Obtain its commit r_stat (that is, the committed transaction status information) and r_cmtseq (commit sequence value) from the transaction registration information of the data node according to rtid. r_stat can include 3 states: ACTIVE, PREPARED, and COMMITTED.
[0112] 4. If r_stat = ACTIVE, it can indicate that the transaction corresponding to rtid has not been committed, then transaction X is not visible to the record to be queried;
[0113] 5. If r_stat = COMMITTED, then compare r_cmtseq with trx_view.snap_cmtseq: If r_cmtseq < trx_view.snap_cmtseq, it means that the transaction corresponding to rtid has been committed before the current query is started, then transaction X is visible to the record to be queried; otherwise it is not visible.
[0114] 6. If r_stat = PREPARED, first compare r_cmtseq with trx_view.snap_cmtseq. If r_cmtseq is greater than or equal to trx_view.snap_cmtseq, it means that when transaction X starts the query, the transaction corresponding to rtid has not processed the second-phase commit yet, and the records to be queried by transaction X are not visible. If r_cmtseq < trx_view.snap_cmtseq, a confirmation request for r_cmtseq needs to be sent to the metadata node to obtain the r_cmtseq corresponding to rtid in the transaction registration information of the metadata node, which can be called the new r_cmtseq. If the new r_cmtseq is 0 (i.e., the initial value), it means that although the corresponding transaction has completed the first-phase commit, it has not started the second-phase commit yet, and the records to be queried by transaction X are not visible. Otherwise, if the new r_cmtseq is non-zero, it means that the corresponding transaction has been committed, and then continue to compare the new r_cmtseq with trx_view.snap_cmtseq. If the new r_cmtseq < trx_view.snap_cmtseq, it means that the transaction corresponding to rtid has been committed before the current transaction X starts the query, and the records to be queried by transaction X are visible. Otherwise, if the new r_cmtseq >= trx_view.snap_cmtseq, the records to be queried by transaction X are not visible.
[0115] As can be seen from the above steps of the present invention: the data visibility judgments in steps 1-5 are all completed on the data node, and only some operations in step 6 need to be assisted by the metadata node to complete. That is to say, when the data node judges the data visibility, for a small number of transactions that have completed the first-phase commit but cannot judge whether the second-phase commit has been completed, the metadata node can be enabled for auxiliary judgment, and then finally determine the data visibility, without communicating with the metadata node for visibility judgment in all steps. Compared with the traditional method, the embodiment of the present invention is more efficient and accurate.
[0116] Embodiment III
[0117] Figure 3 is a schematic structural diagram of a data visibility judgment device provided according to Embodiment III of the present invention. As Figure 3 shown, the device includes: a first acquisition module 310, a second acquisition module 320, and a determination module 330;
[0118] Among them, the first acquisition module 310 is used to obtain the modified transaction ID from the records to be queried when the target transaction executes a database query operation, and the modified transaction is the transaction that makes the last modification to the records to be queried;
[0119] A second acquisition module 320, configured to acquire visibility view information corresponding to the target transaction and / or target transaction registration information corresponding to the modification transaction in local storage, where the visibility view information is used to represent visible information associated with non-target transactions, and the target transaction registration information is used to represent information about the transaction processing registration situation of the modification transaction;
[0120] A determination module 330, configured to determine the visibility of the target transaction to the record to be queried according to the visibility view information and / or the target transaction registration information.
[0121] This embodiment provides a data visibility determination device. First, through a first acquisition module 310, when a target transaction performs a database query operation, a modification transaction ID is acquired from the record to be queried, and the modification transaction is the transaction that last modified the record to be queried; then, through a second acquisition module 320, visibility view information corresponding to the target transaction and / or target transaction registration information corresponding to the modification transaction is acquired in local storage. The visibility view information is used to represent visible information associated with non-target transactions, and the target transaction registration information is used to represent information about the transaction processing registration situation of the modification transaction; finally, through a determination module 330, according to the visibility view information and / or the target transaction registration information, the visibility of the target transaction to the record to be queried is determined. Based on acquiring the modification transaction ID, this device determines the visibility of the target transaction to the record to be queried through the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modification transaction, and can effectively improve the accuracy of data visibility determination.
[0122] Optionally, the visibility view information includes a current minimum active transaction ID and / or a current to-be-allocated transaction ID;
[0123] Determining the visibility of the target transaction to the record to be queried according to the visibility view information includes:
[0124] If the modification transaction ID is less than the current minimum active transaction ID, the target transaction is visible to the record to be queried;
[0125] If the modification transaction ID is greater than the current to-be-allocated transaction ID, the target transaction is not visible to the record to be queried.
[0126] Optionally, the visibility view information includes a current minimum active transaction ID and a current to-be-allocated transaction ID;
[0127] Determining the visibility of the target transaction to the record to be queried according to the visibility view information and / or the target transaction registration information includes:
[0128] If the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current to-be-allocated transaction ID, then determine the visibility of the target transaction to the record to be queried according to the target transaction registration information and the visibility view information;
[0129] Among them, the target transaction registration information includes the transaction status information of the modified transaction and the commit sequence value of the modified transaction; the transaction status information includes: started but not committed status, first-phase commit status, and second-phase commit status.
[0130] Optionally, determining the visibility of the target transaction to the record to be queried according to the target transaction registration information and the visibility view information includes:
[0131] If the transaction status information of the modified transaction is the started but not committed status, then the target transaction is not visible to the record to be queried.
[0132] Optionally, the visibility view information further includes the current system sequence value;
[0133] Determining the visibility of the target transaction to the record to be queried according to the target transaction registration information and the visibility view information includes:
[0134] If the transaction status information of the modified transaction is the second-phase commit status, then compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is less than the current system sequence value, then the target transaction is visible to the record to be queried; otherwise, the target transaction is not visible to the record to be queried;
[0135] If the transaction status information of the modified transaction is the first-phase commit status, then compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is greater than or equal to the current system sequence value, then the target transaction is not visible to the record to be queried; if the commit sequence value of the modified transaction is less than the current system sequence value, then obtain the new commit sequence value corresponding to the modified transaction from the metadata node, and determine the visibility of the target transaction to the record to be queried according to the new commit sequence value and the current system sequence value.
[0136] Optionally, determining the visibility of the target transaction to the record to be queried according to the new commit sequence value and the current system sequence value includes:
[0137] If the new commit sequence value is the initial value, then the target transaction is not visible to the record to be queried;
[0138] If the newly submitted sequence value is not the initial value, compare the newly submitted sequence value with the current system sequence value;
[0139] If the newly submitted sequence value is less than the current system sequence value, the target transaction is visible to the record to be queried;
[0140] If the newly submitted sequence value is greater than or equal to the current system sequence value, the target transaction is not visible to the record to be queried.
[0141] Optionally, obtain the target transaction registration information corresponding to the modification transaction, including:
[0142] According to the modification transaction ID, obtain the target transaction registration information corresponding to the modification transaction from the global transaction registration information, where the global transaction registration information includes the transaction status information and the committed sequence value corresponding to each started transaction.
[0143] Optionally, the device further includes:
[0144] A registration module, configured to register or update the target transaction registration information according to the received transaction processing message.
[0145] Optionally, the transaction processing message includes: a transaction start message, a first-phase commit message, and a second-phase commit message;
[0146] The registering or updating the target transaction registration information according to the received transaction processing message includes:
[0147] If the received transaction processing message is a transaction start message, register the target transaction registration information and store it in the local storage, where the registered target transaction registration information includes that the transaction status information of the modification transaction is the started and uncommitted state, and the committed sequence value of the modification transaction is the initial value;
[0148] If the received transaction processing message is a first-phase commit message, update the transaction status information and the committed sequence value of the target transaction registration information in the local storage to the first-phase commit state and the first system sequence value respectively;
[0149] If the received transaction processing message is a second-phase commit message, update the transaction status information and the committed sequence value of the target transaction registration information in the local storage to the second-phase commit state and the second system sequence value respectively;
[0150] Wherein, the first system sequence value is the system sequence value after receiving the first-phase commit message; the second system sequence value is the system sequence value after receiving the second-phase commit message.
[0151] The data visibility determination device provided by the embodiments of the present invention can execute the data visibility determination method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the method.
[0152] Embodiment 4
[0153] Figure 4 FIG. shows a schematic structural diagram of a database node 10 that can be used to implement the embodiments of the present invention. The database node 10 is intended to represent various forms of digital computers, such as, for example, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The database node 10 can also represent various forms of mobile devices, such as, for example, personal digital processors, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0154] As Figure 4 shown, the database node 10 includes at least one processor 11, and a memory communicatively connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc. The memory stores a computer program executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the database node 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.
[0155] Multiple components in the database node 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the database node 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0156] The processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the data visibility determination method.
[0157] In some embodiments, the data visibility determination method can be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the database node 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method XXX described above can be executed. Alternatively, in other embodiments, the processor 11 can be configured to execute the data visibility determination method in any other suitable manner (e.g., by means of firmware).
[0158] The various embodiments of the systems and techniques described above in this document can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor, and can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit the data and instructions to the storage system, the at least one input device, and the at least one output device.
[0159] The computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to the processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer programs are executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer programs can be executed entirely on the machine, partially on the machine, as a stand-alone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0160] In the context of the present invention, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0161] To provide interaction with a user, the systems and techniques described herein can be implemented on a database node 10 having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the database node 10. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, speech input, or tactile input).
[0162] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0163] A computing system may include a client and a server. The client and the server are generally far from each other and usually interact via a communication network. The relationship between the client and the server is created by computer programs that run on respective computers and have a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system, solving the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.
[0164] It should be understood that various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps recited in the present invention can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved, and no limitations are imposed herein.
[0165] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for judging data visibility, characterized in that, The method includes: When the target transaction performs a database query operation, obtain a modified transaction identification ID from the records to be queried, where the modified transaction is the transaction that last modified the records to be queried; Obtain the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modified transaction in local storage, where the visibility view information is used to represent the visible information associated with non-target transactions, and the target transaction registration information is used to represent the information on the transaction processing registration of the modified transaction; wherein, the visibility view information includes the current minimum active transaction ID, the current transaction ID to be allocated, and the current system sequence value, and the target transaction registration information includes the transaction status information of the modified transaction and the commit sequence value of the modified transaction, and the transaction status information includes the started but uncommitted state, the first-phase commit state, and the second-phase commit state; Determine the visibility of the target transaction to the records to be queried according to the visibility view information and / or the target transaction registration information, including: if the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current transaction ID to be allocated, determine the visibility of the target transaction to the records to be queried according to the target transaction registration information and the visibility view information, including: if the transaction status information of the modified transaction is the started but uncommitted state, the target transaction is not visible to the records to be queried; If the transaction status information of the modified transaction is the second-phase commit state, compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is less than the current system sequence value, the target transaction is visible to the records to be queried; otherwise, the target transaction is not visible to the records to be queried; If the transaction status information of the modified transaction is the first-phase commit state, compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is greater than or equal to the current system sequence value, the target transaction is not visible to the records to be queried; if the commit sequence value of the modified transaction is less than the current system sequence value, obtain the new commit sequence value corresponding to the modified transaction from the metadata node, and determine the visibility of the target transaction to the records to be queried according to the new commit sequence value and the current system sequence value.
2. The method according to claim 1, wherein The visibility view information includes the current minimum active transaction ID and / or the current transaction ID to be allocated; Determine the visibility of the target transaction to the records to be queried according to the visibility view information, including: If the modified transaction ID is less than the current minimum active transaction ID, the target transaction is visible to the records to be queried; If the modified transaction ID is greater than the current transaction ID to be allocated, the target transaction is not visible to the records to be queried.
3. The method according to claim 1, characterized in that, Determine the visibility of the target transaction to the records to be queried according to the new commit sequence value and the current system sequence value, including: If the newly submitted sequence value is the initial value, the target transaction is invisible to the record to be queried; If the newly submitted sequence value is not the initial value, compare the newly submitted sequence value with the current system sequence value; If the newly submitted sequence value is less than the current system sequence value, the target transaction is visible to the record to be queried; If the newly submitted sequence value is greater than or equal to the current system sequence value, the target transaction is invisible to the record to be queried.
4. The method according to claim 1, wherein Obtain the target transaction registration information corresponding to the modification transaction, including: According to the modification transaction ID, obtain the target transaction registration information corresponding to the modification transaction from the global transaction registration information, and the global transaction registration information includes the transaction status information and the submission sequence value corresponding to each started transaction.
5. The method according to claim 1, wherein The method further includes: Register or update the target transaction registration information according to the received transaction processing message.
6. The method according to claim 5, wherein The transaction processing message includes: a transaction start message, a first-phase commit message, and a second-phase commit message; The registering or updating the target transaction registration information according to the received transaction processing message includes: If the received transaction processing message is a transaction start message, register the target transaction registration information and store it in the local storage, where the registered target transaction registration information includes that the transaction status information of the modification transaction is the started and uncommitted state, and the submission sequence value of the modification transaction is the initial value; If the received transaction processing message is a first-phase commit message, update the transaction status information and the submission sequence value of the target transaction registration information in the local storage to the first-phase commit state and the first system sequence value respectively; If the received transaction processing message is a second-phase commit message, update the transaction status information and the submission sequence value of the target transaction registration information in the local storage to the second-phase commit state and the second system sequence value respectively; Wherein, the first system sequence value is the system sequence value after receiving the first-phase commit message; the second system sequence value is the system sequence value after receiving the second-phase commit message.
7. A data visibility judgment device, characterized in that Including: A first obtaining module, configured to obtain a modification transaction identifier ID from a record to be queried when a target transaction executes a database query operation, where the modification transaction is the transaction that finally modifies the record to be queried; A second obtaining module, configured to obtain the visibility view information corresponding to the target transaction and / or the target transaction registration information corresponding to the modification transaction in the local storage, where the visibility view information is used to represent the visible information associated with non-target transactions, and the target transaction registration information is used to represent the information of the transaction processing registration of the modification transaction; wherein, the visibility view information includes the current minimum active transaction ID, the current transaction ID to be allocated, and the current system sequence value, and the target transaction registration information includes the transaction status information of the modification transaction and the submission sequence value of the modification transaction, and the transaction status information includes the started and uncommitted state, the first-phase commit state, and the second-phase commit state; A determination module, configured to determine the visibility of the target transaction to the record to be queried according to the visibility view information and / or the target transaction registration information; Specifically, when the modified transaction ID is greater than or equal to the current minimum active transaction ID and less than or equal to the current to-be-allocated transaction ID, the determination module determines the visibility of the target transaction to the record to be queried according to the target transaction registration information and the visibility view information, including: when the transaction status information of the modified transaction is in the started but uncommitted state, the target transaction is invisible to the record to be queried; When the transaction status information of the modified transaction is in the second-phase commit state, compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is less than the current system sequence value, the target transaction is visible to the record to be queried; otherwise, the target transaction is invisible to the record to be queried; When the transaction status information of the modified transaction is in the first-phase commit state, compare the commit sequence value of the modified transaction with the current system sequence value; if the commit sequence value of the modified transaction is greater than or equal to the current system sequence value, the target transaction is invisible to the record to be queried; if the commit sequence value of the modified transaction is less than the current system sequence value, obtain the new commit sequence value corresponding to the modified transaction from the metadata node, and determine the visibility of the target transaction to the record to be queried according to the new commit sequence value and the current system sequence value.
8. A database node, characterized in that, The database node includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the data visibility determination method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the data visibility determination method according to any one of claims 1-6 is implemented.
Citation Information
Patent Citations
Transaction processing method, transaction system, equipment and storage medium
CN113590273A