Identifier generation method and apparatus, electronic device, and storage medium
Patent Information
- Application Number
- CN202610938225.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-26
- Publication Date
- 2026-08-18
AI Technical Summary
[0004]本申请实施例的目的是提供一种标识符生成方法、装置、电子设备及存储介质,能够解决传统的雪花算法在时钟回拨场景下,生成的标识符重复、不唯一,导致服务中断或业务异常的问题
[0015]The identifier generation method provided in this application responds to an identifier request sent by a client. Based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within that day, the current logical timestamp is calculated. The current logical timestamp is compared with the previous logical timestamp to determine the server's current operating state. If the server is currently in a clock rollback state, a first sequence number is generated through a secure sequence pool. Based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client. This application converts physical time into a logical timestamp, enabling the generation of identifiers with longer durations and achieving epoch-level tolerance for clock rollback. When a clock rollback state is detected, a unique sequence number is allocated from an independent, pre-allocated secure sequence number pool. Through a spatially isolated secure sequence pool, strong disaster recovery capabilities are provided for clock rollback scenarios, avoiding the generation of duplicate identifiers and ensuring that globally unique identifiers are still generated during clock rollback. The identifier duplication rate is reduced to 0%, achieving the uniqueness of distributed identifiers across all scenarios and further improving service availability and business reliability during clock rollback.
Smart Images

Figure CN122601638A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of distributed systems technology, specifically relating to an identifier generation method, apparatus, electronic device, and storage medium. Background Technology With the development of distributed technology, distributed systems have become the standard architecture for handling large-scale data and high-concurrency requests. In distributed systems, generating globally unique identifiers (IDs) is crucial for tracking and distinguishing each data item.
[0002] Currently, among the many algorithms for generating identifiers, the Snowflake algorithm generates identifiers with fewer bits, making it the most widely used algorithm for identifier generation. The ID generated by the Snowflake algorithm is a 64-bit binary long integer, with the timestamp generated based on the local clock of the working machine. Multiple identifiers will be generated at the same timestamp, and these identifiers need to be distinguished by different sequence numbers, with the different sequence numbers increasing over time.
[0003] However, since the timestamp is generated based on the server's local clock, when the server clock rolls back, that is, the server clock goes back from the current time to a previous time, the timestamp used to generate the identifier will also roll back. If the identifier is still generated according to the rolled-back timestamp, the generated identifier may be the same as the identifier generated at that time before the clock rollback, causing the identifier to be duplicated and not unique, which may lead to service interruption or business abnormality. Summary of the Invention
[0004] The purpose of this application is to provide an identifier generation method, apparatus, electronic device, and storage medium that can solve the problem that the traditional snowflake algorithm generates duplicate and non-unique identifiers in clock rollback scenarios, leading to service interruption or business anomalies.
[0005] To solve the above-mentioned technical problems, this application is implemented as follows: In a first aspect, embodiments of this application provide an identifier generation method, the method comprising: In response to the identifier request sent by the client, the current logical timestamp is calculated based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day; The current logical timestamp is compared with the previous logical timestamp to determine the current running status of the server; If the server is currently in a clock rollback state, a first sequence number is generated through the security sequence pool; Based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client.
[0006] Optionally, the current logical timestamp is calculated based on the number of days corresponding to the server-based epoch counter and the compressed millisecond offset within the day, including: Obtain the server's current physical time and a preset physical time anchor point, and use the current physical time and the physical time anchor point to calculate the millisecond offset within a day; The millisecond offset within a day is compressed using a preset compression factor to obtain the compressed millisecond offset within a day. The current logical timestamp is obtained by bit concatenating the number of days corresponding to the epoch counter with the compressed millisecond offset within the day.
[0007] Optionally, comparing the current logical timestamp with the previous logical timestamp to determine the current operating state of the server includes: If the current logical timestamp is less than or equal to the previous logical timestamp, then the server is determined to be in a clock rollback state. If the current logical timestamp is greater than the previous logical timestamp, then the server is determined to be in normal operating condition.
[0008] Optionally, generating a first sequence number through a secure sequence pool when the server is currently in a clock rollback state includes: If the server is currently in a clock rollback state, freeze the current logical timestamp; Acquire the safe sequence pool lock and read the current index value of the safe sequence pool; Based on the current index value, obtain the sequence number of the secure sequence pool; Release the secure sequence pool lock and use the sequence number as the first sequence number.
[0009] Optionally, before releasing the security sequence pool lock and using the sequence number as the first sequence number, the method further includes: The current index value of the secure sequence pool is compared with a preset index value threshold. If the current index value is greater than or equal to the index value threshold, it is determined that the index value of the safe sequence pool has been exhausted, and the current index value of the safe sequence pool is reset to the initial index value for storage. If the current index value is less than the index value threshold, the current index value of the safe sequence pool is increased by a preset step size during storage.
[0010] Optionally, the method further includes: If the index value of the secure sequence pool is exhausted, the server will be switched to a forced time synchronization state. Send a forced time synchronization request to the time server to calibrate the server's current physical time.
[0011] Optionally, the method further includes: If the server is currently in normal operation, a second serial number is generated using the server's serial counter; Based on the current logical timestamp and the second sequence number, a second identifier is generated and returned to the client.
[0012] Secondly, embodiments of this application provide an identifier generation apparatus, the apparatus comprising: The response request module is used to respond to the identifier request sent by the client. It calculates the current logical timestamp based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day. The status determination module is used to compare the current logical timestamp with the previous logical timestamp to determine the current running status of the server. The first generation module is used to generate a first sequence number through a secure sequence pool when the server is currently in a clock rollback state. The first identifier module is used to generate a first identifier based on the previous logical timestamp and the first sequence number, and return the first identifier to the client.
[0013] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the identifier generation method as described in the first aspect.
[0014] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the identifier generation method as described in the first aspect.
[0015] The identifier generation method provided in this application responds to an identifier request sent by a client. Based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within that day, the current logical timestamp is calculated. The current logical timestamp is compared with the previous logical timestamp to determine the server's current operating state. If the server is currently in a clock rollback state, a first sequence number is generated through a secure sequence pool. Based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client. This application converts physical time into a logical timestamp, enabling the generation of identifiers with longer durations and achieving epoch-level tolerance for clock rollback. When a clock rollback state is detected, a unique sequence number is allocated from an independent, pre-allocated secure sequence number pool. Through a spatially isolated secure sequence pool, strong disaster recovery capabilities are provided for clock rollback scenarios, avoiding the generation of duplicate identifiers and ensuring that globally unique identifiers are still generated during clock rollback. The identifier duplication rate is reduced to 0%, achieving the uniqueness of distributed identifiers across all scenarios and further improving service availability and business reliability during clock rollback.
[0016] The above description is merely an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, specific embodiments of this application are given below. Attached Figure Description
[0017] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 This is a flowchart illustrating the steps of an identifier generation method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the architecture of an identifier generation method provided in an embodiment of this application; Figure 3 This is a flowchart illustrating the secure sequence pool in an identifier generation method provided in an embodiment of this application; Figure 4 This is a flowchart illustrating an identifier generation method provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an identifier generation device provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0019] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0020] The identifier generation method, apparatus, electronic device, and storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0021] Reference Figure 1 The flowchart illustrates the steps of an identifier generation method provided in an embodiment of this application. The method may include: Step 101: In response to the identifier request sent by the client, calculate the current logical timestamp based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day.
[0022] In this embodiment of the application, the ID generation server (hereinafter referred to as the server) responds to the identifier request sent by the client and calculates the current logical timestamp based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day. (Referring to...) Figure 2 This diagram illustrates the architecture of an identifier generation method provided in an embodiment of this application. A client initiates a business request. During processing, the application server calls an ID generation server to obtain a unique identifier (ID). The ID generation server includes a time collector, an ID generation engine, and a state storage. The time collector selects the most reliable time from multiple clock sources, such as NTP, RTC, and the system clock. The ID generation engine executes the ID synthesis algorithm, such as an identifier variant of the Snowflake algorithm. The state storage records the current logical timestamp, sequence number step, and worker machine ID. The client requests the identifier ID from the ID generation server through the application server. The ID generation server returns the unique identifier ID to the application server, which then continues processing the client's business and stores the identifier ID in a database.
[0023] The NTP (Network Time Protocol) server, acting as the clock source, is a core device or service node used for time synchronization in computer networks. The NTP server uses Coordinated Universal Time (UTC) for time correction, synchronizing computer clocks on the network to millisecond-level accuracy. The RTC (Real-Time Clock) module is a dedicated integrated circuit for precise timing. Its core function is to provide stable timing for seconds, minutes, hours, days, months, weeks, and years, and to maintain uninterrupted timing via a backup battery after a mains power failure. The time acquisition unit periodically obtains time from the NTP and simultaneously reads the RTC module as a backup, comparing the system clock, NTP, and RTC to select the most appropriate physical time.
[0024] In this embodiment, the epoch counter is used to represent the number of days that have elapsed since the custom base date (epoch). The millisecond offset within a day refers to the time offset from the fixed starting point of the day to the current moment, in milliseconds. It can be calculated from the server's current physical time and the preset physical time anchor. The server's current physical time refers to the actual time from a certain standard reference point to the present, provided by hardware clocks such as RTC modules and NTP servers. The preset physical time anchor is the current UTC (Coordinated Universal Time) millisecond-level physical timestamp obtained when the server is first started.
[0025] It should be noted that the ID generated by the Snowflake algorithm is a 64-bit binary long integer. One bit represents the sign bit, 41 bits represent the timestamp, 10 bits represent the worker machine ID, and 12 bits represent the sequence number. In this embodiment, the timestamp-related bits in the identifier are divided into two parts, using a 15-bit and 26-bit timestamp generation mechanism. The current logical timestamp is obtained by concatenating the epoch counter's corresponding day with the compressed millisecond offset within that day. Specifically, the high 15 bits of the 41-bit timestamp in the identifier to be generated are allocated to the epoch counter's corresponding day (epoch_id), and the low 26 bits of the 41-bit timestamp in the identifier to be generated are allocated to the compressed millisecond offset within that day. The compressed_ms variable is shifted, so epoch_id, which is the number of days corresponding to the epoch counter, automatically increments by 1 every 24 hours. It is persistently stored and only increases, never decreases. Even if the physical time is rolled back more than 24 hours, epoch_id will not decrease. It occupies the high 15 bits and never rolls back at the day level, thus achieving cross-day rollback protection. The persistently stored epoch counter epoch_id globally only increases and never decreases. Even if the physical time is rolled back to the previous generation, epoch_id still maintains its current value. The minimum value of the logical timestamp logical_ts of the current generation, i.e., epoch_id << 26 | 0, is necessarily greater than the maximum value of the logical timestamp of the previous generation, i.e., (epoch_id - 1) << 26 | 0 x 3FFFFFF, ensuring that the cross-generation timestamp is strictly monotonically increasing.
[0026] Step 102: Compare the current logical timestamp with the previous logical timestamp to determine the current running status of the server.
[0027] In this embodiment, the current operating state of the server is determined by comparing the current logical timestamp with the previous logical timestamp. The current operating state is the server's time state, providing an accurate basis for subsequent clock rollback processing. The current logical timestamp is the logical time value generated by the server at the current moment, obtained by bit-concatenating the number of days corresponding to the epoch counter with the compressed millisecond offset within that day. The previous logical timestamp is the logical time value generated and recorded by the server during the last response to an ID request or the last synchronization. The method for determining the previous logical timestamp is the same as the method for generating the current logical timestamp.
[0028] In this embodiment, if the current logical timestamp is less than or equal to the previous logical timestamp, the server is determined to be in a clock rollback state; if the current logical timestamp is greater than the previous logical timestamp, the server is determined to be in a normal operating state. In the normal operating state, the logical timestamp advances normally; in the clock rollback state, a clear backward movement of the logical timestamp or a failure to advance the logical timestamp is detected.
[0029] Step 103: If the server is currently in a clock rollback state, generate the first sequence number through the secure sequence pool.
[0030] In this embodiment, when the server is currently in a clock rollback state, a first sequence number is generated through a secure sequence pool. The secure sequence pool is a pre-allocated, thread-safe sequence number storage structure used to provide monotonically increasing sequence numbers instead of logical timestamps when the server is in a clock rollback state. This ensures the server can still operate normally during periods of physical time unreliability, thereby generating unique, non-repeating distributed identifiers. Furthermore, the spatially isolated secure sequence pool avoids the impact of abnormal sequence counters on its availability.
[0031] In this embodiment, when the server is currently in a clock rollback state, the current logical timestamp is frozen to prevent the use of the backward logical timestamp for ID generation. A secure sequence pool lock is acquired, and the current index value of the secure sequence pool is read. The secure sequence pool lock is a lock used to protect the critical section of the secure sequence pool, ensuring that only one thread can enter the sequence number reading at any given time. The current index value of the secure sequence pool is an integer value used to record the position of the next sequence number to be allocated in the secure sequence pool. It always points to the storage location of the next sequence number to be allocated in the secure sequence pool. Based on the current index value, the sequence number corresponding to the position pointed to by the current index value is retrieved from the secure sequence pool to obtain the first sequence number.
[0032] Step 104: Based on the previous logical timestamp and the first sequence number, generate the first identifier and return the first identifier to the client.
[0033] In this embodiment, after generating the first sequence number through the secure sequence pool, a first identifier is generated based on the previous logical timestamp and the first sequence number, and the first identifier is returned to the client. Specifically, the valid previous logical timestamp, the first sequence number, the sign bit, and the worker machine ID are concatenated to generate a globally unique first identifier, i.e., a distributed ID. Finally, the first identifier is returned to the client, ensuring the uniqueness and temporal order of the identifier.
[0034] The identifier generation method provided in this application responds to an identifier request sent by a client. Based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within that day, the current logical timestamp is calculated. The current logical timestamp is compared with the previous logical timestamp to determine the server's current operating state. If the server is currently in a clock rollback state, a first sequence number is generated through a secure sequence pool. Based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client. This application converts physical time into a logical timestamp, enabling the generation of identifiers with longer durations and achieving epoch-level tolerance for clock rollback. When a clock rollback state is detected, a unique sequence number is allocated from an independent, pre-allocated secure sequence number pool. Through a spatially isolated secure sequence pool, strong disaster recovery capabilities are provided for clock rollback scenarios, avoiding the generation of duplicate identifiers and ensuring that globally unique identifiers are still generated during clock rollback. The identifier duplication rate is reduced to 0%, achieving the uniqueness of distributed identifiers across all scenarios and further improving service availability and business reliability during clock rollback.
[0035] In some embodiments of this application, step 101, which calculates the current logical timestamp based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day, may specifically include the following steps: S11, obtain the server's current physical time and preset physical time anchor point, and calculate the millisecond offset within the day using the current physical time and physical time anchor point; S12, use a preset compression factor to compress the millisecond offset within the day to obtain the compressed millisecond offset within the day; S13, concatenate the number of days corresponding to the epoch counter with the compressed millisecond offset within the day to obtain the current logical timestamp.
[0036] In this embodiment, the timestamp portion of the identifier generated by the traditional Snowflake algorithm is 41 bits with millisecond precision, capable of representing approximately 69 years. To address the time rollback issue in the current Snowflake algorithm-generated identifiers (i.e., distributed IDs) and ensure the global uniqueness of the identifier ID required by the client in various business scenarios, this embodiment divides the timestamp-related bits into two parts. Based on a 15-bit and 26-bit timestamp generation mechanism, the number of days corresponding to the epoch counter and the compressed millisecond offset within the day are concatenated to obtain the current logical timestamp. Specifically, the high 15 bits of the 41-bit timestamp in the identifier to be generated are allocated to the number of days corresponding to the epoch counter (epoch_id), and the low 26 bits of the 41-bit timestamp in the identifier to be generated are allocated to the compressed millisecond offset within the day (compressed_ms).
[0037] The epoch counter represents the number of days elapsed since a custom reference date. It is allocated 15 bits, which in binary can represent 0 to 32767 days, a duration of approximately 89.8 years (32767 days ≈ 89.8 years), longer than the 69 years represented by the traditional snowflake algorithm. The millisecond offset within a day refers to the time offset from a fixed starting point to the current moment, measured in milliseconds. It can be calculated using the server's current physical time and a preset physical time anchor. The server's current physical time refers to the actual time from a certain standard reference point to the present, provided by hardware clocks such as RTC modules or NTP servers. The preset physical time anchor is the current UTC millisecond-level physical timestamp obtained when the server first starts. UTC time is a globally unified standard time, unaffected by time zones or daylight saving time, and serves as the reference for all time zones. The physical time anchor is permanently stored in non-volatile storage after server startup and will not be modified by subsequent server system restarts or power outages. It is used to calculate the time offset with the server system startup time as the standard reference point, avoiding direct impact of global absolute time rollback on logical time.
[0038] In this embodiment, the current physical time and a preset physical time anchor point of the server are obtained. The millisecond offset within a day is calculated using the current physical time and the physical time anchor point. It is known that a day consists of 24h × 3600s × 1000ms = 86,400,000 milliseconds. Specifically, the millisecond offset within a day is calculated using the following formula: ms_in_day=(physical_ts-base_ts)%86400000 Where ms_in_day is the millisecond offset within a day, physical_ts is the current physical time, which is the timestamp converted from the current system physical time. It is unreliable raw data because it may be rolled back due to human table adjustments, NTP synchronization errors, or hardware clock failures. base_ts is the preset physical time anchor point, which can be the current UTC millisecond-level physical timestamp obtained when the server starts for the first time. 86400000 is the total number of milliseconds within a day, and % is the modulo operator.
[0039] Since the lower 26 bits of the 41-bit timestamp of the identifier to be generated can represent a maximum of... =67108864. Since 67108864 is much smaller than 86400000, it cannot accurately represent every millisecond within a day. Therefore, it is necessary to reduce the time precision. A preset compression factor is used to compress the millisecond offset within a day, resulting in the compressed millisecond offset within a day. The preset compression factor is used to reduce the precision of the millisecond offset within a day, making it suitable for a 26-bit range. The compression factor can be set to 1.288, meaning 86400000 ÷ 67108864 is approximately equal to 1.288. Therefore, by using the preset compression factor to compress the millisecond offset within a day, the 86400000 milliseconds of the day are compressed to 67108864 increments that can be represented by 26 bits, resulting in the compressed millisecond offset within a day. Specifically, the compressed millisecond offset within a day is calculated using the following formula: compressed_ms=floor(ms_in_day / 1.288)=67108864 Where compressed_ms is the millisecond offset within a day, floor() is the floor function, ms_in_day is the millisecond offset within a day, and 1.288 is the compression factor. The goal is to map ms_in_day to the entire range [0, 67, 108, 864] that can be represented by a 26-bit binary number.
[0040] In this embodiment, the number of days corresponding to the epoch counter and the compressed millisecond offset within the day are concatenated bitwise to obtain the current logical timestamp. This means merging the day-level epoch counter value and the compressed millisecond offset within the day into a single logical timestamp. The logical timestamp is a time value maintained internally by the server and is not necessarily equal to the physical time. It is used to ensure consistency of time sequence or for specific business logic. Specifically, the current logical timestamp can be represented by the following formula: logical_ts=(epoch_id<<26)|compressed_ms Where logical_ts is the current logical timestamp; epoch_id is the number of days corresponding to the epoch counter, which automatically increments by 1 every 24 hours, is persistently stored and only increases, never decreases, even if the current physical time is rolled back more than 24 hours, epoch_id will not decrease, and it will never roll back at the day level; << is the left shift operator, used to shift binary bits to the left and fill the right side with 0; | is the bitwise OR operator, used to align two binary bits, the result is 1 as long as one of them is 1; compressed_ms is the compressed millisecond offset within the day.
[0041] This application's embodiments convert physical time into logical timestamps, which can generate identifiers with longer durations, enabling epoch-level tolerable clock rollback and providing robust disaster recovery capabilities for clock rollback scenarios.
[0042] In some embodiments of this application, step 102, comparing the current logical timestamp with the previous logical timestamp to determine the current running state of the server, may specifically include the following steps: S21, if the current logical timestamp is less than or equal to the previous logical timestamp, then the server is determined to be in a clock rollback state. S22. If the current logical timestamp is greater than the previous logical timestamp, then the server is determined to be in normal operating condition.
[0043] This application provides a clock rollback detection mechanism. By comparing the current logical timestamp `logical_ts` with the previous logical timestamp `last_logical_ts`, the current operating state of the server is determined. The current operating state is the server's time state, providing an accurate basis for subsequent clock rollback processing. The server monitors the change between the current logical timestamp and the previous logical timestamp in real time. If the current logical timestamp is less than or equal to the previous logical timestamp, it is determined that the server is currently in a clock rollback state, thereby triggering the corresponding clock rollback processing. Conversely, if the current logical timestamp is greater than the previous logical timestamp, it is determined that the server is currently in a normal operating state, and the conventional distributed ID generation process is followed, thereby promptly detecting the server's clock rollback status.
[0044] The current logical timestamp, `logical_ts`, is the logical time value generated by the server at the current moment. It is obtained by concatenating the number of days corresponding to the epoch counter with the compressed millisecond offset within that day. The previous logical timestamp, `last_logical_ts`, is the logical time value generated and recorded by the server during the last response to an ID request or the last synchronization. The method for determining the previous logical timestamp is the same as the method for generating the current logical timestamp, and will not be elaborated here. Clock rollback status includes two situations: logical time has clearly regressed and logical time has not advanced. Therefore, if the current logical timestamp is less than or equal to the previous logical timestamp, it is determined that the server is currently in clock rollback status. If the logical time is strictly monotonically increasing and meets the expected behavior, that is, the current logical timestamp is greater than the previous logical timestamp, it is determined that the server is currently in normal operation status, can process business requests normally, update the security sequence pool index value, and the current logical timestamp is valid. Therefore, the previous logical timestamp is updated to the current logical timestamp for the next timestamp comparison.
[0045] It should be noted that in this embodiment, state machine switching logic is set for the server's operating state. The state machine switching logic is a control mechanism for disaster recovery execution, used to define how the server switches its working mode when it detects clock rollback, and how it resumes normal operation after the clock rollback anomaly is recovered. In specific implementation, the state machine switching logic includes three states: NORMAL state, BACKWARD state, and BACKWARD_EXHAUST state when the sequence number in the security sequence pool is exhausted. Among them, the NORMAL state is the normal operation state, where the logical timestamp advances normally, and the security sequence pool is not used or has been reset. The BACKWARD state is the clock rollback state, where the server enters disaster recovery mode when a clear rollback of the logical timestamp or a failure to advance the logical time is detected. The BACKWARD_EXHAUST state is the forced time synchronization state, which breaks the deadlock by forced time synchronization and prevents the server from getting stuck in the clock rollback state.
[0046] In this embodiment, when the current logical timestamp is detected to be less than or equal to the previous logical timestamp, the server switches from the NORMAL state to the BACKWARD state. When the current logical timestamp is detected to be greater than the previous logical timestamp, the server returns from the BACKWARD state to the NORMAL state. If the index value of the security sequence pool reaches the preset maximum value in the BACKWARD state, that is, the sequence number is exhausted, a forced time synchronization request is triggered to calibrate the physical time and restore the monotonicity of the logical time.
[0047] This application embodiment accurately and promptly detects clock rollback status by judging logical timestamps, so as to provide strong disaster recovery capabilities for clock rollback scenarios, avoid generating duplicate identifiers, and ensure that a globally unique identifier can still be generated during clock rollback.
[0048] In some embodiments of this application, step 103, generating a first sequence number through a secure sequence pool when the server is currently in a clock rollback state, may specifically include the following steps: S31, if the server is currently in a clock rollback state, freeze the current logical timestamp; S32, acquire the safe sequence pool lock, and read the current index value of the safe sequence pool; S33, Based on the current index value, obtain the sequence number of the safe sequence pool; S34, release the safe sequence pool lock and use the sequence number as the first sequence number.
[0049] In this embodiment, the secure sequence pool is a pre-allocated, thread-safe sequence number storage structure used to provide monotonically increasing sequence numbers instead of logical timestamps when the server is in a clock rollback state. This ensures the server can still operate normally during periods when physical time is unreliable, thereby generating unique and non-repeating distributed identifiers. Specifically, when the server is currently in a clock rollback state, the current logical timestamp is first frozen (i.e., the unreliable current logical timestamp is frozen). The current index value of the secure sequence pool is obtained through a locking mechanism. Based on the current index value, the sequence number in the secure sequence pool is obtained. After obtaining the sequence number in the secure sequence pool, the secure sequence pool lock is released promptly, allowing other threads to obtain the sequence number. The sequence number obtained this time is used as the first sequence number, which occupies 12 bits in the identifier.
[0050] In this embodiment, when the server is currently in a clock rollback state, the current logical timestamp is frozen, and updates to the logical timestamp are stopped. The system maintains the last valid previous logical timestamp before the clock rollback occurred, preventing the use of the backward logical timestamp for ID generation. A safe sequence pool lock is acquired, and the current index value of the safe sequence pool is read. The safe sequence pool lock is used to protect the critical section of the safe sequence pool, ensuring that only one thread can enter the critical section at any given time. The critical section includes operations such as reading the current index value, calculating the new index value, retrieving the sequence number, and saving the new index value. Locks can take various forms, such as spin locks, CAS (Compare-And-Swap) atomic operations, or read-write locks. Spin locks are suitable for scenarios with extremely short lock holding times. CAS is a lock-free atomic operation that compares a memory value with an expected value and updates it when they are equal, achieving thread-safe non-blocking operation. Read-write locks allow multiple threads to read simultaneously, but only one thread can write. These will not be elaborated upon further here.
[0051] In this embodiment, the current index value of the secure sequence pool is an integer value used to record the position of the next sequence number to be allocated in the secure sequence pool. It always points to the storage location of the next sequence number to be allocated in the secure sequence pool, and the current index value is automatically incremented after each allocation. Specifically, after acquiring the secure sequence pool lock, the current index value of the secure sequence pool can be read using atomic operations, such as index = atomic_load(index), which atomically reads the current index value. The current index value index ranges from 0 to N, where N is the index value threshold. The index value threshold is determined based on the first sequence number occupying 12 bits in the identifier, and its value is [value missing]. =4096.
[0052] In this embodiment, since the current index value always points to the storage location of the next sequence number to be allocated in the secure sequence pool, the sequence number of the secure sequence pool can be obtained based on the current index value, and the sequence number corresponding to the position pointed to by the current index value can be retrieved from the secure sequence pool by executing the command seq=pool[index], where seq is the sequence number of the secure sequence pool, index is the current index value, and pool is a pre-generated sequence number array, where each sequence number is globally unique and monotonically increasing.
[0053] It should be noted that the safe sequence pool can adopt the following data structures, including fixed arrays, bitmaps, hash maps, or concurrent queues. Fixed arrays are used to represent a pre-allocated sequence pool of fixed size. Bitmaps use bits to indicate whether a sequence number has been allocated. Hash maps are used to dynamically allocate sequence numbers. Concurrent queues pre-generate sequence numbers and put them into the queue, which can reduce lock contention. Through the monotonically increasing characteristic of the sequence numbers in the safe sequence pool, a reliable time substitute source is provided for the server during clock rollback. At the same time, the locking mechanism ensures thread safety in high-concurrency scenarios.
[0054] In the clock rollback state, this application embodiment allocates a unique sequence number from an independent, pre-allocated security sequence number pool. Through the spatially isolated security sequence pool, it provides strong disaster recovery capabilities for clock rollback scenarios, avoids the generation of duplicate identifiers, and ensures that globally unique identifiers can still be generated during clock rollback, reducing the identifier duplication rate to 0%. This achieves the uniqueness of distributed identifiers in all scenarios and further improves the availability of services and the reliability of business during clock rollback.
[0055] In some embodiments of this application, before releasing the secure sequence pool lock and using the sequence number as the first sequence number in step S34, the following may also be included: S35, compare the current index value of the safe sequence pool with the preset index value threshold; S36, If the current index value is greater than or equal to the index value threshold, it is determined that the index value of the safe sequence pool has been exhausted, and the current index value of the safe sequence pool is reset to the initial index value for storage; S37. If the current index value is less than the index value threshold, the current index value of the safe sequence pool is increased by a preset step size for storage.
[0056] In this embodiment, the current index value indicates the position of the currently allocated sequence number. The sequence numbers in the secure sequence pool are finite, and a threshold value is set for each index value. To prevent the secure sequence pool from running out of sequence numbers, which could lead to duplicate allocations of the same sequence number and affect the uniqueness of distributed identifiers, this embodiment compares the current index value of the secure sequence pool with the preset index value threshold. If the current index value is greater than or equal to the index value threshold, it is determined that the secure sequence pool has run out of index numbers. The current index value of the secure sequence pool is then reset to the initial index value, and the new index value is written back to the secure sequence pool. The next sequence number allocation will start from the beginning. If the current index value is less than the index value threshold, and the secure sequence pool still has available sequence numbers, the current index value of the secure sequence pool is increased by a preset step size. This ensures that the next sequence number allocation is based on the latest stored current index value in the secure sequence pool, thus guaranteeing the cyclical use and monotonically increasing allocation of sequence numbers in the secure sequence pool.
[0057] In the specific implementation, if the current index value is greater than or equal to the index value threshold, it is determined that the index value of the safe sequence pool has been exhausted. The current index value of the safe sequence pool is reset to the initial index value, which can be 0. If the current index value is less than the index value threshold, and the safe sequence pool still has available sequence numbers, the current index value of the safe sequence pool is increased by a preset step size, that is, the index value of the safe sequence pool is updated by index=(index+1)%N, where N is the index value threshold and % is the modulo operator, so that when allocating sequence numbers next time, the sequence numbers in the safe sequence pool can be used cyclically and monotonically increased.
[0058] This application embodiment compares the current index value with a preset index value threshold, increments the index value stepwise when the index value is not exhausted, and resets it to the initial value and triggers the subsequent recovery process when the index value is exhausted, thereby ensuring the cyclic use of the safe sequence pool and the monotonic and unique allocation of the sequence number.
[0059] As a specific implementation of an embodiment of this application, refer to Figure 3This document illustrates a flowchart of a secure sequence pool in an identifier generation method provided in this application. Specifically, when `physical_ts` is less than or equal to `last_physical_ts`, it indicates that the current logical timestamp is smaller than the logical timestamp recorded during the last ID generation, meaning a clock rollback has occurred. The server is in a clock rollback state. In systems that rely on timestamps to generate globally unique IDs, clock rollback can lead to ID duplication or disordered order. Therefore, a pre-generated secure sequence pool is used to allocate sequence numbers. The `def allocate_safe_seq()` function first acquires the secure sequence pool lock using the `while atomic test and set(lock):pass` method. Through atomic operations, the current index value of the secure sequence pool, `index = atomic_load(index)`, is read, ensuring multi-threaded safety and preventing multiple threads from simultaneously taking the same sequence number.
[0060] In this embodiment, the sequence number is determined based on the current index value. This can be achieved by executing `seq=pool[index]` or `seq=reserve[index]`, where `index=(index+1)%N`, retrieving the sequence number corresponding to the current index value from the pre-generated safe sequence pool. It is then determined whether the current index value is greater than or equal to the index value threshold. If so, it indicates that the safe sequence pool has exhausted its sequence numbers. To facilitate the allocation of unique sequence numbers in the next iteration, the current index value of the safe sequence pool is reset to its initial index value (e.g., 0). If not, it indicates that the safe sequence pool has a surplus of sequence numbers to support the next allocation. To facilitate the allocation of unique sequence numbers in the next iteration, the index value position of the safe sequence pool needs to be updated by increasing the current index value by a preset step size. This can be done by updating the index value position of the safe sequence pool using `index=(index+1)%N`, where N is the index value threshold and % is the modulo operator. Finally, store the updated index value of the secure sequence pool, release the secure sequence pool lock using atomic_clear(lock), return the assigned secure sequence number, combine them to obtain a valid, unique, and non-repeating identifier, and return it to the client that requested the ID, replacing the identifier obtained by combining timestamps that are no longer available due to time rollback.
[0061] In some embodiments of this application, the method further includes: If the index value of the safe sequence pool is exhausted, the server will be switched to forced time synchronization state; Send a forced time synchronization request to the time server to calibrate the server's current physical time.
[0062] In this embodiment, when the security sequence pool index value is exhausted, the server enters a forced time synchronization state, namely the BACKWARD_EXHAUST state. In this state, the server proactively initiates a forced time synchronization request to the time server to obtain the standard time and calibrate the local physical time. This calibration operation advances the current physical time to the correct time, thereby satisfying the clock rollback recovery conditions. After time synchronization is complete, the server can exit the forced time synchronization state, switch back to normal operation, reset the security sequence pool, and resume normal operation. This serves as a fallback recovery in the clock rollback state, ensuring that the server can automatically recover even in extreme circumstances.
[0063] In practice, by actively switching states and initiating forced time synchronization, the physical time is calibrated, creating conditions for the system to recover from the callback state to normal operation. If the index value of the security sequence pool is exhausted, i.e., the current index value is greater than or equal to the index value threshold, the server is switched to the forced time synchronization state, i.e., the BACKWARD_EXHAUST state. During the forced time synchronization state, no new sequence number allocation requests are accepted. A forced time synchronization request is initiated to the time server to calibrate the server's current physical time. The time server can be an NTP server or an RTC module. The NTP server (Network Time Protocol) is a core device or service node used to realize time synchronization in computer networks. The NTP server performs time correction through Coordinated Universal Time (UTC) and can synchronize computer clocks in the network to millisecond-level accuracy. The RTC module (Real-Time Clock) is a dedicated integrated circuit for precise timekeeping. Its core function is to provide stable timekeeping for seconds, minutes, hours, days, months, weeks, and years, and to maintain uninterrupted timekeeping through a backup battery after the main power supply fails.
[0064] The forced time synchronization state set in this application embodiment serves as a fallback recovery in the clock rollback state, ensuring that the server can still automatically recover under extreme conditions. This provides strong disaster recovery capabilities for clock rollback scenarios, guarantees that a globally unique identifier can still be generated during clock rollback, and improves the availability of services and the reliability of business during clock rollback.
[0065] In some embodiments of this application, the method may further include: If the server is currently operating normally, a second sequence number is generated using the server's sequence counter. Based on the current logical timestamp and the second sequence number, generate a second identifier and return the second identifier to the client.
[0066] In this embodiment, when the server is in normal operation, indicating that the current logical timestamp is accurate and valid, a second identifier can be generated using the snowflake algorithm's identifier generation mechanism and returned to the client. The server first obtains the calculated valid current logical timestamp and increments it using a sequence counter to obtain a second sequence number. The current logical timestamp, the second sequence number, the sign bit, and the worker machine ID are then concatenated to generate a globally unique second identifier. Finally, the second identifier is returned to the client, ensuring both identifier uniqueness and temporal order while achieving high generation performance.
[0067] This application embodiment generates a second identifier by using the current logical timestamp and the auto-incrementing sequence number of the sequence counter. The identifier is kept unique globally and naturally increments according to the time trend. In conjunction with the safe sequence pool allocation sequence number mechanism under the abnormal state of clock rollback, the identifier generation strategy is adaptive under different operating states, achieving a balance between high performance and high reliability.
[0068] To facilitate understanding of the identifier generation method provided in the embodiments of this application by those skilled in the art, please refer to Figure 4 The diagram illustrates a flowchart of an identifier generation method provided in an embodiment of this application. In a specific implementation, in response to an identifier request sent by a client, the current physical time of the server is obtained. The current logical timestamp is calculated by calculating the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day through timestamp generation. Based on the server's time state machine, it determines whether the current running state is normal. If so, it further checks whether the current logical timestamp is greater than the previous logical timestamp. If so, it means the server time is normal, and the current logical timestamp is updated and stored as the previous logical timestamp for comparison when generating the identifier next time. The index value of the security sequence pool is reset, and a second sequence number is generated using the server's sequence counter. Based on the current logical timestamp and the second sequence number, a second identifier is generated and returned to the client. If not, it means the server is in a clock rollback state, and the current logical timestamp needs to be frozen, the index value of the security sequence pool needs to be reset, an independently pre-allocated security sequence pool needs to be enabled, and a new ID is generated by incrementing the sequence number. That is, a first sequence number is generated using the security sequence pool. Finally, based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client. The secure sequence pool is independent of the regular sequence counter, and their address spaces do not overlap, for example, memory offsets 0x1000~0x2000 and 0x3000~0x4000.
[0069] Reference Figure 5The diagram shows a schematic representation of an identifier generation apparatus provided in an embodiment of this application. The apparatus includes: The response request module 201 is used to respond to the identifier request sent by the client and calculate the current logical timestamp based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day. The status determination module 202 is used to compare the current logical timestamp with the previous logical timestamp to determine the current running status of the server; The first generation module 203 is used to generate a first sequence number through a security sequence pool when the server is currently in a clock rollback state. The first identifier module 204 is used to generate a first identifier based on the previous logical timestamp and the first sequence number, and return the first identifier to the client.
[0070] Optionally, the response request module 201 includes: The first calculation submodule is used to obtain the current physical time and the preset physical time anchor point of the server, and to calculate the millisecond offset within the day using the current physical time and the physical time anchor point. The compression submodule is used to compress the millisecond offset within the day using a preset compression factor to obtain the compressed millisecond offset within the day. The splicing submodule is used to perform bit splicing between the number of days corresponding to the epoch counter and the compressed millisecond offset within the day to obtain the current logical timestamp.
[0071] Optionally, the state determination module 202 includes: The first determining submodule is used to determine that the server is currently in a clock rollback state if the current logical timestamp is less than or equal to the previous logical timestamp. The second determining submodule is used to determine that the server is currently in normal operating condition if the current logical timestamp is greater than the previous logical timestamp.
[0072] Optionally, the first generation module 203 includes: The freeze submodule is used to freeze the current logical timestamp when the server is currently in a clock rollback state. The read submodule is used to acquire the safe sequence pool lock and read the current index value of the safe sequence pool; The second calculation submodule is used to obtain the sequence number of the safe sequence pool based on the current index value; The release submodule is used to release the security sequence pool lock, using the sequence number as the first sequence number.
[0073] Optionally, the first generation module 203 further includes: The comparison submodule is used to compare the current index value of the secure sequence pool with a preset index value threshold. The first processing submodule is configured to determine that the index value of the safe sequence pool has been exhausted if the current index value is greater than or equal to the index value threshold, and reset the current index value of the safe sequence pool to the initial index value for storage. The second processing submodule is used to increase the current index value of the safe sequence pool by a preset step size if the current index value is less than the index value threshold.
[0074] Optionally, the device further includes: A state switching module is used to switch the server to a forced time synchronization state if the index value of the security sequence pool has been exhausted. The time calibration module is used to send a forced time synchronization request to the time server to calibrate the server's current physical time.
[0075] Optionally, the device further includes: The second generation module is used to generate a second serial number by means of the server's serial counter when the server is currently in normal operation. The second identifier module is used to generate a second identifier based on the current logical timestamp and the second sequence number, and return the second identifier to the client.
[0076] The identifier generation apparatus provided in this application embodiment can implement each process of the identifier generation method implemented in the above embodiments of this application. To avoid repetition, it will not be described again here.
[0077] The identifier generation device provided in this application responds to an identifier request sent by a client. Based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within that day, it calculates the current logical timestamp. The current logical timestamp is compared with the previous logical timestamp to determine the server's current operating state. If the server is currently in a clock rollback state, a first sequence number is generated through a secure sequence pool. Based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client. This application converts physical time into a logical timestamp, enabling the generation of identifiers with longer durations and achieving epoch-level tolerance for clock rollback. When a clock rollback state is detected, a unique sequence number is allocated from an independent, pre-allocated secure sequence number pool. Through a spatially isolated secure sequence pool, it provides robust disaster recovery capabilities for clock rollback scenarios, avoiding the generation of duplicate identifiers and ensuring that globally unique identifiers are still generated during clock rollback. This reduces the identifier duplication rate to 0%, achieving the uniqueness of distributed identifiers across all scenarios and further improving service availability and business reliability during clock rollback.
[0078] Reference Figure 6 This application also provides an electronic device, such as... Figure 6 As shown, it includes a processor 301, a communication interface 302, a memory 303, and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304. Processor 301, memory 303 for storing processor-executable instructions; The processor 301 is configured to execute the instructions to implement the identifier generation method described above.
[0079] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0080] The communication interface is used for communication between the aforementioned terminal and other devices.
[0081] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0082] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0083] In another embodiment provided in this application, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements any of the identifier generation methods described in the above embodiments.
[0084] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0085] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0086] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0087] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method for generating identifiers, characterized in that, The method includes: In response to the identifier request sent by the client, the current logical timestamp is calculated based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day; The current logical timestamp is compared with the previous logical timestamp to determine the current running status of the server; If the server is currently in a clock rollback state, a first sequence number is generated through the security sequence pool; Based on the previous logical timestamp and the first sequence number, a first identifier is generated and returned to the client.
2. The method according to claim 1, characterized in that, The current logical timestamp is calculated by using the number of days corresponding to the server-based epoch counter and the compressed millisecond offset within the day, including: Obtain the server's current physical time and a preset physical time anchor point, and use the current physical time and the physical time anchor point to calculate the millisecond offset within a day; The millisecond offset within a day is compressed using a preset compression factor to obtain the compressed millisecond offset within a day. The current logical timestamp is obtained by bit concatenating the number of days corresponding to the epoch counter with the compressed millisecond offset within the day.
3. The method according to claim 1, characterized in that, The step of comparing the current logical timestamp with the previous logical timestamp to determine the current operating status of the server includes: If the current logical timestamp is less than or equal to the previous logical timestamp, then the server is determined to be in a clock rollback state. If the current logical timestamp is greater than the previous logical timestamp, then the server is determined to be in normal operating condition.
4. The method according to any one of claims 3, characterized in that, The step of generating a first sequence number through a secure sequence pool when the server is currently in a clock rollback state includes: If the server is currently in a clock rollback state, freeze the current logical timestamp; Acquire the safe sequence pool lock and read the current index value of the safe sequence pool; Based on the current index value, obtain the sequence number of the secure sequence pool; Release the secure sequence pool lock and use the sequence number as the first sequence number.
5. The method according to claim 4, characterized in that, Before releasing the security sequence pool lock and using the sequence number as the first sequence number, the method further includes: The current index value of the secure sequence pool is compared with a preset index value threshold. If the current index value is greater than or equal to the index value threshold, it is determined that the index value of the safe sequence pool has been exhausted, and the current index value of the safe sequence pool is reset to the initial index value for storage. If the current index value is less than the index value threshold, the current index value of the safe sequence pool is increased by a preset step size during storage.
6. The method according to claim 5, characterized in that, The method further includes: If the index value of the secure sequence pool is exhausted, the server will be switched to a forced time synchronization state. Send a forced time synchronization request to the time server to calibrate the server's current physical time.
7. The method according to claim 1, characterized in that, The method further includes: If the server is currently in normal operation, a second serial number is generated using the server's serial counter; Based on the current logical timestamp and the second sequence number, a second identifier is generated and returned to the client.
8. An identifier generation apparatus, characterized in that, The device includes: The response request module is used to respond to the identifier request sent by the client. It calculates the current logical timestamp based on the number of days corresponding to the server's epoch counter and the compressed millisecond offset within the day. The status determination module is used to compare the current logical timestamp with the previous logical timestamp to determine the current running status of the server. The first generation module is used to generate a first sequence number through a secure sequence pool when the server is currently in a clock rollback state. The return identifier module is used to generate a first identifier based on the previous logical timestamp and the first sequence number, and return the first identifier to the client.
9. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to execute the instructions to implement the identifier generation method as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that, A computer program is stored on the readable storage medium, which, when executed by a processor, implements the identifier generation method as described in any one of claims 1 to 7.