Method and apparatus for maintaining global consistency of hybrid logical clocks in a distributed cluster

By introducing the jump value of the physical clock into the distributed cluster and updating the hybrid logic clock, the time correlation and monotonic incremental loss caused by clock jump are solved, and the global consistency and high availability of the hybrid logic clock are achieved.

CN115328930BActive Publication Date: 2025-05-27CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211007280.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-22
Publication Date
2025-05-27
Estimated Expiration
2042-08-22

AI Technical Summary

Technical Problem

In distributed clusters, clock jumps will lead to the loss of time correlation and monotonic incrementality of hybrid logical clocks, which in turn will affect the availability and consistency of the cluster.

Method used

By introducing the jump value of the physical clock and calculating and updating the hybrid logic clock, ensuring that time correlation and monotonic incrementality are met during the time jump, thereby maintaining the global consistency of the hybrid logic clock in a distributed cluster.

Benefits of technology

It realizes the normal operation of the hybrid logic clock in the clock jump or failure scenario, ensures the global consistency of the hybrid logic clock in the distributed cluster, and maintains time correlation and monotonic incrementality without performance loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115328930B_ABST
    Figure CN115328930B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of distributed clocks, and provides a method and device for maintaining global consistency of a hybrid logical clock in a distributed cluster. The method of the present invention includes: Step S1: Obtain the hybrid logical clock value and physical clock value of the local node at time t1; Step S2: Calculate the hybrid logical clock value of the local node at time t2 according to the hybrid logical clock value of the local node at time t1; Step S3: Obtain the physical clock value of the local node at time t2, and calculate the jump value of the physical clock of the local node according to the clock jump type; Step S4: Obtain the physical clock value of the local node at time t3, and update the hybrid logical clock value of the local node at time t3. The present invention can quickly detect a clock jump of a single node within 2 s, and ensure the time correlation and monotonic increase of the HLC in a failure scenario without performance loss, ensure the consistency of the HLC in a distributed cluster, and can tolerate differences in the physical times of each node in the cluster.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed clocks, and particularly to a method and device for maintaining global consistency of hybrid logic clocks in a distributed cluster. Background Art

[0002] The hybrid logic clock (HLC) is generated by combining a physical clock and a logic clock. The high bit uses a physical clock with a certain precision, and the low bit uses a logic clock. The physical clock in the high bit ensures time correlation, and the logic clock in the low bit meets the requirements of high concurrency. The hybrid logic clocks of different nodes in a distributed cluster are synchronized in the cluster as messages spread. The local hybrid logic clock is updated by comparing the local physical clock, the local hybrid logic clock, and the hybrid logic clock in the remote message. The synchronization strategy triggered by message spreading ensures the consistency of the hybrid logic clock in the distributed cluster. In practical applications, there are the following deficiencies: 1. When the clock jumps forward, the available life cycle of the cluster becomes shorter; 2. When the clock jumps backward, the time correlation of the HLC in the cluster is lost; 3. When the cluster fails and a time jump occurs, it is impossible to ensure the monotonically increasing property of the HLC.

[0003] Therefore, how to provide an effective distributed clock method in the scenario of clock jumps has become an urgent technical problem to be solved. Summary of the Invention

[0004] In view of this, in order to overcome the deficiencies of the prior art, the present invention ensures that the hybrid logic clock satisfies time correlation and monotonically increasing property during time jumps by introducing the jump value of the physical clock, maintains the global consistency of the hybrid logic clock in the distributed cluster, and enables the hybrid logic clock to still work normally when there is a time jump in the distributed cluster or in a failure scenario.

[0005] On the one hand, the present invention provides a method for maintaining global consistency of hybrid logic clocks in a distributed cluster, including:

[0006] Step S1: Obtain the hybrid logic clock value and the physical clock value of the local node at time t1;

[0007] Step S2: Calculate the hybrid logic clock value of the local node at time t2 according to the hybrid logic clock value of the local node at time t1;

[0008] Step S3: Obtain the physical clock value of the local node at time t2, calculate the jump value of the physical clock of the local node according to the clock jump type, and determine whether a time jump occurs according to the jump value;

[0009] Step S4: Obtain the physical clock value of the local node at time t3, and update the hybrid logic clock value of the local node at time t3.

[0010] Further, in the method for maintaining the global consistency of the hybrid logical clock in the distributed cluster according to the present invention, in step S1, the hybrid logical clock value of the local node at time t1 is obtained at an interval of no more than 2 s.

[0011] Further, in the method for maintaining the global consistency of the hybrid logical clock in the distributed cluster according to the present invention, in step S2, the hybrid logical clock value of the local node at time t2 is equal to the hybrid logical clock value of the local node at time t1 plus 1.

[0012] Further, in the method for maintaining the global consistency of the hybrid logical clock in the distributed cluster according to the present invention, in step S3, according to the clock jump type, the jump value of the physical clock of the local node is calculated, including:

[0013] When the local node jumps to the future, the jump value of the physical clock of the local node is equal to the difference between the hybrid logical clock value at time t1 and the physical clock value at time t2;

[0014] When the local node jumps to the past, the jump value of the physical clock of the local node is equal to the difference between the hybrid logical clock value at time t2 and the physical clock value at time t2.

[0015] Further, in the method for maintaining the global consistency of the hybrid logical clock in the distributed cluster according to the present invention, in step S3, it is judged whether a time jump occurs according to the jump value, including: when the calculated jump value of the physical clock is greater than 2 s, it is determined that a time jump occurs.

[0016] Further, the method for maintaining the global consistency of the hybrid logical clock in the distributed cluster according to the present invention is characterized in that in step S4, the hybrid logical clock value of the local node at time t3 is updated, including:

[0017] Step S41: The physical clock value of the local node at time t3 and the jump value of the physical clock of the local node are summed to obtain a first sum value;

[0018] Step S42: The hybrid logical clock value at time t2 is summed after adding 1 to obtain a second sum value;

[0019] Step S43: The first sum value and the second sum value are compared, and the larger value is used as the hybrid logical clock value at time t3.

[0020] On the other hand, the present invention also provides a device for maintaining the global consistency of the hybrid logical clock in the distributed cluster, and the device includes:

[0021] A hybrid logical clock value acquisition module, configured to obtain the hybrid logical clock value of the local node at time t1 at an interval of no more than 2 s;

[0022] A physical clock value acquisition module, which is used to acquire the physical clock value of this node at time t1, the physical clock value of this node at time t2, and the physical clock value of this node at time t3;

[0023] A hybrid logical clock value calculation module, which is used to calculate the hybrid logical clock value of this node at time t2 according to the hybrid logical clock value of this node at time t1;

[0024] A physical clock jump value calculation module, which is used to calculate the jump value of the physical clock of this node according to the clock jump type, and determine whether a time jump occurs according to the jump value;

[0025] A hybrid logical clock value update module, which is used to update the hybrid logical clock value of this node at time t3.

[0026] Further, in the device for maintaining the global consistency of the hybrid logical clock in the distributed cluster of the present invention, the hybrid logical clock value of this node at time t2 is equal to the hybrid logical clock value of this node at time t1 plus 1.

[0027] Further, in the device for maintaining the global consistency of the hybrid logical clock in the distributed cluster of the present invention, the hybrid logical clock value calculation module is used to calculate the jump value of the physical clock of this node according to the clock jump type, including:

[0028] When this node jumps to the future, the jump value of the physical clock of this node is equal to the difference between the hybrid logical clock value at time t1 and the physical clock value at time t2;

[0029] When this node jumps to the past, the jump value of the physical clock of this node is equal to the difference between the hybrid logical clock value at time t2 and the physical clock value at time t2.

[0030] Further, in the device for maintaining the global consistency of the hybrid logical clock in the distributed cluster of the present invention, the hybrid logical clock value update module is used to sum the physical clock value of this node at time t3 and the jump value of the physical clock of this node to obtain a first sum value; perform a sum operation of adding 1 to the hybrid logical clock value at time t2 to obtain a second sum value; compare the first sum value and the second sum value, and use the larger value as the hybrid logical clock value at time t3.

[0031] The method and device for maintaining the global consistency of the hybrid logical clock in the distributed cluster of the present invention have the following beneficial effects:

[0032] 1. It can quickly detect the clock jump of a single node within 2 s.

[0033] 2. On the premise of no performance loss, it can ensure the time correlation and monotonic increase of HLC in the fault scenario.

[0034] 3. It can ensure the consistency of HLC in a distributed cluster and tolerate differences in the physical time of each node in the cluster. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings.

[0036] Figure 1 It is a flowchart of a method for maintaining global consistency of a hybrid logical clock in a distributed cluster according to the first embodiment of the present invention.

[0037] Figure 2 It is a flowchart of a method for maintaining global consistency of a hybrid logical clock in a distributed cluster according to the second embodiment of the present invention.

[0038] Figure 3 It is an architecture diagram of a device for maintaining global consistency of a hybrid logical clock in a distributed cluster according to the third embodiment of the present invention.

[0039] Figure 4 It is a schematic diagram of a method for maintaining global consistency of a hybrid logical clock in a distributed cluster according to the fourth embodiment of the present invention.

[0040] Figure 5 It is a schematic diagram of a method for maintaining global consistency of a hybrid logical clock in a distributed cluster according to the fifth embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0041] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0042] It should be noted that, without conflict, the following embodiments and the features in the embodiments can be combined with each other; and, based on the embodiments in the present disclosure, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present disclosure.

[0043] Note that the following description pertains to various aspects of embodiments within the scope of the appended claims. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any specific structure and / or function described herein is illustrative only. Based on this disclosure, those skilled in the art should understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of the aspects set forth herein can be used to implement an apparatus and / or practice a method. Additionally, this apparatus and / or method can be implemented using other structures and / or functionality in addition to one or more of the aspects set forth herein.

[0044] Figure 1 FIG. is a flowchart of a method for maintaining global consistency of a hybrid logical clock in a distributed cluster according to an exemplary first embodiment of the present invention, as Figure 1 shown, the method of this embodiment includes:

[0045] Step S1: Obtain the hybrid logical clock value and physical clock value of this node at time t1;

[0046] Step S2: Calculate the hybrid logical clock value of this node at time t2 based on the hybrid logical clock value of this node at time t1;

[0047] Step S3: Obtain the physical clock value of this node at time t2, calculate the jump value of the physical clock of this node according to the clock jump type, and determine whether a time jump occurs based on the jump value;

[0048] Step S4: Obtain the physical clock value of this node at time t3 and update the hybrid logical clock value of this node at time t3.

[0049] In step S1 of the method of this embodiment, the hybrid logical clock value of this node at time t1 is obtained at a time interval not exceeding 2 s.

[0050] In step S2 of the method of this embodiment, the hybrid logical clock value of this node at time t2 is equal to the hybrid logical clock value of this node at time t1 plus 1. In the method of this embodiment, the unit of the hybrid logical clock value is one-sixteenth of a nanosecond. Therefore, the "1" in step S2 of the method of this embodiment represents one-sixteenth of a nanosecond.

[0051] In step S3 of the method of this embodiment, calculating the jump value of the physical clock of this node according to the clock jump type includes:

[0052] When this node jumps to the future, the jump value of the physical clock of this node is equal to the difference between the hybrid logical clock value at time t1 and the physical clock value at time t2;

[0053] When this node jumps back in time, the jump value of the physical clock of this node is equal to the difference between the value of the hybrid logical clock at time t2 and the value of the physical clock at time t2.

[0054] In step S3 of the method of this embodiment, determining whether a time jump occurs according to the jump value includes: when the calculated jump value of the physical clock is greater than 2s, it is determined that a time jump occurs.

[0055] Figure 2 As a flowchart of a method for maintaining global consistency of hybrid logical clocks in a distributed cluster according to an exemplary second embodiment of the present invention, this embodiment is Figure 1 a preferred embodiment of the method shown, as Figure 2 shown, in step S4 of the method of this embodiment, updating the value of the hybrid logical clock of this node at time t3 includes:

[0056] Step S41: Sum the value of the physical clock of this node at time t3 and the jump value of the physical clock of this node to obtain a first sum value;

[0057] Step S42: Perform a sum - of - adding - 1 operation on the value of the hybrid logical clock at time t2 to obtain a second sum value;

[0058] Step S43: Compare the first sum value with the second sum value, and use the larger value as the value of the hybrid logical clock at time t3.

[0059] In the method of this embodiment, the unit of the hybrid logical clock value is one - sixteenth of a nanosecond. Therefore, the "1" in step 42 of the method of this embodiment represents one - sixteenth of a nanosecond.

[0060] Figure 3 As an architecture diagram of a device for maintaining global consistency of hybrid logical clocks in a distributed cluster according to an exemplary third embodiment of the present invention, as Figure 3 shown, the device of this embodiment includes:

[0061] A hybrid logical clock value acquisition module, configured to acquire the value of the hybrid logical clock of this node at time t1 at an interval of no more than 2s;

[0062] A physical clock value acquisition module, configured to acquire the value of the physical clock of this node at time t1, the value of the physical clock of this node at time t2, and the value of the physical clock of this node at time t3;

[0063] A hybrid logical clock value calculation module, configured to calculate the value of the hybrid logical clock of this node at time t2 according to the value of the hybrid logical clock of this node at time t1;

[0064] A physical clock jump value calculation module, configured to calculate the jump value of the physical clock of this node according to the clock jump type, and determine whether a time jump occurs according to the jump value;

[0065] The hybrid logic clock value update module is used to update the hybrid logic clock value of the local node at time t3.

[0066] In the device for maintaining the global consistency of the hybrid logic clock in the distributed cluster according to this embodiment, the hybrid logic clock value of the local node at time t2 is equal to the hybrid logic clock value of the local node at time t1 plus 1.

[0067] In the device for maintaining the global consistency of the hybrid logic clock in the distributed cluster according to this embodiment, the hybrid logic clock value calculation module is used to calculate the jump value of the physical clock of the local node according to the clock jump type, including:

[0068] When the local node jumps to the future, the jump value of the physical clock of the local node is equal to the difference between the hybrid logic clock value at time t1 and the physical clock value at time t2;

[0069] When the local node jumps to the past, the jump value of the physical clock of the local node is equal to the difference between the hybrid logic clock value at time t2 and the physical clock value at time t2.

[0070] In the device for maintaining the global consistency of the hybrid logic clock in the distributed cluster according to this embodiment, the hybrid logic clock value update module is used to sum the physical clock value of the local node at time t3 and the jump value of the physical clock of the local node to obtain a first sum value; perform a summation process of adding 1 to the hybrid logic clock value at time t2 to obtain a second sum value; compare the first sum value with the second sum value, and take the larger value as the hybrid logic clock value at time t3.

[0071] The fourth exemplary embodiment of the present invention provides a method for maintaining the global consistency of the hybrid logic clock in a distributed cluster. The method of this embodiment is Figure 1 a preferred embodiment of the method shown, and the application principle of the method of this embodiment when the hybrid logic clock jumps to the future is as Figure 4 shown.

[0072] Specifically, as Figure 4As shown in the figure, at time t1, the hybrid logical clock value crt_hlc1 of this node is consistent with the physical clock value pt1 of this node; at time t2, the clock of this node jumps into the future, and the physical clock value of this node after the jump is pt2. After the time jumps into the future, the first hybrid logical clock value HLC obtained by this node is: crt_hlc2 = crt_hlc1 + 1, that is, the hybrid logical clock value crt_hlc1 at time t1 is incremented by 1 to obtain the hybrid logical clock value crt_hlc2 at time t2. At the same time, the jump value of the physical clock of this node is calculated as: delta = crt_hlc1 – pt2, that is, the difference between the hybrid logical clock value crt_hlc1 at time t1 and the physical clock value pt2 at time t2 is used as the jump value delta. When updating HLC at subsequent time t3, the physical clock value pt3 of this node at time t3 and the jump value delta of the physical clock of this node are summed to obtain a first sum value; the hybrid logical clock value crt_hlc2 at time t2 is incremented by 1 and summed to obtain a second sum value; the first sum value and the second sum value are compared, and the larger value is used as the hybrid logical clock value crt_hlc3 at time t3.

[0073] The exemplary fifth embodiment of the present invention provides a method for maintaining global consistency of hybrid logical clocks in a distributed cluster. The method of this embodiment is Figure 1 a preferred embodiment of the method shown. The application principle of the method of this embodiment when the hybrid logical clock jumps into the past is as Figure 5 shown.

[0074] Specifically, as Figure 5 shown, at time t1, the hybrid logical clock value crt_hlc1 of this node is consistent with the physical clock value pt1 of this node; at time t2, the clock jumps into the past, and the physical clock value after the jump is pt2. The value of the hybrid logical clock crt_hlc2 of this node at time t2 is the value of the hybrid logical clock crt_hlc1 at time t1 plus 1. The clock jump value delta calculated at time t2 is the difference between the hybrid logical clock value crt_hlc2 at time t2 and the physical clock value pt2 at time t2; when updating HLC at subsequent time t3, the physical clock value pt3 of this node at time t3 and the jump value delta of the physical clock of this node are summed to obtain a first sum value; the hybrid logical clock value crt_hlc2 at time t2 is incremented by 1 and summed to obtain a second sum value; the first sum value and the second sum value are compared, and the larger value is used as the hybrid logical clock value crt_hlc3 at time t3.

[0075] As described above, it is only the specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A method for maintaining global consistency of hybrid logical clocks in a distributed cluster, characterized in that, the method includes: Step S1: Obtain the hybrid logical clock value and physical clock value of the local node at time t1; at time t1, the hybrid logical clock value crt_hlc1 of the local node is consistent with the physical clock value pt1 of the local node; Step S2: Calculate the hybrid logical clock value of the local node at time t2 according to the hybrid logical clock value of the local node at time t1; Step S3: Obtain the physical clock value of the local node at time t2, calculate the jump value of the physical clock of the local node according to the clock jump type, and determine whether a time jump occurs according to the jump value; Step S4: Obtain the physical clock value of the local node at time t3, and update the hybrid logical clock value of the local node at time t3; In Step S4, updating the hybrid logical clock value of the local node at time t3 includes: Step S41: Sum the physical clock value of the local node at time t3 and the jump value of the physical clock of the local node to obtain a first sum value; Step S42: Perform a sum operation of adding 1 to the hybrid logical clock value at time t2 to obtain a second sum value; Step S43: Compare the first sum value with the second sum value, and use the larger value as the hybrid logical clock value at time t3.

2. The method for maintaining global consistency of hybrid logical clocks in a distributed cluster according to claim 1, characterized in that, in Step S1, the hybrid logical clock value of the local node at time t1 is obtained at a time interval not exceeding 2 s.

3. The method for maintaining global consistency of hybrid logical clocks in a distributed cluster according to claim 1, characterized in that, in Step S2, the hybrid logical clock value of the local node at time t2 is equal to the hybrid logical clock value of the local node at time t1 plus 1.

4. The method for maintaining global consistency of hybrid logical clocks in a distributed cluster according to claim 1, characterized in that, in Step S3, calculating the jump value of the physical clock of the local node according to the clock jump type includes: When the local node jumps to the future, the jump value of the physical clock of the local node is equal to the difference between the hybrid logical clock value at time t1 and the physical clock value at time t2; When the local node jumps to the past, the jump value of the physical clock of the local node is equal to the difference between the hybrid logical clock value at time t2 and the physical clock value at time t2.

5. The method for maintaining global consistency of hybrid logical clocks in a distributed cluster according to claim 1, characterized in that, in Step S3, determining whether a time jump occurs according to the jump value includes: when the calculated jump value of the physical clock is greater than 2 s, it is determined that a time jump occurs.

6. An apparatus for maintaining global consistency of hybrid logical clocks in a distributed cluster based on the method for maintaining global consistency of hybrid logical clocks in a distributed cluster according to any one of claims 1-5, the apparatus includes: A hybrid logical clock value acquisition module for acquiring the hybrid logical clock value of the local node at time t1 at a time interval not exceeding 2 s; A physical clock value acquisition module for acquiring the physical clock value of the local node at time t1, the physical clock value of the local node at time t2, and the physical clock value of the local node at time t3; A hybrid logic clock value calculation module, which is used to calculate the hybrid logic clock value of the local node at time t2 based on the hybrid logic clock value of the local node at time t1; A physical clock jump value calculation module, which is used to calculate the jump value of the physical clock of the local node according to the clock jump type, and determine whether a time jump occurs according to the jump value; A hybrid logic clock value update module, which is used to update the hybrid logic clock value of the local node at time t3.

7. The apparatus for maintaining global consistency of hybrid logic clocks in a distributed cluster according to claim 6, wherein, the hybrid logic clock value of the local node at time t2 is equal to the hybrid logic clock value of the local node at time t1 plus 1.

8. The apparatus for maintaining global consistency of hybrid logic clocks in a distributed cluster according to claim 6, wherein, a hybrid logic clock value calculation module, which is used to calculate the jump value of the physical clock of the local node according to the clock jump type, including: when the local node jumps to the future, the jump value of the physical clock of the local node is equal to the difference between the hybrid logic clock value at time t1 and the physical clock value at time t2; when the local node jumps to the past, the jump value of the physical clock of the local node is equal to the difference between the hybrid logic clock value at time t2 and the physical clock value at time t2.

9. The apparatus for maintaining global consistency of hybrid logic clocks in a distributed cluster according to claim 6, wherein, a hybrid logic clock value update module, which is used to sum the physical clock value of the local node at time t3 and the jump value of the physical clock of the local node to obtain a first sum value; perform a summation process of adding 1 to the hybrid logic clock value at time t2 to obtain a second sum value; compare the first sum value with the second sum value, and use the larger value as the hybrid logic clock value at time t3.

Citation Information

Patent Citations

  • Method and device for determining relationship between events in a distributed storage system

    CN108984101A

  • Clock updating method and device, database and computer storage medium

    CN113420034A