Method for generating a unique identifier and computing device

By generating a unique identifier through a combination of generator identifier, time period, and sequence number, the problems of global uniqueness and efficiency are solved. This achieves unique identifier generation and efficient generation even under time fluctuations, while reducing storage and transmission resource requirements.

CN116401242BActive Publication Date: 2025-10-24XFUSION DIGITAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310146593.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-21
Publication Date
2025-10-24
Estimated Expiration
2043-02-21

AI Technical Summary

Technical Problem

Existing technologies struggle to guarantee global uniqueness when generating unique identifiers, especially when generator time fluctuates, which can easily lead to duplicate identifiers. Furthermore, existing methods are labor-intensive and inefficient.

Method used

A unique identifier is generated by obtaining the generator identifier, the current time, and the time period. The combination of the generator identifier and the time period ensures the global uniqueness of the identifier. The serial number ensures the incremental trend of the identifier, and a circular queue is used to store the space to prevent false overflow.

Benefits of technology

It can still guarantee the global uniqueness of unique identifiers even when the generator time fluctuates, saving manpower, improving generation efficiency, and reducing storage and transmission resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116401242B_ABST
    Figure CN116401242B_ABST
Patent Text Reader

Abstract

Embodiments of the present application relate to the computer field, in particular to a unique identifier generation method, device and equipment. The method comprises: obtaining a generator identifier, a current time and a first serial number; determining a first time period and a start time of a second time period based on the current time; determining the first time period or the second time period as a generation period of the unique identifier based on the current time and the start time of the second time period; and generating a unique identifier according to the generator identifier, the generation period and the first serial number. The method can guarantee the global uniqueness of the unique identifier.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a unique identifier generation method and device. BACKGROUND

[0002] With the development of information technology (IT), a large amount of data needs to be managed. In particular, public clouds, private clouds, data centers, large distributed systems, etc. will generate a large amount of data every day, and the newly generated data needs to be identified to distinguish from other data, so as to facilitate data management.

[0003] Data can be managed as an object. A unique identifier (ID) is used to uniquely identify an object in a computer application system, so the unique identifier used to identify different objects must be different. In addition, a large amount of data requires a large number of unique identifiers, and in order to save storage resources, the shorter the length of the unique identifier, the better. SUMMARY

[0004] Embodiments of the present application provide a unique identifier generation method, device and equipment. The global uniqueness of the unique identifier can be ensured.

[0005] In a first aspect, a unique identifier generation method is provided, the method comprising: obtaining a generator identifier, a current time and a first sequence number; determining a first time period and a start time of a second time period based on the current time; determining the first time period or the second time period as a generation period of the unique identifier based on the current time and the start time of the second time period; and generating a unique identifier according to the generator identifier, the generation period and the first sequence number.

[0006] The method determines the time period by the current time, and divides the unique identifiers generated in different time periods into different generation periods, and ensures that the unique identifiers generated in the same generation period are different by the sequence number, thereby reducing the dependence of the global uniqueness of the unique identifier on the generation time, and ensuring that the unique identifier is not repeated when the time of the generator fluctuates (for example, the clock of the generator appears to be rewound or advanced). In the method, the generator can automatically obtain an identifier that can be distinguished from other generators, which saves manpower and improves efficiency while ensuring the global uniqueness of the unique identifier using the identifier of the generator.

[0007] In a possible implementation, the determining of the first time period or the second time period as the generation period of the unique identifier based on the current time and the start time of the second time period comprises: if the current time is less than the start time of the second time period, taking the first time period as the generation period of the unique identifier. The second time period is the next time period of the first time period.

[0008] In this implementation, the generation period of the unique identifier generated later is later, so that the generated unique identifier conforms to an increasing trend, facilitating storage of the unique identifier.

[0009] In a possible implementation, the generating of the unique identifier according to the generator identifier, the generation period and the first serial number comprises: adding a first preset value to the first serial number to generate a second serial number; and generating the unique identifier according to the generator identifier, the first time period and the second serial number.

[0010] In this implementation, the serial numbers of the unique identifiers in the same generation period are increasing, so that the generated unique identifier conforms to an increasing trend, facilitating storage of the unique identifier.

[0011] In a possible implementation, before the generating of the unique identifier according to the generator identifier, the first time period and the second serial number, the method further comprises: determining whether the second serial number exceeds a threshold; if the second serial number does not exceed the threshold, generating the unique identifier according to the generator identifier, the first time period and the second serial number; and if the second serial number exceeds the threshold, updating the identifier of the generator and reinitializing the second serial number as a third serial number, and generating the unique identifier according to the updated generator identifier, the first time period and the third serial number.

[0012] In this implementation, when available serial numbers are exhausted, the generator identifier can be updated, and the updated generator identifier can be used to guarantee the uniqueness of the unique identifier.

[0013] In a possible implementation, the determining of the first time period or the second time period as the generation period of the unique identifier based on the current time and the start time of the second time period comprises: if the current time is greater than the start time of the second time period, taking the second time period as the generation period of the unique identifier.

[0014] In a possible implementation, the generating the unique identifier according to the generator identifier, the generation period and the first sequence number comprises: reinitializing the first sequence number as a fourth sequence number; and generating the unique identifier according to the generator identifier, the second time period and the fourth sequence number.

[0015] In a possible implementation, after the generating the unique identifier according to the generator identifier, the generation period and the initialized sequence number, the method further comprises: storing the unique identifier into a preset storage space.

[0016] In a possible implementation, before the storing the unique identifier into the preset storage space, the method further comprises: determining whether the preset storage space has available space; and if the preset storage space has the available space, storing the unique identifier into the available space.

[0017] In a possible implementation, the preset storage space is a first-in-first-out circular queue; and the available space is a vacant slot in the circular queue.

[0018] In this implementation, the storage space adopts the form of the circular queue to store the unique identifier, which can prevent the phenomenon of pseudo overflow of the storage space used to store the unique identifier.

[0019] In a possible implementation, the unique identifier comprises a symbol bit, the generator identifier, the generation period and a sequence number.

[0020] In a second aspect, a computing device is provided, comprising: a memory and a processor; the memory and the processor are electrically connected; wherein the memory is configured to store an executable program; and the processor is configured to run the executable program to enable the computing device to perform the method according to the first aspect.

[0021] In a third aspect, a unique identifier generating apparatus is provided, comprising: an obtaining module configured to obtain a generator identifier, a current time and a first sequence number; a first determining module configured to determine a first time period and a start time of a second time period based on the current time; a second determining module configured to determine the first time period or the second time period as a generation period of the unique identifier based on the current time and the start time of the second time period; and a generating module configured to generate the unique identifier according to the generator identifier, the generation period and the first sequence number.

[0022] In a fourth aspect, a computer program product containing instructions is provided, which, when executed by a computing device, enables the computing device to perform the method according to the first aspect.

[0023] In a fifth aspect, a computer-readable storage medium is provided, including computer program instructions, when the computer program instructions are executed by a computing device, the computing device performs the method provided in the first aspect.

[0024] The beneficial effects of the second aspect to the fifth aspect can refer to the beneficial effects of the first aspect described above, and will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0025] Figure 1 A structural schematic diagram of a computing system is provided for the embodiments of the present application;

[0026] Figure 2A A structural schematic diagram of a unique identifier is provided for the embodiments of the present application;

[0027] Figure 2B A structural schematic diagram of a unique identifier is provided for the embodiments of the present application;

[0028] Figure 3 A flowchart of a unique identifier generation method is provided for the embodiments of the present application;

[0029] Figure 4 A structural schematic diagram of a generator is provided for the embodiments of the present application;

[0030] Figure 5 A flowchart of a unique identifier generation method is provided for the embodiments of the present application;

[0031] Figure 6 A structural schematic diagram of a unique identifier generation device is provided for the embodiments of the present application;

[0032] Figure 7 A structural schematic diagram of a computing device is provided for the embodiments of the present application. DETAILED DESCRIPTION

[0033] The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments.

[0034] In the description of the embodiments of the present application, “one embodiment” or “some embodiments” means that the specific features, structures or characteristics described in connection with the embodiment are included in one or more embodiments of the present application. Therefore, the statements “in one embodiment”, “in some embodiments”, “in other some embodiments”, “in further some embodiments” appearing in different places in the present application do not necessarily all refer to the same embodiment, but mean “one or more but not all embodiments”, unless otherwise specifically emphasized.

[0035] In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or, for example, A / B can represent A or B; "and / or" herein is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist together, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0036] In the description of the embodiments of the present application, the terms "first", "second" are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. The terms "include", "contain", "have" and their variants mean "include but are not limited to", unless otherwise specifically emphasized.

[0037] The unique identifier is a string with a certain length, which is widely used in e-commerce platforms, advertising platforms, public clouds, private clouds and other computer systems. For example, the unique identifier is used as an order number to identify the related data of a certain transaction. For another example, the unique identifier is used as a commodity number to identify the related data of a certain commodity. For another example, the unique identifier is used as a billing number to identify the related data of a certain consumption. And so on.

[0038] The unique identifier facilitates the management of data, for example, the required data can be quickly retrieved through the unique identifier, the association of different data is established, and the flow of data between different services is tracked.

[0039] Generally speaking, in order to meet the needs of large computer systems (public cloud, private cloud, e-commerce platform, etc.) for data management, the unique identifier needs to meet the following requirements.

[0040] 1. Global uniqueness: within the same computing system, the unique identifier is not repeated, that is, there are no two identical unique identifiers.

[0041] 2. Tendency to increase: that is, the value of the unique identifier generated later is greater than the value of the unique identifier generated earlier. Specifically, the current mainstream database uses B+ tree to store data, and the unique identifier of the data is stored as the primary key of the data together with the data. If the primary keys of the data stored in sequence are in order, the data write performance can be improved.

[0042] 3. Short length of unique identifier: the shorter the length of the unique identifier, the less storage resources it occupies when stored, and the less bandwidth it occupies when transmitted.

[0043] In one scheme, a universally unique identifier (UUID) is used as the unique identifier. The UUID has a length of 128 bits, which is relatively long and occupies a large amount of storage resources and bandwidth. In addition, the UUIDs are unordered, and the writing efficiency is low when the data is stored, and the query efficiency is also low when the data is queried.

[0044] In another scheme, a long unique identifier is generated by a snowflake algorithm. In this scheme, different unique identifiers are distinguished by the generation time of the unique identifier, the number of the data center where the unique identifier is generated, the number of the machine where the unique identifier is generated, and a sequence number. Since the generation time of the unique identifier is used to distinguish different unique identifiers, when the time of the machine where the unique identifier is generated fluctuates, duplicate unique identifiers can be generated, and the global uniqueness of the unique identifier cannot be guaranteed. In addition, the number of the data center and the number of the machine need to be manually configured, and need to be ensured not to be duplicated (if the number of the data center and the number of the machine are duplicated, duplicate unique identifiers can be generated), which consumes a large amount of manpower and is low in efficiency.

[0045] Embodiments of the present application provide a unique identifier generation method performed by a generator. The method reduces the dependence of the global uniqueness of the unique identifier on the generation time, and can guarantee that the unique identifier is not duplicated when the time of the generator fluctuates (for example, the clock of the generator appears to be rewound or advanced). In addition, in the method, the generator can automatically obtain an identifier that can be distinguished from other generators, which saves manpower and improves efficiency while ensuring the global uniqueness of the unique identifier using the identifier of the generator.

[0046] Next, the unique identifier generation method provided by embodiments of the present application will be described.

[0047] Figure 1 A computing system 100 provided by embodiments of the present application is shown. The computing system 100 can include a plurality of computing devices. For example, in the computing system 100, the plurality of computing devices can adopt a distributed architecture. In some embodiments, the computing system 100 is a public cloud, a private cloud, a data center, an e-commerce platform, an advertising platform, etc. Embodiments of the present application do not limit the specific implementation form of the computing system 100.

[0048] As Figure 1As shown, the computing system 100 may include at least one unique identifier demand end, such as a unique identifier demand end 111 and / or a unique identifier demand end 112. A unique identifier demand end refers to an end that can manage or generate data, which requires a unique identifier to identify the data to facilitate data management. In some embodiments, the unique identifier demand end can be implemented in software. In one example, the unique identifier demand end can be one or more processes or threads. The embodiment of the present application does not specifically limit the implementation form of the unique identifier demand end. The unique identifier demand end can be deployed to a computing device with data processing capabilities. Among them, different unique identifier demand ends can be deployed in different computing devices in the computing system 100, or they can be deployed in the same computing device. Among them, the computing device used to deploy the unique identifier demand end can be a physical machine, such as a server. The computing device used to deploy the unique identifier demand end can also be a virtual computing device, such as a virtual machine (VM) or a container. The embodiment of the present application does not specifically limit the deployment form of the unique identifier demand end.

[0049] like Figure 1 As shown, the computing system 100 may include at least one generator, such as generator 121 and / or generator 122, etc. The generator refers to a device for generating a unique identifier, which is used to generate a unique identifier. In some embodiments, the generator may be implemented in software. In one example, the generator may be one or more processes or threads. The embodiment of the present application does not specifically limit the implementation form of the generator. The generator may be deployed to a computing device with data processing capabilities. Different generators may be deployed in different computing devices in the computing system 100, or they may be deployed in the same computing device. The computing device used to deploy the generator may be a physical machine, such as a server. The computing device used to deploy the generator may also be a virtual computing device, such as a virtual machine or a container. The embodiment of the present application does not specifically limit the deployment form of the unique identifier demand side.

[0050] When a unique identifier is needed, the unique identifier demander can request a unique identifier from the generator. For example, the unique identifier demander sends a unique identifier request to the generator. The generator that receives the unique identifier request can respond to the unique identifier request and send the unique identifier it generates to the unique identifier demander.

[0051] In some embodiments, as Figure 1As shown, when the computing system 100 includes multiple generators, the computing system 100 may further include a load balancer 130. The load balancer 130 is configured to distribute multiple unique identifier requests from a unique identifier demander to different generators, so that when the generation capacity of a single generator is insufficient to meet the needs of the unique identifier demander, the unique identifier demander can obtain unique identifiers from multiple generators, thereby obtaining the unique identifiers in a timely manner.

[0052] Continue reading Figure 1 The computing system 100 includes a generator identification source 150. The generator identification source 150 is used to assign generator identifications to generators. The generator identifications assigned by the generator identification source 150 to different generators are different, and the values ​​of the generator identifications assigned by the generator identification source 150 are increasing according to the order in which the generator identifications are assigned. For example, if the generator identification A1 is assigned to the generator first and the generator identification A2 is assigned to the generator later, the value of the generator identification A1 is smaller than the value of the generator identification A2.

[0053] In some embodiments, the generator identification source 150 stores data B1 that can be modified by the generator. After the data B1 is modified by the generator, the generator identification source 150 can assign a version number to the modified data B1, and the version number is incremental, that is, after the old version of the data B1 is modified, a new version of the data B1 is obtained, and the new version of the data B1 has a version number. The value of the version number of the new version of the data B1 is greater than the value of the version number of the old version of the data B1. Among them, the version number of the data B1 is used as a generator identifier, thereby ensuring that the value of the generator identifier assigned first is less than the generator identifier assigned later, that is, the generator identifier conforms to the increasing trend.

[0054] In one example of this embodiment, after the generator is started and before it begins generating a unique identifier, the generator may send a generator identification request to the generator identification source 150. The generator identification source 150 may respond to the generator identification request and send the generator identification to the generator, i.e., assign the generator identification to the generator. In one example, the generator identification request may be a request to modify data B1. The generator identification source 150 may respond to the modification request, modify the data B1, obtain a version number of the updated data B1, and then assign the updated version number of the data B1 to the generator as the generator identification.

[0055] Whenever a generator starts, it can request a generator ID from the generator ID source 150, which then assigns it a generator ID. Generator IDs are assigned in increments. Therefore, the generator ID can also be referred to as a startup sequence number, which indicates or implies the startup order of the generators.

[0056] In one example of this embodiment, the generator identifier source 150 can specifically be a distributed key value (KV) store (ETCD) for the most critical data of a distributed system. The ETCD is a reliable data storage system, and can provide data access (e.g., data modification operations). The ETCD can achieve reliable data storage and data access through distributed locks, leader election, and write barriers.

[0057] With continued reference to Figure 1 The computing system 100 includes a clock source 140. The clock source 140 can also be referred to as a clock. In some embodiments, the clock source 140 can be a network time protocol (NTP) clock source. After the generator is started, and before the generator starts to generate the unique identifier, the generator can obtain a clock signal from the clock source 140, and set the clock of the generator according to the obtained clock signal.

[0058] The above example introduces the computing system 100 that can be used to implement the unique identifier generation method. Next, the structure of the unique identifier that can be generated by the unique identifier generation method provided by the embodiments of the present application is introduced.

[0059] With reference to Figure 2A The structure of the unique identifier generated by the embodiments of the present application includes a generator identifier field that carries a generator identifier, a generation period field that carries a generation period, and a sequence number field that carries a sequence number.

[0060] The generator identifier refers to the identifier of the generator that generates the unique identifier, and is specifically introduced above and will not be described herein again. The length of the generator identifier field is N2 bits, where N2 is an integer greater than 0, and N2 is the minimum number of bits required to represent or carry one generator identifier.

[0061] The generation period refers to the time period to which the generation time of the unique identifier belongs, and is determined by the generation time of the unique identifier and the start time of the time period. Specifically, when the generation time t1 of the unique identifier is greater than or equal to the start time of the time period T1 and less than the start time of the time period T2, the time period to which the generation time t1 of the unique identifier belongs is the time period T1. In some embodiments, the length of the time period can be a preset value, such as 1 day, 1 hour, 30 minutes, etc.

[0062] The starting time of the first time period after the generator is started is the initial time which is set in advance. The initial time is an earlier time relative to the starting time of the generator, and even if the clock of the generator is rewound, the rewound time will not be earlier than the initial time. For example, if the starting time of the generator is 2022-6-7 00:00:00, the initial time can be 2020-1-1 00:00:00. In this way, after the generator is started, even if the clock is rewound, the generation time of the unique identifier belongs to the first time period, reducing the dependence of the global uniqueness of the unique identifier on the generation time.

[0063] In some embodiments, the time difference between the time represented by the clock signal obtained from the clock source 140 after the generator is started and the initial time can be used to represent the first time period after the generator is started. For example, if the time represented by the clock signal obtained from the clock source 140 is 2022-6-7 00:00:00, and the initial time is 2020-1-1 00:00:00, the first time period after the generator is started can be represented as 889 days.

[0064] For the second time period after the generator is started and subsequent time periods, the time difference between the starting time of the time period and the initial time can be used to represent the time period. For example, the length of the time period can be set to 1 day, the starting time of the second time period can be 2022-6-8 00:00:00, and the initial time can be 2020-1-1 00:00:00. The second time period after the generator is started can be represented as the 890th day.

[0065] In some embodiments, when the length of the time period is 1 day, the starting time of the second time period after the generator is started and subsequent time periods is 00:00:00. After the generator is started, the starting time of the second time period can be determined according to the time represented by the clock signal obtained from the clock source 140. Specifically, the 00:00:00 of the second day (i.e., the next day) of the time represented by the clock signal obtained from the clock source 140 can be used as the starting time of the second time period. Accordingly, the 00:00:00 of the third day (i.e., the day after tomorrow) of the time represented by the clock signal obtained from the clock source 140 can be used as the starting time of the third time period, and so on. For example, if the time represented by the clock signal obtained from the clock source 140 is 2022-6-7 14:30:11, the second day of this time is 2022-6-8, and the starting time of the second time period is 2022-6-8 00:00:00. The third day of this time is 2022-6-9, and the starting time of the third time period is 2022-6-9 00:00:00. And so on.

[0066] In some embodiments, when the length of the time period is 1 hour, the starting time of the second time period and the subsequent time periods after the generator is started is 00:00:00. After the generator is started, the starting time of the second time period can be determined according to the time represented by the clock signal obtained from the clock source 140. Specifically, the starting time of the second time period can be set as 00:00:00 of the next hour of the time represented by the clock signal obtained from the clock source 140. Accordingly, the starting time of the third time period can be set as 00:00:00 of the next two hours of the time represented by the clock signal obtained from the clock source 140, and so on. For example, the time represented by the clock signal obtained from the clock source 140 is 14:30:11, and the next hour of this time is 15:00:00. Therefore, the starting time of the second time period is 15:00:00. The next two hours of this time is 16:00:00. Therefore, the starting time of the third time period is 16:00:00. And so on.

[0067] The length of the generation period field is N3 bits, where N3 is an integer greater than 0, and N3 is the minimum number of bits required to represent or carry a time period. The time period carried by the generation period field in the unique identifier is the time period in which the time represented by the unique identifier is generated.

[0068] The sequence number is used to distinguish the unique identifiers generated by the same generator and in the same generation period, that is, the sequence number is used to avoid the repetition of the unique identifiers generated by the same generator and in the same generation period. When generating a unique identifier, if the generator identifier and the generation period of the current generated unique identifier are the same as those of the last generated unique identifier, the sequence number of the last generated unique identifier is added by a value to obtain the sequence number of the current generated unique identifier, and the value is a positive number to ensure that the sequence number conforms to the increasing trend. In an example, the value can be a preset value, for example, 1. In an example, the value can be a random number, where the random number can ensure that the generated unique identifiers are irregular, thereby ensuring information security.

[0069] The length of the sequence number field is N4 bits, where N4 is an integer greater than 0, and N4 is the minimum number of bits required to represent or carry a sequence number. It can be understood that the larger N4 is, the more sequence numbers there are. However, the larger N4 is, the longer the length of the unique identifier is, which will occupy more storage resources and bandwidth resources. In specific implementation, the specific value of N4 can be set according to specific needs. For example, if the demand for unique identifiers of the computing system 100 is large and frequent, the value of N4 can be set to be larger.

[0070] The unique identifier is a positive number. In one example, the unique identifier is a positive long number. In the order of the digits of the unique identifier, the generator identifier is before the generation period, and the generation period is before the serial number. One generator identifier corresponds to one generator, and one generator can generate unique identifiers in multiple generation periods. The unique identifiers generated in the same generation period are distinguished by the serial numbers. Moreover, the generator identifier, the generation period, and the serial number all conform to the increasing trend. In this way, the unique identifiers generated by the same generator conform to the increasing trend, thereby facilitating the storage of the unique identifiers.

[0071] In some embodiments, as shown in Figure 2A The structure of the unique identifier further includes a sign bit field. The content carried by the sign bit field is used to indicate that the unique identifier is a positive number. The length of the sign bit field is N1 bits. In one example, the value of N1 can be 1. When the value of the bit in the sign bit field is "0", it indicates that the unique identifier in which the sign bit field is located is a positive number.

[0072] The unique identifier can be specifically expressed as: (sign bit << sign bit offset position) | (generator identifier << generator identifier offset position) | (time period << time period offset position) | (serial number << serial number offset position). That is, unique identifier = (sign bit << sign bit offset position) | (generator identifier << generator identifier offset position) | (time period << time period offset position) | (serial number << serial number offset position).

[0073] In some embodiments, the total length of the unique identifier can be 64 bits. In this way, the complete unique identifier can be read by one reading operation.

[0074] In one example, referring to Figure 2B When the total length of the unique identifier is 64 bits, the length of the sign bit field can be 1 bit, the length of the generator identifier field can be 23 bits, the length of the generation period field can be 15 bits, and the length of the serial number field can be 25 bits. Among them, Figure 2B The initial values of the sign bit field, the generator identifier field, the generation period field, and the serial number field are shown, i.e., the initial value of the sign bit field is "0", the initial value of the generator identifier field is "00000000000000000000000", the initial value of the generation period field is "000000000000000", and the initial value of the serial number field is "0000000000000000000000000".

[0075] The above example introduces the structure of the unique identifier. Next, the process of generating the unique identifier by the generator is introduced.

[0076] Any generator in the computing system 100 can perform step 301a to obtain the generator identification CI after completing the startup through step 300. Specifically, the generator can send a generator identification request to the generator identification source 150 after completing the startup. The generator identification source 150 can respond to the generator identification request and send the generator identification CI to the generator. Thus, the generator can obtain the generator identification CI. For details, refer to the foregoing description, which will not be repeated here.

[0077] The generator can also perform step 301b to obtain the current time after completing the startup. The current time here refers to the current time when the generator performs step 301b. Specifically, in step 301b, the generator can obtain a clock signal from the clock source 140 and take the time represented by the obtained clock signal as the current time. For example, the generator can set the clock of the generator according to the obtained clock signal, so as not to need to obtain the clock signal from the clock source 140 again in the future. The clock of the generator refers to the clock inside the generator.

[0078] The generator can perform step 302 after obtaining the current time. In step 302, the generator can obtain the representation information of the first time period after the startup of the generator according to the time difference between the current time and the initial time. In step 302, the generator can also calculate the start time of the second time period according to the current time. For details, refer to the foregoing description of the time period, which will not be repeated here.

[0079] The generator can also perform step 301c to initialize the serial number and the storage space Dl after completing the startup. Initializing the serial number, which can also be referred to as resetting the serial number, refers to setting the serial number to an initial value. For example, the initial value can be 0.

[0080] The storage space Dl refers to the space used by the generator to store the unique identifier generated by the generator. Initializing the storage space Dl refers to deleting the data in the storage space Dl, so that the storage space Dl has available space to store the unique identifier.

[0081] For example, the storage space Dl can be pre-set, which can be the storage space in the memory or the storage space in the cache.

[0082] The larger the storage space D1 is, the more unique identifiers can be accommodated, so that the generator can generate more unique identifiers in advance, and when a unique identifier demand end needs a unique identifier, the generator can have sufficient unique identifiers to meet the needs of the unique identifier demand end. However, the larger the storage space D1 is, the larger the storage resource occupied is. In a specific implementation, the size of the storage space D1 can be set according to specific needs. For example, if the computing system 100 has a large demand for unique identifiers and is frequent, the storage space D1 can be set to be larger.

[0083] In some embodiments, as shown in Figure 4 The storage space D1 can be implemented as a first-in first-out (FIFO) ring queue. The ring queue can be a ring structure formed by a plurality of slots arranged in sequence, where each slot can accommodate a unique identifier. The slot at the last position in the ring queue is wrapped to the first position to form a logical ring space for cyclic use. When the slot at the last position in the ring queue is already occupied, as long as the slot at the first position in the ring queue is idle, the newly generated unique identifier is filled into the slot at the first position, that is, the slot at the first position in the ring queue is used as the tail of the queue. In this way, the fixed-size ring queue can prevent pseudo overflow. Pseudo overflow, also known as false overflow, refers to a phenomenon that the queue uses storage space is not full, but the queue has overflowed.

[0084] The available space in the storage space D1 can be specifically an empty slot in the ring queue.

[0085] Continuing to refer to Figure 3 In step 303, the generator can start the unique identifier generation function. For example, the generator can include a generation module. The generation module can be one or more threads, or one or more processes. The generation module is used to generate unique identifiers. In step 303, the generator can start the generation module, thereby starting the unique identifier generation function.

[0086] In step 304, the generator can determine whether the storage space D1 is full, that is, whether there is available space. If the storage space D1 is full, the generation is paused. If the storage space D1 is not full, that is, there is available space, the unique identifier can be generated and stored in the storage space D1.

[0087] In some embodiments, the storage space D1 is a circular queue as described above. In this case, the generator fills the unique identifiers into the slots of the circular queue in the order of the generation time of the unique identifiers. In other words, the generator generates a unique identifier, fills the unique identifier into a slot, and then generates another unique identifier and fills the unique identifier into the slot after the slot of the previous unique identifier.

[0088] In step 304, the generator determines whether there is an empty slot in the circular queue. When there is an empty slot in the circular queue, the generation module generates a unique identifier and fills the generated unique identifier into the empty slot.

[0089] In one example, the generator includes a generation module as described above. The generation module monitors whether there is an empty slot in the circular queue. When there is an empty slot in the circular queue, the generation module generates a unique identifier and fills the generated unique identifier into the empty slot.

[0090] In this case, when the generator receives a unique identifier request sent by the unique identifier demand end, the generator reads a unique identifier from the circular queue according to the first-in-first-out principle and sends the unique identifier to the unique identifier demand end. The read unique identifier is the earliest generated unique identifier among all the unique identifiers currently stored in the circular queue. The slot containing the unique identifier becomes an empty slot after the unique identifier is read and can be used to contain other unique identifiers, such as newly generated unique identifiers.

[0091] In one example, the generator further includes a reading module as shown in Figure 4 The reading module reads a unique identifier from the circular queue in response to the unique identifier request.

[0092] Next, the generation process of the unique identifier is described in detail.

[0093] Continuing to refer to Figure 3 , the generator determines whether the current time is not less than the start time of the next time period. The current time here refers to the time when the generator executes step 305. The next time period refers to the next time period of the generation period of the most recently generated unique identifier. The most recently generated unique identifier refers to the unique identifier that has been generated or is being generated. When the current generation process is the generation process of the first unique identifier generated after the generator is started, the next time period here is the second time period after the generator is started.

[0094] For convenience of description, the generation period of the unique identifier generated by the generator most recently or the first time period after the generator is started can be referred to as a first time period, and the next time period of the first time period can be referred to as a second time period.

[0095] In step 305, the generator can further determine the size of the current time and the generation time of the unique identifier generated most recently by the generator. The generation time of the unique identifier refers to any time between step 305 and step 309 when the unique identifier is generated. Step 309 will be described below and will not be described here. In the embodiment of the present application, the generator generates unique identifiers in series, that is, after generating a unique identifier, the generator starts the generation process of the next unique identifier. Therefore, if the current time is less than or equal to the generation time of the unique identifier generated most recently by the generator, it indicates that time rollback occurs.

[0096] The method is not affected by time rollback. Specifically, the current time is less than or equal to the generation time of the unique identifier generated most recently by the generator, the generation time of the unique identifier generated most recently by the generator belongs to the first time period, the next time period of the first time period is the second time period, and the current time is necessarily less than the start time of the second time period, that is, the result of step 305 is false. In addition, in the embodiment of the present application, the generator considers that the current time obtained in step 305 is illegal in the case of time rollback. For the illegal current time, the generator considers that it is greater than the start time of the generation period of the unique identifier generated most recently (that is, the first time period). Therefore, the current time is in the generation period of the unique identifier generated most recently, and the globally unique unique identifier can be generated according to the process described below.

[0097] Continuing to refer to Figure 3 If the result of step 305 is false, the generator performs step 306. If the generator generates a unique identifier in the first time period, step 306 includes: obtaining a sequence number E1 and adding a value e to the sequence number E1 to obtain a sequence number E2. The sequence number E1 can be referred to as a first sequence number, and the sequence number E2 can be used as a second sequence number. The sequence number E1 is the sequence number of the unique identifier generated most recently by the generator.

[0098] In some embodiments, the value e can be a preset value, for example, can be 1, 2, or 3, etc., which are not listed one by one here. In some embodiments, the value e can be a random number. Wherein, in step 306, a random number can be generated, and the random number is taken as the value e. For example, in step 306, the value e can be generated within a preset value range, i.e., the value e is a random number within the preset value range. Wherein, the preset value range can be positively correlated with the maximum value that can be carried by the serial number field, so that it can be ensured that enough different serial numbers can be generated between 0 and the maximum value that can be carried by the serial number field. Wherein, the maximum value that can be carried by the serial number field refers to the maximum value represented by the length of the serial number field, i.e., 2 raised to the power of N4.

[0099] If the generator has not generated a unique identifier in the first time period, i.e., the current generation process is the generation process in which the generator generates the first unique identifier in the first time period, step 306 includes: using the initial value of the initialization serial number as the second serial number, for example, using the initial value of the serial number obtained in step 301c as the second serial number.

[0100] After step 306, the generator can perform step 307 to determine whether the serial number E2 is greater than the maximum value that can be carried by the serial number field. Wherein, the maximum value that can be carried by the serial number field can be referred to as a threshold, i.e., in step 307, it is determined whether the serial number E2 (i.e., the second serial number) exceeds the threshold.

[0101] If the serial number E2 is not greater than the maximum value that can be carried by the serial number field, i.e., the second serial number does not exceed the threshold. Then the generator performs step 308 to generate a unique identifier. Wherein, in the case that the results of steps 305 and 307 are both false, in step 308, the unique identifier is generated according to the generator identifier C1, the second serial number, and the first time period. That is, the serial number field of the unique identifier generated in step 308 carries the serial number E2 (i.e., the second serial number), the generator identifier field carries the generator identifier C1, and the generation period field carries the first time period.

[0102] When the result of the determination in step 307 is yes, i.e., when the sequence number E2 is greater than the maximum value that the sequence number field can carry, or when the second sequence number exceeds the threshold, the generator performs step 311 to obtain the generator identifier C2 and updates the generator identifier to the generator identifier C2. The second sequence number can be initialized to the third sequence number in step 311. Illustratively, the third sequence number can be the initial value obtained by initializing the sequence number. Then, the generator performs step 308 to generate the unique identifier. In the case where the result of the determination in step 305 is no and the result of the determination in step 307 is yes, the unique identifier is generated in step 308 according to the generator identifier C2 (i.e., the updated generator identifier), the third sequence number, and the first time period. That is, the sequence number carried in the sequence number field of the unique identifier generated in step 308 is the third sequence number, the generator identifier carried in the generator identifier field is the updated generator identifier, i.e., the generator identifier C2. Moreover, in the case where the result of the determination in step 307 is yes, the generation period carried in the generation period field of the unique identifier generated in step 308 is the first time period.

[0103] Continuing to refer to Figure 3 When the result of the determination in step 305 is yes, i.e., when the current time at which step 305 is performed is not less than the start time of the next time period, it indicates that the generator enters the next generation period. In this case, the generator performs step 310 to update the generation period to the next time period (i.e., the second time period) and initialize the sequence number. In step 310, the sequence number can be initialized to the fourth sequence number, i.e., the first sequence number (i.e., the sequence number E1) is initialized to the fourth sequence number. If the generator has not generated a unique identifier before the current time, the sequence number obtained by initializing the sequence number in step 301c can be used as the fourth sequence number in step 310. Illustratively, the fourth sequence number can be the initial value obtained by initializing the sequence number.

[0104] Then, the generator performs step 308 to generate the unique identifier. In the case where the result of the determination in step 305 is yes, the unique identifier is generated in step 308 according to the generator identifier C1, the second time period, and the fourth sequence number. That is, the sequence number carried in the sequence number field of the unique identifier generated in step 308 is the fourth sequence number, the generation period carried in the generation period field is the updated generation period (i.e., the second time period), and the generator identifier carried in the generator identifier field is the generator identifier C1.

[0105] After step 308, the generator can perform step 309 to store the unique identifier into the storage space D1. In some embodiments, as described above, the storage space D1 can be a circular queue based on the first-in-first-out mechanism. In step 309, the generator fills the unique identifier into the empty slot in the circular queue.

[0106] In this way, the unique identifier can be generated.

[0107] In some embodiments, the generator can perform steps 305-309 whenever there is available space in the storage space D1. In this way, one or more unique identifiers can be generated in advance. When the unique identifier demand side needs a unique identifier, it does not need to wait for the generator to generate it, but can read the unique identifier generated in advance, so that the demand of the unique identifier demand side for the unique identifier can be met more timely.

[0108] In summary, the unique identifier generation method provided by the embodiments of the present application ensures that the unique identifiers in the same generation period are different, wherein the generation period is determined by the time when the generator is started, and before the sequence number in the same generation period is exhausted, as long as the time of generating the unique identifier is less than the start time of the next time period, the generation period of the most recently generated unique identifier is taken as the generation period of the unique identifier to be generated at present, so that the global uniqueness of the unique identifier can also be ensured in the case of clock rollback. In addition, the generator identifier is automatically assigned by the generator identifier source, which saves manpower and improves efficiency, avoids the repetition of the generator identifier, and further ensures the global uniqueness of the unique identifier.

[0109] Based on the unique identifier generation method described above, another unique identifier generation method is provided by the embodiments of the present application. It can be understood that this method is another expression of the unique identifier generation method described above, and the two are combined. Part or all of the contents in this method can be referred to the description of the unique identifier generation method above. This method can be executed by the generator, and the generated unique identifier includes a generation period and a sequence number. Referring to Figure 5 , the method includes the following steps.

[0110] Step 501, obtaining a generator identifier, a current time, and a first sequence number. Specifically, it can be implemented by referring to the introduction of steps 301a, 301b, and 306 in the method described above. Figure 3

[0111] Step 502, determining the start time of a first time period and a second time period based on the current time; specifically, it can be implemented by referring to the introduction of step 302 in the method described above. Figure 3

[0112] Step 503, determining the generation period of the unique identifier based on the current time and the start time of the second time period; wherein the generation period of the unique identifier is the first time period or the second time period. Specifically, it can be implemented by referring to the introduction of step 303 in the method described above. Figure 3 ​​The step 305 and the step 310 are implemented as described above.

[0113] The step 504 generates the unique identifier according to the generator identifier, the generation period and the first sequence number. Details can be referred to the above description of the step 501. Figure 3 The step 308 is implemented as described above.

[0114] In some embodiments, the step of determining the generation period of the unique identifier according to the current time and the start time of the second time period comprises: if the current time is less than the start time of the second time period, taking the first time period as the generation period of the unique identifier. Details can be referred to the above description of the step 306. Figure 3 The step 305 and the step 308 are implemented as described above.

[0115] In one example of the embodiment, the step of generating the unique identifier according to the generator identifier, the generation period and the first sequence number comprises: adding the first sequence number with a first preset value to generate a second sequence number; and generating the unique identifier according to the generator identifier, the first time period and the second sequence number. Details can be referred to the above description of the step 501. Figure 3 The step 306, the step 307 and the step 308 are implemented as described above.

[0116] In one example of the example, before the step of generating the unique identifier according to the generator identifier, the first time period and the second sequence number, the method further comprises: determining whether the second sequence number exceeds a threshold; if the second sequence number does not exceed the threshold, generating the unique identifier according to the generator identifier, the first time period and the second sequence number; and if the second sequence number exceeds the threshold, updating the identifier of the generator and reinitializing the second sequence number as a third sequence number, and generating the unique identifier according to the updated generator identifier, the first time period and the third sequence number. Details can be referred to the above description of the step 307. Figure 3 The step 307, the step 311 and the step 308 are implemented as described above.

[0117] In some embodiments, the step of determining the generation period of the unique identifier according to the current time and the start time of the second time period comprises: if the current time is greater than the start time of the second time period, taking the second time period as the generation period of the unique identifier. Details can be referred to the above description of the step 306. Figure 3 The step 310 and the step 308 are implemented as described above.

[0118] In one example of the embodiment, the generating the unique identifier according to the generator identifier, the generation period and the first sequence number comprises: reinitializing the first sequence number as a fourth sequence number; and generating the unique identifier according to the generator identifier, the second time period and the fourth sequence number. The implementation can refer to the above description of steps 311 and 308 in the method for generating a unique identifier. Figure 3

[0119] In some embodiments, after the generating the unique identifier according to the generator identifier, the generation period and the initialized sequence number, the method further comprises: storing the unique identifier into a preset storage space. The implementation can refer to the above description of step 309 in the method for generating a unique identifier. Figure 4

[0120] In one example of the embodiment, before the storing the unique identifier into the preset storage space, the method further comprises: determining whether the preset storage space has available space; and if the preset storage space has the available space, storing the unique identifier into the available space.

[0121] In one example of the embodiment, the preset storage space is a first-in-first-out circular queue; and the available space is a vacant slot in the circular queue. The implementation can refer to the above description of the embodiment shown in Figure 2A

[0122] In some embodiments, the unique identifier comprises a symbol bit, the generator identifier, the generation period and a sequence number. The implementation can refer to the above description of the embodiment shown in Figure 6

[0123] The method for generating a unique identifier provided by the embodiments of the present application can ensure that the unique identifiers in the same generation period are different, wherein the generation period is determined by the time when the generator is started, and before the sequence number in the same generation period is exhausted, as long as the time when the unique identifier is generated is less than the starting time of the next time period, the generation period of the most recently generated unique identifier is taken as the generation period of the unique identifier to be generated, so that the global uniqueness of the unique identifier can be ensured even in the case of clock rollback. In addition, the generator identifier is automatically assigned by the generator identifier source, which saves manpower and improves efficiency, and avoids duplication of the generator identifier, thereby further ensuring the global uniqueness of the unique identifier.

[0124] Referring to Figure 5 The embodiments of the present application provide a unique identifier generation device 600. The device 600 comprises:

[0125] ​​​​The acquisition module 610 is configured to acquire a generator identifier, a current time, and a first serial number.

[0126] The first determination module 620 is configured to determine a first time period and a start time of a second time period based on the current time.

[0127] The second determination module 630 is configured to determine that the first time period or the second time period is a generation period of the unique identifier based on the current time and the start time of the second time period.

[0128] The generation module 640 is configured to generate a unique identifier according to the generator identifier, the generation period, and the first serial number.

[0129] The functions of the functional units of the apparatus 600 can refer to the descriptions of the methods in the above embodiments, which will not be repeated here. Figure 3 or Figure 7 The functions of the functional units of the apparatus 600 can refer to the descriptions of the methods in the above embodiments, which will not be repeated here.

[0130] Embodiments of the present application provide a computing device. As shown in Figure 3 The computing device includes a processor 710 and a memory 720 electrically connected to the processor 710. The memory 720 is configured to store an executable program. The processor 710 is configured to execute the executable program stored in the memory 720, so that the computing device can perform the unique identifier generation method shown in the above Figure 5 or Figure 5 The computing device can perform the unique identifier generation method shown in the above

[0131] In some embodiments, the processor 710 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs) or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. The general-purpose processor can be a microprocessor, or any conventional processor.

[0132] In some embodiments, the memory 720 can be a volatile memory or a non-volatile memory, such as a register, etc. Specifically, the volatile memory refers to the memory in which the data stored therein will be lost when the power supply is interrupted. Among them, the volatile memory is mainly random access memory (RAM), including static random access memory (SRAM) and dynamic random access memory (DRAM). The non-volatile memory refers to the memory in which the data stored therein will not be lost when the power supply is interrupted. Common non-volatile memories include read only memory (ROM), optical disk, magnetic disk, solid state disk, and various memory cards based on flash memory technology, etc.

[0133] The embodiments of the present application also provide a computer program product containing instructions. The computer program product can be a software or program product containing instructions, which can run on a computing device or be stored in any available medium. When the computer program product runs on the computing device, it makes the computing device execute the method shown in the embodiments of the present application. Figure 5 The method shown in the embodiments of the present application.

[0134] The embodiments of the present application also provide a computer readable storage medium. The computer readable storage medium can be any available medium that the computing device can store or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), optical medium (for example, DVD), or semiconductor medium (for example, solid state disk), etc. The computer readable storage medium includes instructions, which instruct the computing device to execute the method shown in the embodiments of the present application. ​ The method shown in the embodiments of the present application.

[0135] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the protection scope of the technical solutions of the embodiments of the present application.

Claims

1. A method of generating a unique identifier, characterized by, The method comprises: obtaining a generator identifier, a current time and a first sequence number; wherein the first sequence number is a sequence number initialized for the first time; determining a first time period and a start time of a second time period based on the current time; a time difference between the current time and a preset initial time is the first time period; the start time of the second time period is a start time of a next period after the first time period; determining a generation period of the unique identifier based on the current time and the start time of the second time period; wherein the generation period of the unique identifier is the first time period or the second time period; generating a unique identifier according to the generator identifier, the generation period and the first sequence number.

2. The method of claim 1, wherein, The determination of the generation period of the unique identifier based on the current time and the start time of the second time period comprises: if the current time is less than the start time of the second time period, taking the first time period as the generation period of the unique identifier.

3. The method of claim 2, wherein, The generation of the unique identifier according to the generator identifier, the generation period and the initialized sequence number comprises: adding a first preset value to the first sequence number to generate a second sequence number; generating the unique identifier according to the generator identifier, the first time period and the second sequence number.

4. The method of claim 3, wherein, Before the generation of the unique identifier according to the generator identifier, the first time period and the second sequence number, the method further comprises: determining whether the second sequence number exceeds a threshold value; if the second sequence number does not exceed the threshold value, generating the unique identifier according to the generator identifier, the first time period and the second sequence number; if the second sequence number exceeds the threshold value, updating the identifier of the generator and re-initializing a second sequence number as a third sequence number, and generating the unique identifier according to the updated generator identifier, the first time period and the third sequence number.

5. The method according to any one of claims 1 to 4, characterized in that, The determination of the generation period of the unique identifier based on the current time and the start time of the second time period comprises: if the current time is greater than the start time of the second time period, taking the second time period as the generation period of the unique identifier.

6. The method of claim 4, wherein, The generation of the unique identifier according to the generator identifier, the generation period and the initialized sequence number comprises: re-initializing a first sequence number as a fourth sequence number: generating the unique identifier according to the generator identifier, the second time period and the fourth sequence number.

7. The method according to any of claims 1 to 4, 6, characterized in that, After the determination of the first time period and the start time of the second time period based on the current time, the method further comprises: determining whether a preset storage space has available space; if the preset storage space has the available space, determining the generation period of the unique identifier based on the current time and the start time of the second time period.

8. The method of claim 7, wherein, After the generation of the unique identifier according to the generator identifier, the generation period and the first sequence number, the method further comprises: storing the unique identifier to a preset storage space.

9. The method of claim 8, wherein, The preset storage space is a first-in first-out circular queue; wherein the available space is a vacant slot in the circular queue.

10. The method according to any one of claims 1 to 4, 6, 8, 9, characterized in that, The unique identifier includes a symbol bit, the generator identifier, the generation period, and a sequence number.

11. A computing device, comprising: Comprise: A memory and a processor; The memory and the processor are electrically connected; wherein The memory is configured to store an executable program; The processor is configured to run the executable program to enable the computing device to perform the method according to any one of claims 1-9.

Citation Information

Patent Citations

  • Global unique ID generation method and device and vehicle management system

    CN111831639A

  • Identifier generation method and device, equipment and storage medium

    CN111917897A