CN115687367A - ID generation method and system based on ETCD key value version number - Google Patents
ID generation method and system based on ETCD key value version number Download PDFInfo
- Publication number
- CN115687367A CN115687367A CN202310005057.XA CN202310005057A CN115687367A CN 115687367 A CN115687367 A CN 115687367A CN 202310005057 A CN202310005057 A CN 202310005057A CN 115687367 A CN115687367 A CN 115687367A
- Authority
- CN
- China
- Prior art keywords
- key
- version number
- etcd
- value
- generating
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 20
- 241000533950 Leucojum Species 0.000 description 3
- 230000007547 defect Effects 0.000 description 3
- 230000001419 dependent effect Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses an ID generation method and system based on ETCD key value version numbers, and belongs to the technical field of computers. The ID generation method based on the ETCD key value version number comprises the following steps: receiving a key for generating an ID; operating the ETCD module to update the value and the key version number corresponding to the key; and acquiring the key version number, and generating an ID according to the key and the key version number. The invention can conveniently use the ETCD to generate the distributed unique ID which is not repeated, has a serial number, is monotonically increased and can be classified for the distributed system.
Description
Technical Field
The invention belongs to the technical field of computers, and particularly relates to an ID generation method and system based on ETCD key value version numbers.
Background
In a complex distributed system, a large amount of data and messages are required to be uniquely identified, for example, in a system of products such as finance, e-commerce and payment, data is increasing day by day, the limitation of traditional database self-growth ID generation is that IDs generated by a plurality of single applications may be repeated, in the distributed system, a plurality of nodes are used for data identification storage, and the single applications cannot meet large-scale distributed applications realized by emerging technologies such as distributed and micro-service architectures due to defects of the single applications including but not limited to single node faults, insufficient single node computing capacity and the like. The simple use of database self-growth ID as the ID of the data obviously does not satisfy the requirement, and a system capable of generating a globally unique ID is necessary.
The realization scheme of the unique ID of the distributed system is roughly 5, namely a database generation ID, a UUID generation ID, a Redis generation ID, a Zookeeper generation ID and a snowflake algorithm generation ID. The database generation ID is simple and convenient, and the ID number is monotonically increased, but strongly depends on the database; the UUID generated ID has good performance, but the generated ID is too long and the information is unsafe; redis, although not dependent on a database, requires the introduction of new components into the system, increasing the complexity of the system; the Zookeeper generation ID needs to depend on the Zookeeper and also needs to consider a distributed lock; the snowflake algorithm to generate the ID also has the problem that the ID is too long and strongly dependent on the machine clock.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides an ID generation method and system based on ETCD key value version numbers.
The purpose of the invention is realized by the following technical scheme:
according to a first aspect of the present invention, an ID generation method based on an etc key value version number includes:
receiving a key for generating an ID;
operating the ETCD module to update the value and the key version number corresponding to the key;
and acquiring the key version number, and generating an ID according to the key and the key version number.
Further, generating an ID according to the key and the key version number includes:
if the key is empty, using the key version number as an ID;
and if the key is not null, using the combination of the key and the key version number as the ID.
According to a second aspect of the present invention, an ID generation method based on an etc key value version number includes:
updating the value corresponding to the key according to the operation of the ID generation module, and generating a key version number, wherein the key is used for generating the ID and received by the ID generation module;
and sending the key version number to an ID generation module so that the ID generation module generates an ID according to the key and the key version number.
Further, the ID generation module generates an ID according to the key and the key version number, including:
if the key is empty, the ID generation module uses the key version number as the ID;
and if the key is not null, the ID generation module uses the combination of the key and the key version number as the ID.
According to a third aspect of the present invention, an ID generation system based on an ETCD key value version number includes:
the ID generation module is used for receiving a key for generating an ID, operating the ETCD module to update a value and a key version number corresponding to the key, and generating the ID according to the key and the key version number;
and the ETCD module is used for updating the value and the key version number corresponding to the key according to the operation of the ID generation module.
Further, generating an ID according to the key and the key version number includes:
if the key is empty, using the key version number as an ID;
and if the key is not null, using the combination of the key and the key version number as the ID.
The invention has the beneficial effects that:
(1) The distributed unique ID which is not repeated, is connected in number, is increased in monotone and can be classified can be generated for the distributed system by conveniently utilizing the ETCD, so that some defects of the traditional ID generation mode are avoided; for example, conventional digital ID generation typically fixes a bit number, e.g., a user ID is typically fixed as a 7-bit ID or an 11-bit ID; generating an ID based on a UUID is difficult to remember and a long string of alphabets has no practical meaning; the ID generated by the snowflake algorithm has fixed bit number limitation, is difficult to memorize and can generate repetition due to clock callback problems like the traditional digital ID; the ID generated by the invention can be classified and classified, and can carry information with practical significance in the ID, so that the data can be conveniently memorized and processed, a clock cannot be relied on, and repeated ID cannot be generated;
(2) The ETCD is a KEY-VALUE storage component, has the characteristics of data linear consistency, high availability and the like, can provide a distributed KEY-VALUE storage component with high availability, high concurrency and data linear consistency, and has the property of monotonous increase of the obtained ID because the ETCD provides multi-version control of data and the data version is monotonous increase;
(3) Due to the uniqueness of the keys and the free combinability of the keys, the keys can be classified when being stored in the ETCD module, the keys with the same type of ID required can be combined into the unique keys by the same characteristic data and different characteristic data of the keys, and the keys with the same data characteristic can be classified into a group of special sets, so that the requirement of ID classification is met.
Drawings
FIG. 1 is a flow chart of one embodiment of an ID generation method of the present invention;
FIG. 2 is a flow chart of yet another embodiment of an ID generation method of the present invention;
FIG. 3 is a block diagram of an embodiment of an ID generation system according to the present invention.
Detailed Description
The technical solutions of the present invention will be described clearly and completely with reference to the following embodiments, and it should be understood that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without inventive effort based on the embodiments of the present invention, are within the scope of the present invention.
Referring to fig. 1 to fig. 3, the present embodiment provides an ID generation method and system based on an etc key value version number:
the invention provides an ID generation method based on ETCD key value version numbers. As shown in fig. 1, the ID generation method includes steps S100 to S300, which will be described in detail below.
Step S100. The ID generation module receives a key for generating an ID.
Generally, the KEY is empty, which means that a preset KEY value is used, for example, the preset KEY value is "GLOBAL _ ID _ KEY"; the key not being empty indicates that this received key value is used. The key received in this step serves as a key for generating the key version.
And S200. The ID generation module operates the ETCD module to update the value and the key version number corresponding to the key.
And S300, acquiring the key version number by an ID generation module, and generating an ID according to the key and the key version number.
Specifically, if the key is empty, the ID generation module uses the key version number as an ID, for example, 123; if the key is not null, the ID generation module uses the combination of the key and key version number (e.g., "key _ key version number") as the ID, such as user _123.
The invention provides an ID generation method based on ETCD key value version numbers. As shown in fig. 2, the ID generation method includes steps K100 to K200, which will be described in detail below.
The ETCD module updates the value corresponding to the key according to the operation of the ID generation module and generates a key version number; the key is used for generating the ID and received by the ID generation module.
Generally, the KEY is empty, which means that a preset KEY value is used, for example, the preset KEY value is "GLOBAL _ ID _ KEY"; the key not being empty indicates that this received key value is used.
And step K200. The ETCD module sends the key version number to an ID generation module so that the ID generation module generates an ID according to the key and the key version number.
Specifically, if the key is empty, the ID generation module uses the key version number as an ID, for example, 123; if the key is not null, the ID generation module uses the combination of the key and key version number (e.g., "key _ key version number") as the ID, e.g., user _123.
A third aspect of the present invention provides an ID generation system based on an etc key value version number. As shown in fig. 3, the ID generation system includes an ID generation module and an ETCD module.
The ID generation module is used for receiving a key for generating the ID, operating the ETCD module to update the value and the key version number corresponding to the key, and generating the ID according to the key and the key version number.
Generally, the KEY is empty, which means that a preset KEY value is used, for example, the preset KEY value is "GLOBAL _ ID _ KEY"; the key not being empty indicates that this received key value is used. The key received in this step serves as a key for generating the key version.
Specifically, if the key is empty, the ID generation module uses the key version number as an ID, for example, 123; if the key is not null, the ID generation module uses the combination of the key and key version number (e.g., "key _ key version number") as the ID, such as user _123.
The ETCD module is used for updating the value and the key version number corresponding to the key according to the operation of the ID generation module.
The foregoing is illustrative of the preferred embodiments of this invention, and it is to be understood that the invention is not limited to the precise form disclosed herein and that various other combinations, modifications, and environments may be resorted to, falling within the scope of the concept as disclosed herein, either as described above or as apparent to those skilled in the relevant art. And that modifications and variations may be effected by those skilled in the art without departing from the spirit and scope of the invention as defined by the appended claims.
Claims (6)
1. The ID generation method based on the ETCD key value version number is characterized by comprising the following steps:
receiving a key for generating an ID;
operating the ETCD module to update the value and the key version number corresponding to the key;
and acquiring the key version number, and generating an ID according to the key and the key version number.
2. The ETCD key value version number-based ID generation method according to claim 1, wherein generating an ID based on the key and the key version number includes:
if the key is empty, using the key version number as an ID;
and if the key is not null, using the combination of the key and the key version number as the ID.
3. The ID generation method based on the ETCD key value version number is characterized by comprising the following steps:
updating the value corresponding to the key according to the operation of the ID generation module, and generating a key version number, wherein the key is used for generating the ID and received by the ID generation module;
and sending the key version number to an ID generation module so that the ID generation module generates an ID according to the key and the key version number.
4. The ETCD key value version number-based ID generation method according to claim 3, wherein the ID generation module generates an ID according to the key and the key version number, and the method comprises the following steps:
if the key is empty, the ID generation module uses the key version number as the ID;
and if the key is not null, the ID generation module uses the combination of the key and the key version number as the ID.
5. ID generation system based on ETCD key value version number, its characterized in that includes:
the ID generation module is used for receiving a key for generating the ID, operating the ETCD module to update the value and the key version number corresponding to the key, and generating the ID according to the key and the key version number;
and the ETCD module is used for updating the value and the key version number corresponding to the key according to the operation of the ID generation module.
6. The ETCD key value version number-based ID generation system of claim 5, wherein generating an ID from the key and key version number comprises:
if the key is empty, using the key version number as an ID;
and if the key is not null, using the combination of the key and the key version number as the ID.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310005057.XA CN115687367A (en) | 2023-01-04 | 2023-01-04 | ID generation method and system based on ETCD key value version number |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310005057.XA CN115687367A (en) | 2023-01-04 | 2023-01-04 | ID generation method and system based on ETCD key value version number |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN115687367A true CN115687367A (en) | 2023-02-03 |
Family
ID=85057610
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310005057.XA Pending CN115687367A (en) | 2023-01-04 | 2023-01-04 | ID generation method and system based on ETCD key value version number |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN115687367A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117370310A (en) * | 2023-10-19 | 2024-01-09 | 中电云计算技术有限公司 | Distributed file system cross-cluster data increment migration method |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103823810A (en) * | 2012-11-19 | 2014-05-28 | 中国电信股份有限公司 | Method, device and system for generating unique keys in distributed system |
| CN108089916A (en) * | 2017-12-15 | 2018-05-29 | 北京搜狐新媒体信息技术有限公司 | A kind of method and device for generating ID |
| CN111931254A (en) * | 2020-09-26 | 2020-11-13 | 绿漫科技有限公司 | Hybrid identification method for unique identification of Android device |
| US20210090011A1 (en) * | 2019-09-25 | 2021-03-25 | Andrew Marcus Fletcher Rae | Identifying and Tracking System for Searching Items |
| CN112637380A (en) * | 2020-12-31 | 2021-04-09 | 网络通信与安全紫金山实验室 | Distributed cluster ID resource management method, system, device and medium |
| CN113553331A (en) * | 2021-07-28 | 2021-10-26 | 厦门南讯股份有限公司 | Database-based multi-service inter-point log ID generation method |
-
2023
- 2023-01-04 CN CN202310005057.XA patent/CN115687367A/en active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103823810A (en) * | 2012-11-19 | 2014-05-28 | 中国电信股份有限公司 | Method, device and system for generating unique keys in distributed system |
| CN108089916A (en) * | 2017-12-15 | 2018-05-29 | 北京搜狐新媒体信息技术有限公司 | A kind of method and device for generating ID |
| US20210090011A1 (en) * | 2019-09-25 | 2021-03-25 | Andrew Marcus Fletcher Rae | Identifying and Tracking System for Searching Items |
| CN111931254A (en) * | 2020-09-26 | 2020-11-13 | 绿漫科技有限公司 | Hybrid identification method for unique identification of Android device |
| CN112637380A (en) * | 2020-12-31 | 2021-04-09 | 网络通信与安全紫金山实验室 | Distributed cluster ID resource management method, system, device and medium |
| CN113553331A (en) * | 2021-07-28 | 2021-10-26 | 厦门南讯股份有限公司 | Database-based multi-service inter-point log ID generation method |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117370310A (en) * | 2023-10-19 | 2024-01-09 | 中电云计算技术有限公司 | Distributed file system cross-cluster data increment migration method |
| CN117370310B (en) * | 2023-10-19 | 2024-05-28 | 中电云计算技术有限公司 | Distributed file system cross-cluster data increment migration method |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US5758354A (en) | Application independent e-mail synchronization | |
| US6983293B2 (en) | Mid-tier-based conflict resolution method and system usable for message synchronization and replication | |
| US5333317A (en) | Name resolution in a directory database | |
| US6101556A (en) | Method for content-based dynamic formatting for interoperation of computing and EDI systems | |
| CN111797073B (en) | Database management method, electronic device, and computer-readable storage medium | |
| WO1997041520A1 (en) | A method for scaling large e-mail databases for devices with limited storage | |
| US20100145970A1 (en) | Textual Search for Numerical Properties | |
| CN105930390B (en) | Relational database expansion method and system | |
| US20030041069A1 (en) | System and method for managing bi-directional relationships between objects | |
| CN115994141A (en) | Tree-shaped coding method and system | |
| CN113821521B (en) | Distributed identification generation method, device, electronic device and storage medium | |
| CN112487198A (en) | Physical model processing method and device, electronic equipment and computer storage medium | |
| US20080133543A1 (en) | System and Method for Dynamic and On-Demand Data Transfer and Synchronization Between Isolated Networks | |
| CN112541780A (en) | Integral data recording system, recording method, storage medium and terminal | |
| CN112256584B (en) | Internet number making method and system | |
| CN116028505B (en) | A method for implementing high-availability sequences in distributed databases | |
| CN115687367A (en) | ID generation method and system based on ETCD key value version number | |
| US20080005200A1 (en) | Method and apparatus for synchronizing of databases connected by wireless interface | |
| CN110609766B (en) | A KV data storage method and device based on Redis protocol | |
| CN111400274A (en) | Method for designing approval process state field of web application | |
| EP1755050A1 (en) | A data processing system and method of storing a dataset having a hierarchical data structure in a database | |
| US7584219B2 (en) | Incremental non-chronological synchronization of namespaces | |
| CN116501375B (en) | Data dictionary version management method, device, computer equipment and storage medium | |
| GB2386985A (en) | Update resolution procedure for a directory server | |
| CN110716913A (en) | Mutual migration method for Kafka and Elasticissearch database data |
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 | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20230203 |
|
| RJ01 | Rejection of invention patent application after publication |