Summary of the invention
In view of this, this application provides a kind of date storage method being applied to intelligence grain depot and device, for solve prior art need to record in achieving item ID and store this item historical data memory area index information between corresponding relation, thus the problem reducing database purchase ability.
To achieve these goals, it is proposed that scheme as follows:
A kind of date storage method being applied to intelligence grain depot, including:
Receiving the storage request of item, described storage request includes item ID, historical data and timestamp;
Preset index page allocation strategy, record block allocation strategy is inquired about under the root achieved, wherein, described index page allocation strategy defines item ID and manipulative indexing page position, described record block allocation strategy defines item ID and corresponding record block position, described archive has divided according to page in advance, and described record block is made up of some pages;
According to described record block allocation strategy, search and described target record block corresponding for item ID;
Described historical data is filled into described target record block;
According to described index page allocation strategy, search and described target index page corresponding for item ID;
By the index information of described target record block and described timestamp record at described target index page.
Preferably, described described historical data is filled into described target record block, including:
Described historical data is carried out real non-destructive compression, obtains Real Time Compression data;
Described Real Time Compression data are filled in the record page of buffer memory;
Judge whether the occupied state of described record page reaches preset occupied state, if so, then described record page is carried out static text compression, obtain compression blocks;
Described compression blocks is filled in described target record block.
Preferably, also include:
Judge whether described target index page is filled with;
If so, according to described index page allocation strategy, distribute new index page for described item, and the index information of new index page is added in a upper index page.
Preferably, also include:
Judging whether the number of the index page corresponding with described item reaches threshold value, wherein, the index page corresponding with described item is as the one-level index page of described item;
If so, it is that described item creates secondary index page, described secondary index page records the index information of the one-level index page of rheme number to some extent.
Preferably, also include:
The first one-level index page of the secondary index page of described item Yu described item is carried out place-exchange.
A kind of data storage device being applied to intelligence grain depot, including:
Storage request reception unit, for receiving the storage request of item, described storage request includes item ID, historical data and timestamp;
Root query unit, for inquiring about preset index page allocation strategy, record block allocation strategy under the root achieved, wherein, described index page allocation strategy defines item ID and manipulative indexing page position, described record block allocation strategy defines item ID and corresponding record block position, described archive has divided according to page in advance, and described record block is made up of some pages;
Target record block searches unit, for according to described record block allocation strategy, searching and described target record block corresponding for item ID;
Historical data fills unit, for described historical data is filled into described target record block;
Target index page searches unit, for according to described index page allocation strategy, searching and described target index page corresponding for item ID;
Target index page record unit, for by the index information of described target record block and described timestamp record at described target index page.
Preferably, described historical data filling unit includes:
Lossless compression unit, for described historical data is carried out real non-destructive compression, obtains Real Time Compression data;
Real Time Compression data fill unit, for being filled in the record page of buffer memory by described Real Time Compression data;
Record page condition adjudgement unit, for judging whether the occupied state of described record page reaches preset occupied state;
Static Compression unit, for when the judged result of described record page condition adjudgement unit is for being, carrying out static text compression by described record page, obtain compression blocks;
Compression blocks fills unit, for being filled in described target record block by described compression blocks.
Preferably, also include:
Target index page judging unit, is used for judging whether described target index page is filled with;
New index page allocation units, for when the judged result of described target index page judging unit is for being, according to described index page allocation strategy, distributing new index page for described item, and be added in a upper index page by the index information of new index page.
Preferably, also include:
Index page number judging unit, for judging whether the number of the index page corresponding with described item reaches threshold value, wherein, the index page corresponding with described item is as the one-level index page of described item;
Secondary index page creating unit, for when the judged result of described index page number judging unit is for being, creating secondary index page for described item, record the index information of the one-level index page of rheme number to some extent in described secondary index page.
Preferably, also include:
Index page place-exchange unit, for carrying out place-exchange by the secondary index page of described item and the first one-level index page of described item.
Can be seen that from above-mentioned technical scheme, what the embodiment of the present application provided is applied to the date storage method of intelligence grain depot, in advance archive is divided according to page, and prestored index page allocation strategy and record block allocation strategy under the root achieved, wherein, index page allocation strategy defines item ID and manipulative indexing page position, and record block allocation strategy defines item ID and corresponding record block position, and record block is made up of some pages. When the storage receiving the item carrying item ID, historical data and timestamp is asked, preset index page allocation strategy and record block allocation strategy is inquired about under the root achieved, according to record block allocation strategy, the target record block corresponding with item ID is searched from the free area achieved, historical data is filled into target record block, according to index page allocation strategy, search the target index page corresponding with item ID, by the index information of target record block and timestamp record at target index page. The date storage method of the application, prespecified index page allocation strategy and record block allocation strategy, determine record block and index page according to above-mentioned two strategy during storage item, store historical data in record block, index page stores index information and the timestamp of record block, according to item ID and index page allocation strategy and record block allocation strategy, historical data corresponding to item ID can be inquired about during subsequent query item historical data. Owing to the application need not record the corresponding relation between the index information of each item ID and record block in archive, save the space of archive, improve the storage capacity of data base.
Detailed description of the invention
Below in conjunction with the accompanying drawing in the embodiment of the present application, the technical scheme in the embodiment of the present application is clearly and completely described, it is clear that described embodiment is only some embodiments of the present application, rather than whole embodiments. Based on the embodiment in the application, the every other embodiment that those of ordinary skill in the art obtain under not making creative work premise, broadly fall into the scope of the application protection.
Before introducing the application scheme, first introduce archive. Archive has been divided for minimum unit by the application with page, and specifies root page, index page and record block, wherein, root page, index page size can be one page, the size of record block can be multipage, such as 4 pages.
The application presets index page allocation strategy and record block allocation strategy, and the two strategy has been preserved under the root directory. Record block is for storing the historical data of item, and index page is used for storing the index information of record block and the timestamp of item.
For index page allocation strategy and record block allocation strategy, it can have multiple, as shown in Figure 1, the application can set that the first index page of item is positioned at and achieves the page that the page number is identical with described item, namely stores index page corresponding to each item ID backward successively from achieving head (removing root page). Simultaneously, for record block, it according to the allocation strategy contrary with index page, can store forward from achieving afterbody successively, such as item ID be 1 record block be positioned at archive last record block, item ID be 2 record block be positioned at archive penultimate record block.
Certainly, above-mentioned merely illustrating a kind of optional allocation strategy, in addition the application can also set the allocation strategy of other index page and record block.
It is a kind of date storage method flow chart being applied to intelligence grain depot disclosed in the embodiment of the present application referring to Fig. 2, Fig. 2.
As in figure 2 it is shown, the method includes:
Step S200, receive item storage request;
Wherein, described storage request includes item ID, historical data and timestamp. Further, can also carrying Quality Codes in request, Quality Codes represents a kind of state of item.
For the historical data of item, its needs preserve for a long time, it is therefore desirable to be stored in archive, and the history trendline time of the timestamp of log history data, timestamp namely historical data.
The historical data of item can be the intelligence multiparameter monitoring the state of foodstuff data of grain depot, multiparameter grain feelings alert data etc.
Step S210, under the root achieved, inquire about preset index page allocation strategy, record block allocation strategy;
Wherein, described index page allocation strategy defines item ID and manipulative indexing page position, and described record block allocation strategy defines item ID and corresponding record block position, and described archive has divided according to page in advance, and described record block is made up of some pages.
Step S220, according to described record block allocation strategy, search and described target record block corresponding for item ID;
Specifically, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target record block found in this step is likely to stored have historical data. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target record block that this finds is idle block.
Step S230, described historical data is filled into described target record block;
Step S240, according to described index page allocation strategy, search and described target index page corresponding for item ID;
Similar with above-mentioned target record block, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target index page found in this step is likely to stored have index information and timestamp. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target index page that this finds is idle index page.
Step S250, by the index information of described target record block and described timestamp record at described target index page.
Specifically, the index information of target record block can include target record block positional information in achieving.
By the index information of record object record block in the index page corresponding with item ID, during subsequent query item historical data, by inputting item ID, find and corresponding for the item ID index page inputted according to preset index page allocation strategy, and then according to the index information of record block of record in index page and timestamp, find the record block of correspondence, therefrom read historical data.
What the embodiment of the present application provided is applied to the date storage method of intelligence grain depot, prespecified index page allocation strategy and record block allocation strategy, determine record block and index page according to above-mentioned two strategy during storage item, store historical data in record block, index page stores index information and the timestamp of record block, according to item ID and index page allocation strategy and record block allocation strategy, historical data corresponding to item ID can be inquired about during subsequent query item historical data. Owing to the application need not record the corresponding relation between the index information of each item ID and record block in archive, save the space of archive, improve the storage capacity of data base.
It is the date storage method flow chart that another kind disclosed in the embodiment of the present application is applied to intelligence grain depot referring to Fig. 3, Fig. 3.
As it is shown on figure 3, the method includes:
Step S300, receive item storage request;
Wherein, described storage request includes item ID, historical data and timestamp. Further, can also carrying Quality Codes in request, Quality Codes represents a kind of state of item.
For the historical data of item, its needs preserve for a long time, it is therefore desirable to be stored in archive, and the history trendline time of the timestamp of log history data, timestamp namely historical data.
Step S310, under the root achieved, inquire about preset index page allocation strategy, record block allocation strategy;
Wherein, described index page allocation strategy defines item ID and manipulative indexing page position, and described record block allocation strategy defines item ID and corresponding record block position, and described archive has divided according to page in advance, and described record block is made up of some pages.
Step S320, according to described record block allocation strategy, search and described target record block corresponding for item ID;
Specifically, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target record block found in this step is likely to stored have historical data. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target record block that this finds is idle block.
Step S330, described historical data is carried out real non-destructive compression, obtain Real Time Compression data;
Specifically, real non-destructive compression is a kind of lossless compressiong being specifically designed to real time data, and its compression and decompression speed are very fast.
Step S340, described Real Time Compression data are filled in the record page of buffer memory;
Specifically, the application is cached with record page outside achieving. The Real Time Compression data obtained through real non-destructive compression are filled in record page.
Step S350, judge whether the occupied state of described record page reaches preset occupied state, if so, then perform step S360;
Specifically, the occupied state of record page can be whether record page fills completely.
Step S360, described record page is carried out static text compression, obtain compression blocks;
When the occupied state determining record page reaches threshold value occupied state, record page is carried out static text compression, obtains compression blocks. Static text compression has higher compression ratio, by static text compression, the data in record page is compressed further.
Step S370, described compression blocks is filled in described target record block;
Specifically, the compression blocks obtained after record page being carried out static text compression is filled in the target record block in archive.
Step S380, according to described index page allocation strategy, search and described target index page corresponding for item ID;
Similar with above-mentioned target record block, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target index page found in this step is likely to stored have index information and timestamp. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target index page that this finds is idle index page.
Step S390, by the index information of described target record block and described timestamp record at described target index page.
Compared to a upper embodiment, the process that historical data is filled in the present embodiment target record block further is described. When filling historical data in target record block, historical data is carried out two layer compression process and obtains compression blocks, greatly reduce history data store space, in the target record block in finally compression blocks write being achieved, save the memory space of archive.
It is another date storage method flow chart being applied to intelligence grain depot disclosed in the embodiment of the present application referring to Fig. 4, Fig. 4.
As shown in Figure 4, the method includes:
Step S400, receive item storage request;
Wherein, described storage request includes item ID, historical data and timestamp. Further, can also carrying Quality Codes in request, Quality Codes represents a kind of state of item.
For the historical data of item, its needs preserve for a long time, it is therefore desirable to be stored in archive, and the history trendline time of the timestamp of log history data, timestamp namely historical data.
Step S410, under the root achieved, inquire about preset index page allocation strategy, record block allocation strategy;
Wherein, described index page allocation strategy defines item ID and manipulative indexing page position, and described record block allocation strategy defines item ID and corresponding record block position, and described archive has divided according to page in advance, and described record block is made up of some pages.
Step S420, according to described record block allocation strategy, search and described target record block corresponding for item ID;
Specifically, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target record block found in this step is likely to stored have historical data. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target record block that this finds is idle block.
Step S430, described historical data is filled into described target record block;
Step S440, according to described index page allocation strategy, search and described target index page corresponding for item ID;
Similar with above-mentioned target record block, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target index page found in this step is likely to stored have index information and timestamp. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target index page that this finds is idle index page.
Step S450, by the index information of described target record block and described timestamp record at described target index page;
Step S460, judge whether described target index page is filled with, if so, perform step S470;
Specifically, if be filled with a certain target index page corresponding for item ID, then the process of the new index page of following establishment is performed.
Step S470, according to described index page allocation strategy, for the index page that the distribution of described item is new, and the index information of new index page is added in a upper index page.
Specifically, newly assigned index page is blank index page, and the index information of this index page will recorded in an index page. A upper index page described here, refers to the index page that history the last time is the distribution of described item.
By being added to by the index information of new index page in a upper index page, follow-up this index information that can pass through when data query searches the index page of association.
Optionally, above-described embodiment has been described above the allocation strategy of the first index page of item. Further, for the follow-up new index page distributed for described item, it can according to from achieving the mode that afterbody is sequentially allocated forward.
Further, if for the number of index page of some item distribution too much time, the considerable time will be expended during subsequent query. In order to solve this problem, itself first set the index page corresponding with item of the various embodiments described above introduction as one-level index page, namely one-level index page stores index information and the timestamp of record block. On this basis, the application is further introduced into the secondary index page of item, and secondary index page is for storing the index information of each one-level index page of item.
It is another date storage method flow chart being applied to intelligence grain depot disclosed in the embodiment of the present application referring to Fig. 5, Fig. 5.
As it is shown in figure 5, the method includes:
Step S500, receive item storage request;
Wherein, described storage request includes item ID, historical data and timestamp.Further, can also carrying Quality Codes in request, Quality Codes represents a kind of state of item.
For the historical data of item, its needs preserve for a long time, it is therefore desirable to be stored in archive, and the history trendline time of the timestamp of log history data, timestamp namely historical data.
Step S510, under the root achieved, inquire about preset index page allocation strategy, record block allocation strategy;
Wherein, described index page allocation strategy defines item ID and manipulative indexing page position, and described record block allocation strategy defines item ID and corresponding record block position, and described archive has divided according to page in advance, and described record block is made up of some pages.
Step S520, according to described record block allocation strategy, search and described target record block corresponding for item ID;
Specifically, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target record block found in this step is likely to stored have historical data. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target record block that this finds is idle block.
Step S530, described historical data is filled into described target record block;
Step S540, according to described index page allocation strategy, search and described target index page corresponding for item ID;
Similar with above-mentioned target record block, if before the storage request of this item, having stored the historical data of identical item ID in archive, then the target index page found in this step is likely to stored have index information and timestamp. If before the storage request of this item, not storing the historical data of identical item ID in archive, then the target index page that this finds is idle index page.
Step S550, by the index information of described target record block and described timestamp record at described target index page;
Step S560, judge whether described target index page is filled with, if so, perform step S470;
Specifically, if be filled with a certain target index page corresponding for item ID, then the process of the new index page of following establishment is performed.
Step S570, according to described index page allocation strategy, for the index page that the distribution of described item is new, and the index information of new index page is added in a upper index page;
Step S580, judging whether the number of the index page corresponding with described item reaches threshold value, wherein, the index page corresponding with described item is as the one-level index page of described item; If so, step S590 is performed;
Step S590, for described item create secondary index page, described secondary index page records the index information of the one-level index page of rheme number to some extent.
The application, when the number determining one-level index page that item is corresponding exceedes threshold value, creates the secondary index page of item further, is write in secondary index page by the index information of the one-level index page of item. During the historical data of follow-up lookup item, it is possible to by traveling through the secondary index page of item, find the index information of all one-level index pages of item, and then find the one-level index page of correspondence according to these index informations, be greatly improved efficiency data query.
Optionally, owing to the first one-level index page of item is positioned at the head position of archive, therefore to be easy to inquiry, on the basis of the above, the first one-level index page of the secondary index page of described item Yu described item can also be carried out place-exchange by the application further.That is, the secondary index page of item to be adjusted the head position achieved, so easily facilitate when data query and directly find secondary index page.
The data storage device below the embodiment of the present application provided is described, and data storage device described below and above-described date storage method can mutually to should refer to.
It is a kind of data storage device structural representation being applied to intelligence grain depot disclosed in the embodiment of the present application referring to Fig. 6, Fig. 6.
As shown in Figure 6, this device includes:
Storage request reception unit 61, for receiving the storage request of item, described storage request includes item ID, historical data and timestamp;
Root query unit 62, for inquiring about preset index page allocation strategy, record block allocation strategy under the root achieved, wherein, described index page allocation strategy defines item ID and manipulative indexing page position, described record block allocation strategy defines item ID and corresponding record block position, described archive has divided according to page in advance, and described record block is made up of some pages;
Target record block searches unit 63, for according to described record block allocation strategy, searching and described target record block corresponding for item ID;
Historical data fills unit 64, for described historical data is filled into described target record block;
Target index page searches unit 65, for according to described index page allocation strategy, searching and described target index page corresponding for item ID;
Target index page record unit 66, for by the index information of described target record block and described timestamp record at described target index page.
What the embodiment of the present application provided is applied to the data storage device of intelligence grain depot, prespecified index page allocation strategy and record block allocation strategy, determine record block and index page according to above-mentioned two strategy during storage item, store historical data in record block, index page stores index information and the timestamp of record block, according to item ID and index page allocation strategy and record block allocation strategy, historical data corresponding to item ID can be inquired about during subsequent query item historical data. Owing to the application need not record the corresponding relation between the index information of each item ID and record block in archive, save the space of archive, improve the storage capacity of data base.
Optionally, the embodiment of the present application also discloses historical data and fills the optional structure of one of unit, and historical data is filled unit and be may include that
Lossless compression unit, for described historical data is carried out real non-destructive compression, obtains Real Time Compression data;
Real Time Compression data fill unit, for being filled in the record page of buffer memory by described Real Time Compression data;
Record page condition adjudgement unit, for judging whether the occupied state of described record page reaches preset occupied state;
Static Compression unit, for when the judged result of described record page condition adjudgement unit is for being, carrying out static text compression by described record page, obtain compression blocks;
Compression blocks fills unit, for being filled in described target record block by described compression blocks.
Optionally, on above-described embodiment basis, the data storage device being applied to intelligence grain depot of the application can further include:
Target index page judging unit, is used for judging whether described target index page is filled with;
New index page allocation units, for when the judged result of described target index page judging unit is for being, according to described index page allocation strategy, distributing new index page for described item, and be added in a upper index page by the index information of new index page.
Optionally, on above-described embodiment basis, the data storage device being applied to intelligence grain depot of the application can further include:
Index page number judging unit, for judging whether the number of the index page corresponding with described item reaches threshold value, wherein, the index page corresponding with described item is as the one-level index page of described item;
Secondary index page creating unit, for when the judged result of described index page number judging unit is for being, creating secondary index page for described item, record the index information of the one-level index page of rheme number to some extent in described secondary index page.
Optionally, on above-described embodiment basis, the data storage device being applied to intelligence grain depot of the application can further include:
Index page place-exchange unit, for carrying out place-exchange by the secondary index page of described item and the first one-level index page of described item.
Finally, it can further be stated that, in this article, the relational terms of such as first and second or the like is used merely to separate an entity or operation with another entity or operating space, and not necessarily requires or imply the relation that there is any this reality between these entities or operation or sequentially. And, term " includes ", " comprising " or its any other variant are intended to comprising of nonexcludability, so that include the process of a series of key element, method, article or equipment not only include those key elements, but also include other key elements being not expressly set out, or also include the key element intrinsic for this process, method, article or equipment. When there is no more restriction, statement " including ... " key element limited, it is not excluded that there is also other identical element in including the process of described key element, method, article or equipment.
In this specification, each embodiment adopts the mode gone forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, between each embodiment identical similar portion mutually referring to.
Described above to the disclosed embodiments, makes professional and technical personnel in the field be capable of or uses the application. The multiple amendment of these embodiments be will be apparent from for those skilled in the art, and generic principles defined herein when without departing from spirit herein or scope, can realize in other embodiments. Therefore, the application is not intended to be limited to the embodiments shown herein, and is to fit to the widest scope consistent with principles disclosed herein and features of novelty.