CN103164418A - Method and device for processing serial numbers - Google Patents

Method and device for processing serial numbers Download PDF

Info

Publication number
CN103164418A
CN103164418A CN2011104127493A CN201110412749A CN103164418A CN 103164418 A CN103164418 A CN 103164418A CN 2011104127493 A CN2011104127493 A CN 2011104127493A CN 201110412749 A CN201110412749 A CN 201110412749A CN 103164418 A CN103164418 A CN 103164418A
Authority
CN
China
Prior art keywords
database
sequence
sequence number
sequence table
server
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
CN2011104127493A
Other languages
Chinese (zh)
Other versions
CN103164418B (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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201110412749.3A priority Critical patent/CN103164418B/en
Publication of CN103164418A publication Critical patent/CN103164418A/en
Priority to HK13109758.8A priority patent/HK1182479A1/en
Application granted granted Critical
Publication of CN103164418B publication Critical patent/CN103164418B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention provides a method and a device for processing serial numbers. When a server is required to write data records in a data bank, one data bank is selected from a plurality of data banks according to a set data bank inquiry sequence, a sequence list in the selected data bank is read, N available serial numbers are obtained from the read sequence list and the data records are written in the data bank by using the available serial numbers. Due to the fact that the server can select one sequence list of one data bank from the plurality of data banks according to the inquiry sequence so that the serial numbers are obtained, acquisition of the serial numbers are not limited in one sequence list in a certain data bank, dependant relationship between the sequence list and the data bank is effectively weakened and sharing of the serial numbers is achieved. Even though the condition that the serial numbers in the certain data bank are exhausted or the data bank malfunctions, the server still can obtain the serial numbers from other data banks and the problem that the data records can not be written in the data bank continuously due to the fact that the serial numbers in a part of the data banks are exhausted is solved.

Description

A kind of disposal route of sequence number and equipment
Technical field
The application relates to field of computer technology, relates in particular to a kind of disposal route and equipment of sequence number.
Background technology
Sequence table is be used to the database object that creates unique continuous integral number value, and its typical purposes is to create the unique sequence number of the overall situation, with a data record in the identification data table.When the data recording number in tables of data is less, can directly create a sequence table in depositing the database of this tables of data, when newly-increased data recording, server obtains sequence number from this sequence table, and utilizes the newly-increased data recording of this sequence number sign.
After if the data recording quantity that needs in database to record meets or exceeds certain scale (as 1,000 ten thousand), continuation increase along with the data recording number, if all data recording all are recorded in same tables of data, the performance of data recording in this tables of data being carried out reading and writing operations will obviously descend.Therefore, data recording can be documented in a plurality of tables of data, and a plurality of tables of data are deposited in one or more databases, and be sequence number of each data recording distribution.Particularly, when having a newly-increased data recording to need write into Databasce, obtain a serial number assignment to current newly-increased data recording from sequence table, complete the write operation of data recording.
Particularly, the mode of obtaining the sequence number of distributing to data recording from sequence table comprises following two kinds:
First kind of way:
Select a database in a plurality of databases of data table memory, be used for setting up and the storage sequence table, have one to set field in described sequence table.When server need to obtain sequence number data writing in the database and records, obtain an available sequence number from described sequence table.
Under the obtain manner of the first sequence number, there is the single-point risk, namely when be responsible for setting up and the database of storage sequence table when breaking down, obtaining operation and having no way of carrying out of sequence number causes the write operation of data recording also can't carry out.
The second way:
Set up respectively a sequence table in each database, and distribute one section sequence number interval for this sequence table, when system moves, when server need to record to data writing in a certain database, obtain sequence number in the sequence table from this database, that is to say, the serial number assignment in database in sequence table is given the data recording in same database.
Under the obtain manner of the second sequence number, can avoid the single-point risk, but fixing sequence number is interval owing to having distributed for each database, these sequence numbers can only be distributed to the data recording in same database, therefore, the sequence number that may occur in partial database exhausts, but the lower situation of sequence number utilization rate in partial database.
In addition, when database is expanded, may need a database is split as a plurality of databases, also to be split as the sequence table of database before splitting a plurality of simultaneously, at this moment, if the partial sequence in splitting the preorder list number was used, the database after the sequence table after may causing splitting can't reasonable distribution splits to each.
For example: the sequence number in the sequence table 1 of database 1 is 0~999, wherein, 0~300 sequence number was used, when database 1 is split as database 11 and database 12, if sequence table 1 also is split as sequence table 11 and sequence table 12, and the sequence number in sequence table 11 is 0~499, and the sequence number in sequence table 12 is 500~999, number be used due to the partial sequence in sequence table 11, and caused the expansion effect of database relatively poor.
Summary of the invention
The embodiment of the present application provides a kind of disposal route and equipment of sequence number, in order to solve in prior art due to after the sequence number in partial database exhausts, just can't continue to this database the problem of data writing record.
A kind of disposal route of sequence number comprises:
When server records at needs data writing in the database, according to the database query sequence of setting, select a database from a plurality of databases, and read the sequence table in the database of selection;
Server obtains N available sequences number from the sequence table of reading, described N is positive integer;
Server according to the available sequences obtained number with in described data recording write into Databasce.
A kind for the treatment of facility of sequence number comprises:
Select module, be used for when needs record to the database data writing, according to the database query sequence of setting, select a database from a plurality of databases, and read the sequence table in the database of selection;
Acquisition module is used for obtaining N available sequences number from the sequence table of reading, and described N is positive integer;
Writing module is used for according to the available sequences of obtaining number with described data recording write into Databasce.
The application's beneficial effect is as follows:
in the scheme that the embodiment of the present application provides, when server need to record to data writing in database, because server can select the sequence table of a database to obtain sequence number from a plurality of databases by search order, be not limited in some databases sequence table and obtain sequence number, effectively weakened the dependence between sequence table and database, realized sharing of sequence number, sequence number in a certain database exhausts or the situation of database failure even occur, server still can obtain sequence number from other databases, overcome due to after the sequence number in partial database exhausts, just can't continue to this database the problem of data writing record.
Description of drawings
Fig. 1 is the process method step schematic diagram of the embodiment of the present application one sequence number;
Fig. 2 is the process method step schematic diagram of the embodiment of the present application two sequence numbers;
Fig. 3 is the treatment facility structural representation of the embodiment of the present application three sequence numbers.
Embodiment
For realizing the application's purpose, the embodiment of the present application proposes a kind of processing scheme of sequence number, when server need to record to data writing in database, according to the database query sequence of setting, select a database from a plurality of databases, read the sequence table in the database of selection, and obtain the individual available sequences of N (N is positive integer) number from the sequence table of reading, and use available sequences number with in described data recording write into Databasce.because server can select the sequence table of a database to obtain sequence number from a plurality of databases by search order, be not limited in some databases sequence table and obtain sequence number, effectively weakened the dependence between sequence table and database, realized sharing of sequence number, sequence number in a certain database exhausts or the situation of database failure even occur, server still can obtain sequence number from other databases, overcome due to after the sequence number in partial database exhausts, just can't continue to this database the problem of data writing record.
Be described in detail below in conjunction with the scheme of Figure of description to the embodiment of the present application.
Embodiment one
As shown in Figure 1, it is the process method step schematic diagram of sequence number in the embodiment of the present application one, said method comprising the steps of:
Step 101: when server records at needs data writing in the database, according to the database query sequence of setting, select a database from a plurality of databases, and read the sequence table in the database of selection.
Generally, can comprise a plurality of servers and a plurality of database in a database schema, an arbitrary server can carry out belonging to each database in same database schema data recording inquiry, write, the operation such as deletion; More excellent, consider in real process, when operation system starts, a plurality of servers may occur and obtain simultaneously the situation of sequence number from the sequence table of a certain database, can cause sequence number to seize conflict, number seize the probability of conflict in order to reduce occurrence sequence, server selects the mode of a database to be specifically as follows from a plurality of databases according to the database query sequence of setting:
If server is data writing record in the database first, select a database at random from described a plurality of databases;
If server is not data writing record in the database first, determine the last database of selecting, and according to described database query sequence, determine the database of current selection, for example: database is arranged according to name or other modes, after the database of once selecting on determining, next will be with the database that the last time is selected adjacent database is as the database of current selection, if last selection is to be arranged in a last database, can the database of primary database as current selection will be arranged in.
Described first in the database data writing record refer to, after operation system starts, after server powers on for the first time executing data record write operation.
In the scheme of this step 101, when server records at needs data writing in arbitrary database, can carry out according to the scheme of this step 101.
Sequence table in the present embodiment is when creation database, and utilization such as the computereses such as database structure query language (SQL) create.Sequence table can be used for depositing the information generated of sequence number and sequence number, when server carries out the write operation of a data record to database, need to obtain a sequence number from sequence table, to identify this data record.
In the scheme of the present embodiment, include but not limited to following three kinds of modes formation sequence number in sequence table:
First kind of way:
According to the initial sequence number that comes sequence table in the specified data storehouse for the label that arranges in each database, and then increase other sequence numbers in same sequence table according to certain growth step-length, be specifically as follows:
The first step according to label order from small to large, is followed successively by each database label is set.
Second step, with the label of the database initial sequence number as sequence table in this database, and the quantity D that judges described a plurality of databases be whether 2 index doubly, described D is the positive integer greater than 1, if, carried out for the 3rd step, if not, carried out for the 4th step.
The 3rd the step, for the sequence table in arbitrary database, with the initial sequence number in this sequence table successively with D for increasing step-length, the sequence number that obtains as the sequence number in this sequence table, at this moment, is completed the generating run of sequence number together with this initial sequence number.
In the 4th step, determine less than D and 2 nearest index multiple value X of distance B.
The 5th step was not less than D-X and less than the sequence table in the database of X for label, with the initial sequence number in this sequence table successively with X for increasing step-length, the sequence number that obtains is as the sequence number in this sequence table; For the sequence table in the remaining data storehouse, with the initial sequence number in this sequence table successively with 2X for increasing step-length, the sequence number that obtains is as the sequence number in this sequence table.
For example, tentation data storehouse number D is 4, and namely the quantity D of database is 2 index situation doubly, and at this moment, can set each database label is 0,1,2,3, and in each database, the initial sequence number of sequence table is respectively 0,1,2,3.Be 0 database for label, wherein the initial sequence number of sequence table is 0, and with 4 for increasing step-length, the sequence number 4,8,12,16 that obtains ... with 0 together be the sequence number of sequence table in 0 database as label.Sequence number generative process for sequence table in other databases is similar.
Again for example, tentation data storehouse number D is 5, and namely the quantity D of database is not 2 index situation doubly, and at this moment, still can set each database label is 0,1,2,3,4, and in each database, the initial sequence number of sequence table is respectively 0,1,2,3,4.With 5 immediate 2 index multiple value X be 4.
Label is not less than D-X and is database 1, database 2 and database 3 less than the database of X, take database 1 as example, in this database 1, initial sequence number is 1, and with 4 for increasing step-length, the sequence number 5,9,13,17 that obtains ... with 1 together be the sequence number of sequence table in 1 database as label; For database 2 and database 3, its way is with identical for the way of database 1.
Remaining label is 0 and 4 database, database take label as 0 is as example, in this database 0, initial sequence number is 0, and with 8 for increasing step-length, the sequence number 8,16,24,32 that obtains ... with 0 together be the sequence number of sequence table in 0 database as label; For database 4, its way is with identical for the way of database 0.
Need to prove, under first kind of way, the label of database is that acquiescence increases successively by 1 digital naming method since 0 and sets, and the present embodiment also is not limited to other, and to utilize digital naming method (as since 1) be database setting label.
By above-mentioned first kind of way, because being determines to increase step-length for 2 index multiple value, therefore, can realize easily the fractionation to sequence table in database and database.
For example, when a certain database need to be split as K subdata base, sequence table in described database is also removable is divided into K subsequence table, wherein: the initial sequence number of the arbitrary subsequence table in a described K subsequence table is: split a sequence number in minimum K sequence number available in the preorder list, and the initial sequence number of any two subsequence tables is not identical, simultaneously, in arbitrary subsequence table the growth step-length between sequence number for splitting in the preorder list between sequence number the K of step-length doubly.
For example, suppose to split before in database 1 sequence number of sequence table 1 be respectively 0,4,8,12,16,20 ...., its initial sequence number is 0, increasing step-length is 4.0,8,16,24 when this database 1 is split as database 11 and database 12, for sequence number in the sequence table 11 of database 11 be: ..., its initial sequence number is 0, step-length is 8; 4,12,20,28... for sequence number in the sequence table 12 of database 12 be:, its initial sequence number is 4, and step-length is 8.
The second way:
The first step according to label order from small to large, is followed successively by each database label is set.
Second step is with the label of the database initial sequence number as sequence table in this database.
The 3rd the step, for arbitrary sequence table, with the initial sequence number in this sequence table successively with D for increasing step-length, the sequence number that obtains is as the sequence number in this sequence table.
For example, the number D in tentation data storehouse is 5, and setting each database label is 0,1,2,3,4, and in each database, the initial sequence number of sequence table is respectively 0,1,2,3,4.Be 0 database for label, wherein the initial sequence number of sequence table is 0, and with 5 for increasing step-length, the sequence number 5,10,15,20 that obtains ... with 0 together be the sequence number of sequence table in 0 database as label.Sequence number generative process for sequence table in other databases is similar.
The third mode:
Be the setting of the sequence table in each database sequence number interval.
Step 102: server obtains N available sequences number from the sequence table of reading, described N is positive integer.
The specific implementation of this step 102 includes but not limited to following dual mode:
First kind of way:
Server is searched from the sequence table of database does not also have used sequence number, and selects N sequence number as the available sequences of the N in this step 102 number from also there is no used sequence number.
The second way:
Obtain simultaneously the problem that sequence number causes seizing conflict from same database for fear of a plurality of servers, the second way is optimized first kind of way, and is specific as follows:
The first step, server read next available sequences Current_next_value of sequence table in the database of selection.
In the scheme of the present embodiment, server whenever obtain N sequence number from sequence table after, can with in this sequence table with this N that obtains sequence number in the adjacent next one of last sequence number there is no used sequence number as Current_next_value.
0,4,8,12,16,20 for example, in a certain sequence table, sequence number is: ..., certain 4 sequence numbers that obtain of server are 0,4,8,12, are written back in this sequence table as Current_next_value 16.
Second step, server upgrade the Current_next_value that reads according to formula (1):
Current_next_value_new=Current_next_value+increase_step×N (1)
Wherein, Current_next_value_new is next available sequences after upgrading number, and increase_step is for increasing step-length, and N is the number of the sequence number that obtains continuously from Current_next_value in sequence table.
In the 3rd step, server judges whether Current_next_value_new can be written back in sequence table, if carried out for the 4th step; If not, carried out for the 5th step.
Obtain simultaneously the situation of sequence number from same database owing to a plurality of servers may occurring, therefore, when server 1 is written back to sequence table with Current_next_value_new, if trying to be the first, existing other servers 2 obtained sequence table from this database, that is to say, server 2 calculates Current_next_value_new and is written back in sequence table according to above-mentioned formula (1) prior to server 1, therefore, server 1 can't write identical content or the less Current_next_value_new of numerical value again; Do not obtain sequence table if having other servers 2 to try to be the first this moment, the Current_next_value_new that calculates according to formula (1) of server 1 is greater than the current Current_next_value that has stored in sequence table, therefore, server 1 can obtain available sequence number from this sequence table.
The 4th step, server is written back to sequence table with described Current_next_value_new, at this moment, the content update of Current_next_value in sequence table is the content of Current_next_value_new, and will be from N the available sequence number that N continuous sequence number conduct obtained from Current_next_value that reads sequence table.
0,4,8,12,16,20,24,28,32 for example, in a certain sequence table, to increase step-length be 4 to sequence number, and content is respectively: ..., the sequence number quantity N that server obtains at every turn is 4.If certain Current_next_value that obtains that obtains in the first step is 16, the Current_next_value_new that calculates by formula (1) is 32, at this moment, this Current_next_value_new is that 32 value can be written back to sequence table, and server can be with 16,20,24,28 as 4 available sequence numbers that obtain.
In the 5th step, server reads next database according to database query sequence, and restarts to carry out the first step for described next database redirect, until obtain N available sequence number.
Step 103: server according to the available sequences obtained number with in described data recording write into Databasce.
Step 104: when server needed again that data writing records in the database, whether N the available sequences that judgement has been obtained number was all used, if execution in step 105; If not, execution in step 106.
Step 105: re-execute according to the database query sequence of setting, jump to step 101.
Step 106: select also not have used available sequences number from the described N that has an obtained available sequences number, and according to the described available sequences of selecting number with in the data recording write into Databasce.
The present embodiment scheme is applied in SQL database system, Oracel Database Systems or other Database Systems, can but be not limited to and utilize sql like language to realize.
Embodiment two
Consider that server avoiding when obtaining sequence number seize conflict and guarantee the uniqueness of the sequence number that each server obtains, guarantee consistance and the integrality of database, the present embodiment two is described the preferred implementation of the present embodiment one in detail in conjunction with lock technology.
As shown in Figure 2, it is the process method step schematic diagram of sequence number in the embodiment of the present application two, said method comprising the steps of:
Step 201: server obtains synchrolock.
The granularity of described synchrolock locking is data group table.
Described data group table is the general name that records the tables of data of same business in each database in described a plurality of database, forms every data record in the tables of data of data group table and all need obtain the unique available sequences of the overall situation number.
Obtain the request Concurrency problem that synchrolock can avoid a plurality of servers to initiate in this step 201, only allow a thread to attempt obtaining a sequence number in database at a time point.
More excellent, if this programme realize with programming, its kernel data structure can be following form:
Table_group_name//needs use the title of the data group table of overall unique sequence number, each minute
Separate between // group, the sequence souvenir of identical table_group_name
// record is responsible for safeguarding the sequence number of same group of data table, and this sequence-number field exists
Need to guarantee uniqueness in // sequence table
Current_next_value//current next one effectively is worth, and during every secondary program application to get sequence number, all can
// the peaked next effective value of this batch ordered sequence number is updated to
In //current_next_value
The step-length that increase_step // each sequence number increases, its value is in the application's embodiment
//X or 2X
The number of the each ordered sequence that obtains in batches of take_patch//system number is the application's
In // embodiment, its value is N
Step 202: server judges whether this locality has available sequences number, if, utilize this available sequences number to carry out the write operation of data recording, otherwise, execution in step 203.
If this step 202 is the requests of obtaining available sequences number of sending first on server, can obtain N available sequences number from the database of random selection according to the mode of step 102 in embodiment one; Otherwise whether last N the available sequences of obtaining from database of server judgement number is used up, if, execution in step 203, N available sequences number obtained in continuation from database, otherwise, directly use local stored also there is no a used available sequences number.
Step 203: server is waited for the request of obtaining available sequences number of sending.
Step 204: server sends the request of obtaining available sequences number to database, obtain the Current_next_value in sequence table from this database.
Step 205: server can adopt the loose mode that locks (optimistic lock side formula), avoid occuring update inconsistency, and calculate Current_next_value_new according to described Current_next_value, and can judgement Current_next_value_new be written back to sequence table, if can, execution in step 206; Otherwise, execution in step 207.
Step 206: server is written back to sequence table with described Current_next_value_new, and will be from N the available sequence number that N continuous sequence number conduct obtained from Current_next_value that reads sequence table, write local cache, and utilize this available sequences number to carry out the write operation of data recording, and discharge synchrolock and optimistic lock.
In the scheme of the present embodiment, the sequence table that server is worked as pre-treatment can be referred to as the current sequence table, therefore, and in this step 206, server can preset sequence table in next database as the current sequence table, number uses so that obtain N available sequences next time.
Step 207: server reads next database according to database query sequence, and jumps to step 204.
In the scheme of the present embodiment, server can be referred to as the current sequence table when the sequence table of pre-treatment, and therefore, in this step 207, server as the current sequence table, therefrom obtains N available sequences number with the sequence table in next database again.
No matter whether the mode by the present embodiment two can obtain an available N sequence number, if exit criteria satisfy (as arrive post-set time or without available sequences number), just withdraw from the scheme of the present embodiment, finish the operation of obtaining for sequence number.
Embodiment three
The sequence number treatment facility that the embodiment of the present application three proposes under a kind of and embodiment one same idea as shown in Figure 3, comprising: select module 11, acquisition module 12 and writing module 13, wherein:
Select module 11, be used for when needs record to the database data writing, according to the database query sequence of setting, select a database from a plurality of databases, and read the sequence table in the database of selection;
Acquisition module 12 is used for obtaining N available sequences number from the sequence table of reading, and described N is positive integer;
Writing module 13 is used for according to the available sequences of obtaining number with described data recording write into Databasce.
Concrete, described selection module 11 comprises:
The first selected cell 21 if be used for first to database data writing record, is selected a database at random from described a plurality of databases.
The second selected cell 22 is used for if not first to database data writing record, determine the last database of selecting, and according to described database query sequence, determine the database of current selection.
More excellent, described equipment also comprises:
Label arranges module 14, is used to each database in described a plurality of database to set gradually label according to label order from small to large.
Sequence number generation module 15 is used for the sequence table for arbitrary database, in the following manner the sequence number in the formation sequence table:
With the label of the database initial sequence number as sequence table in this database, and the quantity D that judges described a plurality of databases be whether 2 index doubly, described D is the positive integer greater than 1;
If, for the sequence table in arbitrary database, with the initial sequence number in this sequence table successively take D as the sequence number that increases step-length and obtain as the sequence number in this sequence table;
If not, determine less than D and 2 nearest index multiple value X of distance B;
Be not less than D-X and less than the sequence table in the database of X for label, with the initial sequence number in this sequence table successively take X as the sequence number that increases step-length and obtain as the sequence number in this sequence table;
For the sequence table in the remaining data storehouse, with the initial sequence number in this sequence table successively take 2X as the sequence number that increases step-length and obtain as the sequence number in this sequence table.
More excellent, described equipment also comprises:
Split module 16, be used for when arbitrary database need to be split as K subdata base, the sequence table in described database also is split as K subsequence table, and described K is the positive integer greater than 1;
Wherein: the initial sequence number of the arbitrary subsequence table in a described K subsequence table is: split a sequence number in minimum K sequence number available in the preorder list, and the initial sequence number of any two subsequence tables is not identical, and the growth step-length in arbitrary subsequence table between sequence number is for splitting in the preorder list between sequence number the K of step-length doubly.
More excellent, described acquisition module 12 specifically comprises:
Reading unit 31 is for next available sequences Current_next_value of the database sequence table of reading selection.
Updating block 32 is used for upgrading according to following formula the Current_next_value that reads:
Current_next_value_new=Current_next_value+increase_step×N
Wherein, Current_next_value_new is next available sequences after upgrading number, and increase_step is for increasing step-length, and N is the number of the sequence number that obtains continuously from Current_next_value in sequence table.
Judging unit 33 is used for judging whether Current_next_value_new can be written back to sequence table.
Acquiring unit 34, be used for when the judgment unit judges result when being, described Current_next_value_new is written back to sequence table, and will will be N the available sequence number that obtains from N the continuous sequence number from Current_next_value that reads sequence table.
Jump-transfer unit 35 is used for, reading the Current_next_value of sequence table in next database according to database query sequence, and jumping to updating block 32 when being no when the judgment unit judges result.
More excellent, described equipment also comprises:
Judge module 17, when being used for again needing to record to the database data writing, whether N the available sequences that judgement is obtained from described acquisition module 12 number was all used.
The first redirect module 18 is used for when the result of judge module jumping to selection module 11 when being.
The second redirect module 19 is used for when being no, jumping to writing module 13 when the result of judge module.
by the embodiment of the present application one, the method and apparatus that the sequence number that embodiment two and embodiment three provide is processed, because server can select the sequence table of a database to obtain sequence number from a plurality of databases by search order, be not limited in some databases sequence table and obtain sequence number, effectively weakened the dependence between sequence table and database, realized sharing of sequence number, sequence number in a certain database exhausts or the situation of database failure even occur, server still can obtain sequence number from other databases, overcome due to after the sequence number in partial database exhausts, just can't continue to this database the problem of data writing record, preferably, when being sequence table formation sequence in each database, the index take 2 is doubly the basis, makes the fractionation of sequence table in the fractionation of database and database more convenient, again preferably, the scheme of the present embodiment is in obtaining the process of N available sequences number, synchrolock and optimistic lock have been used, avoided seizing conflict and seize conflict in the sequence number update process because a plurality of servers obtain sequence number that available sequences number causes simultaneously from the sequence table of a certain database, guaranteed consistance and the integrality of database.
Those skilled in the art should understand, the application's embodiment can be provided as method, system or computer program.Therefore, the application can adopt complete hardware implementation example, implement software example or in conjunction with the form of the embodiment of software and hardware aspect fully.And the application can adopt the form that wherein includes the upper computer program of implementing of computer-usable storage medium (including but not limited to magnetic disk memory, CD-ROM, optical memory etc.) of computer usable program code one or more.
The application is that reference is described according to process flow diagram and/or the block scheme of method, equipment (system) and the computer program of the embodiment of the present application.Should understand can be by the flow process in each flow process in computer program instructions realization flow figure and/or block scheme and/or square frame and process flow diagram and/or block scheme and/or the combination of square frame.Can provide these computer program instructions to the processor of multi-purpose computer, special purpose computer, Embedded Processor or other programmable data processing device to produce a machine, make the instruction of carrying out by the processor of computing machine or other programmable data processing device produce to be used for the device of realizing in the function of flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame appointments.
These computer program instructions also can be stored in energy vectoring computer or the computer-readable memory of other programmable data processing device with ad hoc fashion work, make the instruction that is stored in this computer-readable memory produce the manufacture that comprises command device, this command device is realized the function of appointment in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame.
These computer program instructions also can be loaded on computing machine or other programmable data processing device, make on computing machine or other programmable devices and to carry out the sequence of operations step producing computer implemented processing, thereby be provided for realizing the step of the function of appointment in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame in the instruction of carrying out on computing machine or other programmable devices.
Although described the application's preferred embodiment, in a single day those skilled in the art get the basic creative concept of cicada, can make other change and modification to these embodiment.So claims are intended to all changes and the modification that are interpreted as comprising preferred embodiment and fall into the application's scope.
Obviously, those skilled in the art can carry out various changes and modification and the spirit and scope that do not break away from the application to the application.Like this, if within these of the application are revised and modification belongs to the scope of the application's claim and equivalent technologies thereof, the application also is intended to comprise these changes and modification interior.

Claims (10)

1. the disposal route of a sequence number, is characterized in that, comprising:
When server records at needs data writing in the database, according to the database query sequence of setting, select a database from a plurality of databases, and read the sequence table in the database of selection;
Server obtains N available sequences number from the sequence table of reading, described N is positive integer;
Server according to the available sequences obtained number with in described data recording write into Databasce.
2. the disposal route of sequence number as claimed in claim 1, is characterized in that, according to the database query sequence of setting, selects a database from a plurality of databases, specifically comprises:
If server is data writing record in the database first, select a database at random from described a plurality of databases;
If server is not data writing record in the database first, determines the last database of selecting, and according to described database query sequence, determine the database of current selection.
3. the disposal route of sequence number as claimed in claim 1, is characterized in that, before server need record to data writing in database, described method also comprised:
For each database in described a plurality of databases sets gradually label according to label order from small to large;
For the sequence table in arbitrary database, the sequence number in the formation sequence table in the following manner:
With the label of the database initial sequence number as sequence table in this database, and the quantity D that judges described a plurality of databases be whether 2 index doubly, described D is the positive integer greater than 1;
If, for the sequence table in arbitrary database, with the initial sequence number in this sequence table successively take D as the sequence number that increases step-length and obtain as the sequence number in this sequence table;
If not, determine less than D and 2 nearest index multiple value X of distance B;
Be not less than D-X and less than the sequence table in the database of X for label, with the initial sequence number in this sequence table successively take X as the sequence number that increases step-length and obtain as the sequence number in this sequence table;
For the sequence table in the remaining data storehouse, with the initial sequence number in this sequence table successively take 2X as the sequence number that increases step-length and obtain as the sequence number in this sequence table.
4. the disposal route of sequence number as claimed in claim 3, is characterized in that, described method also comprises:
When arbitrary database need to be split as K subdata base, the sequence table in described database also was split as K subsequence table, and described K is the positive integer greater than 1;
Wherein: the initial sequence number of the arbitrary subsequence table in a described K subsequence table is: split a sequence number in minimum K sequence number available in the preorder list, and the initial sequence number of any two subsequence tables is not identical, and the growth step-length in arbitrary subsequence table between sequence number is for splitting in the preorder list between sequence number the K of step-length doubly.
5. the disposal route of sequence number as claimed in claim 3, is characterized in that, server obtains N available sequences number in the following manner:
Server reads next available sequences Current_next_value of sequence table in the database of selection;
Server upgrades the Current_next_value that reads according to following formula:
Current_next_value_new=Current_next_value+increase_step×N
Wherein, Current_next_value_new is next available sequences after upgrading number, and increase_step is for increasing step-length, and N is the number of the sequence number that obtains continuously from Current_next_value in sequence table;
Server judges whether Current_next_value_new can be written back in sequence table;
If described Current_next_value_new is written back to sequence table, and will will be N the available sequence number that obtains from N the continuous sequence number from Current_next_value that reads sequence table;
If not, server reads the Current_next_value of sequence table in next database according to database query sequence, and repeat according to described formula and obtain Current_next_value_new, and judge whether Current_next_value_new can be written back to the operation of sequence table.
6. the disposal route of sequence number as claimed in claim 1, is characterized in that, described method also comprises:
When server needed again that data writing records in the database, whether N the available sequences that judgement has been obtained number was all used;
If, re-execute according to the database query sequence of setting, select the operation of a database from a plurality of databases;
If not, select also not have used available sequences number from the described N that has an obtained available sequences number, and according to the described available sequences of selecting number with in the data recording write into Databasce.
7. the treatment facility of a sequence number, is characterized in that, comprising:
Select module, be used for when needs record to the database data writing, according to the database query sequence of setting, select a database from a plurality of databases, and read the sequence table in the database of selection;
Acquisition module is used for obtaining N available sequences number from the sequence table of reading, and described N is positive integer;
Writing module is used for according to the available sequences of obtaining number with described data recording write into Databasce.
8. the treatment facility of sequence number as claimed in claim 7, is characterized in that, described selection module specifically comprises:
The first selected cell if be used for first to database data writing record, is selected a database at random from described a plurality of databases;
The second selected cell is used for if not first to database data writing record, determine the last database of selecting, and according to described database query sequence, determine the database of current selection.
9. the treatment facility of sequence number as claimed in claim 7, is characterized in that, described equipment also comprises:
Label arranges module, is used to each database in described a plurality of database to set gradually label according to label order from small to large;
The sequence number generation module is used for the sequence table for arbitrary database, in the following manner the sequence number in the formation sequence table:
With the label of the database initial sequence number as sequence table in this database, and the quantity D that judges described a plurality of databases be whether 2 index doubly, described D is the positive integer greater than 1;
If, for the sequence table in arbitrary database, with the initial sequence number in this sequence table successively take D as the sequence number that increases step-length and obtain as the sequence number in this sequence table;
If not, determine less than D and 2 nearest index multiple value X of distance B;
Be not less than D-X and less than the sequence table in the database of X for label, with the initial sequence number in this sequence table successively take X as the sequence number that increases step-length and obtain as the sequence number in this sequence table;
For the sequence table in the remaining data storehouse, with the initial sequence number in this sequence table successively take 2X as the sequence number that increases step-length and obtain as the sequence number in this sequence table.
10. the treatment facility of sequence number as claimed in claim 9, is characterized in that, described equipment also comprises:
Split module, be used for when arbitrary database need to be split as K subdata base, the sequence table in described database also is split as K subsequence table, and described K is the positive integer greater than 1;
Wherein: the initial sequence number of the arbitrary subsequence table in a described K subsequence table is: split a sequence number in minimum K sequence number available in the preorder list, and the initial sequence number of any two subsequence tables is not identical, and the growth step-length in arbitrary subsequence table between sequence number is for splitting in the preorder list between sequence number the K of step-length doubly.
CN201110412749.3A 2011-12-12 2011-12-12 A kind of processing method of sequence number and equipment Active CN103164418B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201110412749.3A CN103164418B (en) 2011-12-12 2011-12-12 A kind of processing method of sequence number and equipment
HK13109758.8A HK1182479A1 (en) 2011-12-12 2013-08-21 Method and device for processing serial numbers

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110412749.3A CN103164418B (en) 2011-12-12 2011-12-12 A kind of processing method of sequence number and equipment

Publications (2)

Publication Number Publication Date
CN103164418A true CN103164418A (en) 2013-06-19
CN103164418B CN103164418B (en) 2016-05-04

Family

ID=48587513

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110412749.3A Active CN103164418B (en) 2011-12-12 2011-12-12 A kind of processing method of sequence number and equipment

Country Status (2)

Country Link
CN (1) CN103164418B (en)
HK (1) HK1182479A1 (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103647833A (en) * 2013-12-16 2014-03-19 百度在线网络技术(北京)有限公司 Continuous sequence number generation system and continuous sequence number generation method
CN105468718A (en) * 2015-11-18 2016-04-06 腾讯科技(深圳)有限公司 Data consistency processing method, device and system
CN105589699A (en) * 2014-10-20 2016-05-18 中兴通讯股份有限公司 Serial number information update method, device and terminal
CN105630991A (en) * 2015-12-25 2016-06-01 北京奇虎科技有限公司 Method and device for automatically generating ID
CN106528220A (en) * 2016-10-27 2017-03-22 武汉奥泽电子有限公司 Anti-coincident-code programming system and method for serial number of automobile remote controller
CN107038191A (en) * 2016-11-15 2017-08-11 阿里巴巴集团控股有限公司 A kind of data processing method of database sequence, device and server
CN108243264A (en) * 2016-12-27 2018-07-03 中国移动通信有限公司研究院 A kind of sequence number generation method and system
WO2018177350A1 (en) * 2017-04-01 2018-10-04 北京京东尚科信息技术有限公司 Method and apparatus for providing serial number, electronic device and readable storage medium
CN109165712A (en) * 2018-08-01 2019-01-08 广州唯品会信息科技有限公司 Distributed generation method, device and computer storage medium by stages number
WO2019047351A1 (en) * 2017-09-11 2019-03-14 平安科技(深圳)有限公司 Method, device, electronic apparatus and medium for generating physical card number
CN109656920A (en) * 2018-10-19 2019-04-19 中国建设银行股份有限公司 Sequence number processing method and system, device and storage medium
CN111949730A (en) * 2020-08-12 2020-11-17 中国银行股份有限公司 Distributed global sequence number implementation method and sequence distributor
CN112925787A (en) * 2019-12-06 2021-06-08 中国电信股份有限公司 Data processing method, device and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH10161916A (en) * 1996-11-28 1998-06-19 Hitachi Ltd Detection of update conflict accompanying duplication of data base
CN101216840A (en) * 2008-01-21 2008-07-09 金蝶软件(中国)有限公司 Data enquiry method and data enquiry system
CN101661509A (en) * 2009-09-29 2010-03-03 金蝶软件(中国)有限公司 Method for generating major key field of database table and device thereof
CN102156717A (en) * 2011-03-25 2011-08-17 中国有色矿业集团有限公司 Method and device for mapping entity object into database

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH10161916A (en) * 1996-11-28 1998-06-19 Hitachi Ltd Detection of update conflict accompanying duplication of data base
CN101216840A (en) * 2008-01-21 2008-07-09 金蝶软件(中国)有限公司 Data enquiry method and data enquiry system
CN101661509A (en) * 2009-09-29 2010-03-03 金蝶软件(中国)有限公司 Method for generating major key field of database table and device thereof
CN102156717A (en) * 2011-03-25 2011-08-17 中国有色矿业集团有限公司 Method and device for mapping entity object into database

Cited By (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103647833A (en) * 2013-12-16 2014-03-19 百度在线网络技术(北京)有限公司 Continuous sequence number generation system and continuous sequence number generation method
CN105589699A (en) * 2014-10-20 2016-05-18 中兴通讯股份有限公司 Serial number information update method, device and terminal
CN105468718A (en) * 2015-11-18 2016-04-06 腾讯科技(深圳)有限公司 Data consistency processing method, device and system
CN105468718B (en) * 2015-11-18 2020-09-08 腾讯科技(深圳)有限公司 Data consistency processing method, device and system
CN105630991A (en) * 2015-12-25 2016-06-01 北京奇虎科技有限公司 Method and device for automatically generating ID
CN105630991B (en) * 2015-12-25 2019-11-01 北京奇虎科技有限公司 ID automatic generation method and device
CN106528220B (en) * 2016-10-27 2019-08-09 武汉奥泽电子有限公司 A kind of anti-repeated code automobile remote controllers sequence number programming system and method
CN106528220A (en) * 2016-10-27 2017-03-22 武汉奥泽电子有限公司 Anti-coincident-code programming system and method for serial number of automobile remote controller
CN107038191A (en) * 2016-11-15 2017-08-11 阿里巴巴集团控股有限公司 A kind of data processing method of database sequence, device and server
CN108243264A (en) * 2016-12-27 2018-07-03 中国移动通信有限公司研究院 A kind of sequence number generation method and system
CN108664521A (en) * 2017-04-01 2018-10-16 北京京东尚科信息技术有限公司 A kind of method, apparatus, electronic equipment and readable storage medium storing program for executing that sequence number is provided
WO2018177350A1 (en) * 2017-04-01 2018-10-04 北京京东尚科信息技术有限公司 Method and apparatus for providing serial number, electronic device and readable storage medium
CN108664521B (en) * 2017-04-01 2020-09-01 北京京东尚科信息技术有限公司 Method and device for providing serial number, electronic equipment and readable storage medium
US11314712B2 (en) 2017-04-01 2022-04-26 Beijing Jingdong Shangke Information Technology Co., Ltd. Method and apparatus for providing serial number, electronic device and readable storage medium
WO2019047351A1 (en) * 2017-09-11 2019-03-14 平安科技(深圳)有限公司 Method, device, electronic apparatus and medium for generating physical card number
CN109165712A (en) * 2018-08-01 2019-01-08 广州唯品会信息科技有限公司 Distributed generation method, device and computer storage medium by stages number
CN109165712B (en) * 2018-08-01 2021-06-29 广州唯品会信息科技有限公司 Method and device for generating distributed option number and computer storage medium
CN109656920A (en) * 2018-10-19 2019-04-19 中国建设银行股份有限公司 Sequence number processing method and system, device and storage medium
CN109656920B (en) * 2018-10-19 2021-08-27 中国建设银行股份有限公司 Serial number processing method, system, device and storage medium
CN112925787A (en) * 2019-12-06 2021-06-08 中国电信股份有限公司 Data processing method, device and computer readable storage medium
CN111949730A (en) * 2020-08-12 2020-11-17 中国银行股份有限公司 Distributed global sequence number implementation method and sequence distributor
CN111949730B (en) * 2020-08-12 2023-09-19 中国银行股份有限公司 Distributed global sequence number implementation method and sequence distributor

Also Published As

Publication number Publication date
CN103164418B (en) 2016-05-04
HK1182479A1 (en) 2013-11-29

Similar Documents

Publication Publication Date Title
CN103164418A (en) Method and device for processing serial numbers
CN103365929B (en) The management method of a kind of data base connection and system
CN109726174A (en) Data archiving method, system, equipment and storage medium
CN103106286B (en) Method and device for managing metadata
CN109923534A (en) To the Multi version concurrency control with the data-base recording for not submitting affairs
CN102110121A (en) Method and system for processing data
CN102750356A (en) Construction and management method for secondary indexes of key value library
CN110442329A (en) Generation method, device, storage medium and the computer equipment of code segment
CN105069134A (en) Method for automatically collecting Oracle statistical information
CN101699439A (en) Database transaction submitting method and device
US9086911B2 (en) Multiprocessing transaction recovery manager
CN102682071A (en) Efficient multi-version locking for main memory databases
CN105100050A (en) User permission management method and system
CN101807210A (en) Database data synchronic method, system and device
CN104182441A (en) Data sheet synchronization method and device
CN110309233A (en) Method, apparatus, server and the storage medium of data storage
CN103514177A (en) Data storage method and system
CN109739646A (en) A kind of data processing method and device
Mukherjee Synthesis of non-replicated dynamic fragment allocation algorithm in distributed database systems
CN102347869B (en) Method, device and system for monitoring equipment performance
CN110020272A (en) Caching method, device and computer storage medium
CN103365740A (en) Data cold standby method and device
CN102724301B (en) Cloud database system and method and equipment for reading and writing cloud data
CN110232095A (en) A kind of method of data synchronization, device, storage medium and server
CN103605761A (en) Data entry device and method based on templates

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 1182479

Country of ref document: HK

C14 Grant of patent or utility model
GR01 Patent grant
REG Reference to a national code

Ref country code: HK

Ref legal event code: GR

Ref document number: 1182479

Country of ref document: HK