CN111930765A - Method for generating unique serial number of distributed system - Google Patents
Method for generating unique serial number of distributed system Download PDFInfo
- Publication number
- CN111930765A CN111930765A CN202010760024.2A CN202010760024A CN111930765A CN 111930765 A CN111930765 A CN 111930765A CN 202010760024 A CN202010760024 A CN 202010760024A CN 111930765 A CN111930765 A CN 111930765A
- Authority
- CN
- China
- Prior art keywords
- service
- unique
- generated
- timestamp
- algorithm
- 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 18
- 241000533950 Leucojum Species 0.000 claims abstract description 8
- 230000002159 abnormal effect Effects 0.000 claims abstract description 4
- 238000012544 monitoring process Methods 0.000 claims abstract description 4
- 230000000694 effects Effects 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000000889 atomisation Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2308—Concurrency control
- G06F16/2315—Optimistic concurrency control
- G06F16/2322—Optimistic concurrency control using timestamps
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2458—Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
- G06F16/2471—Distributed queries
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Fuzzy Systems (AREA)
- Mathematical Physics (AREA)
- Probability & Statistics with Applications (AREA)
- Software Systems (AREA)
- Computational Linguistics (AREA)
- Computing Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method for generating a unique serial number of a distributed system, which comprises the following steps: s1, adjusting a default fixed starting time stamp in the snowflake algorithm to be a current time stamp, and increasing the number of generated unique ids; s2, adding a timestamp rollback judgment module; s3, modifying the method lock for acquiring the unique id into a code block lock; s4, monitoring the service operation condition and the server abnormal condition in real time; s5, realizing the service provided by the single object instance by using a single instance mode; s6, forming a cluster service by the working id and the machine id in the adjustment algorithm through multi-node deployment; and S7, combining the generated unique id with the time and service information. The self-increment sequence generated by using the snowflake algorithm does not depend on the performance of a database any more, and the sequence increment is realized directly through the algorithm service, so that the service stability is improved; under highly concurrent test contrast, generating sequences by algorithmic service is generally superior in performance to obtaining database sequences.
Description
Technical Field
The invention relates to the field of distributed systems, in particular to a method for generating a unique serial number of a distributed system.
Background
At present, aiming at the uniqueness of transaction flow information of a company stored in a database, a unique flow number is generated for each transaction flow information and is bound with the transaction information, so that the transaction information is convenient to locate and search. The distributed transaction system generally adopts a simple splicing mode of transaction information, transaction time and database sequences. With the continuous breakthrough of transaction volume, the generation of database sequences depending on various resources and performances in the database will become a major bottleneck for the increase of data volume in the future.
Disclosure of Invention
In order to overcome the defects of the prior art, the invention provides a method for generating a unique serial number of a distributed system.
The technical scheme adopted by the invention for solving the technical problems is as follows:
a method for generating a unique serial number of a distributed system comprises the following steps:
s1, adjusting a default fixed starting time stamp in the snowflake algorithm to be a current time stamp, and increasing the number of generated unique ids;
s2, adding a timestamp rollback judgment module;
s3, modifying the method lock for acquiring the unique id into a code block lock;
s4, monitoring the service operation condition and the server abnormal condition in real time;
s5, realizing the service provided by the single object instance by using a single instance mode;
s6, forming a cluster service by the working id and the machine id in the adjustment algorithm through multi-node deployment;
and S7, combining the generated unique id with the time and service information.
Further, in the step S1: the number of unique ids generated is increased by the corresponding difference generated from the current timestamp difference and used starting from a smaller value.
Further, in the step S2: if the server time adjustment results in a timestamp rollback, the unique id is generated by waiting for the time to regain the timestamp after the latest time.
Further, the step S4 includes: after the fixed times of reacquisition of the timestamp fail, the error exception is directly thrown out, and the capture of the system service exception is combined.
The invention has the beneficial effects that:
1. the self-increment sequence generated by using the snowflake algorithm does not depend on the performance of a database any more, and the sequence increment is realized directly through the algorithm service, so that the service stability is improved;
2. under the condition of high concurrency test comparison, the performance of the generation sequence through the algorithm service is generally better than that of the database sequence;
3. the upper limit of the algorithm service generation sequence is greatly improved, the performance bottleneck is improved by exchanging space resources for time and performance, and no unique conflict is generated;
4. the service is independent, does not depend on third party's resource, and deployment is simple, compares other schemes, for example: redis, which consumes fewer resources;
5. because the database sub-base can not use the self-increment sequence, a globally unique generation rule is uniformly provided for the distributed system.
Drawings
The invention is further illustrated with reference to the following figures and examples.
FIG. 1 is a snowflake algorithm basic schematic diagram;
FIG. 2 is a flow chart of a method for generating a unique serial number of a distributed system according to the present invention.
Detailed Description
The conception, the specific structure, and the technical effects produced by the present invention will be clearly and completely described below in conjunction with the embodiments and the accompanying drawings to fully understand the objects, the features, and the effects of the present invention. It is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments, and those skilled in the art can obtain other embodiments without inventive effort based on the embodiments of the present invention, and all embodiments are within the protection scope of the present invention. In addition, all the connection/connection relations referred to in the patent do not mean that the components are directly connected, but mean that a better connection structure can be formed by adding or reducing connection auxiliary components according to specific implementation conditions. All technical characteristics in the invention can be interactively combined on the premise of not conflicting with each other.
The invention discloses a method for generating a unique serial number of a distributed system, which comprises the following steps:
s1, adjusting a default fixed starting time stamp in the snowflake algorithm to be a current time stamp, and increasing the number of generated unique ids by using a corresponding difference value generated by the difference value of the current time stamp from a smaller value;
s2, a newly-added timestamp backspace judging module, which is used for acquiring the timestamp again after waiting for the latest time to generate the unique id according to the condition that the timestamp backspace is caused by the time adjustment of the server;
s3, modifying the method lock for obtaining the unique id into a code block lock, wherein the effect is that the next id generation request calling method cannot be influenced by thread waiting caused by timestamp rollback;
s4, directly throwing out error abnormity after the time stamp is failed to be acquired again for a fixed number of times, and monitoring the service operation condition and the server abnormal condition in real time by combining the capture of the system service abnormity;
s5, realizing single object instance providing service by using a singleton mode, wherein the effect of the service is that the uniqueness of id generation is ensured under the condition of high concurrency by combining with a code lock;
s6, forming a cluster service by the aid of multi-node deployment of the work id and the machine id in the adjustment algorithm, and ensuring high availability and service atomization of the service in a high-concurrency distributed system;
s7, combining the generated unique id with the time and business information, the purpose of the method is to generate a business-specific transaction flow unique id, and the bottleneck upper limit of the transaction flow uniqueness is greatly improved by combining the time of the day.
The invention has the beneficial effects that:
1. the self-increment sequence generated by using the snowflake algorithm does not depend on the performance of a database any more, and the sequence increment is realized directly through the algorithm service, so that the service stability is improved;
2. under the condition of high concurrency test comparison, the performance of the generation sequence through the algorithm service is generally better than that of the database sequence;
3. the upper limit of the algorithm service generation sequence is greatly improved, the performance bottleneck is improved by exchanging space resources for time and performance, and no unique conflict is generated;
4. the service is independent, does not depend on third party's resource, and deployment is simple, compares other schemes, for example: redis, which consumes fewer resources;
5. because the database sub-base can not use the self-increment sequence, a globally unique generation rule is uniformly provided for the distributed system.
While the preferred embodiments of the present invention have been illustrated and described, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.
Claims (4)
1. A method for generating a unique serial number of a distributed system is characterized by comprising the following steps:
s1, adjusting a default fixed starting time stamp in the snowflake algorithm to be a current time stamp, and increasing the number of generated unique ids;
s2, adding a timestamp rollback judgment module;
s3, modifying the method lock for acquiring the unique id into a code block lock;
s4, monitoring the service operation condition and the server abnormal condition in real time;
s5, realizing the service provided by the single object instance by using a single instance mode;
s6, forming a cluster service by the working id and the machine id in the adjustment algorithm through multi-node deployment;
and S7, combining the generated unique id with the time and service information.
2. The method according to claim 1, wherein in step S1: the number of unique ids generated is increased by the corresponding difference generated from the current timestamp difference and used starting from a smaller value.
3. The method according to claim 1, wherein in step S2: if the server time adjustment results in a timestamp rollback, the unique id is generated by waiting for the time to regain the timestamp after the latest time.
4. The method according to claim 1, wherein the step S4 comprises: after the fixed times of reacquisition of the timestamp fail, the error exception is directly thrown out, and the capture of the system service exception is combined.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010760024.2A CN111930765A (en) | 2020-07-31 | 2020-07-31 | Method for generating unique serial number of distributed system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010760024.2A CN111930765A (en) | 2020-07-31 | 2020-07-31 | Method for generating unique serial number of distributed system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111930765A true CN111930765A (en) | 2020-11-13 |
Family
ID=73315085
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010760024.2A Pending CN111930765A (en) | 2020-07-31 | 2020-07-31 | Method for generating unique serial number of distributed system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111930765A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112559467A (en) * | 2020-12-07 | 2021-03-26 | 掌阅科技股份有限公司 | Request processing method for multiple servers of distributed system and electronic equipment |
CN112988757A (en) * | 2021-04-21 | 2021-06-18 | 杭州魔点科技有限公司 | Method, device, equipment and medium for generating global unique ID of distributed system |
CN113342851A (en) * | 2021-05-28 | 2021-09-03 | 北京银行股份有限公司 | Sequence capacity expansion method |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110147281A (en) * | 2019-05-15 | 2019-08-20 | 上海淇毓信息科技有限公司 | Optimize method, apparatus, the electronic equipment that snowflake algorithm is applied in financial business |
CN111078693A (en) * | 2019-11-29 | 2020-04-28 | 叮当快药科技集团有限公司 | Method and device for generating database record primary key |
-
2020
- 2020-07-31 CN CN202010760024.2A patent/CN111930765A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110147281A (en) * | 2019-05-15 | 2019-08-20 | 上海淇毓信息科技有限公司 | Optimize method, apparatus, the electronic equipment that snowflake algorithm is applied in financial business |
CN111078693A (en) * | 2019-11-29 | 2020-04-28 | 叮当快药科技集团有限公司 | Method and device for generating database record primary key |
Non-Patent Citations (4)
Title |
---|
HY_COMING: "分布式ID——雪花算法", HTTPS://BLOG.CSDN.NET/HY_COMING/ARTICLE/DETAILS/104030516, 18 January 2020 (2020-01-18), pages 2 - 3 * |
XXZ_PHOEBE: "Snowflake雪花算法学习", HTTPS://BLOG.CSDN.NET/ALICE_QIXIN/ARTICLE/DETAILS/104279902, 12 February 2020 (2020-02-12), pages 2 - 6 * |
小波同学: "使用雪花算法为分布式下全局ID、订单号等简单解决方案考虑到时钟回拨", HTTPS://WWW.JIANSHU.COM/P/CF6B855B39A3, 28 September 2019 (2019-09-28), pages 1 - 9 * |
跳刀不跳: "雪花算法的分布式使用方法", HTTPS://WWW.CNBLOGS.COM/CS99LZZS/P/9869414.HTML, 29 October 2018 (2018-10-29), pages 1 - 5 * |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112559467A (en) * | 2020-12-07 | 2021-03-26 | 掌阅科技股份有限公司 | Request processing method for multiple servers of distributed system and electronic equipment |
CN112559467B (en) * | 2020-12-07 | 2021-08-31 | 掌阅科技股份有限公司 | Request processing method for multiple servers of distributed system and electronic equipment |
CN112988757A (en) * | 2021-04-21 | 2021-06-18 | 杭州魔点科技有限公司 | Method, device, equipment and medium for generating global unique ID of distributed system |
CN113342851A (en) * | 2021-05-28 | 2021-09-03 | 北京银行股份有限公司 | Sequence capacity expansion method |
CN113342851B (en) * | 2021-05-28 | 2024-04-02 | 北京银行股份有限公司 | Sequence capacity expansion method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111930765A (en) | Method for generating unique serial number of distributed system | |
CN104199957B (en) | A kind of implementation method of Redis general-purpose proxies | |
CN111782923A (en) | Data query method and device, electronic equipment and storage medium | |
CN1763720A (en) | Model based diagnosis and repair for event logs | |
CN106572165A (en) | Distributed global unique ID application method | |
CN111259071B (en) | Concurrent access control method in distributed database system | |
CN109639775A (en) | Global monotonic increase ID generation method, device, system and equipment | |
CN107423390B (en) | Real-time data synchronization method based on OLTP-OLAP mixed relational database system | |
CN112613993B (en) | Transaction data processing method and device, computer equipment and storage medium | |
CN112905339B (en) | Task scheduling execution method, device and system | |
CN103488526A (en) | System and method for locking business resource in distributed system | |
CN108632078B (en) | Configuration acquisition method | |
CN110716936A (en) | Database optimistic lock implementation method and system based on SpringBoot + JPA | |
CN111708775B (en) | Self-increment ID generation method, device and system | |
CN110196868A (en) | Based on distributed work order flow monitoring method | |
CN113901047A (en) | Simple cluster master-slave election method based on memory database | |
CN100346308C (en) | Automatic test method based on database operation | |
CN112925612A (en) | Monitoring service static configuration management method based on Kubernetes | |
CN111651459A (en) | Service ID generation method based on Redis | |
CN116010498A (en) | Method for generating distributed global unique rule ID | |
CN107122246B (en) | Intelligent numerical simulation operation management and feedback method | |
CN115426356A (en) | Distributed timed task lock update control execution method and device | |
CN102043867B (en) | Internal memory dotting-based data calling method for acquisition system | |
CN114564466A (en) | Database management system and method for managing database | |
CN115146908A (en) | Traffic cascade fault emergency regulation and control strategy generation method, system, terminal and medium |
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 |