Timestamp generation method and device, electronic equipment and computer readable storage medium
By obtaining the physical clock time of the primary and backup timestamp services and generating transition physical timestamps, the system unavailability and inconsistency of timestamps caused by timestamp service failure in distributed systems is solved, and the availability and consistency of timestamp generation in the event of failure is achieved.
Patent Information
- Application Number
- CN202411896977.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-05-13
AI Technical Summary
In distributed systems, centralized timestamp services may experience abnormal unavailability, resulting in system unavailability. The prior art may cause global timestamp fallback or the generated timestamps not to monotonically increase, affecting the availability and consistency of the system.
By obtaining the physical clock time used by the primary and standby timestamp services, determining the transition physical time, and generating timestamps using the logical clock of the transition physical time and the standby timestamp service, ensuring that the timestamp generated after the primary timestamp service fails monotonically.
It realizes that the timestamp is generated without pausing the service after the main timestamp service fails, ensuring the system availability and monotonic incrementality of the timestamp, and does not need to ask all nodes of the distributed system, reducing the system resource usage and time waste of accessing nodes.
Smart Images

Figure CN119995763A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to the technical fields of distributed systems, time synchronization, etc. Specifically, the present disclosure relates to a timestamp generation method and device, an electronic device, and a computer-readable storage medium. Background Art
[0002] TSO (Timestamp Oracle) is a global clock service used in distributed systems, mainly used to ensure the time sequence and consistency of events within the distributed system.
[0003] Timestamp services are generally centralized, so the timestamp service may become abnormally unavailable, causing the entire system to become unavailable.
[0004] In order to ensure the availability of the system, a backup timestamp service will be prepared and switched to the backup timestamp service when the primary timestamp service fails. Summary of the invention
[0005] The present disclosure provides a timestamp generation method and device, an electronic device, and a computer-readable storage medium.
[0006] According to a first aspect of the present disclosure, a timestamp generation method is provided, the method comprising:
[0007] Obtaining a first physical time corresponding to a physical clock used by a primary timestamp service of a distributed system and a second physical time corresponding to a physical clock used by a backup timestamp service of the distributed system;
[0008] Determine a transition physical time according to the first physical time and the second physical time;
[0009] A timestamp is generated using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service.
[0010] According to a second aspect of the present disclosure, a timestamp generating device is provided, the device comprising:
[0011] A monitoring module, used to obtain a first physical time corresponding to a physical clock used by a primary timestamp service of a distributed system, and a second physical time corresponding to a physical clock used by a backup timestamp service of the distributed system;
[0012] A time comparison module, configured to determine a transition physical time according to the first physical time and the second physical time;
[0013] The timestamp generation module is used to generate a timestamp using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service.
[0014] According to a third aspect of the present disclosure, an electronic device is provided, the electronic device comprising:
[0015] at least one processor; and
[0016] A memory in communication with the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the timestamp generation method.
[0018] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the above-mentioned timestamp generation method.
[0019] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, which implements the above-mentioned timestamp generation method when executed by a processor.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0022] Figure 1 It is a flowchart of a timestamp generation method provided by an embodiment of the present disclosure;
[0023] Figure 2 It is a flowchart of some steps of another method for generating a timestamp provided by an embodiment of the present disclosure;
[0024] Figure 3 It is a flowchart of some steps of another method for generating a timestamp provided by an embodiment of the present disclosure;
[0025] Figure 4 is a schematic diagram of a timestamp service switching relationship in a specific embodiment of another timestamp generation method provided by an embodiment of the present disclosure;
[0026] Figure 5 is a structural schematic diagram of a timestamp generating device provided by an embodiment of the present disclosure;
[0027] Figure 6 It is a block diagram of an electronic device used to implement the time stamp generation method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0029] In some related technologies, TSO ensures the time order of events within a distributed system by providing a monotonically increasing global timestamp, thus avoiding the time inconsistency problem caused by clock offset in the distributed system.
[0030] When the primary timestamp service fails and the backup timestamp service is used instead, it is necessary to ensure that the global timestamp is also monotonically increasing. For example, if the physical time used by the primary timestamp service is 10 and the physical time used by the backup timestamp service is 8, when the primary timestamp service fails and the backup timestamp service is used instead, the global timestamp will be rolled back if the physical time of the backup timestamp service is used, thus breaking the monotonically increasing requirement.
[0031] At the same time, since the service providing the global timestamp cannot be suspended, it is not possible to wait for the physical time of the backup timestamp service to catch up with the physical time of the primary timestamp service.
[0032] In some related technologies, when switching to use a backup timestamp service, the maximum timestamp max_ts used in the distributed system is compared, and the backup timestamp service starts service using a timestamp greater than max_ts to ensure monotonic increase.
[0033] However, comparing timestamps requires querying all nodes in the distributed system, which may take a long time and affect the availability of the backup timestamp service. In addition, since some nodes in the distributed system may have stopped working, it is impossible to obtain the maximum timestamp they have used, resulting in the maximum timestamp obtained by comparison not being the maximum timestamp used in the distributed system.
[0034] The maximum timestamp may be larger than the physical time of the backup timestamp service. Using a timestamp service larger than max_ts may cause difficulties in subsequent system maintenance. If you want to wait for the physical time of the backup timestamp service to reach max_ts, you need to suspend the service.
[0035] The timestamp generation method and device, electronic device, and computer-readable storage medium provided by the embodiments of the present disclosure are intended to solve at least one of the above technical problems in the prior art.
[0036] The timestamp generation method provided in the embodiments of the present disclosure can be executed by an electronic device such as a terminal device or a server, and the terminal device can be a vehicle-mounted device, a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory. Alternatively, the method can be executed by a server.
[0037] Figure 1 FIG. 2 is a flow chart showing a method for generating a timestamp according to an embodiment of the present disclosure. Figure 1 As shown in , the timestamp generation method provided by the embodiment of the present disclosure may include step S110, step S120, and step S130.
[0038] In step S110, a first physical time corresponding to a physical clock used by a primary timestamp service of the distributed system and a second physical time corresponding to a physical clock used by a backup timestamp service of the distributed system are obtained;
[0039] In step S120, a transition physical time is determined according to the first physical time and the second physical time;
[0040] In step S130, a timestamp is generated using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service.
[0041] For example, the timestamp generation method provided by the embodiments of the present disclosure can be used in a server running a backup timestamp service of a distributed system, and can be used to generate timestamps when a primary timestamp service fails and a backup timestamp service needs to be switched.
[0042] The generated timestamp may be a hybrid timestamp, which is determined by a physical clock and a logical clock and includes a value of a physical clock part, ie, a physical part value, and a value of a logical clock part, ie, a logical part value.
[0043] In some specific implementations, the unit of the physical part value may be milliseconds; the logical part value is an ordinary value, which may be a value in the range of non-negative integers.
[0044] When the main timestamp service is operating normally, the logical clock is reset when the physical time of the physical clock increases, or it can be reset at preset time intervals. If it is reset once per second, the logical clock increases by 1 every time a new event occurs in the distributed system during the time when the physical time of the physical clock does not change.
[0045] When a new event occurs in the distributed system, the physical time of the physical clock used by the primary timestamp service is obtained as the physical part value of the timestamp, and the logical time of the logical clock used by the primary timestamp service is obtained as the logical part value of the timestamp.
[0046] In some possible implementations, in step S110, during the normal service of the primary timestamp server, the physical time corresponding to the physical clock used by the primary timestamp service, ie, the physical time currently used by the primary timestamp service, can be acquired by monitoring.
[0047] When the primary timestamp service fails, the physical time currently used by the primary timestamp service is obtained, that is, the physical part value of the timestamp currently generated by the primary timestamp service, that is, the first physical time.
[0048] Since the timestamp generation method provided by the embodiment of the present disclosure can be used for a server running a backup timestamp service of a distributed system, the physical time corresponding to the physical clock used by the backup timestamp service of the distributed system, i.e., the second physical time, can be obtained directly by reading the physical clock of the server running the backup timestamp service of the distributed system.
[0049] In some possible implementations, in step S120, since the main timestamp service may have used the first physical time to generate a timestamp during normal service of the main timestamp service, in order to ensure that the timestamp generated thereafter is monotonically increasing compared to the timestamp generated previously, the first physical time can be increased by 1, and the time value of the first physical time plus 1 can be compared with the second physical time to determine the larger value as the transitional physical time.
[0050] In some possible implementations, in step S130, when a new distributed system event occurs, the transition physical time is used as the physical part value of the timestamp, and the logical time corresponding to the logical clock used by the backup timestamp service is used as the logical part value of the timestamp to generate a timestamp corresponding to the newly occurring distributed system event.
[0051] If the second physical time is greater than the first physical time plus 1, the second physical time is used as the physical part value of the timestamp. The physical part value of the timestamp must be greater than the physical part value of the timestamp generated during the normal service period of the main timestamp service, and conforms to monotonically increasing conditions.
[0052] Similarly, if the second physical time is less than the first physical time plus 1, the first physical time plus 1 is used as the physical part value of the timestamp. The physical part value of this timestamp is significantly larger than the physical part value of the timestamp generated during the normal service period of the main timestamp service, and conforms to monotonic increasing conditions.
[0053] In the timestamp generation method provided in the embodiments of the present invention, the timestamp after the failure of the primary timestamp service is determined directly according to the physical time corresponding to the physical clock used by the primary timestamp service and the physical time corresponding to the physical clock used by the backup timestamp service. The timestamp can be generated after the failure of the primary timestamp service without suspending the service, which does not affect the availability of the system and does not require querying all nodes of the distributed system. On the one hand, it can avoid the situation where the generated timestamp is not monotonically increasing due to the maximum timestamp obtained not being the maximum timestamp used in the distributed system. On the other hand, it can also reduce the occupation of system resources by access nodes and reduce the time waste caused by access nodes.
[0054] The following is a detailed introduction to the timestamp generation method provided by the embodiment of the present disclosure.
[0055] Figure 2 A flow chart showing an implementation method of determining a transition physical time according to a first physical time and a second physical time is shown. Figure 2 As shown, determining the transition physical time according to the first physical time and the second physical time may include step S210 and step S220.
[0056] In step S210, the transition time is determined according to the number of logical bits of the logical clock used by the backup timestamp service and the number of response requests per second of the distributed system;
[0057] In step S220, the larger value of the third physical time and the second physical time is determined as the transition physical time;
[0058] The third physical time is the sum of the first physical time and the transition time.
[0059] In some possible implementations, in step S210 and step S220, during the normal service of the main timestamp service, the main timestamp service may have used the first physical time to generate a timestamp. In order to ensure that the timestamp generated thereafter is monotonically increasing compared to the timestamp generated previously, the first physical time plus N (N is a positive integer) can be used as the third physical time, and the third physical time can be compared with the second physical time to determine the larger value as the transitional physical time. In this way, it can be ensured that the transitional physical time must be N larger than the first physical time used by the main timestamp service, thereby ensuring that the generated timestamp conforms to the monotonically increasing conformity.
[0060] Wherein, N is the transition time, and N can be determined according to the number of logical bits of the logical clock used by the backup timestamp service and the QPS (number of response requests per second) of the distributed system.
[0061] QPS is a measure of the amount of traffic processed by a distributed system within a specified time, and it is also a measure of distributed system events that may occur in a distributed system within a specified time; the higher the QPS of a distributed system, the more distributed system events that may occur in the distributed system per unit time.
[0062] The number of logical bits of the logical clock used by the backup timestamp service is a measure of the number of distributed system events that can be counted by the logical clock used by the backup timestamp service. The more logical bits there are, the more distributed system events that can be counted by the logical clock used by the backup timestamp service.
[0063] Generally speaking, the number of distributed system events that may occur in a distributed system within a unit of time will not exceed the number of distributed system events that can be counted by the logical clock, otherwise it may not be possible to ensure that the timestamps of distributed system events are monotonically increasing.
[0064] The closer the number of distributed system events that may occur in a distributed system within a unit time is to the number of distributed system events that can be counted by the logical clock, the closer the physical time corresponding to the distributed system events counted using the logical clock is to the real physical time.
[0065] After the main timestamp service fails, the timestamp is generated using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service. The logical clock can be added to count the distributed system events that occur. The closer the physical time corresponding to the distributed system events counted using the logical clock is to the real physical time, the shorter the real physical time can be used for the same transition physical time.
[0066] Therefore, the degree of proximity between the number of distributed system events that may occur in the distributed system within a unit time and the number of distributed system events that can be counted by the logical clock can be determined based on the ratio of QPS to the distributed system events that can be counted by the logical clock used by the backup timestamp service, and then the real physical time corresponding to each increase of 1 in the first physical time can be determined, and the transition time can be determined based on the time required for the backup timestamp service to prepare for providing the timestamp service, that is, the value of N is determined to provide the preparation time for the backup timestamp service to provide the timestamp service.
[0067] Figure 3 FIG. 1 shows a flow chart of an implementation method of generating a timestamp using the logical time corresponding to the logical clock used by the transitional physical time and the backup timestamp service when the transitional physical time is the third physical time. Figure 3 As shown, step S310 may be included.
[0068] In step S310, when a new event occurs in the distributed system, the transition physical time is used as the physical part value of the timestamp corresponding to the new event, the logical time corresponding to the logical clock is increased, and the increased logical time is used as the logical part value of the timestamp corresponding to the new event.
[0069] In some possible implementations, in step S310, the physical part value of the timestamp is fixed, and only the logical time corresponding to the logical clock used by the backup timestamp service as the logical part value of the timestamp is increased to achieve monotonic increase of the timestamp.
[0070] As new distributed system events, i.e., new events, continue to occur in the distributed system, the logical time of the logical clock will eventually increase to a maximum value, i.e., the number of new events that occurred after the failure of the primary timestamp service reaches the number of events that can be counted by the logical bits of the logical clock.
[0071] At this time, it is necessary to increase the physical part value of the timestamp, that is, to add the transition physical time as the physical part value of the timestamp. That is, when the logical time corresponding to the logical clock increases to the maximum value, increase the transition physical time and use the increased transition physical time as the physical part value of the timestamp corresponding to the new event.
[0072] At the same time, the logical clock needs to be reset, that is, the logical clock needs to increase from the beginning to generate a timestamp to ensure that the generated timestamp is monotonically increasing.
[0073] As mentioned above, since the number of distributed system events that may occur in a distributed system within a unit time will not exceed the number of distributed system events that can be counted by the logical clock, the real physical time corresponding to the increase of the transition physical time by 1 is less than 1.
[0074] In the process of using transitional physical time to generate timestamps, the physical time corresponding to the physical clock used by the backup timestamp service is also increasing. Since the real physical time corresponding to an increase of 1 in the transitional physical time is less than 1, the increase rate of the transitional physical time is less than the increase rate of the physical time corresponding to the physical clock used by the backup timestamp service.
[0075] Therefore, the physical time corresponding to the physical clock used by the backup timestamp service will catch up with the transitional physical time.
[0076] In some possible implementations, the physical time corresponding to the physical clock used by the backup timestamp service is obtained. If the physical time corresponding to the physical clock used by the backup timestamp service is greater than the physical part value of the timestamp corresponding to the new event, the physical time corresponding to the physical clock used by the backup timestamp service is used as the physical part value of the timestamp corresponding to the new event.
[0077] That is to say, after the physical time corresponding to the physical clock used by the backup timestamp service catches up with the transition physical time, the physical clock used by the backup timestamp service is still used to generate timestamps. That is to say, the physical clock and logical clock used by the backup timestamp service are used to generate timestamps, which returns to the method of generating timestamps in the relevant technology.
[0078] That is, when a new event occurs in the distributed system, the physical time of the physical clock used by the backup timestamp service is obtained as the physical part value of the timestamp, and the logical time of the logical clock used by the backup timestamp service is obtained as the logical part value of the timestamp.
[0079] When the backup timestamp service operates normally, the logical clock used by the backup timestamp service is reset when the physical time of the physical clock increases. During the time when the physical time of the physical clock does not change, the logical clock increases by 1 every time a new event occurs in the distributed system.
[0080] That is, the timestamp service is changed from the primary timestamp service to the backup timestamp service.
[0081] In some possible implementations, if the transition physical time is the second physical time, that is, the physical time corresponding to the physical clock used by the backup timestamp service is larger, then directly switching to the backup timestamp service can still achieve monotonic increase of timestamps.
[0082] Therefore, when the transition physical time is the second physical time, you can directly switch to the backup timestamp service, that is, when a new event occurs in the distributed system, obtain the physical time of the physical clock used by the backup timestamp service as the physical part value of the timestamp, and obtain the logical time of the logical clock used by the backup timestamp service as the logical part value of the timestamp.
[0083] The following is a specific example of a method for generating a timestamp provided by the embodiment of the present disclosure.
[0084] Figure 4 A schematic diagram showing the switching relationship of timestamp services in the timestamp generation method of an embodiment of the present disclosure is shown. Figure 4 As shown, when the physical time corresponding to the physical clock used by the primary timestamp service is 6, the primary timestamp service fails and needs to be switched to the backup timestamp service. The physical time corresponding to the physical clock used by the backup timestamp service is 4.
[0085] Then the backup timestamp service will use the physical time 7 (6+1), and start providing timestamp services by adding the logical time corresponding to the logical clock to ensure that the timestamp is monotonically increasing. Before the physical time corresponding to the physical clock used by the backup timestamp service reaches 7, 7 is used as the physical time to provide services. After the physical time corresponding to the physical clock used by the backup timestamp service reaches 7, the actual physical time is used to provide services.
[0086] Based on Figure 1 The same principle as shown in the method, Figure 5 A schematic diagram of the structure of a timestamp generating device provided by an embodiment of the present disclosure is shown. Figure 5 As shown, the timestamp generating device 50 may include:
[0087] A monitoring module 510, configured to obtain a first physical time corresponding to a physical clock used by a primary timestamp service of the distributed system and a second physical time corresponding to a physical clock used by a backup timestamp service of the distributed system;
[0088] A time comparison module 520, configured to determine a transition physical time according to the first physical time and the second physical time;
[0089] The timestamp generation module 530 is used to generate a timestamp using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service.
[0090] In the timestamp generating device provided in the embodiment of the present disclosure, the timestamp after the failure of the primary timestamp service is determined directly according to the physical time corresponding to the physical clock used by the primary timestamp service and the physical time corresponding to the physical clock used by the backup timestamp service. The timestamp can be generated after the failure of the primary timestamp service without suspending the service, which does not affect the availability of the system and does not require querying all nodes of the distributed system. On the one hand, it can avoid the situation where the generated timestamp is not monotonically increasing due to the maximum timestamp obtained not being the maximum timestamp used in the distributed system. On the other hand, it can also reduce the occupation of system resources by access nodes and reduce the time waste caused by access nodes.
[0091] It can be understood that the above modules of the timestamp generation device in the embodiment of the present disclosure have the function of realizing Figure 1 The functions of the corresponding steps of the timestamp generation method in the embodiment shown in . The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. The above modules can be software and / or hardware, and the above modules can be implemented separately or integrated with multiple modules. For the functional description of each module of the above timestamp generation device, please refer to Figure 1The corresponding description of the timestamp generation method in the embodiment shown in will not be repeated here.
[0092] In some possible implementations, the time comparison module includes: a first comparison unit, used to determine the transition time based on the number of logical bits of the logical clock used by the backup timestamp service and the number of response requests per second of the distributed system; a second comparison unit, used to determine the larger value of the third physical time and the second physical time as the transition physical time; wherein the third physical time is the sum of the first physical time and the transition time.
[0093] In some possible implementations, the first comparison unit is used to: determine the number of events of the distributed system that can be counted by the logical clock according to the number of logical bits; determine the transition time according to the ratio of the number of response requests per second to the number of events of the distributed system.
[0094] In some possible implementations, the timestamp includes a physical part value and a logical part value; a timestamp generation module is used to, when the transition physical time is a third physical time and a new event occurs in the distributed system, use the transition physical time as the physical part value of the timestamp corresponding to the new event, increase the logical time corresponding to the logical clock, and use the increased logical time as the logical part value of the timestamp corresponding to the new event.
[0095] In some possible implementations, the timestamp generation device also includes a transition module, which is used to: when the logical time corresponding to the logical clock increases to a maximum value, increase the transition physical time, and use the increased transition physical time as the physical part value of the timestamp corresponding to the new event.
[0096] In some possible implementations, the timestamp generation device also includes a backup timestamp module, which is used to: obtain the physical time corresponding to the physical clock used by the backup timestamp service, and when the physical time corresponding to the physical clock used by the backup timestamp service is greater than the physical part value of the timestamp corresponding to the new event, use the physical time corresponding to the physical clock used by the backup timestamp service as the physical part value of the timestamp corresponding to the new event.
[0097] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision, disclosure and application of user personal information involved comply with the provisions of relevant laws and regulations, take necessary confidentiality measures, and do not violate public order and good morals.
[0098] In the technical solution of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0099] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0100] The electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the timestamp generation method provided in the embodiment of the present disclosure.
[0101] Compared with the prior art, the electronic device directly determines the timestamp after the failure of the primary timestamp service according to the physical time corresponding to the physical clock used by the primary timestamp service and the physical time corresponding to the physical clock used by the backup timestamp service. The timestamp can be generated after the failure of the primary timestamp service without suspending the service, which does not affect the availability of the system and does not require querying all nodes of the distributed system. On the one hand, it can avoid the situation where the generated timestamp is not monotonically increasing due to the maximum timestamp obtained not being the maximum timestamp used in the distributed system. On the other hand, it can also reduce the occupation of system resources by access nodes and reduce the time waste caused by access nodes.
[0102] The readable storage medium is a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the timestamp generation method provided in the embodiment of the present disclosure.
[0103] Compared with the prior art, the readable storage medium directly determines the timestamp after the failure of the primary timestamp service according to the physical time corresponding to the physical clock used by the primary timestamp service and the physical time corresponding to the physical clock used by the backup timestamp service. The timestamp can be generated after the failure of the primary timestamp service without suspending the service, which does not affect the availability of the system and does not require querying all nodes of the distributed system. On the one hand, it can avoid the situation where the generated timestamp is not monotonically increasing due to the maximum timestamp obtained not being the maximum timestamp used in the distributed system. On the other hand, it can also reduce the occupation of system resources by access nodes and reduce the time waste caused by access nodes.
[0104] The computer program product includes a computer program, and when the computer program is executed by a processor, the time stamp generation method provided in the embodiment of the present disclosure is implemented.
[0105] Compared with the prior art, the computer program product directly determines the timestamp after the failure of the primary timestamp service based on the physical time corresponding to the physical clock used by the primary timestamp service and the physical time corresponding to the physical clock used by the backup timestamp service. The timestamp can be generated after the failure of the primary timestamp service without suspending the service, without affecting the availability of the system and without querying all nodes of the distributed system. On the one hand, it can avoid the situation where the generated timestamp is not monotonically increasing due to the maximum timestamp obtained not being the maximum timestamp used in the distributed system. On the other hand, it can also reduce the occupation of system resources by access nodes and reduce the time waste caused by access nodes.
[0106] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0107] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0108] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0109] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as a timestamp generation method. For example, in some embodiments, the timestamp generation method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the timestamp generation method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the timestamp generation method in any other appropriate manner (e.g., by means of firmware).
[0110] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0111] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0112] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0113] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0114] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0115] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0116] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0117] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A timestamp generation method, comprising: Obtaining a first physical time corresponding to a physical clock used by a primary timestamp service of a distributed system and a second physical time corresponding to a physical clock used by a backup timestamp service of the distributed system; Determine a transition physical time according to the first physical time and the second physical time; A timestamp is generated using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service.
2. The method according to claim 1, wherein: The determining the transition physical time according to the first physical time and the second physical time comprises: Determine the transition time according to the number of logical bits of the logical clock used by the backup timestamp service and the number of response requests per second of the distributed system; Determine a larger value between a third physical time and the second physical time as the transition physical time; The third physical time is the sum of the first physical time and the transition time.
3. The method according to claim 2, wherein: The determining of the transition time according to the number of logical bits of the logical clock used by the backup timestamp service and the number of response requests per second of the distributed system comprises: Determine the number of events of the distributed system that can be counted by the logical clock according to the number of logical bits; The transition time is determined according to the ratio of the number of response requests per second of the distributed system to the number of events.
4. The method according to claim 2, wherein: The timestamp includes a physical part value and a logical part value; In the case where the transition physical time is the third physical time, generating a timestamp using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service includes: When a new event occurs in the distributed system, the transition physical time is used as the physical part value of the timestamp corresponding to the new event, the logical time corresponding to the logical clock is increased, and the increased logical time is used as the logical part value of the timestamp corresponding to the new event.
5. The method according to claim 4, further comprising: When the logical time corresponding to the logical clock increases to a maximum value, the transition physical time is increased, and the increased transition physical time is used as the physical part value of the timestamp corresponding to the new event.
6. The method according to claim 4, further comprising: Obtain the physical time corresponding to the physical clock used by the backup timestamp service. If the physical time corresponding to the physical clock used by the backup timestamp service is greater than the physical part value of the timestamp corresponding to the new event, use the physical time corresponding to the physical clock used by the backup timestamp service as the physical part value of the timestamp corresponding to the new event.
7. A timestamp generating device, comprising: A monitoring module, used to obtain a first physical time corresponding to a physical clock used by a primary timestamp service of a distributed system, and a second physical time corresponding to a physical clock used by a backup timestamp service of the distributed system; A time comparison module, configured to determine a transition physical time according to the first physical time and the second physical time; The timestamp generation module is used to generate a timestamp using the transition physical time and the logical time corresponding to the logical clock used by the backup timestamp service.
8. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-6.
10. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 6.