CN110162573A - A kind of distribution sequence generating method, apparatus and system - Google Patents

A kind of distribution sequence generating method, apparatus and system Download PDF

Info

Publication number
CN110162573A
CN110162573A CN201910367543.XA CN201910367543A CN110162573A CN 110162573 A CN110162573 A CN 110162573A CN 201910367543 A CN201910367543 A CN 201910367543A CN 110162573 A CN110162573 A CN 110162573A
Authority
CN
China
Prior art keywords
sequence
value
sequential value
sequential
storage
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.)
Granted
Application number
CN201910367543.XA
Other languages
Chinese (zh)
Other versions
CN110162573B (en
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.)
Bank of China Ltd
Original Assignee
Bank of China 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 Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN201910367543.XA priority Critical patent/CN110162573B/en
Publication of CN110162573A publication Critical patent/CN110162573A/en
Application granted granted Critical
Publication of CN110162573B publication Critical patent/CN110162573B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Computer And Data Communications (AREA)

Abstract

This specification embodiment discloses a kind of distributed sequence generating method, apparatus and system.The request of sequence is obtained the method includes receiving destination server;Obtain First ray value, according to the First ray value and sequence offset amount, currently used sequential value is obtained, the First ray value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is the maximal sequence number generated within a sequence storage period;It is incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein the sequence manager carries out persistent storage to second sequential value every the sequence storage period;Second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server.While globally unique sequence can be generated according to actual scene using this specification embodiment, the efficiency of formation sequence is improved.

Description

A kind of distribution sequence generating method, apparatus and system
Technical field
This specification example scheme belongs to distributed system technical field more particularly to a kind of distributed sequence generation side Method, apparatus and system.
Background technique
With the rapid development of Internet, extensive, distribution application system is increasingly becoming the standard configuration of software systems.Dividing Service can be externally provided in the presence of multiple servers are permitted in cloth system, require to distribute for server under many scenes complete in system The unique sequence code ID of intra-office is specifically the service provided by which platform server, such as industry for distinguishing the same service request Ordering system in business generates globally unique order number, technical point of library divides table system to generate globally unique database table master Key etc..
Currently, being generated there are many modes of globally unique serial ID for server in a distributed system: first is that using system The serial ID generting machanism of one server itself generates unique sequence code ID, for example, oracle database, redis database, Zookeeper etc. can realize similar function.However, which needs to guarantee formation sequence by server characteristics Uniqueness can become "bottleneck" using single-point server under high concurrent scene.Such as the sequence using oracle database Generting machanism, since oracle database is itself is a single-point, receivable connection number is conditional, so when concurrent When amount reaches a certain level, oracle database will become system performance bottleneck.Second is that generating distribution based on local service The snowflake algorithm of globally unique serial ID under formula system.Although it is unique voluntarily to generate which is based entirely on local server The problem of sequence, there is no "bottleneck"s, but the sequence of snowflake algorithm generation is the sequence of maximum 19 bit lengths, it is not possible to it makes by oneself Adopted sequence length when business scenario has strict demand to sequence length, and is not suitable for.Such as certain service application scene requirement Sequence is the fixed length sequence of 12 bit lengths, then snowflake algorithm cannot be met the requirements.
Therefore, it is globally unique that a kind of sequence that can not only guarantee to generate is needed in the industry, but also the sequence generated can be made to adapt to The solution of different distributions formula scene.
Summary of the invention
This specification embodiment is designed to provide a kind of distributed sequence generating method, apparatus and system, can basis The usage scenario of distributed sequence generates globally unique serial ID in distributed system, so as to guarantee high place The efficiency of formation sequence is effectively improved while rationality energy.
On the one hand this application provides a kind of distributed sequence generating methods, comprising:
Receive the request that destination server obtains sequence;
It obtains First ray value and currently used sequential value is obtained according to the First ray value and sequence offset amount, it is described First ray value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is stored in a sequence The maximal sequence number generated in period;
On the basis of the currently used sequential value be incremented by, obtain the second sequential value, wherein the sequence manager every The sequence storage period carries out persistent storage to second sequential value;
Second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server.
In another embodiment of the method that this specification provides, the acquisition First ray value, according to described the One sequential value and sequence offset amount, obtain currently used sequential value, and the First ray value is sequence manager from storage service The sequential value that device is read, comprising:
Judge the sequential value that whether there is persistence in the storage server;
It determines in the storage server there are when the sequential value of persistence, then reads last from the storage server The sequential value of secondary persistence is as the First ray value.
In another embodiment of the method that this specification provides, further includes:
When determining the sequential value that persistence is not present in the storage server, then read from the storage server default Value is used as the First ray value.
It is described on the basis of the currently used sequential value in another embodiment of the method that this specification provides It is incremented by, after obtaining the second sequential value, further includes:
Judge whether second sequential value is greater than predetermined sequence value;
It determines when being greater than predetermined sequence value, then resets second sequential value, the second sequential value after being reset, In, the sequence manager carries out persistent storage to the second sequential value after the resetting every the sequence storage period;
Correspondingly, the second sequential value after the resetting is spliced with machine identification, the destination server is generated Globally unique sequence.
In another embodiment of the method that this specification provides, the storage server includes at least persistence number According to function.
On the other hand, this specification embodiment also provides a kind of distributed sequence generator, and described device includes:
Receiving module obtains the request of sequence for receiving destination server;
First acquisition module, according to the First ray value and sequence offset amount, is worked as obtaining First ray value Preceding to use sequential value, the First ray value is the sequential value that sequence manager is read from storage server, the sequence offset Amount is the maximal sequence number generated within a sequence storage period;
Second obtains module, for being incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein The sequence manager carries out persistent storage to second sequential value every the sequence storage period;
Sequence generating module generates the destination service for splicing second sequential value with machine identification The globally unique sequence of device.
In another embodiment for the described device that this specification provides, described first obtains module, comprising:
First judging unit, the sequential value for judging to whether there is persistence in the storage server;
First reading unit is then deposited from described for determining in the storage server there are when the sequential value of persistence It stores up server and reads the sequential value of last time persistence as the First ray value.
In another embodiment for the described device that this specification provides, further includes:
Second reading unit, when for determining the sequential value that persistence is not present in the storage server, then from described Storage server reads preset value as the First ray value.
It is described on the basis of the currently used sequential value in another embodiment for the described device that this specification provides It is incremented by, after obtaining the second sequential value, further includes:
Second judgment unit, for judging whether second sequential value is greater than predetermined sequence value;
Third obtaining unit then resets second sequential value, after being reset when being greater than predetermined sequence value for determining The second sequential value, wherein the sequence manager every the sequence storage period to the second sequential value after the resetting Carry out persistent storage;
Correspondingly, the second sequential value after the resetting is spliced with machine identification, the destination server is generated Globally unique sequence.
On the other hand, this specification embodiment provides a kind of distributed sequence generating device, including processor and for depositing Store up processor-executable instruction memory, when described instruction is executed by the processor realization the following steps are included:
Receive the request that destination server obtains sequence;
It obtains First ray value and currently used sequential value is obtained according to the First ray value and sequence offset amount, it is described First ray value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is stored in a sequence The maximal sequence number generated in period;
On the basis of the currently used sequential value be incremented by, obtain the second sequential value, wherein the sequence manager every The sequence storage period carries out persistent storage to second sequential value;
Second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server.
On the other hand, this specification embodiment provides a kind of distributed sequence generation system, including at least one processor And the memory of storage computer executable instructions, the processor realize any one above-mentioned implementation when executing described instruction The step of example the method.
A kind of distributed sequence generating method, apparatus and system that this specification embodiment provides, on the one hand, by sequence Calling sequence manager in column-generation service, the sequence currently used for intermittently persistence, and read when servicing starting It takes the sequence data of persistence and plus offset as currently used sequential value, can effectively solve to utilize memory storage sequence The problem of column, sequence is lost after server resets, the sequence for guaranteeing that service starting front and back generates is globally unique, to improve The efficiency of formation sequence.On the other hand, it since service operation phase time series uses local service to generate completely, can effectively keep away Exempt from the problem of single-point server is as performance bottleneck, to guarantee high process performance.In another aspect, due to being complete base Sequence accumulation is carried out in the mode that currently used sequence synchronization is incremented by, is added to sequence without any element in addition to machine identification In, it is customized so the length of sequence can be actually needed completely according to business scenario, can make the sequence generated suitable in this way Answer different distributed scenes.Therefore, using each embodiment of this specification, can according to the usage scenario of distributed sequence, Globally unique serial ID is generated in distributed system, to effectively improve generation sequence while guaranteeing high process performance The efficiency of column.
Detailed description of the invention
In order to illustrate more clearly of this specification embodiment or technical solution in the prior art, below will to embodiment or Attached drawing needed to be used in the description of the prior art is briefly described, it should be apparent that, the accompanying drawings in the following description is only The some embodiments recorded in this specification, for those of ordinary skill in the art, in not making the creative labor property Under the premise of, it is also possible to obtain other drawings based on these drawings.
Fig. 1 is a kind of schematic diagram of a scene embodiment of distributed sequence generating method that this specification provides;
Fig. 2 is a kind of flow diagram of the one embodiment for distributed sequence generating method that this specification provides;
Fig. 3 is the flow diagram of a specific embodiment of the distributed sequence generating method that this specification provides;
Fig. 4 is that sequence manager is taking in a specific embodiment of the distributed sequence generating method that this specification provides Flow diagram when business starting;
Fig. 5 is that sequence manager is taking in a specific embodiment of the distributed sequence generating method that this specification provides The flow diagram of business runtime;
Fig. 6 is a kind of modular structure signal of the one embodiment for distributed sequence generator that this specification provides Figure;
Fig. 7 is the hardware configuration frame that a kind of distributed sequence that this specification provides generates one embodiment of server Figure.
Specific embodiment
In order to make those skilled in the art more fully understand the technical solution in this specification, below in conjunction with this explanation Attached drawing in book embodiment is clearly and completely described the technical solution in this specification embodiment, it is clear that described Embodiment be only a part of the embodiment in this specification, instead of all the embodiments.Base in this manual one A or multiple embodiments, every other reality obtained by those of ordinary skill in the art without making creative efforts Example is applied, the range of this specification embodiment protection all should belong to.
Currently, being generated there are many modes of globally unique serial ID for server in a distributed system: first is that using system The serial ID generting machanism of one server itself generates unique sequence code ID, but which needs to guarantee by server characteristics The uniqueness of formation sequence can become "bottleneck" using single-point server under high concurrent scene.Second is that being based on local service The snowflake algorithm of globally unique serial ID under distributed system is generated, although which is based entirely on local server and comes from The problem of row generates unique sequence code, and "bottleneck" is not present, but the sequence of snowflake algorithm generation is the sequence of maximum 19 bit lengths, Cannot custom list length, when business scenario has strict demand to sequence length, and be not suitable for.
Correspondingly, this specification embodiment provides a kind of distributed sequence generating method, on the one hand, by raw in sequence At calling sequence manager in service, the sequence currently used for intermittently persistence, and read and hold when servicing starting The sequence data changed long and plus offset as currently used sequential value, can effectively solve using memory storage sequence, The problem of sequence is lost after server resets, the sequence for guaranteeing that service starting front and back generates is globally unique, to improve life At the efficiency of sequence.On the other hand, carry out formation sequence by using local service in the service operation phase, it is possible to prevente effectively from single-point Server becomes the problem of performance bottleneck, to guarantee high process performance.In another aspect, being incremented by by using sequence synchronization Mode carry out sequence accumulation, be added in sequence in addition to machine identification without any element, so the length of sequence completely may be used To be customized according to business scenario actual needs, the sequence generated can be made to adapt to different distributed scenes in this way.Therefore, Using each embodiment of this specification, the overall situation can be generated only in distributed system according to the usage scenario of distributed sequence One serial ID, to effectively improve the efficiency of formation sequence while guaranteeing high process performance.
For exploitation angle, in the embodiment that this specification provides, developer needs according to actual business field Scape carries out sequential structure setting, and selects suitable storage server for persistence current sequence value, selects suitable sequence Manager, which is used to generate service to sequence, to be managed.
The embodiment that this specification provides can be applied in distributed system and distribute in system uniquely for server In the scene of ID, the distributed system may include multiple servers.As shown in Figure 1, Fig. 1 is one kind that this specification provides The schematic diagram of one scene embodiment of distributed sequence generating method.Specifically, generated in service in distributed system sequence, By calling sequence manager, for reading the sequential value of persistence from storage server when servicing starting so as to raw in sequence At being used in service;It is taken in addition, sequence manager can be also used for the currently used sequential value of intermittently persistence to storage Business device, in this way it is possible to prevente effectively from using memory storage sequence, after server resets the problem of sequence loss, to guarantee to service The sequence that starting front and back generates is globally unique, to improve the efficiency of formation sequence.
This specification embodiment is illustrated by taking a specific application scenarios as an example below.Specifically, Fig. 2 is this A kind of flow diagram of the one embodiment for distributed sequence generating method that specification provides.Although present description provides As the following examples or method operating procedure shown in the drawings or apparatus structure, but based on conventional or be not necessarily to creative labor Less operating procedure or modular unit after may include more in the method or device or part merging.In logicality In upper the step of there is no necessary causalities or structure, the execution sequence of these steps or the modular structure of device are not limited to this Specification embodiment or execution shown in the drawings sequence or modular structure.The dress in practice of the method or modular structure It sets, server or end product are in application, can be according to embodiment or method shown in the drawings or modular structure progress sequence Execute or it is parallel execute (such as parallel processor or multiple threads environment, even include distributed treatment, server The implementation environment of cluster).
Certainly, the description of following embodiments does not constitute limit to other technical solutions extended to based on this specification System.
A kind of specific embodiment is as shown in Fig. 2, Fig. 2 is a kind of distributed sequence generating method that this specification provides The flow diagram of one embodiment, the method may include:
S0: the request that destination server obtains sequence is received.
Wherein, sequence is referred to as serial ID, is made of sequential value and machine identification splicing.Sequential value is one Fixed length numerical value (can be unified for long type), and when each formation sequence synchronizes cumulative 1, i.e., sequential value is a series of from increasing numerical value. Machine identification, that is, Work machine ID, is referred to as machine ID, is the unique identification of machine, environmental variance, data can be used The various ways setting such as library storage.Due to being multiple servers in distributed system environment while running, in order to make every clothes Being engaged in, the sequence that device generates is inconsistent, so increasing machine ID, i.e., machine ID is for distinguishing clothes different under distributed system Business device, for guaranteeing the uniqueness of different server formation sequence.In addition, machine ID is just initialized when server starts It is good, that is to say, that have determined that it is any platform server when formation sequence.For example, two-server, number is 1 and 2 respectively, So when server 1 starts, it is necessary to load machine ID.In ordinary circumstance, the length of sequence can according to actual scene into Row setting, the length of the length and machine ID that thus can use sequence determine the length of sequential value, then can be using pre- If mode is by sequential value polishing.Wherein, predetermined manner can be the mode of the left benefit 0 of Right Aligns, be also possible to other modes, this theory Bright book is not construed as limiting this.Such as, it is assumed that the length of sequence is 12, and the length of machine ID is 3, then can determine the length of sequential value For 12-3=9, if sequential value is 1, by Right Aligns it is left mend 0 in the way of by 1 polishing of sequential value be 9 bit lengths, i.e., 000000001.In this specification one embodiment, destination server, can be to distributed system when needing to obtain unique sequence code Send the request for obtaining sequence.
S2: obtaining First ray value according to the First ray value and sequence offset amount and obtain currently used sequential value, The First ray value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is in a sequence Store the maximal sequence number generated in the period.
In this specification one embodiment, after destination server sends the request for obtaining sequence to distributed system, point Cloth system can read sequential value from storage server by sequence manager, i.e. acquisition First ray value, then by reading Sequential value generates the current sequence of service plus a sequence offset amount as the sequence being managed.
Wherein, storage server is an encapsulation to storage server operation, can be and works as persistence record The server of preamble train value.Further, storage server can carry out type selecting according to actual needs, e.g., can be mysql, The databases such as oracle are also possible to the registrar such as zookeeper, are also possible to redis cache server, can also To be file system etc., as long as storage server can be all can serve as with perdurable data, this specification is not limited this. In some embodiments, storage server may include the function of perdurable data.In other embodiments, storage server in addition to It may include the function of perdurable data, also may include other function, such as read the operating function of data.
Sequence manager is to carry out persistent storage operation to currently used sequential value.When servicing starting, sequence Manager can read the sequential value of last time record from storage server, and generate and take as sequence plus sequence offset amount The current sequence of business, i.e., currently used sequential value;In service operation, sequence manager can store week every specified sequence Currently used sequential value is persisted to storage server by the phase.
Sequence offset amount is the maximal sequence number that may be generated in a sequence storage period.Such as the sequence storage period is 60 seconds, single service support maximum TPS (1 second accessible transaction request) was 1000 (not handling more than 1000), then sequence is inclined Shifting amount should be more than or equal to 60 × 1000=60000.Specifically, for example currently used sequential value is 55, this timing column management Device has carried out persistence to it, that is to say, that recording the sequential value that last time uses is 55, and persistence is next time After 60 seconds, if having sequence to need to generate again during this period, i.e., sequential value has been likely to become 56,57,58 etc., not yet When reaching 60 seconds, service is restarted, and the perdurable data read after restarting is 55, it is clear that because 56,57,58 etc. are made With cannot use 55 as the initial sequence value after restarting, so to increase an offset on the basis of 55, this is partially Shifting amount is exactly the maximal sequence number that may occur in 60 seconds.Wherein, the sequence storage period is properly termed as sequence storage again when Limit, can be configured according to actual needs, and when setting the sequence storage period, sequence manager is just at interval of the time limit Time carries out a current sequence value persistence operation, such as is set as 1 minute, then once works as preamble every 1 minute persistence Train value.
In addition, sequence offset amount can also be greater than can in the sequence storage period in this specification one or more embodiment The maximal sequence number that can be generated is greater than the sequence number maximum value that may be consumed in a cycle, this way it is secured that opening Sequence to be used and the sequence of post-consumer do not repeat after dynamic service.
In this specification one embodiment, the acquisition First ray value, according to the First ray value and sequence offset Amount, obtains currently used sequential value, and the First ray value is the sequential value that sequence manager is read from storage server, packet It includes: judging the sequential value that whether there is persistence in the storage server, determine that there are persistences in the storage server Sequential value when, then from the storage server read last time persistence sequential value as the First ray value.Tool Body, when sequence manager reads sequential value from storage server, sequence manager judges in storage server first is No there are the sequential values of persistence, if it is present reading the sequential value conduct of last time persistence from storage server Then First ray value adds a sequence offset amount to generate working as service as the sequence being managed on the basis of the sequential value It is preceding to use sequential value.
In another embodiment of this specification, the acquisition First ray value is inclined according to the First ray value and sequence Shifting amount obtains currently used sequential value, and the First ray value is the sequential value that sequence manager is read from storage server, packet It includes: judging the sequential value that whether there is persistence in the storage server, determine that there is no lasting in the storage server When the sequential value of change, then preset value is read as the First ray value from the storage server.Specifically, in sequence management When device reads sequential value from storage server, sequence manager judges the sequence that whether there is persistence in storage server first Train value, if it does not exist, then reading default value from storage server as First ray value, then on the basis of the sequential value A upper plus sequence offset amount generates the currently used sequential value of service as the sequence being managed.Wherein, default value can be 0 Or 1, or other values, this specification do not limit this.
In another embodiment of this specification, the acquisition First ray value is inclined according to the First ray value and sequence Shifting amount obtains currently used sequential value, and the First ray value is the sequential value that sequence manager is read from storage server, packet It includes: judging the sequential value that whether there is persistence in the storage server, determine that there are persistences in the storage server Sequential value when, then from the storage server read last time persistence sequential value as the First ray value;Really When the sequential value of persistence is not present in the fixed storage server, then read described in preset value conduct from the storage server First ray value.
In above-described embodiment, by generating calling sequence manager in service in sequence, on the one hand, can guarantee well The sequence that service starting front and back generates is globally unique, i.e., the sequence generated will not be caused not unique because internal storage data loses.Separately On the one hand, the service only currently used sequence of periodically asynchronous reading is generated for sequence due to sequence manager, so The performance of formation sequence is almost no impact, it can guarantee high process performance.In another aspect, due to for Formation sequence is based entirely on the operation of memory when the service operation phase, i.e., completely using local service come formation sequence, Ke Yiyou Effect avoids the problem that single-point server causes performance bottleneck.
It should be noted that also can be applied to service operation when this specification embodiment can be applied to service starting In the process.
S4: being incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein the sequence manager Persistent storage is carried out to second sequential value every the sequence storage period.
In this specification one embodiment, sequential value is read from storage server in sequence manager, is then reading sequence After the current sequence for adding a sequence offset amount to generate service as the sequence being managed on the basis of train value, need working as preamble Required sequential value in destination server formation sequence, i.e. the second sequential value are incremented by the basis of column.Wherein, above-mentioned to be incremented by It is to carry out adding 1 on the basis of current sequence.
In this specification embodiment, in service operation, sequence manager can store the period every specified sequence will Currently used sequential value is persisted to storage server.Specifically, sequence manager can be periodic by current sequential value It stores in storage server, i.e., it is primary every the storage of specified period, and also the only storage record of record last time, history Data do not save.In this way, due to sequence manager the runtime be it is asynchronous store the sequential value that is managed, so not only for The performance that sequence generates does not have any intrusion effect, and even if service is restarted after, sequential value remains unchanged sequential value before restarting On the basis of carry out incremental, the global uniqueness of sequence after server resets can be effectively ensured.Wherein, sequence manager is every one It is exactly sequence that currently used sequential value is persisted to the designated time period being related in storage server by a designated time period Store the period.
It should be noted that is be related in above-described embodiment is asynchronous in addition to being embodied in periodical persistence sequence process In, it is also embodied in sequence and generates service functional independence in program operation.For example, sequence, which generates service, is generating this 9 sequences of 1-9 When column, when sequence manager goes to read sequence, what is read is 5, in reading process, has no effect on sequence and continues to generate, It may just read, sequence has reformed into 6, that is, reads and be independent from each other with generation.
In this specification one embodiment, it is incremented by the basis of the currently used sequential value, after obtaining the second sequential value, Further include: judge whether second sequential value is greater than predetermined sequence value, determine when being greater than predetermined sequence value, then resets described the Two sequential values, the second sequential value after being reset, wherein the sequence manager is every the sequence storage period to described The second sequential value after resetting carries out persistent storage, correspondingly, by after the resetting the second sequential value and machine identification into Row splicing, generates the globally unique sequence of the destination server.Specifically, being passed on the basis of the currently used sequential value Increase, after obtaining the second sequential value, further judge whether the sequential value accumulates default maximum-sequence-value, when accumulation to maximum sequence When train value, then rolls back to minimum value and start the cycle over use.It should be noted that sequential value accumulation is needed to default maximum-sequence-value Rolling back to minimum value and starting the cycle over is to need to guarantee by data scrubbing that the sequence generated in the business time limit is unique, maximum Sequential value and minimum value can be set according to actual scene, be not construed as limiting to this.
In another embodiment of this specification, after judging whether second sequential value is greater than predetermined sequence value, determine When second sequential value is not more than predetermined sequence value, then the second sequential value is converted to according to predetermined manner the sequence of fixed length Value, then the sequential value of fixed length is spliced, generate the globally unique sequence of the destination server with machine identification, Wherein, predetermined manner can be the mode of the left zero padding of Right Aligns, be also possible to other modes.Specifically, for example, currently used sequence Train value is 55, and presetting maximum-sequence-value is 100, and 1 is added on the basis of currently used sequential value 55, obtains the second sequential value 56, And 56 < 100, then 56 are converted into fixed length by the way of the left zero padding of Right Aligns, are then spliced with machine identification, is Destination server generates globally unique sequence, and wherein fixed length can be according to the length of actually required sequence and machine identification Length determines that if the length of sequence is 12, the length of machine identification is 3, then can determine that the fixed length of sequential value is 12-3=9.
In another embodiment of this specification, after judging whether second sequential value is greater than predetermined sequence value, determine When greater than predetermined sequence value, then second sequential value, the second sequential value after being reset are reset;Determine the second sequential value not When greater than predetermined sequence value, then the second sequential value is converted to according to predetermined manner the sequential value of fixed length.Wherein, the sequence Column manager carries out persistence to the second sequential value after the resetting/second sequential value every the sequence storage period and deposits Storage, correspondingly, converting the second sequential value after the resetting/second sequential value to according to predetermined manner the sequence of fixed length Value is spliced with machine identification, generates globally unique sequence for destination server.
S6: second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server Column.
Since sequence is made of sequential value and machine identification splicing, so, in some embodiments, obtaining sequential value Afterwards, sequential value and machine identification can be carried out being spliced into the globally unique sequence of destination server generation.Wherein, ordinary circumstance Under, in some embodiments, machine ID needs are put into front when splicing.
Due to being multiple servers in distributed system environment while running, for the sequence for generating every server It is inconsistent, so increasing machine identification.Machine identification is the unique identification of machine.
This illustrates in embodiment, because only adding 1 mode to carry out sequence accumulation based entirely on currently used sequence synchronization, It is added in sequence in addition to machine identification without any element, so the length of sequence completely can be according to the practical need of business scenario It is customized, the limitation of 19 bit lengths can be thus needed to avoid snowflake algorithm.
In this specification embodiment, when generating globally unique sequence using sequential value and machine identification splicing, can first it adopt The sequential value that fixed length is generated with predetermined manner, is then spliced with machine identification again.Wherein, predetermined manner can be the right side It is aligned the mode of left benefit 0, is also possible to other modes, this specification is not construed as limiting this.Since the length of sequence can basis Actual scene is set, and machine ID be it is known, length is it was determined that so the length of sequential value is can be according to sequence What the length of column length and machine ID determined.Specifically, such as, it is assumed that the length of sequence is 12, and machine ID is 123 (can to determine Its length is that 3), sequential value is 1, then the length of sequential value is 12-3=9, is turned sequential value by the way of the left benefit 0 of Right Aligns Turn to length be 9 000000001, due in usual situation splice when machine ID to be put into front, so machine ID (123) with The final result obtained after sequential value (000000001) splicing after conversion is 123000000001, i.e., destination server is complete Office's unique sequence code.It should be noted that this, which illustrates in embodiment that sequence generates in service, is handled using synchrolock, i.e., As long as must assure that 1 thread work when multiple thread requests, other threads are waited.
A kind of distributed sequence generating method that this specification embodiment provides, on the one hand, serviced by being generated in sequence Middle calling sequence manager reads the sequence data of persistence when servicing starting and plus offset as currently used sequence Then train value carries out being accumulated as target on the basis of currently used sequential value in the service operation phase using in sequence process Sequence the current sequence value in service is generated using sequence manager while server generates ultimate sequence periodically to deposit Storage server is stored up, in this way, can effectively solve the problems, such as that memory storage sequence is lost after server resets, guarantees service starting The sequence that front and back generates is globally unique, to improve the efficiency of formation sequence.On the other hand, in the service operation phase, pass through Using local service come formation sequence, it is possible to prevente effectively from the problem of single-point server becomes performance bottleneck, to guarantee high Process performance.In another aspect, being removed since the mode being only incremented by based entirely on currently used sequence synchronization carries out sequence accumulation It is added in sequence outside machine identification without any element, so the length of sequence can be actually needed completely according to business scenario It is customized, the sequence generated can thus be made to adapt to different distributed scenes.Therefore, each implementation of this specification is utilized Example, can generate globally unique serial ID according to the usage scenario of distributed sequence, thus guaranteeing in distributed system The efficiency of formation sequence is effectively improved while high process performance.
In order to further verify the practicability and feasibility of this method, this specification additionally provided using above scheme One specific example, as shown in figure 3, Fig. 3 is a specific embodiment of the distributed sequence generating method that this specification provides Flow diagram.The specific implementation steps are as follows:
(1) request of formation sequence is received.
(2) current sequence value is added 1, as new current sequence value.
When servicing starting, sequence manager reads sequential value from storage server, then on the basis for reading sequential value It is upper to be assigned to sequence generation service plus sequence offset amount, that is, it is used as current sequence value, subsequent sequence generates then in this sequence base On plinth plus 1 as new current sequence value.Wherein, when there are when sequential value, then read last time to record in storage server Sequential value, in the absence of, then be defaulted as 0.Specifically, as shown in figure 4, Fig. 4 is that the distributed sequence that this specification provides is raw At flow diagram of the sequence manager in a specific embodiment of method when servicing starting.
(3) judge whether new current sequence value is greater than preset maximum value.
If new current sequence value is greater than preset maximum value, (4) are thened follow the steps;If new current sequence value is no more than pre- If maximum value, (5) are thened follow the steps.Wherein, preset maximum value is according to the preset value of actual scene.
(4) it is 0 (or 1) by new current sequence value rollback, and executes step (5)-step (7).
(5) according to Right Aligns 0 mode of left benefit, new current sequence value is generated as to the sequential value of designated length.
(6) globally unique sequence is generated using machine identification+fixed length sequential value connecting method.
The sequential value of the designated length generated using machine identification and step (5) is carried out splicing and generates globally unique sequence.
(7) spliced sequence is returned.
It should be noted that, in the service operation phase, sequence manager can be stored every specified sequence in above-described embodiment Current sequence value is persisted to storage server by the period.Specifically, service operation phase sequence manager work step is as follows: 1. Obtain the current sequence value that the sequence being managed generates service;2. the current sequence value that will acquire is persisted to storage server; 3. being spaced specified sequence stores the period, continues to execute the and 1. walk.As shown in figure 5, Fig. 5 is the distributed sequence that this specification provides Flow diagram of the sequence manager in the service operation phase in one specific embodiment of generation method.
The result shows that implementing the scheme provided using the application, can be distributed according to the usage scenario of distributed sequence Globally unique serial ID is generated in formula system, so as to effectively improve formation sequence while guaranteeing high process performance Efficiency.
Various embodiments are described in a progressive manner for the above method in this specification, identical between each embodiment Similar part is participated in mutually, and each embodiment focuses on the differences from other embodiments.Correlation Locate the part explanation of mothed of participating embodiment.
Based on a kind of distributed sequence generating method described above, this specification one or more embodiment also provides one The distributed sequence generator of kind.The device may include the system (packet for having used this specification embodiment the method Include distributed system), software (application), module, component, server, client etc. and combine the necessary device for implementing hardware. Device such as the following examples institute based on same innovation thinking, in one or more embodiments of this specification embodiment offer It states.Since the implementation that device solves the problems, such as is similar to method, the implementation of the specific device of this specification embodiment can With referring to the implementation of preceding method, overlaps will not be repeated.Used below, term " unit " or " module " can be real The combination of the software and/or hardware of existing predetermined function.Although device described in following embodiment is preferably realized with software, But the realization of the combination of hardware or software and hardware is also that may and be contemplated.
Specifically, Fig. 6 is a kind of module knot of the one embodiment for distributed sequence generator that this specification provides Structure schematic diagram, as shown in fig. 6, a kind of distributed sequence generator that this specification provides may include: receiving module 120, First obtains module 122, and second obtains module 124, sequence generating module 126.
Receiving module 120 can be used for receiving the request that destination server obtains sequence;
First obtains module 122, can be used for obtaining First ray value, according to the First ray value and sequence offset Amount, obtains currently used sequential value, the First ray value is the sequential value that sequence manager is read from storage server, described Sequence offset amount is the maximal sequence number generated within a sequence storage period;
Second obtains module 124, can be used for being incremented by the basis of the currently used sequential value, obtains the second sequence Value, wherein the sequence manager carries out persistent storage to second sequential value every the sequence storage period;
Sequence generating module 126 can be used for splicing second sequential value with machine identification, generate the mesh Mark the globally unique sequence of server.
In another embodiment of described device, described first obtains module 122, may include:
First judging unit can be used for judging whether there is in the storage server sequential value of persistence;
First reading unit is determined in the storage server there are when the sequential value of persistence, then from institute It states storage server and reads the sequential value of last time persistence as the First ray value.
In another embodiment of described device, described first obtains module 122, can also include:
Second reading unit, be determined in the storage server be not present persistence sequential value when, then from The storage server reads preset value as the First ray value.
It is described to be incremented by the basis of the currently used sequential value in another embodiment of described device, obtain second After sequential value, can also include:
Second judgment unit, can be used for judging whether second sequential value is greater than predetermined sequence value;
Third obtaining unit then resets second sequential value, is weighed when being determined for being greater than predetermined sequence value The second sequential value postponed, wherein the sequence manager is every the sequence storage period to the second sequence after the resetting Train value carries out persistent storage;
Correspondingly, the second sequential value after the resetting is spliced with machine identification, the destination server is generated Globally unique sequence.
A kind of distributed sequence generator that this specification embodiment provides, on the one hand, serviced by being generated in sequence Middle calling sequence manager, the sequence currently used for intermittently persistence, and persistence is read when servicing starting Sequence data simultaneously adds offset as currently used sequential value, can effectively solve servicing using memory storage sequence Restart the problem of rear sequence is lost, the sequence for guaranteeing that service starting front and back generates is globally unique, to improve formation sequence Efficiency.On the other hand, since service operation phase time series uses local service to generate completely, it is possible to prevente effectively from single-point takes The problem of device be engaged in as performance bottleneck, to guarantee high process performance.In another aspect, due to only based entirely on currently making Sequence accumulation is carried out with the mode that sequence synchronization is incremented by, is added in sequence in addition to machine identification without any element, so sequence The length of column can be actually needed according to business scenario be customized completely, and the sequence generated can be made to adapt to different points in this way Cloth scene.Therefore, using each embodiment of this specification, can be in distribution according to the usage scenario of distributed sequence Globally unique serial ID is generated in system, to effectively improve the efficiency of formation sequence while guaranteeing high process performance.
It should be noted that device described above can also include other embodiment party according to the description of embodiment of the method Formula, concrete implementation mode are referred to the description of related method embodiment, do not repeat one by one herein.
This specification embodiment also provides a kind of distributed sequence generating device, including processor and is used for storage processor The memory of executable instruction, when described instruction is executed by the processor realize the following steps are included:
Receive the request that destination server obtains sequence;
It obtains First ray value and currently used sequential value is obtained according to the First ray value and sequence offset amount, it is described First ray value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is stored in a sequence The maximal sequence number generated in period;
On the basis of the currently used sequential value be incremented by, obtain the second sequential value, wherein the sequence manager every The sequence storage period carries out persistent storage to second sequential value;
Second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server.
It should be noted that equipment described above can also include other embodiment party according to the description of embodiment of the method Formula.Concrete implementation mode is referred to the description of related method embodiment, does not repeat one by one herein.
This specification embodiment also provides a kind of distributed sequence generation system, including at least one processor and storage The memory of computer executable instructions, the processor realize above-mentioned any one or multiple implementations when executing described instruction The step of method described in example, for example, receive the request that destination server obtains sequence;First ray value is obtained, according to The First ray value and sequence offset amount, obtain currently used sequential value, and the First ray value is sequence manager from depositing The sequential value that server is read is stored up, the sequence offset amount is the maximal sequence number generated within a sequence storage period;? It is incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein the sequence manager is deposited every the sequence The period is stored up to second sequential value progress persistent storage;Second sequential value is spliced with machine identification, is generated The globally unique sequence of the destination server.The system can be individual server, also may include having used this The server cluster of one or more the methods of specification or one or more embodiment devices, system (including distribution System), software (application), practical operation device, logic gates device, quantum computer etc. and combine necessary implementation hardware Terminal installation.
Embodiment of the method provided by this specification embodiment can mobile terminal, terminal, server or It is executed in similar arithmetic unit.For running on the server, Fig. 7 is that a kind of distributed sequence that this specification provides is raw At the hardware block diagram of one embodiment of server, which can be the generation of the distributed sequence in above-described embodiment Device or distributed sequence generation system.As shown in fig. 7, server 10 may include one or more (only showing one in figure) (processor 100 can include but is not limited to the processing dress of Micro-processor MCV or programmable logic device FPGA etc. to processor 100 Set), memory 200 for storing data and the transmission module 300 for communication function.Those of ordinary skill in the art It is appreciated that structure shown in Fig. 7 is only to illustrate, the structure of above-mentioned electronic device is not caused to limit.For example, server 10 may also include the more or less component than shown in Fig. 7, such as can also include other processing hardware, such as database Or multi-level buffer, GPU, or with the configuration different from shown in Fig. 7.
Memory 200 can be used for storing the software program and module of application software, such as point in this specification embodiment Corresponding program instruction/the module of cloth sequence generating method, the software that processor 100 is stored in memory 200 by operation Program and module, thereby executing various function application and data processing.Memory 200 may include high speed random access memory, It may also include nonvolatile memory, as one or more magnetic storage device, flash memory or other nonvolatile solid states are deposited Reservoir.In some instances, memory 200 can further comprise the memory remotely located relative to processor 100, these are remote Journey memory can pass through network connection to terminal.The example of above-mentioned network includes but is not limited to internet, in enterprise Portion's net, local area network, mobile radio communication and combinations thereof.
Transmission module 300 is used to that data to be received or sent via a network.Above-mentioned network specific example may include The wireless network that the communication providers of terminal provide.In an example, transmission module 300 includes a Network adaptation Device (Network Interface Controller, NIC), can be connected by base station with other network equipments so as to it is mutual Networking is communicated.In an example, transmission module 300 can be radio frequency (Radio Frequency, RF) module, use In wirelessly being communicated with internet.
It is above-mentioned that this specification specific embodiment is described.Other embodiments are in the scope of the appended claims It is interior.In some cases, the movement recorded in detail in the claims or step can be come according to the sequence being different from embodiment It executes and desired result still may be implemented.In addition, process depicted in the drawing not necessarily require show it is specific suitable Sequence or consecutive order are just able to achieve desired result.In some embodiments, multitasking and parallel processing be also can With or may be advantageous.
Method or apparatus described in above-described embodiment that this specification provides can realize that business is patrolled by computer program It collects and records on a storage medium, the storage medium can be read and be executed with computer, realize this specification embodiment institute The effect of description scheme.
The storage medium may include the physical unit for storing information, usually by after information digitalization again with benefit The media of the modes such as electricity consumption, magnetic or optics are stored.It may include: that letter is stored in the way of electric energy that the storage medium, which has, The device of breath such as, various memory, such as RAM, ROM;The device of information is stored in the way of magnetic energy such as, hard disk, floppy disk, magnetic Band, core memory, magnetic bubble memory, USB flash disk;Using optical mode storage information device such as, CD or DVD.Certainly, there are also it Readable storage medium storing program for executing of his mode, such as quantum memory, graphene memory etc..
The above-mentioned distributed sequence generating method or device that this specification embodiment provides can be in a computer by handling Device executes corresponding program instruction to realize, such as using the c++ language of windows operating system in the realization of the end PC, Linux system It realizes or other is for example realized using android, iOS system programming language in intelligent terminal, and be based on quantum calculation Processing logic realization of machine etc..
It should be noted that specification device described above, computer storage medium, system are implemented according to correlation technique The description of example can also include other embodiments, and concrete implementation mode is referred to the description of corresponding method embodiment, It does not repeat one by one herein.
Various embodiments are described in a progressive manner in the application, same and similar part between each embodiment It may refer to each other, each embodiment focuses on the differences from other embodiments.Especially for hardware+journey For sequence class embodiment, since it is substantially similar to the method embodiment, so being described relatively simple, related place is referring to method The part of embodiment illustrates.
This specification embodiment is not limited to meet industry communication standard, standard computer data processing sum number According to situation described in storage rule or this specification one or more embodiment.The right way of conduct is made in certain professional standards or use by oneself In formula or the practice processes of embodiment description embodiment modified slightly also may be implemented above-described embodiment it is identical, it is equivalent or The implementation result being anticipated that after close or deformation.Using these modifications or deformed data acquisition, storage, judgement, processing side The embodiment of the acquisitions such as formula still may belong within the scope of the optional embodiment of this specification embodiment.
In the 1990s, the improvement of a technology can be distinguished clearly be on hardware improvement (for example, Improvement to circuit structures such as diode, transistor, switches) or software on improvement (improvement for method flow).So And with the development of technology, the improvement of current many method flows can be considered as directly improving for hardware circuit. Designer nearly all obtains corresponding hardware circuit by the way that improved method flow to be programmed into hardware circuit.Cause This, it cannot be said that the improvement of a method flow cannot be realized with hardware entities module.For example, programmable logic device (Programmable Logic Device, PLD) (such as field programmable gate array (Field Programmable Gate Array, FPGA)) it is exactly such a integrated circuit, logic function determines device programming by user.By designer Voluntarily programming comes a digital display circuit " integrated " on a piece of PLD, designs and makes without asking chip maker Dedicated IC chip.Moreover, nowadays, substitution manually makes IC chip, this programming is also used instead mostly " is patrolled Volume compiler (logic compiler) " software realizes that software compiler used is similar when it writes with program development, And the source code before compiling also write by handy specific programming language, this is referred to as hardware description language (Hardware Description Language, HDL), and HDL is also not only a kind of, but there are many kind, such as ABEL (Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL (Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language) etc., VHDL (Very-High-Speed is most generally used at present Integrated Circuit Hardware Description Language) and Verilog.Those skilled in the art also answer This understands, it is only necessary to method flow slightly programming in logic and is programmed into integrated circuit with above-mentioned several hardware description languages, The hardware circuit for realizing the logical method process can be readily available.
Controller can be implemented in any suitable manner, for example, controller can take such as microprocessor or processing The computer for the computer readable program code (such as software or firmware) that device and storage can be executed by (micro-) processor can Read medium, logic gate, switch, specific integrated circuit (Application Specific Integrated Circuit, ASIC), the form of programmable logic controller (PLC) and insertion microcontroller, the example of controller includes but is not limited to following microcontroller Device: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320 are deposited Memory controller is also implemented as a part of the control logic of memory.It is also known in the art that in addition to Pure computer readable program code mode is realized other than controller, can be made completely by the way that method and step is carried out programming in logic Controller is obtained to come in fact in the form of logic gate, switch, specific integrated circuit, programmable logic controller (PLC) and insertion microcontroller etc. Existing identical function.Therefore this controller is considered a kind of hardware component, and to including for realizing various in it The device of function can also be considered as the structure in hardware component.Or even, it can will be regarded for realizing the device of various functions For either the software module of implementation method can be the structure in hardware component again.
System, device, module or the unit that above-described embodiment illustrates can specifically realize by computer chip or entity, Or it is realized by the product with certain function.It is a kind of typically to realize that equipment is computer.Specifically, computer for example may be used Think personal computer, laptop computer, vehicle-mounted human-computer interaction device, cellular phone, camera phone, smart phone, individual Digital assistants, media player, navigation equipment, electronic mail equipment, game console, tablet computer, wearable device or The combination of any equipment in these equipment of person.
Although this specification one or more embodiment provides the method operating procedure as described in embodiment or flow chart, It but may include more or less operating procedure based on conventional or without creativeness means.The step of being enumerated in embodiment Sequence is only one of numerous step execution sequence mode, does not represent and unique executes sequence.Device in practice or When end product executes, can be executed according to embodiment or the execution of method shown in the drawings sequence or parallel (such as it is parallel The environment of processor or multiple threads, even distributed data processing environment).The terms "include", "comprise" or its Any other variant is intended to non-exclusive inclusion so that include the process, methods of a series of elements, product or Equipment not only includes those elements, but also including other elements that are not explicitly listed, or further include for this process, Method, product or the intrinsic element of equipment.In the absence of more restrictions, being not precluded is including the element There is also other identical or equivalent elements in process, method, product or equipment.The first, the second equal words are used to indicate name Claim, and does not indicate any particular order.
For convenience of description, it is divided into various modules when description apparatus above with function to describe respectively.Certainly, implementing this The function of each module can be realized in the same or multiple software and or hardware when specification one or more, it can also be with The module for realizing same function is realized by the combination of multiple submodule or subelement etc..Installation practice described above is only It is only illustrative, for example, in addition the division of the unit, only a kind of logical function partition can have in actual implementation Division mode, such as multiple units or components can be combined or can be integrated into another system or some features can be with Ignore, or does not execute.Another point, shown or discussed mutual coupling, direct-coupling or communication connection can be logical Some interfaces are crossed, the indirect coupling or communication connection of device or unit can be electrical property, mechanical or other forms.
The present invention be referring to according to the method for the embodiment of the present invention, the process of device (system) and computer program product Figure and/or block diagram describe.It should be understood that every one stream in flowchart and/or the block diagram can be realized by computer program instructions The combination of process and/or box in journey and/or box and flowchart and/or the block diagram.It can provide these computer programs Instruct the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates, Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one The step of function of being specified in a box or multiple boxes.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data. The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM), Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage, graphene stores or other Magnetic storage device or any other non-transmission medium, can be used for storage can be accessed by a computing device information.According to herein In define, computer-readable medium does not include temporary computer readable media (transitory media), such as the data of modulation Signal and carrier wave.
It will be understood by those skilled in the art that this specification one or more embodiment can provide as method, system or calculating Machine program product.Therefore, this specification one or more embodiment can be used complete hardware embodiment, complete software embodiment or The form of embodiment combining software and hardware aspects.Moreover, this specification one or more embodiment can be used at one or It is multiple wherein include computer usable program code computer-usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) on the form of computer program product implemented.
All the embodiments in this specification are described in a progressive manner, same and similar portion between each embodiment Dividing may refer to each other, and each embodiment focuses on the differences from other embodiments.Especially for system reality For applying example, since it is substantially similar to the method embodiment, so being described relatively simple, related place is referring to embodiment of the method Part explanation.In the description of this specification, reference term " one embodiment ", " some embodiments ", " example ", The description of " specific example " or " some examples " etc. means specific features described in conjunction with this embodiment or example, structure, material Or feature is contained at least one embodiment or example of this specification.In the present specification, to the signal of above-mentioned term Property statement be necessarily directed to identical embodiment or example.Moreover, particular features, structures, materials, or characteristics described It may be combined in any suitable manner in any one or more of the embodiments or examples.In addition, without conflicting with each other, this The technical staff in field can be by the spy of different embodiments or examples described in this specification and different embodiments or examples Sign is combined.
The foregoing is merely the embodiments of this specification one or more embodiment, are not limited to book explanation Book one or more embodiment.To those skilled in the art, this specification one or more embodiment can have various Change and variation.All any modification, equivalent replacement, improvement and so within the spirit and principles of the present application should all include Within scope of the claims.

Claims (11)

1. a kind of distribution sequence generating method characterized by comprising
Receive the request that destination server obtains sequence;
First ray value is obtained, according to the First ray value and sequence offset amount, obtains currently used sequential value, described first Sequential value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is to store the period in a sequence The maximal sequence number of interior generation;
It is incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein the sequence manager is every described Sequence stores the period to second sequential value progress persistent storage;
Second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server.
2. a kind of distributed sequence generating method as described in claim 1, which is characterized in that the acquisition First ray value, According to the First ray value and sequence offset amount, currently used sequential value is obtained, the First ray value is sequence manager The sequential value read from storage server, comprising:
Judge the sequential value that whether there is persistence in the storage server;
It determines in the storage server there are when the sequential value of persistence, then reads last time from the storage server and hold The sequential value changed long is as the First ray value.
3. a kind of distributed sequence generating method as claimed in claim 2, which is characterized in that further include:
When determining the sequential value that persistence is not present in the storage server, then preset value is read from the storage server and made For the First ray value.
4. a kind of distributed sequence generating method as described in claim 1, which is characterized in that described in the currently used sequence It is incremented by the basis of train value, after obtaining the second sequential value, further includes:
Judge whether second sequential value is greater than predetermined sequence value;
When determining greater than predetermined sequence value, then second sequential value, the second sequential value after being reset, wherein institute are reset It states sequence manager and persistent storage is carried out to the second sequential value after the resetting every the sequence storage period;
Correspondingly, the second sequential value after the resetting is spliced with machine identification, the complete of the destination server is generated Office's unique sequence code.
5. a kind of distributed sequence generating method as described in claim 1, which is characterized in that the storage server is at least wrapped Include the function of perdurable data.
6. a kind of distribution sequence generator characterized by comprising
Receiving module obtains the request of sequence for receiving destination server;
First obtains module, and for obtaining First ray value, according to the First ray value and sequence offset amount, acquisition currently makes With sequential value, the First ray value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is The maximal sequence number generated within a sequence storage period;
Second obtains module, for being incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein described Sequence manager carries out persistent storage to second sequential value every the sequence storage period;
Sequence generating module generates the destination server for splicing second sequential value with machine identification Globally unique sequence.
7. a kind of distributed sequence generator as claimed in claim 6, which is characterized in that described first obtains module, packet It includes:
First judging unit, the sequential value for judging to whether there is persistence in the storage server;
First reading unit then takes from the storage for determining in the storage server there are when the sequential value of persistence The sequential value for device reading last time persistence of being engaged in is as the First ray value.
8. a kind of distributed sequence generator as claimed in claim 7, which is characterized in that further include:
Second reading unit, when for determining the sequential value that persistence is not present in the storage server, then from the storage Server reads preset value as the First ray value.
9. a kind of distributed sequence generator as claimed in claim 6, which is characterized in that described in the currently used sequence It is incremented by the basis of train value, after obtaining the second sequential value, further includes:
Second judgment unit, for judging whether second sequential value is greater than predetermined sequence value;
Third obtaining unit then resets second sequential value when being greater than predetermined sequence value for determining, and the after being reset Two sequential values, wherein the sequence manager carries out the second sequential value after the resetting every the sequence storage period Persistent storage;
Correspondingly, the second sequential value after the resetting is spliced with machine identification, the complete of the destination server is generated Office's unique sequence code.
10. a kind of distribution sequence generating device, which is characterized in that including processor and be used for storage processor executable instruction Memory, when described instruction is executed by the processor realize the following steps are included:
Receive the request that destination server obtains sequence;
First ray value is obtained, according to the First ray value and sequence offset amount, obtains currently used sequential value, described first Sequential value is the sequential value that sequence manager is read from storage server, and the sequence offset amount is to store the period in a sequence The maximal sequence number of interior generation;
It is incremented by the basis of the currently used sequential value, obtains the second sequential value, wherein the sequence manager is every described Sequence stores the period to second sequential value progress persistent storage;
Second sequential value is spliced with machine identification, generates the globally unique sequence of the destination server.
11. a kind of distribution sequence generation system, which is characterized in that can be held including at least one processor and storage computer The memory of row instruction, the processor realize the step of any one of claim 1-5 the method when executing described instruction Suddenly.
CN201910367543.XA 2019-05-05 2019-05-05 Distributed sequence generation method, device and system Active CN110162573B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910367543.XA CN110162573B (en) 2019-05-05 2019-05-05 Distributed sequence generation method, device and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910367543.XA CN110162573B (en) 2019-05-05 2019-05-05 Distributed sequence generation method, device and system

Publications (2)

Publication Number Publication Date
CN110162573A true CN110162573A (en) 2019-08-23
CN110162573B CN110162573B (en) 2021-04-30

Family

ID=67633418

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910367543.XA Active CN110162573B (en) 2019-05-05 2019-05-05 Distributed sequence generation method, device and system

Country Status (1)

Country Link
CN (1) CN110162573B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111523002A (en) * 2020-04-23 2020-08-11 中国农业银行股份有限公司 Main key distribution method, device, server and storage medium
CN112402983A (en) * 2020-08-03 2021-02-26 上海幻电信息科技有限公司 Game result verification method and system
CN113297327A (en) * 2021-05-24 2021-08-24 建信金融科技有限责任公司 System and method for generating distributed ID
WO2022002044A1 (en) * 2020-06-29 2022-01-06 中兴通讯股份有限公司 Method and apparatus for processing distributed database, and network device and computer-readable storage medium

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20030030514A (en) * 2001-10-11 2003-04-18 한국전자통신연구원 A method for optimizing the post-processing of sub-sequence matching in time-series databases
CN101174857A (en) * 2006-09-30 2008-05-07 华为技术有限公司 Sequence distribution method, sequence processing method and device in communication system
CN101963944A (en) * 2010-09-30 2011-02-02 用友软件股份有限公司 Object storage method and system
CN106407050A (en) * 2016-10-20 2017-02-15 厦门科华恒盛股份有限公司 Data storage method
CN106549990A (en) * 2015-09-18 2017-03-29 阿里巴巴集团控股有限公司 A kind of processing method and system of distributed data
CN106570097A (en) * 2016-10-31 2017-04-19 华为技术有限公司 Sequence generating method and device
CN106899654A (en) * 2016-08-10 2017-06-27 阿里巴巴集团控股有限公司 A kind of sequence value generation method, apparatus and system
CN106940712A (en) * 2017-03-01 2017-07-11 星环信息科技(上海)有限公司 Sequence generating method and equipment
CN107038191A (en) * 2016-11-15 2017-08-11 阿里巴巴集团控股有限公司 A kind of data processing method of database sequence, device and server
CN108959386A (en) * 2018-05-31 2018-12-07 深圳壹账通智能科技有限公司 Distributed globally unique ID generation method, device, equipment and storage medium
CN109241447A (en) * 2018-10-29 2019-01-18 金蝶软件(中国)有限公司 A kind of method, terminal and the server of inquiring document data

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20030030514A (en) * 2001-10-11 2003-04-18 한국전자통신연구원 A method for optimizing the post-processing of sub-sequence matching in time-series databases
CN101174857A (en) * 2006-09-30 2008-05-07 华为技术有限公司 Sequence distribution method, sequence processing method and device in communication system
CN101963944A (en) * 2010-09-30 2011-02-02 用友软件股份有限公司 Object storage method and system
CN106549990A (en) * 2015-09-18 2017-03-29 阿里巴巴集团控股有限公司 A kind of processing method and system of distributed data
CN106899654A (en) * 2016-08-10 2017-06-27 阿里巴巴集团控股有限公司 A kind of sequence value generation method, apparatus and system
CN106407050A (en) * 2016-10-20 2017-02-15 厦门科华恒盛股份有限公司 Data storage method
CN106570097A (en) * 2016-10-31 2017-04-19 华为技术有限公司 Sequence generating method and device
CN107038191A (en) * 2016-11-15 2017-08-11 阿里巴巴集团控股有限公司 A kind of data processing method of database sequence, device and server
CN106940712A (en) * 2017-03-01 2017-07-11 星环信息科技(上海)有限公司 Sequence generating method and equipment
CN108959386A (en) * 2018-05-31 2018-12-07 深圳壹账通智能科技有限公司 Distributed globally unique ID generation method, device, equipment and storage medium
CN109241447A (en) * 2018-10-29 2019-01-18 金蝶软件(中国)有限公司 A kind of method, terminal and the server of inquiring document data

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
刘家志: "基于Hadoop架构和多级索引技术的医学影像存储检索系统研究", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111523002A (en) * 2020-04-23 2020-08-11 中国农业银行股份有限公司 Main key distribution method, device, server and storage medium
CN111523002B (en) * 2020-04-23 2023-06-09 中国农业银行股份有限公司 Main key distribution method, device, server and storage medium
WO2022002044A1 (en) * 2020-06-29 2022-01-06 中兴通讯股份有限公司 Method and apparatus for processing distributed database, and network device and computer-readable storage medium
CN112402983A (en) * 2020-08-03 2021-02-26 上海幻电信息科技有限公司 Game result verification method and system
CN113297327A (en) * 2021-05-24 2021-08-24 建信金融科技有限责任公司 System and method for generating distributed ID

Also Published As

Publication number Publication date
CN110162573B (en) 2021-04-30

Similar Documents

Publication Publication Date Title
CN110162573A (en) A kind of distribution sequence generating method, apparatus and system
CN110096528A (en) The method, apparatus and system of formation sequence in a kind of distributed system
CN109002362A (en) A kind of method of servicing, device, system and electronic equipment
CN110401700A (en) Model loading method and system, control node and execution node
CN110989939A (en) Data cache processing method, device and equipment and cache component
CN109947643B (en) A/B test-based experimental scheme configuration method, device and equipment
CN108959341A (en) A kind of method, device and equipment that data are synchronous
CN109240848A (en) A kind of data object tag generation method and device
CN110244957A (en) A kind of resource data updating method, apparatus and system
CN110134735A (en) The storage method and device of distributed transaction log
CN109936642A (en) The method, apparatus and system of machine ID are generated in a kind of distributed system
CN110659137A (en) Processing resource allocation method and system for offline tasks
CN109002357A (en) Resource allocation methods, device and Internet of things system
CN111402058B (en) Data processing method, device, equipment and medium
CN109739627A (en) Dispatching method, electronic equipment and the medium of task
CN110442480A (en) A kind of mirror image data method for cleaning, apparatus and system
CN116305298A (en) Method and device for managing computing power resources, storage medium and electronic equipment
CN116932175B (en) Heterogeneous chip task scheduling method and device based on sequence generation
CN116107728B (en) Task execution method and device, storage medium and electronic equipment
CN110427426A (en) A kind of data synchronizing processing method and device
CN112328289B (en) Firmware upgrading method, device, equipment and storage medium
CN109063088A (en) The generation method and device of sequence number
CN109144600A (en) A kind of operation method of application program, equipment and computer-readable medium
CN108399089A (en) The display methods and device of view interface
CN108769152B (en) Service refresh policy registration method, service refresh request method, device and equipment

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
GR01 Patent grant
GR01 Patent grant