A kind of data-updating method and device
Technical field
The present invention relates to computer realm, more particularly to a kind of data-updating method and device.
Background technology
Subscription/renewal(Pub/Sub)Model is how to issue and subscribe to the model of message, message hair to a content node
News release to content node, message subscribing person are subscribed to message by cloth person from content node.The message of subscription/renewal is closed by message
Key word(key)Data value corresponding with the message(value)Composition, general message key is constant, corresponding with the message
Value frequently changes, it is therefore desirable to timely update value values so that message subscribing person can timely and accurately read
Ordered message content.
At present, the KV in existing Pub/Sub models(key-value)Data update main method be:Disappear multiple
Cease respective key and value storages and distribute an entry reference into tables of data 1, and for the tables of data 1, visitor enters at this
Data message is obtained in the tables of data that mouth pointer is pointed to, tables of data 1 is replicated(n-1)Part, copy table is designated as tables of data 2, data
Table 3 ... tables of data n, will be to be updated in tables of data 2- tables of data n when the data value changes for having message need to update the data
Data are updated, and when the data in tables of data 2- tables of data n are updated, now visitor obtains number by entry reference
According to the data in table 1.After the completion of the data in tables of data 2- tables of data n update, the entry reference is pointed into tables of data 2, when
When having new visitor, the new visitor obtains the data in tables of data 2 by entry reference, now still has in tables of data 1
The data that the former visitor in part does not update in reading.When the data value changes for having message again need to update the data, in data
Data to be updated are updated in table 3- tables of data n, above-mentioned data updating process is repeated.
Above-mentioned existing KV data-updating methods, due to being carried out more when updating the data, it is necessary to which tables of data is replicated into many parts
Newly, tables of data occupies substantial amounts of memory headroom, causes the waste of system resource.
The content of the invention
The embodiment of the present invention provides a kind of data-updating method and device, to solve the presence of system resource in the prior art
Waste the problem of.
The embodiment of the present invention provides a kind of data-updating method, including:
When there is data to need renewal, it will update the data in idle storage space of the storage into tables of data;
Corresponding data directory and the storage address pair updated the data in the tables of data are updated the data by described
It should store in renewal queue;
The corresponding storage address of corresponding data directory is updated the data using described in the renewal queue, index ground is updated
Storage address corresponding with the data directory in the table of location, index address table have recorded the data of the data stored in the tables of data
The corresponding relation of the storage address of index and the data of storage in the tables of data.
Using the above method provided in an embodiment of the present invention, due to tables of data need not be replicated to many parts, the internal memory of occupancy
Space is small, saves system resource.
Further, the above method, in addition to:
When there is new data to need storage, by new data storage into the idle storage space in the tables of data;
Deposit storage address of the corresponding data directory of the new data with the new data in the tables of data is corresponding
Store up in the renewal queue;
By the corresponding data directory of new data and the new data described in the renewal queue in the tables of data
Storage address, correspondence storage is into index address table.
Further, the above method, in addition to:
Remove and corresponding former data are updated the data described in the tables of data.
So, the tables of data can have enough idle storage space storages to update the data or new data.
The embodiment of the present invention also provides a kind of method that data are read in tables of data from above-mentioned data-updating method, bag
Include:
From the duplication index address table of the index address table, the corresponding storage of data directory of data to be read is inquired about
Address, the duplication index address epitope is local in the visitor of the tables of data;
The data stored in the corresponding memory space of the storage address are read from the tables of data.
Further, the above method, in addition to:
Using it is described renewal queue in the corresponding storage address of data directory, update it is described duplication index address table in
The corresponding storage address of the data directory.
The embodiment of the present invention also provides a kind of data update apparatus, including:
First memory cell, is deposited for when there is data to need renewal, will update the data free time of the storage into tables of data
Store up in space;
Second memory cell, for updating the data corresponding data directory by described and described updating the data in the data
Storage address correspondence storage in table is into renewal queue;
Index address table updating block, for updating the data corresponding data directory pair using described in the renewal queue
The storage address answered, updates storage address corresponding with the data directory in index address table, index address table have recorded described
The corresponding relation of the storage address of the data directory of the data stored in tables of data and the data of storage in the tables of data.
Using said apparatus provided in an embodiment of the present invention, due to tables of data need not be replicated to many parts, the internal memory of occupancy
Space is small, saves system resource.
Further, said apparatus, in addition to:
3rd memory cell, for when there is new data to need storage, by new data storage to the sky in the tables of data
In not busy memory space;
4th memory cell, for by the corresponding data directory of the new data and the new data in the tables of data
Storage address correspondence storage to it is described renewal queue in;
5th memory cell, for updating the corresponding data directory of new data and the new data described in queue by described
Storage address in the tables of data, correspondence storage is into index address table.
Further, said apparatus, in addition to:
Clearing cell, corresponding former data are updated the data for removing described in the tables of data.
So, the tables of data can have enough idle storage space storages to update the data or new data.
The embodiment of the present invention also provides the device that data are read in a kind of tables of data from above-mentioned data update apparatus, bag
Include:
Query unit, for from the duplication index address table of the index address table, inquiring about the data of data to be read
Corresponding storage address is indexed, the duplication index address epitope is local in the visitor of the tables of data;
Reading unit, for reading the data stored in the corresponding memory space of the storage address from the tables of data.
Further, said apparatus, in addition to:
Index address table updating block is replicated, for using the corresponding storage of data directory in the renewal queue
Location, updates storage address corresponding with the data directory in the duplication index address table.
Other features and advantage will be illustrated in the following description, also, partly be become from specification
Obtain it is clear that or being understood by implementing the application.The purpose of the application and other advantages can be by the explanations write
Specifically noted structure is realized and obtained in book, claims and accompanying drawing.
Brief description of the drawings
Accompanying drawing is used for providing a further understanding of the present invention, and constitutes a part for specification, with present invention implementation
Example is used to explain the present invention together, is not construed as limiting the invention.In the accompanying drawings:
Fig. 1 is the flow chart of data-updating method provided in an embodiment of the present invention;
Fig. 2 is the flow chart of the data-updating method provided in the embodiment of the present invention 1;
Fig. 3 be the embodiment of the present invention 2 in provide from the tables of data in data-updating method provided in an embodiment of the present invention
The flow chart of the middle method for reading data;
Fig. 4 is the structural representation of the data update apparatus provided in the embodiment of the present invention 3;
Fig. 5 is to be read in the tables of data from the embodiment of the present invention 3 in data update apparatus that provides in the embodiment of the present invention 4
The structural representation of the device for evidence of fetching.
Embodiment
The implementation of system resource is saved when carrying out data renewal to be given at, the embodiments of the invention provide one kind
The preferred embodiments of the present invention are illustrated by data-updating method and device below in conjunction with Figure of description, it will be appreciated that this
The preferred embodiment of place description is merely to illustrate and explain the present invention, and is not intended to limit the present invention.And what is do not conflicted
In the case of, the feature in embodiment and embodiment in the application can be mutually combined.
The embodiment of the present invention provides a kind of data-updating method, as shown in figure 1, including:
Step 101, when there is data to need renewal, will update the data in idle storage space of the storage into tables of data.
Step 102, this is updated the data into corresponding data directory and this updates the data the storage address in the tables of data
Correspondence storage is into renewal queue.
Step 103, the corresponding storage address of corresponding data directory is updated the data using this in the renewal queue, update rope
Draw storage address corresponding with the data directory in address table, index address table have recorded the number of the data stored in the tables of data
According to the corresponding relation of the storage address of index and the data of storage in the tables of data.
In method shown in above-mentioned Fig. 1 provided in an embodiment of the present invention, the data directory is usually constant, the data directory
Corresponding data often change, and can be that data in the tables of data change and need to update the tables of data, can also
It is to have new data to generate, it is necessary to the new data be stored into the tables of data, so as to update the tables of data.Wherein, the tables of data,
The renewal queue and the index address table can be in shared memories(SHM, Share Memory)Upper to create, the tables of data can be with
For slab tables, the index address table can be B-tree, by the data directory of the data stored in tables of data and the data of storage at this
The corresponding relation of storage address in tables of data is stored onto the node of B-tree.
Further, visitor can be from the tables of data in the method shown in above-mentioned Fig. 1 provided in an embodiment of the present invention
Data are read, the index address table is copied to the data rope that data to be read are locally inquired about from the duplication index address table
Draw corresponding storage address, data to be read are read in the tables of data according to the storage address.
Below in conjunction with the accompanying drawings, the method and device provided with specific embodiment the present invention is described in detail.
Embodiment 1:
Fig. 2 is a kind of flow chart for data-updating method that the embodiment of the present invention 1 is provided, and specifically includes following processing step
Suddenly:
Step 201, when there is data to need renewal, will update the data in idle storage space of the storage into tables of data.
Step 202, this is updated the data into corresponding data directory and this updates the data the storage address pair in the tables of data
It should store in renewal queue.
Wherein, the renewal queue can for update round-robin queue, when by this update the data corresponding data directory and this more
It is each in round-robin queue to update when the corresponding storage of new data storage address in the tables of data is into the renewal round-robin queue
Individual data directory distributes a time marking respectively, and the time marking represents data directory storage corresponding with the data directory
Address enters the time of the renewal round-robin queue.
When the active position of the data directory stored in the renewal round-robin queue storage address corresponding with the data directory
Quantity is more than when presetting effective number of positions, and the time that the renewal round-robin queue is indicated entry into from round-robin queue is updated is earliest
Time marking starts, and deletes the data directory storage address corresponding with the data directory for presetting effective number of positions;Or work as
Update round-robin queue in data directory storage address corresponding with the data directory storage time apart from current time when
Between difference be more than preset time it is poor when, delete data directory storage address corresponding with data directory, in this manner it is ensured that this
Update round-robin queue in have all the time enough clear positions be used for store update the data corresponding data directory and this update the data
Storage address in tables of data, wherein, it is poor that this presets effective number of positions, the default index address quantity, the preset time
According to practical experience and it can need flexibly to be set.
Step 203, the corresponding storage address of corresponding data directory is updated the data using this in the renewal queue, update rope
Draw storage address corresponding with the data directory in address table.
Wherein, the index address table have recorded the data directory of the data stored in the tables of data and the data of storage at this
The corresponding relation of storage address in tables of data.
In this step, corresponding data can be updated the data using this in the renewal queue at interval of the default update cycle
Corresponding storage address is indexed, storage address corresponding with the data directory in index address table is updated, wherein, the default renewal
Cycle can flexibly be set according to practical experience and needs, for example, the default update cycle can be 200 milliseconds.
Step 204, when there is new data to need storage, by new data storage to the idle storage space in the tables of data
In.
Step 205, the storage address by the corresponding data directory of the new data with the new data in the tables of data are corresponding
Store in the renewal queue.
It is in this step, storage address of the corresponding data directory of the new data with the new data in the tables of data is corresponding
The processing method for storing renewal queue use is identical with the processing method that above-mentioned steps 202 are used, and no longer carries out herein detailed
Thin description.
Step 206, by the corresponding data directory of the new data and the new data in the renewal queue in the tables of data
Storage address, correspondence storage is into index address table.
, can be at interval of the default update cycle, by the corresponding data directory of the new data in the renewal queue in this step
With storage address of the new data in the tables of data, correspondence storage is into index address table.
There is no strict sequencing between above-mentioned steps 204-206 and step 201-203, step 204- can be first carried out
206, then step 201-203 is performed, step 201-202 and step 204-205 can also be first carried out, then perform step 203 and step
Rapid 206.
Step 207, remove this in the tables of data and update the data corresponding former data.
In this step, this in the tables of data can be updated the data into corresponding former data when default cycle of removing is reached
Remove, wherein, the default cycle of removing can flexibly be set according to practical experience and needs, be removed preferably, this is preset
Cycle can be 2.5 times of default update cycle.
Further, can be by the corresponding data rope of the data to be deleted when there is the data in tables of data to need deletion
Draw in queue is updated corresponding storage address labeled as available, when updating the data or new data is assigned to labeled as available
During memory space in the corresponding tables of data of storage address, it can use that this is updated the data or the new data replaces the memory space
Interior data to be deleted.
The method provided by the above embodiment of the present invention, due to tables of data need not be replicated to many parts, the internal memory of occupancy
Space is small, saves system resource.
Embodiment 2:
Tables of data in the data-updating method provided according to the above embodiment of the present invention, the embodiment of the present invention 2 is also provided
A kind of method that data are read from the tables of data, as shown in figure 3, specifically include following process step:
Step 301, the visitor replicate to the index address table.
In this step, the visitor can be according to the index address table of this on SHM, by the data rope in the index address table
Draw storage address corresponding with the data directory to copy in local index address table, using local index address table as again
Index address table processed.The visitor will can also look into according to the data directory itself subscribed in the index address table on SHM
The data directory to be subscribed to looked for storage address corresponding with the data directory to be subscribed to is copied in local index address table, will
Local index address table is used as duplication index address table.
Step 302, the visitor replicate the data directory storage address corresponding with the data directory updated in queue.
In this step, the visitor can replicate data directory in the renewal queue on SHM at interval of the default update cycle
Storage address corresponding with the data directory, or the visitor can travel through and update in queue at interval of the default update cycle
Data directory, the data directory that the visitor is subscribed to storage address corresponding with the data directory replicated.Wherein, should
The default update cycle can flexibly be set according to practical experience and needs, for example, the default update cycle can be 200 millis
Second.
Step 303, the visitor use the corresponding storage address of data directory of the duplication, updates the visitor local
Replicate storage address corresponding with the data directory in index address table.
Step 304, the visitor are from the duplication index address table, and the data directory of inquiry data to be read is corresponding to be deposited
Store up address.
In this step, the data for replicating the data to be read in index address table that the visitor can be inquired about after the renewal
Corresponding storage address is indexed, can also be when the duplication index address table update, the duplication index inquired about before updating
The corresponding storage address of data directory of data to be read in address table, due to CPU physical limit, it is ensured that to be read
The corresponding storage address of data directory of data is effective.
Step 305, the visitor read the data stored in the corresponding memory space of the storage address from the tables of data.
Embodiment 3:
Based on same inventive concept, the data-updating method provided according to the above embodiment of the present invention, correspondingly, the present invention
Embodiment 3 additionally provides a kind of data update apparatus, and its structural representation is as shown in figure 4, specifically include:
First memory cell 401, for when there is data to need renewal, free time of the storage into tables of data will to be updated the data
In memory space;
Second memory cell 402, for updating the data corresponding data directory by described and described updating the data described
Storage address correspondence storage in tables of data is into renewal queue;
Index address table updating block 403, for updating the data corresponding data rope using described in the renewal queue
Draw corresponding storage address, update storage address corresponding with the data directory in index address table, index address table have recorded
The correspondence pass of the storage address of the data directory of the data stored in the tables of data and the data of storage in the tables of data
System.
Further, said apparatus, in addition to:
3rd memory cell 404, for when there is new data to need storage, by new data storage into the tables of data
In idle storage space;
4th memory cell 405, for by the corresponding data directory of the new data and the new data in the data
Storage address correspondence storage in table is into the renewal queue;
5th memory cell 406, for updating the corresponding data directory of new data described in queue and described new by described
Storage address of the data in the tables of data, correspondence storage is into index address table.
Further, said apparatus, in addition to:
Clearing cell 407, corresponding former data are updated the data for removing described in the tables of data.
Embodiment 4:
The embodiment of the present invention 4 additionally provides the dress that data are read in a kind of tables of data from above-mentioned data update apparatus
Put, as shown in figure 5, including:
Query unit 501, for from the duplication index address table of the index address table, inquiring about the number of data to be read
According to corresponding storage address is indexed, the duplication index address epitope is local in the visitor of the tables of data;
Reading unit 502, for reading the number stored in the corresponding memory space of the storage address from the tables of data
According to.
Further, said apparatus, in addition to:
Index address table updating block 503 is replicated, for using the corresponding storage of data directory in the renewal queue
Address, updates storage address corresponding with the data directory in the duplication index address table.
The respective handling step that the function of above-mentioned each unit may correspond in flow shown in Fig. 1 or Fig. 2, no longer goes to live in the household of one's in-laws on getting married herein
State.
In summary, scheme provided in an embodiment of the present invention, including:When there are data to need renewal, deposited updating the data
Store up in the idle storage space in tables of data;This is updated the data into corresponding data directory and this is updated the data in the tables of data
In storage address correspondence storage to update queue in;Using the corresponding storage address of data directory in the renewal queue, more
Storage address corresponding with the data directory in new index address table, index address table have recorded the data stored in the tables of data
Data directory and storage storage address of the data in the tables of data corresponding relation.Using provided in an embodiment of the present invention
Scheme, compared with prior art, it is not necessary to tables of data is replicated many parts, the memory headroom of occupancy is small, saves system resource.
The data update apparatus that embodiments herein is provided can be realized by computer program.Those skilled in the art
It should be appreciated that above-mentioned Module Division mode is only one kind in numerous Module Division modes, if being divided into other moulds
Block or non-division module, all should be within the protection domain of the application as long as data update apparatus has above-mentioned functions.
The application is with reference to method, the equipment according to the embodiment of the present application(System)And the flow of computer program product
Figure and/or block diagram are described.It should be understood that can be by every first-class in computer program instructions implementation process figure and/or block diagram
Journey and/or the flow in square frame and flow chart and/or block diagram and/or the combination of square frame.These computer programs can be provided
The processor of all-purpose computer, special-purpose computer, Embedded Processor or other programmable data processing devices is instructed to produce
A raw machine so that produced by the instruction of computer or the computing device of other programmable data processing devices for real
The device for the function of being specified in present one flow of flow chart or one square frame of multiple flows and/or block diagram or multiple square frames.
These computer program instructions, which may be alternatively stored in, can guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works so that the instruction being stored in the computer-readable memory, which is produced, to be included referring to
Make the manufacture of device, the command device realize in one flow of flow chart or multiple flows and/or one square frame of block diagram or
The function of being specified in multiple square frames.
These computer program instructions can be also loaded into computer or other programmable data processing devices so that in meter
Series of operation steps is performed on calculation machine or other programmable devices to produce computer implemented processing, thus in computer or
The instruction performed on other programmable devices is provided for realizing in one flow of flow chart or multiple flows and/or block diagram one
The step of function of being specified in individual square frame or multiple square frames.
Obviously, those skilled in the art can carry out the essence of various changes and modification without departing from the present invention to the present invention
God and scope.So, if these modifications and variations of the present invention belong to the scope of the claims in the present invention and its equivalent technologies
Within, then the present invention is also intended to comprising including these changes and modification.