CN114726658A - Method and device - Google Patents

Method and device Download PDF

Info

Publication number
CN114726658A
CN114726658A CN202210258067.XA CN202210258067A CN114726658A CN 114726658 A CN114726658 A CN 114726658A CN 202210258067 A CN202210258067 A CN 202210258067A CN 114726658 A CN114726658 A CN 114726658A
Authority
CN
China
Prior art keywords
time
data
message
counter
virtual
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210258067.XA
Other languages
Chinese (zh)
Other versions
CN114726658B (en
Inventor
方义
徐少华
吴东兴
魏峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202210258067.XA priority Critical patent/CN114726658B/en
Publication of CN114726658A publication Critical patent/CN114726658A/en
Application granted granted Critical
Publication of CN114726658B publication Critical patent/CN114726658B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/02Details
    • H04L12/12Arrangements for remote connection or disconnection of substations or of equipment thereof
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • H04J3/0658Clock or time synchronisation among packet nodes
    • H04J3/0661Clock or time synchronisation among packet nodes using timestamps
    • H04J3/0667Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Abstract

The embodiment of the application provides a method and a device for measuring time deviation, relates to the field of terminals, and can save the power consumption of equipment. The method comprises the following steps: the first device sends a first message to the second device, and obtains the virtual sending time t1 of the first message; t1 is determined according to a first offset and a system time, wherein the first offset comprises a first initial value and a jump amount of the system time of the first device; the first device receives a response message of the first message from the second device and acquires a virtual receiving time t2 of the response message of the first message, wherein t2 is determined according to the first offset and the system time; wherein, the response message of the first message carries the virtual receiving time t1 'when the second device receives the first message and the virtual sending time t 2' when the second device sends the response message of the first message; the first device determines a first virtual time offset between the first device and the second device according to t1, t2, t1 'and t 2', and saves the first virtual time offset.

Description

Method and device
Technical Field
The present application relates to the field of terminals, and in particular, to a method and an apparatus.
Background
In a distributed system, time synchronization can be performed between devices (or called nodes). Generally, each device may periodically perform time synchronization with a Network Time Protocol (NTP) server in a networking mode, so as to ensure that the time of the device and the time of the NTP server are consistent.
In the above manner, not only multiple communications between each node of the distributed system and the NTP server are required, but also the subsequent synchronization time calculation process is complicated, and the power consumption of the device is improved.
Disclosure of Invention
The embodiment of the application provides a method and a device, which can reduce the power consumption of equipment.
In a first aspect, an embodiment of the present application provides a method, including: the first device sends a first message to the second device, and obtains the virtual sending time t1 of the first message; t1 is determined according to a first offset and a system time of the first device for sending the first message, wherein the first offset comprises a first initial value and a jump amount of the system time of the first device; the first device receives the response message of the first message from the second device and obtains a virtual receiving time t2 of the response message of the first message, wherein t2 is determined according to the first offset and the system time of the first device receiving the response message of the first message; the response message of the first message carries a virtual receiving time t1 'when the second device receives the first message and a virtual sending time t 2' when the second device sends the response message of the first message, t1 'is determined according to a second offset and the system time when the second device receives the first message, t 2' is determined according to the second offset and the system time when the second device sends the response message of the first message, and the second offset comprises a second initial value and a jump amount of the system time of the second device; the first device determines a first virtual time offset between the first device and the second device according to t1, t2, t1 'and t 2', and saves the first virtual time offset.
Based on the method provided by the embodiment of the present application, after the first device determines the first virtual time offset between the first device and the second device according to t1, t2, t1 ', and t 2', the time offset between the two devices is not changed no matter which device (the first device or the second device) performs a time jump (for example, a time jump is caused by a change of a user or an NTP service), since t1, t2, t1 ', and t 2' may be compensated according to the jump amount of the system time, and thus do not jump as much as the system time. Thus, time deviation detection is not required to be carried out frequently, and power consumption of the equipment can be saved. For example, assuming that the time deviation detection is performed every 30 minutes in the prior art, the time deviation detection can be performed every 24 hours in the present application, which can improve the standby time by 20% compared with the prior art.
In one possible implementation, the method further includes: the first device sends the second message to the third device, and obtains the virtual sending time t3 of the second message; t3 is determined according to the first offset and the system time at which the first device sent the second message; the first device receives the response message of the second message from the third device and obtains a virtual receiving time t4 of the response message of the second message, wherein t4 is determined according to the first offset and the system time of the first device receiving the response message of the second message; the response message of the second message carries a virtual receiving time t3 'when the third device receives the second message and a virtual sending time t 4' when the third device sends the response message of the second message, t3 'is determined according to a third offset and a system time when the third device receives the second message, t 4' is determined according to the third offset and the system time when the third device sends the response message of the second message, and the third offset comprises a third initial value and a jump amount of the system time of the third device; the first device determines a second virtual time offset between the first device and the third device according to t3, t4, t3 'and t 4', and saves the second virtual time offset.
Based on the method provided by the embodiment of the present application, after the first device determines the second virtual time offset between the first device and the third device according to t3, t4, t3 ', and t 4', the time offset between the two devices is not changed no matter which device (the first device or the third device) performs the time jump, since t3, t4, t3 ', and t 4' can be compensated according to the jump amount of the system time, and therefore do not jump as much as the system time. Thus, time deviation detection is not required to be carried out frequently, and power consumption of the equipment can be saved.
In one possible implementation, t1 and t2 are read from a first counter, the first counter is used to read the system time of the first device from a second counter, and the first counter writes a first offset; t1 'and t 2' are read from a third counter, which is used to read the system time of the second device from a fourth counter, and the third counter writes a second offset. The first counter may be a counter maintained independently of the first device and monotonically increases, since the value of the first counter may be compensated accordingly according to the amount of system time jump of the first device, and thus may not jump as much as the system time. The third counter is a second device independently maintained counter that is monotonically incremented. This is because the value of the first counter can be compensated according to the jump amount of the system time of the second device, and thus does not jump as much as the system time.
In one possible implementation, the method further includes: the first equipment compares the step values of a second counter and a fifth counter based on a preset period, and the fifth counter is used for counting the starting operation time of the first equipment; if the difference value of the step values of the second counter and the fifth counter is equal to the step value of the second counter when the first device is started, the jump variable of the system time of the first device is 0; and if the difference value of the step values of the second counter and the fifth counter is smaller than or larger than the step value of the second counter when the first equipment is started, the jump variable of the system time of the first equipment is the difference value of the step values of the second counter and the fifth counter and the step value of the second counter when the first equipment is started. That is, the amount of jump in the system time of the first device may be counted from the power-on time of the first device. When the first device is powered on and the first device sends the first message, the system time of the first device jumps for several times, and the jump quantity of the system time of the first device comprises jump variables corresponding to the jumps for several times.
In one possible implementation, the method further includes: when the first device starts the database, the virtual starting time t5 is read from the first counter, and if t5 is smaller than the virtual writing time t6 of the last data written into the database, a correction value is written into the first counter, wherein the correction value comprises the difference between t7 and t5 and a preset value. Therefore, when the database is not started (the database process is not operated), the system time jumps, and can be corrected after the database is started, so that the monotonous increment of the virtual time is kept, and the availability and the accuracy of the virtual time are ensured.
In one possible implementation, the method further includes: when the first device writes data into the database for the first time after starting the database, the virtual writing time t7 is read from the first counter, and if the time t7 is smaller than the virtual writing time t6 of the last data written into the database, a correction value is written into the first counter, wherein the correction value comprises a difference value between t7 and t6 and a preset value. Therefore, when the database is not started (the database process is not operated), the system time jumps, the virtual time of the equipment can be corrected after the database is started, the monotonous increment of the virtual time is kept, and the availability and the accuracy of the virtual time are ensured.
In one possible implementation, the method further includes: the first device recalculates the virtual time offset of the first device with the second device. Since the virtual time of the device is corrected, the virtual time offset between the first device and the second device needs to be recalculated to ensure the accuracy of the virtual time offset between the first device and the second device.
In one possible implementation, the method further includes: writing first data by the first device, and acquiring virtual writing time t7 of the first data and logic time of the first data; if t7 is the same as the virtual write time t8 when the first device writes the previous data of the first data, the logical time of the first data is the logical time of the previous data of the first data plus 1. The logical time may be used to improve the accuracy of the virtual time.
In one possible implementation, t7 is read from the first counter, and the logic time of the first data is read from the eighth counter; if t7 is the same as t8, the eighth counter is incremented by 1; if t7 is not the same as t8, the eighth counter is cleared.
In one possible implementation, the method further includes: the first device receives a data synchronization message from the second device, wherein the data synchronization message comprises the second data and a first timestamp of the second data, and the first timestamp comprises a virtual write time t9 corresponding to the second data at the second device and a logic time of the second data; the first device determines a second timestamp for the second data, the second timestamp comprising a corresponding virtual write time t10 for the second data at the first device and a logical time for the second data, and t10 comprising a deviation of t9 from the first virtual time. That is, the first device may convert the time (i.e., the first timestamp) corresponding to the second data on the second device into the time (i.e., the second timestamp) corresponding to the second data on the first device (local), so that the time scales of the second data and other data on the first device may be unified, and the first device may correctly identify the writing order of the second data and other data on the first device.
In one possible implementation, the method further includes: the first device determining whether the second data conflicts with other data in the database; if the second data conflicts with third data in the database, comparing a second timestamp of the second data with a timestamp of the third data, wherein the timestamp of the third data comprises virtual writing time of the third data corresponding to the first device and logic time of the third data; the first device stores the most time-stamped data. That is, when data conflict is resolved, the first device may compensate the first virtual time offset for the second data from the second device, and convert the virtual time corresponding to the second data on the second device into the virtual time corresponding to the first device, so that the time scales of the second data and other data on the first device may be unified, and the first device may correctly recognize the sequence of writing the external data and the data on the first device, thereby making the conflict resolution policy more accurate.
In one possible implementation, the first device determining whether the second data conflicts with other data in the database includes: the first device determines whether the keyword of the second data is the same as the keyword of the third data, and if so, determines that the second data conflicts with the third data. The second data and other data in the database may be "key-value" type data, i.e. each data corresponds to a key and a value. If the keywords of any two data are the same, the two data conflict and conflict resolution is needed.
In a second aspect, an embodiment of the present application provides a method, applied to a system including a first device and a second device, including: the first device sends a first message to the second device, and obtains the virtual sending time t1 of the first message; t1 is determined according to a first offset and a system time of the first device for sending the first message, wherein the first offset comprises a first initial value and a jump amount of the system time of the first device; the second device receives a first message from the first device; the second equipment sends a response message of the first message to the first equipment; the response message of the first message carries a virtual receiving time t1 'when the second device receives the first message and a virtual sending time t 2' when the second device sends the response message of the first message, t1 'is determined according to a second offset and the system time when the second device receives the first message, t 2' is determined according to the second offset and the system time when the second device sends the response message of the first message, and the second offset comprises a second initial value and a jump amount of the system time of the second device; the first device receives the response message of the first message from the second device and obtains a virtual receiving time t2 of the response message of the first message, wherein t2 is determined according to the first offset and the system time of the first device receiving the response message of the first message; the first device determines a first virtual time offset between the first device and the second device according to t1, t2, t1 'and t 2', and saves the first virtual time offset.
Based on the method provided by the embodiment of the present application, after the first device determines the first virtual time offset between the first device and the second device according to t1, t2, t1 ', and t 2', the time offset between the two devices is not changed no matter which device (the first device or the second device) performs a time jump (for example, a time jump is caused by a change of a user or an NTP service), since t1, t2, t1 ', and t 2' may be compensated according to the jump amount of the system time, and thus do not jump as much as the system time. Thus, time deviation detection is not required to be carried out frequently, and power consumption of the equipment can be saved. For example, assuming that the time deviation detection is performed every 30 minutes in the prior art, the time deviation detection can be performed every 24 hours in the present application, which can improve the standby time by 20% compared with the prior art.
In one possible implementation, the system further includes a third device, and the method further includes: the first device sends the second message to the third device, and obtains the virtual sending time t3 of the second message; t3 is determined according to the first offset and the system time at which the first device sent the second message; the third device receives a second message from the first device; the third equipment sends a response message of the second message to the first equipment; the response message of the second message carries a virtual receiving time t3 'when the third device receives the second message and a virtual sending time t 4' when the third device sends the response message of the second message, t3 'is determined according to a third offset and a system time when the third device receives the second message, t 4' is determined according to the third offset and the system time when the third device sends the response message of the second message, and the third offset includes a third initial value and a jump amount of the system time of the third device; the first device receives the response message of the second message from the third device and obtains a virtual receiving time t4 of the response message of the second message, wherein t4 is determined according to the first offset and the system time of the first device receiving the response message of the second message; the first device determines a second virtual time offset between the first device and the third device according to t3, t4, t3 'and t 4', and saves the second virtual time offset.
In one possible implementation, t1 and t2 are read from a first counter, the first counter is used to read the system time of the first device from a second counter, and the first counter writes a first offset; t1 'and t 2' are read from a third counter, which is used to read the system time of the second device from a fourth counter, and the third counter writes a second offset.
In one possible implementation, the method further includes: the first equipment compares the step values of a second counter and a fifth counter based on a preset period, wherein the fifth counter is used for counting the starting operation time of the first equipment; if the difference value of the step values of the second counter and the fifth counter is equal to the step value of the second counter when the first equipment is started, the jump variable of the system time of the first equipment is 0; and if the difference value of the step values of the second counter and the fifth counter is smaller than or larger than the step value of the second counter when the first equipment is started, the jump variable of the system time of the first equipment is the difference value of the step values of the second counter and the fifth counter and the step value of the second counter when the first equipment is started.
In one possible implementation, the method further includes: when the first device starts the database, the virtual starting time t5 is read from the first counter, and if t5 is smaller than the virtual writing time t6 of the last data written into the database, a correction value is written into the first counter, wherein the correction value comprises the difference between t7 and t5 and a preset value.
In one possible implementation, the method further includes: and when the first device writes data into the database for the first time after starting the database, reading the virtual writing time t7 from the first counter, and if t7 is less than the virtual writing time t6 of the last data written into the database, writing a correction value into the first counter, wherein the correction value comprises the difference between t7 and t6 and a preset value.
In one possible implementation, the method further includes: the first device recalculates the virtual time offset of the first device with the second device.
In one possible implementation, the method further includes: writing first data by the first device, and acquiring virtual writing time t7 of the first data and logic time of the first data; if t7 is the same as the virtual write time t8 when the first device writes the previous data of the first data, the logical time of the first data is the logical time of the previous data of the first data plus 1.
In one possible implementation, t7 is read from the first counter, and the logic time of the first data is read from the eighth counter; if t7 is the same as t8, the eighth counter is incremented by 1; if t7 is not the same as t8, the eighth counter is cleared.
In one possible implementation, the method further includes: the first device receives a data synchronization message from the second device, wherein the data synchronization message comprises the second data and a first timestamp of the second data, and the first timestamp comprises a virtual write time t9 corresponding to the second data at the second device and a logic time of the second data; the first device determines a second timestamp for the second data, the second timestamp comprising a corresponding virtual write time t10 for the second data at the first device and a logical time for the second data, and t10 comprising a deviation of t9 from the first virtual time.
In one possible implementation, the method further includes: the first device determining whether the second data conflicts with other data in the database; if the second data conflict with third data in the database is determined, comparing a second timestamp of the second data with a timestamp of the third data, wherein the timestamp of the third data comprises virtual writing time of the third data corresponding to the first equipment and logic time of the third data; the first device stores the most time-stamped data.
In one possible implementation, the first device determining whether the second data conflicts with other data in the database includes: the first device determines whether the key of the second data is the same as the key of the third data, and if so, determines that the second data conflicts with the third data.
In a third aspect, an embodiment of the present application provides a computer-readable storage medium, which includes instructions that, when executed on a computer, cause the computer to perform any one of the methods provided in the first aspect.
In a fourth aspect, embodiments of the present application provide a computer program product containing instructions, which when run on a computer, cause the computer to perform any one of the methods provided in the first aspect.
In a fifth aspect, an embodiment of the present application provides a chip system, where the chip system includes a processor and may further include a memory, and is configured to implement any one of the methods provided in the first aspect. The chip system may be formed by a chip, and may also include a chip and other discrete devices.
In a sixth aspect, embodiments of the present application further provide an apparatus, which may be a processing device, an electronic device, or a chip. The apparatus comprises a processor configured to implement any one of the methods provided by the first aspect. The apparatus may also include a memory for storing program instructions and data, which may be memory integrated within the apparatus or off-chip memory disposed external to the apparatus. The memory is coupled to the processor, and the processor can call and execute the program instructions stored in the memory, so as to implement any one of the methods provided by the first aspect. The apparatus may also include a communication interface for the apparatus to communicate with another device (e.g., a second device).
Drawings
Fig. 1 is a schematic diagram of a distributed network according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a first device/a second device/a third device according to an embodiment of the present application;
FIG. 3 is a schematic diagram illustrating a comparison between a system time and a virtual time provided in an embodiment of the present application;
fig. 4 is a schematic diagram of a signal interaction provided in an embodiment of the present application;
FIG. 5 is a schematic diagram illustrating a process of reading a virtual time and a logical time when writing data 1 according to an embodiment of the present application;
FIG. 6 is a schematic diagram of another signal interaction provided in the embodiments of the present application;
FIG. 7 is a schematic diagram of a time scaling provided in an embodiment of the present application;
FIG. 8 is a diagram illustrating conflict resolution provided by an embodiment of the present application;
fig. 9 is a schematic structural diagram of a chip system according to an embodiment of the present disclosure.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. In the description of the present application, unless otherwise specified, "at least one" means one or more, "a plurality" means two or more. In addition, in order to facilitate clear description of technical solutions of the embodiments of the present application, in the embodiments of the present application, terms such as "first" and "second" are used to distinguish the same items or similar items having substantially the same functions and actions. Those skilled in the art will appreciate that the terms "first," "second," etc. do not denote any order or quantity, nor do the terms "first," "second," etc. denote any order or importance.
Fig. 1 is a schematic structural diagram of a distributed network (system) according to an embodiment of the present disclosure. The distributed network may include a plurality of devices, which may include, for example, a first device 101, a second device 102, and a third device 103. The above devices may be a router, a network switch, a firewall, a wavelength division multiplexing device, a packet transport network device, a base station controller, or a data center, and the application is not limited thereto.
For example, the apparatus for implementing the functions of the first device, the second device, or the third device provided in the embodiments of the present application may be implemented by the apparatus 200 in fig. 2. Fig. 2 is a schematic hardware structure diagram of an apparatus 200 according to an embodiment of the present disclosure. The apparatus 200 includes at least one processor 201 for implementing the functions of the first device provided in the embodiments of the present application. A communication bus 202 and at least one communication interface 204 may also be included in the apparatus 200. Memory 203 may also be included in the apparatus 200.
In the embodiment of the present application, the processor may be a Central Processing Unit (CPU), a general purpose processor, a Network Processor (NP), a Digital Signal Processor (DSP), a microprocessor, a microcontroller, and a Programmable Logic Device (PLD). The processor may also be any other device with processing functionality, such as an application-specific integrated circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic device, transistor logic, hardware components, software modules, or any combination thereof.
A communication bus 202 may be used to transfer information between the above-mentioned components.
A communication interface 204 for communicating with other devices or communication networks, such as ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc. The communication interface 204 may be an interface, a circuit, a transceiver, or other device capable of implementing communication, and is not limited in this application. The communication interface 204 may be coupled with the processor 201. The coupling in the embodiments of the present application is an indirect coupling or a communication connection between devices, units or modules, and may be an electrical, mechanical or other form for information interaction between the devices, units or modules.
In the embodiments of the present application, the memory may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a Random Access Memory (RAM) or other types of dynamic storage devices that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compact disc, laser disc, optical disc, digital versatile disc, blu-ray disc, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory may be stand alone or may be coupled to the processor, such as through a communication bus 202. The memory may also be integrated with the processor.
The memory 203 is used for storing program instructions and can be controlled by the processor 201 to execute, so as to implement the methods provided by the following embodiments of the present application. The processor 201 is configured to call and execute the instructions stored in the memory 203, thereby implementing the methods provided by the embodiments described below.
Optionally, the computer-executable instructions in the embodiments of the present application may also be referred to as application program codes, which are not specifically limited in the embodiments of the present application.
Optionally, the memory 203 may be included in the processor 201.
In particular implementations, processor 201 may include one or more CPUs such as CPU0 and CPU1 in fig. 2 as one embodiment.
In particular implementations, apparatus 200 may include multiple processors, such as processor 201 and processor 207 in FIG. 2, for example, as an example. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. A processor herein may refer to one or more devices, circuits, and/or processing cores for processing data (e.g., computer program instructions).
In one implementation, the apparatus 200 may further include an output device 205 and an input device 206, as an example. An output device 205 is coupled to the processor 201 and may display information in a variety of ways. For example, the output device 205 may be a Liquid Crystal Display (LCD), a Light Emitting Diode (LED) display device, a Cathode Ray Tube (CRT) display device, a projector (projector), or the like. The input device 206 is coupled to the processor 201 and may receive user input in a variety of ways. For example, the input device 206 may be a touch screen device or a sensing device, etc.
A database exists on each device in the distributed network, and data synchronization can be carried out between any two devices. When data synchronization is performed, the sequence of data writing needs to be determined. Each data record on each device may contain an (operation) time stamp that may record the system time of the data write.
Because the process of time synchronization is complicated, in one implementation, the deviation of the system time of the two devices can be determined, and each device compensates the deviation for the operation time stamp of the data record from the opposite device, so that the sequence of data writing can be correctly determined. Since the system time may jump (due to user adjustment, power off, failure, etc., the system time may jump), the time deviation detection between two devices needs to be performed at intervals (for example, every 30 minutes/time) to ensure the accuracy of the time deviation between the two devices.
In the embodiment of the present application, a virtual time (also referred to as a virtual clock) is introduced, and the virtual time is determined according to a system time (also referred to as a system clock) and an offset of a device. Wherein the offset comprises an initial value and a jump amount of a system time of the device. The virtual time is a counter independently maintained by each device and is monotonically increased (the virtual time can be compensated according to the jump amount of the system time, and therefore does not jump like the system time). Therefore, after the time deviation is measured once by the two devices, the time deviation between the two devices is not changed no matter which device generates the time jump (for example, the time jump is caused by the change of the user or the NTP service), so that the time deviation detection is not required to be frequently carried out, and the power consumption of the devices can be saved. For example, if the time deviation detection is performed every 30 minutes in the prior art, the time deviation detection can be performed every 24 hours in the application, and the standby time can be increased by 20% compared with the prior art.
In the embodiment of the present application, the relationship between the virtual time and the system time may be as shown in equation (1):
Figure BDA0003549164100000071
where Tv denotes a virtual time, Tr denotes a system time, λ denotes an Offset (Offset) between the virtual time and the system time, F denotes a multiple of the precision of the virtual time and the precision of the system time, and F ═ 1 denotes that the virtual time coincides with the system time precision (i.e., goes as fast). For example, if the system time steps by 1 microsecond, the virtual time also steps by 1 microsecond. Equation (1) can be simplified to equation (2):
Tv=Tr+λ (2)
where λ is the initial value + the amount of system time hopping of the device. The initial value of λ may be a random non-0 value x of 16 bits, where x is a predetermined value, for example, x is 10/20/100. The unit of x may be nanoseconds (ns), microseconds (μ s), seconds(s), or the like.
It should be noted that each device in the distributed system may correspond to different initial values, so that the difference between the virtual times of the devices is large, and the influence caused by the error in the time deviation measurement process is reduced. For example, assuming that the error of the time deviation measurement process is 1s, when the initial value corresponding to the first device is 10s and the initial value corresponding to the second device is 100s, and the deviation of the virtual time between the two devices is at least 90s, the influence of the measurement error of 1s is negligible.
As shown in fig. 3, the system time of the device may jump due to user adjustment, device power off, device failure, etc., where λ may reversely compensate the jump amount of the system time in order to maintain the continuous increment of the virtual time. If λ is equal to the initial value before the time jump occurs, λ is equal to the initial value plus the jump amount of the system time after the time jump occurs. That is, before the time jump, the virtual time is the system time + λ (initial value); after the time jump, the virtual time is system time + λ (initial value + jump variable of system time). When the system time is detected to jump again, the lambda can be recalculated, and the jump amount of the system time is continuously compensated.
In one possible implementation, the virtual clock may be a counter maintained independently by each device, the counter being evenly spaced in steps and monotonically incremented without backing off. Illustratively, the virtual time of the first device may be recorded by the first counter. The first counter may read a system time (also may be referred to as a system clock) of the first device from the second counter, and the first counter writes a first offset. The first offset includes a first initial value and a transition amount of a system time of the first device. The second counter may count events generated from the event source. The event source may be a clock chip (clock circuit) or a Central Processing Unit (CPU), and the event may be an interrupt generated by the clock chip (clock circuit) or TICKs (TICKs) inside the CPU. The value of the second counter is stepped (incremented) once per event generated by the event source. For example, if the period during which the event source generates an event is 1 millisecond, then the value of the second counter is incremented by 1 every millisecond.
The second counter may hop (i.e., system time hops) when the user adjusts system time on the device, or when the device fails, such as when it is powered off. The jump amount of the system time may be obtained by the first device comparing step values of the second counter and the fifth counter based on a preset period. The fifth counter is used for counting the starting-up running time of the first equipment; if the difference value of the step values of the second counter and the fifth counter is equal to the step value of the second counter when the first equipment is started, the jump variable of the system time of the first equipment is 0; and if the difference value of the step values of the second counter and the fifth counter is smaller than or larger than the step value of the second counter when the first equipment is started, the jump variable of the system time of the first equipment is the difference value of the step values of the second counter and the fifth counter and the step value of the second counter when the first equipment is started.
In the above description of the virtual time, the following description of the method (for example, the time deviation measuring method) provided by the embodiment of the present application, taking the first device initiating the virtual time deviation measurement (which may also be simply referred to as time deviation measurement) as an example, as shown in fig. 4, includes:
401. the first device sends the first message to the second device and obtains the virtual sending time t1 of the first message.
After the first device opens the database, a first message may be sent to the second device to initiate a time offset measurement. Alternatively, the first device may initiate the time offset measurement based on a preset period.
Where t1 is determined according to a first offset and a system time at which the first device transmits the first message, the first offset includes a first initial value and a hop amount of the system time of the first device. The amount of hopping of the system time of the first device may be determined with reference to the associated description above. The first initial value may be a 16-bit random non-0 value x, where x is a predetermined value, such as x 10/20/100.
402. The first device receives the response message of the first message from the second device and acquires a virtual reception time t2 of the response message of the first message.
Where t2 is determined according to the first offset and the system time at which the first device receives the response message to the first message. The response message of the first message carries the virtual receiving time t1 'when the second device receives the first message and the virtual sending time t 2' when the second device sends the response message of the first message, t1 'is determined according to the second offset and the system time when the second device receives the first message, t 2' is determined according to the second offset and the system time when the second device sends the response message of the first message, and the second offset comprises the second initial value and the jump amount of the system time of the second device. The amount of hopping of the system time of the second device may be determined with reference to the associated description above. The second initial value may be a 16-bit random non-0 value x, where x is a predetermined value, for example, x is 10/20/100.
403. The first device determines a first virtual time offset between the first device and the second device according to t1, t2, t1 'and t 2', and saves the first virtual time offset.
Where t1 and t2 may be read from a first counter of the first device, the first counter being used to read the system time of the first device from a second counter of the first device, and the first counter having written thereto a first offset (offset corresponding to the first device). t1 'and t 2' may be read from a third counter of the second device, the third counter being used to read the system time of the second device from a fourth counter of the second device, and the third counter having written a second offset (the offset to which the second device corresponds).
The calculation procedure of the first virtual time offset between the first device and the second device may be as shown in equation (3):
Figure BDA0003549164100000081
where Δ t represents a virtual time deviation of the first device and the second device, i.e., a first virtual time deviation, and RTT is a round trip delay of the network.
Assuming that when the first device and the second device perform time offset measurement for the first time, neither the first device nor the second device generates a time jump, the virtual time of the first device is the system time + λ 1 of the first device, the virtual time of the second device is the system time + λ 2 of the second device, and the time offset Δ t1 obtained by the first time offset measurement is the system time + λ 1 of the first device- (the system time + λ 2 of the second device); when the time jump occurs in the first device, the virtual time of the first device is equal to (the system time-system time jump variable of the first device) + (λ 1+ system time jump variable) — the system time of the first device + λ 1, and the time deviation Δ t2 after the time jump occurs is equal to the system time of the first device + λ 1- (system time of the second device + λ 2), that is, Δ t1 is equal to Δ t 2. Namely, no matter which device generates time jump, the time deviation between the two devices is not changed, so that the time deviation detection is not required to be frequently carried out, and the power consumption can be saved.
Optionally, the first device may also measure a time offset between the first device and the third device, that is, after step 403, the following steps are further included:
404. the first device sends the second message to the third device and obtains the virtual sending time t3 of the second message.
Where t3 is determined based on the first offset and the system time at which the first device sent the second message.
405. The first device receives the response message of the second message from the third device and acquires the virtual reception time t4 of the response message of the second message.
Wherein t4 is determined according to the first offset and the system time at which the first device receives the response message of the second message; the response message of the second message carries a virtual receiving time t3 'when the third device receives the second message and a virtual sending time t 4' when the third device sends the response message of the second message, t3 'is determined according to a third offset and a system time when the third device receives the second message, t 4' is determined according to the third offset and the system time when the third device sends the response message of the second message, and the third offset includes a third initial value and a jump amount of the system time of the third device.
406. The first device determines a second virtual time offset between the first device and the third device according to t3, t4, t3 'and t 4', and saves the second virtual time offset.
Where t3 and t4 may be read from a first counter of the first device. t3 'and t 4' may be read from a third counter of the second device.
The process of the first device determining the second virtual time offset may refer to the process of the first device determining the first virtual time offset in step 403. Of course, the first device may also measure a virtual time offset between the first device and other devices (e.g., a fourth device, a fifth device, etc.), and the process is not described in detail.
It will be appreciated that time offset measurements may be made between any two devices in the distributed system, and that each device may maintain a virtual time offset between that device and the other devices in the distributed system.
Illustratively, the first device may store a Metadata (Metadata) table as shown in table 1.
TABLE 1
Figure BDA0003549164100000091
Where Δ t1 is the time offset of the virtual time of the first device from the virtual time of the second device. For example, Δ t1 is the virtual time of the first device-the virtual time of the second device, or Δ t1 is the virtual time of the second device-the virtual time of the first device. Δ t2 is the time offset of the virtual time of the first device from the virtual time of the third device. For example, Δ t2 is the virtual time of the first device-the virtual time of the third device, or Δ t2 is the virtual time of the third device-the virtual time of the first device. Δ t3 is the time offset of the virtual time of the first device from the virtual time of the fourth device. For example, Δ t3 is the virtual time of the first device-the virtual time of the fourth device, or Δ t3 is the virtual time of the fourth device-the virtual time of the first device.
Optionally, table 1 may also include λ, as shown in table 2:
TABLE 2
Figure BDA0003549164100000092
Table 2 may be stored in a database of the first device, and when the database is started, table 2 may be loaded, i.e. both λ and the respective time offset are loaded into the memory, so that the first device may read λ and the respective time offset from the memory.
In one possible scenario, the virtual time of the device may need to be corrected. This is because the database service (database program) can always detect whether the system time jumps or not during the database operation. However, during the closing of the database, the database service cannot detect whether the system time jumps, and if the system time jumps during the closing of the database, the virtual time needs to be corrected. Illustratively, the modification of the virtual time of the first device may be triggered by two scenarios:
(1) when the first device starts the database, the virtual start time t5 is read from the first counter, and if t5 is less than the virtual write time t6 of the last data written into the database, it indicates that a time jump occurs during the shutdown of the database, and the time jump needs to be corrected. A correction value may be written to the first counter, the correction value including the difference between t7 and t5 and a preset value.
(2) When the first device writes data into the database for the first time (first time) after starting the database, reading the virtual writing time t7 from the first counter, and if t7 is less than the virtual writing time t6 of the data written into the database last time, indicating that a time jump occurs during closing of the database and the data needs to be corrected. A correction value may be written to the first counter, the correction value including the difference between t7 and t6 and a preset value.
Therefore, if the database is not started (the database process is not operated), the system time jumps, the virtual time of the equipment can be corrected after the database is started, the monotonous increasing of the virtual time is kept, and the availability and the accuracy of the virtual time are ensured.
In addition, in one possible design, the database service may request the amount of system time jump from the resident process after it is opened, so that no modification of the virtual time is required.
It is to be appreciated that after the virtual time is modified, the first device may recalculate the time offset of the second device between the first device and the other devices (e.g., the second device, the third device, etc.) and update the contents of table 1 or table 2. The specific process is referred to above and will not be described herein.
In a possible design, when the precision of the virtual time is consistent with that of the system time, since the system time is at most accurate to microsecond, in a scenario where a large amount of data is written in batch, the read interval of the virtual time may be less than microsecond, which results in that the writing sequence of part of data cannot be distinguished. Based on this, a logical time (logical time bit/logical section) can be introduced, which can be used to improve the accuracy of the virtual time. For example, if the precision of the virtual time (i.e., the precision of the event source) is 1 millisecond, it is ensured that different values can be obtained when the virtual time is uniformly obtained with a frequency less than 1,000 times/s, and if the virtual time is obtained with a frequency greater than 1,000 times/s (e.g., 1,000,000 times/s), a plurality of identical virtual times may be obtained, and the order of operations (e.g., write operations) cannot be distinguished. After the logic time is added to the virtual time, when the virtual time is acquired at a frequency of more than 1,000 times/s, if the same virtual time is acquired, the logic time can be incremented, so that when the virtual time is acquired at a frequency of more than 1,000 times/s, the values of the virtual time are different, and the sequence of operations (for example, write operations) can be distinguished. The number of bits of the logic time may include 1 bit, 2 bits, or 3 bits, among others.
For example, when the first device writes the first data, not only the virtual write time t7 of the first data but also the logical time of the first data can be acquired. As shown in fig. 5, when the first device writes the first data (data 1), t7 can be read from the first counter, the logical time of data 1 can be read from the eighth counter, then t7 and the logical time of data 1 can be used as the time stamp of data 1, and the time stamps of data 1 and data 1 can be combined into one record to be written into the database. Wherein the logical time is independently incremented and cleared when the physical portion transitions. For example, if t7 is the same as the virtual writing time t8 when the first device writes the previous data of the first data, the logical time of the first data is the logical time of the previous data of the first data plus 1; if t7 is different from the virtual write time t8 when the first device writes the previous data of the first data, the logical time of the first data is 0. Where t7 is read from the first counter, and the logic time of the first data is read from the eighth counter; if t7 is the same as t8, the eighth counter is incremented by 1; if t7 is not the same as t8, the eighth counter is cleared.
In the above, the virtual time (virtual transmission time, virtual reception time, virtual write time, etc.) refers to a time (part a) determined from the system time and the offset. After introducing the logical time, the virtual time may also be considered to include a part a and the logical time, where the part a may be referred to as a physical part of the virtual time and the logical time may be referred to as a logical part of the virtual time. Unless otherwise specified, the virtual time referred to in the embodiments of the present application refers to a time (part a) determined based on the system time and the offset.
The above-mentioned step 401 and step 406 illustrate the process of determining the time deviation between the devices, and after the time deviation is determined, when data synchronization is performed, the corresponding time deviation can be compensated for the virtual time of the data from the opposite device, so as to correctly determine the sequence of data writing. The following describes a data synchronization process between a first device and a second device, as shown in fig. 6, including:
407a, the second device sends a data synchronization message to the first device.
The second device may invoke the synchronization interface to send a data synchronization message to the first device.
407b, the first device receives a data synchronization message from the second device.
Wherein the data synchronization message includes record 1(record1), the record1 includes the second data and a first timestamp of the second data, and the first timestamp includes a corresponding virtual write time t9 of the second data at the second device and a logical time of the second data.
408. The first device determines a second timestamp of the second data.
That is, the first device translates the time (i.e., the first timestamp) corresponding to the second data on the second device to the time (i.e., the second timestamp) corresponding to the second data on the first device (locally). Wherein the second timestamp includes a corresponding virtual write time t10 of the second data at the first device and a logical time of the second data, and the t10 includes a deviation of t9 from the first virtual time. The first device may read the first virtual time offset from the memory.
As shown in fig. 7, record1 includes second data, which is key-value (kv) type data, and includes key 1 and value 2, and a first time stamp 1596697041000,000,1 (total 17 bits) in 100ns (i.e., 0.1 μ s). The first 16 bits (1596697041000,000) of the first timestamp are the corresponding virtual time of the second data on the second device (which may be read from a third counter of the second device), and the last bit (bit 17, i.e., 1) of the first timestamp is the logical time of the second data. It is assumed that the first virtual time offset is the virtual time of the second device — the virtual time of the first device is 100, i.e., the virtual time of the first device is 100 units slower than the virtual time of the second device, i.e., 100 × 100 ns. After receiving record1, the first device may add 100 to 1596697041000,00 (the corresponding virtual time for the second data on the second device), thereby modifying t9 (i.e., 1596697041000,000) to t10 (i.e., 1596697041000,100), the logical time remaining unchanged, and the second timestamp being a combination of t10 and the logical time (i.e., 1596697041000,100, 1). The first device combines the second data and the second timestamp into record 2.
409. The first device determines whether the second data conflicts with other data in the database.
The database may store therein key-value (kv) type data, each piece of data (data record) including a key and a value. The first device determines whether there is a data record (like key record) in the database that has the same keyword. And if the key record does not exist, directly storing the key record in a warehouse. If there is a same key record, conflict resolution is required.
For example, the first device determines whether the key of the second data is the same as the key of the third data, and if so, determines that the second data conflicts with the third data.
410. And if the second data is determined to conflict with third data in the database, comparing a second time stamp of the second data with a time stamp of the third data.
And the timestamp of the third data comprises a virtual writing time corresponding to the third data in the first device and a logic time of the third data. The virtual writing time of the third data corresponding to the first device and the virtual writing time of the second data corresponding to the first device may be compared, and when the virtual writing time is longer, the timestamp is larger. If the virtual writing time is the same, the logic time of the third data and the logic time of the second data can be compared, and when the logic time is longer, the timestamp is larger. Wherein the third data is any piece of data in the database of the first device.
Illustratively, as shown in fig. 8, record1 and record 2 may refer to the related description of fig. 7, record 3 includes third data and a timestamp of the third data, the third data is kv-type data, the third data includes a key 1 and a value 1, the timestamp of the third data is 1596697041000,000,0 (17 bits in total), and has a unit of 100ns (i.e., 0.1 μ s), the first 16 bits (1596697041000,000) of the timestamp of the third data is a corresponding virtual time of the third data on the first device (which may be read from the first counter of the first device), and the last bit (17 th bit, i.e., 0) of the timestamp of the third data may be a logical time of the second data. Since the key of the second data is the same as the key of the third data, the second data conflicts with the third data, and conflict resolution is required. The second timestamp (i.e., the time-scaled timestamp) of the second data may be compared to the timestamp of the third data. Specifically, the size of the virtual write time (1596697041000,100) in the second time stamp of the second data and the size of the virtual write time (1596697041000,000) in the time stamp of the third data may be compared first, and when the virtual write time is larger, the time stamp is larger. Since 1596697041000,000<1596697041000,100, the timestamp of the second data (second timestamp) is larger, thus record 2: < keyword 1, value 2, 1596697041000,100, 1 >.
411. The first device stores the most time-stamped data.
It will be appreciated that the data with the largest time stamp is the data with the latest write time.
In addition, to reduce the influence of time drift, the time offset may be measured again at a preset time interval (e.g., 24 hours) after the two devices (e.g., the first device and the second device) measure the time offset for the first time.
Based on the method provided by the embodiment of the present application, the first device may maintain a time deviation list, where the time deviation list includes time deviations between the virtual time of the first device and the virtual times of other devices (e.g., the second device, the third device, etc.). In this way, the first device can compensate for the corresponding time offset when performing data synchronization. For example, after the foreign data (e.g., data from the second device) arrives at the first device, the first device may convert the original virtual time of the foreign data (e.g., the virtual time corresponding to the second device) into the virtual time corresponding to the first device, so as to achieve a uniform scale, and thus the first device can correctly identify the sequence of the writing of the foreign data and the data on the first device. Even if the equipment generates time jump, the time deviation between the two equipment is not changed, and the problem that the sequence of data writing cannot be correctly identified due to the change of the time deviation cannot be caused.
Another embodiment of the present application provides a chip system, as shown in fig. 9, which includes at least one processor 901 and at least one interface circuit 902. The processor 901 and the interface circuit 902 may be interconnected by wires. For example, the interface circuit 902 may be used to receive signals from other apparatuses (e.g., a memory of a first device, a memory of a second device). Also for example, the interface circuit 902 may be used to send signals to other devices, such as the processor 901.
For example, the interface circuit 902 may read instructions stored in the memory and send the instructions to the processor 901. The instructions, when executed by the processor 901, may cause the first device or the second device to perform the various steps in the embodiments described above.
Of course, the chip system may further include other discrete devices, which is not specifically limited in this embodiment of the present application.
Embodiments of the present application also provide a computer-readable storage medium, which includes computer instructions, when the computer instructions are executed on the apparatus 200 shown in fig. 2, the apparatus 200 is caused to perform various functions or steps performed by the first device or the second device in the above-described method embodiments.
Embodiments of the present application further provide a computer program product, which when run on a computer, causes the computer to execute each function or step performed by the first device or the second device in the foregoing method embodiments.
Through the description of the above embodiments, it is clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely used as an example, and in practical applications, the above function distribution may be completed by different functional modules according to needs, that is, the internal structure of the device may be divided into different functional modules to complete all or part of the above described functions.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the above-described device embodiments are merely illustrative, and for example, the division of the modules or units is only one logical functional division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another device, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may be one physical unit or multiple physical units, that is, may be located in one place, or may be distributed in multiple different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or partially contributed to by the prior art, or all or part of the technical solutions may be embodied in the form of a software product, where the software product is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only an embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (26)

1. A method, comprising:
the method comprises the steps that a first device sends a first message to a second device, and virtual sending time t1 of the first message is obtained; the t1 is determined according to a first offset and a system time of the first device for sending the first message, wherein the first offset comprises a first initial value and a jump amount of the system time of the first device;
the first device receives the response message of the first message from the second device and obtains a virtual receiving time t2 of the response message of the first message, wherein t2 is determined according to the first offset and the system time of the first device receiving the response message of the first message; the response message of the first message carries a virtual receiving time t1 'when the second device receives the first message and a virtual sending time t 2' when the second device sends the response message of the first message, the t1 'is determined according to a second offset and a system time when the second device receives the first message, the t 2' is determined according to the second offset and the system time when the second device sends the response message of the first message, and the second offset comprises a second initial value and a jump amount of the system time of the second device;
the first device determines a first virtual time offset between the first device and the second device from the t1, the t2, the t1 ', and the t 2'.
2. The method of claim 1, further comprising:
the first device sends a second message to a third device, and obtains virtual sending time t3 of the second message; the t3 is determined according to the first offset and the system time of the first device sending the second message;
the first device receiving the response message of the second message from the third device and obtaining a virtual receiving time t4 of the response message of the second message, the t4 being determined according to the first offset and a system time at which the first device receives the response message of the second message; the response message of the second message carries a virtual receiving time t3 'when the third device receives the second message and a virtual sending time t 4' when the third device sends the response message of the second message, the t3 'is determined according to a third offset and a system time when the third device receives the second message, the t 4' is determined according to the third offset and the system time when the third device sends the response message of the second message, and the third offset comprises a third initial value and a jump amount of the system time of the third device;
the first device determines a second virtual time offset between the first device and the third device from the t3, the t4, the t3 ', and the t 4'.
3. The method according to claim 1 or 2,
the t1 and the t2 are read from a first counter, the first counter is used to read the system time of the first device from a second counter, and the first counter writes a first offset;
the t1 'and the t 2' are read from a third counter for reading the system time of the second device from a fourth counter, and the third counter writes a second offset.
4. The method of claim 3, further comprising:
the first equipment compares the step values of the second counter and a fifth counter based on a preset period, wherein the fifth counter is used for counting the starting-up running time of the first equipment;
if the difference value between the step values of the second counter and the fifth counter is equal to the step value of the second counter when the first device is started, the jump variable of the system time of the first device is 0; and if the difference value of the step values of the second counter and the fifth counter is smaller than or larger than the step value of the second counter when the first device is started, the jump variable of the system time of the first device is the difference value of the step values of the second counter and the fifth counter and the difference value of the step value of the second counter when the first device is started.
5. The method according to claim 3 or 4, characterized in that the method further comprises:
when the first device starts the database, reading a virtual starting time t5 from the first counter, and if t5 is smaller than the virtual writing time t6 of the last data written into the database, writing a correction value into the first counter, wherein the correction value comprises a difference value between t7 and t5 and a preset value.
6. The method according to claim 3 or 4, characterized in that the method further comprises:
and when the first device writes data into the database for the first time after starting the database, reading virtual writing time t7 from the first counter, and if t7 is less than the virtual writing time t6 of the last data written into the database, writing a correction value into the first counter, wherein the correction value comprises a difference value between t7 and t6 and a preset value.
7. The method of claim 5 or 6, further comprising:
the first device recalculates a virtual time offset of the first device with the second device.
8. The method according to any one of claims 1-7, further comprising:
the first device writes first data, and obtains virtual writing time t7 of the first data and logic time of the first data;
if the time t7 is the same as the virtual writing time t8 when the first device writes the previous data of the first data, the logical time of the first data is the logical time of the previous data of the first data plus 1.
9. The method of claim 8,
the t7 is read from the first counter, and the logic time of the first data is read from the eighth counter;
if the t7 is the same as the t8, the eighth counter is incremented by 1; if the t7 is not the same as the t8, the eighth counter is cleared.
10. The method according to any one of claims 1-9, further comprising:
the first device receiving a data synchronization message from the second device, the data synchronization message including second data and a first timestamp of the second data, the first timestamp including a corresponding virtual write time t9 of the second data at the second device and a logical time of the second data;
the first device determines a second timestamp of the second data, the second timestamp comprising a virtual write time t10 corresponding to the second data at the first device and a logical time of the second data, the t10 comprising the t9 offset from the first virtual time.
11. The method of claim 10, further comprising:
the first device determining whether the second data conflicts with other data in the database;
if the second data is determined to conflict with third data in the database, comparing a second timestamp of the second data with a timestamp of the third data, where the timestamp of the third data includes a virtual write time corresponding to the third data in the first device and a logic time of the third data;
the first device stores the data with the largest time stamp.
12. The method of claim 11, wherein the first device determining whether the second data conflicts with other data in the database comprises:
and the first equipment determines whether the keyword of the second data is the same as the keyword of the third data, and if so, determines that the second data conflicts with the third data.
13. A method, applied to a system comprising a first device and a second device, comprising:
the method comprises the steps that a first device sends a first message to a second device, and virtual sending time t1 of the first message is obtained; the t1 is determined according to a first offset and a system time of the first device for sending the first message, wherein the first offset comprises a first initial value and a jump amount of the system time of the first device;
the second device receiving the first message from the first device;
the second device sends a response message of the first message to the first device; the response message of the first message carries a virtual receiving time t1 'when the second device receives the first message and a virtual sending time t 2' when the second device sends the response message of the first message, the t1 'is determined according to a second offset and a system time when the second device receives the first message, the t 2' is determined according to the second offset and the system time when the second device sends the response message of the first message, and the second offset comprises a second initial value and a jump amount of the system time of the second device;
the first device receives the response message of the first message from the second device and obtains a virtual receiving time t2 of the response message of the first message, wherein t2 is determined according to the first offset and the system time of the first device receiving the response message of the first message;
the first device determines a first virtual time offset between the first device and the second device from the t1, the t2, the t1 ', and the t 2'.
14. The method of claim 13, wherein the system further comprises a third device, the method further comprising:
the first equipment sends a second message to third equipment, and obtains the virtual sending time t3 of the second message; the t3 is determined according to the first offset and the system time of the first device sending the second message;
the third device receiving the second message from the first device;
the third device sends a response message of the second message to the first device; wherein, the response message of the second message carries a virtual receiving time t3 'when the third device receives the second message and a virtual sending time t 4' when the third device sends the response message of the second message, the t3 'is determined according to a third offset and a system time when the third device receives the second message, the t 4' is determined according to the third offset and the system time when the third device sends the response message of the second message, and the third offset includes a third initial value and a jump amount of the system time of the third device;
the first device receives the response message of the second message from the third device and obtains a virtual receiving time t4 of the response message of the second message, wherein t4 is determined according to the first offset and the system time of the first device receiving the response message of the second message;
the first device determines a second virtual time offset between the first device and the third device from the t3, the t4, the t3 ', and the t 4'.
15. The method according to claim 13 or 14,
the t1 and the t2 are read from a first counter, the first counter is used to read the system time of the first device from a second counter, and the first counter writes a first offset;
the t1 'and the t 2' are read from a third counter for reading the system time of the second device from a fourth counter, and the third counter writes a second offset.
16. The method of claim 15, further comprising:
the first equipment compares the step values of the second counter and a fifth counter based on a preset period, wherein the fifth counter is used for counting the starting-up running time of the first equipment;
if the difference value between the step values of the second counter and the fifth counter is equal to the step value of the second counter when the first device is started, the jump variable of the system time of the first device is 0; and if the difference value between the step values of the second counter and the fifth counter is smaller than or larger than the step value of the second counter when the first device is started, the jump variable of the system time of the first device is the difference value between the step values of the second counter and the fifth counter and the difference value between the step values of the second counter when the first device is started.
17. The method according to claim 15 or 16, characterized in that the method further comprises:
when the first device starts the database, reading a virtual starting time t5 from the first counter, and if t5 is smaller than the virtual writing time t6 of the last data written into the database, writing a correction value into the first counter, wherein the correction value comprises a difference value between t7 and t5 and a preset value.
18. The method according to claim 15 or 16, further comprising:
and when the first device writes data into the database for the first time after starting the database, reading virtual writing time t7 from the first counter, and if t7 is less than the virtual writing time t6 of the last data written into the database, writing a correction value into the first counter, wherein the correction value comprises a difference value between t7 and t6 and a preset value.
19. The method according to claim 17 or 18, further comprising:
the first device recalculates a virtual time offset of the first device with the second device.
20. The method according to any one of claims 13-19, further comprising:
the first device writes first data, and obtains virtual writing time t7 of the first data and logic time of the first data;
if the t7 is the same as the virtual writing time t8 of the first device writing the previous data of the first data, the logical time of the first data is the logical time of the previous data of the first data plus 1.
21. The method of claim 20,
the t7 is read from the first counter, and the logic time of the first data is read from an eighth counter;
if the t7 is the same as the t8, the eighth counter is incremented by 1; and if the t7 is not the same as the t8, the eighth counter is cleared.
22. The method according to any one of claims 13-21, further comprising:
the first device receiving a data synchronization message from the second device, the data synchronization message including second data and a first timestamp of the second data, the first timestamp including a corresponding virtual write time t9 of the second data at the second device and a logical time of the second data;
the first device determines a second timestamp of the second data, the second timestamp including a virtual write time t10 of the second data at the first device and a logical time of the second data, the t10 including the t9 offset from the first virtual time.
23. The method of claim 22, further comprising:
the first device determining whether the second data conflicts with other data in the database;
if the second data conflicts with third data in the database, comparing a second timestamp of the second data with a timestamp of the third data, where the timestamp of the third data includes a virtual writing time corresponding to the third data in the first device and a logic time of the third data;
the first device stores the data with the largest time stamp.
24. The method of claim 23, wherein the first device determining whether the second data conflicts with other data in the database comprises:
and the first equipment determines whether the keyword of the second data is the same as the keyword of the third data, and if so, determines that the second data conflicts with the third data.
25. An apparatus comprising a processor coupled to a memory, the memory having stored therein instructions that, when invoked and executed, cause the apparatus to perform the method of any of claims 1-12.
26. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the method of any of claims 1-12.
CN202210258067.XA 2020-08-31 2020-08-31 Method and device for measuring time deviation Active CN114726658B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210258067.XA CN114726658B (en) 2020-08-31 2020-08-31 Method and device for measuring time deviation

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010899339.5A CN114124274A (en) 2020-08-31 2020-08-31 Method and device
CN202210258067.XA CN114726658B (en) 2020-08-31 2020-08-31 Method and device for measuring time deviation

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
CN202010899339.5A Division CN114124274A (en) 2020-08-31 2020-08-31 Method and device

Publications (2)

Publication Number Publication Date
CN114726658A true CN114726658A (en) 2022-07-08
CN114726658B CN114726658B (en) 2023-04-11

Family

ID=80354711

Family Applications (2)

Application Number Title Priority Date Filing Date
CN202210258067.XA Active CN114726658B (en) 2020-08-31 2020-08-31 Method and device for measuring time deviation
CN202010899339.5A Pending CN114124274A (en) 2020-08-31 2020-08-31 Method and device

Family Applications After (1)

Application Number Title Priority Date Filing Date
CN202010899339.5A Pending CN114124274A (en) 2020-08-31 2020-08-31 Method and device

Country Status (2)

Country Link
CN (2) CN114726658B (en)
WO (1) WO2022042748A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106603518A (en) * 2016-12-05 2017-04-26 深圳市泛海三江科技发展有限公司 Time stamp generating method and time stamp generating device of real-time transmission protocol system
CN107360060A (en) * 2017-08-07 2017-11-17 瑞斯康达科技发展股份有限公司 A kind of time-delay measuring method and device
CN110289930A (en) * 2019-06-27 2019-09-27 深圳市元征科技股份有限公司 A kind of embedded device method for synchronizing time, system and relevant device
CN110620632A (en) * 2019-09-12 2019-12-27 华为技术有限公司 Time synchronization method and device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8837530B2 (en) * 2010-03-12 2014-09-16 University Of Maryland Method and system for adaptive synchronization of timing information generated by independently clocked communication nodes
CN111541531A (en) * 2020-04-27 2020-08-14 腾讯音乐娱乐科技(深圳)有限公司 Double-end time delay alignment method and device, server and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106603518A (en) * 2016-12-05 2017-04-26 深圳市泛海三江科技发展有限公司 Time stamp generating method and time stamp generating device of real-time transmission protocol system
CN107360060A (en) * 2017-08-07 2017-11-17 瑞斯康达科技发展股份有限公司 A kind of time-delay measuring method and device
CN110289930A (en) * 2019-06-27 2019-09-27 深圳市元征科技股份有限公司 A kind of embedded device method for synchronizing time, system and relevant device
CN110620632A (en) * 2019-09-12 2019-12-27 华为技术有限公司 Time synchronization method and device

Also Published As

Publication number Publication date
CN114726658B (en) 2023-04-11
CN114124274A (en) 2022-03-01
WO2022042748A1 (en) 2022-03-03

Similar Documents

Publication Publication Date Title
US11050501B2 (en) Performing PHY-level hardware timestamping and time synchronization in cost-sensitive environments
CN111385051B (en) Clock synchronization method, device and storage medium
US11811501B2 (en) Clock synchronization method and apparatus, and storage medium
US20160065435A1 (en) Communication device and communication system
JP7401656B2 (en) METHODS, APPARATUS AND SYSTEM AND STORAGE MEDIA FOR SELECTING CLOCK SOURCES
CN111510237B (en) Controller and method for modifying clock signal, and synchronization device
CN106533399B (en) Circuit and method for modifying clock signal and device for executing time-sensitive task
WO2020059139A1 (en) Communication device, communication system, communication method, and communication program
US20220248353A1 (en) Synchronization method and device
Dong et al. The design and implementation of ieee 1588v2 clock synchronization system by generating hardware timestamps in mac layer
CN114726658B (en) Method and device for measuring time deviation
CN106533598B (en) Circuit and method for estimating occurrence time difference between events, and computer-readable storage medium
US11907754B2 (en) System to trigger time-dependent action
US10784976B2 (en) Nanosecond accuracy of timestamping by leveraging alignment marker and method for producing the same
WO2020059137A1 (en) Communication device, communication system, communication method, and communication program
US7085948B2 (en) Method, apparatus, and computer program product for implementing time synchronization correction in computer systems
JP5845771B2 (en) Information transmission system and information transmission method
CN108401287B (en) Networking method and device
CN114296511A (en) Real-time clock calibration circuit, method and chip structure
CN113704045A (en) Clock synchronization test method, system and chip
JPH096464A (en) Time setting device
WO2022253348A1 (en) Time source signal determination method and apparatus, network device, and storage medium
Kumar et al. Hardware Time-stamping in Network Time Protocol and NTP to 1PPS Generation
TW202224342A (en) Oscillator calibration method, module, chip and electronic device
CN117015024A (en) Time synchronization method, network equipment and communication system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant