Transaction processing method and device, node and computer readable storage medium
Patent Information
- Application Number
- CN202280094542.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-04
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-08-04
AI Technical Summary
In a distributed database scenario, the transaction processing delay is long, especially when the write object is successfully locked and the version value verification is passed before the read object version value is verified, resulting in a long data submission delay.
In the transaction processing method, the data items are first read from the master node of the write object and the read object respectively, and write lock and read lock messages are sent in parallel after reading, so as to lock the object and verify the version value in parallel to avoid Depend on the successful locking of the write object and then verify the version value of the read object.
The transaction processing delay is shortened, the transaction processing efficiency is improved, and the correctness and reliability of the data are ensured.
Smart Images

Figure CN119013659A_ABST
Abstract
Description
Transaction processing method, device, node and computer-readable storage medium Technical Field
[0001] The present application relates to the field of data access technology, and in particular to a transaction processing method, device, node, and computer-readable storage medium. Background Art
[0002] Applications can access storage objects in a database through multiple transactions. A transaction includes information about at least one storage object to be accessed and information about at least one access operation to be performed on the at least one storage object. The at least one access operation can include a read operation and / or a write operation. The storage object targeted by a read operation is referred to as a read object, and the storage object targeted by a write operation is referred to as a write object. Currently, in distributed scenarios such as data centers, storage objects in a database are distributed across multiple physical nodes. Furthermore, to ensure data reliability, after a storage object is stored on a corresponding physical node, it can also be backed up to other physical nodes. The physical node corresponding to the storage object is the primary node where the storage object resides, and the other physical nodes used to back up the storage object are the backup nodes for the storage object. Therefore, when a transaction accesses multiple storage objects, the primary and backup nodes for these multiple storage objects may be different. In this case, the transaction initiating node can process transactions based on the optimistic concurrency control (OCC) protocol to implement transaction concurrency control.
[0003] Currently, in the OCC protocol, the transaction initiating node first reads the storage object including the version value from the master node where the storage object to be accessed is located based on the transaction to be processed. If there are multiple storage objects read and the multiple storage objects include read objects and write objects, the transaction initiating node first modifies the data items of the write object among the multiple storage objects. After modifying the data items of the write object, the transaction initiating node interacts with the master node where the write object is located to lock the write object and verify the version value of the write object. After the write object is locked successfully and the version value is verified successfully, the transaction initiating node interacts with the master node where the read object is located among the multiple storage objects to verify the version value of the read object. After the version value of the read object is verified successfully, the transaction initiating node submits the updated data items of the write object to the master node and backup node of the write object. After the submission is successful, the transaction initiating node can generate a transaction completion notification to notify the upper-layer application that the transaction processing is completed.
[0004] It can be seen from this that in the above transaction processing process, after the data item of the write object is modified, the transaction initiating node must interact with the primary node where the write object is located, the primary node where the read object is located, and the backup node of the write object multiple times in sequence to complete the submission of the updated data item, thereby notifying the upper-level application that the transaction processing is completed, which takes a long time.
[0005] Summary of the Invention
[0006] The embodiments of the present application provide a transaction processing method, device, node, and computer-readable storage medium, which can shorten transaction processing latency and improve transaction processing efficiency.
[0007] In a first aspect, the present application provides a transaction processing method, applied to a first node, the method comprising: based on information of a write object and information of a read object included in a first transaction, reading the write object from a second node and reading the read object from a third node, the write object including a first data item, the second node being the primary node where the write object is located, and the third node being the primary node where the read object is located; modifying the first data item to obtain an updated first data item; sending a write lock message to the second node and sending a read lock message to the third node, the read lock message being used to add a read lock to the read object and detecting whether the read object read by the first node is correct; upon receiving a write lock success response from the second node and a read lock success response from the third node, submitting the updated first data item to the second node and the fourth node, the write lock success response indicating that the write lock is successfully added to the write object and the read write object is correct, and the read lock success response indicating that the read lock is successfully added to the read object and the read read object is correct, the fourth node being a backup node for the write object.
[0008] In an embodiment of the present application, a first node reads a write object from a second node and a read object from a third node. After modifying the data item of the write object, it can send a write lock message to the second node and a read lock message to the third node. In this way, the second and third nodes can lock the object and verify the version value in no particular order. That is, the first node can initiate the lock and version value verification of the write object and the version value verification of the read object in parallel. This shortens the transaction processing time compared to performing the version value verification of the read object after the write object is successfully locked and the version value is verified. Moreover, in an embodiment of the present application, even if the third node returns a read lock response first and the second node returns a write lock response later, that is, even if the third node successfully verifies the version value of the read object before the second node successfully locks the write object, because the third node successfully verifies the version value of the read object and also successfully adds a read lock to the read object, the read object will not be tampered with by other transactions before the second node successfully adds a write lock to the write object, thus ensuring the correctness of the submitted data. As can be seen from this, the embodiment of the present application shortens the transaction processing time while ensuring the correctness of the submitted data.
[0009] Optionally, the implementation process of sending a write lock message to the second node and sending a read lock message to the third node can be: sending the write lock message to the second node and sending the read lock message to the third node at the same time; or, sending the write lock message to the second node; after sending the write lock message and when the write lock success response has not been received, sending the read lock message to the third node; or, sending the read lock message to the third node; after sending the read lock message and when the read lock success response has not been received, sending the write lock message to the second node.
[0010] In an embodiment of the present application, since the read lock message instructs the third node not only to verify the version of the read object, but also to lock the read object, even if the third node successfully verifies the version value of the read object before the second node successfully locks the write object, the read object will not be tampered with by other transactions before the write object is successfully locked. It can be seen that the first node does not have to send the read lock message after receiving the write lock success response from the second node. In other words, the verification of the read object does not have to rely on the locking and verification of the write object, and data correctness can be guaranteed. Moreover, since the read object does not need to be verified after the write object is successfully locked, the two can be executed in parallel or in a very short time difference, so the transaction processing delay can be shortened, thereby improving transaction processing efficiency.
[0011] Optionally, when submitting the updated first data item to the second node and the fourth node, the first node may also send a read lock release message to the third node, where the read lock release message is used to instruct the third node to release the read lock of the read object.
[0012] The first node may send a read lock release message to the third node during the process of submitting the updated first data item. In this way, this step may be executed in parallel with the step of submitting the updated first data item, thereby shortening the transaction processing delay.
[0013] Optionally, the first node may also send a read lock release message to the third node after the updated first data item is successfully submitted. In this way, other transactions cannot modify the read object during the submission process.
[0014] Optionally, upon receiving a write lock failure response from the second node and / or a read lock failure response from the third node, a process abort message is sent to the second node and the third node, the write lock failure response indicating that the write lock on the write object failed and / or the write object read by the first node is incorrect, the read lock failure response indicating that the read lock on the read object failed and / or the read object read by the first node is incorrect, the process abort message is used to indicate the abort of processing of the first transaction, and the process abort message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0015] In an embodiment of the present application, if any of the verification and locking of the read object and the verification and locking of the write object fails, the first node can abort the processing of the first transaction and instruct the second node and the third node to release the locks added to the corresponding objects based on the first transaction.
[0016] Optionally, the write object and the read object read by the first node both include version values, the write lock message includes the version value of the write object read by the first node, and the read lock message includes the version value of the read object read by the first node. The write object or the read object read by the first node is correct if the version value of the corresponding object read by the first node meets the verification conditions.
[0017] Optionally, the verification condition refers to that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding master node is a stable version value corresponding to the version value of the corresponding object read by the first node, or, the verification condition refers to that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been submitted successfully, and the stable version value is used to indicate that the updated data item of the corresponding object has been submitted successfully.
[0018] Optionally, the write lock message also includes the updated first data item; when the version value of the object includes the above-mentioned intermediate version value and stable version value, the implementation process of submitting the updated first data item to the second node and the fourth node may include: sending a main submission message to the second node, and sending a backup submission message to the fourth node, the backup submission message including the updated first data item; upon receiving a main submission success response from the second node and a backup submission success response from the fourth node, determining that the updated first data item is successfully submitted, the main submission success response is sent by the second node after updating the stored data item and the first version value of the write object based on the main submission message and the updated first data item, the updated write object includes a second version value, and the second version value is the next intermediate version value of the first version value. The backup submission success response is sent by the fourth node after receiving the backup submission message.
[0019] In an embodiment of the present application, the version value of any object may include a stable version value and an intermediate version value. The intermediate version value is used to indicate that the updated data item of the corresponding object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the corresponding object has been successfully submitted. On this basis, the state of the write object can be identified by switching between the two version values. Therefore, even if the first node sends a main submission message before receiving a successful response to the backup submission, the second node can also switch the version value of the write object to the intermediate version value to indicate that the write object is in the modification process. In this way, for other transactions that want to modify the write object, the version of the write object can be verified based on the intermediate version value, thereby ensuring the correctness of the data. In this way, by switching between the two version values, on the one hand, write conflicts of transactions on the corresponding objects are avoided, ensuring the correctness of the data read by the transaction. On the other hand, the sending of the main submission message does not depend on the reception of the successful response to the backup submission. In this way, the sending of the main submission message and the sending of the backup submission message can be executed in a very short time or even in parallel, shortening the time required from starting to process the first transaction to notifying the upper-level application of the completion of the transaction processing.
[0020] Optionally, the implementation process of sending the main submission message to the second node and sending the backup submission message to the fourth node can be: sending the main submission message to the second node and sending the backup submission message to the fourth node at the same time; or, sending the backup submission message to the fourth node, and after sending the backup submission message and when the backup submission success response has not been received, sending the main submission message to the second node; or, sending the main submission message to the second node, and when sending the main submission message and when the main submission success response has not been received, sending the backup submission message to the fourth node.
[0021] Optionally, when the first node does not receive a primary submission success response from the second node and / or a backup submission success response from the fourth node, the first node may send a process termination message to the second node, the third node and the fourth node, and the process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0022] Optionally, in the case where any object includes an intermediate version value and a stable version value, after the updated first data item is successfully submitted, the first node may also send a write lock release message to the second node, wherein the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object, wherein the third version value is the stable version value corresponding to the second version value.
[0023] In an embodiment of the present application, after the updated first data item is successfully submitted, the first node can instruct the second node to update the version value of the write object to a stable version value to indicate that the write object has entered a stable state, and at the same time unlock the write object so that other subsequent transactions can access the write object.
[0024] Optionally, after the updated first data item is successfully submitted, the first node may send a first deletion message to the second node, where the first deletion message is used to instruct the second node to delete the write lock message and the main submission message; and send a second deletion message to the fourth node, where the second deletion message is used to instruct the fourth node to update the stored data item and the first version value of the write object based on the backup submission message and delete the backup submission message.
[0025] Optionally, after the updated first data item is successfully submitted, the first node may also notify the upper-layer application that the transaction processing is completed.
[0026] In a second aspect, a transaction processing method is provided, which is applied to a first node, the method comprising: based on the information of the write object and the read object included in the first transaction, reading the write object from the second node and reading the read object from the third node, the write object and the read object both including version values, and the write object including a first data item, the second node being the master node where the write object is located, and the third node being the master node where the read object is located; modifying the first data item to obtain an updated first data item; when a write lock is successfully added to the write object in the second node and the write object and the read object read by the first node are both correct, sending a primary commit message for submitting the updated first data item to the second node, and sending a backup commit message for submitting the updated first data item to the fourth node, the correctness of the write object or the read object read by the first node means that the version value of the corresponding object read by the first node is the intermediate version value and the version value of the corresponding object in the corresponding master node is the first node. The stable version value corresponding to the version value of the corresponding object read by the first node, or the stable version value corresponding to the version value of the corresponding object read by the first node, or the stable version value of the corresponding object read by the first node and the version value of the corresponding object in the corresponding master node are the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the corresponding object has been successfully submitted, and the fourth node is the backup node of the write object; upon receiving the primary submission success response from the second node and the backup submission success response from the fourth node, a transaction completion notification is generated, the primary submission success response is sent by the second node after updating the stored data item and the first version value of the write object based on the primary submission message and the updated first data item, the updated write object includes a second version value, and the second version value is the next intermediate version value of the first version value, and the backup submission success response is sent by the fourth node after receiving the backup submission message.
[0027] In an embodiment of the present application, the version value of any object may include a stable version value and an intermediate version value. The intermediate version value is used to indicate that the updated data item of the corresponding object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the corresponding object has been successfully submitted. On this basis, the state of the write object can be identified by switching between the two version values. Therefore, even if the first node sends a main submission message before receiving a successful backup submission response, the second node can also switch the version value of the write object to the intermediate version value to indicate that the write object is in the modification process. In this way, for other transactions that want to modify the write object, the version of the write object can be verified based on the intermediate version value, thereby ensuring the correctness of the data. In this way, by switching between the two version values, on the one hand, write conflicts between transactions and storage objects are avoided, ensuring the correctness of the data read by the transaction. On the other hand, the sending of the main submission message does not depend on the reception of a successful backup submission response. In this way, the sending of the main submission message and the sending of the backup submission message can be executed in a very short time or even in parallel, shortening the time required from starting to process the first transaction to notifying the upper-level application of the completion of the transaction processing.
[0028] Optionally, the implementation process of sending the main submission message to the second node for submitting the updated first data item and sending the backup submission message to the fourth node for submitting the updated first data item can be: sending the main submission message to the second node and sending the backup submission message to the fourth node at the same time; or, sending the backup submission message to the fourth node, and after sending the backup submission message and when the backup submission success response has not been received, sending the main submission message to the second node; or, sending the main submission message to the second node, and after sending the main submission message and when the main submission success response has not been received, sending the backup submission message to the fourth node.
[0029] Optionally, after generating the transaction completion notification, the first node may also send a write lock release message to the second node, wherein the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
[0030] Optionally, after modifying the data item of the write object to obtain the updated first data item, the first node may send a write lock message to the second node, wherein the write lock message instructs the second node to add a write lock to the write object and verify whether the write object is correct. Upon receiving the write lock success response sent by the second node, the first node sends a verification message to the third node, wherein the verification message instructs the third node to verify whether the read object read by the first node is correct. Upon receiving the verification success response sent by the third node, it is determined that the write lock on the write object in the second node is successfully added and that the write object and the read object read by the first node are correct.
[0031] Optionally, after modifying the data item of the write object to obtain an updated first data item, the first node may send a write lock message to the second node and a read lock message to the third node, the write lock message instructing the second node to add a write lock to the write object and detect whether the write object read by the first node is correct, and the read lock message instructs the third node to add a read lock to the read object and detect whether the read object read by the first node is correct; upon receiving a write lock success response from the second node and a read lock success response from the third node, it is determined that the write lock on the write object in the second node is successful and that the write object and the read object read by the first node are both correct.
[0032] Optionally, if the first node sends a read lock message to the third node, then in the process of sending a primary commit message to the second node and sending a backup commit message to the fourth node, or when receiving a primary commit success response and a backup commit success response, the first node may also send a read lock release message to the third node to instruct the third node to release the read lock added to the read object based on the first transaction.
[0033] In a third aspect, a transaction processing device is provided. The transaction processing device is deployed on a first node and includes at least one module configured to implement the transaction processing method described in the first aspect. Exemplarily, the at least one module includes a read module, a modify module, a send module, and a commit module.
[0034] Among them, the reading module is used to read the write object from the second node and the read object from the third node based on the information of the write object and the read object included in the first transaction, the write object including a first data item, the second node is the primary node where the write object is located, and the third node is the primary node where the read object is located; the modification module is used to modify the first data item to obtain an updated first data item; the sending module is used to send a write lock message to the second node and a read lock message to the third node, the read lock message is used to add a read lock to the read object and detect whether the read object read by the first node is correct; the commit module is used to commit the updated first data item to the second node and the fourth node when receiving a write lock success response from the second node and a read lock success response from the third node, the write lock success response indicating that the write lock is successfully added to the write object and the read write object is correct, and the read lock success response indicating that the read lock is successfully added to the read object and the read read object is correct, and the fourth node is a backup node for the write object.
[0035] Optionally, the sending module is mainly used to: send the write lock message to the second node and send the read lock message to the third node at the same time; or, send the write lock message to the second node; after sending the write lock message and when the write lock success response has not been received, send the read lock message to the third node; or, send the read lock message to the third node; after sending the read lock message and when the read lock success response has not been received, send the write lock message to the second node.
[0036] Optionally, the sending module is also used to: when the submission module submits the updated first data item to the second node and the fourth node, send a read lock release message to the third node, and the read lock release message is used to instruct the third node to release the read lock of the read object.
[0037] Optionally, the sending module is also used to: upon receiving a write lock failure response from the second node and / or a read lock failure response from the third node, send a process termination message to the second node and the third node, the write lock failure response indicating that the write lock on the write object failed and / or the write object read by the first node is incorrect, the read lock failure response indicating that the read lock on the read object failed and / or the read object read by the first node is incorrect, the process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0038] Optionally, the write object and the read object read by the first node both include version values, the write lock message includes the version value of the write object read by the first node, and the read lock message includes the version value of the read object read by the first node. The write object or the read object read by the first node is correct if the version value of the corresponding object read by the first node meets the verification conditions.
[0039] Optionally, the verification condition refers to that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding master node is a stable version value corresponding to the version value of the corresponding object read by the first node, or, the verification condition refers to that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been submitted successfully, and the stable version value is used to indicate that the updated data item of the corresponding object has been submitted successfully.
[0040] Optionally, the write lock message also includes the updated first data item; the submission module is mainly used to: send a main submission message to the second node, and send a backup submission message to the fourth node, the backup submission message including the updated first data item; upon receiving a main submission success response from the second node and a backup submission success response from the fourth node, determine that the updated first data item is successfully submitted, the main submission success response is sent by the second node after updating the stored data item and the first version value of the write object based on the main submission message and the updated first data item, the updated write object includes a second version value, and the second version value is the next intermediate version value of the first version value, and the backup submission success response is sent by the fourth node after receiving the backup submission message.
[0041] Optionally, the submission module is mainly used to: send the main submission message to the second node, and send the backup submission message to the fourth node at the same time; or, send the backup submission message to the fourth node, and after sending the backup submission message and when the backup submission success response has not been received, send the main submission message to the second node; or, send the main submission message to the second node, and after sending the main submission message and when the main submission success response has not been received, send the backup submission message to the fourth node.
[0042] Optionally, the sending module is also used to: send a process termination message to the second node, the third node and the fourth node when no primary submission success response from the second node and / or a backup submission success response from the fourth node is received, the process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0043] Optionally, the sending module is also used to: send a write lock release message to the second node, wherein the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object, and the third version value is the stable version value corresponding to the second version value.
[0044] Optionally, the sending module is also used to: send a first deletion message to the second node, the first deletion message is used to instruct the second node to delete the write lock message and the main commit message; send a second deletion message to the fourth node, the second deletion message is used to instruct the fourth node to update the stored data items and first version value of the write object based on the backup commit message and delete the backup commit message.
[0045] In a fourth aspect, a transaction processing device is provided. The transaction processing device is deployed on a first node and includes at least one module configured to implement the transaction processing method described in the second aspect. Exemplarily, the at least one module includes a read module, a modify module, a commit module, and a generate module.
[0046] Among them, the reading module is used to read the write object from the second node and the read object from the third node based on the information of the write object and the read object included in the first transaction, the write object and the read object both include version values, and the write object includes a first data item, the second node is the master node where the write object is located, and the third node is the master node where the read object is located; the modification module is used to modify the first data item to obtain an updated first data item; the submission module is used to send a primary submission message for submitting the updated first data item to the second node and a backup submission message for submitting the updated first data item to the fourth node when the write lock is successfully added to the write object in the second node and the write object and the read object read by the first node are correct, the write object or the read object read by the first node is correct means that the version value of the corresponding object read by the first node is the intermediate version value and the version value of the corresponding object in the corresponding master node is the corresponding version value read by the first node. The stable version value corresponding to the version value of the object, or the version value of the corresponding object read by the first node is the stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the corresponding object has been successfully submitted, and the fourth node is the backup node of the write object; a generation module is used to generate a transaction completion notification when receiving a primary submission success response from the second node and a backup submission success response from the fourth node, the primary submission success response is sent by the second node after updating the stored data item and the first version value of the write object based on the primary submission message and the updated first data item, the updated write object includes a second version value, the second version value is the next intermediate version value of the first version value, and the backup submission success response is sent by the fourth node after receiving the backup submission message.
[0047] Optionally, the submission module is mainly used to: send the main submission message to the second node, and send the backup submission message to the fourth node at the same time; or, send the backup submission message to the fourth node, and after sending the backup submission message and when the backup submission success response has not been received, send the main submission message to the second node; or, send the main submission message to the second node, and after sending the main submission message and when the main submission success response has not been received, send the backup submission message to the fourth node.
[0048] Optionally, the device also includes: a sending module, used to send a write lock release message to the second node, the write lock release message is used to instruct the second node to update the second version value to a third version value, and release the write lock of the updated write object, the third version value is the stable version value corresponding to the second version value.
[0049] Optionally, the sending module is further configured to, after modifying the data item of the write object and obtaining the updated first data item, send a write lock message to the second node, the write lock message instructing the second node to add a write lock to the write object and verify whether the write object read by the first node is correct. Upon receiving a write lock success response from the second node, the sending module sends a verification message to the third node, the verification message instructing the third node to verify whether the read object read by the first node is correct. Upon receiving a verification success response from the third node, the sending module determines that the write lock on the write object in the second node is successfully added and that both the write object and the read object read by the first node are correct.
[0050] Optionally, the sending module is also used to send a write lock message to the second node and a read lock message to the third node, the write lock message instructing the second node to add a write lock to the write object and detect whether the write object read by the first node is correct, and the read lock message instructs the third node to add a read lock to the read object and detect whether the read object read by the first node is correct; upon receiving a write lock success response from the second node and a read lock success response from the third node, it is determined that the write lock on the write object in the second node is successful and that the write object and the read object read by the first node are correct.
[0051] Optionally, if the first node sends a read lock message to the third node, then in the process of sending a primary commit message to the second node and sending a backup commit message to the fourth node, or when receiving a primary commit success response and a backup commit success response, the sending module is also used to send a read lock release message to the third node to instruct the third node to release the read lock added to the read object based on the first transaction.
[0052] In a fifth aspect, a node is provided, comprising a processor and a memory, the memory being configured to store at least one program instruction or code that supports the node in executing the transaction processing method provided in the first or second aspect, and storing data involved in implementing the transaction processing method provided in the first or second aspect. The processor is configured to execute the program instruction or code stored in the memory.
[0053] In a sixth aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, which, when executed on a computer, enables the computer to execute the transaction processing method described in the first or second aspect above.
[0054] In a seventh aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the transaction processing method described in the first or second aspect above.
[0055] The technical solutions provided by the embodiments of the present application include at least the following beneficial effects:
[0056] In an embodiment of the present application, a first node reads a write object from a second node and reads a read object from a third node. After modifying the data item of the write object, a write lock message can be sent to the second node where the write object is located, and a read lock message can be sent to the third node where the read object is located. In this way, the second and third nodes can lock the object and verify the version value in no particular order. That is, the first node can initiate the lock and version value verification of the write object and the version value verification of the read object in parallel. This shortens the transaction processing time compared to verifying the version value of the read object after the write object is successfully locked and the version value is verified. Furthermore, in an embodiment of the present application, even if the third node returns a read lock response first and the second node returns a write lock response later, that is, even if the third node successfully verifies the version value of the read object before the second node successfully locks the write object, because the third node successfully verifies the version value of the read object and successfully adds a read lock to the read object at the same time as the read lock is passed, the read object will not be tampered with by other transactions before the second node successfully adds a write lock to the write object, thus ensuring the correctness of the submitted data. It can be seen that the embodiment of the present application shortens the transaction processing time while ensuring the correctness of the submitted data. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] FIG1 is a diagram of a system architecture involved in a transaction processing method provided in an embodiment of the present application;
[0058] FIG2 is another system architecture diagram involved in the transaction processing method provided in an embodiment of the present application;
[0059] FIG3 is a schematic diagram of the interaction timing between various nodes in a transaction processing flow provided in the related art;
[0060] FIG4 is a flow chart of a transaction processing method provided in an embodiment of the present application;
[0061] FIG5 is a schematic diagram of a data structure of a storage object provided in an embodiment of the present application;
[0062] FIG6 is a flowchart of another transaction processing method provided in an embodiment of the present application;
[0063] FIG7 is a flowchart of a first method of interaction between nodes to process transactions provided by an embodiment of the present application;
[0064] FIG8 is a schematic diagram of the interaction timing between various nodes in the first transaction processing flow provided by an embodiment of the present application;
[0065] FIG9 is a flowchart of a second method of interaction between nodes to process transactions provided by an embodiment of the present application;
[0066] FIG10 is a schematic diagram of the interaction timing between nodes in the second transaction processing flow provided in an embodiment of the present application;
[0067] FIG11 is a flowchart of a third method of interaction between nodes to process transactions provided by an embodiment of the present application;
[0068] FIG12 is a schematic diagram of the interaction timing between nodes in the third transaction processing flow provided by an embodiment of the present application;
[0069] FIG13 is a schematic diagram of the structure of a transaction processing device provided in an embodiment of the present application;
[0070] FIG14 is a schematic structural diagram of another transaction processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0071] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0072] Before explaining the embodiments of the present application in detail, the system architecture involved in the embodiments of the present application is first introduced.
[0073] The transaction processing method provided in the embodiment of the present application can be used to process distributed transactions in distributed scenarios such as data centers, etc. A distributed transaction refers to a transaction in which the storage objects to be accessed are distributed in different nodes.
[0074] Based on this, Figure 1 is a system architecture diagram involved in a transaction processing method provided in an embodiment of the present application. As shown in Figure 1, the system includes a computing node cluster and a storage node cluster. The computing node cluster includes one or more computing nodes 10 (two computing nodes 10 are shown in Figure 1, but are not limited to two computing nodes 10), and each computing node 10 can communicate with each other. The computing node 10 is a computing device, such as a server, desktop computer, etc.
[0075] At the hardware level, as shown in FIG1 , the computing node 10 includes at least a processor 101 , a memory 102 , and a network card 103 .
[0076] The processor 101 is a central processing unit (CPU) configured to process data access requests from outside the computing node 10 or requests generated within the computing node 10. The data access requests include read requests and write requests.
[0077] Memory 102 refers to an internal memory that directly exchanges data with processor 101. It can read and write data at any time and at a very high speed, and serves as a temporary data storage for the operating system or other running programs. Memory 102 includes at least two types of memory. For example, the memory can be either a random access memory or a read-only memory (ROM). For example, the random access memory is a dynamic random access memory (DRAM) or a storage class memory (SCM). However, DRAM and SCM are only exemplary in this embodiment. Memory 102 can also include other random access memories, such as static random access memory (SRAM). As for read-only memory, for example, it can be a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), etc. In addition, the memory 102 can also be a dual in-line memory module or a dual-line memory module (Dual In-line Memory Module, abbreviated as DIMM), that is, a module composed of dynamic random access memory (DRAM), or a solid state disk (SSD). In actual applications, multiple memories 102, as well as different types of memories 102, can be configured in the computing node 10. This embodiment does not limit the number and type of memory 102. In addition, the memory 102 can be configured to have a power-saving function. The power-saving function means that when the system loses power and then powers on again, the data stored in the memory 102 will not be lost. A memory with a power-saving function is called a non-volatile memory.
[0078] Network card 103 is used to communicate with storage node 11. For example, when the total amount of data in memory 102 reaches a certain threshold, compute node 10 can send a request to storage node 11 via network card 103 to persistently store the data. Network card 103 can be a remote direct memory access (RDMA) network card. In this case, network card 103 can bypass processor 101 and directly read and write to the memory of storage node 11.
[0079] In addition, the computing node 10 may also include a bus for communication between the various components within the computing node 10. Functionally, since the computing node 10 in Figure 1 primarily performs computing tasks, it can utilize remote storage for persistent data storage. Therefore, it has less local storage than a conventional server, thereby saving cost and space. However, this does not mean that the computing node 10 cannot have local storage. In actual implementation, the computing node 10 may also have a small number of internal hard drives or external hard drives.
[0080] At the software level, as shown in Figure 1, an application 104 (abbreviated as application) can be run on the computing node 10. Application 104 is a general term for various applications presented to users. The client 105 is used to receive data access requests triggered by the application 104, and interact with the storage node 11 to send the data access request to the storage node 11. The client 105 is also used to receive data from the storage node 11 and forward the data to the application 104. It can be understood that when the client 105 is a software program, the function of the client 105 is implemented by the processor 101 included in the computing node 10 running the program in the memory 102. The client 105 can also be implemented by a hardware component located inside the computing node 10. Any client 105 in the computing node cluster can access any storage node 11 in the storage node cluster.
[0081] For example, in an embodiment of the present application, application 104 may trigger a transaction processing request, and client 105 may be a coordinator client in a distributed transaction processing system. The coordinator client is configured to receive the transaction processing request from application 104, initiate the processing of the transaction, and interact with storage node 11 to coordinate the execution of the transaction, determine the steps for executing the transaction, and ultimately determine whether the transaction is committed or terminated. Accordingly, the computing node on which the coordinator client is deployed may be referred to as a transaction initiating node.
[0082] Any computing node 10 can access any storage node 11 in the storage node cluster through the network. The storage node cluster includes multiple storage nodes 11 (three storage nodes 11 are shown in Figure 1, but are not limited to three storage nodes 11). Among them, some storage nodes among the multiple storage nodes 11 are master nodes for certain storage objects, and some storage nodes are backup nodes for certain storage objects. That is, in an embodiment of the present application, in the storage node cluster, a master-copy mechanism is adopted to store objects. Each storage object has a corresponding master node and backup node. Among them, the master node of a storage object refers to the node that stores the master copy of the storage object, and the backup node refers to the node that stores the backup copy of the storage object.
[0083] Exemplarily, a storage node 11 includes one or more controllers 111, a network card 112, and multiple hard disks 113. The network card 112 is used to communicate with the computing node 10. The network card 112 can be an RDMA network card. The hard disk 113 is used to store data and can be a disk or other types of storage media, such as a solid-state drive or a shingled magnetic recording hard disk. The controller 111 is used to write data to the hard disk 113 or read data from the hard disk 113 according to the read / write data request sent by the computing node 10. In the process of reading and writing data, the controller 111 needs to convert the address carried in the read / write data request into an address that can be recognized by the hard disk. It can be seen that the controller 111 also has some simple computing functions.
[0084] In actual applications, the controller 111 can have various forms. In one case, the controller 111 includes a CPU and a memory. The CPU is used to perform operations such as address conversion and reading and writing data. The memory is used to temporarily store data to be written to the hard disk 113, or data read from the hard disk 113 to be sent to the computing node 10. In addition, the memory can also store program instructions executable by the CPU. For example, in an embodiment of the present application, the memory stores program instructions for implementing the master node and / or backup node where the storage node is located in the transaction processing system, and accordingly, the CPU can execute the program instructions so that the corresponding storage node 11 implements the relevant functions of the master node and / or backup node where the storage object is located in the transaction processing system.
[0085] In the system architecture shown in Figure 1, compute nodes and storage nodes are separate. The coordinator client in the distributed transaction processing system runs on the compute nodes, while the primary or backup node functions for storage objects are deployed on the storage nodes. In other words, in the system shown in Figure 1, the compute nodes are the transaction initiating nodes, while the storage objects accessed by the transactions are located on the storage nodes.
[0086] In another possible implementation, a node can be deployed with both a coordinator client and program instructions for implementing the processing functions of the primary node and / or backup node where the storage object is located. That is, a node can serve as a transaction initiating node, and at the same time, the node can also be the primary node for some storage objects and the backup node for other storage objects. For example, referring to Figure 2, the system includes multiple nodes 20 (three nodes 20 are shown in Figure 2, but are not limited to three nodes 20), and the multiple nodes 20 can communicate with each other. Among them, the node 20 is a device with both computing power and storage capacity, such as a server, a desktop computer, etc. For example, an ARM server or an X86 server can serve as the node 20 here. Moreover, in an embodiment of the present application, when each node 20 provides storage resources to store data, each storage object has not only a primary node but also a backup node, that is, the data stored persistently in the system is stored using a master-copy mechanism. Among them, the primary node of a storage object refers to the node that stores the primary copy of the storage object, and the backup node of a storage object refers to the node that stores the backup copy of the storage object.
[0087] At the hardware level, as shown in Figure 2, node 20 includes at least a processor 201, a memory 202, a network card 203, and a hard disk 204. The processor 201, the memory 202, the network card 203, and the hard disk 204 are connected via a bus.
[0088] Processor 201 and memory 202 are used to provide computing resources. Specifically, processor 201 is a central processing unit (CPU) that processes data access requests from outside node 20 (application servers or other nodes 20) and also processes requests generated within node 20. The data access request can be a write request or a read request.
[0089] Memory 202 refers to internal storage that directly exchanges data with processor 201. It can read and write data at any time and at high speed, serving as temporary data storage for the operating system or other running programs. Memory 201 includes at least two types of memory. For example, memory can be either random access memory (RAM) or ROM. For example, random access memory is DRAM or SCM. However, DRAM and SCM are merely exemplary in this embodiment; memory can also include other random access memories, such as SRAM. For example, read-only memory can be PROM, EPROM, etc. Memory 202 can also be a DIMM (a module composed of DRAM) or an SSD. In actual applications, node 20 can be configured with multiple memories 202, and memories 202 of different types. This embodiment does not limit the number or type of memory 202. Furthermore, memory 202 can be configured with a power-saving feature. This power-saving feature ensures that data stored in memory 202 is not lost even after the system loses power and then powers back on. Memory with a power-saving feature is called non-volatile memory.
[0090] The network card 203 is used to communicate with other nodes 20. For example, in the embodiment of the present application, the network card 203 may be an RDMA network card. In this case, the RDMA network card in any node 20 can bypass the processor 201 of the node and directly access the memory in other nodes 20.
[0091] The hard disk 204 is used to provide storage resources, such as storing data, and can be a magnetic disk or other types of storage media, such as a solid state drive or a shingled magnetic recording hard disk.
[0092] At the software level, as shown in Figure 2, node 20 is deployed with an application 205 (referred to as the application) and a client program 206 (referred to as the client). Application 205 can directly trigger write or read requests through client 206 in node 20, which are then processed by that node 20 or sent to other nodes 20 for processing. In this case, a data access request sent by client 206 to the local node 20 is specifically a data access request sent by the client to the processor.
[0093] Exemplarily, in an embodiment of the present application, the client 206 may be a software client of a distributed transaction processing system. The client 206 may include a coordinator processing module, a master node processing module, and a backup node processing module. When the application 205 in the node 20 triggers a transaction processing request, the coordinator processing module in the client 206 may receive the transaction processing request and interact with the master node and backup node where the storage object to be accessed by the transaction processing request is located to coordinate the execution of the transaction, determine the steps for executing the transaction, and determine whether the transaction is ultimately submitted or terminated. At this point, the function implemented by the node 20 is the function of a transaction initiating node. When the node 20 receives a data access request triggered by other nodes 20 based on a transaction processing request, the node 20 may process the data access request through the master node processing module and execute subsequent transaction processing steps under the scheduling of other nodes 20. At this point, the function implemented by the node 20 is the function of the master node where the storage object in a transaction is located. If the node 20 receives a backup commit message from another node 20, the node 20 can process the message through the backup node processing module and execute subsequent transaction processing steps under the scheduling of the other node 20. At this time, the function implemented by the node 20 is the function of the backup node where the storage object in a transaction is located.
[0094] As can be seen from the above description, in the distributed transaction processing process, nodes can be divided into transaction initiation nodes, primary nodes for the storage objects accessed by the transaction, and backup nodes, based on the different functions implemented by each node. Furthermore, it should be noted that in the embodiments of the present application, a node can be a physical machine.
[0095] Currently, transaction initiating nodes, primary nodes storing objects, and backup nodes typically process distributed transactions based on a distributed optimistic concurrency control (OCC) protocol.
[0096] In the distributed OCC protocol, the transaction processing process is divided into two phases, namely the execution phase and the submission phase. In the execution phase, the transaction initiating node has a temporary version of the storage object to be accessed by the transaction, and the temporary version is a copy of the latest successfully submitted version of the storage object. In addition, when the transaction includes a write operation, the transaction initiating node can modify the temporary version of the write object and record the modified version. In the submission phase, the transaction initiating node verifies the version value of each storage object by interacting with the master node of each storage object to be accessed to determine whether the operation of the transaction on the storage object conflicts with the operation of other transactions on the same storage object. If the verification is successful, that is, there is no conflict, the transaction initiating node interacts with the master node and backup node of each storage object to complete the submission of the transaction. For the write object, the modified version is mainly stored persistently in the corresponding master node and backup node.
[0097] In related art, when a first transaction to be processed includes both read and write operations, for example, as shown in Figure 3, when the two write operations in the first transaction target storage objects W1 and the one read operation targets storage object R1, during the execution phase, the transaction initiating node C first reads W1 from the primary node P1 where W1 resides, and reads R1 from the primary node P2 where R1 resides. W1 includes version value V1, and R1 includes version value V2. Subsequently, the transaction initiating node C modifies data item D1 in W1 and records the modified data item D1'.
[0098] In the commit phase, the transaction initiating node C can commit the transaction through the following five steps.
[0099] 1. Lock
[0100] In this step, the transaction initiating node C sends a lock message to the master node P1. The lock message includes (V1, D1'). The master node P1 compares V1 with the version value of W1 stored in its own storage and locks W1 stored in its own storage. If the version value of V1 is the same as the version value of W1 stored in its own storage and W1 is locked successfully, a lock success response is returned to the transaction initiating node C. If the version value of V1 is different from the version value of W1 stored in its own storage or the lock of W1 fails, a lock failure response is returned to the transaction initiating node.
[0101] If the transaction initiating node C receives a lock success response from the primary node P1, it executes step 2. If it receives a lock failure response from the primary node P1, the transaction initiating node C aborts the transaction processing flow and sends a abandon message to the primary node P1 to instruct it to unlock the successfully locked object.
[0102] 2. Verification
[0103] In this step, the transaction initiating node C reads R1 again from the master node P2. If the version value in the re-read R1 is the same as the version value V2 in R1 read in the execution phase and the re-read R1 is not locked, step 3 is executed.
[0104] If the version value in R1 read again is different from the version value V2 in R1 read in the execution phase or the R1 read again is locked, the transaction initiating node C terminates the processing flow of the transaction and sends a abandon message to the primary node P1 to instruct the successfully locked object to be unlocked.
[0105] 3. Backup submission
[0106] In this step, the transaction initiating node C sends a backup commit message to W1's backup node B1. The backup commit message contains the same content as the lock message in step 1. After receiving the backup commit message, backup node B1 can send a successful backup commit response back to the transaction initiating node C.
[0107] If the transaction initiating node C receives a backup commit success response sent by the backup node B1, step 4 is executed.
[0108] If the transaction initiating node C does not receive the backup commit success response sent by the backup node B1, the transaction processing flow is terminated and a abandon message is sent to the primary node P1 to instruct the successfully locked object to be unlocked.
[0109] 4. Master submission
[0110] In this step, the transaction initiating node C sends a master commit message to the master node P1. After receiving the master commit message, master node P1 updates the data item in its own storage W1 with D1' carried in the lock message received in step 1 and unlocks its own storage W1. It then returns a master commit success response to the transaction initiating node C.
[0111] If the transaction initiating node C receives the master commit success response from the master node P1, it generates a transaction completion notification to notify the upper-layer application of the transaction execution completion. After that, the transaction initiating node C executes step 5.
[0112] 5. Delete
[0113] In this step, the transaction initiating node C sends a delete message to primary nodes P1 and P2, and backup node B1. Upon receiving the delete message, each primary node deletes all messages involved in the transaction. Upon receiving the delete message, the backup node modifies the corresponding write object data item stored in its own storage to the modified data item carried in the backup commit message, and then deletes all messages involved in the transaction.
[0114] As can be seen from the above description of the transaction processing process, currently, during the commit phase, the version value of the read object can only be verified after the write object is successfully locked. This is because if the read object's version value is verified before the write object is successfully locked, the read object may still be modified during the write object locking process, resulting in errors in the transaction's operations on the write object. Therefore, by successfully locking the write object first and then verifying the read object's version value, data correctness can be guaranteed. Furthermore, during the commit phase, data can only be submitted to the primary node after successfully submitting to the backup node, thereby ensuring data reliability. However, the timing between locking the write object and verifying the read object's version value, as well as the timing between the backup commit and the primary commit, while ensuring the correctness and reliability of data submission, results in longer transaction commit delays, which is unacceptable for certain latency-sensitive businesses.
[0115] Based on this, an embodiment of the present application provides a transaction processing method, wherein the first node reads the write object from the master node of the write object and reads the read object from the master node of the read object based on the information of the write object and the information of the read object included in the first transaction. After modifying the data item of the write object, the first node can send a write lock message to the master node of the write object and send a read lock message to the master node of the read object. In this way, the master node of the write object and the master node of the read object can perform locking and version value verification of the object in no particular order, that is, the first node can initiate locking and version value verification of the write object and version value verification of the read object in parallel. In this way, compared with verifying the version value of the read object after the write object is successfully locked and the version value verification is passed, the transaction processing time is shortened. Furthermore, in the embodiment of the present application, even if the master node of the read object returns a read lock response first and the master node of the write object returns a write lock response later, that is, even if the version value of the read object is successfully verified before the write object is successfully locked, because the master node of the read object successfully adds a read lock to the read object at the same time as the version value of the read object is verified, the read object will not be tampered with by other transactions before the master node of the write object successfully adds a write lock to the write object, thereby ensuring the correctness of the submitted data. As can be seen from this, the embodiment of the present application reduces the transaction submission delay while ensuring the correctness of the submitted data.
[0116] Next, the transaction processing method provided in the embodiment of the present application is introduced.
[0117] FIG4 is a flow chart of a transaction processing method provided in an embodiment of the present application. The method can be applied to a first node. The first node can be any computing node in the system architecture shown in FIG1 or any node in the system architecture shown in FIG2. Furthermore, the first node is the node that triggers transaction processing, that is, the first node is the transaction initiating node in the transaction processing process. Referring to FIG4, the method includes the following steps:
[0118] Step 401: Based on the information of the write object and the read object included in the first transaction, read the write object from the second node and read the read object from the third node, the write object includes the first data item, the second node is the master node where the write object is located, and the third node is the master node where the read object is located.
[0119] In an embodiment of the present application, the write object information included in the first transaction to be processed may include the address information of the write object, and the read object information may include the address information of the read object. Based on this, the first node can read the write object from the master node where the write object is located, that is, the second node, based on the address information of the write object, and read the read object from the master node where the read object is located, that is, the third node, based on the address information of the read object.
[0120] Exemplarily, the first node may read the write object from the storage object stored by the second node through the RDMA network card according to the address information of the write object, and read the read object from the storage object stored by the third node through the RDMA network card according to the address information of the read object.
[0121] It should be noted that both the write object and the read object described above may be referred to as a storage object. A storage object in the embodiments of the present application refers to a data unit stored in a node, for example, a data unit stored in the node's memory. A storage object may include metadata items and data items. Metadata items may include version values and lock information.
[0122] The version value is used to indicate the version of the storage object. In a possible implementation, the version value may include two types of version values, namely, an intermediate version value and a stable version value.
[0123] The intermediate version value indicates that the updated data item of the storage object has not been successfully submitted. In other words, the updated data item of the storage object already exists in the primary node of the storage object, but the updated data item has not yet been notified to the backup node of the storage object, or the updated data item has been notified to the backup node of the storage object, but the backup node has not yet confirmed receipt of the updated data item.
[0124] The stable version value indicates that the updated data item of the storage object has been successfully submitted. In other words, the master node has completed the update of the data item of the storage object stored on its own based on the updated data item of the storage object. In addition, the updated data item has been notified to all backup nodes of the storage object, and all backup nodes have confirmed receipt of the updated data item.
[0125] As an example, the intermediate version value in the embodiment of the present application can be represented by an odd number, and the stable version value can be represented by an even number. For any intermediate version value, the stable version value corresponding to the intermediate version value can be equal to the intermediate version value plus 1. The intermediate version value and the corresponding stable version value are version values in the process of modifying the storage object based on a transaction. In addition, for any stable version value, the stable version value corresponds to a unique next intermediate version value, and the next intermediate version value of the stable version value is equal to the stable version value plus 1. At this time, the stable version value is the version value after the updated data item of the storage object is successfully submitted based on a transaction, and the next intermediate version value corresponding to the stable version value is the version value when the updated data item of the storage object has not been successfully submitted in the process of modifying the version of the storage object indicated by the stable version value based on another transaction.
[0126] The above is an example of an intermediate version value and a stable version value given in this application. Obviously, the intermediate version value can also be represented by an even number. In this case, the stable version value can be represented by an odd number. This embodiment of the present application will not be repeated here.
[0127] In another possible implementation, the version value may not be divided into intermediate version values and stable version values. In this case, each time an updated data item is committed according to a transaction, the current version value of the storage object is incremented by 1. However, the version value of the storage object will not change until the transaction is committed.
[0128] The lock information may include a read lock field and a write lock field. The read lock field is used to implement a read lock on the storage object, and the write lock field is used to implement a write lock on the storage object. For example, when the value of the write lock field is 1, it indicates that the storage object is currently write-locked. When the value of the write lock field is 0, it indicates that the storage object is not currently write-locked. For another example, when the value of the read lock field is 0, it indicates that the storage object is not currently read-locked. When the value of the read lock field is n, it indicates the number of accessors who currently have a read lock on the storage object, that is, how many accessors share the read access to the storage object. Wherein, n is a positive integer greater than 0. In addition, in an embodiment of the present application, the above-mentioned accessor may refer to a transaction.
[0129] It is worth noting that in the embodiments of the present application, when a storage object is write-locked, it cannot be read-locked, and vice versa. For example, in the above examples of the values of the write lock field and the read lock field, when the value of the write lock field of the storage object is 1, the value of the read lock field will be 0, and when the value of the read lock field is n, the value of the write lock field will be 0. In other words, the situation where the read lock field is n and the write lock field is 1 will not occur.
[0130] In addition to the version value and lock information, the metadata item of the storage object may also include other information describing the data item, for example, the length information of the data item, which is not limited in the embodiments of the present application.
[0131] Figure 5 is a data structure diagram of a storage object provided by an embodiment of the present application. As shown in Figure 5, the storage object includes the aforementioned lock information, which includes a read lock field and a write lock field. Following the lock information is the version value of the storage object, followed by other metadata information, and following the other metadata information are the data items of the storage object.
[0132] Step 402: Modify the first data item to obtain an updated first data item.
[0133] After reading the write object and the read object, the first node modifies the first data item included in the read write object to obtain an updated first data item. The first node can then cache the updated first data item locally.
[0134] Step 403: Send a write lock message to the second node and send a read lock message to the third node. The read lock message is used to add a read lock to the read object and detect whether the read object read by the first node is correct.
[0135] After modifying the first data item to obtain the updated first data item, the first node may send a write lock message to the second node and a read lock message to the third node. In the embodiments of the present application, the first node does not specify a timing for sending the write lock message and the read lock message. That is, the first node may send the write lock message and the read lock message in any order.
[0136] For example, the first node may send a read lock message to the third node at the same time as sending a write lock message to the second node. Alternatively, the first node may first send a write lock message to the second node, and then, if it has not yet received a write lock success response from the second node based on the write lock message, send a read lock message to the third node. Alternatively, the first node may first send a read lock message to the third node, and then, if it has not yet received a read lock success response from the third node based on the read lock message, send a write lock message to the second node.
[0137] The write lock message instructs the second node to apply a write lock to the write object and detect whether the write object read by the first node is correct. Exemplarily, the write lock message includes a version value of the write object, which is the version value in the metadata item of the write object read by the first node from the second node. Based on this, detecting whether the write object read by the first node is correct may refer to detecting whether the version value of the write object read by the first node satisfies a verification condition. Furthermore, the write lock message may also include the updated first data item.
[0138] Optionally, when there are multiple write objects and the multiple write objects are located on different second nodes, the write lock messages sent by the first node to each second node may be the same or different. When the write lock messages sent to each second node are the same, the write lock messages include the version value of each write object and the updated first data item of each write object. When the write lock messages sent to each second node are different, the write lock message sent to any second node includes the version value and the updated first data item of the write object located on the second node, as read by the first node, from among the multiple write objects.
[0139] The read lock message instructs the third node to apply a read lock to the read object and detect whether the read object read by the first node is correct. Exemplarily, the read lock message includes a version value of the read object, which is the version value in the metadata item of the read object read by the first node from the third node. Based on this, detecting whether the read object read by the first node is correct may refer to detecting whether the version value of the read object read by the first node satisfies a verification condition.
[0140] It should be noted that, in addition to the above information, in the embodiment of the present application, the write lock message and the read lock message may also include the identifier and message type of the first transaction, wherein the identifier of the first transaction indicates that the write lock message and the read lock message are messages related to the first transaction sent by the first node. The message type indicates what type of message the corresponding message is. Of course, in the subsequent steps, the various messages sent by the first node to the second node, the third node, and the fourth node may also include the identifier and message type of the first transaction. In addition, when the corresponding message instructs the node to operate on a storage object, the message may also include the object identifier of the object to be operated. For example, the object identifier of the write object may be included in the write lock message so that the second node can determine the write object to be currently operated based on the object identifier of the write object. Similarly, the object identifier of the read object may be included in the read lock message, which will not be described in detail in the embodiment of the present application.
[0141] After receiving the write lock message, the second node caches the write lock message, adds a write lock to the write object based on the write lock message, and detects whether the write object read by the first node is correct.
[0142] The second node can search for the write object stored in its own storage based on the object identifier of the write object in the write lock message, and then detect whether the write object has been write-locked or read-locked based on the lock information of the write object found. If the lock information indicates that the write object has been write-locked or read-locked, the second node is unable to write-lock the write object. In this case, it is determined that the write lock failed for the write object. If the lock information indicates that the write object has neither been write-locked nor read-locked, the second node can write-lock the write object by modifying the lock information.
[0143] Exemplarily, as described above, the lock information of the write object may include a read lock field and a write lock field. The second node may detect whether the values of the read lock field and the write lock field are 0. If the value of the read lock field is not 0, it is determined that the write object has been read-locked. If the value of the write lock field is not 0, it is determined that the write object has been write-locked. In this case, it is determined that the write lock has failed to be added to the write object. If the values of the read lock field and the write lock field are both 0, the second node may modify the value of the write lock field to a non-zero value, for example, to 1, so as to implement a write lock for the write object.
[0144] In addition, the second node may also obtain the version value of the write object carried in the write lock message and obtain the current version value of the write object stored in its own storage. Based on the current version value of the write object stored in its own storage, it determines whether the version value of the write object read by the first node and carried in the write lock message meets the verification condition.
[0145] In the first implementation, if the version value of the storage object includes an intermediate version value and a stable version value, then when the version value of the write object read by the first node is an intermediate version value, the second node can determine whether the current version value of the write object stored in itself is the stable version value corresponding to the version value of the write object read by the first node. If the current version value of the write object stored in the second node is the stable version value corresponding to the version value read by the first node, it means that the write object read by the first node is the stable version of the write object currently stored in the second node. In this case, the second node can determine that the version value of the write object read by the first node meets the verification condition, that is, the write object read by the first node is correct.
[0146] If the current version value of the write object stored in the second node is not the stable version value corresponding to the version value of the write object read by the first node, then it means that the write object currently stored in the second node has changed relative to the write object read by the first node, or the write object currently stored in the second node has not changed relative to the write object read by the first node, but the write object currently stored in the second node is in a state of being modified by other transactions, that is, the write object currently stored in the second node has not entered a stable state. In this case, the second node can determine that the version value of the write object read by the first node does not meet the verification condition, that is, the write object read by the first node is incorrect.
[0147] For example, assuming that the version value of the write object read by the first node is 11, the stable version value corresponding to the version value of the write object is 12. Therefore, if the current version value of the write object stored in the second node is 12, it can be determined that the write object read by the first node is correct. If the current version value of the write object stored in the second node is 13, it means that the write object stored in the second node has been modified by another transaction. At this time, the write object stored in the second node is not the same as the write object read by the first node. In this case, it is determined that the write object read by the first node is incorrect. If the current version value of the write object stored in the second node is 11, it means that the write object stored in the second node is still in a state of being modified by other transactions, that is, the modifications to the write object by other transactions have not been successfully submitted, and the write object has not entered the stable state. In this case, the second node cannot accept the modifications to the write object by the first node. Therefore, the second node can determine that the write object read by the first node is wrong.
[0148] When the version value of the write object read by the first node is a stable version value, the second node can determine whether the current version value of the write object stored in its own storage is the same as the version value read by the first node. If the current version value of the write object stored in the second node is the same as the version value read by the first node, it means that the write object read by the first node is the write object currently stored in the second node, and the write object has not been modified by other transactions. In this case, the second node can determine that the version value of the write object meets the verification condition, that is, the write object read by the first node is correct.
[0149] If the current version value of the write object stored in the second node is different from the version value read by the first node, then the write object read by the first node is different from the write object currently stored in the second node. In this case, the second node can determine that the version value of the write object read by the first node does not meet the verification condition, that is, the write object read by the first node is incorrect.
[0150] For example, assuming the version value of the write object read by the first node is 12, if the current version value of the write object stored in the second node is also 12, then it can be determined that the write object read by the first node is correct. If the current version value of the write object stored in the second node is 13, then it can be determined that the write object read by the first node is incorrect.
[0151] In the second implementation method, if the version value of the storage object does not distinguish between the intermediate version value and the stable version value, the second node can determine whether the version value of the write object read by the first node carried in the write lock message is the same as the current version value of the write object stored by itself. If they are the same, it means that the write object read by the first node is the same as the write object stored by the second node. At this time, the second node can determine that the version value of the write object read by the first node meets the verification condition, that is, the write object read by the first node is correct.
[0152] If the version value of the write object read by the first node carried in the write lock message is different from the current version value of the write object stored by the second node, the second node can determine that the version value of the write object read by the first node does not meet the verification conditions, that is, the write object read by the first node is incorrect.
[0153] If the second node successfully applies a write lock to the write object using the above method and determines that the write object read by the first node is correct, the second node may return a write lock success response to the first node. If the second node fails to apply a write lock to the write object using the above method or determines that the write object read by the first node is incorrect, the second node may return a write lock failure response to the first node.
[0154] After receiving the read lock message, the third node may cache the read lock message, add a read lock to the read object based on the read lock message, and detect whether the read object read by the first node is correct.
[0155] The third node can determine whether the read object is read-locked or write-locked based on the lock information of the read object stored in the node. If the read object is already write-locked, the node determines that the read lock attempt on the read object has failed. If the read object is not write-locked, the third node can re-read-lock the read object regardless of whether the read object is already read-locked.
[0156] The implementation method for determining whether a read object is read locked or write locked can refer to the relevant implementation methods described above, and the embodiments of this application will not be repeated here. In addition, the third node can also implement a read lock on the read object by modifying the lock information. For example, the third node can add 1 to the value of the read lock field in the lock information of the read object stored by itself, thereby implementing a read lock for the read object again.
[0157] In addition, the third node can also verify the version value of the read object with reference to the method used by the second node to verify the version value of the write object, so as to detect whether the read object read by the first node is correct. The embodiments of this application will not be repeated here.
[0158] If the third node successfully applies a read lock to the read object and determines that the read object read by the first node is correct, the third node may return a read lock success response to the first node. If the third node fails to apply a read lock to the read object or determines that the read object read by the first node is incorrect, the third node may return a read lock failure response to the first node.
[0159] When the first node receives a write lock success response from the second node and a read lock success response from the third node, the following step 404 may be executed. Optionally, if the first node receives a write lock failure response from the second node, or receives a read lock failure response from the third node, or receives both, the first node may send a process abort message to the second node and the third node, where the process abort message is used to instruct the second node and the third node to abort the processing of the first transaction, and the process abort message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0160] It should be noted that, as can be seen from the above introduction, the write lock failure response may be returned by the second node when the write lock is successfully added to the write object but the version value verification fails. The read lock failure response may be returned by the third node when the read lock is successfully added to the read object but the version value verification fails. On this basis, after the second node and the third node receive the process termination message, if the second node returns a write lock success response or the second node returns a write lock failure response when it successfully adds a write lock to the write object but the version value verification fails, then the second node can release the write lock added to the write object. Similarly, if the third node returns a read lock success response or the third node returns a read lock failure response when it successfully adds a read lock to the read object but the version verification fails, then the third node can release the read lock added to the read object based on the first transaction.
[0161] For example, the second node may modify the value of the write lock field in the stored lock information of the write object to 0 to unlock the write object. The third node may decrement the value of the read lock field in the stored lock information of the read object by 1 to release the read lock on the read object held by the first transaction.
[0162] Step 404: Upon receiving a write lock success response from the second node and a read lock success response from the third node, submit the updated first data item to the second node and the fourth node. The write lock success response indicates that the write lock is successfully added to the write object and the read write object is correct. The read lock success response indicates that the read lock is successfully added to the read object and the read read object is correct. The fourth node is the backup node for the write object.
[0163] When the first node receives a successful write lock response from the second node and a successful read lock response from the third node, it means that the write object and read object read by itself are correct, and both the write object and the read object have been locked successfully. In this case, the first node can submit the updated first data item to the primary node and backup node of the write object, that is, the second node and the fourth node.
[0164] In the first implementation method, if the version value of the storage object is implemented by two version values, a stable version value and an intermediate version value, the first node can send a main submission message to the second node and a backup submission message to the fourth node, and the backup submission message includes the updated first data item; upon receiving the main submission success response from the second node and the backup submission success response from the fourth node, it is determined that the updated first data item is submitted successfully. The main submission success response is sent by the second node after updating the data item and the first version value of the stored write object based on the main submission message and the updated first data item. The updated write object includes a second version value, and the second version value is the next intermediate version value of the first version value. The backup submission success response is sent by the fourth node after receiving the backup submission message.
[0165] In an embodiment of the present application, the first node may send the primary commit message and the backup commit message in any order. For example, the first node may send the backup commit message to the fourth node at the same time as sending the primary commit message to the second node. Alternatively, the first node may send the primary commit message to the second node after sending the backup commit message to the fourth node and before receiving a successful backup commit response. Alternatively, the first node may send the backup commit message to the fourth node after sending the primary commit message to the second node and before receiving a successful primary commit response.
[0166] After receiving the master commit message, the second node may cache the master commit message, obtain the updated first data item based on the master commit message, and then update the data item of the write object stored in the second node according to the updated first data item, and update the version value of the write object stored in the second node.
[0167] Exemplarily, the master commit message may include the updated first data item. In this case, the second node may obtain the updated first data item from the master commit message. Alternatively, the aforementioned write lock message may include the updated first data item, while the master commit message does not. In this case, the second node may obtain the identifier of the first transaction in the master commit message, and based on the identifier of the first transaction, obtain a write lock message containing the identifier of the first transaction from its cached write lock message, and then obtain the updated first data item from the obtained write lock message.
[0168] After obtaining the updated first data item, the second node can replace the data item of the write object stored in its own storage with the updated first data item and modify the first version value of the write object stored in its own storage to the second version value. Afterwards, the second node can return a master submission success response to the first node to notify the first node that the updated data item of the write object submitted to the master node has been updated.
[0169] It should be noted that, from the process in which the second node verifies the version value of the write object read by the first node based on the intermediate version value and the stable version value in step 403, it can be seen that the first version value of the above-mentioned write object is the stable version value. Based on this, after the second node replaces the data item of the stored write object with the updated first data item, since the write object has been modified and it has not yet been determined whether the backup node of the write object has received the updated first data item, the second node can modify the first version value to the corresponding next intermediate version value, that is, the second version value, to represent that the write object is being modified. Exemplarily, the second node can add 1 to the first version value to obtain the second version value.
[0170] After receiving the backup commit message, the fourth node caches the backup commit message. The backup commit message includes the updated first data item, the object identifier of the write object, and the version value, so that the fourth node can subsequently update the stored data item and version value of the write object based on the updated first data item, the object identifier of the write object, and the version value in the backup commit message. After caching the backup commit message, the fourth node can send a backup commit success response to the first node to notify the first node that it has received the backup commit message.
[0171] In an embodiment of the present application, since the second node can identify the state of the write object by switching between the stable version value and the intermediate version value, even if the first node sends a primary commit message before receiving a successful backup commit response, the second node can also switch the version value of the write object stored in its own storage to the intermediate version value to indicate that the write object is in the process of modification. In this way, for other transactions that want to modify the write object, the version value of the write object read by the corresponding transaction can be verified based on the intermediate version value through the aforementioned method, thereby ensuring the correctness of the data. In this way, by switching between the two version values, on the one hand, write conflicts between transactions on stored objects are avoided, ensuring the correctness of the data read by the transaction. On the other hand, the sending of the primary commit message can be independent of the receipt of a successful backup commit response. In this way, the primary commit message and the backup commit message can be executed in a very short time or even in parallel, shortening the transaction processing time and improving the transaction processing efficiency.
[0172] In a second implementation, after receiving the write lock success response and the read lock success response, the first node may first send a backup commit message to the fourth node. After receiving the backup commit success response from the fourth node, the first node then sends a primary commit message to the second node. After receiving the primary commit success response returned by the second node, the first node determines that the updated first data item has been successfully committed.
[0173] That is, in this embodiment of the present application, the first node may first submit the updated first data item to the backup node of the write object, and after successfully submitting the data item to the backup node, submit it to the primary node. In this case, the version value of the storage object can be implemented by using the intermediate version value and the stable version value, or it can be implemented without distinguishing between the intermediate version value and the stable version value.
[0174] Among them, if the version value of the storage object is implemented by the intermediate version value and the stable version value, the operation of the second node after receiving the main commit message can refer to the implementation method introduced above.
[0175] If the version value of the stored object does not distinguish between an intermediate version value and a stable version value, then after receiving the primary commit message and updating the data item of the stored write object based on the primary commit message, the second node can add 1 to the first version value of the stored write object to obtain the second version value. Since the first node sends the primary commit message after receiving a successful backup commit response, after the second node updates the data item and version value of the stored write object, the second node can determine that the updated first data item has been committed, that is, the commit is successful. In this case, the second node can release the write lock of the stored write object and then return a successful primary commit response to the first node.
[0176] In addition, the operation of the fourth node after receiving the backup submission message can refer to the implementation method introduced above, and the embodiment of the present application will not be repeated here.
[0177] Optionally, if the second node fails to complete the update of the data items and version values of the stored write object after receiving the main commit message, or if the second node does not receive the main commit message, the second node will not return a main commit success response to the first node. Similarly, if the fourth node does not receive the backup commit message or fails to cache the backup commit message successfully, the fourth node will not return a backup commit success response to the first node. On this basis, if the first node does not receive the main commit success response from the second node or the backup commit success response from the fourth node or neither, the first node can send a process termination message to the second node, the third node and the fourth node to notify each node to terminate the processing of the first transaction and instruct the second node and the third node to unlock the objects that have been successfully locked.
[0178] Among them, it can be seen from the above introduction that the second node adds a write lock to the write object, and the third node adds a read lock to the read object. Therefore, if the first node fails to receive the primary submission success response from the second node and / or the backup submission success response from the fourth node, that is, it is determined that the submission of the updated first data item has failed, then the first node can notify the second node to release the write lock added to the write object, and notify the third node to release the read lock added to the read object based on the first transaction. Among them, the implementation method of releasing the write lock of the write object and releasing the read lock added to the read object based on the first transaction can refer to the relevant implementation method introduced above, and the embodiments of this application will not be repeated here.
[0179] Optionally, in some possible implementations, when the first node submits the updated first data item to the second node and the fourth node, or after the first node submits the updated first data item to the second node and the fourth node, the first node may also send a read lock release message to the third node to instruct the third node to release the read lock of the read object.
[0180] For example, the first node may send a read lock release message to the third node simultaneously with sending the primary commit message and the backup commit message. Alternatively, the first node may send a read lock release message to the third node immediately after sending the primary commit message and the backup commit message. Alternatively, the first node may send a read lock release message to the third node after receiving a primary commit success response and a backup commit success response, that is, after the updated first data item is successfully committed.
[0181] After receiving the read lock release message, the third node may release the read lock added to the read object based on the first transaction based on the read lock release message.
[0182] When the first node determines that the updated first data item is successfully submitted, the first node may also generate a transaction completion notification and send the transaction completion notification to the upper-layer application to notify the upper-layer application that the first transaction processing is completed.
[0183] Optionally, if the version value of the storage object in an embodiment of the present application includes an intermediate version value and a stable version value, then after the updated first data item is successfully submitted, for example, after generating a transaction completion notification, the first node may also send a write lock release message to the second node, and the write lock release message instructs the second node to update the second version value to a third version value and release the write lock of the updated write object, where the third version value is the stable version value corresponding to the second version value.
[0184] As can be seen from the above introduction, when the version value of the storage object includes an intermediate version value and a stable version value, after the second node updates the data item of the write object based on the main submission message, it will also update the first version value to the second version value. At this time, the second version value is the intermediate version value. On this basis, when the first node determines that the updated first data item has been successfully submitted to the second node and the fourth node, it can notify the second node to update the second version value to the corresponding stable version value, that is, the third version value, to identify the write object currently stored in the second node as a write object that has been successfully submitted. For example, the second node can add 1 to the second version value to obtain the third version value.
[0185] Optionally, after the updated first data item is successfully submitted, the first node may also send a first deletion message to the second node, where the first deletion message is used to instruct the second node to delete the write lock message and the main submission message; and send a second deletion message to the fourth node, where the second deletion message is used to instruct the fourth node to update the stored data item and the first version value of the write object based on the backup submission message and delete the backup submission message.
[0186] Among them, after sending the write lock release message, the first node can send a first delete message to the second node and a second delete message to the fourth node. Optionally, if the version value of the storage object does not distinguish between an intermediate version value and a stable version value, since the second node can release the write lock of the write object after updating the data item and version value of the write object stored in itself, the first node does not need to send a write lock release message to the second node. In this case, the first node can immediately send the first delete message to the second node and the second delete message to the fourth node after the updated first data item is successfully submitted or after a transaction completion notification is generated.
[0187] After receiving the first delete message, the second node searches its cache for messages containing the first transaction identifier based on the first transaction identifier carried in the first delete message. The second node then deletes the found messages. The found messages include write lock messages and master commit messages. Optionally, the found messages may also include write lock release messages.
[0188] After receiving the second delete message, the fourth node searches for a cached backup commit message containing the first transaction identifier based on the first transaction identifier carried in the second delete message. The fourth node updates the stored data item and the first version value of the write object based on the backup commit message and deletes the backup commit message.
[0189] It should be noted that the fourth node may also currently store backup commit messages sent by transactions other than the first transaction after modifying the write object. That is, the fourth node may store backup commit messages submitted by different transactions after modifying the same write object. For ease of explanation, the backup commit message corresponding to the first transaction, i.e., the backup commit message containing the identifier of the first transaction, is referred to as the target backup commit message, while the backup commit messages corresponding to other transactions are referred to as other backup commit messages. As described above, the target backup commit message includes the updated first data item and the version value of the write object. Based on this, after finding the target backup commit message, the fourth node obtains other backup commit messages that also contain the object identifier of the write object based on the object identifier of the write object included in the target backup commit message. The fourth node can then compare the version values carried in the target backup commit message with those in the obtained other backup commit messages. If the version value in the target backup commit message is greater than the version value in the other backup commit messages, the fourth node updates the stored write object based on the updated first data item and the version value of the write object in the target backup commit message.
[0190] Exemplarily, each backup commit message may carry the version value of the write object read by the corresponding transaction. In this case, when the fourth node updates the stored write object based on the updated first data item and the version value of the write object in the target backup commit message, it may replace the stored data item of the write object with the updated first data item and update the version value of the stored write object based on the version value in the target backup commit message.
[0191] If the version value of the storage object includes an intermediate version value and a stable version value, the fourth node may update the first version value of the stored write object to a third version value based on the version value in the target backup commit message.
[0192] For example, when the version value in the target backup commit message is an intermediate version value, the fourth node may add 3 to the version value to obtain a third version value. When the version value is a stable version value, the fourth node may add 2 to the version value to obtain a third version value.
[0193] If the version value of the stored object does not distinguish between an intermediate version value and a stable version value, the fourth node may update the first version value of the stored write object to a second version value based on the version value in the target backup commit message. For example, the fourth node may increase the version value by 1 to obtain the second version value.
[0194] Optionally, each backup commit message may also carry the current version value of the write object calculated by the transaction-issuing node of the corresponding transaction based on the read version value of the write object. In this case, when the fourth node updates the stored write object based on the updated first data item and the version value of the write object in the target backup commit message, it may replace the stored data item of the write object with the updated first data item and directly replace the stored version value of the write object with the version value carried in the target backup commit message.
[0195] After the fourth node updates the data item and version value of the write object, the fourth node may delete the cached backup commit message. In addition, the fourth node may also delete other messages containing the identifier of the first transaction.
[0196] Optionally, while sending the delete message to the second node and the fourth node, the first node may also send a third delete message to the third node to instruct the third node to delete the cached message related to the first transaction.
[0197] For example, the third node may search for a cached message containing the identifier of the first transaction based on the identifier of the first transaction contained in the third delete message, and then delete the found message. The found delete message may include the aforementioned read lock message and may also include a read lock release message.
[0198] In an embodiment of the present application, after a first node reads a write object from a second node and then reads a read object from a third node, it modifies the data item of the read write object. Subsequently, it can send a write lock message to the second node and a read lock message to the third node. In this way, the second and third nodes can lock and verify the object's version value in no particular order. That is, the first node can initiate locking and version value verification of the write object and version value verification of the read object in parallel. This shortens transaction processing time compared to verifying the read object's version value after the write object has been successfully locked and its version value has been verified. Furthermore, in an embodiment of the present application, even if the third node returns a read lock success response first and the second node returns a write lock success response later, that is, even if the third node successfully verifies the read object's version value before the second node successfully locks the write object, because the third node successfully applies a read lock to the read object at the same time as it verifies the read object's version value, the read object cannot be tampered with by other transactions before the second node successfully applies a write lock to the write object, thus ensuring the correctness of the submitted data. It can be seen that the embodiment of the present application shortens the transaction processing time while ensuring the correctness of the submitted data.
[0199] In addition, in an embodiment of the present application, since the second node can identify the state of the write object by switching between the stable version value and the intermediate version value, even if the first node sends a primary commit message before receiving a successful backup commit response, the second node can also indicate that the write object is in the process of modification by switching the version value of the write object to the intermediate version value. In this way, for other transactions that want to modify the write object, the version value of the write object read by itself can be verified based on the intermediate version value, thereby ensuring the correctness of the data. In this way, by switching between the two version values, on the one hand, write conflicts of transactions on storage objects are avoided, ensuring the correctness of the data read by transactions, and on the other hand, the sending of the primary commit message does not depend on the receipt of a successful backup commit response. In this way, the primary commit message and the backup commit message can be executed in a very short time or even in parallel, shortening transaction processing time and improving transaction processing efficiency.
[0200] FIG6 is a flowchart of another transaction processing method provided in an embodiment of the present application, which can be applied to a first node. The first node can be any computing node in the system architecture shown in FIG1 , or any node in the system architecture shown in FIG2 . Furthermore, the first node is the node that triggers transaction processing, that is, the first node is the transaction initiating node in the transaction processing process. Referring to FIG6 , the method includes the following steps:
[0201] Step 601: Based on the information of the write object and the read object included in the first transaction, the write object is read from the second node and the read object is read from the third node, both the write object and the read object include version values, and the write object includes a first data item, the second node is the master node where the write object is located, and the third node is the master node where the read object is located.
[0202] The implementation of this step may refer to the implementation of step 401. As described in step 401, the storage object may include metadata items and data items, wherein the metadata items may include version values and lock information.
[0203] In the embodiment of the present application, the version value of the storage object includes an intermediate version value and a stable version value. For the relevant introduction of the intermediate version value and the stable version value, please refer to the above text, and the embodiment of the present application will not be repeated here.
[0204] In addition, the lock information can be implemented in the manner of the aforementioned step 401, that is, the metadata item includes a read lock field for implementing a read lock for the storage object and a write lock field for implementing a write lock for the storage object.
[0205] Alternatively, unlike step 401, in this embodiment of the present application, the lock information may include only a write lock field. In this case, the write lock field can be used to write-lock the storage object, but a read lock cannot be applied to the storage object. In this case, the write lock applied to the storage object can also be called an exclusive lock. That is, for any storage object, if the storage object is not write-locked, multiple accessors can share read access to the storage object.
[0206] Step 602: Modify the first data item to obtain an updated first data item.
[0207] The implementation of this step can refer to the implementation of step 602, and the embodiment of the present application will not be repeated here.
[0208] Step 603: When the write lock is successfully added to the write object in the second node and the write object and the read object read by the first node are correct, a main submission message for submitting the updated first data item is sent to the second node, and a backup submission message for submitting the updated first data item is sent to the fourth node. The fourth node is the backup node of the write object.
[0209] In an embodiment of the present application, after the first node modifies the first data item included in the write object, if the lock information of the storage object includes a write lock field and a read lock field, the first node can refer to the method described in the aforementioned step 403 to send a write lock message to the second node and send a write lock message to the third node. Accordingly, the second node can refer to the method described in step 403 to add a write lock to the write object stored by itself, and the third node can refer to the method described in step 403 to add a read lock to the read object stored by itself. In addition, the second node and the third node can also refer to the first implementation method described in step 403 to verify the version values of the write object and the read object read by the first node. In this case, after the first node receives the write lock success response and the read lock success response from the second node, it determines that the write lock is successfully added to the write object in the second node, the read lock is successfully added to the read object in the third node, and the write object and read object read by the first node are correct.
[0210] Alternatively, in another possible implementation, if the lock information of the storage object includes a write lock field but does not include a read lock field, after modifying the first data item, the first node may first send a write lock message to the second node. Upon receiving a write lock success response from the second node, the first node may then verify the version value of the read object. If the version value of the read object is successfully verified, the first node determines that the write lock on the write object in the second node has been successfully applied and that both the write object and the read object read by the first node are correct.
[0211] Exemplarily, after receiving the write lock message, the second node searches for the write object stored in its own storage based on the object identifier of the write object carried in the write lock message. Thereafter, based on the lock information of the write object found, the second node detects whether the write object has been write-locked. If the lock information indicates that the write object has been write-locked, the second node is unable to write-lock the write object at this time. In this case, it is determined that the write lock has failed to be added to the write object. If the lock information indicates that the write object has not been write-locked, the second node can write-lock the write object by modifying the lock information.
[0212] If the value of the write lock field of the write object is not 0, it is determined that the write object has been write-locked. If the value of the write lock field of the write object is 0, it is determined that the write object has not been write-locked. In this case, the second node can modify the value of the write lock field to a non-zero value to implement write locking on the write object. For example, the value of the write lock field can be modified to 1.
[0213] In addition, the second node may also refer to the first method in the aforementioned step 401 to verify the version value of the write object read by the first node and carried in the write lock message.
[0214] If the second node successfully applies a write lock to the write object and verifies the version value of the write object read by the first node, the second node returns a write lock success response to the first node. If the second node fails to apply a write lock to the write object and / or fails to verify the version value of the write object read by the first node, the second node returns a write lock failure response to the first node.
[0215] When the first node receives a write lock success response, it can be determined that the write lock is successfully added to the write object. In this case, the first node can send a verification message to the third node, and the verification message carries the version value of the read object read by the first node. After receiving the verification message, the third node verifies the version value of the read object read by the first node with reference to the first method in the aforementioned step 403. When the version value of the read object read by the first node is verified, the third node can return a verification success response to the first node. When the version value of the read object read by the first node is not verified, the third node returns a read verification failure response to the first node. After receiving the verification success response, the first node determines that the read object it has read is correct. After receiving the read verification failure response, it is determined that the read object it has read is incorrect.
[0216] Optionally, in one possible implementation, after the first node determines that the write lock on the write object has been successfully added, the first node may also read the read object again from the third node. Thereafter, the first node may refer to the first method in step 403 above, use the version value in the read object read again as the current version value, and verify the version value of the read object initially read based on the current version value. If the verification succeeds, the first node determines that the read object it has read is correct. If the verification fails, the first node determines that the read object it has read is incorrect.
[0217] After the first node successfully applies a write lock to the write object in the above manner and confirms that the write object and read object it has read are correct, the first node can refer to the first implementation of step 404 and send a primary commit message to the second node and a backup commit message to the fourth node. That is, in this embodiment of the present application, the first node sends the primary commit message and the backup commit message in any particular order. This implementation process will not be further described in this embodiment of the present application.
[0218] Optionally, if the first node determines that adding a write lock to the write object has failed through the above method, or determines that the write object and / or read object read by itself is incorrect, the first node may send a process abort message to the second node and the third node, the process abort message instructing the second node and the third node to abort the processing of the first transaction, and if the second node successfully adds a write lock to the write object based on the first transaction in the aforementioned process, the process abort message also instructs the second node to unlock the write object that was successfully locked. If the third node successfully adds a read lock to the read object based on the first transaction in the aforementioned process, the process abort message also instructs the third node to release the read lock added to the read object based on the first transaction.
[0219] Optionally, if the lock information of the storage object includes a read lock field, when the first node submits the updated first data item to the second node and the fourth node, or after the first node submits the updated first data item to the second node and the fourth node, the first node may further send a read lock release message to the third node to instruct the third node to release the read lock of the read object. For related implementations, reference may be made to the implementation of the read lock release in step 404.
[0220] Step 604: upon receiving a primary commit success response from the second node and a backup commit success response from the fourth node, a transaction completion notification is generated.
[0221] After the first node receives the primary commit success response from the second node and the backup commit success response from the fourth node, it can determine that the updated first data item has been successfully committed. In this case, the first node can generate a transaction completion notification and send the transaction completion notification to the upper-layer application to notify the upper-layer application that the first transaction processing is complete.
[0222] After generating the transaction completion notification, the first node may also send a write lock release message to the second node. The write lock release message instructs the second node to update the currently stored intermediate version value of the write object, i.e., the second version value, to a third version value, and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value. The implementation of updating the version value refers to the relevant implementation in the aforementioned step 405 and will not be repeated here in this embodiment of the present application.
[0223] After sending the write lock release message, the first node may also send a first deletion message to the second node, where the first deletion message is used to instruct the second node to delete the write lock message and the main commit message; and send a second deletion message to the fourth node, where the second deletion message is used to instruct the fourth node to update the data items and the first version value of the stored write object based on the backup commit message and delete the backup commit message.
[0224] Among them, the processing method after the second node and the fourth node receive the deletion message can refer to the relevant implementation method in the aforementioned step 405, and the embodiment of the present application will not be repeated here.
[0225] Optionally, while sending the delete message to the second node and the fourth node, the first node may also send a third delete message to the third node to instruct the third node to delete the cached message related to the first transaction. For related implementations, refer to step 405.
[0226] In an embodiment of the present application, the version value of a storage object may include a stable version value and an intermediate version value. The intermediate version value is used to indicate that the updated data item of the storage object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the storage object has been successfully submitted. On this basis, the state of the write object can be identified by switching between the two version values. Therefore, even if the first node sends a primary commit message before receiving a successful backup submission response, the primary node of the write object, that is, the second node, can also switch the version value of the write object to the intermediate version value to indicate that the write object is in the modification process. In this way, for other transactions that want to modify the write object, the version value of the write object read by itself can be verified based on the intermediate version value, thereby ensuring the correctness of the data. In this way, by switching between the two version values, on the one hand, write conflicts between transactions on storage objects are avoided, ensuring the correctness of the data read by transactions, and on the other hand, the sending of the primary commit message does not depend on the receipt of a successful backup submission response. In this way, the two steps of sending the primary commit message and sending the backup commit message can be executed in a very short time or even in parallel, shortening the time required from starting to process the first transaction to notifying the upper-level application of the completion of transaction processing.
[0227] In addition, in an embodiment of the present application, after modifying the first data item included in the write object, the first node can send a write lock message to the second node and a read lock message to the third node. In this way, the second and third nodes can lock the object and verify the version value in no particular order, that is, the first node can initiate the lock and version value verification of the write object and the version value verification of the read object in parallel. In this way, compared to verifying the version value of the read object after the write object is successfully locked and the version value is verified, the transaction processing time is shortened. Moreover, in an embodiment of the present application, even if the third node returns a read lock success response first and the second node returns a write lock success response later, that is, even if the third node successfully verifies the version value of the read object before the second node successfully locks the write object, because the third node successfully verifies the version value of the read object and also successfully adds a read lock to the read object, the read object will not be tampered with by other transactions before the second node successfully adds a write lock to the write object, thereby ensuring the correctness of the submitted data. As can be seen from this, the embodiment of the present application shortens the transaction processing time while ensuring the correctness of the submitted data.
[0228] Next, taking the case where the storage objects targeted by the two write operations in the first transaction are W1, the storage object targeted by the one read operation is R1, the first node is C, the primary node of W1, i.e. the second node, is P1, the backup node, i.e. the fourth node, is B1, and the primary node of R1, i.e. the third node, is P2 as an example, the transaction processing method based on the above-mentioned Figures 4 and 6 is illustrated through three exemplary embodiments.
[0229] FIG7 is a flow chart of a transaction processing method provided by an embodiment of the present application. Referring to FIG7 , the transaction processing process includes the following steps:
[0230] Step 701: Node C reads W1 from node P1 and reads R1 from node P2.
[0231] W1 includes version value V1 and data item D1, and R1 includes version value V2 and data item D2.
[0232] Step 702: Node C modifies the data item D1 in W1 and records the modified data item D1'.
[0233] Here, D1' is the first data item after update.
[0234] Step 703: Node C sends a write lock message to node P1 and simultaneously sends a read lock message to node P2.
[0235] The write lock message includes (V1, D1') and the read lock message includes V2.
[0236] Step 704: Node P1 write-locks the stored W1 and verifies V1.
[0237] Node P1 may add a write lock to W1 based on the method described in step 403 .
[0238] In addition, when V1 is an odd number, that is, when V1 is an intermediate version value, node P1 determines whether the version value V1' of W1 stored in itself is equal to V1+1. If V1' is equal to V1+1, the verification is determined to be successful. If V1' is not equal to V1+1, the verification is determined to be unsuccessful.
[0239] When V1 is an even number, that is, when V1 is a stable version value, node P1 determines whether the version value V1' of W1 stored in itself is equal to V1. If V1' is equal to V1, the verification is determined to be successful. If V1' is not equal to V1, the verification is determined to be unsuccessful.
[0240] Step 705: Node P2 read-locks the stored R1 and verifies V2.
[0241] Node P2 applies a read lock to R1 by referring to the method described in step 403 , and verifies V2 by referring to the method described in step 704 .
[0242] The execution order of the above steps 704 and 705 is not particular.
[0243] Step 706: When node P1 successfully adds a write lock to W1 and V1 passes verification, node P1 returns a write lock success response to node C.
[0244] Step 707: When node P2 successfully adds a read lock to R1 and V2 passes verification, node P2 returns a read lock success response to node C.
[0245] The execution order of the above steps 706 and 707 is not particular.
[0246] Step 708: Node C sends a primary commit message to node P1, a backup commit message to node B1, and a read lock release message to node P2.
[0247] Step 709: Node P1 replaces the stored D1 with D1′ based on the master commit message, and updates the stored version value V1′ of W1 to V1′+1.
[0248] Step 710: Node P1 returns a master submission success response to node C.
[0249] Step 711: After caching the backup submission message, node B1 returns a backup submission success response to node C.
[0250] Step 712: Node P2 releases the read lock added to R1 based on the first transaction based on the read lock release message.
[0251] The execution order of steps 709 to 712 is not specific.
[0252] Step 713: Node C notifies the upper-layer application that the first transaction is completed.
[0253] Step 714: Node C sends a write lock release message to node P1.
[0254] Step 715: Node P1 releases the write lock of W1 and updates the version value V1′+1 of W1 to V1′+2.
[0255] Step 716: Node C sends a deletion message to node P1, node B1, and node P2.
[0256] Step 717: Node P1 deletes the related messages of the first transaction based on the delete message.
[0257] Step 718: Node P2 deletes the related messages of the first transaction based on the delete message.
[0258] Step 719: Node B1 updates the stored D1 to D1′ and the stored V1′ to V1′+2 based on the deletion message, and deletes the related messages of the first transaction.
[0259] Among them, the execution order of steps 717 to 719 is not particular.
[0260] It should be noted that the above-mentioned 701 and 702 can be called the execution phase of the transaction, steps 703 to 707 are the locking and verification phase of the transaction, steps 708 to 713 are the submission phase of the transaction, steps 714 and 715 are the write lock release phase, and step 716 is the deletion phase. A schematic diagram of the interaction timing between the nodes in each phase is shown in Figure 8. Comparing Figure 8 with Figure 3, it can be seen that compared with the relevant technology, the embodiment of the present application executes the locking and version verification of the storage object in parallel, and executes the steps of submitting the updated data items to the master node and backup node of the write object in parallel. In this way, the round-trip delay of the interaction between each node in the transaction processing process is shortened, and the transaction processing efficiency is improved. Moreover, compared with the relevant technology, the time required from starting to process the transaction to notifying the upper-layer application that the transaction has been processed is shorter in the embodiment of the present application.
[0261] FIG9 is a flow chart of another transaction processing method provided in an embodiment of the present application. Referring to FIG9 , the transaction processing flow includes the following steps:
[0262] Step 901: Node C reads W1 from node P1 and reads R1 from node P2.
[0263] W1 includes version value V1 and data item D1, and R1 includes version value V2 and data item D2.
[0264] Step 902: Node C modifies the data item D1 in W1 and records the modified data item D1'.
[0265] Here, D1' is the first data item after update.
[0266] Step 903: Node C sends a write lock message to node P1 and simultaneously sends a read lock message to node P2.
[0267] The write lock message includes (V1, D1') and the read lock message includes V2.
[0268] Step 904: Node P1 write-locks the stored W1 and verifies V1 by determining whether V1 is equal to the version value V1′ of W1 stored in itself.
[0269] Node P1 may add a write lock to W1 based on the method described in step 403 .
[0270] In addition, if V1' is equal to V1, it is determined that the verification is passed. If V1' is not equal to V1, it is determined that the verification is not passed.
[0271] Step 905: Node P2 adds a read lock to the stored R1 and verifies V2 by determining whether V2 is equal to the version value V2′ of R1 stored in itself.
[0272] Node P2 applies a read lock to R1 by referring to the method described in step 403 , and verifies V2 by referring to the method described in step 904 .
[0273] The execution order of the above steps 904 and 905 is not specific.
[0274] Step 906: When node P1 successfully adds a write lock to W1 and V1 passes verification, node P1 returns a write lock success response to node C.
[0275] Step 907: When node P2 successfully adds a read lock to R1 and V2 passes verification, node P2 returns a read lock success response to node C.
[0276] The execution order of the above steps 906 and 907 is not specific.
[0277] Step 908: Node C sends a backup commit message to node B1.
[0278] Step 909: After caching the backup submission message, node B1 returns a backup submission success response to node C.
[0279] Step 910: Node C sends a master commit message to node P1 and simultaneously sends a read lock release message to node P2.
[0280] Step 911: Node P1 replaces the stored D1 with D1′ based on the master commit message, updates the stored version value V1′ of W1 to V1′+1, and releases the write lock of W1.
[0281] Step 912: Node P1 returns a master submission success response to node C.
[0282] Step 913: Node P2 releases the read lock added to R1 based on the first transaction based on the read lock release message.
[0283] The execution order of steps 911 to 913 is not specific.
[0284] Step 914: Node C notifies the upper-layer application that the first transaction is completed.
[0285] Step 915: Node C sends a deletion message to node P1, node B1, and node P2.
[0286] Step 916: Node P1 deletes the related messages of the first transaction based on the delete message.
[0287] Step 917: Node P2 deletes the related messages of the first transaction based on the delete message.
[0288] Step 918: Node B1 updates the stored D1 to D1′ and the stored V1′ to V1′+1 based on the deletion message, and deletes the related messages of the first transaction.
[0289] The execution order of steps 916 to 918 is not specific.
[0290] It should be noted that the above 901 and 902 can be called the execution phase of the transaction, steps 903 to 907 are the locking and verification phase of the transaction, steps 908 to 914 are the submission phase of the transaction, and steps 915 to 918 are the deletion phase. A schematic diagram of the interaction timing between nodes in each phase is shown in Figure 10. Comparing Figure 10 with Figure 3, it can be seen that compared with the related art, the embodiment of the present application executes the locking and version verification of the storage object in parallel, thus shortening the round-trip delay of the interaction between each node in the transaction processing process and improving the transaction processing efficiency. Moreover, compared with the related art, the time required from starting to process the transaction to notifying the upper-layer application that the transaction has been processed is shorter in the embodiment of the present application.
[0291] FIG11 is a flow chart of another transaction processing method provided in an embodiment of the present application. Referring to FIG11 , the transaction processing process includes the following steps:
[0292] Step 1101: Node C reads W1 from node P1 and reads R1 from node P2.
[0293] W1 includes version value V1 and data item D1, and R1 includes version value V2 and data item D2.
[0294] Step 1102: Node C modifies the data item D1 in W1 and records the modified data item D1'.
[0295] Here, D1' is the first data item after update.
[0296] Step 1103: Node C sends a write lock message to node P1.
[0297] The write lock message includes (V1, D1').
[0298] Step 1104: Node P1 locks the stored W1 and verifies V1.
[0299] Node P1 may add a write lock to W1 based on the method described in step 603 .
[0300] In addition, node P1 may verify V1 using the method described in step 704 .
[0301] Step 1105: When node P1 successfully adds a write lock to W1 and V1 passes verification, node P1 returns a write lock success response to node C.
[0302] Step 1106: Node C sends a verification message to node P2.
[0303] The verification message includes V2.
[0304] Step 1107: Node P2 verifies V2.
[0305] Node P2 verifies V2 by referring to the method in the aforementioned step 704 .
[0306] Step 1108: When node P2 successfully verifies V2, it returns a verification success response to node C.
[0307] Step 1109: Node C sends a primary commit message to node P1 and simultaneously sends a backup commit message to node B1.
[0308] Step 1110 : Node P1 replaces the stored D1 with D1 ′ based on the master commit message, and updates the stored version value V1 ′ of W1 to V1 ′+1.
[0309] Step 1111: Node P1 returns a master submission success response to node C.
[0310] Step 1112: After caching the backup submission message, node B1 returns a backup submission success response to node C.
[0311] The execution order of steps 1110 to 1112 is not specific.
[0312] Step 1113: Node C notifies the upper-layer application that the first transaction is completed.
[0313] Step 1114: Node C sends a write lock release message to node P1.
[0314] Step 1115: Node P1 releases the write lock of W1 and updates the version value V1′+1 of W1 to V1′+2.
[0315] Step 1116: Node C sends a deletion message to node P1, node B1, and node P2.
[0316] Step 1117: Node P1 deletes the related messages of the first transaction based on the delete message.
[0317] Step 1118: Node P2 deletes the related messages of the first transaction based on the delete message.
[0318] Step 1119: Node B1 updates the stored D1 to D1′ and the stored V1′ to V1′+2 based on the deletion message, and deletes the related messages of the first transaction.
[0319] Among them, the execution order of steps 1117 to 1119 is not particular.
[0320] It should be noted that the above 1101 and 1102 can be called the execution phase of the transaction, steps 1103 to 1105 are the locking phase of the transaction, steps 1106 to 1108 are the verification phase, steps 1109 to 1113 are the commit phase of the transaction, steps 1114 and 1115 are the write lock release phase, and steps 1116 to 1119 are the deletion phase. A schematic diagram of the interaction timing between the nodes in each phase is shown in Figure 12. Comparing Figure 12 with Figure 3, it can be seen that compared with the related art, the embodiment of the present application executes the steps of submitting the updated data items to the primary node and backup node of the write object in parallel. In this way, compared with the related art, the time required from starting to process the transaction to notifying the upper-layer application that the transaction has been processed is shorter in the embodiment of the present application.
[0321] In the above, an example explanation is given with the case that both the write object and the read object corresponding to the first transaction are one. It is worth noting that the number of write objects to be operated by the first transaction may be more than one, and the number of read objects may also be more than one, or the first transaction may include write objects but not read objects, or include read objects but not write objects. When the first transaction includes write objects but not read objects, the operation steps regarding read objects in the transaction processing flow described in the above embodiment may be deleted to operate on write objects. When read objects are included but not write objects, the operation steps regarding write objects in the transaction processing flow described in the above embodiment may be deleted to operate on read objects, and the embodiments of the present application will not be repeated here.
[0322] Next, the transaction processing device provided in the embodiment of the present application is introduced.
[0323] Figure 13 is a schematic diagram of the structure of a transaction processing device according to an embodiment of the present application. The transaction processing device can be deployed in the first node described above. As shown in Figure 13, the transaction processing device 1300 includes a reading module 1301, a modification module 1302, a sending module 1303, and a submission module 1304.
[0324] The reading module 1301 is used to execute step 401 in the above embodiment;
[0325] Modification module 1302, configured to execute step 402 in the aforementioned embodiment;
[0326] A sending module 1303 is configured to execute step 403 in the aforementioned embodiment;
[0327] The submitting module 1304 is used to execute step 404 in the above embodiment.
[0328] Optionally, the sending module 1303 is mainly used to:
[0329] Send a write lock message to the second node and send a read lock message to the third node at the same time; or, send a write lock message to the second node; after sending the write lock message and when a write lock success response has not been received, send a read lock message to the third node; or, send a read lock message to the third node; after sending the read lock message and when a read lock success response has not been received, send a write lock message to the second node.
[0330] Optionally, the sending module 1303 is further configured to:
[0331] When the submission module 1304 submits the updated first data item to the second node and the fourth node, a read lock release message is sent to the third node, where the read lock release message is used to instruct the third node to release the read lock of the read object.
[0332] Optionally, the sending module 1303 is further configured to:
[0333] Upon receiving a write lock failure response from the second node and / or a read lock failure response from the third node, a process termination message is sent to the second node and the third node. The write lock failure response indicates that the write lock on the write object failed and / or the write object read by the first node is incorrect. The read lock failure response indicates that the read lock on the read object failed and / or the read object read by the first node is incorrect. The process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0334] Optionally, the write object and read object read by the first node both include version values, the write lock message includes the version value of the write object read by the first node, and the read lock message includes the version value of the read object read by the first node. The write object or read object read by the first node is correct if the version value of the corresponding object read by the first node meets the verification conditions.
[0335] Optionally, the verification condition refers to that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding master node is a stable version value corresponding to the version value of the corresponding object read by the first node, or, the verification condition refers to that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been submitted successfully, and the stable version value is used to indicate that the updated data item of the corresponding object has been submitted successfully.
[0336] Optionally, the write lock message further includes the updated first data item; the submit module 1304 is mainly used to:
[0337] Sending a primary commit message to the second node and a backup commit message to the fourth node, where the backup commit message includes the updated first data item;
[0338] Upon receiving a successful primary submission response from the second node and a successful backup submission response from the fourth node, it is determined that the updated first data item is submitted successfully. The successful primary submission response is sent by the second node after updating the data item and the first version value of the stored write object based on the primary submission message and the updated first data item. The updated write object includes a second version value, which is the next intermediate version value of the first version value. The successful backup submission response is sent by the fourth node after receiving the backup submission message.
[0339] Optionally, the submission module 1304 is mainly used to:
[0340] Send a primary commit message to the second node and a backup commit message to the fourth node simultaneously;
[0341] Alternatively, a backup commit message is sent to the fourth node, and after sending the backup commit message and when a backup commit success response has not been received, a primary commit message is sent to the second node;
[0342] Alternatively, a primary commit message is sent to the second node, and when the primary commit message is sent and a primary commit success response has not been received, a backup commit message is sent to the fourth node.
[0343] Optionally, the sending module 1303 is further configured to:
[0344] In the case that no primary submission success response from the second node and / or no backup submission success response from the fourth node is received, a process termination message is sent to the second node, the third node and the fourth node. The process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
[0345] Optionally, the sending module 1303 is further configured to:
[0346] A write lock release message is sent to the second node. The write lock release message is used to instruct the second node to update the second version value to the third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
[0347] Optionally, the sending module 1303 is further configured to:
[0348] Sending a first delete message to the second node, where the first delete message is used to instruct the second node to delete the write lock message and the master commit message;
[0349] A second deletion message is sent to the fourth node, where the second deletion message is used to instruct the fourth node to update the data item and the first version value of the stored write object based on the backup commit message and to delete the backup commit message.
[0350] In an embodiment of the present application, a first node reads a write object from a second node and a read object from a third node. After modifying the first data item included in the write object, a write lock message can be sent to the second node and a read lock message can be sent to the third node. In this way, the second and third nodes can lock the object and verify the version value in no particular order. That is, the first node can initiate the lock and version value verification of the write object and the version value verification of the read object in parallel. In this way, compared to verifying the version value of the read object after the write object is successfully locked and the version value is verified, the transaction processing time is shortened. Moreover, in an embodiment of the present application, even if the third node returns a read lock success response first and the second node returns a write lock success response later, that is, even if the third node successfully verifies the version value of the read object before the second node successfully locks the write object, because the third node successfully verifies the version value of the read object and successfully adds a read lock to the read object at the same time as the read lock is passed, the read object will not be tampered with by other transactions before the second node successfully adds a write lock to the write object, thus ensuring the correctness of the submitted data. It can be seen that the embodiment of the present application shortens the transaction processing time while ensuring the correctness of the submitted data.
[0351] FIG14 is a schematic diagram of another transaction processing device provided in an embodiment of the present application. The transaction processing device is deployed in a first node. Referring to FIG14 , the transaction processing device 1400 includes a reading module 1401 , a modification module 1402 , a submission module 1403 , and a generation module 1404 .
[0352] A reading module 1401 is used to execute step 601 in the above embodiment;
[0353] Modification module 1402, configured to execute step 602 in the aforementioned embodiment;
[0354] Submission module 1403, configured to execute step 603 in the aforementioned embodiment;
[0355] The generating module 1404 is used to execute step 604 in the above embodiment.
[0356] Optionally, the submission module 1403 is mainly used to:
[0357] Send a primary commit message to the second node and a backup commit message to the fourth node simultaneously;
[0358] Alternatively, a backup commit message is sent to the fourth node, and after sending the backup commit message and when a backup commit success response has not been received, a primary commit message is sent to the second node;
[0359] Alternatively, a primary commit message is sent to the second node, and when the primary commit message is sent and a primary commit success response has not been received, a backup commit message is sent to the fourth node.
[0360] Optionally, the apparatus 1400 further includes:
[0361] The sending module is used to send a write lock release message to the second node. The write lock release message is used to instruct the second node to update the second version value to the third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
[0362] In an embodiment of the present application, the version value of a storage object may include a stable version value and an intermediate version value. The intermediate version value is used to indicate that the updated data item of the storage object has not been successfully submitted, while the stable version value is used to indicate that the updated data item of the storage object has been successfully submitted. Based on this, the switching of these two version values can identify the state of the write object. Therefore, even if the first node sends a primary commit message before receiving a successful backup commit response, the second node can switch the version value of the write object to the intermediate version value to indicate that the write object is in the process of being modified. In this way, for other transactions that want to modify the write object, the version value of the write object read by itself can be verified based on the intermediate version value, thereby ensuring the correctness of the data. In this way, by switching between the two version values, on the one hand, write conflicts between transactions on the storage object are avoided, ensuring the correctness of the data read by the transaction, and on the other hand, the sending of the primary commit message can be independent of the receipt of a successful backup commit response. In this way, the two steps of sending the primary commit message and sending the backup commit message can be executed in a very short time or even in parallel, shortening the time required from starting to process the first transaction to notifying the upper-level application of the completion of the transaction processing.
[0363] It should be noted that the transaction processing device provided in the above embodiment is merely illustrated by the division of the aforementioned functional modules when processing transactions. In actual applications, the aforementioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the transaction processing device provided in the above embodiment and the aforementioned transaction processing method embodiment are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0364] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0365] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or may be accomplished by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.
[0366] The above description is merely an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A transaction processing method, characterized in that: Applied to the first node, the method includes: Based on information of a write object and information of a read object included in the first transaction, the write object is read from a second node and the read object is read from a third node, the write object includes the first data item, the second node is a primary node where the write object is located, and the third node is a primary node where the read object is located; Modifying the first data item to obtain an updated first data item; Sending a write lock message to the second node and a read lock message to the third node, wherein the read lock message is used to add a read lock to the read object and detect whether the read object read by the first node is correct; Upon receiving a write lock success response from the second node and a read lock success response from the third node, the updated first data item is submitted to the second node and the fourth node, the write lock success response indicates that the write lock is successfully added to the write object and the read write object is correct, the read lock success response indicates that the read lock is successfully added to the read object and the read read object is correct, and the fourth node is the backup node of the write object.
2. The method according to claim 1, characterized in that The sending a write lock message to the second node and sending a read lock message to the third node includes: Sending the write lock message to the second node and simultaneously sending the read lock message to the third node; Alternatively, the write lock message is sent to the second node; after the write lock message is sent and when the write lock success response has not been received, the read lock message is sent to the third node; Alternatively, the read lock message is sent to the third node; after the read lock message is sent and when the read lock success response has not been received, the write lock message is sent to the second node.
3. The method according to claim 1 or 2, characterized in that When submitting the updated first data item to the second node and the fourth node, the method further includes: A read lock release message is sent to the third node, where the read lock release message is used to instruct the third node to release the read lock of the read object.
4. The method according to claim 1 or 2, characterized in that The method further comprises: Upon receiving a write lock failure response from the second node and / or a read lock failure response from the third node, a process abort message is sent to the second node and the third node, wherein the write lock failure response indicates that the write lock on the write object failed and / or the write object read by the first node is incorrect, and the read lock failure response indicates that the read lock on the read object failed and / or the read object read by the first node is incorrect, and the process abort message is used to indicate the abort of processing of the first transaction, and the process abort message is also used to instruct the second node and the third node to unlock the object that was successfully locked.
5. The method according to claim 1, characterized in that The write object and the read object read by the first node both include version values, the write lock message includes the version value of the write object read by the first node, and the read lock message includes the version value of the read object read by the first node. The write object or the read object read by the first node is correct if the version value of the corresponding object read by the first node meets the verification conditions.
6. The method according to claim 5, characterized in that The verification condition means that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding master node is a stable version value corresponding to the version value of the corresponding object read by the first node, or, the verification condition means that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been submitted successfully, and the stable version value is used to indicate that the updated data item of the corresponding object has been submitted successfully.
7. The method according to claim 6, characterized in that The write lock message further includes the updated first data item; Submitting the updated first data item to the second node and the fourth node includes: Sending a primary commit message to the second node and a backup commit message to the fourth node, wherein the backup commit message includes the updated first data item; Upon receiving a successful primary submission response from the second node and a successful backup submission response from the fourth node, it is determined that the updated first data item is successfully submitted. The successful primary submission response is sent by the second node after updating the stored data item and the first version value of the write object based on the primary submission message and the updated first data item. The updated write object includes a second version value, which is the next intermediate version value of the first version value. The successful backup submission response is sent by the fourth node after receiving the backup submission message.
8. The method according to claim 7, characterized in that The sending of a primary commit message to the second node and a backup commit message to the fourth node includes: Sending the primary commit message to the second node and simultaneously sending the backup commit message to the fourth node; Alternatively, the backup commit message is sent to the fourth node, and after sending the backup commit message and when the backup commit success response has not been received, the primary commit message is sent to the second node; Alternatively, a primary submission message is sent to the second node, and when the primary submission message is sent and the primary submission success response has not been received, the backup submission message is sent to the fourth node.
9. The method according to claim 7, characterized in that The method further comprises: In the case that a primary submission success response from the second node and / or a backup submission success response from the fourth node is not received, a process termination message is sent to the second node, the third node and the fourth node, and the process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
10. The method according to claim 7 or 8, characterized in that After the updated first data item is successfully submitted, the method further includes: A write lock release message is sent to the second node, where the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
11. The method according to claim 7, 8 or 10, characterized in that After the updated first data item is successfully submitted, the method further includes: Sending a first delete message to the second node, where the first delete message is used to instruct the second node to delete the write lock message and the master commit message; A second deletion message is sent to the fourth node, where the second deletion message is used to instruct the fourth node to update the stored data item and the first version value of the write object based on the backup commit message and to delete the backup commit message.
12. A transaction processing method, characterized in that: Applied to the first node, the method includes: Based on information of a write object and a read object included in the first transaction, read the write object from a second node and read the read object from a third node, wherein both the write object and the read object include a version value, and the write object includes a first data item, the second node is a primary node where the write object is located, and the third node is a primary node where the read object is located; Modifying the first data item to obtain an updated first data item; When a write lock is successfully added to the write object in the second node and the write object and the read object read by the first node are correct, a primary commit message for submitting the updated first data item is sent to the second node, and a backup commit message for submitting the updated first data item is sent to the fourth node. The write object or the read object read by the first node is correct if it means that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding primary node is a stable version value corresponding to the version value of the corresponding object read by the first node, or it means that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding primary node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the corresponding object has been successfully submitted, and the fourth node is the backup node of the write object; Upon receiving a successful primary commit response from the second node and a successful backup commit response from the fourth node, a transaction completion notification is generated. The successful primary commit response is sent by the second node after updating the stored data item and the first version value of the write object based on the primary commit message and the updated first data item. The updated write object includes a second version value, which is the next intermediate version value of the first version value. The successful backup commit response is sent by the fourth node after receiving the backup commit message.
13. The method according to claim 12, characterized in that The sending of a primary commit message for submitting the updated first data item to the second node, and the sending of a backup commit message for submitting the updated first data item to the fourth node, comprises: Sending the primary commit message to the second node and simultaneously sending the backup commit message to the fourth node; Alternatively, the backup commit message is sent to the fourth node, and after sending the backup commit message and when the backup commit success response has not been received, the primary commit message is sent to the second node; Alternatively, a primary submission message is sent to the second node, and when the primary submission message is sent and the primary submission success response has not been received, the backup submission message is sent to the fourth node.
14. The method according to claim 12 or 13, characterized in that After generating the transaction completion notification, the method further includes: A write lock release message is sent to the second node, where the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
15. A transaction processing device, characterized in that: Applied to a first node, the apparatus includes: a reading module, configured to read the write object from the second node and the read object from the third node based on information of the write object and the read object included in the first transaction, wherein the write object includes the first data item, the second node is a primary node where the write object is located, and the third node is a primary node where the read object is located; a modification module, configured to modify the first data item to obtain an updated first data item; a sending module, configured to send a write lock message to the second node and a read lock message to the third node, wherein the read lock message is used to add a read lock to the read object and detect whether the read object read by the first node is correct; A submission module is used to submit the updated first data item to the second node and the fourth node upon receiving a write lock success response from the second node and a read lock success response from the third node, the write lock success response indicating that the write lock is successfully added to the write object and the read write object is correct, the read lock success response indicating that the read lock is successfully added to the read object and the read read object is correct, and the fourth node is a backup node for the write object.
16. The device according to claim 15, characterized in that The sending module is mainly used for: Sending the write lock message to the second node and simultaneously sending the read lock message to the third node; Alternatively, sending the write lock message to the second node; After sending the write lock message and when the write lock success response has not been received, sending the read lock message to the third node; Alternatively, sending the read lock message to the third node; After sending the read lock message and when the read lock success response has not been received, sending the write lock message to the second node.
17. The device according to claim 15 or 16, characterized in that The sending module is further used for: When the submission module submits the updated first data item to the second node and the fourth node, a read lock release message is sent to the third node, where the read lock release message is used to instruct the third node to release the read lock of the read object.
18. The device according to claim 15 or 16, characterized in that The sending module is further used for: Upon receiving a write lock failure response from the second node and / or a read lock failure response from the third node, a process abort message is sent to the second node and the third node, wherein the write lock failure response indicates that the write lock on the write object failed and / or the write object read by the first node is incorrect, and the read lock failure response indicates that the read lock on the read object failed and / or the read object read by the first node is incorrect, and the process abort message is used to indicate the abort of processing of the first transaction, and the process abort message is also used to instruct the second node and the third node to unlock the object that was successfully locked.
19. The device according to claim 15, characterized in that The write object and the read object read by the first node both include version values, the write lock message includes the version value of the write object read by the first node, and the read lock message includes the version value of the read object read by the first node. The write object or the read object read by the first node is correct, which means that the version value of the corresponding object read by the first node meets the verification condition.
20. The device according to claim 19, characterized in that The verification condition means that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding master node is a stable version value corresponding to the version value of the corresponding object read by the first node, or, the verification condition means that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been submitted successfully, and the stable version value is used to indicate that the updated data item of the corresponding object has been submitted successfully.
21. The device according to claim 20, characterized in that The write lock message also includes the updated first data item; the commit module is mainly used to: Sending a primary commit message to the second node and a backup commit message to the fourth node, wherein the backup commit message includes the updated first data item; Upon receiving a successful primary submission response from the second node and a successful backup submission response from the fourth node, it is determined that the updated first data item is successfully submitted. The successful primary submission response is sent by the second node after updating the stored data item and the first version value of the write object based on the primary submission message and the updated first data item. The updated write object includes a second version value, which is the next intermediate version value of the first version value. The successful backup submission response is sent by the fourth node after receiving the backup submission message.
22. The device according to claim 21, characterized in that The submission module is mainly used for: Sending the primary commit message to the second node and simultaneously sending the backup commit message to the fourth node; Alternatively, the backup commit message is sent to the fourth node, and after sending the backup commit message and when the backup commit success response has not been received, the primary commit message is sent to the second node; Alternatively, a primary submission message is sent to the second node, and when the primary submission message is sent and the primary submission success response has not been received, the backup submission message is sent to the fourth node.
23. The device according to claim 21, characterized in that The sending module is further used for: In the case that a primary submission success response from the second node and / or a backup submission success response from the fourth node is not received, a process termination message is sent to the second node, the third node and the fourth node, and the process termination message is used to indicate the termination of processing of the first transaction, and the process termination message is also used to instruct the second node and the third node to unlock the successfully locked object.
24. The device according to claim 21 or 22, characterized in that The sending module is further used for: A write lock release message is sent to the second node, where the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
25. The device according to claim 21, 22 or 24, characterized in that The sending module is further used for: Sending a first delete message to the second node, where the first delete message is used to instruct the second node to delete the write lock message and the master commit message; A second deletion message is sent to the fourth node, where the second deletion message is used to instruct the fourth node to update the stored data item and the first version value of the write object based on the backup commit message and to delete the backup commit message.
26. A transaction processing device, characterized in that: Applied to a first node, the apparatus includes: a reading module, configured to read the write object from a second node and the read object from a third node based on information of the write object and the read object included in the first transaction, wherein both the write object and the read object include a version value, and the write object includes a first data item, the second node is a primary node where the write object is located, and the third node is a primary node where the read object is located; a modification module, configured to modify the first data item to obtain an updated first data item; A commit module, configured to, when a write lock is successfully added to the write object in the second node and the write object and the read object read by the first node are correct, send a primary commit message for submitting the updated first data item to the second node, and send a backup commit message for submitting the updated first data item to the fourth node, wherein the write object or the read object read by the first node is correct means that the version value of the corresponding object read by the first node is an intermediate version value and the version value of the corresponding object in the corresponding master node is a stable version value corresponding to the version value of the corresponding object read by the first node, or means that the version value of the corresponding object read by the first node is a stable version value and the version value of the corresponding object in the corresponding master node is the same as the version value of the corresponding object read by the first node, the intermediate version value is used to indicate that the updated data item of the corresponding object has not been successfully submitted, and the stable version value is used to indicate that the updated data item of the corresponding object has been successfully submitted, and the fourth node is a backup node for the write object; A generation module is used to generate a transaction completion notification upon receiving a primary submission success response from the second node and a backup submission success response from the fourth node, wherein the primary submission success response is sent by the second node after updating the stored data item and the first version value of the write object based on the primary submission message and the updated first data item, the updated write object includes a second version value, and the second version value is the next intermediate version value of the first version value, and the backup submission success response is sent by the fourth node after receiving the backup submission message.
27. The device according to claim 26, characterized in that The submission module is mainly used for: Sending the primary commit message to the second node and simultaneously sending the backup commit message to the fourth node; Alternatively, the backup commit message is sent to the fourth node, and after sending the backup commit message and when the backup commit success response has not been received, the primary commit message is sent to the second node; Alternatively, a primary submission message is sent to the second node, and when the primary submission message is sent and the primary submission success response has not been received, the backup submission message is sent to the fourth node.
28. The device according to claim 26 or 27, characterized in that The device further comprises: A sending module is used to send a write lock release message to the second node, and the write lock release message is used to instruct the second node to update the second version value to a third version value and release the write lock of the updated write object. The third version value is the stable version value corresponding to the second version value.
29. A node, characterized in that The node includes a processor and a memory, the memory is used to store at least one program instruction or code, and the processor is used to execute the at least one program instruction or code stored in the memory to implement the transaction processing method described in any one of claims 1 to 11 or claims 12 to 14.
30. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the computer is caused to execute the transaction processing method according to any one of claims 1 to 11 or claims 12 to 14.
Citation Information
Patent Citations
Method and device for locking data and distributed storage system
CN104572917A
Recovery in data centers
CN107771321A
Unified optimistic and pessimistic concurrency control for a software transactional memory (STM) system
US20100153953A1
Performing transactions in distributed transactional memory systems
US20190294711A1
