Transaction management methods, first node, electronic devices and storage media

By introducing physical clock skew into the vector clock structure, the problem of data conflicts in distributed database systems is solved, and transaction management performance is improved.

CN117725073BActive Publication Date: 2026-11-10GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311745395.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-15
Publication Date
2026-11-10
Estimated Expiration
2043-12-15

AI Technical Summary

Technical Problem

Existing distributed database management systems cannot provide a highly accurate and reliable global clock order in transaction management, leading to frequent data conflicts and reduced system performance.

Method used

By introducing a physical clock into the vector clock structure, the timing relationship between data replicas can be accurately determined by identifying the physical clock offset of the nodes, thereby resolving data conflicts.

Benefits of technology

It improves the transaction management performance of distributed database systems by introducing physical clock skew to overcome the problem of inaccurate local physical clocks, thus ensuring the resolution of data conflicts and the improvement of system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117725073B_ABST
    Figure CN117725073B_ABST
Patent Text Reader

Abstract

This application discloses a transaction management method, a first node, an electronic device, and a storage medium. The method includes: when there is a logical conflict between the data copy of the first node and the data copy of the second node, determining a first physical clock based on a first vector clock corresponding to the data copy of the first node, and determining a second physical clock based on a second vector clock corresponding to the data copy of the second node; determining the physical clock deviation between the first node and the second node; and determining the timing relationship between the data copy of the first node and the data copy of the second node based on the first physical clock, the second physical clock, and the physical clock deviation, so as to perform transaction management based on the timing relationship.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to a transaction management method, a first node, an electronic device, and a storage medium. Background Technology

[0002] A Distributed Database Management System (DDBMS) is a set of software systems responsible for managing logically integrated data access, consistency, and integrity in a distributed environment. Typically, a DDBMS consists of four components: a local database management system, data connections, a global system directory, and the DDBMS itself. The local database management system component is a standard database management system responsible for managing the data in its local node's database.

[0003] However, common transaction management methods based on distributed database management systems cannot provide a highly accurate and reliable global clock sequence, which in turn cannot effectively resolve data conflicts and reduces the transaction management performance of distributed database systems. Summary of the Invention

[0004] This application provides a transaction management method, a first node, an electronic device, and a storage medium, which can provide a highly accurate and reliable global clock sequence.

[0005] The technical solution of this application embodiment is implemented as follows:

[0006] In a first aspect, embodiments of this application provide a transaction management method, which is applied to a first node in a distributed system, and the method includes:

[0007] In the event of a logical conflict between the data replicas of the first node and the data replicas of the second node, the first physical clock is determined based on the first vector clock corresponding to the data replica of the first node, and the second physical clock is determined based on the second vector clock corresponding to the data replica of the second node.

[0008] Determine the physical clock offset between the first node and the second node;

[0009] The timing relationship between the data replicas of the first node and the data replicas of the second node is determined based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship.

[0010] Secondly, embodiments of this application provide a first node, which includes: a determining unit.

[0011] The determining unit is configured to, in the event of a logical conflict between the data replicas of the first node and the data replicas of the second node, determine a first physical clock based on a first vector clock corresponding to the data replica of the first node, and determine a second physical clock based on a second vector clock corresponding to the data replica of the second node; determine the physical clock offset between the first node and the second node; and determine the timing relationship between the data replicas of the first node and the data replicas of the second node based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship.

[0012] Thirdly, embodiments of this application provide an electronic device applied to a first node in a distributed system. The electronic device includes a processor and a memory storing processor-executable instructions. When the instructions are executed by the processor, the method described in the first aspect above is implemented.

[0013] Fourthly, embodiments of this application provide a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the method described in the first aspect above.

[0014] This application provides a transaction management method, a first node, an electronic device, and a storage medium. When a logical conflict exists between a data copy of the first node and a data copy of the second node, a first physical clock is determined based on a first vector clock corresponding to the data copy of the first node, and a second physical clock is determined based on a second vector clock corresponding to the data copy of the second node. The physical clock deviation between the first and second nodes is determined. The timing relationship between the data copies of the first and second nodes is determined based on the first physical clock, the second physical clock, and the physical clock deviation, thereby enabling transaction management based on the timing relationship. In other words, in this application's embodiments, the clock results of common vector clocks can be improved by adding a physical clock representing the node to the vector clock structure. This allows for more accurate determination of the timing relationship between data based on the node's physical clock and the physical clock deviation between different nodes, thus resolving data conflicts. In other words, in this application's embodiments, the physical clock of the node is used to determine the event timing, and the introduction of physical clock deviation overcomes the problem of inaccurate local physical clocks, thereby resolving data conflicts and improving the transaction management performance of the distributed database system. Attached Figure Description

[0015] Figure 1 This is a schematic diagram of the distributed system proposed in the embodiments of this application;

[0016] Figure 2This is a schematic diagram illustrating the implementation process of the transaction management method proposed in the embodiments of this application;

[0017] Figure 3 This is a schematic diagram illustrating data synchronization as proposed in an embodiment of this application;

[0018] Figure 4 This is a schematic diagram of the clock information proposed in an embodiment of this application;

[0019] Figure 5 This is a schematic diagram illustrating the determination of relative clock error according to an embodiment of this application;

[0020] Figure 6 This is a schematic diagram illustrating the calculation of relative clock error according to an embodiment of this application;

[0021] Figure 7 This is a schematic diagram of the experimental results of the transaction management method proposed in the embodiments of this application. Figure 1 ;

[0022] Figure 8 This is a schematic diagram of the experimental results of the transaction management method proposed in the embodiments of this application. Figure 2 ;;

[0023] Figure 9 This is a schematic diagram of the composition structure of the first node proposed in an embodiment of this application;

[0024] Figure 10 This is a schematic diagram of the composition structure of the electronic device proposed in the embodiments of this application. Detailed Implementation

[0025] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0026] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0027] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0028] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0029] A Distributed Database Management System (DDBMS) is a set of software systems responsible for managing the logical integration of data access, consistency, and integrity in a distributed environment. Due to the distributed nature of the data, a DDBMS must also possess the distributed management characteristics of computer network communication protocols in its management mechanism.

[0030] Generally, a distributed database management system consists of four components: a local database management system, a data connection, a global system directory, and a distributed database management system.

[0031] The local database management system component is a standard database management system responsible for managing the data in its local node's database. It has its own system log table, which stores overall information about the data on that node. The data connection component is software that allows all nodes to connect to other nodes; it contains information about the nodes and their connections. The global system directory component, in addition to the centralized database's data directory (data dictionary), also contains information about data distribution, such as sharding, replication, and distribution patterns. It can itself be sharded and replicated to various nodes like a relation. The distributed database management system component is the control center of the entire system. It is primarily responsible for executing global transactions, coordinating local database management systems to complete global applications, and ensuring global database consistency.

[0032] In other words, the distributed database management system is a very important part of the practical application of distributed systems. It not only possesses and uses all the characteristics of distributed systems, but also puts forward higher requirements for data storage and processing.

[0033] Currently, clock technologies for distributed database systems mainly include: physical clock technology, logical clock technology, and hybrid clock technology.

[0034] For physical clock technology, a distributed database transaction processing method based on Global Positioning System (GPS) atomic clocks is proposed. Node servers handle multiple transaction requests. If concurrency conflicts are detected between transactions, the start time of each transaction is obtained using a physical clock method. The calculation and correction of the physical clock are achieved by synchronizing the local time of the node server with the time of the GPS atomic clock server in its region, and then processing each transaction accordingly. In this scheme, each transaction is assigned a unique timestamp, and the start and commit times of the transaction are recorded on each node. To reduce the deviation of physical clocks between different nodes, a high-precision time signal provided by a GPS atomic clock is used as a global clock to coordinate the time of various nodes in the distributed database system.

[0035] However, the physical clocks mentioned above have clock drift issues at different nodes, and the clock frequencies may differ, leading to inaccurate timekeeping. They are also susceptible to interference from external factors, thus requiring high hardware configuration from the device.

[0036] For logical clock technology, some common techniques have proposed a distributed transaction management method and system based on distributed logical timestamps. This method uses logical time values ​​to characterize the temporal order of events. Nodes include three types: coordinating nodes, cataloging nodes, and data nodes. At the start of a transaction, the transaction start time is set to the local logical time of the coordinating node. If the difference between the local logical time of a data node and the coordinating node exceeds a preset threshold, the local logical time of the data node is synchronized, and the coordinating node rolls back the transaction. After synchronizing the time of the coordinating node, the transaction is retried. If the difference between the transaction pre-commit time and the transaction start time is greater than the transaction tolerance error, the transaction pre-commit time and the pre-commit message are sent to all data nodes participating in the transaction. Based on the difference in timestamps between two different transactions, a data node is selected as an arbitration node to arbitrate the timestamp order of the two different transactions.

[0037] However, the aforementioned logical clock cannot provide a global clock sequence; it can only provide a partial order relationship between events. In some cases, the logical clock cannot accurately determine the timing of events.

[0038] For hybrid clock technology, some common techniques propose a method and system for distributed transaction parallel replay based on Hybrid Logic Clock (HLC), specifically a transaction scheduling and execution strategy based on HLC timestamps. Each transaction is assigned a unique HLC timestamp and is scheduled and executed in chronological order. By comparing transaction timestamps, the system can guarantee the order and consistency of transactions, avoiding conflicts and data inconsistencies caused by concurrent execution. The key technology for achieving data consistency uses HLC and its algorithm to describe the temporal order between events. HLC technology combines physical clocks and logical clocks, simultaneously storing global physical clock information and logical clock information from the last data update. The recorded global physical clock value must be greater than or equal to the local physical clock value of the current node.

[0039] However, because the hybrid clocks mentioned above combine the characteristics of physical and logical clocks, they are more complex to design and implement, have higher maintenance costs, and may introduce certain system overhead. Furthermore, since they still rely on physical clocks, their high accuracy and reliability cannot be guaranteed 100%.

[0040] Furthermore, vector clock technology is an extension of logical clock technology. When traditional vector clock technology compares multiple clocks through its defined comparison relationship, if it finds that multiple vector clocks are not comparable, then there is a conflict between the corresponding data replicas. However, the data information stored in the vector clock is insufficient to resolve the conflict. Most consistency protocol products that use vector clock technology usually retain these conflicting data versions, inform the user of the data conflict, and push these conflicting data to the user, allowing the user to decide which data version to keep. This process, because it involves the user and cannot automatically resolve the conflict, is not very user-friendly.

[0041] It is evident that common vector clock techniques cannot completely resolve data conflict issues, thus reducing the transaction management performance of distributed database systems.

[0042] To address the aforementioned issues, in embodiments of this application, when a logical conflict exists between the data replicas of the first node and the data replicas of the second node, a first physical clock is determined based on the first vector clock corresponding to the data replica of the first node, and a second physical clock is determined based on the second vector clock corresponding to the data replica of the second node; the physical clock offset between the first and second nodes is determined; and the timing relationship between the data replicas of the first and second nodes is determined based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship. In other words, in embodiments of this application, the clock results of common vector clocks can be improved by adding a physical clock representing the node to the vector clock structure. This allows for more accurate determination of the timing relationship between data based on the physical clocks of the nodes, combined with the physical clock offsets between different nodes, in the event of data conflict, thereby resolving the data conflict. In other words, in embodiments of this application, the physical clocks of the nodes are used to determine the event timing, and the introduction of physical clock offsets overcomes the problem of inaccurate local physical clocks, thus resolving the data conflict problem and improving the transaction management performance of the distributed database system.

[0043] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0044] One embodiment of this application provides a transaction management method that can be applied to the first node in a distributed system. The distributed system includes at least two nodes, and these at least two nodes include at least the first node and the second node.

[0045] For example, in some embodiments, the distributed system may include n nodes, where n is an integer greater than 1. Among the n nodes, there is a first node, and any one of the other n-1 nodes can be a second node.

[0046] Exemplary, in some embodiments, Figure 1 This is a schematic diagram of the distributed system proposed in the embodiments of this application, such as... Figure 1 As shown, the distributed system 100 includes multiple nodes 101, and the number of nodes 101 in the distributed system 100 is greater than or equal to 2. Different nodes in the distributed system can be understood as different electronic devices, and different nodes are directed to different users.

[0047] Furthermore, in the embodiments of this application, Figure 2 This is a schematic diagram illustrating the implementation process of the transaction management method proposed in this application. Figure 2 As shown, the method for the first node to perform transaction management may include the following steps:

[0048] Step 101: In the event of a logical conflict between the data replica of the first node and the data replica of the second node, determine the first physical clock based on the first vector clock corresponding to the data replica of the first node, and determine the second physical clock based on the second vector clock corresponding to the data replica of the second node.

[0049] In the embodiments of this application, if there is a logical conflict between the data copy of the first node and the data copy of the second node, the first node can first determine the first physical clock corresponding to the first node through the corresponding first vector clock. At the same time, the first node can also determine the second physical clock corresponding to the second node based on the second vector clock corresponding to the data copy of the second node.

[0050] It should be noted that in the examples of this application, the first node is any node in the distributed system, and the second node is another node in the distributed system that is different from the first node. This application uses the first node and the second node as examples to describe the transaction management method of the distributed system provided in the embodiments of this application.

[0051] It should be noted that, in the example of this application, when the second node synchronizes data with the first node, the copy of the data written by the second node to each node in the distributed system is the data copy of the second node. Correspondingly, the copy of the data read by the first node from each node in the distributed system is the data copy of the first node.

[0052] It is understood that, in the embodiments of this application, the content of the data copy is actually the data itself.

[0053] It should be noted that, in the embodiments of this application, the data copy of the first node read by the first node from each node in the distributed system may come from the second node, or it may be a copy of the data previously stored by the first node, that is, the second node writes data copies to each node in the distributed system.

[0054] Exemplary, in some embodiments, Figure 3 This is a schematic diagram illustrating data synchronization as proposed in an embodiment of this application, such as... Figure 3 As shown, when the second node synchronizes data with the first node, the second node 101-2 in the distributed system writes data copies to each node 101 in the distributed system (including the first node 101-1), and the first node 101-1 reads data copies from each node 101 in the distributed system (including the second node 101-2).

[0055] It is understood that, in the embodiments of this application, when a second node successfully writes a data copy to a node in the distributed system, the first node may successfully read a data copy from that node. The data copy written by the second node can be considered the latest copy of that data, while the data copies stored by other nodes in the distributed system are not necessarily the latest copies. Accordingly, for the first node, the data copy it reads may be the latest data copy written by the second node, or it may be a data copy stored by other nodes themselves that is not the latest.

[0056] In other words, in the embodiments of this application, the data copy of the first node and the data copy of the second node may be the same or different.

[0057] It should be noted that, in the examples of this application, for a node in a distributed system, if a second node writes a data copy to the node, when the first node reads a data copy from the node, the data copy read is the data copy written by the second node; if the second node does not write a data copy to the node, when the first node reads a data copy from the node, the data copy read by the first node is the data copy stored by the node itself, rather than the data copy synchronized by the second node.

[0058] It should be noted that, in the examples of this application, when the first node reads data copies from all nodes in the distributed system, including itself, the second node writes data copies to all nodes in the distributed system, including the first node; when the first node reads data copies from all other nodes in the distributed system, excluding itself, the second node writes data copies to each node in the distributed system other than the first node.

[0059] It should be noted that, in the example of this application, when the second node writes the first data copy to each node in the distributed system, the second node may write the first data copy to itself or may not write the first data copy to itself.

[0060] For example, in some embodiments, the distributed system includes the following nodes: node 1, node 2, node 3 and node 4. Taking node 1 as the first node and node 2 as the second node, node 2 writes data copies to node 1, node 2, node 3 and node 4 respectively, and node 1 reads data copies from node 1, node 2, node 3 and node 4 respectively.

[0061] For example, in some embodiments, the distributed system includes the following nodes: node 1, node 2, node 3 and node 4. Taking node 1 as the first node and node 2 as the second node, node 2 writes data copies to node 1, node 3 and node 4 respectively, and node 1 reads data copies from node 1, node 3 and node 4 respectively.

[0062] For example, in some embodiments, the distributed system includes the following nodes: node 1, node 2, node 3 and node 4. Taking node 1 as the first node and node 2 as the second node, node 2 writes data copies to node 3 and node 4 respectively, and node 1 reads data copies from node 3 and node 4 respectively.

[0063] Furthermore, in the embodiments of this application, if there is a logical conflict between the data copy of the first node and the data copy of the second node, then the first node can determine the first physical clock corresponding to the first node and the second physical clock corresponding to the second node, respectively.

[0064] It should be noted that, in the embodiments of this application, the first node can determine its corresponding first physical clock through the corresponding first vector clock, and can also determine its corresponding second physical clock through the second vector clock corresponding to the data replica of the second node.

[0065] It is understood that, in the embodiments of this application, a vector clock can be used to determine the clock information of the data copy. The clock information of the data copy may include logical clock information and physical clock information.

[0066] In other words, in the embodiments of this application, the clock information of the data replica can be understood as its corresponding vector clock. The vector clock is an extension and expansion of the logical clock. Compared to the logical clock, the vector clock no longer increments the version counter for message sending and receiving events. The difference between the vector clock and the logical clock lies in their data structure design. Compared to the logical clock, the vector clock maintains the version counters of other nodes from the perspective of each node in the distributed system, and combines these version counters into an n-dimensional vector (n is the number of different nodes in the entire distributed system, and n is an integer greater than 1). This n-dimensional vector represents the version information of the corresponding data, and it is transmitted along with the data during communication and data transmission.

[0067] Accordingly, in the embodiments of this application, the first physical clock corresponding to the first node can represent the physical clock information of the data copy of the first node, and the second physical clock corresponding to the second node can represent the physical clock information of the data copy of the second node.

[0068] It is understood that, in the embodiments of this application, logical clock information can be understood as clock information defined by the user without referring to actual clock information.

[0069] For example, in some embodiments, logical clock information is a sequence of node identifiers and their logical version values, representing the logical version value information of data of other nodes known to the current node, reflecting the number of times the current node knows that other nodes have modified the data object.

[0070] It is understood that, in the embodiments of this application, physical clock information can be understood as actual clock information, which can be timestamp data, representing the physical time when the vector clock was last updated in the logical part at the current node.

[0071] Furthermore, in the embodiments of this application, the first vector clock corresponding to the data replica of the first node includes an n-dimensional vector corresponding to n nodes in the distributed system and a one-dimensional first physical time vector; wherein, the n-dimensional vector is the identifier and logical version number corresponding to the n nodes; and the first physical time vector is used to determine the first physical time.

[0072] Furthermore, in the embodiments of this application, the second vector clock corresponding to the data replica of the second node includes an n-dimensional vector corresponding to n nodes in the distributed system and a one-dimensional second physical time vector; wherein, the n-dimensional vector is the identifier and logical version number corresponding to the n nodes; the second physical time vector is used to determine the second physical time.

[0073] It is understood that in the embodiments of this application, n is an integer greater than 1.

[0074] It should be noted that, in the embodiments of this application, the vector clock is a data structure that maintains the data version perspective of this node from other nodes. Assuming there are n nodes in the entire distributed system, each data copy of the node has a corresponding n-dimensional vector. Each dimension of the vector corresponds to a node identifier and its corresponding logical version number in the distributed system. That is, each dimension represents the data version perspective of this node from that node.

[0075] It is understood that, in the embodiments of this application, in order to solve the problem that the vector clock technology itself cannot determine the event timing of incomparable clocks, in addition to the n-dimensional information of the above-mentioned n-dimensional vector, the clock structure of the vector clock also stores the timestamp of the last update of this vector clock. The timestamp can be represented as a one-dimensional vector, that is, the corresponding physical time vector. The timestamp can be the latest local time corresponding to the node when updating the clock vector.

[0076] In other words, in the embodiments of this application, compared with the clock structure of a common vector clock, the clock structure of the vector clock in this application adds a physical time vector that represents the physical clock of the node. Specifically, the newly added physical time vector can be used to represent the local timestamp information recorded when the node last updated the vector clock.

[0077] For example, in some embodiments, the clock structure of a vector clock can be represented as follows:

[0078] VC j =[[N0:v0,N1:v1,...,N j :v j ,...,N n :v n ,],t j ]

[0079] Where n is the number of nodes in the distributed system, N j The identifier representing the j-th node, v j This represents the logical version number of the j-th node recorded in this node, while t j This indicates the local timestamp information recorded when node j last updated this vector clock.

[0080] For example, in some embodiments, assuming the first node is the first node in the distributed system, i.e., node 1, then the clock structure of the vector clock corresponding to the data replica of the first node can be VC1 = [[N0:v0,N1:v1,...,N...]. n :v n [,],t1]. Here, the first vector clock includes n-dimensional vectors [N0:v0,N1:v1,...,N] corresponding to n nodes in the distributed system. n :v n ,] and a one-dimensional first physical time vector t1; an n-dimensional vector N represents the identifiers corresponding to the n nodes. n and logical version number v n The first physical time vector t1 is used to determine the first physical time, which is the local timestamp information recorded when the first node last updated the first vector clock VC1.

[0081] For example, in some embodiments, assuming the second node is the third node in the distributed system, i.e., node 3, then the clock structure of the vector clock corresponding to the data replica of the second node can be VC3 = [[N0:v0,N1:v1,N2:v2,N3:v3,...,N...]. n :v n[,],t3]. The second vector clock comprises n-dimensional vectors [N0:v0,N1:v1,N2:v2,N3:v3,...,N] corresponding to n nodes in the distributed system. n :v n ,] and a one-dimensional second physical time vector t3; an n-dimensional vector is the identifier N corresponding to n nodes. n and logical version number v n The second physical time vector t3 is used to determine the second physical time, which is the local timestamp information recorded when the second node last updated the second vector clock VC3.

[0082] Exemplary, in some embodiments, Figure 4 This is a schematic diagram of the clock information proposed in the embodiments of this application, such as... Figure 4 As shown, the clock information settings for the same data replica in nodes A, B, and C are as follows: (A:0 B:0 C:0 timestamp A0), (A:0 B:0 C:0 timestamp B0), and (A:0 B:0 C:0 timestamp C0), respectively. For a data replica, after the data replica is modified at time TA1 of node A, the clock information (A:1 B:0 C:0 timestamp A1) is obtained, indicating that the data replica was modified by node A at time A1 of node A. For a data copy of the same data, after node B modifies the data copy at time TB1, the resulting clock information is (A:0 B:1 C:0 timestamp B1), indicating that node B modified the data copy at time B1. When node A sends its own data copy to node B, and node B receives it at time TB2, the two data copies are merged, and their clock information is also merged, resulting in the data copy's time information (A:1 B:1 C:0 timestamp B2), indicating that the latest modification time of this data copy is TB2, and it has been modified by both nodes A and B. Similarly, when node A sends its own data copy to node C, and node C receives it at time TC1, the resulting clock information is (A:1 B:0 C:0 timestamp C1), indicating that the latest modification time of this data copy is TC1, and it has been modified by node A. It should be noted that in this clock information, the timestamp represents the physical time of the node where the data copy resides, while the information other than the timestamp is logical clock information, indicating whether any node has modified the data copy.

[0083] Furthermore, in the embodiments of this application, the first node can synchronously update the corresponding first physical time vector according to the update of the corresponding logical clock.

[0084] In other words, in the embodiments of this application, when the first logical clock corresponding to the first node in the first vector clock is updated, the first physical time vector can be updated synchronously.

[0085] It should be noted that, in the embodiments of this application, for a data copy, if the first node modifies the data copy at time T1, that is, the first logical clock corresponding to the first node is updated at time T1, the first physical time vector in the vector clock corresponding to the data copy will also be updated synchronously to T1.

[0086] For example, in some embodiments, assuming the distributed system includes nodes A, B, and C, for the same data replica, if node A modifies the data replica at time TA, then the vector clock corresponding to the data replica of node A can be represented as (A: 1 B: 0 C: 0 TA). This clock information indicates that the data replica was modified by node A at time TA of node A.

[0087] For example, in some embodiments, assuming the distributed system includes nodes A, B, and C, for the same data replica, if node B modifies the data replica at time TB, then the vector clock corresponding to the data replica of node B can be represented as (A: 0 B: 1 C: 0 TB). This clock information indicates that the data replica was modified by node B at time TB of node B.

[0088] Step 102: Determine the physical clock offset between the first node and the second node.

[0089] In the embodiments of this application, when there is a logical conflict between the data copy of the first node and the data copy of the second node, in addition to determining the first physical clock corresponding to the first node and the second physical clock corresponding to the second node, it is also necessary to determine the physical clock deviation between the first node and the second node.

[0090] It should be noted that, in the embodiments of this application, the first node can maintain a relative error state; wherein, the relative error state includes n-1 clock relative errors between the first node and the other n-1 nodes in the distributed system.

[0091] It should be noted that, in the embodiments of this application, each node in the distributed system can maintain a relative error state corresponding to that node. The relative error state maintained by each node can be used to determine the clock relative error between that node and other nodes.

[0092] It is understood that, in the embodiments of this application, the relative clock error between different nodes can be used to determine the relative error of the physical clock between different nodes, that is, it can be used to determine the physical clock offset between different nodes.

[0093] It should be noted that, in the embodiments of this application, the first node can store and maintain n-1 clock relative errors between the first node and other n-1 nodes in the form of a node state table. That is, the relative error state maintained by the first node can be represented as the node state table corresponding to the first node.

[0094] In other words, in the embodiments of this application, each node in the distributed system can be equipped with a node state table. The node state table maintained by any node includes the clock relative error between that node and other nodes in the distributed system, i.e., the clock relative error.

[0095] For example, in some embodiments, the node state table may be represented in the form of a hash table.

[0096] It should be noted that, in the embodiments of this application, the node state table in the data layer can periodically maintain the relative error of the physical clock between the node and other nodes, wherein the maintenance process can be implemented through the heartbeat packet sending process.

[0097] Furthermore, in an embodiment of this application, the first node can send heartbeat data packets to the other n-1 nodes in the distributed system; wherein the heartbeat data packets carry a first transmission time; then it can receive acknowledgment information sent by the other n-1 nodes; wherein the acknowledgment information carries a first reception time and a second transmission time; then it can determine n-1 clock relative errors based on the first transmission time, the first reception time, and the second transmission time; finally, the relative error state can be updated based on the n-1 clock relative errors.

[0098] It is understood that in the embodiments of this application, the first sending time represents the sending time of the first node sending the heartbeat data packet (heartbeat packet), the second sending time represents the sending time of other nodes sending confirmation information, and the first receiving time represents the receiving time of other nodes receiving the heartbeat data packet.

[0099] Accordingly, in the embodiments of this application, corresponding to the other n-1 nodes besides the first node in the distributed system, the first node can receive n-1 acknowledgment messages sent by the n-1 nodes, that is, obtain n-1 second sending times and n-1 first receiving times corresponding to the other n-1 nodes.

[0100] In other words, in the embodiments of this application, considering that the processing flow of heartbeat packets is similar to the calculation process of clock relative error, the calculation process of clock relative error can be integrated with the process of node heartbeat packet detection, thereby reducing additional communication overhead.

[0101] Exemplary, in some embodiments, Figure 5 This is a schematic diagram illustrating the determination of relative clock error according to an embodiment of this application, as shown below. Figure 5 As shown, device A corresponds to the first node, and devices B, C, D, etc., are other nodes in the distributed system. When device A sends a heartbeat to other devices, the sending time of the heartbeat can be recorded. After receiving the heartbeat from device A, devices B, C, D, etc., need to send a response acknowledgment to device A. At this time, the receiving time of the heartbeat and the sending time of the response can be written into the response acknowledgment information. Therefore, when device A receives the broadcast response, it can calculate the relative error of the physical clock using the information recorded in the transmitted acknowledgment information, thus determining the relative clock error between the first node and other nodes.

[0102] In other words, in the embodiments of this application, based on the heartbeat packet processing flow, some additional information can be added to the transmitted data packet to record the sending time and receiving time. Finally, after the node receives the broadcast response, error calculation can be performed based on the recorded sending time and receiving time to determine the relative clock error between the node and other nodes, thereby updating the error data in the node status table to maintain the relative error state corresponding to the node.

[0103] Furthermore, in the embodiments of this application, the first node can receive confirmation information sent by the other n-1 nodes at a second receiving time. Specifically, corresponding to the other n-1 nodes, the first node can receive n-1 confirmation messages sent by the other n-1 nodes at n-1 second receiving times respectively.

[0104] Furthermore, in the embodiments of this application, when the first node determines n-1 clock relative errors based on the first transmission time, the first reception time, and the second transmission time, it can first determine a first time difference based on the first transmission time and the first reception time; determine a second time difference based on the second transmission time and the second reception time; and then determine n-1 clock relative errors based on the first time difference and the second time difference.

[0105] It is understood that, in the embodiments of this application, for any node other than the first node, the first node can determine the first transmission time of sending the heartbeat data packet to that node, and determine the first and second transmission times corresponding to that node, as well as the second reception time of receiving the definite information sent by that node. Therefore, based on the first transmission time, first reception time, second transmission time, and second reception time corresponding to that node, the relative clock error between the first node and that node can be further determined. Accordingly, by traversing all n-1 nodes, n-1 relative clock errors between the first node and the other n-1 nodes can be determined.

[0106] Exemplary, in some embodiments, Figure 6 This is a schematic diagram illustrating the calculation of relative clock error according to an embodiment of this application, as shown below. Figure 6 As shown, for nodes A and B in a distributed system, T A2 T represents the time when the data packet (heartbeat packet) is sent. B1 At the moment of receiving the data packet, node B needs to send an acknowledgment to the source node (node ​​A) after receiving the heartbeat packet. B2 T is the confirmed transmission time. A3 This is the confirmed reception time. After recording these key data points, the physical clock offset between node A and node B can be calculated using the following formula, which is the relative clock error θ between node A and node B:

[0107]

[0108] Among them, T B1 -T A2 This can be understood as the first time difference between node A and node B, T. A3 -T B2 This can be understood as the second time difference between node A and node B.

[0109] It should be noted that, in the embodiments of this application, based on the first transmission time, the first reception time, the second transmission time, and the second reception time, other calculation methods can also be used to calculate the relative clock error between different nodes, and this application does not impose specific limitations.

[0110] For example, in some embodiments, the relative error state maintained by the first node can be represented in the form of a node state table. As shown in Table 1, assuming the first node is node 1, the node state table maintained by the first node records the relative clock error between the first node and other nodes in the entire distributed system.

[0111] Table 1

[0112] node Clock relative error Node 2 θ12 Node 3 θ13 Node 4 θ14 …… …… node n θ1n

[0113] For example, in some embodiments, the relative error state maintained by the first node can be represented in the form of a node state table. As shown in Table 2, assuming the first node is node n, the node state table maintained by the first node records the relative clock error between the first node and other nodes in the entire distributed system.

[0114] Table 2

[0115] node Clock relative error Node 1 θ1n Node 2 θ2n Node 3 θ3n …… …… node n-1 θ(n-1)n

[0116] Furthermore, in the embodiments of this application, when determining the physical clock deviation between the first node and the second node, the relative clock error between the first node and the second node can be determined based on the relative error state; then the relative clock error between the first node and the second node can be determined as the physical clock deviation.

[0117] In other words, in the embodiments of this application, the clock relative error between the two nodes indicated in the relative error state maintained by the first node can be used to determine the physical clock deviation between the two nodes. Specifically, the clock relative error indicated in the relative error state can be directly determined as the physical clock deviation, or the physical clock deviation can be determined by performing mathematical operations on the clock relative error indicated in the relative error state. This application does not impose specific limitations.

[0118] Step 103: Determine the timing relationship between the data replica of the first node and the data replica of the second node based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship.

[0119] In the embodiments of this application, if there is a logical conflict between the data replica of the first node and the data replica of the second node, then after determining the first physical clock based on the first vector clock corresponding to the data replica of the first node, determining the second physical clock based on the second vector clock corresponding to the data replica of the second node, and determining the physical clock deviation between the first node and the second node, the timing relationship between the data replica of the first node and the data replica of the second node can be further determined based on the first physical clock, the second physical clock, and the physical clock deviation, so that transaction management can be performed based on the timing relationship.

[0120] Furthermore, in the embodiments of this application, when the first node determines the timing relationship between the data replica of the first node and the data replica of the second node based on the first physical clock, the second physical clock, and the physical clock offset, it can first determine the actual physical clock corresponding to the second node based on the physical clock offset and the second physical clock; and then determine the timing relationship between the data replica of the first node and the data replica of the second node based on the first physical clock and the actual physical clock, so as to perform transaction management based on the timing relationship.

[0121] It should be noted that, in the embodiments of this application, since the physical clock deviation between the first node and the second node can characterize the relative error value of the physical clock between the first node and the second node, the first node can use the physical clock deviation with the second node to perform error compensation on the second physical clock corresponding to the second node, thereby determining the real physical clock corresponding to the second node, that is, the actual physical clock corresponding to the second node.

[0122] It is understood that, in the embodiments of this application, when the first node determines the actual physical clock corresponding to the second node based on the physical clock deviation and the second physical clock, it can perform an addition operation on the physical clock deviation and the second physical clock, and finally determine the sum of the calculated values ​​as the actual physical clock corresponding to the second node.

[0123] It should be noted that, in the embodiments of this application, after completing the error compensation for the second physical clock corresponding to the second node, when the first node determines the timing relationship between the data replica of the first node and the data replica of the second node based on the first physical clock and the actual physical clock, it can compare the magnitudes of the first physical clock and the actual physical clock, thereby determining the timing relationship between the data replica of the first node and the data replica of the second node based on the comparison result, and then using the timing relationship between the data replica of the first node and the data replica of the second node for transaction management.

[0124] For example, in an embodiment of this application, after comparing the size between the first physical clock and the actual physical clock, if the comparison result is that the first physical clock is less than the actual physical clock, then the data copy of the second node can be considered as the latest data copy synchronized from the second node, that is, the latest data synchronized from the second node.

[0125] It is understood that, in the embodiments of this application, the data copy synchronized by the second node may differ from the data copies stored by other nodes themselves in the following ways: modification, addition, deletion, etc.

[0126] It should be noted that, in the embodiments of this application, determining the temporal relationship between the data replicas of the first node and the data replicas of the second node ensures that the latest data is obtained, thereby guaranteeing the validity of the synchronized data.

[0127] In summary, the transaction management method proposed in steps 101 to 103 adds a timestamp representing the last update of the vector clock to the common vector clock structure, that is, it adds the physical clock corresponding to the node. Thus, when there is a conflict between data replicas, the timing relationship of the data replicas can be further determined by the physical clock indicated by the vector clock and the physical clock deviation between different nodes, so as to resolve the data conflict.

[0128] It is understood that the transaction management method proposed in this application uses a logical clock part to compare the sizes of clocks with causal timing, which can quickly obtain the order of events based on the size relationship of the logical clock parts, thereby determining the data version; and a physical clock part to compare the sizes of clocks without causal timing, which can make up for the inherent defect that the logical clock cannot solve the problem of parallel logical clocks.

[0129] In other words, the transaction management method proposed in this application can solve the problem that vector clocks cannot compare clocks that do not have a logical causal relationship by improving the clock structure of the vector clock; and in order to minimize the overhead of introducing physical clocks, the deviation calculation process is combined with the heartbeat detection process to deal with the physical clock deviation values ​​between different machines.

[0130] Understandably, the time it takes for a consensus protocol to complete a synchronization operation is the most important performance metric. Different data operations use different amounts of data; for example, an insert operation processes only one row of data, while an update operation may update multiple existing rows in the table simultaneously. By gradually increasing the amount of data required to synchronize in a single data operation, the overall time consumption and the effective latency after removing transmission delays can be measured.

[0131] For example, in some embodiments, experiments are conducted on the transaction management method proposed in the embodiments of this application. Figure 7 This is a schematic diagram of the experimental results of the transaction management method proposed in the embodiments of this application. Figure 1 ,like Figure 7As shown, latency tests were conducted for four data sizes: 1KB, 4KB, 16KB, and 64KB. Different data manipulation commands were used to achieve the required data transmission volume for each size. Latency measurements were performed in environments with two mobile devices (two nodes) and three mobile devices (three nodes). Each size was tested five times, and the average total latency and the average latency after removing the transmission time were calculated. Figure 7 This demonstrates the increase in total latency with varying data volume for two nodes (curve 702) and three nodes (curve 701). The total latency includes the processing time of the protocol algorithm and the data packet transmission time during inter-node communication. Only the start time of the first request and the completion time of the last request synchronization need to be recorded. Based on... Figure 7 It can be determined that the total time is higher in the case of three nodes than in the case of two nodes. This is because in the case of three nodes, one more node needs to be synchronized, which increases the time for data transmission over the network. As the amount of data increases, the processing latency and the latency for transmission over the network also increase, thus increasing the total time.

[0132] For example, in some embodiments, experiments are conducted on the transaction management method proposed in the embodiments of this application. Figure 8 This is a schematic diagram of the experimental results of the transaction management method proposed in the embodiments of this application. Figure 2 ,like Figure 8 As shown, after eliminating transmission delay, only the protocol processing time is considered for comparison. Since transmission delay is excluded, although there is a time difference between two nodes (curve 802) and three nodes (curve 801), the difference is small. In the protocol processing flow, the case of three nodes only has one more parallel request sending process and response receiving process compared to the case of two nodes. Therefore, the effective delay difference between the two cases is small.

[0133] Therefore, the transaction management method proposed in this application improves upon vector clock technology by adding a dimension of information, enabling vector clocks to resolve data conflicts that were previously unsolvable. Experiments show that the consistency protocol designed and implemented by the transaction management method proposed in this application has good time performance, achieving a transmission time of approximately 40ms for 1KB of data without considering transmission latency.

[0134] This application provides a transaction management method. When a logical conflict exists between a data replica of a first node and a data replica of a second node, a first physical clock is determined based on a first vector clock corresponding to the data replica of the first node, and a second physical clock is determined based on a second vector clock corresponding to the data replica of the second node. The physical clock offset between the first and second nodes is determined. The timing relationship between the data replicas of the first and second nodes is determined based on the first physical clock, the second physical clock, and the physical clock offset, thereby enabling transaction management based on this timing relationship. In other words, this application improves upon common vector clock results by adding a physical clock representing a node to the vector clock structure. This allows for more accurate determination of the timing relationship between data based on the physical clock of the node and the physical clock offset between different nodes, thus resolving data conflicts. In other words, this application utilizes the physical clock of the node for event timing judgment and overcomes the problem of inaccurate local physical clocks by introducing physical clock offsets, thereby resolving data conflicts and improving the transaction management performance of the distributed database system.

[0135] Based on the above embodiments, this application provides a transaction management method that can be applied to a first node or an electronic device, wherein the electronic device can be applied to the first node in a distributed management system.

[0136] For example, in some embodiments, the distributed system may include n nodes, where n is an integer greater than 1. Among the n nodes, there is a first node, and any one of the other n-1 nodes can be a second node.

[0137] Exemplary, in some embodiments, such as Figure 1 As shown, the distributed system 100 includes multiple nodes 101, and the number of nodes 101 in the distributed system 100 is greater than or equal to 2. Different nodes in the distributed system can be understood as different electronic devices, and different nodes are directed to different users.

[0138] Furthermore, in the embodiments of this application, on the one hand, an additional dimension is added to the vector clock technology to represent the timestamp of the last update of the vector clock. Thus, when a data conflict is detected through the vector clock, the event sequence can be determined by the value of this dimension and the physical clock offset stored locally on the node. On the other hand, the calculation process of the physical clock offset can be integrated into the timing communication process between nodes, avoiding additional communication overhead.

[0139] It should be noted that, in the embodiments of this application, vector clock technology can be selected to describe the time sequence between events. At the same time, an improvement is made on the basis of common vector clocks by adding a dimension to represent the local physical timestamp information when the vector clock was last updated. When parallel clock relationships occur, the timing can be determined by the added physical clock dimension and the clock deviation between locally stored nodes.

[0140] It is understood that, in the embodiments of this application, in order to solve the problem that the vector clock technology itself cannot determine the event timing of incomparable clocks, in addition to the n-dimensional information of the above-mentioned n-dimensional vector, the clock structure of the vector clock also stores the timestamp of the last update of this vector clock. The timestamp can be represented as a one-dimensional vector, that is, the corresponding physical time vector. The timestamp can be the latest local time corresponding to the node when updating the clock vector.

[0141] In other words, in the embodiments of this application, compared with the clock structure of a common vector clock, the clock structure of the vector clock in this application adds a physical time vector that represents the physical clock of the node. Specifically, the newly added physical time vector can be used to represent the local timestamp information recorded when the node last updated the vector clock.

[0142] It is understood that in the embodiments of this application, the vector clock is a data structure that maintains the data version perspective of the current node from other nodes. Assuming there are n nodes in the entire distributed system, each data copy of the node has a corresponding n-dimensional vector. Each dimension of the vector corresponds to a node identifier and its corresponding logical version number in the distributed system. That is, each dimension represents the data version perspective of the current node from that node. Since the vector clock technology itself cannot determine the event timing of incomparable clocks, in addition to this n-dimensional information, the clock structure also stores the timestamp of the last update of the current vector clock for auxiliary judgment in subsequent algorithms.

[0143] For example, in some embodiments, for the clock structure of a vector clock, there are n nodes in the distributed system, N j The identifier representing the j-th node, v j This represents the logical version number of the j-th node recorded in this node, while t j This represents the local timestamp information recorded when node j last updated this vector clock. Therefore, the vector clock structure held by a piece of data from node j is as follows:

[0144] VC j =[[N0:v0,N1:v1,...,N j :v j ,...,Nn :v n ,],t j ]

[0145] It is understood that, in the embodiments of this application, since the timestamp of the last update of the vector clock is stored in the clock structure of the vector clock, the process of resolving data conflicts overcomes the shortcomings of logical clocks that can only provide partial order relationships, and solves the problem that the vector clock technology itself cannot completely resolve conflicts between data.

[0146] It should be noted that, in the embodiments of this application, the first node can maintain a relative error state; wherein, the relative error state includes n-1 clock relative errors between the first node and the other n-1 nodes in the distributed system.

[0147] It should be noted that, in the embodiments of this application, each node in the distributed system can maintain a relative error state corresponding to that node. The relative error state maintained by each node can be used to determine the clock relative error between that node and other nodes.

[0148] It is understood that, in the embodiments of this application, the relative clock error between different nodes can be used to determine the relative error of the physical clock between different nodes, that is, it can be used to determine the physical clock offset between different nodes.

[0149] It should be noted that, in the embodiments of this application, the first node can store and maintain n-1 clock relative errors between the first node and other n-1 nodes in the form of a node state table. That is, the relative error state maintained by the first node can be represented as the node state table corresponding to the first node.

[0150] It should be noted that, in the embodiments of this application, the node state table in the data layer can periodically maintain the relative error of the physical clock between the node and other nodes, wherein the maintenance process can be implemented through the heartbeat packet sending process.

[0151] Furthermore, in an embodiment of this application, the first node can send heartbeat data packets to the other n-1 nodes in the distributed system; wherein the heartbeat data packets carry a first transmission time; then it can receive acknowledgment information sent by the other n-1 nodes; wherein the acknowledgment information carries a first reception time and a second transmission time; then it can determine n-1 clock relative errors based on the first transmission time, the first reception time, and the second transmission time; finally, the relative error state can be updated based on the n-1 clock relative errors.

[0152] Exemplary, in some embodiments, such as Figure 5As shown, device A corresponds to the first node, and devices B, C, D, etc., are other nodes in the distributed system. When device A sends a heartbeat to other devices, the sending time of the heartbeat can be recorded. After receiving the heartbeat from device A, devices B, C, D, etc., need to send a response acknowledgment to device A. At this time, the receiving time of the heartbeat and the sending time of the response can be written into the response acknowledgment information. Therefore, when device A receives the broadcast response, it can calculate the relative error of the physical clock using the information recorded in the transmitted acknowledgment information, thus determining the relative clock error between the first node and other nodes.

[0153] Exemplary, in some embodiments, such as Figure 6 As shown, for nodes A and B in a distributed system, T A2 T represents the time when the data packet (heartbeat packet) is sent. B1 At the moment of receiving the data packet, node B needs to send an acknowledgment to the source node (node ​​A) after receiving the heartbeat packet. B2 T is the confirmed transmission time. A3 This is the confirmed reception time. After recording these key data, the physical clock deviation between node A and node B can be calculated according to the following formula, that is, the relative clock error between node A and node B is as shown in formula (1).

[0154] Among them, T B1 -T A2 This can be understood as the first time difference between node A and node B, T. A3 -T B2 This can be understood as the second time difference between node A and node B.

[0155] Furthermore, in the embodiments of this application, if there is a logical conflict between the data replica of the first node and the data replica of the second node, then after determining the first physical clock based on the first vector clock corresponding to the data replica of the first node, determining the second physical clock based on the second vector clock corresponding to the data replica of the second node, and determining the physical clock deviation between the first node and the second node, the timing relationship between the data replica of the first node and the data replica of the second node can be further determined based on the first physical clock, the second physical clock, and the physical clock deviation, so that transaction management can be performed based on the timing relationship.

[0156] It should be noted that, in the embodiments of this application, since the physical clock deviation between the first node and the second node can characterize the relative error value of the physical clock between the first node and the second node, the first node can use the physical clock deviation with the second node to perform error compensation on the second physical clock corresponding to the second node, thereby determining the real physical clock corresponding to the second node, that is, the actual physical clock corresponding to the second node.

[0157] In summary, the transaction management method proposed in this application adds a timestamp representing the last update of the vector clock to the common vector clock structure, that is, it adds the physical clock corresponding to the node. Thus, when there is a conflict between data replicas, the timing relationship of the data replicas can be further determined by the physical clock indicated by the vector clock and the physical clock deviation between different nodes, so as to resolve the data conflict.

[0158] It is understood that the transaction management method proposed in this application uses a logical clock part to compare the sizes of clocks with causal timing, which can quickly obtain the order of events based on the size relationship of the logical clock parts, thereby determining the data version; and a physical clock part to compare the sizes of clocks without causal timing, which can make up for the inherent defect that the logical clock cannot solve the problem of parallel logical clocks.

[0159] In other words, the transaction management method proposed in this application can solve the problem that vector clocks cannot compare clocks that do not have a logical causal relationship by improving the clock structure of the vector clock; and in order to minimize the overhead of introducing physical clocks, the deviation calculation process is combined with the heartbeat detection process to deal with the physical clock deviation values ​​between different machines.

[0160] This application provides a transaction management method. When a logical conflict exists between a data replica of a first node and a data replica of a second node, a first physical clock is determined based on a first vector clock corresponding to the data replica of the first node, and a second physical clock is determined based on a second vector clock corresponding to the data replica of the second node. The physical clock offset between the first and second nodes is determined. The timing relationship between the data replicas of the first and second nodes is determined based on the first physical clock, the second physical clock, and the physical clock offset, thereby enabling transaction management based on this timing relationship. In other words, this application improves upon common vector clock results by adding a physical clock representing a node to the vector clock structure. This allows for more accurate determination of the timing relationship between data based on the physical clock of the node and the physical clock offset between different nodes, thus resolving data conflicts. In other words, this application utilizes the physical clock of the node for event timing judgment and overcomes the problem of inaccurate local physical clocks by introducing physical clock offsets, thereby resolving data conflicts and improving the transaction management performance of the distributed database system.

[0161] Based on the above embodiments, in another embodiment of this application... Figure 9 This is a schematic diagram of the composition structure of the first node proposed in an embodiment of this application, as shown below. Figure 9 As shown, the first node 110 proposed in this embodiment may include a determining unit 111, wherein,

[0162] The determining unit 111 is configured to, in the event of a logical conflict between the data replicas of the first node and the data replicas of the second node, determine a first physical clock based on a first vector clock corresponding to the data replica of the first node, and determine a second physical clock based on a second vector clock corresponding to the data replica of the second node; determine the physical clock offset between the first node and the second node; and determine the timing relationship between the data replicas of the first node and the data replicas of the second node based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship.

[0163] In the embodiments of this application, further, Figure 10 This is a schematic diagram of the composition structure of the electronic device proposed in the embodiments of this application, such as... Figure 10 As shown, the electronic device 120 proposed in this application embodiment may include a processor 121, a memory 122 storing instructions executable by the processor 121, and further, the electronic device 120 may also include a communication interface 123 and a bus 124 for connecting the processor 121, the memory 122 and the communication interface 123.

[0164] In the embodiments of this application, the processor 121 can be at least one of the following: Application-Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), Central Processing Unit (CPU), Controller, Microcontroller, and Microprocessor. It is understood that for different devices, the electronic device used to implement the above-mentioned processor function can also be other types, and this application embodiment does not specifically limit this. The electronic device 120 may also include a memory 122, which can be connected to the processor 121. The memory 122 is used to store executable program code, which includes computer operation instructions. The memory 122 may include high-speed RAM memory and may also include non-volatile memory, such as at least two disk drives.

[0165] In embodiments of this application, bus 124 is used to connect communication interface 123, processor 121, and memory 122, as well as the mutual communication between these devices.

[0166] In embodiments of this application, memory 122 is used to store instructions and data.

[0167] Furthermore, in an embodiment of this application, the processor 121 is configured to, when there is a logical conflict between the data replica of the first node and the data replica of the second node, determine a first physical clock based on a first vector clock corresponding to the data replica of the first node, and determine a second physical clock based on a second vector clock corresponding to the data replica of the second node; determine the physical clock offset between the first node and the second node; and determine the timing relationship between the data replica of the first node and the data replica of the second node based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship.

[0168] In practical applications, the aforementioned memory 122 can be volatile memory, such as random-access memory (RAM); or non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); or a combination of the above types of memory, and provide instructions and data to the processor 121.

[0169] Furthermore, in this embodiment, the functional modules can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional module.

[0170] If the integrated unit is implemented as a software functional module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the method of this embodiment. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0171] This application provides a first node and an electronic device. When a logical conflict exists between a data copy of the first node and a data copy of a second node, a first physical clock is determined based on a first vector clock corresponding to the data copy of the first node, and a second physical clock is determined based on a second vector clock corresponding to the data copy of the second node. The physical clock offset between the first and second nodes is determined. Based on the first physical clock, the second physical clock, and the physical clock offset, the timing relationship between the data copies of the first and second nodes is determined for transaction management based on the timing relationship. In other words, in this application's embodiments, the clock results of common vector clocks can be improved by adding a physical clock representing the node to the vector clock structure. This allows for more accurate determination of the timing relationship between data based on the node's physical clock and the physical clock offset between different nodes, thus resolving data conflicts. In other words, in this application's embodiments, the physical clock of the node is used to determine the event timing, and the introduction of physical clock offset overcomes the problem of inaccurate local physical clocks, thereby resolving data conflicts and improving the transaction management performance of the distributed database system.

[0172] This application provides a computer-readable storage medium storing a program thereon, which, when executed by a processor, implements the transaction management method described above.

[0173] Specifically, the program instructions corresponding to a transaction management method in this embodiment can be stored on storage media such as optical discs, hard disks, and USB flash drives. When the program instructions corresponding to a transaction management method in the storage media are read or executed by an electronic device, the following steps are included:

[0174] In the event of a logical conflict between the data replicas of the first node and the data replicas of the second node, the first physical clock is determined based on the first vector clock corresponding to the data replica of the first node, and the second physical clock is determined based on the second vector clock corresponding to the data replica of the second node.

[0175] Determine the physical clock offset between the first node and the second node;

[0176] The timing relationship between the data replicas of the first node and the data replicas of the second node is determined based on the first physical clock, the second physical clock, and the physical clock offset, so as to perform transaction management based on the timing relationship.

[0177] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.

[0178] This application is described with reference to schematic and / or block diagrams of implementations of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block of the schematic and / or block diagrams can be implemented by computer program instructions, and combinations of blocks in the schematic and / or block diagrams can be implemented. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the schematic and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0179] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in the implementation flow diagram. Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0180] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0181] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application.

Claims

1. A transaction management method, characterized in that, The method is applied to the first node in a distributed system, and the method includes: In the event of a logical conflict between the data replicas of the first node and the data replicas of the second node, the first physical clock is determined based on the first vector clock corresponding to the data replica of the first node, and the second physical clock is determined based on the second vector clock corresponding to the data replica of the second node; the second node is any one of the other n-1 nodes besides the first node. The physical clock offset between the first node and the second node is determined based on the relative error state; wherein, the relative error state is updated based on the n-1 clock relative errors between the first node and the other n-1 nodes in the distributed system; The actual physical clock corresponding to the second node is determined based on the physical clock deviation and the second physical clock. If the first physical clock is less than the actual physical clock, then the latest data is synchronized from the second node. The method further includes: The first node sends a heartbeat data packet to the second node, wherein the heartbeat data packet carries a first transmission time; The second receiving time receives the confirmation information sent by the second node, wherein the confirmation information carries the first receiving time and the second sending time; Based on the first transmission time, the first reception time, the second transmission time, and the second reception time, the clock relative error between the first node and the second node is determined, and the number of clock relative errors is n-1.

2. The method according to claim 1, characterized in that, The first vector clock includes an n-dimensional vector corresponding to n nodes in the distributed system and a one-dimensional first physical time vector; wherein, the n-dimensional vector is the identifier and logical version number corresponding to the n nodes; the first physical time vector is used to determine the first physical time; n is an integer greater than 1; The second vector clock includes an n-dimensional vector corresponding to n nodes in the distributed system and a one-dimensional second physical time vector; wherein, the n-dimensional vector is the identifier and logical version number corresponding to the n nodes; the second physical time vector is used to determine the second physical time.

3. The method according to claim 2, characterized in that, The method further includes: When the first logical clock corresponding to the first node in the first vector clock is updated, the first physical time vector is updated.

4. The method according to claim 2 or 3, characterized in that, The method further includes: Maintain the relative error state; wherein the relative error state includes n-1 clock relative errors between the first node and the other n-1 nodes in the distributed system.

5. The method according to claim 4, characterized in that, The determination of the physical clock offset between the first node and the second node based on the relative error state includes: Based on the relative error state, the clock relative error between the first node and the second node is determined; The relative clock error between the first node and the second node is defined as the physical clock deviation.

6. The method according to claim 1, characterized in that, The method further includes: Determining the relative clock error between the first node and the second node based on the first transmission time, the first reception time, and the second transmission time includes: A first time difference is determined based on the first transmission time and the first reception time; a second time difference is determined based on the second transmission time and the second reception time. The relative clock error between the first node and the second node is determined based on the first time difference and the second time difference.

7. A first node for transaction management, characterized in that, The first node includes: a determining unit. The determining unit is configured to, in the event of a logical conflict between the data replicas of the first node and the data replicas of the second node, determine a first physical clock based on a first vector clock corresponding to the data replica of the first node, and determine a second physical clock based on a second vector clock corresponding to the data replica of the second node, wherein the second node is any one of the other n-1 nodes besides the first node; determine the physical clock deviation between the first node and the second node based on a relative error state; wherein the relative error state is updated based on n-1 clock relative errors between the first node and the other n-1 nodes in the distributed system; determine the actual physical clock corresponding to the second node based on the physical clock deviation and the second physical clock; if the first physical clock is less than the actual physical clock, then synchronize the latest data from the second node; The determining unit is further configured to send a heartbeat data packet to the second node, wherein the heartbeat data packet carries a first sending time; receive confirmation information sent by the second node at a second receiving time, wherein the confirmation information carries a first receiving time and a second sending time; and determine the clock relative error between the first node and the second node based on the first sending time, the first receiving time, the second sending time, and the second receiving time, wherein the number of clock relative errors is n-1.

8. An electronic device, characterized in that, The electronic device, applied to the first node in a distributed system, includes a processor and a memory storing processor-executable instructions, which, when executed by the processor, implement the method as described in any one of claims 1-6.

9. A computer-readable storage medium having a program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • High availability stream processing system and method

    CN105959151A

  • Cloud edge-end virtual-real combination simulation time synchronization method and system

    CN115134034A