CN110334092A - Distributed ID generation method, storage medium - Google Patents
Distributed ID generation method, storage medium Download PDFInfo
- Publication number
- CN110334092A CN110334092A CN201910514044.9A CN201910514044A CN110334092A CN 110334092 A CN110334092 A CN 110334092A CN 201910514044 A CN201910514044 A CN 201910514044A CN 110334092 A CN110334092 A CN 110334092A
- Authority
- CN
- China
- Prior art keywords
- list
- application example
- application
- generation method
- obtains
- 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
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/22—Indexing; Data structures therefor; Storage structures
-
- 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/2365—Ensuring data consistency and integrity
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Software Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The present invention provides distribution ID generation method, storage medium, and it includes more than two ID in the ID list that method, which includes: that application example obtains ID list from the central database,;Application example stores the ID list to local memory and local file respectively;Application program obtains ID, and corresponding ID in the ID list of Delete Local File from the ID list of local memory.The present invention not only can be reduced using the interactive operation with center, improve the efficiency that application obtains ID;And energy decentralization, significantly reduce central point influences caused by application extremely, to improve the stability of application;Further, moreover it is possible to the probability that application success obtains ID is improved under complications;Finally, also have many advantages, such as to be easy to implement, practicability it is high.
Description
Technical field
The present invention relates to distributed system ID management domains, and in particular to distributed ID generation method, storage medium.
Background technique
ID generating mode there are many kinds of existing among practical item development the following is some Mass production ID thinkings
It illustrates and advantage and disadvantage therein:
1, database increases major key certainly
Advantage: simple;Uniquely;It is incremented by;Amplification is fixed;
Disadvantage: write performance determines the generation quantity upper limit per second, and it is poor to extend;Host node in distributed data base is hung, only
It can rely on when slave node and be likely to occur problem (host node is written successfully, and log is not synchronized to slave node, and id is caused to repeat)
Remarks: can write library by one and become multiple libraries while writing, and such as 1,2,3 three library is write simultaneously, initial id is respectively 1,
2,3, it is all 3 from amplification degree.This mode can guarantee that id is not repeated.But id is caused not instead of absolutely not to be incremented by, on overall trend
It is incremented by;The pressure being followed by written is still very big, and mysql easily becomes performance bottleneck.
2, database Mass production id
Advantage: high-efficient;Reduce database pressure;
Disadvantage: need to consider safety issue, prevent from getting repetition id;If business demand is to only generate an id every time,
Performance is problematic.
Remarks: utilizing database, initializes data line, and initial value 1 takes 10 id, just adds 10 to the value, calls end
Take preceding 10 numerical value for returning to id value.
In general distributed system, the mode for generating distribution ID is typically all a central point storage.For example, every
A application or the place for needing ID when obtaining ID every time, require to obtain id information to central database or central cache,
When getting and then carry out subsequent operation.In such cases, one is the operation for needing to carry out primary network interaction, separately
One is if obtaining ID failure in the case of central database or central cache delay machine, and regular traffic can not go on.
Old this mode requests ID all directly from the central database or central cache is directly accessed, to handle up not high every time.
Summary of the invention
The technical problems to be solved by the present invention are: providing a kind of distribution ID generation method, storage medium, can reduce
Network interaction number removes centralization, to improve practicability.
In order to solve the above-mentioned technical problem, the technical solution adopted by the present invention are as follows:
A kind of distribution ID generation method, comprising:
Application example obtains ID list from the central database, includes more than two ID in the ID list;
Application example stores the ID list to local memory and local file respectively;
Application program obtains ID, and phase in the ID list of Delete Local File from the ID list of local memory
The ID answered.
Another technical solution provided by the invention are as follows:
A kind of computer readable storage medium is stored thereon with computer program, described program when being executed by processor,
It is able to achieve the step of a kind of distribution ID generation method is included.
The beneficial effects of the present invention are: a certain number of ID are pre-stored to local memory and local text by application example
Part, and the synchronous ID Expenditure Levels of the two;Application daily need ID when, can be obtained directly from local memory ID without with
Data center's interaction;When delay machine or application are restarted at center, local file can also be directly based upon and restored in ID list to local
It deposits, then proceedes to enable local obtaining mode, without being interacted with central database.The present invention can substantially reduce the friendship with center
Mutual number not only realizes decentralization, but also guarantees the availability of application under the abnormal conditions of center;ID can be improved again simultaneously to obtain
Take speed.
Detailed description of the invention
Fig. 1 is a kind of flow diagram of distribution ID generation method of the embodiment of the present invention;
Fig. 2 is a kind of flow diagram of the distribution ID generation method of the embodiment of the present invention one.
Specific embodiment
To explain the technical content, the achieved purpose and the effect of the present invention in detail, below in conjunction with embodiment and cooperate attached
Figure is explained.
The most critical design of the present invention is: using a certain number of ID are pre-stored to local memory and local file, and
The two synchronizes ID Expenditure Levels;Even if center is abnormal, using also can normally obtain ID, decentralization is realized.
Fig. 1 is please referred to, the present invention provides a kind of distribution ID generation method, comprising:
Application example obtains ID list from the central database, includes more than two ID in the ID list;
Application example stores the ID list to local memory and local file respectively;
Application program obtains ID, and phase in the ID list of Delete Local File from the ID list of local memory
The ID answered.
As can be seen from the above description, the beneficial effects of the present invention are: multiple net interaction can be reduced;Meanwhile
A problem of central point can also be removed, prevents all not available situations of application caused by central point delay machine.
Further, further includes:
After application example is restarted, inquire in local file whether be stored with the ID list;
If so, then loading the ID list to local memory.
Seen from the above description, when center delay machine or application are restarted, directly the ID list of local file can be restored
It to local memory, then proceedes to enable local obtaining mode, without interacting with central database, guarantees application not acceptor center shadow
Loud normal operation.
Further, further includes:
When list is empty by the ID, the ID that application example obtains preset quantity from the central database is stored in the ID column
Table.
Seen from the above description, after local ID runs out of, then from center a certain number of ID are paid in advance, thus reduce with
Center interaction times, and guarantee that the ID service condition of application is unaffected.
Further, the application example obtains ID list from the central database, specifically:
Application example start when, according to ID needed for it ID from type to central database request preset quantity;
Central database generates starting ID number and the preset quantity current in allocation list according to its ID, returns by corresponding
The ID list that constitutes of ID to application example;
Updating the ID to generate allocation list includes the field information for originating ID number, revision number and ID type.
It seen from the above description, will be according to preset quantity, from current starting ID number start sequence in a specific example
The ID of respective numbers is obtained, and is prevented more using the ID record case that version number's mode updates central database is taken simultaneously
The problem of concurrently causing in the case of thread, and can ensure that the order and good for use of ID distribution.
Further, further includes:
Fail when application example obtains ID list from the central database, then retry, until continuous failure preset times.
Seen from the above description, when obtaining ID list, under complications, failure may be obtained, while being configured certain time
Several retry mechanisms can improve the probability for successfully obtaining ID.
Another technical solution provided by the invention are as follows:
A kind of computer readable storage medium is stored thereon with computer program, described program when being executed by processor,
It is able to achieve the step of a kind of distribution ID generation method is included.
As can be seen from the above description, corresponding those of ordinary skill in the art will appreciate that realizing the whole in above-mentioned technical proposal
Or part process, relevant hardware can be instructed to realize by computer program, the program can be stored in one
In computer-readable storage medium, the program is when being executed, it may include such as the process of above-mentioned each method.Described program executes
Afterwards, the beneficial effect of correlation method can equally be obtained.
Wherein, the storage medium can be disk, optical disc, read-only memory (Read-Only Memory,
) or random access memory (Random Access Memory, RAM) etc. ROM.
Embodiment one
Referring to figure 2., the present embodiment provides a kind of distribution ID generation method, a central point problem can be removed, thus
It effectively prevent central point delay machine and causes all applications unavailable, and then improve application and run to obtain stability;Simultaneously, moreover it is possible to realize
Using more easily use ID.
Firstly, there are ID to generate allocation list id_start in central database, the primary fields in table have: major key id,
(type of id is defined with specific reference to business by start_id (ID start field), version (revision number) and type
The type of id).For example, one table data of initialization, data content are as follows: id=1, start_id=1000, version=1,
Type=1.
Secondly, (refer in particular to start with the first time of this method) when each application example starting for needing to use ID, it can be to
Central database obtains data, i.e. ID list.Wherein, it after central database is by inquiring starting ID, is sent out according to application example
The ID that the quantity specified in the request brought pays respective numbers in advance constitutes ID list, returns to application example.
In a specific example, application example is by the type according to required ID, such as " type=1 " removes centre data
The record that ID generates allocation list id_start is inquired in library, it is assumed that inquiring start_id (starting ID) is 1000, at this point, foundation
The pre-set ID quantity to be obtained of application example obtains the end value of starting ID+1000=2000, removes calculation in update
According to the start_id field in library.The detailed process of update includes: to take start_id+1 every time, until plus 1000;It takes simultaneously
Version number updates the corresponding version number field content of each start_id simultaneously.Taking the mode that version number is updated is
General database optimism lock mechanism, in the case of multithreading capable of being prevented, the problem of concurrently causing.In the specific example, application
Example get from the central database be start_id be 1000-2000 within the scope of numerical value, that is, correspond to the specific value of ID
For 1001,1002,1003 ... .1999,2000;ID list is formed by this thousand specific ID.
In another specific example, for complications, the above-mentioned result for obtaining ID list from the central database may be lost
It loses.Therefore each application example is configured when obtaining ID list failure from the central database, will be retried, if continuously retrying pre-
If number, if still failed after 3 times, then determining application example, request ID fails from the central database.This specific example energy
It improves application example under complications and obtains the successful probability of ID list, reduce adverse effect of the complications to application example.
Particularly, after application example gets ID list, local memory and local file will be respectively stored into.Wherein, originally
Ground memory refers to local virtual memory space;Local file refers to creating the file in local disk, corresponding physics
Memory space.
Through the above steps, application example has been pre-stored a certain number of available ID in local.When the journey of application
When sequence needs ID, application example directly will sequentially take out ID from the ID list of local memory and carry out using ID is once used, then
It is considered being consumed;At the same time, ID corresponding in the ID list in synchronization removal local file also (is consumed by application example
ID) record.I.e. under application example normal operation, the ID column stored in local memory and local file are remained
The consistency of table.It is recorded for example, application example takes out the ID that ID number is 1009 according to demand from local memory, then local text
In the ID list of part, this ID that ID number is 1009 will be deleted and recorded.
When the ID in the ID list that application program is locally stored is recorded as sky or is less than preset threshold (as less than 3
Record), then a certain number of ID are paid in advance to central database again, and be stored in ID list.Preferably, the ID record paid in advance every time
Quantity records corresponding with the vacant ID of ID list.
Whether application example is restarted each time, will all inquire in its local file and be stored in ID list and ID list
Record whether be empty;ID list or be recorded as sky if it does not exist, then return from above-mentioned " secondly " " to central database
Acquisition data, i.e. ID list " step starts to execute, and reacquires ID list or filling ID list.If being stored in local file
ID list is then loaded directly into the ID list in local file into local memory, then according to above-mentioned, is needing ID's each time
When directly obtained from the ID list of local memory.
The present embodiment is using the completely new application ID generation method being different from the prior art, and each application example is in local ident
When not enough, just from the central database or central cache carry out ID acquisition, and every time obtain a period of time (or certain amount)
Within ID;Later, write-in ID list is stored among local memory, meanwhile, need to record the ID list into local file.
After the ID of each memory is exhausted, corresponding data record in synchronous removing local file is needed.As a result, when application delay machine or
It when restarting, does not need again to central database request ID yet, but ID list can be restored directly from local log
Into local memory;If central database exception occurs and can not issue ID, all application examples also can be based on local ID
List guarantees to operate normally, and unaffected.Such mode, as long as the ID list of application local is not sky, without in access
Heart database, it is possible to reduce multiple net interaction improves ID service efficiency;Simultaneously, moreover it is possible to remove a central point
Problem, even if ID can be used normally in center extremely, to significantly improve the stability using operation.
Embodiment two
The present embodiment provides a kind of computer readable storage mediums, are stored thereon with computer program, described program is in quilt
When processor executes, it is able to achieve the step of a kind of distribution ID generation method described in above-described embodiment one is included.Specifically
Step content without repeating, for further details, please refer to the record of embodiment one herein.
In conclusion a kind of distribution ID generation method provided by the invention, storage medium, not only can be reduced using in
The interactive operation of the heart improves the efficiency that application obtains ID;And energy decentralization, it significantly reduces central point exception and application is caused
Influence, to improve the stability of application;Further, moreover it is possible to improve application success under complications and obtain the general of ID
Rate;Finally, also have many advantages, such as to be easy to implement, practicability it is high.
The above description is only an embodiment of the present invention, is not intended to limit the scope of the invention, all to utilize this hair
Equivalents made by bright specification and accompanying drawing content are applied directly or indirectly in relevant technical field, similarly include
In scope of patent protection of the invention.
Claims (6)
1. a kind of distribution ID generation method characterized by comprising
Application example obtains ID list from the central database, includes more than two ID in the ID list;
Application example stores the ID list to local memory and local file respectively;
Application program obtains ID from the ID list of local memory, and corresponding in the ID list of Delete Local File
ID。
2. a kind of distribution ID generation method as described in claim 1, which is characterized in that further include:
After application example is restarted, inquire in local file whether be stored with the ID list;
If so, then loading the ID list to local memory.
3. a kind of distribution ID generation method as described in claim 1, which is characterized in that further include:
When list is empty by the ID, the ID that application example obtains preset quantity from the central database is stored in the ID list.
4. a kind of distribution ID generation method as described in claim 1, which is characterized in that the application example is from centre data
Library obtains ID list, specifically:
Application example start when, according to ID needed for it ID from type to central database request preset quantity;
Central database generates starting ID number and the preset quantity current in allocation list according to its ID, returns by corresponding ID
The ID list of composition is to application example;
Updating the ID to generate allocation list includes the field information for originating ID number, revision number and ID type.
5. a kind of distribution ID generation method as described in claim 1, which is characterized in that further include:
Fail when application example obtains ID list from the central database, then retry, until continuous failure preset times.
6. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that described program is processed
When device executes, it is able to achieve the step of a kind of distribution ID generation method described in the claims 1-5 any one is included.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910514044.9A CN110334092A (en) | 2019-06-14 | 2019-06-14 | Distributed ID generation method, storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910514044.9A CN110334092A (en) | 2019-06-14 | 2019-06-14 | Distributed ID generation method, storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110334092A true CN110334092A (en) | 2019-10-15 |
Family
ID=68142179
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910514044.9A Pending CN110334092A (en) | 2019-06-14 | 2019-06-14 | Distributed ID generation method, storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110334092A (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110082908A1 (en) * | 2009-10-06 | 2011-04-07 | Bela Ban | Dynamic caching of nodes |
CN102880705A (en) * | 2012-09-28 | 2013-01-16 | 用友软件股份有限公司 | Database primary key generating device and database primary key generating method |
CN105447167A (en) * | 2015-12-04 | 2016-03-30 | 北京奇虎科技有限公司 | Processing method and apparatus for node cache data in distributed system |
CN106572165A (en) * | 2016-10-26 | 2017-04-19 | 宜人恒业科技发展(北京)有限公司 | Distributed global unique ID application method |
CN109033292A (en) * | 2018-07-13 | 2018-12-18 | 南京邮电大学 | A kind of database distributed caching system and method |
-
2019
- 2019-06-14 CN CN201910514044.9A patent/CN110334092A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110082908A1 (en) * | 2009-10-06 | 2011-04-07 | Bela Ban | Dynamic caching of nodes |
CN102880705A (en) * | 2012-09-28 | 2013-01-16 | 用友软件股份有限公司 | Database primary key generating device and database primary key generating method |
CN105447167A (en) * | 2015-12-04 | 2016-03-30 | 北京奇虎科技有限公司 | Processing method and apparatus for node cache data in distributed system |
CN106572165A (en) * | 2016-10-26 | 2017-04-19 | 宜人恒业科技发展(北京)有限公司 | Distributed global unique ID application method |
CN109033292A (en) * | 2018-07-13 | 2018-12-18 | 南京邮电大学 | A kind of database distributed caching system and method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11132350B2 (en) | Replicable differential store data structure | |
US11442961B2 (en) | Active transaction list synchronization method and apparatus | |
US20090063807A1 (en) | Data redistribution in shared nothing architecture | |
CN109582686B (en) | Method, device, system and application for ensuring consistency of distributed metadata management | |
CN105183400A (en) | Object storage method and system based on content addressing | |
EP3593243B1 (en) | Replicating storage tables used to manage cloud-based resources to withstand storage account outage | |
US11449402B2 (en) | Handling of offline storage disk | |
CN104765661A (en) | Multiple-node hot standby method of metadata service nodes in cloud storage service | |
CN107451172A (en) | Method of data synchronization and equipment for edition management system | |
CN108762982B (en) | A kind of database restoring method, apparatus and system | |
CN114528255A (en) | Metadata management method, electronic device and computer program product | |
CN109726264A (en) | Method, apparatus, equipment and the medium updated for index information | |
CN109271367A (en) | Distributed file system multinode snapshot rollback method and system | |
US10243869B2 (en) | System and method for providing a distributed queue in a distributed data grid | |
CN111291062B (en) | Data synchronous writing method and device, computer equipment and storage medium | |
CN109933609A (en) | A kind of method and terminal of Mass production ID | |
JP7215971B2 (en) | METHOD AND APPARATUS FOR PROCESSING DATA LOCATION IN STORAGE DEVICE, COMPUTER DEVICE AND COMPUTER-READABLE STORAGE MEDIUM | |
KR101875763B1 (en) | The database management system and method for preventing performance degradation of transaction when table reconfiguring | |
CN109815207A (en) | Date storage method and Client Agent | |
US11442663B2 (en) | Managing configuration data | |
CN108984779A (en) | Distributed file system snapshot rollback metadata processing method, device and equipment | |
CN110334092A (en) | Distributed ID generation method, storage medium | |
US20170177615A1 (en) | TRANSACTION MANAGEMENT METHOD FOR ENHANCING DATA STABILITY OF NoSQL DATABASE BASED ON DISTRIBUTED FILE SYSTEM | |
CN114168380A (en) | Database configuration method, device, system and storage medium | |
CN108271420A (en) | Manage method, file system and the server system of file |
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 |