A kind of distribution of ID mark and persistence method and system
Technical field
The present invention relates to router technology fields, and in particular to a kind of distribution of ID mark and persistence method and system.
Background technique
Router product includes many subsystems, and each subsystem includes many business modules, and each business module needs
Id is distributed for business keyword Key, and keeps the mapping relations between them in real time, guarantees the consistency of data.This
Under complex environment, distribution and the persistence for how managing ID mark are particularly important.ID mark is distributed and is held in existing router
Longization is responsible for by modules oneself, and defect is that ID mark is redistributed, moreover, restarting in single master control, masterslave switchover, distribution
Mapping relations between the Key value redistributed under the scenes such as formula board and Id, it cannot be guaranteed that the consistency of ID.
Therefore, it needs a kind of technical solution and solves the problems, such as that each business module ID mark of router product is redistributed, and
Solve the problems, such as that ID is inconsistent by restoring the mapping relations between Key and ID.
Summary of the invention
In view of the deficiencies in the prior art, the purpose of the present invention is to provide a kind of distribution of ID mark and persistence side
Method and system avoid each business module ID mark of router product from redistributing, but restore the mapping between Key and ID and close
System.
To achieve the above objectives, the technical solution adopted by the present invention is that: a kind of distribution of ID mark and persistence method are used
In the ID mark for distributing persistence for each business module of router, comprising the following steps:
It calls registration function to register the library IDAP, the module rope in the library IDAP is respectively distributed for each business module of router
Draw, setting ID allocation rule, KEY Value Types and KEY value comparison function;IDAP depositary management reason structure, institute are generated after registering the library IDAP
Stating IDAP depositary management reason structure includes the module index of IDAP, ID allocation rule, KEY Value Types and KEY value comparison function;It is described
The library IDAP is a kind of library lib, is used to distribute the ID mark of persistence for each business module of router;
Corresponding module handle is created for each module index, creates the corresponding IDAP library file of each module and the library IDAP
Filename;
When each business module is specified KEY value distribution ID, the corresponding ID of KEY value first is searched using KEY value comparison function
It whether there is, and if it exists, directly return to already present ID;If it does not exist, it is distributed according to ID allocation rule to the KEY value called
ID, and newly-increased KEY value and ID mapping relations list item, the KEY value and ID mapping relations list item include memory node in ID tree,
Memory node, ID, KEY value, the length of KEY and aging label in KEY tree;
IDAP library file, insertion and KEY value and ID mapping table is written into newly-increased KEY value and ID mapping relations list item
The corresponding list item handle of item;Periodic backups IDAP library file;
When module restarts or switches recovery, the IDAP library file of backup is read, whole KEY value in load id AP library file
It with ID mapping relations list item, reads the KEY value and ID value in list item and stores in the buffer, while aging label is set;
In business module recovery process, when business module is specified KEY value distribution ID, remove corresponding KEY value with
The aging of ID mapping relations list item marks;
After business module recovery, the KEY value and ID mapping relations list item of calling the aging of aging interface still to there is aging to mark.
Based on the above technical solution, the ID allocation rule includes ID allocation algorithm, smallest allocation ID and maximum
Distribute ID.
Based on the above technical solution, the module index include module service mark and srvice instance number, according to
The service field of router traffic module defines service identifiers, the corresponding srvice instance number of each router traffic module.
Based on the above technical solution, KEY Value Types include two kinds of forms of character string and structural body, if KEY value
Type be structural body, then business module provide structural body is formatted as character string method.
Based on the above technical solution, ID allocation algorithm includes smallest allocation algorithm, order-assigned algorithm and business
Custom algorithm;Smallest allocation algorithm is that the ID of every sub-distribution is currently available minimum ID;Order-assigned refers in order
Incremental manner distributes ID;The customized allocation algorithm of business distributes ID according to business actual conditions, needs business module to provide specific
Allocation algorithm.
Based on the above technical solution, IDAP depositary management reason structure further includes IDAP delay write timing device, last time
The written document time and whether start delay write timing device, the delay write timing device for periodically will be newly-increased KEY value with
IDAP library file is written in ID mapping relations list item.
The invention also discloses a kind of distribution of ID mark and persistent object system, it is used for as each business module distribution of router
The ID of persistence is identified, comprising:
The library IDAP registration module, the library IDAP registration module are router for calling registration function to register the library IDAP
Each business module respectively distributes the module index in a library IDAP, and setting ID allocation rule, KEY Value Types and KEY value compare letter
Number;It generates IDAP depositary management and manages structure, the IDAP depositary management reason structure includes the module index of IDAP, ID allocation rule, KEY value class
Type and KEY value comparison function;The library IDAP is a kind of library lib, is used to distribute persistence for each business module of router
ID mark;Create corresponding module handle for each module index, create the corresponding IDAP library file of each module handle and
IDAP library file name;
ID distribution module, the ID distribution module are used to first compare using KEY value when each business module calls KEY value
The corresponding ID of function lookup KEY value whether there is, and if it exists, directly return to already present ID;If it does not exist, it is distributed and is advised according to ID
Then ID is distributed to specified KEY value;
List item generation module, the list item generation module is for ID distribution module according to ID allocation rule to the KEY called
When value distributes new ID, KEY value and ID mapping relations list item are increased newly, the KEY value and ID mapping relations list item include in ID tree
Memory node, the memory node in KEY tree, ID, KEY value, the length of KEY, KEY label;
List item memory module, the KEY value and ID mapping relations list item that the list item memory module is used to increase newly are written
IDAP library file, insertion and KEY value list item handle corresponding with ID mapping relations list item;Periodic backups IDAP library file;
List item recovery module reads backup when the list item recovery module restarts for module or switches recovery
IDAP library file, whole KEY value and ID mapping relations list item in load id AP library file, reads the KEY value and ID value in list item
And it stores in the buffer, while being arranged and just changing label.
Based on the above technical solution, the ID mark distribution and persistent object system further include ageing module, described
For ageing module for system reboot or when switching recovery, aging is arranged in KEY value and ID mapping relations list item to all loads
Label removes the entry aging label of business module hit in business module recovery process;After business module recovery, adjust
The KEY value and ID mapping relations list item for still thering is aging to mark with the aging of aging interface.
Based on the above technical solution, the module index include module service mark and srvice instance number, according to
The service field of router traffic module defines service identifiers, and a service of each router traffic module can correspond to multiple
Srvice instance distinguishes different instances by srvice instance number.
Based on the above technical solution, IDAP depositary management reason structure further includes IDAP delay write timing device, last time
The written document time and whether start delay write timing device, the delay write timing device for periodically will be newly-increased KEY value with
IDAP library file is written in ID mapping relations list item.
Compared with the prior art, the advantages of the present invention are as follows:
The present invention calls registration function to register the library IDAP, and the mould in a library IDAP is respectively distributed for each business module of router
Block index, setting ID allocation rule, KEY Value Types and KEY value comparison function;It needs in each business module for specified KEY value
When distributing ID, ID is distributed to specified KEY value according to ID allocation rule;When module restarts or switches recovery, backup is read
IDAP library file, whole KEY value and ID mapping relations list item in load id AP library file, reads the KEY value and ID value in list item
And store in the buffer, while aging label is set, so that redistributing for each business module ID mark of router product is avoided,
The mapping relations between Key and ID before recovery.
Detailed description of the invention
Fig. 1 is a kind of flow diagram of ID mark distribution and persistence method in the embodiment of the present invention;
Fig. 2 is a kind of structural schematic diagram of ID mark distribution and persistent object system in the embodiment of the present invention.
Specific embodiment
Invention is further described in detail with reference to the accompanying drawings and embodiments.
Shown in Figure 1, the embodiment of the present invention provides a kind of distribution of ID mark and persistence method, is used for as router
Each business module distribution ID mark and the ID mark of persistence distribution, comprising the following steps:
S1 calls registration function to register the library IDAP, and the module in a library IDAP is respectively distributed for each business module of router
Index, setting ID allocation rule, KEY Value Types and KEY value comparison function;IDAP depositary management reason structure is generated after registering the library IDAP,
It includes the module index of IDAP, ID allocation rule, KEY Value Types and KEY value comparison function that structure is managed in IDAP depositary management;The library IDAP is
A kind of library lib is used to distribute the ID mark of persistence for each business module of router;Module index includes module service mark
With srvice instance number, service identifiers are defined according to the service field of router traffic module, each router traffic module is corresponding
One srvice instance number.KEY Value Types include two kinds of forms of character string and structural body, if the type of KEY value is structural body,
Business module provides the method that structural body is formatted as character string.
S2 creates corresponding module handle for each module index, creates the corresponding IDAP library file of each module handle
And IDAP library file name;
When each business module is specified KEY value distribution ID, it is corresponding first to search KEY value using KEY value comparison function by S3
ID whether there is, and if it exists, directly return to already present ID;If it does not exist, it is distributed according to ID allocation rule to the KEY value called
ID, and newly-increased KEY value and ID mapping relations list item, KEY value and ID mapping relations list item include memory node, KEY in ID tree
Memory node, ID, KEY value in tree, the length of KEY;ID allocation rule includes ID allocation algorithm, smallest allocation ID and maximum point
With ID.ID allocation algorithm includes smallest allocation algorithm, order-assigned algorithm and business custom algorithm;Smallest allocation algorithm is every
The ID of sub-distribution is currently available minimum ID;Order-assigned refers to incremental manner distribution ID in order;Customized point of business
ID is distributed according to business actual conditions with algorithm.
IDAP library file, insertion KEY value and ID mapping relations are written in newly-increased KEY value and ID mapping relations list item by S4
The corresponding list item handle of list item;Periodic backups IDAP library file;
S5 when module restarts or switches recovery, reads the IDAP library file of backup, whole in load id AP library file
KEY value and ID mapping relations list item read the KEY value and ID value in list item and store in the buffer, while aging label is arranged;
S6 when calling the KEY value or ID in caching in business module recovery process, removes corresponding KEY value and ID maps
The aging of relationship list item marks;
S7, after business module restores, the KEY value and ID mapping table of calling the aging of aging interface still to there is aging to mark
, terminate.
IDAP depositary management reason structure further includes whether IDAP postpones write timing device, last time written document time and start to prolong
Slow write timing device, delay write timing device is for being periodically written IDAP library file for newly-increased KEY value and ID mapping relations list item.
The invention also discloses a kind of distribution of ID mark and persistent object system, it is used for as each business module distribution of router
ID mark and the ID mark of persistence distribution, comprising:
The library IDAP registration module, the library IDAP registration module are that router is each for calling registration function to register the library IDAP
Business module respectively distributes the module index in a library IDAP, setting ID allocation rule, KEY Value Types and KEY value comparison function;It is raw
Structure is managed at IDAP depositary management, it includes the module index of IDAP, ID allocation rule, KEY Value Types and KEY value that structure is managed in IDAP depositary management
Comparison function;The library IDAP is a kind of library lib, is used to distribute the ID of ID mark and persistence distribution for each business module of router
Mark;Corresponding module handle is created for each module index, creates the corresponding IDAP library file of each module handle and IDAP
Library file name;
ID distribution module, ID distribution module are used to first use KEY value comparison function when each business module calls KEY value
Searching the corresponding ID of KEY value whether there is, and if it exists, directly return to already present ID;If it does not exist, it is given according to ID allocation rule
The KEY value of calling distributes ID;
List item generation module, list item generation module is for ID distribution module according to ID allocation rule to the KEY value point called
When with new ID, increase KEY value and ID mapping relations list item newly, KEY value and ID mapping relations list item include memory node in ID tree,
Memory node, ID, KEY value in KEY tree, the length of KEY;
The library IDAP is written in list item memory module, the KEY value and ID mapping relations list item that list item processing module is used to increase newly
File, insertion and KEY value list item handle corresponding with ID mapping relations list item;Periodic backups IDAP library file;
List item recovery module reads the library IDAP of backup when list item recovery module restarts for module or switches recovery
File, whole KEY value and ID mapping relations list item in load id AP library file read the KEY value and ID value in list item and store
In the buffer, while aging label is set.
The distribution of ID mark and persistent object system further include ageing module, system reboot or when switching recovery, to all plus
KEY value and ID mapping relations list item the setting aging of load mark, and in business module recovery process, remove business module hit
Entry aging label;After business module recovery, the KEY value and ID mapping relations of calling the aging of aging interface still to there is aging to mark
List item.
Module index includes module service mark and srvice instance number, is defined according to the service field of router traffic module
Service identifiers, the corresponding srvice instance number of each router traffic module.
IDAP depositary management reason structure further includes whether IDAP postpones write timing device, last time written document time and start to prolong
Slow write timing device, delay write timing device is for being periodically written IDAP library file for newly-increased KEY value and ID mapping relations list item.
The present invention is not limited to the above-described embodiments, for those skilled in the art, is not departing from
Under the premise of the principle of the invention, several improvements and modifications can also be made, these improvements and modifications are also considered as protection of the invention
Within the scope of.The content being not described in detail in this specification belongs to the prior art well known to professional and technical personnel in the field.