CN111611247A - ID generator and ID generating method for multi-domain computer room - Google Patents

ID generator and ID generating method for multi-domain computer room Download PDF

Info

Publication number
CN111611247A
CN111611247A CN202010449818.7A CN202010449818A CN111611247A CN 111611247 A CN111611247 A CN 111611247A CN 202010449818 A CN202010449818 A CN 202010449818A CN 111611247 A CN111611247 A CN 111611247A
Authority
CN
China
Prior art keywords
timestamp
generator
generated
bits
serial number
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010449818.7A
Other languages
Chinese (zh)
Inventor
黎文志
赵印
潘琪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Health Medical Big Data Co ltd
Original Assignee
Shandong Health Medical Big Data Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong Health Medical Big Data Co ltd filed Critical Shandong Health Medical Big Data Co ltd
Priority to CN202010449818.7A priority Critical patent/CN111611247A/en
Publication of CN111611247A publication Critical patent/CN111611247A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures

Abstract

The invention discloses an ID generator and an ID generating method of a multi-domain computer room, and relates to the technical field of ID generators, wherein the generator faces to the business of a distributed system, the generated ID has uniqueness in the whole situation, and the generated ID is increased progressively in the trend; the ID generated by the generator comprises a positive bit, a negative bit, a timestamp, a working machine ID and a serial number, wherein the working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time; the generator self-defines the uniqueness workid according to time, and guarantees the uniqueness of the self-increment ID in a very short time. The invention realizes the generation of the distributed ID generator with global uniqueness, increasing trend, high availability and high performance, and meets the requirement of high-speed generation of unrepeated IDs in high-concurrency service scenes.

Description

ID generator and ID generating method for multi-domain computer room
Technical Field
The invention relates to the technical field of ID generators, in particular to an ID generator and an ID generating method of a multi-domain computer room.
Background
With the continuous acceleration of social modernization and intellectualization, the number of users and services of various APPs is also rapidly increasing. When the service data volume is not large, the single database list table can completely support the existing service, and the data is larger, so that the master-slave synchronous read-write separation of the database can be used for dealing with the problem. However, as data grows day by day, master-slave synchronization cannot be carried out, the database needs to be subjected to database division and table division, a unique ID is needed to identify one piece of data after the database division and table division, and the self-increment ID of the database obviously cannot meet the requirement; in particular, transaction orders, coupons, etc. also need to have unique IDs for identification. A system capable of generating a globally unique ID is then necessary.
Disclosure of Invention
The technical task of the invention is to provide the ID generator and the ID generation method of the multi-domain computer room aiming at the defects, so that the generation of the distributed ID generator with global uniqueness, increasing trend, high availability and high performance is realized, and the requirement of high-speed generation and unrepeated ID under the high-concurrency service scene is met.
The technical scheme adopted by the invention for solving the technical problems is as follows:
an ID generator of a multi-domain computer room faces to the business of a distributed system, the generated ID has uniqueness in the whole situation, and the generated ID is increased in trend;
the ID generated by the generator contains positive and negative bits, a timestamp, a work machine ID and a serial number,
the working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time;
the generator self-defines the uniqueness workid according to time, and guarantees the uniqueness of the self-increment ID in a very short time.
The ID generated by the generator can not generate great reading and writing pressure on the database, can generate the ID with certain business meaning and increasing trend, and can ensure that the unrepeated ID is generated efficiently and quickly.
Preferably, the generated ID has a size of 64 bits, wherein the positive and negative bits are 1bit, the time stamp is 41bit, the work machine ID is 10bit, and the serial number is 12 bit.
Further, the positive and negative bits are fixed to 0. The most significant bit of 1 in the binary is all negative, but the ID generated by the generator is generally positive, so this most significant bit is fixed to 0.
Preferably, the time stamp is recorded as millisecond time, so that the efficiency of generating the ID is improved.
Preferably, the upper 5 bits of the working machine ID represent a data center ID, and the lower 5 bits represent a working node ID. The length of the working machine ID10bit can support deployment of 1024 nodes at most, and the generator generates the ID mainly by means of the data center ID and the working node ID.
Specifically, the process of ensuring the uniqueness of the ID by customization is as follows:
after initiating a request for generating an ID, the system automatically acquires a current timestamp and compares the current timestamp with a last timestamp;
if the acquired current timestamp is smaller than the last timestamp, the algorithm prompts that the acquired timestamp is abnormal; if the two are equal, adding one to the serial number; if the current timestamp is larger than the last timestamp, subtracting the current timestamp from the last timestamp, and setting the serial number to be 0;
then, carrying out bit operation, leftwards shifting the timestamp by corresponding bit numbers, leftwards shifting the data ID by corresponding bit numbers, and leftwards shifting the work ID by corresponding bit numbers; and splicing the calculated parts in sequence and outputting to obtain a new ID.
The invention also claims an ID generation method of the multi-domain computer room, which is oriented to the service of the distributed system, the generated ID has uniqueness in the whole situation, and the generated ID is increased progressively in the trend;
the generated ID includes a positive and negative bit, a timestamp, a work machine ID and a serial number,
the working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time;
the method self-defines the uniqueness according to time, and guarantees the uniqueness of the self-increment ID in a very short time.
Preferably, the generated ID has a size of 64 bits, plus and minus 1bit, a time stamp of 41 bits, a work machine ID of 10 bits, and a serial number of 12 bits.
The highest bit of the binary is 1 and is negative, but the ID generated by the generator is generally positive, so the highest bit is fixed to be 0. The timestamp is recorded as millisecond time, and the ID generation efficiency is improved. The length of the working machine ID10bit can support deployment of 1024 nodes at most, wherein the upper 5 bits of the working machine ID represent the ID of the data center, and the lower 5 bits represent the ID of the working node. The generator implementation generates the ID primarily by data center ID and worker node ID.
Specifically, in the method, the process of ensuring the uniqueness of the ID through self-definition is as follows:
after initiating a request for generating an ID, the system automatically acquires a current timestamp and compares the current timestamp with a last timestamp;
if the acquired current timestamp is smaller than the last timestamp, the algorithm prompts that the acquired timestamp is abnormal; if the two are equal, adding one to the serial number; if the current timestamp is larger than the last timestamp, subtracting the current timestamp from the last timestamp, and setting the serial number to be 0;
then, carrying out bit operation, leftwards shifting the timestamp by corresponding bit numbers, leftwards shifting the data ID by corresponding bit numbers, and leftwards shifting the work ID by corresponding bit numbers; and splicing the calculated parts in sequence and outputting to obtain a new ID.
The invention also claims a computer readable medium having stored thereon computer instructions which, when executed by a processor, cause the processor to perform the above-described method.
Compared with the prior art, the ID generator and the ID generating method of the multi-domain computer room have the following beneficial effects:
the ID generated by the method and the generator has the effect of increasing the trend, the rule can not be easily found by people as continuous increasing, and the requirement on time sequencing in service can be met;
the ID of the working machine is distinguished by the ID of the data center and the ID of the working node, so that the collision of the IDs cannot occur in the whole distributed system;
the ID generation efficiency is high, and the requirement of high-speed generation of non-repetitive IDs under a high-concurrency service scene is met.
Detailed Description
The present invention will be further described with reference to the following specific examples.
In a complex distributed system, a large amount of data and messages are often required to be uniquely identified, as data in a business system gradually increases, a unique ID is required to identify one piece of data or message after data is divided into databases and tables, and the self-increment ID of the database cannot meet requirements, particularly transaction orders and personal health records are also required to be uniquely identified by the unique ID.
The first reaction to mention unique identification is UUID, but UUID is not suitable for actual service requirement. A string such as UUID has no meaning whatsoever if used as an order number, and no useful information relating to the order can be seen, whereas for a database UUID is used as the service primary key ID, which is not only too long but also a string, and a query with poor storage performance is time-consuming, and therefore not recommended for use as a distributed ID.
The embodiment of the invention provides an ID generator of a multi-domain computer room, which is oriented to the service of a distributed system, wherein the generated ID has uniqueness in the whole situation, and the generated ID is increased progressively in the trend;
the ID generated by the generator contains positive and negative bits, a timestamp, a work machine ID and a serial number,
the working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time;
the generator self-defines the uniqueness workid according to time, and guarantees the uniqueness of the self-increment ID in a very short time.
The ID generated by the generator can not generate great reading and writing pressure on the database, can generate the ID with certain business meaning and increasing trend, and can ensure that the unrepeated ID is generated efficiently and quickly.
The generated ID size is 64 bits, wherein the positive and negative bits are 1bit, the timestamp is 41bit, the working machine ID is 10bit and the serial number is 12 bit.
The positive and negative fixes are 0. The highest bit in the binary is 1 and is all negative, but the ID generated by the generator is generally a positive integer, so the highest bit is fixed to be 0.
The timestamp is recorded as millisecond time, and the 41 bits can represent 241-1 positive integers, that is, (241-1)/(1000 × 60 × 24 × 365) can represent 69 years, and theoretically, the algorithm can be used for 69 years without repeating in the case of no server time callback.
The length of the working machine ID10bit can support deployment of 1024 nodes at most, wherein the upper 5 bits of the working machine ID represent the ID of the data center, and the lower 5 bits represent the ID of the working node. The generator implementation generates the ID primarily by data center ID and worker node ID.
The serial numbers are used for recording different IDs generated in the same machine within the same millisecond, each node starts to accumulate continuously every 0 millisecond, can accumulate to 4095 at most, and can generate 4095 IDs in total. A 12bit serial number, combined with a 10bit work machine ID, can produce 4194304 non-repeating IDs within 1 ms.
The specific implementation process for ensuring the uniqueness of the ID through self-definition is as follows:
after initiating a request for generating an ID, the system automatically acquires a current timestamp and compares the current timestamp with a last timestamp;
if the acquired current timestamp is smaller than the last timestamp, the algorithm prompts that the acquired timestamp is abnormal; if the two are equal, adding one to the serial number; if the current timestamp is larger than the last timestamp, subtracting the current timestamp from the last timestamp, and setting the serial number to be 0;
then, carrying out bit operation, leftwards shifting the timestamp by corresponding bit numbers, leftwards shifting the data ID by corresponding bit numbers, and leftwards shifting the work ID by corresponding bit numbers; and splicing the calculated parts in sequence and outputting to obtain a new ID.
The ID generated by the generator has the effect of increasing the trend, can not be easily found by people as the rule of continuous increasing, and can meet the requirement on time sequencing on business; no ID collision (distinguished by data center ID and working node ID) occurs in the whole distributed system; more than 400 tens of thousands of different IDs can be generated every millisecond, and the efficiency of generating the IDs is extremely high.
The embodiment of the invention also provides an ID generation method of the multi-domain computer room, which is oriented to the service of the distributed system, the generated ID has uniqueness in the whole situation, and the generated ID is increased progressively in the trend;
the generated ID comprises a positive bit, a negative bit, a timestamp, a working machine ID and a serial number, wherein the ID size is 64 bits, and the positive bit and the negative bit are 1bit, the timestamp is 41bit, the working machine ID is 10bit and the serial number is 12 bit.
The working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time;
the method self-defines the uniqueness according to time, and guarantees the uniqueness of the self-increment ID in a very short time.
The timestamp is recorded as millisecond time, and the timestamp 41bit may represent 241-1 positive integers, that is, (241-1)/(1000 × 60 × 24 × 365) may represent 69 years, and theoretically, in the case that the server time callback does not occur, the algorithm may be used for 69 years without repetition.
The length of the working machine ID10bit can support deployment of 1024 nodes at most, wherein the upper 5 bits of the working machine ID represent the ID of the data center, and the lower 5 bits represent the ID of the working node. The generator implementation generates the ID primarily by data center ID and worker node ID.
The serial numbers are used for recording different IDs generated in the same machine within the same millisecond, each node starts to accumulate continuously every 0 millisecond, can accumulate to 4095 at most, and can generate 4095 IDs in total. A 12bit serial number, combined with a 10bit work machine ID, can produce 4194304 non-repeating IDs within 1 ms.
In the method, the realization process of ensuring the uniqueness of the ID through self-definition is as follows:
after initiating a request for generating an ID, the system automatically acquires a current timestamp and compares the current timestamp with a last timestamp;
if the acquired current timestamp is smaller than the last timestamp, the algorithm prompts that the acquired timestamp is abnormal; if the two are equal, adding one to the serial number; if the current timestamp is larger than the last timestamp, subtracting the current timestamp from the last timestamp, and setting the serial number to be 0;
then, carrying out bit operation, leftwards shifting the timestamp by corresponding bit numbers, leftwards shifting the data ID by corresponding bit numbers, and leftwards shifting the work ID by corresponding bit numbers; and splicing the calculated parts in sequence and outputting to obtain a new ID.
An embodiment of the present invention further provides a computer-readable medium, where a computer instruction is stored on the computer-readable medium, and when the computer instruction is executed by a processor, the processor is caused to execute the ID generation method of the multi-domain computer room in the embodiment of the present invention. Specifically, a system or an apparatus equipped with a storage medium on which software program codes that realize the functions of any of the above-described embodiments are stored may be provided, and a computer (or a CPU or MPU) of the system or the apparatus is caused to read out and execute the program codes stored in the storage medium.
In this case, the program code itself read from the storage medium can realize the functions of any of the above-described embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
Examples of the storage medium for supplying the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (e.g., CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD + RW), a magnetic tape, a nonvolatile memory card, and a ROM. Alternatively, the program code may be downloaded from a server computer via a communications network.
Further, it should be clear that the functions of any one of the above-described embodiments may be implemented not only by executing the program code read out by the computer, but also by causing an operating system or the like operating on the computer to perform a part or all of the actual operations based on instructions of the program code.
Further, it is to be understood that the program code read out from the storage medium is written to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion unit connected to the computer, and then causes a CPU or the like mounted on the expansion board or the expansion unit to perform part or all of the actual operations based on instructions of the program code, thereby realizing the functions of any of the above-described embodiments.
While the invention has been shown and described in detail with reference to preferred embodiments thereof, it will be understood by those skilled in the art that the present invention is not limited to the embodiments disclosed, and that various combinations of the code auditing means in the different embodiments described above may be used to obtain further embodiments of the invention, which are also within the scope of the invention.

Claims (10)

1. An ID generator of a multi-domain computer room is characterized in that the generator is oriented to the services of a distributed system, the generated ID has uniqueness in the whole world, and the generated ID is increased in trend;
the ID generated by the generator contains positive and negative bits, a timestamp, a work machine ID and a serial number,
the working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time;
the generator self-defines the uniqueness workid according to time, and guarantees the uniqueness of the self-increment ID in a very short time.
2. The ID generator of the multi-domain computer room of claim 1, wherein the generated ID has a size of 64 bits, a plus-minus 1bit, a timestamp of 41 bits, a working machine ID of 10 bits, and a serial number of 12 bits.
3. An ID generator for a multi-domain computer room as claimed in claim 2, wherein the positive and negative bits are fixed to 0.
4. The ID generator for multi-domain computer room of claim 2, wherein the time stamp is recorded as millisecond time.
5. The ID generator of the multi-domain computer room of claim 2, wherein the upper 5 bits of the working machine ID represent a data center ID and the lower 5 bits represent a working node ID.
6. The ID generator of the multi-domain computer room of any one of claims 1 to 5, wherein the process of ensuring the ID uniqueness by self-definition is as follows:
after initiating a request for generating an ID, the system automatically acquires a current timestamp and compares the current timestamp with a last timestamp;
if the acquired current timestamp is smaller than the last timestamp, the algorithm prompts that the acquired timestamp is abnormal; if the two are equal, adding one to the serial number; if the current timestamp is larger than the last timestamp, subtracting the current timestamp from the last timestamp, and setting the serial number to be 0;
then, carrying out bit operation, leftwards shifting the timestamp by corresponding bit numbers, leftwards shifting the data ID by corresponding bit numbers, and leftwards shifting the work ID by corresponding bit numbers; and splicing the calculated parts in sequence and outputting to obtain a new ID.
7. The method is characterized in that the method faces to the service of a distributed system, the generated ID has uniqueness in the whole situation, and the generated ID is increased in trend;
the generated ID includes a positive and negative bit, a timestamp, a work machine ID and a serial number,
the working machine ID comprises a data center ID and a working node ID, and the serial number is used for recording different IDs generated by the same machine at the same time;
the method self-defines the uniqueness according to time, and guarantees the uniqueness of the self-increment ID in a very short time.
8. The ID generation method of the multi-domain computer room of claim 7, wherein the generated ID has a size of 64 bits, a plus-minus bit of 1bit, a timestamp of 41 bits, a working machine ID of 10 bits, and a serial number of 12 bits.
9. The ID generation method of the multi-domain computer room according to claim 7 or 8, wherein the process of ensuring the uniqueness of the ID by self-definition is as follows:
after initiating a request for generating an ID, the system automatically acquires a current timestamp and compares the current timestamp with a last timestamp;
if the acquired current timestamp is smaller than the last timestamp, the algorithm prompts that the acquired timestamp is abnormal; if the two are equal, adding one to the serial number; if the current timestamp is larger than the last timestamp, subtracting the current timestamp from the last timestamp, and setting the serial number to be 0;
then, carrying out bit operation, leftwards shifting the timestamp by corresponding bit numbers, leftwards shifting the data ID by corresponding bit numbers, and leftwards shifting the work ID by corresponding bit numbers; and splicing the calculated parts in sequence and outputting to obtain a new ID.
10. Computer readable medium, characterized in that it has stored thereon computer instructions which, when executed by a processor, cause the processor to carry out the method of any of claims 7 to 9.
CN202010449818.7A 2020-05-25 2020-05-25 ID generator and ID generating method for multi-domain computer room Pending CN111611247A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010449818.7A CN111611247A (en) 2020-05-25 2020-05-25 ID generator and ID generating method for multi-domain computer room

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010449818.7A CN111611247A (en) 2020-05-25 2020-05-25 ID generator and ID generating method for multi-domain computer room

Publications (1)

Publication Number Publication Date
CN111611247A true CN111611247A (en) 2020-09-01

Family

ID=72200763

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010449818.7A Pending CN111611247A (en) 2020-05-25 2020-05-25 ID generator and ID generating method for multi-domain computer room

Country Status (1)

Country Link
CN (1) CN111611247A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112650776A (en) * 2020-11-03 2021-04-13 重庆盈熙横纵信息技术有限公司 Redis-based distributed lock implementation method, storage device and server
CN113708983A (en) * 2021-11-01 2021-11-26 湖南新云网科技有限公司 Distributed node ID generation method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100023797A1 (en) * 2008-07-25 2010-01-28 Rajeev Atluri Sequencing technique to account for a clock error in a backup system
CN107454203A (en) * 2017-07-19 2017-12-08 成都数联铭品科技有限公司 The method for generating unique ID in a distributed system
CN107864233A (en) * 2017-11-08 2018-03-30 千寻位置网络有限公司 Globally unique ID structures and generation method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100023797A1 (en) * 2008-07-25 2010-01-28 Rajeev Atluri Sequencing technique to account for a clock error in a backup system
CN107454203A (en) * 2017-07-19 2017-12-08 成都数联铭品科技有限公司 The method for generating unique ID in a distributed system
CN107864233A (en) * 2017-11-08 2018-03-30 千寻位置网络有限公司 Globally unique ID structures and generation method

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112650776A (en) * 2020-11-03 2021-04-13 重庆盈熙横纵信息技术有限公司 Redis-based distributed lock implementation method, storage device and server
CN113708983A (en) * 2021-11-01 2021-11-26 湖南新云网科技有限公司 Distributed node ID generation method, device, equipment and storage medium
CN113708983B (en) * 2021-11-01 2022-02-11 湖南新云网科技有限公司 Distributed node ID generation method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111611247A (en) ID generator and ID generating method for multi-domain computer room
CN101504672B (en) Method and system for dynamically configuring physical data table
CN110334152B (en) Data synchronization method and device and server
CN110162526B (en) Method, device and equipment for inquiring data records in block chain type account book
CN105430118B (en) A kind of MAC Address generation method and device
CN108415846B (en) Method and device for generating minimum automatic test case set
CN110634052A (en) Method and device for generating order number by distributed architecture
JP2021518021A (en) Data processing methods, equipment and computer readable storage media
CN112241437A (en) Loop control method, device and equipment for multi-master synchronization of database and storage medium
CN104714957A (en) List structure changing method and device
CN109063070B (en) Database operation method and database server
CN114285554A (en) Key generation method and device based on equipment identification and computer readable medium
CN113377813B (en) Global unique identification code generation method, device, system and computer readable medium
CN114153893A (en) Redis-based distributed ID generation method, device and medium
CN111563123B (en) Real-time synchronization method for hive warehouse metadata
CN112925746A (en) File archiving method and device
CN112445800A (en) Method and system for generating data serial number and electronic equipment
CN115757412A (en) Unique key generation method for distributed database
CN112202905B (en) Information storage method, device and equipment and computer readable storage medium
CN109697216A (en) Exchange information processing method, apparatus and system
CN112202873B (en) Data issuing method and device, computer and computer readable medium
CN115658387A (en) Java-based database backup and restoration method and device, electronic equipment and medium
CN110879721B (en) Method and device for generating help document
CN117632755A (en) Buried point event processing method and device, storage medium and electronic equipment
CN114528575A (en) File encryption method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination