Distributed unique identification code generation method and device, computer equipment and medium
By pre-setting the association between the preset type bit and the processing system in the distributed system, the problem of multiple systems using the SnowFlake algorithm to generate duplicate IDs is solved, realizing the uniqueness of the distributed unique identifier and the system stability, and avoiding data errors.
Patent Information
- Application Number
- CN202010575714.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-22
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2040-06-22
AI Technical Summary
When multiple systems share the SnowFlake algorithm to generate distributed unique identifiers, there is a risk of generating duplicate IDs, which can lead to errors in business processes, especially when searching for insurance policy numbers, where it is easy to find the wrong data.
By pre-setting the association between preset type bits and the distributed processing system, the corresponding distributed processing system is determined according to the incremented preset type bits after receiving the processing request, ensuring that a unique distributed identification code is generated at each time point and avoiding duplication.
This effectively avoids system data errors caused by duplicate distributed unique identifiers (IDs), improves the accuracy of generated IDs and system stability, and ensures the correctness of business processes.
Smart Images

Figure CN111709216B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, in particular to a distributed unique identification code generation method and device, computer equipment and medium. BACKGROUND
[0002] In the SnowFlake algorithm, the method of generating a distributed unique identification code id is commonly used in the case of independent use of a system. If two systems use the same database at the same time, that is, the two systems have intersections, the same id generation rule needs to be used. The traditional method is to generate an id in each system using the SnowFlake method.
[0003] However, there is a certain probability that the two systems generate the same distributed unique identification code id at a certain time node. If the insert database operation is executed, the distributed unique identification code id will be reported as a duplicate entry, and if the distributed unique identification code id is used in a business scenario, it is difficult to find and trace the problem, which may eventually lead to serious consequences, such as finding wrong data according to the same distributed unique identification code id generated by the insurance policy number, affecting the entire business flow of the insurance policy. SUMMARY
[0004] Therefore, it is necessary to provide a distributed unique identification code generation method, device, computer equipment and medium capable of improving the generation accuracy of the identification code in the algorithm to solve the above technical problems.
[0005] A distributed unique identification code generation method, the method comprising:
[0006] receiving a processing request sent by a terminal and obtaining a current system time;
[0007] obtaining a last generated distributed unique identification code, and incrementing a preset type bit in the last generated distributed unique identification code;
[0008] obtaining a current distributed unique identification code according to the incremented preset type bit and the current system time;
[0009] obtaining a distributed processing system corresponding to the incremented preset type bit, the association between the preset type bit and the distributed processing system being pre-set;
[0010] associating and distributing the processing request and the current distributed unique identification code to the obtained distributed processing system.
[0011] In one embodiment, the obtaining of the distributed processing system corresponding to the incremented preset type bit comprises:
[0012] obtain a reference value corresponding to the preset type bit;
[0013] calculate a remainder obtained by performing a modulo operation on the reference value after incrementing the preset type bit;
[0014] obtain the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder.
[0015] In one embodiment, the processing request carries a system identifier; and the obtaining the distributed processing system corresponding to the incremented preset type bit comprises:
[0016] obtain a reference value corresponding to the preset type bit;
[0017] calculate a remainder obtained by performing a modulo operation on the reference value after incrementing the preset type bit;
[0018] determine whether the remainder corresponds to the distributed processing system corresponding to the system identifier;
[0019] when the remainder corresponds to the distributed processing system corresponding to the system identifier, the distributed processing system corresponding to the system identifier is taken as the distributed processing system corresponding to the incremented preset type bit;
[0020] when the remainder does not correspond to the distributed processing system corresponding to the system identifier, a last generated distributed unique identifier is obtained, and the preset type bit in the last generated distributed unique identifier is incremented until the remainder corresponds to the distributed processing system corresponding to the system identifier.
[0021] In one embodiment, the generation manner of the association relationship between the preset type bit and the distributed processing system comprises:
[0022] obtain the number of distributed processing systems and the bit number of the preset type bit;
[0023] evenly divide the bit number of the preset type bit according to the number of the distributed processing systems;
[0024] establish an association relationship between the distributed processing systems and the evenly divided bit numbers as the association relationship between the preset type bit and the distributed processing systems.
[0025] In one embodiment, the generation manner of the association relationship between the preset type bit and the distributed processing system comprises:
[0026] obtain the historical traffic of each distributed processing system and the bit number of the preset type bit;
[0027] calculate the proportion of the historical traffic of each distributed processing system;
[0028] divide the bit number of the preset type bit according to the calculated ratio;
[0029] establish the association between the divided bit number and the distributed processing system as the association between the preset type bit and the distributed processing system.
[0030] In one embodiment, the association between the preset type bit and the distributed processing system is generated in the following manner:
[0031] acquire the preset type bit to the bit number and display;
[0032] receive a bit number allocation instruction for the preset type bit;
[0033] establish the association between the preset type bit and the distributed processing system according to the allocation instruction.
[0034] A distributed unique identification code generation device, the device comprising:
[0035] a first receiving module for receiving a processing request sent by a terminal and acquiring a current system time;
[0036] an incrementing module for acquiring a last generated distributed unique identification code and incrementing a preset type bit in the last generated distributed unique identification code;
[0037] a generating module for obtaining a current distributed unique identification code according to the incremented preset type bit and the current system time;
[0038] a system acquiring module for acquiring a distributed processing system corresponding to the incremented preset type bit, the association between the preset type bit and the distributed processing system being preset;
[0039] an allocation module for associating and allocating the processing request and the current distributed unique identification code to the acquired distributed processing system.
[0040] In one embodiment, the system acquiring module comprises:
[0041] a first reference value acquiring unit for acquiring a reference value corresponding to the preset type bit;
[0042] a first remainder calculating unit for calculating a remainder obtained by performing a remainder operation on the incremented preset type bit with respect to the reference value;
[0043] a first output unit for acquiring the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder.
[0044] A computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the steps of the method in any one of the above embodiments when executing the computer program.
[0045] A computer readable storage medium, which stores a computer program, the computer program implements the steps of the method in any one of the above embodiments when executed by a processor.
[0046] The distributed unique identification code generation method, device, computer device and medium described above do not rely on a third party such as a database, the association relationship between the preset type bit and the distributed processing system is pre-set, and after receiving a request, the corresponding distributed processing system is determined according to the preset type bit after increment, so that the distributed system shares a set of distributed unique identification codes, so that the same distributed unique identification code id is not generated at any time node to cause system data error, for example, the situation of finding error data according to the insurance policy number is avoided. BRIEF DESCRIPTION OF DRAWINGS
[0047] Figure 1 An application scenario diagram of the distributed unique identification code generation method in an embodiment;
[0048] Figure 2 A flowchart of the distributed unique identification code generation method in an embodiment;
[0049] Figure 3 A structure block diagram of the distributed unique identification code generation device in an embodiment;
[0050] Figure 4 An internal structure diagram of the computer device in an embodiment. DETAILED DESCRIPTION
[0051] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.
[0052] The distributed unique identification code generation method provided by the present application can be applied to, for example, Figure 1The application environment shown. Among them, the terminal 102 and the server 104 communicate through the network. The terminal 102 sends a processing request to the server, and the server obtains the current system time when receiving the processing request, then obtains the last generated distributed unique identification code, and increments the preset type bit in the last generated distributed unique identification code, and then obtains the current distributed unique identification code according to the incremented preset type bit and the current system time, and then the server 104 determines the corresponding distributed processing system according to the incremented preset type bit, and finally the server 104 associates and distributes the processing request and the current distributed unique identification code to the obtained distributed processing system, so that the same distributed unique identification code id will not be generated at any time node to make the system data error. Among them, the terminal 102 can be but not limited to various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices, and the server 104 can be realized by an independent server or a server cluster composed of multiple servers.
[0053] Before detailing the present application, first the principle of SnowFlake algorithm is explained:
[0054] The binary structure of the id produced by Snowflake is as follows, which includes a symbol bit 1, a millisecond level timestamp bit 41, a work machine bit 5, a sequence number bit 5 and a millisecond internal timestamp bit 12, a total of 64 bits, as follows:
[0055] 0-00000000 00000000 00000000 00000000 00000000 0-00000-00000-000000000000
[0056] Wherein, the first bit is a sign bit, and generally generated id is positive number, so the first bit is 0 by default. The next 41 bits are millisecond level time (41 bits can be used for 69 years, from 1970-01-01 08:00:00), then 5 bits datacenterId (maximum support 2^5 = 32, binary representation from 00000-11111, that is, 0-31 in decimal), and 5 bits workerId (maximum support 2^5 = 32, principle same as datacenterId), so datacenterId multiplied by workerId supports deployment of 1024 nodes at most, and the last 12 bits are the count within the millisecond (12 bits of count sequence number support 2^12 = 4096 id sequence numbers per millisecond per node). All bits add up to 64 bits, which is exactly a Long type (converted to a string length of 18). Single machine instance, through the timestamp to ensure that the first 41 bits are unique, distributed processing system multiple machine instances, by assigning different datacenterId and workerId to each machine instance to avoid the collision of the middle 10 bits. The last 12 bits are incremented from 0 per millisecond to produce id, and again: up to 4096 ids per millisecond, up to 4096000 per second. In theory, as long as the CPU computing power is sufficient, a single machine can produce more than 400 million ids per second.
[0057] In one embodiment, as shown in Figure 2 , a distributed unique identification code generation method is provided, which is applied to the server in Figure 1 for example, including the following steps:
[0058] S202: receiving the processing request sent by the terminal and obtaining the current system time.
[0059] Specifically, the request sent by the terminal can be any service request, but the request is processed through the distributed processing system, such as the policy number query request. The current system time refers to the time when the processing request sent by the terminal is received, which can be represented by 41 bits, so it can represent 2^41-1 millisecond level values, which is converted into years (2^41-1) / (1000*60*60*24*365) = 69 years.
[0060] S204: obtaining the last generated distributed unique identification code, and incrementing the preset type bit in the last generated distributed unique identification code.
[0061] S206: obtaining the current distributed unique identification code according to the incremented preset type bit and the current system time.
[0062] Specifically, the last generated distributed unique identification code is the distributed unique identification code calculated according to the last request, so the server generally defaults the symbol bit to 1, then adds the 41-bit millisecond level bit, then increments the preset type bit, and then generates a 12-bit unique sequence number for the request received in the current millisecond, so that up to 4096 ids can be generated per millisecond, up to 4096000 per second. Thus the current distributed unique identification code is obtained. The preset type bit can be the workerID in the worker machine bit and / or the datacenterID bit.
[0063] For example, if separate processing is performed, the workerID and the datacenterID each support 2^5 = 32 bits, i.e., up to 32 distributed processing systems can be supported, and if they are combined together, a total of 2^10 = 1024 bits can be supported, i.e., up to 1024 distributed processing systems can be supported. That is, the preset type bit can be any number of bits from 1 to 10.
[0064] S208: Obtain the distributed processing system corresponding to the incremented preset type bit, and the association between the preset type bit and the distributed processing system is pre-set.
[0065] Specifically, the association between the preset type bit and the distributed processing system is pre-set. For example, taking the workerID as an example, the workerID supports up to 2^5 = 32, so if two systems use the same library and have intersection, the workerID can be divided into two parts to generate different ids. Each system occupies 16, and if three systems can divide the 32-bit system into three parts, the same applies to the workerID. Assuming that there are toss and emcs systems, when generating the workerID, if it is the toss system, 0-15 is used, and if it is the emcs system, 16-31 is occupied.
[0066] In this way, the server can obtain the incremented preset type bit, then calculate to determine which bits are used, and finally determine the corresponding distributed processing system according to the number of bits used.
[0067] S210: Associate and allocate the processing request and the current distributed unique identification code to the obtained distributed processing system.
[0068] Specifically, after the corresponding distributed processing system is determined, the corresponding processing request and the current distributed unique identification code are associated and allocated to the corresponding distributed processing system, so that the corresponding distributed processing system processes and does not cause confusion.
[0069] The distributed unique identification code generation method does not rely on a third party such as a database, the association relationship between the preset type bit and the distributed processing system is pre-set, and after receiving a request, the corresponding distributed processing system is determined according to the incremented preset type bit, so that the distributed processing system shares a set of distributed unique identification codes, so that the same distributed unique identification code id is not generated at any time node to cause system data errors, such as avoiding the case that the same production distributed unique identification code id causes to find error data according to the insurance policy number.
[0070] In one of the embodiments, obtaining the distributed processing system corresponding to the incremented preset type bit includes: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the reference value of the incremented preset type bit; and obtaining the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder.
[0071] Specifically, when obtaining the distributed processing system corresponding to the incremented preset type bit, the server can obtain the corresponding reference value according to the preset type bit, for example, assuming that only workerID and datacenterID are used, the reference value is 2^5=32, and if workerID and datacenterID are used together, the reference value is 2^10=1024. The remainder is obtained by performing a modulo operation on the reference value of the incremented preset type bit, for example, assuming that there are 2 distributed processing systems, and 0-15 bits are allocated to the first distributed processing system and 16-31 bits are allocated to the second distributed processing system, then the remainder is obtained. If the remainder is 0-15, the first distributed processing system is obtained as the distributed processing system corresponding to the incremented preset type bit, and if the remainder is 16-31, the second distributed processing system is obtained as the distributed processing system corresponding to the incremented preset type bit.
[0072] In the above embodiments, the corresponding distributed processing system is calculated by taking the remainder, which is simple to calculate and occupies less resources, thereby ensuring the uniqueness of the distributed unique identification code while improving the processing efficiency.
[0073] In one of the embodiments, the processing request carries a system identifier; the distributed processing system corresponding to the incremented preset type bit is obtained, including: obtaining a reference value corresponding to the preset type bit; calculating the remainder obtained by performing a modulo operation on the reference value corresponding to the incremented preset type bit; determining whether the remainder corresponds to the distributed processing system corresponding to the system identifier; when the remainder corresponds to the distributed processing system corresponding to the system identifier, taking the distributed processing system corresponding to the system identifier as the distributed processing system corresponding to the incremented preset type bit; and when the remainder does not correspond to the distributed processing system corresponding to the system identifier, obtaining the last generated distributed unique identifier, incrementing the preset type bit in the last generated distributed unique identifier, and repeating the above operations until the remainder corresponds to the distributed processing system corresponding to the system identifier.
[0074] Specifically, the above embodiment is for the case where the distributed processing systems are all the same. In this embodiment, the distributed processing systems are different, for example, some distributed processing systems process first-type requests, and some distributed processing systems process second-type requests. The processing request sent by the terminal received at this time carries a system identifier. Then, the server performs a modulo operation on the reference value corresponding to the incremented preset type bit to obtain a remainder, and determines whether the distributed processing system corresponding to the remainder matches the distributed processing system corresponding to the system identifier. If yes, the distributed processing system corresponding to the system identifier is directly taken as the distributed processing system corresponding to the incremented preset type bit. Otherwise, the above operations are repeated until the distributed processing system corresponding to the remainder matches the distributed processing system corresponding to the system identifier, and the distributed processing system corresponding to the system identifier is directly taken as the distributed processing system corresponding to the incremented preset type bit.
[0075] In the above embodiments, the corresponding distributed processing system is calculated by taking the remainder, which is simple and occupies less resources, thereby ensuring the uniqueness of the distributed unique identifier and improving the processing efficiency. Moreover, the differences between the systems are fully considered, so that the distribution of the preset type bit is more accurate.
[0076] Specifically, the distribution of the association between the preset type bit and the distributed processing system can be in several ways: one is direct equal distribution, the second is distribution according to historical traffic, and the third is receiving manual distribution instructions for distribution.
[0077] In one embodiment, the preset type bit and the distributed processing system are directly and equally divided to establish the association relationship. Specifically, the generation method of the association relationship between the preset type bit and the distributed processing system comprises the following steps: obtaining the number of the distributed processing systems and the bit number of the preset type bit; dividing the bit number of the preset type bit according to the number of the distributed processing systems; and establishing the association relationship between the distributed processing systems and the divided bit number as the association relationship between the preset type bit and the distributed processing system.
[0078] Specifically, in this embodiment, all the distributed systems can be indifferently processed the request sent by the terminal, so the preset type bit can be equally divided. For example, there are n bits of the preset type bit and m distributed processing systems. Then the preset type bit can be divided by n / m. Optionally, if it is not an integer multiple, for example, there is a remainder a, then the bit number corresponding to a distributed processing system is n / m+1, and the bit number corresponding to the remaining m-a distributed processing systems is n / m.
[0079] In one embodiment, the preset type bit and the distributed processing system are divided according to the historical traffic to establish the association relationship. Specifically, the generation method of the association relationship between the preset type bit and the distributed processing system comprises the following steps: obtaining the historical traffic of each distributed processing system and the bit number of the preset type bit; calculating the proportion of the historical traffic of each distributed processing system; dividing the bit number of the preset type bit according to the calculated proportion; and establishing the association relationship between the divided bit number and the distributed processing system as the association relationship between the preset type bit and the distributed processing system.
[0080] Specifically, in this embodiment, all the distributed systems can be differentially processed the request sent by the terminal, so the historical traffic of each distributed processing system can be fully considered, and the preset type bit is divided according to the historical traffic of each distributed processing system. For example, there are n bits of the preset type bit and m distributed processing systems, and the proportion is b1:b2:…:bm. Then the preset type bit can be divided by n / m*bi, where i takes a value from 1 to m.
[0081] In one embodiment, the association relationship between the preset type bit and the distributed processing system is established by receiving a manual allocation instruction. Specifically, the generation method of the association relationship between the preset type bit and the distributed processing system comprises the following steps: obtaining the bit number of the preset type bit and displaying; receiving a bit number allocation instruction for the preset type bit; and establishing the association relationship between the preset type bit and the distributed processing system according to the allocation instruction.
[0082] Specifically, in this embodiment, the user can assign the preset type bits as needed, so that the convenience in use is fully considered, and the user can directly specify the association between each bit and the distributed processing system, for example, the association between 3-6 bits and the first distributed system can be randomly specified.
[0083] Compared with the prior art, the above embodiment has at least the following advantages: the trend is increasing: the millisecond number is in the high bit, and the serial number is in the low bit. The performance is high and there is no single point: the local calculation does not depend on the database and other third parties. The use is flexible: the bit number of the three components can be adjusted as needed, especially after the modification, the id rule is used flexibly, and the solution to the id generation repeatability has been realized, which greatly improves the coding efficiency and stability of the system, solves the problem of repeatability of multiple systems using the same set of id generation rules, so that the same id is not generated at any time node to cause system data errors, such as avoiding the situation of finding error data according to the insurance policy number due to the same production id, which also improves the experience of the end user to some extent.
[0084] It should be understood that, although Figure 2 The steps in the flowchart are shown in sequence according to the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, Figure 2 At least part of the steps in At least part of the steps in
[0085] In one embodiment, as shown in Figure 3 A distributed unique identification code generation device is provided, comprising: a first receiving module 100, an incrementing module 200, a generating module 300, a system obtaining module 400, and an assigning module 500, wherein:
[0086] The first receiving module 100 is configured to receive a processing request sent by a terminal and obtain a current system time;
[0087] The incrementing module 200 is configured to obtain a last generated distributed unique identification code and increment a preset type bit in the last generated distributed unique identification code;
[0088] The generating module 300 is configured to obtain a current distributed unique identification code according to the incremented preset type bit and the current system time;
[0089] The system obtaining module 400 is configured to obtain a distributed processing system corresponding to the preset type bit after increment, and an association relationship between the preset type bit and the distributed processing system is preconfigured.
[0090] The distribution module 500 is configured to distribute the processing request and the current distributed unique identification code to the obtained distributed processing system.
[0091] In one embodiment, the system obtaining module 400 comprises:
[0092] The first reference value obtaining unit is configured to obtain a reference value corresponding to the preset type bit;
[0093] The first remainder calculating unit is configured to calculate a remainder obtained by performing a remainder operation on the reference value by the preset type bit after increment;
[0094] The first output unit is configured to obtain the distributed processing system corresponding to the preset type bit after increment according to the obtained remainder.
[0095] In one embodiment, the processing request carries a system identifier; and the system obtaining module 400 can comprise:
[0096] The second reference value obtaining unit is configured to obtain a reference value corresponding to the preset type bit;
[0097] The second remainder calculating unit is configured to calculate a remainder obtained by performing a remainder operation on the reference value by the preset type bit after increment;
[0098] The judging unit is configured to judge whether the remainder corresponds to the distributed processing system corresponding to the system identifier;
[0099] The second output unit is configured to, when the remainder corresponds to the distributed processing system corresponding to the system identifier, take the distributed processing system corresponding to the system identifier as the distributed processing system corresponding to the preset type bit after increment;
[0100] When the remainder does not correspond to the distributed processing system corresponding to the system identifier, the last generated distributed unique identification code is obtained, the preset type bit in the last generated distributed unique identification code is incremented, and the process is repeated until the remainder corresponds to the distributed processing system corresponding to the system identifier.
[0101] In one embodiment, the distributed unique identification code generation device can further comprise:
[0102] The first bit number obtaining module is configured to obtain the number of distributed processing systems and the bit number of the preset type bit;
[0103] The first division module is configured to divide the bit number of the preset type bit according to the number of distributed processing systems;
[0104] The first correlation relationship determining module is configured to establish the correlation relationship between the distributed processing system and each bit number after the division as the correlation relationship between the preset type bit and the distributed processing system.
[0105] In one of the embodiments, the distributed unique identification code generation apparatus can further include:
[0106] The second bit number obtaining module is configured to obtain the historical traffic of each distributed processing system and the bit number of the preset type bit.
[0107] The proportion calculating module is configured to calculate the proportion of the historical traffic of each distributed processing system.
[0108] The second dividing module is configured to divide the bit number of the preset type bit according to the calculated proportion.
[0109] The second correlation relationship determining module is configured to establish the correlation relationship between the divided bit number and the distributed processing system as the correlation relationship between the preset type bit and the distributed processing system.
[0110] In one of the embodiments, the distributed unique identification code generation apparatus can further include:
[0111] The third bit number obtaining module is configured to obtain the bit number of the preset type bit and display the bit number.
[0112] The second receiving module is configured to receive a bit number allocation instruction for the preset type bit.
[0113] The third dividing module is configured to establish the correlation relationship between the preset type bit and the distributed processing system according to the allocation instruction.
[0114] The specific limitation of the distributed unique identification code generation apparatus can refer to the limitation of the distributed unique identification code generation method in the foregoing, and will not be repeated here. Each module in the distributed unique identification code generation apparatus can be realized by software, hardware and a combination thereof in whole or in part. Each module can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so as to be called and executed by the processor to perform the operation corresponding to each module.
[0115] In one of the embodiments, a computer device is provided, which can be a server, and the internal structure diagram of the computer device can be as shown in Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium, an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store the distributed unique identification code data generated each time. The network interface of the computer device is used to communicate with the external terminal through the network connection. The computer program is executed by the processor to implement a distributed unique identification code generation method.
[0116] Those skilled in the art can understand that, Figure 4 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.
[0117] In one embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the following steps: receiving a processing request sent by a terminal and obtaining a current system time; obtaining a last generated distributed unique identification code, incrementing a preset type bit in the last generated distributed unique identification code; obtaining a current distributed unique identification code according to the incremented preset type bit and the current system time; obtaining a distributed processing system corresponding to the incremented preset type bit, the association relationship between the preset type bit and the distributed processing system being pre-set; and associating and distributing the processing request and the current distributed unique identification code to the obtained distributed processing system.
[0118] In one embodiment, the processor executing the computer program to implement the step of obtaining the distributed processing system corresponding to the incremented preset type bit includes: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the incremented preset type bit with respect to the reference value; and obtaining the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder.
[0119] In one embodiment, the processing request carried by the system identification is implemented when the processor executes the computer program; the distributed processing system corresponding to the incremented preset type bit is obtained by: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the reference value after the incremented preset type bit; determining whether the remainder corresponds to the distributed processing system corresponding to the system identification; when the remainder corresponds to the distributed processing system corresponding to the system identification, taking the distributed processing system corresponding to the system identification as the distributed processing system corresponding to the incremented preset type bit; and when the remainder does not correspond to the distributed processing system corresponding to the system identification, obtaining a last generated distributed unique identification code, incrementing the preset type bit in the last generated distributed unique identification code, and repeating the above operations until the remainder corresponds to the distributed processing system corresponding to the system identification.
[0120] In one embodiment, the generation mode of the association relationship between the preset type bit and the distributed processing system involved when the processor executes the computer program includes: obtaining the number of distributed processing systems and the bit number of the preset type bit; dividing the bit number of the preset type bit according to the number of distributed processing systems; and establishing an association relationship between the distributed processing systems and each divided bit number as the association relationship between the preset type bit and the distributed processing system.
[0121] In one embodiment, the generation mode of the association relationship between the preset type bit and the distributed processing system involved when the processor executes the computer program includes: obtaining the historical traffic of each distributed processing system and the bit number of the preset type bit; calculating the proportion of the historical traffic of each distributed processing system; dividing the bit number of the preset type bit according to the calculated proportion; and establishing an association relationship between the divided bit number and the distributed processing system as the association relationship between the preset type bit and the distributed processing system.
[0122] In one embodiment, the generation mode of the association relationship between the preset type bit and the distributed processing system involved when the processor executes the computer program includes: obtaining the bit number of the preset type bit and displaying; receiving a bit number allocation instruction for the preset type bit; and establishing an association relationship between the preset type bit and the distributed processing system according to the allocation instruction.
[0123] In one embodiment, a computer readable storage medium is provided, and a computer program is stored on the computer readable storage medium, and the computer program is executed by a processor to implement the following steps: receiving a processing request sent by a terminal, and obtaining a current system time; obtaining a last generated distributed unique identifier, and incrementing a preset type bit in the last generated distributed unique identifier; obtaining a current distributed unique identifier according to the incremented preset type bit and the current system time; obtaining a distributed processing system corresponding to the incremented preset type bit, and an association relationship between the preset type bit and the distributed processing system is pre-set; and associating and distributing the processing request and the current distributed unique identifier to the obtained distributed processing system.
[0124] In one embodiment, the computer program is executed by the processor to implement the obtaining of the distributed processing system corresponding to the incremented preset type bit, including: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the incremented preset type bit with respect to the reference value; and obtaining the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder.
[0125] In one embodiment, the processing request carries a system identifier, and the computer program is executed by the processor to implement the obtaining of the distributed processing system corresponding to the incremented preset type bit, including: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the incremented preset type bit with respect to the reference value; judging whether the remainder corresponds to the distributed processing system corresponding to the system identifier; when the remainder corresponds to the distributed processing system corresponding to the system identifier, taking the distributed processing system corresponding to the system identifier as the distributed processing system corresponding to the incremented preset type bit; and when the remainder does not correspond to the distributed processing system corresponding to the system identifier, obtaining the last generated distributed unique identifier, incrementing the preset type bit in the last generated distributed unique identifier, and repeating the above steps until the remainder corresponds to the distributed processing system corresponding to the system identifier.
[0126] In one embodiment, the computer program is executed by the processor to implement the generation of the association relationship between the preset type bit and the distributed processing system, including: obtaining a number of the distributed processing systems and a bit number of the preset type bit; dividing the bit number of the preset type bit according to the number of the distributed processing systems; and establishing an association relationship between the distributed processing systems and each bit number after the division as the association relationship between the preset type bit and the distributed processing system.
[0127] In one embodiment, the generation of the association relationship between the preset type bit and the distributed processing system when the computer program is executed by the processor includes: obtaining historical traffic of each distributed processing system and bit number of the preset type bit; calculating a proportion of the historical traffic of each distributed processing system; dividing the bit number of the preset type bit according to the calculated proportion; and establishing an association relationship between the divided bit number and the distributed processing system as the association relationship between the preset type bit and the distributed processing system.
[0128] In one embodiment, the generation of the association relationship between the preset type bit and the distributed processing system when the computer program is executed by the processor includes: obtaining historical traffic of each distributed processing system and bit number of the preset type bit; calculating a proportion of the historical traffic of each distributed processing system; dividing the bit number of the preset type bit according to the calculated proportion; and establishing an association relationship between the divided bit number and the distributed processing system as the association relationship between the preset type bit and the distributed processing system.
[0129] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by a computer program instructing related hardware, and the computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, the computer program can include the processes of the above-mentioned embodiments. Any reference to a memory, storage, database or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM) and memory bus dynamic RAM (RDRAM).
[0130] Each technical feature of the above embodiments can be combined arbitrarily. In order to make the description simple, not all possible combinations of the technical features in the above embodiments are described, however, as long as the combinations of the technical features do not exist, they should be considered as the scope of the present disclosure.
[0131] The above-described embodiments are merely illustrative of several embodiments of the present application, which are described in more detail and in a specific and detailed manner, but should not be construed as limiting the scope of the patent. It should be noted that for those skilled in the art, several modifications and improvements can be made without departing from the concept of the present application, and these are all within the scope of the present application. Therefore, the scope of protection of the patent of the present application should be subject to the appended claims.
Claims
1. A distributed unique identification code generation method, the method comprising: receiving a processing request sent by a terminal and obtaining a current system time; obtaining a last generated distributed unique identification code, and incrementing a preset type bit in the last generated distributed unique identification code; the distributed unique identification code comprises a symbol bit 1 bit, a millisecond timestamp bit 41 bit, a working machine bit 5 bit, a serial number bit 5 bit, and a time stamp within a millisecond bit 12 bit, a total of 64 bits, and the preset type bit is the working machine bit and / or the serial number bit; obtaining a current distributed unique identification code according to the incremented preset type bit and the current system time, comprising: determining the symbol bit, then generating the millisecond timestamp bit based on the current time, determining the incremented preset type bit, generating a unique serial number for the request received in the current millisecond, and finally obtaining the current distributed unique identification code; obtaining a distributed processing system corresponding to the incremented preset type bit, the association between the preset type bit and the distributed processing system being pre-set; associating and distributing the processing request and the current distributed unique identification code to the obtained distributed processing system.
2. The method of claim 1, wherein, The obtaining of the distributed processing system corresponding to the incremented preset type bit comprises: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the incremented preset type bit with respect to the reference value; obtaining the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder.
3. The method of claim 1, wherein, The processing request carries a system identifier; the obtaining of the distributed processing system corresponding to the incremented preset type bit comprises: obtaining a reference value corresponding to the preset type bit; calculating a remainder obtained by performing a modulo operation on the incremented preset type bit with respect to the reference value; determining whether the remainder corresponds to the distributed processing system corresponding to the system identifier; when the remainder corresponds to the distributed processing system corresponding to the system identifier, taking the distributed processing system corresponding to the system identifier as the distributed processing system corresponding to the incremented preset type bit; when the remainder does not correspond to the distributed processing system corresponding to the system identifier, obtaining a last generated distributed unique identification code, incrementing a preset type bit in the last generated distributed unique identification code, until the remainder corresponds to the distributed processing system corresponding to the system identifier.
4. The method according to any one of claims 1 to 3, characterized in that, The generation mode of the association between the preset type bit and the distributed processing system comprises: obtaining the number of distributed processing systems and the bit number of the preset type bit; equally dividing the bit number of the preset type bit according to the number of the distributed processing systems; establishing the association between the distributed processing systems and the divided bit numbers as the association between the preset type bit and the distributed processing systems.
5. The method according to any one of claims 1 to 3, characterized in that, The generation mode of the association between the preset type bit and the distributed processing system comprises: obtaining the historical traffic of each distributed processing system and the bit number of the preset type bit; calculating the proportion of the historical traffic of each distributed processing system; dividing the bit number of the preset type bit according to the calculated proportion; Establish the association between the divided bit number and the distributed processing system as the association between the preset type bit and the distributed processing system.
6. The method according to any one of claims 1 to 3, characterized in that, The generation mode of the association between the preset type bit and the distributed processing system comprises: Obtaining the preset type bit to the bit number and displaying; Receiving the bit number allocation instruction for the preset type bit; Establishing the association between the preset type bit and the distributed processing system according to the allocation instruction.
7. A distributed unique identifier generation device, characterized in that, The device comprises: The first receiving module is configured to receive a processing request sent by a terminal and obtain a current system time; The incrementing module is configured to obtain a last generated distributed unique identification code, and increment a preset type bit in the last generated distributed unique identification code; the distributed unique identification code comprises a symbol bit of 1 bit, a millisecond level timestamp bit of 41 bits, a working machine bit of 5 bits, a serial number bit of 5 bits, and a millisecond internal timestamp bit of 12 bits, a total of 64 bits, and the preset type bit is the working machine bit and / or the serial number bit; The generating module is configured to obtain a current distributed unique identification code according to the incremented preset type bit and the current system time, comprising: determining a symbol bit, then generating a millisecond level timestamp bit based on the current time, determining the incremented preset type bit, generating a unique serial number for the request received in the current millisecond, and finally obtaining the current distributed unique identification code; The system obtaining module is configured to obtain a distributed processing system corresponding to the incremented preset type bit, and an association between the preset type bit and the distributed processing system is preset; The allocation module is configured to associate and allocate the processing request and the current distributed unique identification code to the obtained distributed processing system.
8. The apparatus of claim 7, wherein, The system obtaining module comprises: The first reference value obtaining unit is configured to obtain a reference value corresponding to the preset type bit; The first remainder calculating unit is configured to calculate a remainder obtained by performing a remainder operation on the incremented preset type bit with respect to the reference value; The first output unit is configured to obtain the distributed processing system corresponding to the incremented preset type bit according to the obtained remainder. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the method of any one of claims 1 to 6.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Method, device and system for generating unique keys in distributed system
CN103823810A
Distributed global ID generation method, device and equipment, and storage medium
CN108959386A