A clock synchronization method, a sequence number generation method and apparatus
By obtaining the local time interval of the second device and using the Marzullo algorithm to calculate the intersection, the problem of clock synchronization accuracy loss between devices is solved, achieving high-precision time synchronization and resource saving.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2022-05-24
- Publication Date
- 2026-04-21
AI Technical Summary
In computer systems, clock synchronization between devices suffers from precision loss, especially during multiple synchronization processes, leading to decreased time accuracy and significant network resource overhead.
The first device sends probe messages to the second device to obtain its local time interval, and updates the local time based on multiple time intervals. The Marzullo algorithm is used to calculate the intersection to improve synchronization accuracy, reduce network access, and save resources.
It improves the time synchronization accuracy from the second device to the first device, reduces time and frequency resource overhead, and lowers network response latency.
Smart Images

Figure CN117155499B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a clock synchronization method, a serial number generation method, and an apparatus. Background Technology
[0002] In computer systems, each device maintains an independent clock crystal oscillator. However, the timing accuracy of these crystals varies due to factors such as temperature and voltage. Therefore, clock synchronization is necessary between devices to ensure they have a unified timeline. For example, a clock server is a computer network instrument typically used to obtain the actual time from a clock source device and then transmit this time information to other devices that need clock synchronization, such as database servers, terminals, or smart home devices. In other words, clock synchronization from the clock source device to other devices requires at least two synchronization steps. Compared to the clock source device itself, the accuracy of the clock synchronized from the clock server to other devices requiring synchronization will be lower. Summary of the Invention
[0003] This application aims to provide a clock synchronization method, a serial number generation method, and an apparatus to improve the accuracy of time synchronization from a second device to a first device.
[0004] In a first aspect, a clock synchronization method is provided, applied to a first device, comprising:
[0005] The first device sends a probe message to the second device, the probe message being used to request a first time interval, the first time interval indicating the time range in which the local time of the second device is located;
[0006] The first device receives the first time interval;
[0007] The first device updates its local time based on a first moment, the first device's local time, a second moment, and the first time interval. The first moment is the moment when the first device sends a probe message to the second device, and the second moment is the moment when the first device receives the first time interval.
[0008] In this way, the first device directly obtains the local clock interval of the second device, and then updates its local time based on the time corresponding to the local clock interval received by the second device, the first device's local time, and the local clock interval itself. Since updating the local time by the second device would reduce time accuracy, this clock synchronization method avoids directly using the second device's local time to update the first device's local time, thus improving the accuracy of the clock synchronized to the first device. Furthermore, when synchronizing the clocks of the first and second devices, the first device only needs to receive messages from the second device that send the second device's local time interval, reducing time and frequency resource overhead.
[0009] In one possible implementation, the first device sends multiple probe messages to one or more second devices; the first device receives multiple first time intervals; the first device updates its local time based on multiple first moments, its local time, multiple second moments, and the multiple first time intervals. Thus, multiple first time intervals are obtained based on multiple probe messages, and clock synchronization accuracy is improved by referencing multiple first time intervals together.
[0010] In one possible implementation, the first device updating its local time based on a plurality of first moments, its local time, a plurality of second moments, and the plurality of first time intervals includes: the first device obtaining a second time interval based on the plurality of first moments, its local time, the plurality of second moments, and the plurality of first time intervals, wherein the second time interval is the time range in which the first device's local time falls; and the first device updating its local time based on the second time interval, wherein the updated local time is a moment within the second time interval. Thus, by first determining the possible time range in which the first device's local time might fall based on the plurality of first time intervals, and then updating the first device's local time to a moment within that time range, the accuracy of clock synchronization is improved.
[0011] In one possible implementation, the first device obtaining the second time interval based on a plurality of first moments, the first device's local time, a plurality of second moments, and the plurality of first time intervals includes: the first device obtaining a plurality of third time intervals based on a plurality of first moments, the first device's local time, a plurality of second moments, and the plurality of first time intervals, wherein different third time intervals are reliable time intervals obtained by the first device based on different first time intervals; the first device performing calculations on the plurality of third time intervals to obtain the second time interval, wherein the second time interval is the intersection of at least two third time intervals.
[0012] In one possible implementation, the second time interval is obtained by the first device from the plurality of third time intervals based on the Marzullo algorithm.
[0013] In one possible implementation, the supremum of the plurality of third time intervals is obtained based on the local time of the first device, the plurality of first moments, and the supremum of the plurality of first time intervals; the infimum of the plurality of third time intervals is obtained based on the local time of the first device, the plurality of first moments, and the infimum of the plurality of first time intervals.
[0014] In one possible implementation, the first device is equipped with an operating system that runs the first instance, and the second time interval is cached in the storage space corresponding to the first instance. When time synchronization is required, there is no need to access the physical network card's time again, nor is it necessary to access the backend, such as the database, saving network overhead, saving internal network bandwidth, and resulting in lower response latency.
[0015] In one possible implementation, the operating system of the first device is further used to run a second instance, and the method further includes:
[0016] The second instance obtains the second time interval stored in the storage space corresponding to the first instance;
[0017] The second instance generates a transaction consistency sequence number based on the second time interval or the updated local time of the first device.
[0018] In one possible implementation, the transaction consistency sequence number is generated based on the supremum of the second time interval.
[0019] In one possible implementation, the first device is a database server and the second device is a time server.
[0020] In one possible implementation, the local clock interval of the second device is obtained based on the local time of the second device and multiple sets of second clock data, and the second clock data is obtained based on clock synchronization between the third device and the second device; the second clock data includes: the time when the third device sends a synchronization message to the second device, the time when the second device receives the synchronization message, the time when the second device sends a delay request to the third device, the time when the third device receives the delay request, and the local time of the second device.
[0021] In one possible implementation, when the first device synchronizes its clock with the second device, the second device synchronizes its clock with the clock source device, and the third device is the master clock device. The clock source device may include a GPS receiver for communicating with satellites to obtain the local clock interval of the satellite clock source. The clock source device may also include one or more atomic clocks to prevent inaccurate acquisition of the satellite clock interval due to GPS signal interference. The clock source device may also include a GPS receiver and atomic clocks, communicating with the second device via the atomic clocks when GPS signals are interfered with.
[0022] In one possible implementation, there can be multiple clock source devices with a master-slave relationship. In another possible implementation, there can be multiple clock source devices, and one or more clock source devices can be deployed in different clock domains. Of course, multiple clock source devices can also be deployed in a single clock domain.
[0023] In one possible implementation, the first device is a smart home device, the second device is a mobile terminal, and the third device is a clock server or a base station.
[0024] In one possible implementation, the first device sending probe messages to the second device multiple times can mean that the first device sends probe messages to one second device multiple times, or that the first device sends probe messages to multiple second devices once or multiple times.
[0025] In one possible implementation, the transaction consistency sequence number is generated based on the supremum of the current clock interval (second time interval) of the first device, and the method further includes the first process sleeping when receiving the time fetch request;
[0026] After a preset sleep duration, the first process sends the current clock interval of the first device to the second process.
[0027] In one possible implementation, the preset duration is the difference between the supremum and infimum of the current clock interval of the first device. This ensures that the supremum of the current clock interval of the database server has become a past tense, making the next acquired transaction consistency sequence number larger than the current transaction consistency sequence number; the transaction consistency sequence number provided by the database server is guaranteed to be monotonically non-decreasing, ensuring that the transaction consistency sequence number increases; thus guaranteeing the consistency of the transaction consistency sequence number.
[0028] Secondly, a clock synchronization method is provided, applied to a first device, comprising: the first device receiving a first time interval, the first time interval indicating the time range in which the local time of the second device is located; the first device updating its local time according to its local time, a second moment, and the first time interval, wherein the second moment is the moment when the first device receives the first time interval.
[0029] Optionally, the first device receives multiple first time intervals; the first device updates its local time based on its local time, multiple second times, and multiple first time intervals.
[0030] Optionally, the first device updating its local time based on its local time, multiple second moments, and multiple first time intervals includes: the first device obtaining multiple third time intervals based on its local time, multiple second moments, and multiple first time intervals, wherein different third time intervals are reliable time intervals obtained by the first device based on different first time intervals; the first device calculating a second time interval from the multiple third time intervals, wherein the second time interval is the intersection of at least two third time intervals, and the second time interval is the time range in which the first device's local time is located; and the first device updating its local time based on the second time interval, wherein the updated local time of the first device is the moment in the second time interval.
[0031] Thirdly, a clock synchronization device is provided, which has the function of implementing the clock synchronization method as described in any of the above aspects and any possible implementations thereof. This function can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions.
[0032] Fourthly, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to perform a clock synchronization method as described in any of the foregoing aspects and any possible implementation thereof.
[0033] Fifthly, a computer-readable storage medium is provided that stores computer instructions, which, when executed, implement a clock synchronization method as described in any of the foregoing aspects and any possible implementation thereof.
[0034] In a sixth aspect, a database server is provided, including a clock synchronization device as described in the third aspect. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below.
[0036] Figure 1 This is a schematic diagram of a prior art clock synchronization method according to this application;
[0037] Figure 2 This is a signaling diagram of a prior art clock synchronization method according to this application;
[0038] Figure 3 This is a schematic diagram of a network architecture for clock synchronization in one embodiment of this application;
[0039] Figure 4 This is a signaling diagram of a clock synchronization method in one embodiment of this application;
[0040] Figure 5 Signaling diagram of a clock synchronization method in another embodiment of this application;
[0041] Figure 6 Signaling diagram of a clock synchronization method in another embodiment of this application;
[0042] Figure 7 This is a flowchart of a clock synchronization method in one embodiment of this application;
[0043] Figure 8 This is a flowchart of a clock synchronization method in yet another embodiment of this application;
[0044] Figure 9 This is a schematic diagram illustrating the acquisition of the current clock interval of the database server in one embodiment of this application;
[0045] Figure 10 This is a schematic diagram illustrating the acquisition of the current clock interval of the database server in yet another embodiment of this application;
[0046] Figure 11 This is a schematic diagram illustrating the acquisition of the current clock interval of the database server in another embodiment of this application;
[0047] Figure 12 This is a signaling diagram of a clock synchronization method in one embodiment of this application;
[0048] Figure 13 This is a schematic diagram of a clock synchronization device in one embodiment of this application;
[0049] Figure 14 This is a schematic diagram of a clock synchronization device in another embodiment of this application. Detailed Implementation
[0050] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. The specific operation methods in the method embodiments can also be applied to the device embodiments or system embodiments. In the description of this application, unless otherwise stated, "multiple" means two or more. The terms "first" and "second" in the text do not constitute a limitation on the specific quantity or sequence, but are only for the purpose of distinction and description.
[0051] In the description of this specification, references to terms such as "embodiment," "one embodiment," and "a method of implementation," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or method of implementation is included in at least one embodiment or illustrative embodiment of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or method of implementation. Furthermore, the specific features, methods, or characteristics described may be combined in any suitable manner in one or more embodiments or methods of implementation.
[0052] The architecture and business scenarios described in this application are intended to more clearly illustrate the technical solutions of this application and do not constitute a limitation on the technical solutions provided in this application. As network architectures evolve and new business scenarios emerge, the technical solutions provided in this application are also applicable to similar technical problems.
[0053] A clock source device can act as a master clock, providing time synchronization services to slave clocks. The clock source device may include a GPS receiver for communicating with satellites to obtain the local clock interval of the satellite clock source. The clock source device may also include one or more atomic clocks to prevent inaccuracies in the obtained satellite clock interval due to GPS signal interference. The clock source device may also include both a GPS receiver and atomic clocks, communicating with a clock server via the atomic clocks when GPS signals are interfered with. For example, the clock source device can synchronize time with a clock server.
[0054] A clock server, also known as a time server, is a computer network instrument that obtains the actual time from a reference clock and then transmits the time information to users via a computer network. For example, the clock referenced by the time server could be provided by another time server, a connected atomic clock, or a radio clock. A clock server can also provide time synchronization to terminals or database servers.
[0055] A process is a single execution of a program on a specific set of data in a computer. It is the basic unit for resource allocation and scheduling in a system and forms the foundation of the operating system structure. A process can be the basic execution entity of a program. A program is a description of instructions, data, and their organization; a process is the physical entity of a program. A process can be the basic unit of dynamic execution by the operating system, and it can also be the basic unit of resource allocation.
[0056] A probe message is a probe message used in this application to request the local clock interval of a clock server.
[0057] A response message is a type of message; in this application, a response message indicates the local clock interval of the clock server.
[0058] A clock interval, also known as a time interval, can be, for example, a first time interval indicating the time range in which the local time of a second device is located, and is used to update the local time of the second device. Conversely, a second time interval might be the time range in which the local time of the first device is located, and is used to update the local time of the first device. Here, the second device can be a clock server, and the first time interval is the time interval used to update the local time of the clock server. This first time interval is obtained by the clock server and the clock source device through interaction based on the NTP or PTP protocol.
[0059] like Figure 1 As shown, Figure 1 This diagram illustrates a network clock synchronization method. A client initiates a query request at 12:00:00 and receives a message from the server two seconds later, also returning 12:00:00. This does not mean the local clock is accurate, as it takes time for the message to reach the server. The local clock is actually faster than the server's clock, but the exact difference is unclear. We are certain that the time from when the local device sends the message to when it receives it is 2 seconds, but the time from when the message is sent to when it is received by the server, and the time from when the server sends its response to when the message is received by the local device, are unknown. Therefore, we move the time back one second, resulting in an error range of ±1 second. This network clock synchronization method has relatively low accuracy.
[0060] like Figure 2 As shown, Figure 2This is a flowchart illustrating a clock synchronization method. The process involves communication between network devices and terminal devices. The network device corresponds to the master clock node, and the terminal device corresponds to the slave clock node. The master clock node has an external clock module, such as an atomic clock or a Global Positioning System (GPS), or it can be calibrated with an external clock to obtain high-precision absolute time. During communication with the master clock node, the slave clock node calculates the clock deviation of its local clock relative to the master clock node and corrects its local clock based on this deviation to ensure synchronization. The following detailed explanation uses a base station as the master clock node and the terminal device as the slave clock node as an example. Figure 1 The clock synchronization method shown includes the following steps:
[0061] Step S21: The master clock node sends a notification message to the slave clock node.
[0062] Specifically, the master clock node can be the best clock source selected from the network. After the master clock node is selected, it can send a notification message to the slave clock nodes to notify them that it is the master clock node.
[0063] Step S22: The master clock node sends a synchronization message to the slave clock node. The master clock node records the sending time t1 of the synchronization message according to the master clock. When the slave clock node receives the synchronization message, it records the receiving time t2 of the synchronization message according to the slave clock.
[0064] Step S23: The master clock node sends a follow-up message to the slave clock node. The follow-up message carries timestamp information t1, which is the time when the synchronization message was sent.
[0065] Step S24: The slave clock node sends a delay request message (Delay_Req Message) to the master clock node. The slave clock node records the sending time t3 of the delay request message according to the slave clock. When the master clock node receives the delay request message, it records the receiving time t4 of the delay request message according to the master clock.
[0066] Step S25: The master clock node sends a delay request message (Delay_ResponseMessage) to the slave clock node. The delay request message carries timestamp information t4, which is the time when the delay request message was received.
[0067] Step S26: Calculate the clock deviation from the clock node and correct the timing of the local clock.
[0068] Specifically, the slave clock node calculates the clock offset relative to the master clock node based on the sending time t1 of the synchronization message, the receiving time t2 of the synchronization message, the sending time t3 of the delay request message, and the receiving time t4 of the delay request message. This clock offset is denoted as Offset. The relationship between Offset, t1, t2, t3, and t4 is as follows:
[0069]
[0070] Additionally, the slave clock node can calculate the transmission delay (Delay) from the master clock node to the slave clock node using t1, t2, t3, and t4. The formula for calculating Delay is as follows:
[0071]
[0072] After calculating the clock deviation from the master clock node, the timing of the slave clock node's local clock is further corrected based on the clock deviation, so that the slave clock node's local clock is kept in high-precision synchronization with the master clock node's clock, thereby keeping the slave clock node's local clock in high-precision synchronization with absolute time.
[0073] like Figure 2 As shown, steps S22 to S26 can be considered as a clock synchronization process. In this process, the base station needs to send two timestamp messages to the terminal device: one is the timestamp t1 carried in the follow message, and the other is the timestamp t4 carried in the delay request message. The base station needs to obtain the clock from the satellite, then perform clock synchronization, update the base station's local time, and then interact with the terminal to synchronize the terminal's clock. Compared to the satellite, the accuracy of the clock synchronized from the satellite to the terminal is lower. In addition, the base station needs to send a follow message after sending the synchronization message. If the base station corresponds to multiple terminal devices, after sending the synchronization message to each terminal device, the base station also needs to send a follow message to each terminal device. Therefore, the base station needs to configure time and frequency resources for sending the synchronization message and the follow message, and schedule the time and frequency resources. When the base station corresponds to a large number of terminal devices, it will lead to a large overhead of time and frequency resources in the network and increase the complexity of the base station's time and frequency resource scheduling.
[0074] like Figure 3 As shown, Figure 3This diagram illustrates a possible network architecture applicable to embodiments of the present application, including a clock source device 102, one or more clock servers 103, and one or more database servers 104. The clock source device 102 is communicatively connected to each clock server 103, and each clock server 103 is communicatively connected to each database server 104. One clock source device can communicate with multiple clock servers simultaneously, and one clock server 103 can communicate with multiple database servers 104 simultaneously. A distributed database 1041, such as GaussDB, can be deployed in the database servers.
[0075] In one embodiment, clock source devices 102 can be deployed in different clock domains. In another embodiment, multiple clock source devices 102 can be deployed in the same clock domain to avoid increased network pressure caused by a single clock source device 102. In one embodiment of this application, clock source device 102 may include a GPS receiver for communicating with satellite 101 to obtain the local clock interval of satellite 101. In one embodiment, clock source device 102 may include one or more atomic clocks to prevent inaccurate acquisition of the clock interval of satellite 101 due to GPS signal interference. In one embodiment, clock source device 102 may include a GPS receiver and an atomic clock, communicating with clock server 103 via the atomic clock when GPS signal interference occurs.
[0076] In one embodiment of this application, multiple time servers can be deployed in the same data center. In another embodiment of this application, multiple event servers can be deployed in the same time domain.
[0077] In one embodiment, the first device may be a database server, and the second device may be a time server. In another embodiment, the first device may be a smart home device, and the second device may be a terminal.
[0078] A terminal is a device with wireless transceiver capabilities. Terminals can be deployed on land, including indoors or outdoors, handheld or vehicle-mounted; they can also be deployed on water (such as on ships); and they can be deployed in the air (such as on airplanes, balloons, and satellites). The terminal can be a mobile phone, tablet, computer with wireless transceiver capabilities, virtual reality (VR) terminal, augmented reality (AR) terminal, wireless terminal in industrial control, wireless terminal in self-driving, wireless terminal in remote medical care, wireless terminal in smart grid, wireless terminal in transportation safety, wireless terminal in smart city, wireless terminal in smart home, and may also include user equipment (UE), etc. The terminal can also be a cellular phone, cordless phone, session initiation protocol (SIP) phone, wireless local loop (WLL) station, personal digital assistant (PDA), handheld device with wireless communication capabilities, computing device or other processing device connected to a wireless modem, vehicle-mounted device, wearable device, terminal device in the future 5G network, or terminal device in the future evolved public land mobile network (PLMN), etc. The terminal may also be referred to as terminal equipment, user equipment (UE), access terminal equipment, vehicle-mounted terminal, industrial control terminal, UE unit, UE station, mobile station, mobile station, remote station, remote terminal equipment, mobile device, UE terminal equipment, terminal equipment, wireless communication equipment, UE agent, or UE device, etc. The terminal can be fixed or mobile. This application embodiment does not limit this.
[0079] Smart home devices include, but are not limited to: smart desk lamps, smart sockets, smart switches, gateways, door and window sensors, curtain controllers, temperature and humidity sensors, smart speakers, and smart robot vacuums.
[0080] This explanation uses the example of the first device being a database server and the second device being a time server. Figures 4-6 As shown, Figure 4A signaling diagram for a clock synchronization method provided in this application. The clock synchronization method described in this embodiment includes the following steps:
[0081] like Figure 8 As shown, in step S411: the database server sends a probe message to the clock server and records the first moment of each probe message transmission. The probe message is used to request a first time interval, which indicates the time range in which the local time of the second device is located.
[0082] In one implementation, there can be multiple database servers and one clock server. Multiple database servers synchronize with the same clock server, and each database server sends probe messages to the same clock server multiple times. In another implementation, the database server may send a probe message to the clock server at fixed intervals, such as every 10 milliseconds or 15 milliseconds.
[0083] In one implementation, the database server sends multiple probe messages to multiple clock servers. That is, there can be multiple clock servers, and a single database server can simultaneously synchronize its clock with multiple clock servers in a clock domain. For example, the database server can send probe messages to multiple clock servers simultaneously. In another implementation, one or more clock servers can be deployed in different clock domains. The time in other clock domains simply needs to be converted to the time in the current clock domain. This conversion can be performed when the clock source device sends a message or when the clock server receives the time. The database server simultaneously sends probe messages to clock servers in different clock domains. Since the clock crystals in different clock domains have different offsets, resulting in different clock accuracies, the clocks from different clock domains can be used as a reference to improve clock accuracy.
[0084] Optionally, the local clock interval of the clock server is obtained based on multiple sets of second clock data, which include: the time when the clock source device sends a synchronization message to the clock server, the time when the clock server receives the synchronization message, the time when the clock server sends a delay request to the clock source device, the time when the clock source device receives the delay request, and the local time of the clock server.
[0085] Step S412: The clock server obtains its local clock interval (first time interval) based on its local time and one or more sets of second clock data. The second clock data includes: the time when the clock source device sends a synchronization message to the clock server, the time when the clock server receives the synchronization message, the time when the clock server sends a delay request to the clock source device, the time when the clock source device receives the delay request, and the clock server's local time. A clock interval is a time range. The first time interval can be obtained through interaction between the clock server and the clock source device based on the NTP or PTP protocol. The second clock data represents the times of message transmission and reception during the interaction between the clock server and the clock source device.
[0086] In one implementation, such as Figure 4 , Figure 6 and Figure 7 As shown, the acquisition of the second clock data may include the following method: Step S401: The clock source device sends a synchronization message to the clock server, the synchronization message indicating the time of sending the synchronization message. Step S402: After receiving the synchronization message, the clock server will obtain the local time by reading the network card timestamp. The clock server sends a delay request to the clock source device and records the time when the delay request was sent. Step S403: After receiving the delay request, the clock source device obtains the network card time of the clock source device at this time. The clock source device sends a delay response to the clock server, the delay response indicating the time when the clock source device received the delay request; steps S401-S403 are repeated every preset duration. The second clock data may include... and
[0087] In one implementation, according to the PTP protocol, the clock source device periodically broadcasts Sync messages, and immediately follows each Sync message with a follow-up message to return the network interface card (NIC) timestamp from when the Sync message was sent. The Sync or follow-up message from the clock source device carries the timestamp from when the message was sent. Upon receiving the sync message, the clock server obtains the local timestamp by reading the network card timestamp. At the same time, the clock server immediately sends a delay request message to the clock source, and simultaneously obtains the network card timestamp. In the subsequent delay-response message, the network interface card timestamp of the moment the clock source device receives the delay request message can be obtained. The second clock data may include and
[0088] Optionally, the clock server obtains a set of second clock data every preset interval; the preset interval can be 15 milliseconds, 10 milliseconds, 5 milliseconds, etc. In other words, the clock server obtains a set of second clock data every preset interval. Where j represents the number of the clock source device, for example, the number j of the first clock source device is 1, and the number j of the second clock source device is 2; i represents the number of the second clock data, for example, the number of the second clock data of the first clock source device can be 1, 2, 3, etc., and the number of the second clock data of the second clock source device can also be 1, 2, 3, etc. Of course, there is no limitation on how to number them here; the numbering is only to distinguish different clock data. Here, we take... Let's take an example to illustrate. This refers to the moment when the first clock source device sends the first Sync message or the first follow-up message.
[0089] Optionally, the clock server can continuously acquire second clock data, but it can also save only the latest two or more sets of second clock data. In one implementation, when the clock server interacts with multiple clock source devices, it can save one or more sets of the latest second clock data obtained from interactions with each clock source device.
[0090] In one implementation, there can be multiple clock source devices with a master-slave relationship. In another implementation, there can be multiple clock source devices, and one or more clock source devices can be deployed in different clock domains. Of course, multiple clock source devices can also be deployed in a single clock domain.
[0091] Optionally, when the clock server receives a probe message, it obtains the local clock interval of the clock server based on the local time of the clock server and the latest set or more sets of second clock data. Here, the local clock interval of the clock server is the interval calculated by the clock server that includes the precise time of the clock source device.
[0092] At a certain point in time, the local time of the clock server is T. S At this time, the precise time of the corresponding clock source device is T. P In order to synchronize the time of the clock server with the time of the clock source device, the clock server estimates the time of the clock source device based on... Figure 7 It can be known that:
[0093]
[0094] The clock interval of the clock server is obtained as follows:
[0095]
[0096] Wherein, ∈1 represents the clock crystal drift speed of the clock server. For example, the clock crystal drift speed can be 50ppm, 100ppm, 150ppm, or 50 microseconds / second, 100 microseconds / second, and 200 microseconds / second.
[0097] Because there are multiple sets of second clock data, multiple clock intervals of the clock server can be obtained.
[0098] For example:
[0099]
[0100] Here, based on the Marzullo algorithm, the local clock interval of the clock server is obtained from multiple clock intervals of the clock server.
[0101] In one implementation, the local clock interval of the clock server is the intersection of multiple clock intervals of the clock server; for example, such as Figure 9 As shown, the clock server has multiple clock intervals of [8,12], [11,13] and [10,12], respectively; therefore, the local clock interval of the clock server is [11,12].
[0102] In one implementation, when there is no common intersection among the multiple clock intervals of the clock server, the local clock interval of the clock server is the intersection of the clock intervals of the multiple clock servers that do have intersection. For example, as... Figure 10 As shown, the clock ranges of the clock server are [8,12], [11,13] and [14,15], respectively; therefore, the local clock range of the clock server is [11,12].
[0103] In one implementation, when the clock intervals of multiple clock servers intersect, the local clock interval of a clock server is the intersection of the clock intervals of the clock server with the largest number of corresponding intersections. In another implementation, when the clock intervals of multiple clock servers intersect, and the number of clock intervals corresponding to each intersection is equal, the local clock interval of the clock server is the intersection with the largest range. For example, as... Figure 11 As shown, the clock server has multiple clock intervals of [8,12], [8,9] and [10,12], respectively; therefore, the local clock interval of the clock server is [10,12].
[0104] Step S413: The clock server sends its local clock interval (first time interval) to the database server. The first time interval can be carried in a message; for example, the clock server sends a message to the database server containing the first time interval. That is, the clock server does not directly send the specific time to the database server each time, but instead sends its calculated local clock interval (first time interval). Of course, this does not affect the updating of the clock server's local time. The clock server can update its local time separately.
[0105] like Figure 8 As shown, in step S414: the database server receives the first time interval and records the second moment when the database server receives the first time interval.
[0106] In one implementation, the database server sends a probe message to a clock server, and the database server receives a first time interval. In another implementation, the database server sends multiple probe messages to a clock server, and the database server receives multiple different first time intervals. In yet another implementation, the database server sends multiple probe messages to multiple clock servers, and the database server receives multiple different first time intervals.
[0107] Here, the database server can send a probe message to the clock server at fixed intervals, such as every 10 milliseconds or 15 milliseconds. After sending the probe message, the database server will receive the first time interval. The time when the database server receives the first time interval can be before, after, or at the same time as the next time the database server sends a probe message; there is no strict order between the two.
[0108] Step S415: The database server updates its local time based on the first moment, the database server's local time, the second moment, and the first time interval.
[0109] Here, the local time of the database server before the update can be the time that triggered the clock synchronization or the current time of the database server. Since there is a certain time difference when the program is executed, there is no restriction on the local time of the database server before the update. It can be any time of the database server before the update. Of course, the closer the time before the update is to the real time, the higher the accuracy of the clock synchronization.
[0110] In one implementation, the updated local time of the database server can be any time within the following range.
[0111]
[0112] Where ∈2 represents the clock crystal drift of the database server, i∈n, j∈m; for example, the clock crystal drift speed can be 50ppm, 100ppm, 150ppm, or 50 microseconds / second, 100 microseconds / second, and 200 microseconds / second. The local time of the database server is T. c At this time, the precise time of the corresponding clock source device is T. P ; The first moment when the database server sends a probe message, The database server receives the data at the second moment of the first time interval, where the first time interval is...
[0113] In one implementation, step S415 includes:
[0114] Step S4151: The database server obtains the second time interval based on multiple first moments, the local time of the first device, multiple second moments, and multiple first time intervals. The second time interval is the time range in which the local time of the database server is located. The second time interval can also be understood as the time range in which the real time is located. The real time refers to the local time of the clock source device.
[0115] In one implementation, step S4151 may include:
[0116] Step S4251: The first device obtains multiple third time intervals based on multiple first moments, the local time of the first device, multiple second moments, and the multiple first time intervals. Different third time intervals are reliable time intervals obtained by the first device based on different first time intervals. Here, a reliable time interval refers to the time range in which the real time is most likely to be. Different first time intervals can correspond to different third time intervals.
[0117] The database server obtains multiple first clock intervals based on its local time and multiple sets of first clock data. These multiple first clock intervals are multiple time intervals containing multiple real times. Here, real time refers to the time of the clock source device, and the multiple real times indicate the time of different clock source devices, or the real time of the same clock source device at different times.
[0118] like Figure 8 As shown, the first clock data includes the first moment when the database server sends the probe message. The database server receives the second moment of the first time interval. and the first time interval Where m represents the number of the first clock data corresponding to each clock server. For example, the number of the first clock data corresponding to the first clock server can be 1, 2, 3, etc., and the number of the first clock data corresponding to the second clock server can also be 1, 2, 3, etc.; n represents the number of the clock server. For example, the number n of the first clock server is 1, and the number n of the second clock server is 2. Of course, there is no restriction on how to number them here; the numbering is only to distinguish different clock data. Here, we take... Let's take an example to illustrate. This refers to the very first moment when the database server sends the first probe message to the first clock server.
[0119] In one implementation, the database server can continuously obtain the first clock data, but the database server can only store the latest two or more sets of the first clock data.
[0120] At a certain point in time, the local time of the database server is T. c At this time, the precise time of the corresponding clock source device is T. P In other words, the actual time, due to errors introduced by the transmission protocol, means the clock server can only calculate the interval containing the actual time, but cannot obtain the actual time. To synchronize the database server's time with the time of the clock source device, the database server estimates the time of the clock source device based on... Figure 8 It can be seen that the third time interval is:
[0121]
[0122] Where ∈2 represents the clock crystal drift of the database server, i∈n, j∈m; for example, the clock crystal drift speed can be 50ppm, 100ppm, 150ppm, or 50 microseconds / second, 100 microseconds / second and 200 microseconds / second.
[0123] In other words, the supremum of the first time interval is obtained based on the local time of the first device, the time corresponding to the first device sending multiple probe messages, and the supremum of the local clock interval; the infimum of the first time interval is obtained based on the local time of the first device, the time corresponding to the first device receiving the local clock interval, and the infimum of the local clock interval.
[0124] Step S4151 further includes step S4252: the first device calculates a second time interval from multiple third time intervals, the second time interval being the intersection of at least two third time intervals.
[0125] The database server can use the Marzullo algorithm to calculate the current clock interval of the database server from the multiple first clock intervals.
[0126] In one implementation, the current clock interval (second time interval) of the database server is the intersection of multiple third time intervals; for example, such as Figure 9 As shown, the multiple third time intervals are [8,12], [11,13] and [10,12]; therefore, the current clock interval of the database server is [11,12].
[0127] In one implementation, when there is no common intersection among multiple third time intervals, the current clock interval (second time interval) of the database server is the intersection of multiple intersecting third time intervals. For example, as... Figure 10 As shown, the multiple third time intervals are [8,12], [11,13] and [14,15]; therefore, the current clock interval of the database server is [11,12].
[0128] In one implementation, when multiple overlapping third time intervals have multiple intersections, the current clock interval (second time interval) of the database server is the intersection of the third time intervals with the largest number of intersections. In another implementation, when multiple overlapping third time intervals have multiple intersections, and the number of third time intervals corresponding to each intersection is equal, the current clock interval (second time interval) of the database server is the intersection with the largest range. For example, such as... Figure 11 As shown, the multiple third time intervals are [8,12], [8,9] and [10,12]; therefore, the current clock interval of the database server is [10,12].
[0129] In one implementation, the database server is equipped with an operating system, which runs a first instance and a second instance. The current clock interval (second time interval) of the first device is cached in the first instance. For example, the first instance can be a process or a thread, such as a clock process or a thread within a clock process. When the second process needs to synchronize time, it does not need to access the physical network card's time again, nor does it need to access the backend, such as the database, saving network overhead, saving internal network bandwidth, and resulting in lower response latency.
[0130] For example, the first instance is a clock process, and the second instance can be a thread within an application process. The second instance can be the application process or other processes requiring clock synchronization, such as a database process. The database, as an application deployed on a database server, can store its clock data in the storage space corresponding to the clock process. The database process and the clock process communicate via TCP. The database process periodically sends a time retrieval request to the clock process, and the clock process sends its clock data to the database process. In one implementation, the local clock interval of the database server is cached in the storage space corresponding to the first process. When the second process needs to retrieve time, it directly retrieves the time from the storage space corresponding to the first process. This storage space can be a shared storage space for both the first and second processes.
[0131] Optionally, the operating system of the first device is further used to run a second process, and the method further includes: the second process sending a timing request to the first process; the first process receiving the timing request and sending the current clock interval of the first device to the second process; and the second process receiving the current clock interval of the first device sent by the first process.
[0132] Optionally, when the first process receives a time fetch request, the database server obtains the current clock interval of the database server based on the plurality of first clock intervals, and stores the current clock interval of the database server in the clock process.
[0133] Optionally, the multiple sets of first clock data are multiple sets of first clock data closest to the third time point; the third time point is the time when the first process receives the time request. Alternatively, the first clock interval is the clock interval closest to the third time point.
[0134] Step S4152: The database server updates its local time according to the second time interval, and the updated local time of the first device is the time in the second time interval.
[0135] In one implementation, the local time of the database server can be updated to the upper bound of the current clock interval (second time interval) of the database server, ensuring that the time provided by the database server is monotonically non-decreasing and that the timestamp does not roll back. In another implementation, the local time of the first device can be updated to the lower bound of the current clock interval of the database server or any value within the current clock interval (second time interval) of the database server.
[0136] Compared to traditional clock synchronization methods, the clock synchronization method described in this embodiment involves the database server directly obtaining its local clock interval from the time server. Then, it updates the database server's local time based on the time corresponding to the local clock interval received by the time server, the database server's local time, and the local clock interval itself. Since updating the local time by the time server can reduce time accuracy, this clock synchronization method avoids directly using the time server's local time to update the database server's local time, thus improving the accuracy of the clock synchronized to the database server. Furthermore, during clock synchronization between the database server and the time server, the database server only needs to receive messages from the time server sending its local time interval, reducing time-frequency resource overhead.
[0137] In one embodiment of this application, the terminal can also synchronize its clock with the clock server using the same clock synchronization method. For details, refer to the clock synchronization method of the database server and the clock server, which will not be repeated here.
[0138] In one embodiment of this application, the smart home device can also synchronize its clock with the terminal using the same clock synchronization method. The terminal transmits its local time interval to the smart home device. The local time interval of the terminal is obtained by synchronizing the clock of the terminal and the clock server or base station. The specific method is similar to the clock synchronization method between the terminal and the clock server in the previous embodiment.
[0139] In high-concurrency scenarios, a typical metric for measuring database transaction processing capabilities is the number of transactions processed per second. However, databases have strict requirements for Atomicity, Consistency, Isolation, and Durability. Conflicts caused by concurrent reads and writes cannot be resolved simply by using locks; otherwise, transaction processing performance will be significantly reduced. Therefore, mainstream databases use MVCC (Multi-Version Concurrency Control) to achieve read-write isolation and avoid data concurrency blocking caused by locks. In simple terms, MVCC determines data visibility by storing historical versions of data and comparing version numbers. The challenge then becomes how to provide the database with a globally incrementing version number, i.e., a consistent sequence number.
[0140] In one embodiment of this application, the clock synchronization method further includes: the second instance obtaining the second time interval stored in the storage space corresponding to the first instance; the second instance generating a transaction consistency sequence number based on the second time interval or the updated local time of the first device.
[0141] Taking a database as an example, the current clock interval of the database server is stored in the storage space corresponding to the clock process. When the database needs to generate a transaction consistency sequence number, the database process sends a time fetch message to the clock process to request the current clock interval of the database server, or the database process directly reads the shared memory space to obtain the current clock interval of the database server.
[0142] In one embodiment, the sequence number can be generated based on the supremum of the current clock interval of the database server. In another embodiment, the sequence number can be generated based on the infimum of the current clock interval of the database server or any value within the current clock interval of the database server.
[0143] When the sequence number is generated based on the supremum of the current clock interval of the database server, the method further includes the first instance going into sleep mode upon receiving the time request; the first instance sending the current clock interval of the database server to the second instance after a preset sleep duration. Alternatively, the second instance may also go into sleep mode upon receiving the current clock interval of the database server.
[0144] Optionally, the preset duration of the hibernation is greater than or equal to the difference between the supremum and infimum of the current clock interval of the database server. This ensures that the supremum of the current clock interval of the database server has become a past tense, making the next acquired sequence number larger than the current sequence number; the sequence number provided by the database server is guaranteed to be monotonically non-decreasing, ensuring sequence number increment; and the consistency of the sequence number is guaranteed.
[0145] In one embodiment of this application, the clock synchronization method described above is also applicable to terminals or smart home devices, and will not be repeated here.
[0146] One embodiment of this application provides a clock synchronization device, such as... Figure 13 As shown, it is applied to the first device and includes:
[0147] Sending module 131 is used to send a probe message to the second device, the probe message being used to request a first time interval, the first time interval indicating the time range in which the local time of the second device is located;
[0148] Receiver module 132 is used to receive the first time interval;
[0149] The calculation module 133 is used to update the local time of the first device according to the first moment, the local time of the first device, the second moment, and the first time interval, wherein the second moment is the moment when the first device receives the first time interval, and the first moment is the moment when the first device sends a probe message to the second device.
[0150] This embodiment provides a clock synchronization device that implements the clock synchronization methods described in the above embodiments. This function can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, which will not be elaborated further here.
[0151] This embodiment provides a clock synchronization method, which includes the following steps:
[0152] like Figure 12 As shown, in step S511: the second device obtains the local clock interval (first time interval) of the clock server based on the local time of the clock server and one or more sets of second clock data. The content of step S511 is the same as that of step S412. Steps S501-S503 are the same as those of steps S401-S403, and will not be described again here.
[0153] Step S512: The clock server sends the first time interval to the database server. The content of step S512 is the same as that of step S413, and will not be repeated here.
[0154] Step S513: The database server receives the first time interval. The first time interval indicates the time range in which the local time of the clock server is located; the content of step S513 is the same as that of step S414, and will not be repeated here.
[0155] Here, the first time interval received is the same as that involved in the previous embodiment, and will not be repeated here. The difference is that the clock server can actively send the first time interval to the database server, and the database server updates its local time after receiving the first time interval.
[0156] Step S514: The database server uses the local time T of the first device. c Second moment and the first time interval Update the local time of the database server; the second time interval is the time when the database server receives the data from the first time interval.
[0157] Here, the local time of the database server before the update can be the time that triggered the clock synchronization or the current time of the database server. Since there is a certain time difference when the program is executed, there is no restriction on the local time of the database server before the update. It can be any time of the database server before the update. Of course, the closer the time before the update is to the real time, the higher the accuracy of the clock synchronization.
[0158] In one implementation, the updated local time of the database server can be T as follows: p Any time within the specified interval.
[0159]
[0160] Where ∈2 represents the clock crystal drift of the database server, i∈n, j∈m; for example, the clock crystal drift speed can be 50ppm, 100ppm, 150ppm, or 50 microseconds / second, 100 microseconds / second and 200 microseconds / second.
[0161] When the first device receives multiple first time intervals, the first device updates its local time based on its local time, multiple second times, and multiple first time intervals.
[0162] In one implementation, updating the local time of the first device based on the local time of the first device, a plurality of second moments, and a plurality of first time intervals includes:
[0163] Step S5141: The first device obtains multiple third time intervals based on its local time, multiple second moments, and multiple first time intervals. Different third time intervals are reliable time intervals obtained by the first device based on different first time intervals. The third time intervals can be:
[0164]
[0165]
[0166] Where m represents the number of the first clock data corresponding to each clock server. For example, the number of the first clock data corresponding to the first clock server can be 1, 2, 3, etc., and the number of the first clock data corresponding to the second clock server can also be 1, 2, 3, etc.; n represents the number of the clock server. For example, the number n of the first clock server is 1, and the number n of the second clock server is 2. Of course, there is no restriction on how to number them here; the numbering is only to distinguish different clock data.
[0167] Step S5142: The first device calculates a second time interval from multiple third time intervals. The second time interval is the intersection of at least two third time intervals and is the time range in which the local time of the first device is located. Step S5142 is similar to the content of step S4252 and will not be repeated here.
[0168] Step S5143: The first device updates its local time according to the second time interval. The updated local time of the first device is the time within the second time interval. Step S5143 is similar to step S4152 and will not be described again here.
[0169] This embodiment provides a clock synchronization device that implements the clock synchronization methods described in the above embodiments. This function can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions.
[0170] One embodiment of this application provides a clock synchronization device, such as... Figure 14 As shown, it is applied to the first device and includes:
[0171] The receiving module 141 is used to receive a first time interval, which indicates the time range in which the local time of the second device is located.
[0172] The calculation module 142 is used to update the local time of the first device according to the local time of the first device, the second moment, and the first time interval, wherein the second moment is the moment when the first device receives the first time interval.
[0173] One embodiment of this application provides a clock synchronization device that implements the clock synchronization method as described in any of the above embodiments. This function can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above function, which will not be elaborated further here.
[0174] One embodiment of this application provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to perform a clock synchronization method as described in any of the above embodiments.
[0175] One embodiment of this application provides a computer-readable storage medium storing computer instructions that, when executed, implement the clock synchronization method as described in any of the above embodiments. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state drive).
[0176] One embodiment of this application provides a database server including a clock synchronization device as described in any of the above embodiments.
[0177] One embodiment of this application provides a terminal including a clock synchronization device as described in any of the above embodiments.
[0178] One embodiment of this application provides a smart home device, including the clock synchronization device described above.
[0179] One embodiment of this application provides a computer program product that, when executed by a computer, causes a processor or computer to perform the corresponding steps and / or processes in the above method embodiments.
[0180] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means.
[0181] Although this application has been described in conjunction with specific features and embodiments, it is obvious that various modifications and combinations can be made thereto without departing from the spirit and scope of this application. Accordingly, this specification and drawings are merely illustrative descriptions of the application as defined by the appended claims, and are considered to cover any and all modifications, variations, combinations, or equivalents within the scope of this application. Clearly, those skilled in the art can make various alterations and modifications to this application without departing from its scope. Thus, if such modifications and modifications fall within the scope of the claims and their equivalents, this application is also intended to include such modifications and modifications.
Claims
1. A clock synchronization method, characterized in that, Applied to the first device, including: The first device sends a probe message to the second device, the probe message being used to request a first time interval, the first time interval indicating the time range in which the local time of the second device is located; The first device receives the first time interval; The first device updates its local time based on a first moment, the first device's local time, a second moment, and the first time interval. The first moment is the moment when the first device sends a probe message to the second device, and the second moment is the moment when the first device receives the first time interval.
2. The clock synchronization method according to claim 1, characterized in that, The first device sends multiple probe messages to one or more second devices; The first device receives multiple first time intervals; The first device updates its local time based on multiple first moments, the first device's local time, multiple second moments, and the multiple first time intervals.
3. The clock synchronization method of claim 2, wherein, The first device updates its local time based on multiple first moments, the first device's local time, multiple second moments, and the multiple first time intervals, including: The first device obtains a second time interval based on multiple first moments, the local time of the first device, multiple second moments, and the multiple first time intervals. The second time interval is the time range in which the local time of the first device is located. The first device updates its local time according to the second time interval, and the updated local time of the first device is the time in the second time interval.
4. The clock synchronization method of claim 3, wherein, The first device obtains the second time interval based on multiple first moments, the local time of the first device, multiple second moments, and the multiple first time intervals, including: The first device obtains multiple third time intervals based on multiple first moments, the local time of the first device, multiple second moments, and the multiple first time intervals. Different third time intervals are reliable time intervals obtained by the first device based on different first time intervals. The first device performs calculations on the plurality of third time intervals to obtain the second time interval, wherein the second time interval is the intersection of at least two third time intervals.
5. The clock synchronization method of claim 4, wherein, The second time interval is obtained by the first device from the calculation of the multiple third time intervals based on the Marzullo algorithm.
6. The clock synchronization method of claim 5, wherein, The supremacy of the plurality of third time intervals is obtained based on the local time of the first device, the plurality of first moments, and the supremacy of the plurality of first time intervals; The infimum of the plurality of third time intervals is obtained based on the local time of the first device, the plurality of first moments, and the infimum of the plurality of first time intervals.
7. The clock synchronization method of claim 6, wherein, The first device has an operating system installed, and the operating system of the first device is used to run the first instance. The second time interval is cached in the storage space corresponding to the first instance.
8. The clock synchronization method of claim 7, wherein, The operating system of the first device is also used to run a second instance, and the method further includes: The second instance obtains the second time interval stored in the storage space corresponding to the first instance; The second instance generates a transaction consistency sequence number based on the second time interval or the updated local time of the first device.
9. The clock synchronization method of claim 8, wherein, The transaction consistency sequence number is generated based on the supremum of the second time interval.
10. The clock synchronization method according to any one of claims 1 to 9, characterized in that, The first device is a database server, and the second device is a time server.
11. A clock synchronization method, characterized by, Applied to the first device, including: The first device receives a first time interval, which indicates the time range in which the local time of the second device is located. The first device updates its local time based on its local time, a second moment, and the first time interval, where the second moment is the moment when the first device receives the first time interval.
12. The clock synchronization method of claim 11, wherein, The first device receives multiple first time intervals; The first device updates its local time based on its local time, a plurality of second moments, and the plurality of first time intervals.
13. The clock synchronization method of claim 12, wherein, The first device updates its local time based on its local time, multiple second moments, and the multiple first time intervals, including: The first device obtains multiple third time intervals based on the local time of the first device, the multiple second moments, and the multiple first time intervals. Different third time intervals are reliable time intervals obtained by the first device based on different first time intervals. The first device calculates a second time interval from the plurality of third time intervals, the second time interval being the intersection of at least two third time intervals, and the second time interval being the time range in which the local time of the first device is located; The first device updates its local time according to the second time interval, and the updated local time of the first device is the time in the second time interval.
14. A clock synchronization apparatus characterized by comprising: Applied to the first device, including: The sending module is used to send a probe message to the second device, the probe message being used to request a first time interval, the first time interval indicating the time range in which the local time of the second device is located; The receiving module is used to receive the first time interval; The calculation module is used to update the local time of the first device based on a first moment, the local time of the first device, a second moment, and the first time interval, wherein the second moment is the moment when the first device receives the first time interval, and the first moment is the moment when the first device sends a probe message to the second device.
15. The clock synchronization device according to claim 14, characterized in that, The sending module is used to send multiple probe messages to one or more second devices; The receiving module is used to receive multiple first time intervals; The calculation module is used to update the local time of the first device based on multiple first moments, the local time of the first device, multiple second moments, and the multiple first time intervals.
16. The clock synchronization apparatus of claim 15, wherein, The calculation module is further configured to obtain a second time interval based on a plurality of first moments, the local time of the first device, a plurality of second moments, and the plurality of first time intervals, wherein the second time interval is the time range in which the local time of the first device is located; The calculation module is further configured to update the local time of the first device according to the second time interval, wherein the updated local time of the first device is the time in the second time interval.
17. The clock synchronization apparatus of claim 16, wherein The calculation module is also configured to obtain multiple third time intervals based on multiple first moments, the local time of the first device, multiple second moments, and the multiple first time intervals, wherein different third time intervals are reliable time intervals obtained by the first device based on different first time intervals; The calculation module is also used to calculate the second time interval from the plurality of third time intervals, wherein the second time interval is the intersection of at least two third time intervals.
18. The clock synchronization apparatus of claim 17, wherein, The second time interval is obtained by the calculation module based on the Marzullo algorithm for the multiple third time intervals.
19. The clock synchronization apparatus of claim 18, wherein The supremacy of the plurality of third time intervals is obtained based on the local time of the first device, the plurality of first moments, and the supremacy of the plurality of first time intervals; The infimum of the plurality of third time intervals is obtained based on the local time of the first device, the plurality of first moments, and the infimum of the plurality of first time intervals.
20. The clock synchronization apparatus of claim 19, wherein, The first device has an operating system installed, and the operating system of the first device is used to run the first instance. The second time interval is cached in the storage space corresponding to the first instance.
21. The clock synchronization apparatus of claim 20, wherein The operating system of the first device is also used to run a second instance, which obtains the second time interval stored in the storage space corresponding to the first instance; The second instance generates a transaction consistency sequence number based on the second time interval or the updated local time of the first device.
22. The clock synchronization apparatus of claim 21, wherein, The transaction consistency sequence number is generated based on the supremum of the second time interval.
23. The clock synchronization apparatus of any of claims 14-22, wherein, The first device is a database server, and the second device is a time server.
24. A clock synchronization apparatus, characterized by comprising: Applied to the first device, including: A receiving module is used to receive a first time interval, wherein the first time interval indicates the time range in which the local time of the second device is located. The calculation module is used to update the local time of the first device according to the local time of the first device, the second moment, and the first time interval, wherein the second moment is the moment when the first device receives the first time interval.
25. The clock synchronization device according to claim 24, characterized in that, The receiving module is used to receive multiple first time intervals; The calculation module is also used to update the local time of the first device based on the local time of the first device, a plurality of second moments, and the plurality of first time intervals.
26. The clock synchronization apparatus of claim 25, wherein, The calculation module is further configured to obtain multiple third time intervals based on the local time of the first device, the multiple second moments, and the multiple first time intervals, wherein different third time intervals are reliable time intervals obtained by the first device based on different first time intervals; The calculation module is also used to calculate a second time interval from the plurality of third time intervals, wherein the second time interval is the intersection of at least two third time intervals and the second time interval is the time range in which the local time of the first device is located. The computing module is further configured to update the local time of the first device according to the second time interval, and the updated local time of the first device is a time point in the second time interval.
27. An electronic device, comprising: Comprise: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to perform the clock synchronization method of any one of claims 1-10 or the clock synchronization method of any one of claims 11-13.
28. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, which when executed, implement the clock synchronization method of any one of claims 1-10 or the clock synchronization method of any one of claims 11-13.
29. A database server, characterized by Comprise the clock synchronization apparatus of any one of claims 14-23 or the clock synchronization apparatus of any one of claims 24-26.
Citation Information
Patent Citations
Systems and Methods of Increasing Database Access Concurrency Using Granular Timestamps
US20140006458A1