A data identifier generation method, apparatus, device, and medium
By combining node identifiers and growth sequences, data identifiers are generated, solving the problem of relying on machine clocks and third-party coordinators in existing technologies. This achieves efficient, unique, and short data identifier generation, which is suitable for distributed systems.
Patent Information
- Application Number
- CN202111624849.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In existing technologies, data identifier generation schemes suffer from problems such as reliance on machine clocks, third-party coordinators, limited timestamp ranges, and excessively long identifier lengths, resulting in low generation efficiency and insufficient uniqueness and reliability.
Data identifiers are generated by determining node identifiers and growth sequences. The node identifiers integrate hardware information, process IDs, and random numbers, while the growth sequences include time series and tail numbers. Data identifiers are generated in a monotonically increasing manner to avoid dependence on third-party coordinators.
The generated data identifiers are sequentially increasing in natural order, short in length, and highly unique. They can efficiently generate data identifiers in distributed systems, reduce the probability of identifier collisions, and support long-term use and high-concurrency scenarios.
Smart Images

Figure CN114297734B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data identifier generation method, apparatus, device and medium. Background Technology
[0002] In existing technologies, a unique data identifier needs to be generated for each piece of data. This data identifier enables the data to be quickly located and distinguished, so as to perform various data processing operations.
[0003] Therefore, a more effective and efficient data labeling generation scheme is needed. Summary of the Invention
[0004] This specification provides a data identifier generation method, apparatus, device, and medium to address the technical problem of how to generate data identifiers more effectively and efficiently.
[0005] To address the aforementioned technical problems, the embodiments in this specification provide the following technical solutions:
[0006] This specification provides a data identifier generation method, including:
[0007] Determine the node identifier and the latest growth sequence; wherein, the growth sequence includes a time sequence and a tail number;
[0008] Obtain a first timestamp, determine the target data in the first timestamp, and determine whether the target data is greater than the time series in the latest growth sequence; wherein, the first timestamp is the timestamp when the data identifier generation condition is triggered;
[0009] If so, the latest growth sequence is incremented, and the incremented growth sequence is used as the updated growth sequence. A data identifier is formed based on the updated growth sequence and the node identifier.
[0010] Optionally, the node identifier includes the hardware information corresponding to the node, the process ID of the node, and a random number.
[0011] Optional,
[0012] Determining the node identifier includes:
[0013] Obtain the hardware information corresponding to the node, concatenate the hardware information into a first string, and obtain the hash value of the first string;
[0014] Obtain the process ID of the node and generate a random number;
[0015] The hash value, process ID, and random number are concatenated to form a node identifier.
[0016] Optionally, the method further includes:
[0017] If obtaining hardware information fails, a random number will be used instead of the hash value.
[0018] or,
[0019] If obtaining the process ID fails, the hash value of the process name is used instead of the process ID.
[0020] Optional,
[0021] The method further includes:
[0022] The initial value of the growth sequence is determined based on the timestamp at which the node starts, including:
[0023] Obtain the timestamp when the node starts, perform a truncation operation on the timestamp when the node starts, and determine the initial value of the time series based on the truncation data;
[0024] The initial value of the time series is concatenated with the initial value of the tail index to form the initial value of the growing sequence;
[0025] or,
[0026] Determining the target data in the first timestamp includes:
[0027] Perform a cut operation on the first timestamp to determine the target data in the first timestamp.
[0028] Optionally, the method further includes:
[0029] If it is determined that the target data is not greater than the time series in the latest growth sequence, then wait until the target data in the timestamp after the data identifier generation condition is triggered is greater than the time series in the latest growth sequence, then increment the latest growth sequence, and use the incremented growth sequence as the updated growth sequence. A data identifier is formed based on the updated growth sequence and the node identifier.
[0030] Optionally, in the formed data identifier, the data corresponding to the updated growth sequence is located before the data corresponding to the node identifier.
[0031] Optionally, the method further includes:
[0032] After determining the node identifier, starting from the leftmost data of the node identifier, select data of a preset number of digits in order from left to right, and convert each selected data into a base-32 numeric character as the base-32 numeric character corresponding to the node identifier; concatenate the base-32 numeric characters corresponding to the node identifier to form the base-32 numeric character group corresponding to the node identifier.
[0033] The data identifier formed based on the updated growth sequence and the node identifier includes: starting from the leftmost data of the updated growth sequence, selecting data of a preset number of positions in order from left to right; converting each data selected by the updated growth sequence into a base-32 numeric character as the base-32 numeric character corresponding to the updated growth sequence; and concatenating each base-32 numeric character corresponding to the updated growth sequence into a base-32 numeric character group corresponding to the updated growth sequence.
[0034] The 32-bit numeric character set corresponding to the node identifier and the 32-bit numeric character set corresponding to the updated growth sequence are concatenated to form a data identifier.
[0035] This specification provides a data identifier generation device, comprising:
[0036] An initial module is used to determine the node identifier and the latest growth sequence; wherein, the growth sequence includes a time sequence and a tail number;
[0037] The judgment module is used to obtain a first timestamp, determine the target data in the first timestamp, and determine whether the target data is greater than the time series in the latest growth sequence; wherein, the first timestamp is the timestamp when the data identifier generation condition is triggered;
[0038] The identification module is used to increment the latest growth sequence if the first timestamp is greater than the time sequence in the latest growth sequence, and use the incremented growth sequence as the updated growth sequence to form a data identifier based on the updated growth sequence and the node identifier.
[0039] This specification provides a data identifier generation device, comprising:
[0040] At least one processor;
[0041] as well as,
[0042] A memory that is communicatively connected to the at least one processor;
[0043] in,
[0044] The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the data identifier generation method described above.
[0045] This specification provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the data identifier generation method described above.
[0046] The above-described at least one technical solution adopted in the embodiments of this specification can achieve the following beneficial effects:
[0047] The above technical solution generates data identifiers through an increasing sequence and node identifiers. The increasing sequence is a monotonically increasing sequence, and the node identifier is a unique identifier for each node. The generated data identifiers have the characteristics of increasing in natural order, short length, and no dependence on a third-party coordinator, which can improve the effectiveness and efficiency of data identifiers. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the drawings used in the description of the embodiments of this specification or the prior art will be briefly introduced below. Obviously, the drawings described below are only some of the drawings that may be involved in the embodiments described in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0049] Figure 1 This is a schematic diagram of the distributed IDs generated by the Snowflake algorithm.
[0050] Figure 2 This is a schematic diagram of the execution entity of the data identifier generation method in the first embodiment of this specification.
[0051] Figure 3 This is a flowchart illustrating the data identifier generation method in the first embodiment of this specification.
[0052] Figure 4 This is a schematic diagram of the data identifier generation process in the first embodiment of this specification. Figure 4 The numbers 44, 6, 24, 16, and 10 represent the number of bits.
[0053] Figure 5 This is a schematic diagram of the data identifier generation device in the second embodiment of this specification. Detailed Implementation
[0054] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions of the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described in this specification are merely some embodiments of this application, and not all embodiments. Based on the embodiments of this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this application.
[0055] In existing technologies, a unique data identifier needs to be generated for each piece of data. This data identifier enables the data to be quickly located and distinguished, so as to perform various data processing operations.
[0056] Currently, the schemes for generating data identifiers include the Snowflake algorithm and UUID, which are described below:
[0057] Snowflake is an open-source distributed ID generation method from Twitter that uses 64-bit integer storage. The structure of the distributed IDs generated by this algorithm is shown in the diagram below. Figure 1 As shown.
[0058] Snowflake Algorithm Description:
[0059] The highest bit is the sign bit, which is always 0.
[0060] • 41-bit time series, accurate to the millisecond level
[0061] • 10-bit machine identifier, supporting a maximum deployment of 1024 nodes.
[0062] • A 12-bit sequence number within a millisecond can support the generation of 4096 IDs within the same millisecond on the same node. Snowflake algorithm drawbacks:
[0063] • Strongly dependent on machine clock; if clock rollback occurs, it will lead to duplicate number issuance or render the service unavailable.
[0064] • Machine IDs are assigned via a third-party coordinator
[0065] • A 41-bit timestamp can only store a limited range of time; ideally, it can only support a maximum of 69 years of use.
[0066] UUID: The standard format of a UUID (Universally Unique Identifier) consists of 32 hexadecimal digits, divided into five segments by hyphens, in the form of 8-4-4-4-12 (36 characters), for example, 550e8400-e29b-41d4-a716-446655440000. Currently, there are five versions of UUID, each with a different algorithm and application scope.
[0067] Disadvantages of UUID:
[0068] UUIDs are too long, making them difficult to store and unsuitable for certain scenarios.
[0069] UUIDs are unordered, and when used as primary keys in databases, they may cause frequent changes in data location, severely impacting performance.
[0070] The first embodiment of this specification (hereinafter referred to as "Embodiment 1") provides a data identifier generation method. The executing entity of Embodiment 1 can be a terminal (including but not limited to mobile phones, computers, tablets, and televisions), a server, an operating system, an application, a data identifier generation platform, or a data identifier generation system, etc. That is, the executing entity can be diverse, and can be set, used, or changed as needed. Alternatively, a third-party application can assist the executing entity in executing Embodiment 1. For example... Figure 2 As shown, the data identifier generation method in Embodiment 1 can be executed by the server, and a corresponding application can be installed on the terminal (held by the user). Data can be transmitted between the terminal or the application and the server. Data can be collected, input, or output, or pages or information can be processed (to the user) through the terminal or the application, thereby assisting the server in executing the data identifier generation method in Embodiment 1.
[0071] like Figure 3 and Figure 4 As shown, the data identifier generation method provided in Embodiment 1 includes:
[0072] S101: (Executing entity) Determines the node identifier and the latest growth sequence; wherein, the growth sequence includes a time sequence and a tail number;
[0073] In Embodiment 1, a node can also be referred to as a service instance, which is a service process on a machine or device. In particular, the executing entity in Embodiment 1 can be the node or the machine or device where the node resides.
[0074] The execution entity in Implementation Example 1 can determine the node identifier and the latest growth sequence. The node identifier includes the hardware information corresponding to the node, the process ID of the node, and a random number. The initial value of the growth sequence is determined based on the timestamp when the node starts.
[0075] The following will explain each point:
[0076] I. Node Identifier (corresponding) Figure 4 (Node Identifier Area)
[0077] In Example 1, the node identifier may include the hardware information corresponding to the node, the node's process ID, and a random number. The following details how the node identifier is determined:
[0078] For any node, the execution entity in Embodiment 1 can obtain the hardware information corresponding to that node. This hardware information refers to the hardware information of the device where the node resides. The execution entity in Embodiment 1 can concatenate the hardware information into a single string (let's call it the first string) and obtain its hash value. In Embodiment 1, the hardware information includes, but is not limited to, the node's network interface card (NIC) information (corresponding to...). Figure 4 The network card information includes, but is not limited to, the network card name and MAC address.
[0079] The executing entity in Implementation Example 1 can obtain the process ID (i.e., PID) of the node. Figure 4 The "process ID" in the example, and the execution entity in Example 1 can generate a random number (corresponding to...). Figure 4 The hash value, process ID, and random number are then concatenated to form the node identifier. The hash value, process ID, and random number can be concatenated from left to right to form the node identifier.
[0080] Specifically, in Implementation Example 1, the executing entity can take the lower 24 bits of the hash value of the first string (which may be called the first data), the process ID can take 16 bits (which may be called the second data), and the random number can take the lower 10 bits (which may be called the third data). Then, the first data, the second data, and the third data are concatenated into a 50-bit node identifier in order from left to right.
[0081] In Embodiment 1, if hardware information cannot be obtained, the execution entity of Embodiment 1 can use a random number (the lower 24 bits can be taken) to replace the hash value of the first string; or, if the process ID of the node cannot be obtained, the execution entity of Embodiment 1 can use the hash value of the process name of the node (the lower 16 bits can be taken) to replace the process ID; or, if the process name of the node cannot be obtained, the execution entity of Embodiment 1 can use a random number (the lower 16 bits can be taken) to replace the process ID.
[0082] In Embodiment 1, the type of the random number can be adapted to the programming language environment in which the node is located. That is, the type of the random number may be different depending on the programming language environment. For example, the random number may be a 32-bit integer or a 64-bit long integer. Embodiment 1 does not limit this. Similarly, depending on the programming language environment, the node identifier can be stored as a 64-bit long integer variable or other types of variables. Embodiment 1 does not limit this.
[0083] In Implementation Example 1, since the node identifier integrates the hardware information (i.e., the machine ID information where the node is located) and process information, the node identifier can serve as a unique identifier for the node, representing the uniqueness of the node within the distributed system.
[0084] After determining the node identifier, the execution entity in Embodiment 1 can start from the leftmost data of the node identifier and sequentially select data of a preset number of bits from left to right. Each selected data is converted into a base-32 numeric character, which serves as the base-32 numeric character corresponding to the node identifier. The preset number of bits can be 5 bits, i.e., selecting data from left to right as 1 to 5 bits, 6 to 10 bits, 11 to 15 bits, and so on. The node identifier can be 50 bits, or the above data selection can be performed on the first 50 bits of the node identifier; therefore, data can be selected 10 times, with each selection being 5 bits. From the list of base-32 numeric characters, the base-32 numeric characters corresponding to the values of each selected data (from the node identifier) are determined (i.e., each 5-bit data corresponds to one base-32 numeric character). Thus, each selected data is converted into a "base-32 numeric character corresponding to the values of each selected data (from the node identifier)," and the execution entity in Embodiment 1 obtains 10 base-32 numeric characters, which can serve as the base-32 numeric character corresponding to the node identifier.
[0085] The executing entity in Embodiment 1 can concatenate the 32-bit numeric characters corresponding to the node identifier into a string (which may be called the second string), and the second string is the 32-bit numeric character group corresponding to the node identifier.
[0086] II. Growth Sequence (corresponding to) Figure 4 (the "growth zone" in the text)
[0087] The growth sequence includes a time series and a tail sequence number, such as... Figure 4 As shown, the time series and the tail sequence number can be concatenated to form the growing sequence.
[0088] The execution entity in Embodiment 1 can determine the initial value of the growth sequence based on the timestamp when the node starts. Determining the initial value of the growth sequence based on the timestamp when the node starts may include: obtaining the timestamp when the node starts; performing a truncation operation on the timestamp; determining the initial value of the time series based on the truncated data; and concatenating the initial value of the time series with the initial value of the tail sequence number to form the initial value of the growth sequence.
[0089] In Example 1, performing a truncation operation on any timestamp (whether it's the startup timestamp, the first timestamp, or the real-time timestamp mentioned below) may include: assuming the timestamp has m bits, first shift the timestamp left by n bits (n is preset, generally n < m), then shift the left-shifted data right by n bits. After performing the left and right shift operations on the timestamp, the resulting data is the "truncated data." The first to nth bits from the left of the truncated data are 0, and the (n+1)th to mth bits from the left are the (n+1)th to mth bits from the left of the timestamp. The "truncation" operation described below refers to the operation method of "performing a truncation operation on any timestamp" here. The operation methods for all truncation operations in Example 1 are generally consistent.
[0090] The timestamp described in Example 1 can be... Unix Millisecond timestamp;
[0091] And / or, the left shift operation can be a binary left shift of 20 bits on the timestamp, and the right shift operation can be a binary right shift of 20 bits, that is, n can be 20;
[0092] For example, the original timestamp is a 64-bit long integer.
[0093] 00000000000000000000010111110111010111100000011011111000001001. Assuming this long integer data is first shifted left by 20 bits and then right by 20 bits, the new data is obtained.
[0094] 000000000000000000000010111110111010111100000011011111000001001.
[0095] The 21st to 64th bits from the left of the new data are data extracted from the original timestamp.
[0096] In Example 1, the timestamp of node startup is obtained, and the above-described truncation operation is performed on the timestamp of node startup to obtain the data truncated from the timestamp of node startup. Determining the initial value of the time series based on the data truncated from the timestamp of node startup can include: shifting the data truncated from the timestamp of node startup left by k bits (k is preset, generally k < n), and using the resulting data as the carrier of the initial value of the growing sequence. Specifically, the (n-k+1)th to the mth bit from the left of the carrier of the initial value of the growing sequence are the initial values of the growing sequence; the (n-k+1)th to the (mk)th bit from the left of the carrier of the initial value of the growing sequence are the initial values of the time series within the growing sequence; and the (m-k+1)th to the mth bit from the left of the carrier of the initial value of the growing sequence are the initial values of the tail index within the growing sequence, with the initial value of the tail index being k bits of 0.
[0097] In this case, shifting the timestamp of the node startup time left by k bits can be equivalent to shifting the timestamp of the node startup time left by 6 bits, i.e., k can be 6.
[0098] For example, data extracted from the timestamp when the node starts is
[0099] 000000000000000000000010111110111010111100000011011111000001001, assuming the truncated data is shifted left by 6 bits, the new data is obtained.
[0100] 000000000000000010111110111010111100000011011111000001001000000, the 15th to 64th bits from the left of this new data can be used as the initial value of the growth sequence, the 15th to 58th bits from the left of this new data can be used as the initial value of the time series, and the 59th to 64th bits from the left of this new data are the initial values of the tail sequence.
[0101] The execution entity in Example 1 can concatenate the initial value of the time series with the initial value of the tail sequence to form the initial value of the growing sequence.
[0102] Depending on the programming language environment, the timestamp or growth sequence can be stored as a long type or AtomicLong type variable or other type variable; Implementation Example 1 does not limit this.
[0103] In Example 1, the growth sequence can be continuously changing (described below), therefore the executing entity in Example 1 will determine the latest growth sequence. Of course, when the executing entity in Example 1 determines the growth sequence for the first time, the latest growth sequence is the initial value of the growth sequence.
[0104] S103: (Executing entity) Obtains the first timestamp, determines the target data in the first timestamp, and judges whether the target data is greater than the time series in the latest growth sequence; wherein, the first timestamp is the timestamp when the data identifier generation condition is triggered;
[0105] The execution entity in Implementation Example 1 can be configured with data identifier generation conditions. Triggering data identifier generation conditions may include: triggering data identifier generation conditions when data is generated and data identifiers need to be generated.
[0106] The executing entity in Implementation Example 1 can obtain a first timestamp, which is the timestamp when the data identifier generation condition is triggered.
[0107] Whenever a data ID is generated, that is, whenever a data identifier generation condition is triggered, the execution entity in Implementation Example 1 obtains the first timestamp when the data identifier generation condition is triggered, determines the target data in the first timestamp, and judges whether the target data is greater than "the time series in the latest growth sequence (when the data identifier generation condition is triggered)". This also shows that the first timestamp is also dynamically changing.
[0108] Determining the target data in the first timestamp may include:
[0109] The above-described truncation operation is performed on the first timestamp (the steps for performing the truncation operation on the first timestamp are the same as the steps for performing the truncation operation on the timestamp when the node starts), resulting in data truncated from the first timestamp. The data truncated from the first timestamp is the target data within the first timestamp, and the number of bits in the data truncated from the first timestamp is the same as the number of bits in the time series. The generation method for all the "target data" involved in Embodiment 1 is generally the same.
[0110] S105: (Execution subject) If the target data is greater than the time series in the latest growth sequence, then the latest growth sequence is incremented, and the incremented growth sequence is used as the updated growth sequence. A data identifier is formed based on the updated growth sequence and the node identifier.
[0111] The following is a breakdown of different scenarios:
[0112] Scenario 1: The target data is greater than the time series in the latest growth sequence.
[0113] After any data identifier generation condition is triggered, if the target data in the first timestamp at the time the data identifier generation condition is triggered is greater than the time series in the latest growth sequence at the time the data identifier generation condition is triggered, then the execution entity of Embodiment 1 increments the latest growth sequence, that is, the execution entity of Embodiment 1 performs an increment operation on the latest growth sequence. Incrementing the latest growth sequence may include: incrementing the entire latest growth sequence by 1.
[0114] In Implementation Example 1, the executing entity uses the auto-incremented growth sequence as the updated growth sequence (hereinafter referred to as the "updated growth sequence"), thus making the updated growth sequence the latest growth sequence.
[0115] Scenario 2: The target data is not greater than the time series in the latest growth sequence.
[0116] After any data identifier generation condition is triggered, if the target data in the first timestamp at the time the data identifier generation condition is triggered is not greater than the time series in the latest growth sequence at the time the data identifier generation condition is triggered, then we can wait (millisecond-level wait) until the target data in the timestamp after the data identifier generation condition is triggered is greater than the time series in the latest growth sequence. That is, after the data identifier generation condition is triggered, we wait until the target data in the real-time timestamp (the method for determining the target data is the same as above) is greater than the time series in the latest growth sequence. When the target data in the real-time timestamp is greater than the time series in the latest growth sequence, the execution entity of Embodiment 1 increments the latest growth sequence (as above) to obtain the updated growth sequence.
[0117] Regardless of whether it's scenario one or scenario two, the executing entity in embodiment one can form a data identifier based on the updated growth sequence and the node identifier. Forming a data identifier based on the updated growth sequence and the node identifier can include:
[0118] In Embodiment 1, the executing entity can start from the leftmost data in the updated growth sequence and sequentially select data of a preset number of bits from left to right. Each data selected from the updated growth sequence is converted into a base-32 numeric character, which serves as the base-32 numeric character corresponding to the updated growth sequence. The preset number of bits can be 5 bits, meaning data is selected from left to right as bits 1 to 5, 6 to 10, 11 to 15, and so on. The updated growth sequence can be 50 bits, or the above data selection can be performed on the first 50 bits of the growth sequence; therefore, data can be selected 10 times, with each selection being 5 bits. The list of base-32 numeric characters determines the base-32 numeric characters corresponding to the values of the selected data (from the updated growth sequence) in each iteration (i.e., one base-32 numeric character for every 5 bits of data). This converts each selected data into "base-32 numeric characters corresponding to the values of the selected data (from the updated growth sequence) in each iteration". The execution subject of Embodiment 1 then obtains 10 base-32 numeric characters, which can be used as the base-32 numeric characters corresponding to the updated growth sequence.
[0119] The executing entity in Embodiment 1 can concatenate the 32-bit numeric characters corresponding to the updated growth sequence into a string (which may be called the third string), and the third string is the 32-bit numeric character group corresponding to the updated growth sequence.
[0120] In Embodiment 1, the executing entity can concatenate the 32-bit numeric character set corresponding to the node identifier and the 32-bit numeric character set corresponding to the updated growth sequence to form a data identifier. In Embodiment 1, the data identifier can serve as an identifier for the data generated by the node.
[0121] Since both the base 32 numeric character set corresponding to the node identifier and the base 32 numeric character set corresponding to the updated growth sequence can be 10 base 32 numeric characters, the data identifier can be a string of 20 characters in length.
[0122] The above describes the process of first obtaining the 32-bit numeric character set corresponding to the node identifier and the 32-bit numeric character set corresponding to the updated growth sequence, and then assembling them into a data identifier. Alternatively, in Embodiment 1, the updated growth sequence and the node identifier can be concatenated into an array (let's call it the first array, which can be 100 bits and stores all the information of the data ID to be generated). Then, starting from the leftmost data in the first array, data of a preset number of bits are selected sequentially from left to right. Each data selected from the first array is converted into a 32-bit numeric character set, which serves as the 32-bit numeric character set corresponding to the first array. This directly obtains each 32-bit numeric character set corresponding to the first array, and the 32-bit numeric character sets corresponding to the first array are then concatenated into a data identifier.
[0123] In the formed data identifier, the data corresponding to the updated growth sequence (i.e., the 32-bit numeric character group corresponding to the updated growth sequence) is located before the data corresponding to the node identifier (i.e., the 32-bit numeric character group corresponding to the node identifier). Specifically, the 10 32-bit numeric characters corresponding to the updated growth sequence can be located at index positions 0 to 9 of the data identifier, and the 32-bit numeric character group corresponding to the node identifier can be located at index positions 10 to 19 of the data identifier.
[0124] In the generated data identifier, the 32-bit numeric characters corresponding to the node identifier are arranged in order. That is, the data with a preset number of bits selected from the node identifier comes first, and the corresponding 32-bit numeric characters also come first. Specifically, the 32-bit numeric characters corresponding to the 1st to 5th bits of the node identifier are ordered first, the 32-bit numeric characters corresponding to the 6th to 10th bits of the node identifier are ordered second, the 32-bit numeric characters corresponding to the 11th to 15th bits of the node identifier are ordered third, and so on. This is also the arrangement order of the 32-bit numeric characters corresponding to the node identifier in the data identifier.
[0125] Similarly, in the resulting data identifier, the 32-bit numeric characters corresponding to the updated growth sequence are arranged in order. That is, the data with the preset number of bits selected from the updated growth sequence comes first, and the corresponding 32-bit numeric characters also come first. Specifically, the 32-bit numeric characters corresponding to the 1st to 5th bits of the updated growth sequence are ranked first, the 32-bit numeric characters corresponding to the 6th to 10th bits of the updated growth sequence are ranked second, the 32-bit numeric characters corresponding to the 11th to 15th bits of the updated growth sequence are ranked third, and so on. This is also the arrangement order of the 32-bit numeric characters corresponding to the updated growth sequence in the data identifier.
[0126] As can be seen from the above, after a node starts, the latest growth sequence is formed by the initial value of the time series and the initial value of the tail sequence number. Therefore, when generating a data identifier for the first time, it is necessary to determine whether the target data in the first timestamp is greater than the initial value of the time series. Each time a data identifier is generated, the growth sequence increments once, and the growth sequence is updated. The latest growth sequence is the updated growth sequence. Since each time a data identifier is determined, the latest growth sequence is obtained. Therefore, the updated growth sequence in the previous data identifier determination process is used as the "latest growth sequence" to be obtained for the next (previous and next are two consecutive) data identifier generation. This also ensures that the growth sequence always maintains a monotonically increasing change as data identifiers are determined.
[0127] After the node restarts, the initial value of the growth sequence can be redefined, and data identifiers can be generated according to the above content.
[0128] The 32-bit numeric characters used above can be arranged in natural order (ASCII code order) using the Base32 standard.
[0129] In Example 1, the function that generates data identifiers can be locked to ensure data security in a multi-threaded environment.
[0130] In Example 1, data identifiers are generated using an increasing sequence and node identifiers. The increasing sequence increments continuously as data identifiers are generated, making it a monotonically increasing sequence. The node identifier is a unique identifier for each node and remains constant after the node starts and before restarting. Thus, the generated data identifiers have the following characteristics:
[0131] (1) The generated data identifiers are generated in natural order; this is because the data identifiers are generated based on an increasing sequence, and the increasing sequence is incremental.
[0132] (2) The generated data identifier is shorter; this is because generating the data identifier requires the conversion of 32-bit numeric characters, which effectively compresses the length of the generated data identifier compared to existing number conversion schemes such as hexadecimal.
[0133] (3) It does not rely on a third-party coordinator. This is because the data identifier is also generated based on the node identifier, and the node identifier can play the role of a unique identifier for the node. This makes the generation of data identifiers (especially in distributed systems) not dependent on a third-party coordinator, which simplifies the implementation and deployment complexity of generating data identifiers and reduces the complexity of data identifier generation.
[0134] Specifically, the node identifier integrates the node's corresponding hardware information (i.e., the machine ID information where the node resides), process information, and a random number—a triple guarantee that effectively reduces the probability of node identifier collisions (collision meaning different nodes have the same node identifier), thus reducing the probability of data identifier collisions or duplications. In a finite number of node deployments, the probability of node identifier collisions or duplications between different nodes can be considered zero. The uniqueness of the node identifier ensures the uniqueness and validity of the data identifiers generated based on it.
[0135] In Example 1, since the node identifier is a constant, it can be used continuously for data identifier generation before the node restarts. This means that the node identifier can be directly used to generate data identifiers each time (for example, the node identifier can be used as a backup array or a constant for data identifiers, remaining unchanged until the node restarts). This implies that the data obtained based on the node identifier (e.g., the second string) in the data identifier does not need to be recalculated each time a data identifier is generated, but can be used directly each time, effectively improving the efficiency of data identifier generation.
[0136] In Example 1, a time-stamp-based growth sequence is used as the leading bit of the data identifier. While ensuring that the list of base-32 numeric characters is sorted in natural order, the generated data ID satisfies the characteristics of monotonically increasing for single nodes and trending increasing for multiple nodes (especially in distributed systems).
[0137] Existing solutions such as the Snowflake algorithm use the current timestamp at the time of data identifier generation as a parameter each time. Implementation 1, on the other hand, obtains a timestamp once when the node starts up, which is used to construct the initial value of the growth sequence. After that, each time the data identifier is generated based on the auto-incrementing growth sequence, it is not necessary to use the timestamp to construct the data identifier again until the node restarts, thereby further improving the efficiency of data identifier generation.
[0138] In Example 1, a first timestamp is obtained each time a data identifier is generated, so the first timestamp is also constantly increasing. When generating data identifiers, as long as the number of data identifiers to be generated per millisecond (i.e., the concurrency of data identifier generation per millisecond) is less than 64 (2^6), the "growth rate" of the time series in the growth sequence will be less than the "growth rate" of the first timestamp. Therefore, the "growth rate" of the time series in the growth sequence will be less than the "growth rate" of the target data in the first timestamp. Thus, Example 1 can handle a data identifier generation concurrency of no less than 64 per millisecond, i.e., no less than 64 / ms, further improving the data identifier generation efficiency.
[0139] In Example 1, the first timestamp corresponds to the real-time timestamp at which data identifiers need to be generated. When the node is in an "idle" state (idle time generally refers to when there are fewer worker threads on the node; the fewer worker threads on the node, the lower the concurrency per millisecond for data identifier generation), the concurrency per millisecond for data identifier generation is low, and the difference between the time series in the latest growth sequence and the "target data in the real-time timestamp" will increase. The lower the concurrency per millisecond for data identifier generation, the greater the difference between the time series in the latest growth sequence and the "target data in the real-time timestamp." In Implementation 1, data identifiers need to be generated when the target data in the first timestamp is greater than the time series in the latest growth sequence. Therefore, the larger the difference between the time series in the latest growth sequence and the "target data in the real-time timestamp," and the larger the difference between the time series in the latest growth sequence and the "target data in the first timestamp" when data identifiers need to be generated, the more times the latest growth sequence can increment (as long as the time series of the latest growth sequence is less than the "target data in the first timestamp" when data identifiers need to be generated after incrementing). This results in more data identifiers available for generation, thus enabling the handling of higher concurrency per millisecond for data identifier generation and stronger support for extremely high concurrency data identifier generation in the short term. Specifically, even if a clock rollback occurs, causing a real-time timestamp rollback, as long as the rollback duration is less than the difference between the "target data in the timestamp when the rollback occurred" and the "time series in the latest growth sequence when the rollback occurred," it can be guaranteed that the target data in the first timestamp when data identifiers are generated again is greater than the time series in the latest growth sequence, thus not affecting data identifier generation. Therefore, the greater the difference between the target data in the real-time timestamp when a rollback occurs and the time series in the latest growth sequence when a rollback occurs, the longer the rollback duration can be handled (as long as the rollback duration is less than the difference between the target data in the timestamp when a rollback occurs and the time series in the latest growth sequence when a rollback occurs), and the higher the tolerance for clock rollback.
[0140] In Example 1, the time series in the growing sequence occupies 44 bits, while the snowflake algorithm occupies 41 bits of timestamp data. Therefore, Example 1 supports a longer usage period than the snowflake algorithm, and the validity and reliability of the data identifiers generated by Example 1 are higher. Specifically, the snowflake algorithm generates IDs based on the difference between the current time and the start time by setting a start time, and can support usage for up to approximately 69 years. Example 1, however, does not require using a difference and can support usage for at least 2527 years. This will be explained below:
[0141] From the start time of the Unix millisecond timestamp (which is 0, corresponding to the actual time 1970-01-01 08:00:00:000 Beijing time) to the present, the first 20 bits from the left of the timestamp have always been 0. Therefore, after performing a truncation operation on any timestamp, as long as the first 20 bits from the left of the truncated data remain 0, the data truncated from that timestamp can represent the size of that timestamp.
[0142] A timestamp is considered broken when the first 19th bit from the left is 0, the 20th bit from the left is 1, and the 21st to 64th bits from the left are all 0 (i.e., the smallest timestamp where the condition of "the first 19th bit from the left" is broken).
[0143] When a timestamp like 0000000000000000010 ...
[0144] Therefore, in Example 1, the data extracted from the first timestamp before the time 2527-06-23 14:20:44:416, i.e., the target data in the first timestamp, can be used to characterize the size of the first timestamp. This allows for comparison of the target data in the first timestamp with the time series in the latest growth sequence, preventing inaccuracies in the first timestamp due to truncation. Thus, if the target data in the first timestamp is greater than the time series in the latest growth sequence (regardless of whether it's Case 1 or Case 2 above), identification data is generated.
[0145] Example 1 can be implemented using the Java language, which is highly extensible and easy to maintain and extend.
[0146] As can be seen from the above, Example 1 is particularly effective in improving the validity, efficiency and reliability of data identifier generation.
[0147] like Figure 5 As shown, the second embodiment of this specification provides a data identifier generation apparatus corresponding to the data identifier generation method described in Embodiment 1, comprising:
[0148] The initial module 202 is used to determine the node identifier and the latest growth sequence; wherein, the growth sequence includes a time sequence and a tail number;
[0149] The judgment module 204 is used to obtain a first timestamp, determine the target data in the first timestamp, and determine whether the target data is greater than the time series in the latest growth sequence; wherein, the first timestamp is the timestamp when the data identifier generation condition is triggered;
[0150] The identification module 206 is used to increment the latest growth sequence if the first timestamp is greater than the time sequence in the latest growth sequence, and use the incremented growth sequence as the updated growth sequence, and form a data identifier based on the updated growth sequence and the node identifier.
[0151] Optionally, the node identifier includes the hardware information corresponding to the node, the process ID of the node, and a random number.
[0152] Optionally, determining the node identifier includes:
[0153] Obtain the hardware information corresponding to the node, concatenate the hardware information into a first string, and obtain the hash value of the first string;
[0154] Obtain the process ID of the node and generate a random number;
[0155] The hash value, process ID, and random number are concatenated to form a node identifier.
[0156] Optionally, the initial module 202 is further configured to use a random number instead of the hash value if obtaining hardware information fails;
[0157] or,
[0158] If obtaining the process ID fails, the hash value of the process name is used instead of the process ID.
[0159] Optionally, the initial module 202 is further configured to determine the initial value of the growth sequence based on the timestamp at node startup, including:
[0160] Obtain the timestamp when the node starts, perform a truncation operation on the timestamp when the node starts, determine the initial value of the time series based on the truncated data, and concatenate the initial value of the time series with the initial value of the tail sequence number to form the initial value of the growth sequence.
[0161] or,
[0162] Determining the target data in the first timestamp includes performing a truncation operation on the first timestamp to determine the target data in the first timestamp.
[0163] Optionally, the identification module 206 is further configured to, if it is determined that the target data is not greater than the time series in the latest growth sequence, wait until the target data in the timestamp after the data identification generation condition is triggered is greater than the time series in the latest growth sequence, then increment the latest growth sequence, use the incremented growth sequence as the updated growth sequence, and form a data identification based on the updated growth sequence and the node identification.
[0164] Optionally, in the formed data identifier, the data corresponding to the updated growth sequence is located before the data corresponding to the node identifier.
[0165] Optionally, the identification module 206 is further configured to, after determining the node identifier, start from the leftmost data of the node identifier and select data of a preset number of positions in order from left to right, convert each selected data into a base-32 numeric character as the base-32 numeric character corresponding to the node identifier; and concatenate the base-32 numeric characters corresponding to the node identifier into a base-32 numeric character group corresponding to the node identifier.
[0166] Optional,
[0167] The data identifier formed based on the updated growth sequence and the node identifier includes: starting from the leftmost data of the updated growth sequence, selecting data of a preset number of positions in order from left to right; converting each data selected by the updated growth sequence into a base-32 numeric character as the base-32 numeric character corresponding to the updated growth sequence; and concatenating each base-32 numeric character corresponding to the updated growth sequence into a base-32 numeric character group corresponding to the updated growth sequence.
[0168] The 32-bit numeric character set corresponding to the node identifier and the 32-bit numeric character set corresponding to the updated growth sequence are concatenated to form a data identifier.
[0169] The third embodiment of this specification provides a data identifier generation device, including:
[0170] At least one processor;
[0171] as well as,
[0172] A memory that is communicatively connected to the at least one processor;
[0173] in,
[0174] The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the data identifier generation method described in Embodiment 1.
[0175] The fourth embodiment of this specification provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the data identifier generation method described in Embodiment 1.
[0176] The above embodiments can be used in combination, and modules with the same name in different embodiments or within the same embodiment can be the same or different modules.
[0177] The foregoing has described specific embodiments of this specification; other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than those shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily have to follow the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0178] The various embodiments in this specification are described in a progressive 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 embodiments of apparatus, devices, and non-volatile computer-readable storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0179] The apparatus, device, non-volatile computer-readable storage medium and method provided in the embodiments of this specification are corresponding. Therefore, the apparatus, device and non-volatile computer storage medium also have similar beneficial technical effects as the corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the corresponding apparatus, device and non-volatile computer storage medium will not be repeated here.
[0180] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0181] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0182] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0183] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware.
[0184] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, the embodiments of this specification can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the embodiments of this specification can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0185] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0186] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0187] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0188] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0189] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0190] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0191] It should also be noted that 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 limitation, 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.
[0192] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0193] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. 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 in the method embodiments.
[0194] The above description is merely an embodiment of this specification and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of this application should be included within the scope of the claims of this application.
Claims
1. A data identifier generation method, characterized in that, include: Determine the node identifier and the latest growth sequence; wherein the growth sequence includes a time sequence and a tail number; wherein determining the node identifier includes: obtaining the hardware information corresponding to the node, concatenating the hardware information into a first string, and obtaining the hash value of the first string; obtaining the process ID of the node, and generating a random number; concatenating the hash value, process ID, and random number into a node identifier; Obtain a first timestamp, determine the target data in the first timestamp, and determine whether the target data is greater than the time series in the latest growth sequence; wherein, the first timestamp is the timestamp when the data identifier generation condition is triggered; If so, the latest growth sequence is incremented, and the incremented growth sequence is used as the updated growth sequence. A data identifier is formed based on the updated growth sequence and the node identifier. The step of forming a data identifier based on the updated growth sequence and the node identifier includes: starting from the leftmost data of the updated growth sequence, selecting data of a preset number of digits sequentially from left to right; converting each data selected by the updated growth sequence into a base-32 numeric character as the base-32 numeric character corresponding to the updated growth sequence; concatenating each base-32 numeric character corresponding to the updated growth sequence into a base-32 numeric character group corresponding to the updated growth sequence; and concatenating the base-32 numeric character group corresponding to the node identifier and the base-32 numeric character group corresponding to the updated growth sequence into a data identifier.
2. The method as described in claim 1, characterized in that, The node identifier includes the hardware information corresponding to the node, the process ID of the node, and a random number.
3. The method as described in claim 1, characterized in that, The method further includes: The initial value of the growth sequence is determined based on the timestamp at which the node starts, including: Obtain the timestamp when the node starts, perform a truncation operation on the timestamp when the node starts, and determine the initial value of the time series based on the truncation data; The initial value of the time series is concatenated with the initial value of the tail index to form the initial value of the growing sequence; or, Determining the target data in the first timestamp includes: Perform a cut operation on the first timestamp to determine the target data in the first timestamp.
4. The method as described in claim 1, characterized in that, The method further includes: If it is determined that the target data is not greater than the time series in the latest growth sequence, then wait until the target data in the timestamp after the data identifier generation condition is triggered is greater than the time series in the latest growth sequence, then increment the latest growth sequence, and use the incremented growth sequence as the updated growth sequence. A data identifier is formed based on the updated growth sequence and the node identifier.
5. The method as described in claim 1, characterized in that, In the resulting data identifier, the data corresponding to the updated growth sequence is located before the data corresponding to the node identifier.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: After determining the node identifier, starting from the leftmost data of the node identifier, select data of a preset number of digits in order from left to right, and convert each selected data into a 32-bit numeric character as the 32-bit numeric character corresponding to the node identifier; concatenate the 32-bit numeric characters corresponding to the node identifier to form the 32-bit numeric character group corresponding to the node identifier.
7. A data identifier generation device, characterized in that, include: An initial module is used to determine the node identifier and the latest growth sequence; wherein the growth sequence includes a time sequence and a tail number; wherein determining the node identifier includes: obtaining the hardware information corresponding to the node, concatenating the hardware information into a first string, and obtaining the hash value of the first string; obtaining the process ID of the node, and generating a random number; concatenating the hash value, process ID, and random number into a node identifier; The judgment module is used to obtain a first timestamp, determine the target data in the first timestamp, and determine whether the target data is greater than the time series in the latest growth sequence; wherein, the first timestamp is the timestamp when the data identifier generation condition is triggered; The identification module is used to increment the latest growth sequence if the first timestamp is greater than the time sequence in the latest growth sequence, and use the incremented growth sequence as the updated growth sequence, and form a data identifier based on the updated growth sequence and the node identifier. The step of forming a data identifier based on the updated growth sequence and the node identifier includes: starting from the leftmost data of the updated growth sequence, selecting data of a preset number of digits sequentially from left to right; converting each data selected by the updated growth sequence into a base-32 numeric character as the base-32 numeric character corresponding to the updated growth sequence; concatenating each base-32 numeric character corresponding to the updated growth sequence into a base-32 numeric character group corresponding to the updated growth sequence; and concatenating the base-32 numeric character group corresponding to the node identifier and the base-32 numeric character group corresponding to the updated growth sequence into a data identifier.
8. The apparatus as claimed in claim 7, characterized in that, The node identifier includes the hardware information corresponding to the node, the process ID of the node, and a random number.
9. The apparatus as claimed in claim 7, characterized in that, The initial module is further configured to determine the initial value of the growth sequence based on the timestamp at node startup, including: Obtain the timestamp of node startup, perform a truncation operation on the timestamp of node startup, determine the initial value of the time series based on the truncated data; concatenate the initial value of the time series with the initial value of the tail sequence number to form the initial value of the growing sequence; or, Determining the target data in the first timestamp includes performing a truncation operation on the first timestamp to determine the target data in the first timestamp.
10. The apparatus as claimed in claim 7, characterized in that, The identification module 206 is further configured to, if it is determined that the target data is not greater than the time series in the latest growth sequence, wait until the target data in the timestamp after the data identification generation condition is triggered is greater than the time series in the latest growth sequence, then increment the latest growth sequence, use the incremented growth sequence as the updated growth sequence, and form a data identification based on the updated growth sequence and the node identification.
11. The apparatus as claimed in claim 7, characterized in that, In the resulting data identifier, the data corresponding to the updated growth sequence is located before the data corresponding to the node identifier.
12. The apparatus according to any one of claims 7 to 11, characterized in that, The identification module is further configured to, after determining the node identifier, select data of a preset number of digits sequentially from left to right, starting from the leftmost data of the node identifier, and convert each selected data into a base-32 numeric character as the base-32 numeric character corresponding to the node identifier. Each 32-bit numeric character corresponding to the node identifier is concatenated to form a 32-bit numeric character group corresponding to the node identifier.
13. A data identifier generation device, comprising: At least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the data identifier generation method according to any one of claims 1 to 6.
14. A computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the data identifier generation method of any one of claims 1 to 6.
Citation Information
Patent Citations
A method and apparatus for calling service
CN110263565A
Serial number generation method and device, electronic equipment and storage medium
CN112035547A