A kind of ID marks distribution and persistence method and system
Technical field
The present invention relates to router technology field, and in particular to a kind of ID marks distribution and persistence method and system.
Background technology
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, ensures the uniformity of data.This
Under complex environment, distribution and the persistence for how managing ID marks are particularly important.The distribution of ID marks is with holding in existing router
Longization is responsible for by modules oneself, and its defect is that ID marks are redistributed, moreover, restart in single master control, masterslave switchover, distribution
Mapping relations between the Key values and Id redistributed under the scenes such as formula board, it is impossible to ensure ID uniformity.
Therefore, need a kind of technical scheme badly and solve the problems, such as that each business module ID marks of router product are redistributed, and
Solve the problems, such as that ID is inconsistent by recovering the mapping relations between Key and ID.
The content of the invention
For defect present in prior art, it is an object of the invention to provide a kind of distribution of ID marks and persistence side
Method and system, avoid each business module ID marks of router product from redistributing, but recover the mapping between Key and ID and close
System.
To achieve the above objectives, the present invention adopts the technical scheme that:A kind of ID marks distribution and persistence method, it is used
In the ID marks that persistence is distributed for each business module of router, comprise the following steps:
Registration function registration IDAP storehouses are called, are the module rope that each business module of router respectively distributes an IDAP storehouse
Draw, ID allocation rules, KEY Value Types and KEY value comparison functions are set;IDAP library management structures, institute are generated after registering IDAP storehouses
Stating IDAP library managements structure includes IDAP module index, ID allocation rules, KEY Value Types and KEY value comparison functions;It is described
IDAP storehouses are a kind of lib storehouses, and it is used for the ID marks that persistence is distributed for each business module of router;
For module handle corresponding to the establishment of each module index, IDAP library files corresponding to each module and IDAP storehouses are created
Filename;
When each business module is the KEY values distribution ID specified, first ID corresponding to KEY values is searched using KEY values comparison function
It whether there is, if in the presence of directly returning to already present ID;If being not present, distributed according to ID allocation rules to the KEY values called
ID, and newly-increased KEY values and ID mapping relations list items, the KEY values and ID mapping relations list item including the memory node in ID trees,
Memory node, ID, KEY value, KEY length and aging mark in KEY trees;
By newly-increased KEY values and ID mapping relations list item write-in IDAP library files, insertion and KEY values and ID mapping tables
List item handle corresponding to;Periodic backups IDAP library files;
When module is restarted or switches recovery, the IDAP library files of backup are read, whole KEY values in load id AP library files
With ID mapping relations list items, read the KEY values in list item and ID values and store in the buffer, while set aging to mark;
In business module recovery process, business module be specify KEY values distribution ID when, KEY values corresponding to removing and
The aging mark of ID mapping relations list items;
After business module recovery, the aging of aging interface is called still to have the KEY values that aging marks and ID mapping relations list items.
On the basis of above-mentioned technical proposal, the ID allocation rules include ID allocation algorithms, smallest allocation ID and maximum
Distribute ID.
On the basis of above-mentioned technical proposal, the module index includes 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.
On the basis of above-mentioned technical proposal, KEY Value Types include two kinds of forms of character string and structure, if KEY values
Type be structure, then business module provide structure is formatted as to character string method.
On the basis of above-mentioned technical proposal, ID allocation algorithms include smallest allocation algorithm, order-assigned algorithm and business
Custom algorithm;Smallest allocation algorithm is that the ID per sub-distribution is currently available minimum ID;Order-assigned refers in order
Incremental manner distributes ID;The self-defined allocation algorithm of business distributes ID, it is necessary to which business module provides specifically according to business actual conditions
Allocation algorithm.
On the basis of above-mentioned technical proposal, IDAP library managements structure also includes IDAP delay write timings device, last time
The written document time and whether start delay write timing device, the delay write timing device be used for periodically by newly-increased KEY values and
ID mapping relations list item writes IDAP library files.
The invention also discloses a kind of distribution of ID marks and persistent object system, and it is used for for each business module distribution of router
The ID marks of persistence, including:
IDAP storehouses Registering modules, IDAP storehouses Registering modules are used to call registration function registration IDAP storehouses, are router
Each business module respectively distributes the module index in an IDAP storehouse, sets ID allocation rules, KEY Value Types and KEY values to compare letter
Number;Generate IDAP library management structures, module index of the IDAP library managements structure including IDAP, ID allocation rules, KEY value classes
Type and KEY value comparison functions;The IDAP storehouses are a kind of lib storehouses, and it is used to distribute persistence for each business module of router
ID is identified;For each module index create corresponding to module handle, create IDAP library files corresponding to each module handle and
IDAP library file names;
ID distribute modules, the ID distribute modules are used to, when each business module calls KEY values, first using KEY values compare
ID corresponding to function lookup KEY values whether there is, if in the presence of directly returning to already present ID;If being not present, distributed and advised according to ID
Then to the KEY values distribution ID specified;
List item generation module, the list item generation module are used for ID distribute modules according to ID allocation rules to the KEY called
When value distributes new ID, KEY values and ID mapping relations list items are increased newly, the KEY values include in ID trees with ID mapping relations list item
Memory node, the memory node in KEY trees, ID, KEY value, KEY length, KEY mark;
List item memory module, the list item memory module are used to write newly-increased KEY values and ID mapping relations list item
IDAP library files, insert list item handle corresponding with ID mapping relations list items with KEY values;Periodic backups IDAP library files;
List item recovery module, when the list item recovery module is restarted for module or switches recovery, read backup
IDAP library files, whole KEY values and ID mapping relations list items, read the KEY values and ID values in list item in load id AP library files
And store in the buffer, while set and just change mark.
On the basis of above-mentioned technical proposal, the ID marks distribution also includes ageing module with persistent object system, described
When ageing module is used for system reboot or switches recovery, KEY values and ID mapping relations list item to all loadings set aging
Mark, in business module recovery process, remove the list item aging mark of business module hit;After business module recovery, adjust
Still there are the KEY values that aging marks and ID mapping relations list items with the aging of aging interface.
On the basis of above-mentioned technical proposal, the module index includes 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 be correspondingly multiple
Srvice instance, different instances are distinguished by srvice instance number.
On the basis of above-mentioned technical proposal, IDAP library managements structure also includes IDAP delay write timings device, last time
The written document time and whether start delay write timing device, the delay write timing device be used for periodically by newly-increased KEY values and
ID mapping relations list item writes IDAP library files.
Compared with prior art, the advantage of the invention is that:
The present invention calls registration function registration IDAP storehouses, is the mould in one IDAP storehouse of each distribution of each business module of router
Block indexes, and sets ID allocation rules, KEY Value Types and KEY value comparison functions;The KEY values for needing to specify in each business module
When distributing ID, the KEY values specified are given to distribute ID according to ID allocation rules;When module is restarted or switches recovery, backup is read
IDAP library files, whole KEY values and ID mapping relations list items, read the KEY values and ID values in list item in load id AP library files
And store in the buffer, while set aging to mark, so as to avoid redistributing for each business module ID marks of router product,
The mapping relations between Key and ID before recovery.
Brief description of the drawings
Fig. 1 is a kind of ID marks distribution and the schematic flow sheet of persistence method in the embodiment of the present invention;
Fig. 2 is a kind of ID marks distribution and the structural representation of persistent object system in the embodiment of the present invention.
Embodiment
The present invention is described in further detail below in conjunction with drawings and Examples.
Shown in Figure 1, the embodiment of the present invention provides a kind of ID marks distribution and persistence method, and it is used for for router
Each business module distribution ID marks and the ID marks of persistence distribution, comprise the following steps:
S1, registration function registration IDAP storehouses are called, be the module that each business module of router respectively distributes an IDAP storehouse
Index, ID allocation rules, KEY Value Types and KEY value comparison functions are set;IDAP library management structures are generated after registering IDAP storehouses,
IDAP library managements structure includes IDAP module index, ID allocation rules, KEY Value Types and KEY value comparison functions;IDAP storehouses are
A kind of lib storehouses, it is used for the ID marks that persistence is distributed for each business module of router;Module index identifies including module service
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 structure, if the type of KEY values is structure,
Business module provides the method that structure is formatted as to character string.
S2, for module handle corresponding to the establishment of each module index, create IDAP library files corresponding to each module handle
And IDAP library file names;
S3, when each business module is the KEY values distribution ID specified, first searched using KEY values comparison function corresponding to KEY values
ID whether there is, if in the presence of directly returning to already present ID;If being not present, distributed according to ID allocation rules to the KEY values called
ID, and newly-increased KEY values and ID mapping relations list items, KEY values include memory node, KEY in ID trees with ID mapping relations list item
Memory node, ID, KEY value in tree, KEY length;ID allocation rules include ID allocation algorithms, smallest allocation ID and maximum point
With ID.ID allocation algorithms include 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;Self-defined point of business
With algorithm ID is distributed according to business actual conditions.
S4, newly-increased KEY values and ID mapping relations list item are write into IDAP library files, insertion KEY values and ID mapping relations
List item handle corresponding to list item;Periodic backups IDAP library files;
S5, when module is restarted or switches recovery, read the IDAP library files of backup, in load id AP library files all
KEY values and ID mapping relations list items, read the KEY values in list item and ID values and store in the buffer, while set aging to mark;
S6, when the KEY values or ID in caching are called in business module recovery process, KEY values corresponding to removing and ID mappings
The aging mark of relation list item;
S7, after business module recovers, the aging of aging interface is called still to have the KEY values that aging marks and ID mapping tables
, terminate.
Whether IDAP library managements structure also includes IDAP delay write timings device, last time written document time and starts to prolong
Slow write timing device, delay write timing device are used to newly-increased KEY values and ID mapping relations list item periodically are write into IDAP library files.
The invention also discloses a kind of distribution of ID marks and persistent object system, and it is used for for each business module distribution of router
ID is identified and the ID marks of persistence distribution, including:
IDAP storehouses Registering modules, IDAP storehouses Registering modules are used to call registration function registration IDAP storehouses, are that router is each
Business module respectively distributes the module index in an IDAP storehouse, sets ID allocation rules, KEY Value Types and KEY value comparison functions;It is raw
Into IDAP library management structures, IDAP library managements structure includes IDAP module index, ID allocation rules, KEY Value Types and KEY values
Comparison function;IDAP storehouses are a kind of lib storehouses, and it is used for the ID that ID marks and persistence distribution are distributed for each business module of router
Mark;For module handle corresponding to the establishment of each module index, IDAP library files and IDAP corresponding to each module handle are created
Library file name;
ID distribute modules, ID distribute modules are used for when each business module calls KEY values, first using KEY value comparison functions
ID corresponding to searching KEY values whether there is, if in the presence of directly returning to already present ID;If being not present, given according to ID allocation rules
The KEY values distribution ID of calling;
List item generation module, list item generation module are used for ID distribute modules according to ID allocation rules to the KEY values point called
During with new ID, increase KEY values and ID mapping relations list items newly, KEY values and ID mapping relations list item including the memory node in ID trees,
Memory node, ID, KEY value in KEY trees, KEY length;
List item memory module, list item processing module are used to newly-increased KEY values and ID mapping relations list item writing IDAP storehouses
File, insert list item handle corresponding with ID mapping relations list items with KEY values;Periodic backups IDAP library files;
List item recovery module, when list item recovery module is restarted for module or switches recovery, read the IDAP storehouses of backup
File, whole KEY values and ID mapping relations list items in load id AP library files, reads the KEY values in list item and ID values and stores
In the buffer, while aging is set to mark.
ID mark distribution also includes ageing module with persistent object system, system reboot or when switching recovery, adds to all
The KEY values of load set aging to mark with ID mapping relations list item, in business module recovery process, remove business module hit
List item aging marks;After business module recovery, the aging of aging interface is called still to have the KEY values that aging marks and ID mapping relations
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.
Whether IDAP library managements structure also includes IDAP delay write timings device, last time written document time and starts to prolong
Slow write timing device, delay write timing device are used to newly-increased KEY values and ID mapping relations list item periodically are write into IDAP library files.
The present invention is not limited to the above-described embodiments, for those skilled in the art, is not departing from
On the premise of the principle of the invention, some improvements and modifications can also be made, these improvements and modifications are also considered as the protection of the present invention
Within the scope of.The content not being described in detail in this specification belongs to prior art known to professional and technical personnel in the field.