Summary of the invention
The main purpose of the present invention is to provide a kind of distributed generation method, device and computer storages by stages number to be situated between
Matter, it is intended to solve traditional in payment transaction system, using UUID as bill, number there are dangerous and inconvenient by stages
The technical issues of.
To achieve the above object, the present invention provides a kind of distributed generation method by stages number, it is described it is distributed by stages number
Generation method comprising steps of
Receive obtain request by stages number when, according to the service identification that the request carries obtain it is corresponding by stages number
Buffer area, wherein multiple number buffer areas by stages are arranged to each industry of correspondence to distinguish different business in the service identification
Business;
Whether the judgement number buffer area by stages is empty;
When number buffer area by stages is empty, described in the database refresh by stages the corresponding data of number buffer area to generate
By stages number;
By number preservation by stages to number buffer area by stages.
Preferably, the step of corresponding data of number buffer area are by stages to generate by stages number described in database refresh packet
It includes:
Lock database simultaneously updates the currently stored corresponding ID of number buffer area by stages of the database, wherein institute
The quantity by stages number for stating that ID indicates that presently described number buffer area by stages generated;
It obtains updated ID and discharges the locking of the database;
Digital encryption is carried out to the numerical value between the ID for updating front and back, wherein the numerical value between ID before and after the update
It does not include the ID before updating, including updated ID;
Using the encrypted numerical value as by stages number.
Preferably, the lock database and to update the currently stored number buffer area by stages of the database corresponding
The step of ID includes:
Lock database obtains the currently stored corresponding ID of number buffer area by stages of the database and present count
Value, wherein the default value is to refresh the number amount by stages that number buffer area generates by stages every time;
Target id is calculated according to the ID and default value of acquisition;
Using Target id update prestore described in the corresponding ID of number buffer area by stages.
Preferably, the distributed generation method by stages number further include:
It is described number buffer area is not sky by stages when, obtained from number buffer area by stages by stages number.
Preferably, the distributed generation method by stages number further include:
When number buffer area by stages is empty, asking on the corresponding same node of number buffer area by stages is obtained
It asks, wherein the corresponding business of number buffer area by stages uses distributed deployment, there is multiple operation nodes;
Obtain the single request thread that synchrolock is taken in the request;
Judge whether the corresponding number buffer area by stages of the single request thread is empty;
If number buffer area by stages is sky, the corresponding number of number buffer area by stages described in the database refresh is executed
It generates accordingly by stages number, and the step of described number saving by stages to number buffer area by stages;
If number buffer area by stages be not it is empty, execute the step obtained from number buffer area by stages by stages number
Suddenly.
Preferably, the distributed generation method by stages number further include:
The synchrolock of the single request thread is discharged, so that other threads of the request obtain the synchronization
Lock.
In addition, to achieve the above object, the present invention also provides a kind of distributed generating means by stages number, the distributions
Generating means by stages number include memory, processor and are stored on the memory and can run on the processor
Computer program realizes generation by stages number as described above distributed when the computer program is executed by the processor
The step of method.
In addition, to achieve the above object, the present invention also provides a kind of computer storage medium, the computer storage medium
On be stored with distributed generation program by stages number, reality when the distributed generation program by stages number is executed by the processor
The step of generation method by stages number now as described above distributed.
Distributed generation method, device and computer storage medium by stages number proposed by the present invention, obtains receiving
When request by stages number, corresponding number buffer area by stages is obtained according to the service identification that the request carries, wherein the business
To distinguish different business multiple number buffer areas by stages are arranged to each business of correspondence, then judgement is described by stages in mark
Number buffer area whether be it is empty, when number buffer area by stages is empty, number buffer area is corresponding by stages described in the database refresh
Data described number will be saved to number buffer area by stages by stages with generating by stages number, realize the generation of safe and convenient by stages
Number for docking system obtain.
Specific embodiment
It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, it is not intended to limit the present invention.
The primary solutions of the embodiment of the present invention are:
Receive obtain request by stages number when, according to the service identification that the request carries obtain it is corresponding by stages number
Buffer area, wherein multiple number buffer areas by stages are arranged to each industry of correspondence to distinguish different business in the service identification
Business;
Whether the judgement number buffer area by stages is empty;
When number buffer area by stages is empty, described in the database refresh by stages the corresponding data of number buffer area to generate
By stages number;
By number preservation by stages to number buffer area by stages.
Due in the prior art, use UUID as by stages number, there is technical issues that it is dangerous, be not easy to.
The present invention provides a solution, receive obtain request by stages number when, carried according to the request
Service identification obtains corresponding number buffer area by stages, wherein the service identification is arranged multiple points to distinguish different business
Issue buffer area is to each business of correspondence, and then whether the judgement number buffer area by stages is sky, in number caching by stages
When area is empty, the corresponding data of number buffer area and described number will be protected by stages by stages with generating by stages number described in the database refresh
It deposits to number buffer area by stages, realizes the generation of safe and convenient by stages number so that the system of docking obtains.
As shown in Figure 1, Fig. 1 is the terminal structure schematic diagram for the hardware running environment that the embodiment of the present invention is related to.
The terminal of that embodiment of the invention is PC or server.
As shown in Figure 1, the terminal may include: processor 1001, such as CPU, network interface 1004, user interface
1003, memory 1005 and communication bus 1002.Wherein, communication bus 1002 is logical for realizing the connection between these components
Letter.User interface 1003 may include display screen (Display), input unit such as keyboard (Keyboard), and optional user connects
Mouth 1003 can also include standard wireline interface and wireless interface.Network interface 1004 optionally may include the wired of standard
Interface, wireless interface (such as WI-FI interface).Memory 1005 can be high speed RAM memory, be also possible to stable memory
(non-volatile memory), such as magnetic disk storage.Memory 1005 optionally can also be independently of aforementioned processor
1001 storage device.
It will be understood by those skilled in the art that the restriction of the not structure paired terminal of terminal structure shown in Fig. 1, can wrap
It includes than illustrating more or fewer components, perhaps combines certain components or different component layouts.
As shown in Figure 1, as may include that operating system, network are logical in a kind of memory 1005 of computer storage medium
Believe module, Subscriber Interface Module SIM and distributed generation program by stages number.
In terminal shown in Fig. 1, network interface 1004 is mainly used for connecting background server, carries out with background server
Data communication;User interface 1003 is mainly used for connecting client (user terminal), carries out data communication with client;And processor
1001 can be used for calling the distributed generation program by stages number stored in memory 1005, and execute following operation:
Receive obtain request by stages number when, according to the service identification that the request carries obtain it is corresponding by stages number
Buffer area, wherein multiple number buffer areas by stages are arranged to each industry of correspondence to distinguish different business in the service identification
Business;
Whether the judgement number buffer area by stages is empty;
When number buffer area by stages is empty, described in the database refresh by stages the corresponding data of number buffer area to generate
By stages number;
By number preservation by stages to number buffer area by stages.
Further, processor 1001 can call the distributed generation program by stages number stored in memory 1005,
Also execute following operation:
Lock database simultaneously updates the currently stored corresponding ID of number buffer area by stages of the database, wherein institute
The quantity by stages number for stating that ID indicates that presently described number buffer area by stages generated;
It obtains updated ID and discharges the locking of the database;
Digital encryption is carried out to the numerical value between the ID for updating front and back, wherein the numerical value between ID before and after the update
It does not include the ID before updating, including updated ID;
Using the encrypted numerical value as by stages number.
Further, processor 1001 can call the distributed generation program by stages number stored in memory 1005,
Also execute following operation:
Lock database obtains the currently stored corresponding ID of number buffer area by stages of the database and present count
Value, wherein the default value is to refresh the number amount by stages that number buffer area generates by stages every time;
Target id is calculated according to the ID and default value of acquisition;
Using Target id update prestore described in the corresponding ID of number buffer area by stages.
Further, processor 1001 can call the distributed generation program by stages number stored in memory 1005,
Also execute following operation:
It is described number buffer area is not sky by stages when, obtained from number buffer area by stages by stages number.
Further, processor 1001 can call the distributed generation program by stages number stored in memory 1005,
Also execute following operation:
When number buffer area by stages is empty, asking on the corresponding same node of number buffer area by stages is obtained
It asks, wherein the corresponding business of number buffer area by stages uses distributed deployment, there is multiple operation nodes;
Obtain the single request thread that synchrolock is taken in the request;
Judge whether the corresponding number buffer area by stages of the single request thread is empty;
If number buffer area by stages is sky, the corresponding number of number buffer area by stages described in the database refresh is executed
It generates accordingly by stages number, and the step of described number saving by stages to number buffer area by stages;
If number buffer area by stages be not it is empty, execute the step obtained from number buffer area by stages by stages number
Suddenly.
Further, processor 1001 can call the distributed generation program by stages number stored in memory 1005,
Also execute following operation:
The synchrolock of the single request thread is discharged, so that other threads of the request obtain the synchronization
Lock.
Referring to Fig. 2, Fig. 2 is the flow diagram of the distributed generation method first embodiment by stages number of the present invention;
The present embodiment proposes a kind of distributed generation method by stages number, and the generation method of distribution by stages number includes walking
It is rapid:
Step S10, receive obtain request by stages number when, obtained and corresponded to according to the service identification that the request carries
Number buffer area by stages, wherein multiple number buffer areas by stages are arranged to right to distinguish different business in the service identification
Answer each business;
As shown in figure 3, each service is using distributed deployment, service described herein can be with for frame diagram of the invention
One interface of system external offer is provided, a business of a system popular can also be interpreted as.The present embodiment
In, corresponding number buffer area by stages is arranged to each service, to place by stages number.Receiving the request obtained by stages number
When, which service the service identification judgement first carried according to the request belongs to, which can use according to specific business
Different names has determined that corresponding number buffer area by stages after determining corresponding service.
Whether step S20, the judgement number buffer area by stages are empty;
Step S30, when number buffer area by stages is empty, the corresponding number of number buffer area by stages described in the database refresh
It generates accordingly by stages number;
Step S40, by number preservation by stages to number buffer area by stages.
Judge that this by stages in number buffer area with the presence or absence of by stages number, if it exists by stages number, can be directly acquired;If it does not exist
By stages number, that is, this number buffer area is sky by stages, at this time, it may be necessary in the database refresh corresponding data of number buffer area by stages
To generate by stages number, specific implementation process elaborates in a second embodiment, wouldn't explain herein.In database refresh number
After obtaining by stages number, these obtained number are back to corresponding number buffer area by stages by stages and are saved.
Further, multiple number buffer areas by stages are arranged to each business of correspondence, so that performance is fully able in the present invention
Most of business scenarios are supported, and have higher transplantability using component of the invention, can be docked from different operation systems.
The distributed generation method by stages number that the present embodiment proposes, receive obtain request by stages number when, according to
The service identification that the request carries obtains corresponding number buffer area by stages, wherein the service identification is different to distinguish
Multiple number buffer areas by stages are arranged to each business of correspondence in business, and then whether the judgement number buffer area by stages is sky,
When number buffer area by stages is empty, described in the database refresh by stages the corresponding data of number buffer area to generate by stages number, and
It described number will save by stages to number buffer area by stages, and realize the generation of safe and convenient by stages number so that the system of docking obtains
It takes.
Further, referring to Fig. 4, propose that the distributed generation method second by stages number of the present invention is real based on first embodiment
Example is applied, in the present embodiment, the step S30 includes:
Step S31, lock database, obtain the currently stored corresponding ID of number buffer area by stages of the database and
Default value, wherein the quantity by stages number that the ID indicates that presently described number buffer area by stages generated, the present count
Value is the number amount by stages that number buffer area generates by stages of refreshing every time;
Step S32 calculates Target id according to the ID and default value of acquisition;
Step S33, using Target id update prestore described in the corresponding ID of number buffer area by stages;
Step S34 obtains updated ID and discharges the locking of the database;
Step S35 carries out digital encryption to the numerical value between the ID for updating front and back, wherein ID before and after the update it
Between numerical value do not include ID, including updated ID before updating;
Step S36, using the encrypted numerical value as by stages number.
In the present embodiment, introduce how in the corresponding data of database refresh to generate by stages number.Firstly, it is each by stages number
Buffer area is provided with corresponding ID and step-length, wherein the ID indicate it is current this by stages number buffer area generated by stages number
Quantity, the step-length, a that is, default value, to refresh the number amount by stages that number buffer area generates by stages every time.
The initial value of ID can be set as 0, that is, indicate that corresponding number buffer area by stages does not generate excessive issue also, the setting of step-length can be according to number
Depending on the performance in library, and the operation system demand of docking.In addition, needing to pass through Pessimistic Locking in database refresh data
Mode lock database, be to prevent multiple nodes of a service while while updating the same ID not will cause dirty data, because
The multiple nodes serviced for one are the corresponding same number buffer areas by stages.That is, if two nodes of a service
The same ID is updated simultaneously, then needs to be updated operation twice respectively, and updating for second is on the basis that first time updates
Upper progress, the two is not in repetition.
For example, ID is 0, step-length 1000, lock database discharges database after ID is updated to 0+1000=1000
Locking.Then, to 1~1000, this 1000 numbers carry out digital encryption respectively, using 1000 numerical value obtained after encryption as
This time refresh generate by stages number.It should be noted that encrypted string length can be with autonomous control, it so can be effective
Prevent be not easy to store existing for UUID, information is dangerous and is easy the problem of being imitated.
It in technical solution disclosed in the present embodiment, is generated by stages number by digital encryption, so that is generated number both pacified by stages
Full length again is controllable, convenient for storage.Further, since the corresponding ID of each number buffer area by stages and step-length difference, for different
Service, obtains ID and step-length is mutually isolated, is independent of each other, and brushes newly generated number will not repeat by stages every time.
Further, referring to Fig. 5, propose that the present invention is distributed by stages number based on first to second embodiment any embodiment
Generation method 3rd embodiment, in the present embodiment, the distributed generation method by stages number further include:
Step S50, it is described number buffer area is not sky by stages when, obtained from number buffer area by stages by stages number.
In technical solution disclosed in the present embodiment, after refreshing a database, it can obtain large number of number depositing by stages
Storage, can be directly from buffer area in when number being also not run out by stages of number buffer area by stages into corresponding number buffer area by stages
Take by stages number, only go database refresh again when buffer area number is used up by stages with obtain it is new by stages number, in this way, can be effective
Mitigation database pressure, can also tolerate database short time delay machine situation.
Further, referring to Fig. 6, propose that the present invention is distributed by stages number based on first to second embodiment any embodiment
Generation method fourth embodiment, in the present embodiment, the distributed generation method by stages number further include:
Step S60 is obtained when number buffer area by stages is empty in the corresponding same section of number buffer area by stages
Request on point, wherein the corresponding business of number buffer area by stages uses distributed deployment, there is multiple operation nodes;
Step S70 obtains the single request thread that synchrolock is taken in the request;
Step S80 judges whether the corresponding number buffer area by stages of the single request thread is empty;
Step S30 executes number buffer area by stages described in the database refresh if number buffer area by stages is sky
The step of corresponding data are to generate by stages number;
Step S40 executes described the step of described number saving by stages to number buffer area by stages;
Step S50, if number buffer area by stages is not empty, the execution acquisition point from number buffer area by stages
The step of issue.
The present embodiment can be understood as the concrete condition of first embodiment, since each service is using distributed deployment
, therefore will appear on an operation node of a service has the request thread of multiple acquisitions by stages number, at this point, same using thread
Step lock mechanism ensures that every time the thread of synchrolock is taken in only processing, and synchrolock can be taken by only having a thread every time,
His thread needs to wait until to remove contention synchrolock again after thread release synchrolock.In the present embodiment, method by stages number is generated
It is identical with the first embodiment, details are not described herein.It should be noted that the present embodiment tell about be handle concurrent thread side
Method is handled the single thread for possessing synchrolock in synchronized code block with ensureing.
In addition, synchrolock is discharged when detecting that the single thread for possessing synchrolock has had been processed, for obtaining by stages
Number request other threads obtain synchrolock.
In technical solution disclosed in the present embodiment, using thread synchronization lock, database Pessimistic Locking, so that in refresh
When generating by stages number, it is ensured that the case where correctness and uniqueness of data are not in data corruption and data redundancy.
In addition, the embodiment of the present invention also proposes a kind of distributed generating means by stages number, it is described it is distributed by stages number
Generating means include memory, processor and are stored in the computer journey that can be run on the memory and on the processor
Sequence, the computer program realize the generation method of distribution described in embodiment as above by stages number when being executed by the processor
The step of.
In addition, the embodiment of the present invention also proposes a kind of computer storage medium, it is stored in the computer storage medium
Distributed generation program by stages number, the distributed generation program by stages number are realized as above in fact when being executed by the processor
The step of applying the generation method of distribution described in example by stages number.
It should be noted that, in this document, the terms "include", "comprise" or its any other variant are intended to non-row
His property includes, so that the process, method, article or the device that include a series of elements not only include those elements, and
And further include other elements that are not explicitly listed, or further include for this process, method, article or device institute it is intrinsic
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including being somebody's turn to do
There is also other identical elements in the process, method of element, article or device.
The serial number of the above embodiments of the invention is only for description, does not represent the advantages or disadvantages of the embodiments.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment side
Method can be realized by means of software and necessary general hardware platform, naturally it is also possible to by hardware, but in many cases
The former is more preferably embodiment.Based on this understanding, technical solution of the present invention substantially in other words does the prior art
The part contributed out can be embodied in the form of software products, which is stored in one as described above
In storage medium (such as ROM/RAM, magnetic disk, CD), including some instructions are used so that terminal device (it can be mobile phone,
Computer, cloud server, air conditioner or network equipment etc.) method that executes each embodiment of the present invention.
The above is only a preferred embodiment of the present invention, is not intended to limit the scope of the invention, all to utilize this hair
Equivalent structure or equivalent flow shift made by bright specification and accompanying drawing content is applied directly or indirectly in other relevant skills
Art field, is included within the scope of the present invention.