Id generation method, medium, apparatus, and computing device

By acquiring business identifiers, data center information, and machine information, and generating IDs using a combination of high-order and low-order segments, the problem of non-unique ID generation in a globalized multi-data center environment is solved, achieving efficient and stable global unique ID generation, and adapting to high performance and high availability in complex scenarios.

CN116015676BActive Publication Date: 2025-11-28HANGZHOU NETEASE CLOUD MUSIC TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211634255.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-19
Publication Date
2025-11-28
Estimated Expiration
2042-12-19

AI Technical Summary

Technical Problem

In a globalized, multi-datacenter distributed system, existing technologies struggle to generate globally unique IDs, especially when there are time differences and time synchronization issues between datacenters in different regions, leading to uncertainty in ID generation and the risk of duplicate IDs.

Method used

By acquiring the target data's business identifier, data center information, and machine information, an ID is generated using a combination of high-order and low-order segments. This includes binary conversion of the target number, hash processing of the business identifier, data center information, and machine information, and binary concatenation to generate a globally unique ID.

Benefits of technology

It enables efficient and stable generation of globally unique IDs in multi-datacenter environments, supports high performance and high availability, adapts to the needs of geographically dispersed multi-datacenter scenarios in complex scenarios, has high scalability and disaster recovery capabilities, and avoids the impact of time rollback and network latency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116015676B_ABST
    Figure CN116015676B_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure provide an ID generation method. The ID generation method comprises: obtaining a service identifier of target data to be generated with an ID, and generating machine room information and machine information of the target data; in response to the existence of a first number segment corresponding to the service identifier, generating the ID of the target data according to a target number in the first number segment, the service identifier, the machine room information and the machine information, the first number segment comprising a plurality of numbers for generating the ID. Through the number corresponding to the service identifier, the service identifier, the machine room information and the machine information, a unique ID can be generated, thus ensuring the uniqueness and stability of the ID and bringing a better experience for users. In addition, embodiments of the present disclosure provide a medium, an ID generation device and a computing device.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present disclosure relate to the field of data processing, and more particularly, to an ID generation method, medium, device and computing device. BACKGROUND

[0002] This section is intended to provide background information to facilitate a better understanding of embodiments of the present disclosure. Information in this section does not constitute admission of prior art.

[0003] In a complex distributed system architecture or monolithic architecture, in order to distinguish different data, it is often necessary to generate a unique identity document (ID) for the data.

[0004] In related technologies, an ID is usually generated based on the current time by using a snowflake algorithm. However, in a global multi-machine room scenario, there is a certain time difference between different regional machine rooms, and the server also needs a certain time to synchronize the time. If the server is not synchronized with the international time, the time rollback problem occurs, which leads to the uncertainty of ID generation and the duplication of ID. Therefore, there is an urgent need for a solution that can generate a globally unique ID. SUMMARY

[0005] The present disclosure provides an ID generation method, medium, device and computing device to achieve the purpose of generating a globally unique ID.

[0006] In a first aspect of the embodiments of the present disclosure, an ID generation method is provided, comprising: obtaining a business identifier of target data to be generated, and generating machine room information and machine information of the target data; in response to the existence of a first number segment corresponding to the business identifier, generating an ID of the target data according to a target number in the first number segment, the business identifier, the machine room information and the machine information, the first number segment comprising a plurality of numbers for generating the ID.

[0007] In an embodiment of the present disclosure, generating the ID of the target data according to the target number in the first number segment, the business identifier, the machine room information and the machine information comprises: performing binary conversion processing on the target number to obtain a first value; performing hash processing on the business identifier, the machine room information and the machine information to obtain a second value; and performing binary splicing processing on the first value and the second value to obtain the ID.

[0008] In another embodiment of the present disclosure, the service identifier, the machine room information and the machine information are hashed to obtain a second numerical value, including: hashing the service identifier to obtain a first hash value; hashing the machine room information to obtain a second hash value; hashing the machine information to obtain a third hash value; respectively placing the third hash value, the first hash value and the second hash value at high bits, middle bits and low bits of the second numerical value to obtain the second numerical value.

[0009] In yet another embodiment of the present disclosure, the first numerical value and the second numerical value are binary spliced to obtain the ID, including: respectively placing the first numerical value and the second numerical value at high bits and low bits of the ID to obtain the ID.

[0010] In still another embodiment of the present disclosure, further comprising: in response to the first number segment not existing or the usage rate of the number included in the first number segment exceeding a preset value, obtaining a number maximum value and a step value corresponding to the service identifier in the database; determining the second number segment according to the number maximum value and the step value, wherein the number maximum value is a maximum value of the current number in the database; and storing the second number segment.

[0011] In still another embodiment of the present disclosure, determining the second number segment according to the number maximum value and the step value includes: obtaining a sum of the number maximum value and the step value to obtain a number segment maximum value of the second number segment; determining a number segment starting value of the second number segment according to the number maximum value; and determining the second number segment according to the number segment starting value and the number segment maximum value.

[0012] In still another embodiment of the present disclosure, further comprising: sending the number segment maximum value to the database.

[0013] In still another embodiment of the present disclosure, the database includes a master database and a slave database, and obtaining the second number segment in the database includes: in response to the master database being abnormal, obtaining the second number segment in a first database, the first database being a database selected from the slave database and switched to the master database.

[0014] In still another embodiment of the present disclosure, obtaining the service identifier of the target data to be generated ID includes: obtaining the service identifier carried in an ID generation request from a server.

[0015] In a second aspect of the present disclosure, a medium is provided, and the medium stores computer execution instructions, and the computer execution instructions are used to implement the ID generation method of the first aspect when executed by a processor.

[0016] In a third aspect of the embodiments of the present disclosure, an ID generation apparatus is provided, comprising: an acquisition module configured to acquire a service identifier of target data to be generated with an ID, and generate room information and machine information of the target data; and a generation module configured to, in response to a first number segment corresponding to the service identifier existing, generate the ID of the target data according to a target number in the first number segment, the service identifier, the room information and the machine information, the first number segment comprising a plurality of numbers for generating the ID.

[0017] In a fourth aspect of the embodiments of the present disclosure, a computing device is provided, comprising: a processor, and a memory connected to the processor in communication; the memory stores computer execution instructions; and the processor executes the computer execution instructions stored in the memory to implement the ID generation method of the first aspect.

[0018] According to the ID generation method, medium, apparatus and computing device of the embodiments of the present disclosure, by acquiring the service identifier of the target data, and generating the room information and the machine information of the target data, and acquiring the target number corresponding to the service identifier of the target data, the ID of the target data can be generated by the target number, the service identifier, the room information and the machine information, and since the target number, the service identifier, the room information and the machine information are always different, the generated ID is a globally unique ID, thereby providing a better experience for users. BRIEF DESCRIPTION OF DRAWINGS

[0019] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will be more apparent from the following detailed description taken in conjunction with the accompanying drawings, in which:

[0020] FIG. 1 An application scenario diagram of the ID generation method of the embodiments of the present disclosure;

[0021] FIG. 2 Another application scenario diagram of the ID generation method of the embodiments of the present disclosure;

[0022] FIG. 3 A flow diagram of the ID generation method of the embodiments of the present disclosure;

[0023] FIG. 4 An ID segment analysis diagram of the embodiments of the present disclosure;

[0024] FIG. 5 Another flow diagram of the ID generation method of the embodiments of the present disclosure;

[0025] FIG. 6 A structure diagram of the storage medium of the embodiments of the present disclosure;

[0026] FIG. 7 Structure diagram of an ID generation device according to an embodiment of the present disclosure;

[0027] FIG. 8 Structure diagram of a computing device according to an embodiment of the present disclosure.

[0028] In the drawings, identical or corresponding reference signs refer to identical or corresponding parts. DETAILED DESCRIPTION

[0029] The principles and spirits of the present disclosure will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are given only to enable those skilled in the art to better understand and implement the present disclosure, and do not limit the scope of the present disclosure in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0030] Those skilled in the art understand that the embodiments of the present disclosure can be implemented as a system, a device, an apparatus, a method or a computer program product. Therefore, the present disclosure can be embodied as a complete hardware, a complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.

[0031] According to embodiments of the present disclosure, an ID generation method, medium, device and computing device are proposed. In this document, it should be understood that the terms involved are explained as follows:

[0032] Machine room: In the present disclosure, it can represent a certain predetermined area.

[0033] In addition, the number of any elements in the drawings is used for example and not limitation, and any naming is only used for distinction and does not have any limiting meaning.

[0034] In addition, the data involved in the present disclosure can be data authorized by users or fully authorized by all parties, and the collection, dissemination, use, etc. of the data meet the requirements of relevant national laws and regulations. The embodiments of the present disclosure can be combined with each other.

[0035] The principles and spirits of the present disclosure will be described below with reference to several representative embodiments of the present disclosure. SUMMARY

[0037] The present inventors find that in a complex distributed system architecture or a monolithic architecture, a unique ID often needs to be generated for data to distinguish different data. The unique ID features include: globally unique, the ID must be globally unique; high performance, high availability and low latency, the ID generation response needs to be fast; high availability, high availability needs to be met to avoid single point of failure; easy to access, easy to understand and access; and trend increasing. In the related art, there are mainly the following ways:

[0038] One is a Universally Unique Identifier (UUID) based approach. The UUID is simple to use, but the UUID is an unordered string and does not have the trend increasing feature, and is not suitable for actual business requirements. For example, the UUID used as an order number has no practical meaning, and cannot show useful information related to the UUID and the order. For a database, the UUID is not only a string, but also the string is too long, the storage performance is poor, and the query is time-consuming, and is not suitable for business primary ID.

[0039] Another is a database-based auto-increment ID approach. The database-based auto-increment ID can completely serve as a distributed ID, and the specific implementation is: a separate MySQL instance is needed to generate the ID, and when an ID is needed, a record is inserted into the table to return the primary key ID. Although this approach is simple to implement, the ID can be monotonically increased, and the numerical type query speed is fast, but when the access volume surges, the MySQL has a risk of downtime and cannot withstand high concurrency scenarios, and therefore, it is not easy to implement distributed services.

[0040] Another is a database-based number segment mode. The number segment mode can batch obtain the auto-increment ID from the database, and each time a number segment range is obtained from the database, for example, (1, 1000] represents 1000 IDs, and the specific business service generates 1-1000 auto-increment IDs from the number segment and loads them into the memory. If the IDs in the batch number segment are used up, a new number segment is applied to the database. Although this approach is simple to implement and has good performance, it cannot adapt to global data centers and can only be used in a single data center.

[0041] Another is a Snowflake-based method. The composition of the ID generated by Snowflake is: positive digits (1 bit) + timestamp (41 bits) + machine ID (5 bits) + data center (5 bits) + auto-increment value (12 bits), a total of 64 bits to form a Long type. This method can meet the business requirements in terms of performance and uniqueness in an ideal environment, but in actual production, there is a certain time error in multi-region machine rooms, and server time synchronization also needs a certain time. Once the server and international time are out of sync, time rollback may occur, which may cause uncertainty in ID generation and produce duplicate IDs.

[0042] Therefore, the present disclosure provides an ID generation method, which divides the namespace by using the combination of high-bit number segments and low-bit segments to generate IDs. The IDs can be divided into multiple segments, and the auto-increment step, machine information, and machine room information are represented separately. The step is used for the auto-increment model of different machine rooms, and the machine information and machine room information are used to distinguish that the ID comes from different spaces to ensure uniqueness. At the same time, the method provides a splitting method according to different business modes to improve stability and scalability. Thus, a unique ID with high efficiency, high performance, high availability, high scalability, and support for multi-machine rooms in different places can be generated. In the case of multi-machine rooms due to regional delay and clock desynchronization, a globally unique ID can still be generated with high performance.

[0043] After introducing the basic principles of the present disclosure, various non-limiting embodiments of the present disclosure will be specifically introduced below.

[0044] Overview of Application Scenarios

[0045] First, refer to FIG. 1 , FIG. 1 is a schematic diagram of an application scenario of the ID generation method of the embodiment of the present disclosure. In FIG. 1In the remote service mode (also known as the application service mode), both server 11 and server 12 can send requests to number generators 111, 112, and 113 to obtain IDs. Upon receiving a request, number generators 111, 112, and 113 retrieve the corresponding number segment information from the database. The number segment information retrieved by number generator 111 can be from 1 to 1000, by number generator 112 from 1001 to 2000, and by number generator 113 from 2001 to 3000. After obtaining the corresponding number segment information, the number generator determines the target number from the number segment information and simultaneously obtains the business identifier, machine information, and data center information. Using the target number, business identifier, machine information, and data center information, a globally unique ID can be generated. For example, number generator 111 can generate user IDs, denoted as UID; number generator 112 can generate order IDs, denoted as orderID; and number generator 113 can generate song IDs, denoted as songID.

[0046] In this scenario, when an ID generation error occurs in the application service mode, the centralized ID generator uses a distributed deployment and has a certain load balancing capability. When some ID generators malfunction, the load can be balanced to the other ID generator nodes, thus not affecting normal use.

[0047] FIG. 2 This is a schematic diagram illustrating another application scenario of the ID generation method according to the present disclosure. FIG. 2 In the Software Development Kit (SDK) model, FIG. 1 The ID generator can be deployed as an SDK on the server. Specifically, SDK211 is deployed on server 21, SDK212 on server 22, and SDK213 on server 23. The SDK obtains the request for ID generation locally on the server and then retrieves the corresponding number range information from the database. Specifically, SDK211 retrieves number range information from the database for numbers 1 to 1000, SDK212 retrieves number range information from the database for numbers 1001 to 2000, and SDK213 retrieves number range information from the database for numbers 2001 to 3000. The ID generator generates UID, orderID, and songID. After obtaining the corresponding number range information, the SDK determines the target number from the number range information and simultaneously obtains the business identifier, machine information, and data center information. Using the target number, business identifier, machine information, and data center information, a globally unique ID can be generated. For example, SDK211 can generate a user ID, denoted as UID; SDK212 can generate an order ID, denoted as orderID; and SDK213 can generate a song ID, denoted as songID.

[0048] In this scenario, when the ID generated in the SDK mode is abnormal, since the SDK is deployed in the server, in the abnormal case, only the single server interface is affected, and the influence is not spread.

[0049] Exemplary Method

[0050] The ID generation method according to the exemplary embodiments of the present disclosure will be described below in conjunction with the application scenarios of FIG. 1 and FIG. 2 , with reference to FIG. 3 . It should be noted that the above-mentioned application scenarios are only shown for the purpose of facilitating the understanding of the spirit and principles of the present disclosure, and the embodiments of the present disclosure are not limited in this respect. On the contrary, the embodiments of the present disclosure can be applied to any applicable scenario.

[0051] Referring to FIG. 3 , FIG. 3 is a flowchart of the ID generation method according to the embodiments of the present disclosure, as shown in FIG. 3 , the ID generation method can be applied to a number generator as shown in FIG. 1 or an SDK as shown in FIG. 2 , and the ID generation method comprises the following steps:

[0052] S301: Obtain the business identifier of the target data to be generated ID, and generate the machine room information and the machine information of the target data.

[0053] Specifically, the business identifier can be the identifier information of different businesses, such as order business and express business, etc., and the identifier information is different. The machine room information can be the geographic location information of a preset area, such as a certain country, a certain city, a certain district, etc. The machine information can be the Internet Protocol Address (IP Address) information of the machine.

[0054] Specifically, the business identifiers corresponding to different businesses are different, the geographic location information of different machine rooms is different, and the IP addresses of different machines are different.

[0055] S302: In response to the existence of the first number segment corresponding to the business identifier, generating the ID of the target data according to the target number in the first number segment, the business identifier, the machine room information and the machine information.

[0056] In this step, the first number segment includes a plurality of numbers for generating ID.

[0057] Specifically, different service types correspond to different number segments, so it can be determined whether there is a number segment corresponding to the service identifier, that is, whether the first number segment is stored locally. If the first number segment exists, the target number can be determined in the first number segment, so that the ID of the target data is generated according to the target number, the service identifier, the machine room information and the machine information. Alternatively, after it is determined that the first number segment is stored locally, it can also be determined whether the capacity of the first number segment needs to be expanded. If not, the ID of the target data is generated according to the target number in the first number segment, the service identifier, the machine room information and the machine information.

[0058] Specifically, since different service identifiers correspond to different number segments, different services correspond to different service identifiers, different machine rooms correspond to different geographic location information, and different machines correspond to different IP addresses, the ID generated by the target number, the service identifier, the machine room information and the machine information is definitely globally unique. In addition, since the machine room information is mixed in the ID, data synchronization will not be performed in a multi-country scenario, and each machine room is independently deployed, so that a unique ID can be generated when the multi-country and multi-place network is interrupted.

[0059] Alternatively, the local storage structure can be ConcurrentHashMap, which guarantees concurrent safety. ConcurrentHashMap includes key and value, wherein the key can be used to represent service type data, and the value can be used to store the current number segment information and step length.

[0060] The ID generation method of the present disclosure can generate an ID for the target data by obtaining the service identifier of the target data, generating the machine room information and the machine information of the target data, and obtaining the target number corresponding to the service identifier of the target data. Since the target number, the service identifier, the machine room information and the machine information always differ, the generated ID is a globally unique ID, thereby providing better experience for users.

[0061] In an embodiment of the present disclosure, the ID of the target data is generated according to the target number in the first number segment, the service identifier, the machine room information and the machine information, including: performing binary conversion processing on the target number to obtain a first value; performing hash processing on the service identifier, the machine room information and the machine information to obtain a second value; and performing binary splicing processing on the first value and the second value to obtain the ID.

[0062] In this embodiment, the first number segment can represent a value range of the number, for example, the first number segment is 1 to 100, or 301 to 700, etc. An unused number can be arbitrarily taken in the first number segment, or the first unused number is taken as a target number, and then the target number is subjected to binary conversion processing to obtain a binary value, that is, a first value.

[0063] In this embodiment, the service identifier, the machine room information and the machine information can also be converted into binary values, that is, a second value, so that the first value and the second value which are both binary values can be spliced to obtain an ID of the target data. Since each part of the obtained ID has actual business significance, and the target number, the service identifier, the machine room information and the machine information are different, the obtained ID is a globally unique ID with actual business significance.

[0064] In one embodiment of the present disclosure, the service identifier, the machine room information and the machine information are subjected to hash processing to obtain the second value, including: the service identifier is subjected to hash processing to obtain a first hash value; the machine room information is subjected to hash processing to obtain a second hash value; and the machine information is subjected to hash processing to obtain a third hash value; the third hash value, the first hash value and the second hash value are respectively placed in high bits, middle bits and low bits of the second value to obtain the second value.

[0065] In this embodiment, since the second value includes the service identifier, the machine room information and the machine information, the three kinds of information can be subjected to hash processing respectively to obtain three hash values. The second value can be obtained by shifting the obtained three hash values. Thus, the obtained ID has global uniqueness.

[0066] Specifically, the first hash value corresponding to the service identifier can be placed in the middle bits of the second value, the second hash value corresponding to the machine room information can be placed in the low bits of the second value, and the third hash value corresponding to the machine information can be placed in the high bits of the second value, so as to obtain the second value.

[0067] Optionally, the third hash value can be a machine identifier code obtained by subjecting the machine information to hash processing, which is 8 bits; the first hash value is self-defined identifier information of the service, which can be 6 bits; and the second hash value is identifier information of a global machine room, which can be 4 bits, and at most 16 machine rooms can be supported.

[0068] Optionally, to adapt to different scenarios, part of the hash values in the second value can be configured by itself, for example, in the scenario of a single machine room or no machine room, the number of bits corresponding to the machine room information can be set to 0 to save the length of the ID.

[0069] Optionally, the positions of the first hash value, the second hash value and the third hash value can also be shifted according to actual requirements.

[0070] In one embodiment of the present disclosure, the first value and the second value are subjected to binary splicing to obtain the ID, including: respectively placing the first value and the second value at high bits and low bits of the ID to obtain the ID.

[0071] In this embodiment, after obtaining the first value and the second value, since the first value is obtained by binary conversion of the target number in the first number segment, the number of bits is uncertain, while the number of bits of the service identifier, the machine room information and the machine information in the second value is determined, therefore, the first value can be placed at high bits of the ID, and the second value can be placed at low bits of the ID, so as to improve the stability of ID generation, and the ID generation can have certain expansibility.

[0072] Optionally, the segment analysis of the ID can be as shown in FIG. 4 FIG. 4 FIG. 1 is a schematic diagram of segment analysis of the ID according to an embodiment of the present disclosure, in which FIG. 4 the ID has 40 bits in total, of which 22 high bits are the first value corresponding to the target number, i.e. the increment step, and 18 low bits are the second value corresponding to the service identifier, the machine room information and the machine information, in which 8 high bits of the second value are the third hash value corresponding to the machine information, 6 middle bits are the first hash value corresponding to the service identifier, and 4 low bits are the second hash value corresponding to the machine room information. Optionally, the ID can be inversely analyzed to obtain the machine room information and the cluster information to which the machine room belongs.

[0073] In one embodiment of the present disclosure, further comprising: S303, in response to the absence of the first number segment, or the usage rate of the number included in the first number segment exceeding a preset value, obtaining the maximum number and the step value corresponding to the service identifier in the database; determining the second number segment according to the maximum number and the step value, wherein the maximum number is the maximum number of the current number in the database; and storing the second number segment.

[0074] In this embodiment, if the first number segment corresponding to the service identifier does not exist, i.e. the first number segment is not stored locally, a new number segment needs to be obtained from the database. Alternatively, the first number segment exists, but the usage rate of the number in the first number segment exceeds the preset value, i.e. the first number segment is stored locally, but the usage of the number in the first number segment exceeds the loading factor (default is 0.75), therefore, a new number segment needs to be asynchronously preloaded, for example, the first number segment stored locally is 1 to 1000, but the number has been obtained to 751, which exceeds the loading factor 0.75, therefore, the capacity of the first number segment needs to be expanded.

[0075] ​Specifically, the step value corresponding to different service identifiers can be different, such as 100 for A service, 400 for B service, and 1000 for C service. The database stores the maximum value of the current number and the step value corresponding to different service identifiers. When a new number segment needs to be obtained, the step value corresponding to the current service identifier can be obtained from the database, and the maximum value of the current number can be obtained, so that the new number segment, that is, the second number segment, can be obtained. For example, the step value is 100, and the maximum value of the current number is 600, so the second number segment is 601 to 700. After obtaining the second number segment, the second number segment is stored for subsequent use.

[0076] Optionally, the step value stored in the database can be modified according to actual needs.

[0077] Optionally, by obtaining the step value and the maximum value of the current number in the database, the new number segment can be quickly obtained, and the step values corresponding to different service identifiers are different, which can ensure the rationality of generating IDs corresponding to different services and avoid occupying numbers due to too long step values or frequent acquisition of number segments due to too short step values.

[0078] In an embodiment of the present disclosure, the second number segment is determined according to the maximum number value and the step value, comprising: obtaining the sum of the maximum number value and the step value to obtain the maximum number segment value of the second number segment; determining the starting number segment value of the second number segment according to the maximum number value; and determining the second number segment according to the starting number segment value and the maximum number segment value.

[0079] In this embodiment, after obtaining the maximum value of the current number, that is, the maximum number value, and the step value corresponding to the service identifier in the database, the sum of the maximum number value and the step value can be used as the maximum number segment value of the new number segment, that is, the maximum number segment value of the second number segment. For example, the maximum number value is 200, and the step value is 300, so the maximum number segment value of the second number segment is 200+300=500, that is, the second number segment needs to start from 201 (200 has been in the database and may have been used, so the starting value of the second number segment needs to be 1 more than the maximum number value) to 500.

[0080] Optionally, by obtaining the step value and the maximum value of the current number in the database, the new number segment can be quickly obtained, and the step values corresponding to different service identifiers are different, which can ensure the rationality of generating IDs corresponding to different services and avoid occupying numbers due to too long step values or frequent acquisition of number segments due to too short step values.

[0081] In an embodiment of the present disclosure, it further comprises: S304, sending the maximum number segment value to the database.

[0082] In this embodiment, after the second number segment is determined, in order to facilitate the next time to obtain a new number segment, the number segment maximum value of the second number segment can be stored in the database, so that the next time to obtain a new number segment can add 1 to the number segment maximum value of the second number segment as the number segment starting value of the new number segment.

[0083] In an embodiment of the present disclosure, the database includes a master database and a slave database, and obtaining the second number segment in the database includes: in response to an exception of the master database, obtaining the second number segment in the first database, the first database being a database selected from the slave database and switched to the master database.

[0084] In this embodiment, in order to avoid the database exception leading to the inability to obtain a new number segment, thereby affecting the ID generation, the database can be deployed in a distributed manner and adopt a one-master multi-slave deployment architecture, so that when an exception occurs in the database layer, there is a certain disaster recovery and fault tolerance capability.

[0085] Specifically, the database single point exception, because of using the distributed deployment of database and table, the exception of a single database node only damages part of the business scenario, therefore, the node switching method can be used to restore the database function, that is, the normal slave database is switched to replace the abnormal slave database.

[0086] Specifically, the master database exception, because of using the one-master multi-slave manner, when the master database is in a large area of unavailability, the master-slave switching can be performed to switch the slave database to the master database, thereby recovering the database function.

[0087] Specifically, when the database as a whole is unavailable, or the database network is interrupted, because part of the number is stored locally, the service can still be provided for a short time until the database recovers or the network recovers.

[0088] In an embodiment of the present disclosure, the business identifier of the target data to be generated ID is obtained, including: obtaining the business identifier carried in the ID generation request from the server.

[0089] In this embodiment, the server (also can be called as application service layer) can generate the ID generation request, and the request carries the business identifier. The server can assemble the remote service mode as shown in FIG. 1 or as shown in FIG. 2The interface parameter in the SDK mode is shown, the main parameter in the interface parameter is a service type parameter, the service type parameter is a String string type, and is used for ID uniqueness judgment. The ID obtained by the service type parameter is different because the numbers in the number segment are different. The ID obtained by different service type parameters is different because the service type parameters themselves are different. The service type parameter is determined by the upper service party. The server generates an ID generation request after determining the service type. The server can request the local in the SDK mode, and needs to initiate a remote request to request the number generator in the remote service mode.

[0090] The ID generation method shown in FIG. 3 may also be described by another process. Referring to FIG. 5 , FIG. 5 is another process diagram of the ID generation method of the embodiment of the present disclosure. As shown in FIG. 5 , the ID generation method can be applied to the number generator as shown in FIG. 1 or the SDK as shown in FIG. 2 . The ID generation method comprises the following steps:

[0091] S501: Obtain an ID generation request from a server, and the ID generation request carries a service identifier.

[0092] S502: Determine whether the local caches a number segment corresponding to the service identifier.

[0093] Specifically, if the local does not cache the number segment, jump to step S506, and if the local caches the number segment, jump to step S503.

[0094] S503: Determine whether the numbers in the locally cached number segment are exhausted.

[0095] Specifically, if the numbers in the number segment are exhausted, jump to step S506, and if the numbers in the number segment are not exhausted, jump to step S504.

[0096] S504: Determine whether the numbers in the number segment need to be expanded.

[0097] Specifically, if the numbers in the number segment need to be expanded, jump to step S55, and if the numbers in the number segment do not need to be expanded, jump to step S509.

[0098] S505: Asynchronously pre-allocate numbers in the database according to the loading factor.

[0099] S506: Obtain a new number segment according to the step value corresponding to the service identifier stored in the database.

[0100] S507: Send the maximum value of the new number segment to the database.

[0101] S508: locally store the new number segment.

[0102] S509: determine the unique ID according to the target number in the number segment, and the service identifier, the machine room information, and the machine information.

[0103] The ID generation method provided by the present disclosure has the following advantages:

[0104] It has high scalability, provides an SDK mode, deploys SDK in each server, and can obtain a unique ID by calling a local service without load balancing allocation of traffic and avoiding instability caused by centralized services; supports a relatively flexible number generator deployment mode, and the number generator can be individually deployed according to its own needs to avoid mutual influence.

[0105] It has high performance. In theory, the limit of the transaction per second (TPS) is the hardware persistence layer, and the TPS formula is: step value * persistence layer. For example, the step is configured as 1000, the persistence layer is selected as a single-instance mysql, the single-point TPS is 3000, and the highest TPS is 1000*3000=100w tps. For another example, the step is configured as 100, the persistence layer is selected as redis, the single-point TPS is 10w, and the highest theoretical tps is 100*10w=1000w tps.

[0106] It can avoid clock influence. The timestamp is not used as part of the id, so it is not affected by time reversal in a global range.

[0107] It is suitable for complex scenarios. In the scenarios of multiple countries and regions in the world, multiple regions cannot use a separate centralized persistence layer due to network delay fluctuations caused by address distance. The present disclosure can be split and individually deployed in multiple machine rooms. Each number generator relies on the persistence layer of the respective machine room to avoid performance and stability influence caused by network fluctuations.

[0108] It has complete disaster recovery capability. The database uses multi-node distributed deployment, and damage to a certain node does not affect normal use. The database is deployed as one master and multiple slaves. If the master database is abnormal, master-slave switching can be performed. The switching time is in the order of minutes, that is, there will be a minute-level unavailability, so the influence is small. If the database network is abnormal or the one master and multiple slave databases cannot work normally, the number generator itself has a certain number of number segment caches, and services can still be provided in a short time until the database recovers. Cross-country and cross-machine room, no network interaction, avoid mutual influence and data inconsistency.

[0109] The number of IDs that can be generated is relatively large. The technical solution provided in this disclosure can support up to 2^(64-18) = 70368744177664 IDs, which is sufficient to support the long-term development of the business.

[0110] A load factor is used to avoid short-term jitter caused by real-time loading. When the usage of a local number segment exceeds the load factor, the next sequence of number segments will be loaded in advance to avoid loading jitter when the number segments are exhausted.

[0111] Exemplary Medium

[0112] After introducing the methods of exemplary embodiments of this disclosure, the following references are made. FIG. 6 The medium for exemplary embodiments of this disclosure will be described.

[0113] FIG. 6 This is a schematic diagram of the structure of the storage medium according to an embodiment of the present disclosure, with reference to... FIG. 6 As shown, the medium can be a storage medium 60 storing a program product for implementing the above-described method according to embodiments of the present disclosure. This storage medium can be a portable compact disc read-only memory (CD-ROM) and includes computer-executable instructions for causing a computing device to execute the ID generation method provided in this disclosure. However, the program product of this disclosure is not limited to this.

[0114] The program product disclosed herein can take the form of any combination of one or more readable media. A readable medium can be a readable signal medium or a readable storage medium. A readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0115] A readable signal medium may include data signals propagated in baseband or as part of a carrier wave, carrying computer-executed instructions. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium.

[0116] Computer-executable instructions for performing the operations of the present disclosure can be written in any combination of one or more programming languages, including an object-oriented programming language such as Java, C++, or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-executable instructions can execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device or entirely on the remote computing device or server. In the latter scenario, the remote computing device can be connected to the user's device through any kind of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).

[0117] Exemplary Apparatus

[0118] Having introduced the medium of the exemplary embodiments of the present disclosure, next, reference is made to the drawings to describe in detail the exemplary embodiments of the present disclosure. FIG. 7 The ID generation apparatus of the exemplary embodiments of the present disclosure is described, which is used to implement the method in any of the method embodiments, and has similar implementation principles and technical effects, which will not be described here.

[0119] FIG. 7 The structure schematic diagram of the ID generation apparatus of the embodiments of the present disclosure is shown in FIG. 7, which includes: FIG. 7

[0120] The obtaining module 701 is configured to obtain the service identifier of the target data to be generated ID, and obtain the machine room information and the machine information of the target data.

[0121] The generating module 702 is configured to, in response to the existence of the first number segment corresponding to the service identifier, generate the ID of the target data according to the target number in the first number segment, the service identifier, the machine room information and the machine information, and the first number segment includes a plurality of numbers for generating the ID.

[0122] Optionally, the generating module 702 implements the generation of the ID of the target data according to the target number in the first number segment, the service identifier, the machine room information and the machine information by the following steps: performing binary conversion processing on the target number to obtain a first value; performing hash processing on the service identifier, the machine room information and the machine information to obtain a second value; and performing binary splicing processing on the first value and the second value to obtain the ID.

[0123] ​Optionally, the generating module 702 implements the hash processing on the service identifier, the machine room information and the machine information to obtain the second numerical value by the following steps: performing hash processing on the service identifier to obtain a first hash value; performing hash processing on the machine room information to obtain a second hash value; performing hash processing on the machine information to obtain a third hash value; and placing the third hash value, the first hash value and the second hash value at high bits, middle bits and low bits of the second numerical value respectively to obtain the second numerical value.

[0124] Optionally, the generating module 702 implements the binary splicing processing on the first numerical value and the second numerical value to obtain the ID by the following steps: placing the first numerical value and the second numerical value at high bits and low bits of the ID respectively to obtain the ID.

[0125] Optionally, the ID generating apparatus 700 further includes a processing module 703 configured to: in response to the first number segment not existing or the usage rate of the number included in the first number segment exceeding a preset value, acquire a maximum number and a step value corresponding to the service identifier in the database; determine the second number segment according to the maximum number and the step value, wherein the maximum number is a maximum value of the current number in the database; and store the second number segment.

[0126] Optionally, the processing module 703 determines the second number segment according to the maximum number and the step value by the following steps: obtains a sum of the maximum number and the step value to obtain a maximum number segment value of the second number segment; determines a starting number segment value of the second number segment according to the maximum number; and determines the second number segment according to the starting number segment value and the maximum number segment value.

[0127] Optionally, the ID generating apparatus 700 further includes a sending module 704 configured to send the maximum number segment value to the database.

[0128] Optionally, the database includes a master database and a slave database, and the processing module 703 acquires the second number segment in the database by the following steps: in response to the master database being abnormal, acquires the second number segment in a first database, wherein the first database is a database selected from the slave database and switched to the master database.

[0129] Optionally, the acquiring module 701 acquires the service identifier of the target data to be generated by the ID by the following steps: acquires the service identifier carried in an ID generation request from a server.

[0130] Exemplary Computing Device

[0131] After introducing the method, medium and apparatus of the example embodiments of the present disclosure, next, reference is made to FIG. 8 The computing device of the example embodiments of the present disclosure is described.

[0132] FIG. 8The computing device 80 shown is only one example of a computing device and should not be taken in a limiting sense, as the scope of embodiments of the present disclosure encompasses other computing devices that have fewer components or more components, different configurations of components, mount different versions of the same components, or the like.

[0133] FIG. 8 A schematic diagram of a computing device for embodiments of the present disclosure is shown in FIG. 8. FIG. 8 As shown in FIG. 8, the computing device 80 is in the form of a general- purpose computing device. The components of computing device 80 can include, but are not limited to, one or more processors 801, one or more storage devices 802, and a bus 803 that connects the various system components, including the processor 801 and the storage device 802. The storage device 802 includes a memory that stores computer-executable instructions for implementing the methods described above. The processor 801 executes the computer-executable instructions to implement the methods described above.

[0134] The bus 803 includes an address bus, a control bus, and a data bus.

[0135] The storage device 802 can include a readable medium that is in the form of volatile memory, such as a random access memory (RAM) 8021 and / or cache memory 8022, and can further include a readable medium that is in the form of non-volatile memory, such as read-only memory (ROM) 8023.

[0136] The storage device 802 can also include a program / utility 8025 having a set (at least one) of program modules 8024, including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or a combination thereof can include an implementation of a network environment.

[0137] The computing device 80 can also communicate with one or more external devices 804 (e.g., a keyboard, a pointing device, etc.) via an input / output (I / O) interface 805. Further, the computing device 80 can communicate with one or more networks, such as a local area network (LAN), a wide area network (WAN), and / or the public network, such as the Internet, via a network adapter 806. As FIG. 8 illustrated, the network adapter 806 communicates with the other modules of the computing device 80 via the bus 803. It should be understood that although not shown, other hardware and / or software modules could be used in conjunction with the computing device 80. These include, but are not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data archival storage systems, etc.

[0138] It should be noted that although several units / modules or sub-units / modules of the ID generating apparatus are mentioned in the foregoing detailed description, such a division is merely exemplary and not mandatory. Indeed, according to an embodiment of the disclosure, the features and functionalities of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functionalities of one unit / module described above can be further divided into units / modules embodied by several units / modules.

[0139] Moreover, although the operations of the methods of the present disclosure are described in a particular, sequential order, this order is not meant to be a limitation and is not intended to imply that there is an absolute requirement that the operations be performed in the order described. On the contrary, many of the aspects described can be performed in any order, omitted, substituted, and / or combined other aspects to be within the scope of the disclosure. Additionally or alternatively, certain of the described aspects can be performed concurrently, e.g., accomplished in parallel, and / or accomplished separately.

[0140] While the spirit and principles of the present disclosure have been described with reference to several specific embodiments, it is to be understood that the disclosure is not limited to the specific embodiments disclosed and that modifications to various aspects can be effected without departing from the spirit of the disclosure. The disclosure is therefore intended to cover all reasonable modifications and equivalent arrangements resided within the spirit and scope of the appended claims.

Claims

1. An ID generation method, said method being applied in both Software Development Kit (SDK) mode and remote service mode scenarios, characterized in that, include: Obtain the business identifier of the target data to be generated, as well as the data center information and machine information for generating the target data; In response to the existence of a first number segment corresponding to the service identifier, the target number in the first number segment is subjected to binary conversion to obtain a first value. The service identifier is hashed to obtain a first hash value; The data center information is hashed to obtain a second hash value; The machine information is hashed to obtain a third hash value; The third hash value, the first hash value, and the second hash value are respectively placed in the high, middle, and low bits of the second value to obtain the second value; The first value and the second value are placed in the high and low bits of the ID respectively to obtain the ID of the target data. The first number segment includes multiple numbers used to generate the ID. It also includes: when the numbers in the locally cached number segment are not exhausted, in response to the absence of the first number segment or the usage rate of the numbers included in the first number segment exceeding a preset value, obtaining the maximum number value and the step value corresponding to the service identifier from the database; The sum of the maximum number value and the step size value is obtained to get the maximum number value of the second number segment; Based on the maximum value of the number, determine the starting value of the second number segment; The second number segment is determined based on the starting value and the maximum value of the number segment, wherein the maximum value of the number is the maximum value of the current number in the database; Store the second segment.

2. The ID generation method according to claim 1, characterized in that, Also includes: Send the maximum value of the number segment to the database.

3. The ID generation method according to claim 1, characterized in that, The database includes a master database and a slave database. Obtaining the second number segment from the database includes: In response to the main database anomaly, the second number segment is retrieved from the first database, which is the database selected from the slave databases to switch to the main database.

4. The ID generation method according to claim 1, characterized in that, The business identifier for obtaining the target data to be generated ID includes: Obtain the business identifier carried in the ID generation request from the server.

5. A medium, characterized in that, The medium stores computer execution instructions, which, when executed by a processor, are used to implement the ID generation method as described in any one of claims 1 to 4.

6. An ID generation device, the device being applied in both Software Development Kit (SDK) mode and remote service mode scenarios, characterized in that, include: The acquisition module is used to acquire the business identifier of the target data to be generated, as well as the data center information and machine information for generating the target data; The generation module is configured to, in response to the existence of a first number segment corresponding to the service identifier, perform binary conversion processing on the target number in the first number segment to obtain a first value; perform hash processing on the service identifier, the data center information, and the machine information to obtain a second value; and perform binary concatenation processing on the first value and the second value to obtain the ID of the target data, wherein the first number segment includes multiple numbers used for generating IDs; The generation module performs hash processing on the service identifier, the data center information, and the machine information through the following steps to obtain the second value: The service identifier is hashed to obtain a first hash value; The data center information is hashed to obtain a second hash value; The machine information is hashed to obtain a third hash value; The third hash value, the first hash value, and the second hash value are respectively placed in the high, middle, and low bits of the second value to obtain the second value; The generation module performs binary concatenation processing on the first value and the second value through the following steps to obtain the ID: The first value and the second value are placed in the high and low bits of the ID respectively to obtain the ID; It also includes: a processing module, used to, when the numbers in the locally cached number segment are not exhausted, in response to the absence of the first number segment or the usage rate of the numbers included in the first number segment exceeding a preset value, obtain the maximum number value and the step value corresponding to the service identifier from the database; determine the second number segment based on the maximum number value and the step value, wherein the maximum number value is the maximum value of the current number in the database; and store the second number segment; The processing module determines the second number segment based on the maximum number value and the step size value through the following steps: The sum of the maximum number value and the step size value is obtained to get the maximum number value of the second number segment; Based on the maximum value of the number, determine the starting value of the second number segment; The second number segment is determined based on the starting value and the maximum value of the number segment.

7. The ID generation apparatus according to claim 6, characterized in that, Also includes: The sending module is used to send the maximum value of the number segment to the database.

8. The ID generation apparatus according to claim 6, characterized in that, The database includes a master database and a slave database. The processing module retrieves the second number segment from the database through the following steps: In response to the main database anomaly, the second number segment is retrieved from the first database, which is the database selected from the slave databases to switch to the main database.

9. The ID generation apparatus according to claim 6, characterized in that, The acquisition module obtains the business identifier of the target data to be generated ID through the following steps: Obtain the business identifier carried in the ID generation request from the server.

10. A computing device, comprising: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the ID generation method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Global unique ID generating method and system and storage medium

    CN108108252A

  • Data object identifier generation method and device, computer equipment and storage medium

    CN110750506A

  • Data identifier generation method and device, equipment and storage medium

    CN113163027A