Embodiment
Below in conjunction with the accompanying drawing in the present invention, the technical scheme in the present invention is carried out to clear, complete description, obviously, described embodiment is a part of embodiment of the present invention, rather than whole embodiment.Embodiment based in the present invention, all other embodiment that those of ordinary skills obtain under the prerequisite of not making creative work, belong to the scope of protection of the invention.
Embodiment mono-
In the present embodiment, more new data is stored in updating file with the storage organization of Memtable, and historical data is stored in one or more data files with the storage organization of SSTable.The SSTable structure is a kind of distributed key assignments storage organization, can comprise a plurality of SSTable in each data file, can store value corresponding to a plurality of value(major keys in each SSTable) and the corresponding interior index of piece, the structure of each SSTable can be as shown in Figure 2.When being inquired about, can be first according to the key(major key) inquire about the data file under it, and then further inquire about its SSTable affiliated in this data file, because the quantity of historical data is very huge, adopt the SSTable structure can promote search efficiency.Memtable is a kind of non-distributed storage organization, because the more general quantity of new data is fewer, so adopt the Memtable structure can promote storage efficiency.
As shown in Figure 3, the flow process of the processing of the non-relational database data update method provided for the embodiment of the present invention specifically comprises the following steps:
Step 301, system receives update instruction, and records the more new data carried in update instruction, and more new data packets is drawn together major key and corresponding renewal content of operation.
The maintainer of database can send update instruction by server or office terminal, after system receives update instruction, can first the more new data in update instruction be stored in the middle of updating file, specifically can adopt form storage key and the corresponding renewal content of operation of list.More in new data, can comprise the key that it need to upgrade, and comprise the operation (upgrading content of operation) to carrying out to corresponding key-value, this renewal content of operation can be delete key-value to, add key-value to or revise value etc.
Step 302, when the first default trigger event occurs, each data file under the major key in new data more of system searching.
Concrete, this first default trigger event can be to reach default more new data to merge the cycle, and system sets in advance more new data and merges the cycle, carries out the more merging of new data and historical data according to the cycle.In addition, the first default trigger event can also be to receive more new data merge command, can send more new data merge command by the database maintenance personnel, and with indication mechanism, more new data and historical data are merged.
Concrete, as shown in Figure 4, system can be according to the metadata recorded in meta data file, searches each more data file corresponding to key in new data.Metadata is a kind of data for data of description, and the queue of the metadata recorded in meta data file can be as shown in Figure 5, can comprise the scope of key in the reference number of a document, file of each data file, the information such as memory capacity of file.In addition, the information of all right log file numbering in meta data file, as numbered by reference number of a document, file available.
Step 303, system, according to the renewal content of operation in new data more, merges to each data file that more new data is corresponding with it in new data file, and replaces the front data file of merging by new data file.
System is for every new data more, according to the key in new data more, finds its corresponding data file, and then more new data is merged with corresponding data file.Concrete, the operation of merging is to carry out according to the renewal content of operation in new data more, can comprise delete key-value to, add key-value to or revise value etc.
When a plurality of more new data key correspond to same data file, common and this data file of these a plurality of more new datas merges in new data file.Merging process can be according to each key and the value in former data file, and the more key in new data and corresponding renewal content of operation, according to the order of key, in new data file, order generates each SSTable again, and the memory capacity of SSTable is the numerical value set in advance.
Preferably, system can be distributed new reference number of a document (choosing in the file available numbering) for the new data file that merging obtains.After merging end, system can be deleted the data file be replaced, and discharges the reference number of a document of this data file, and this document numbering is by with reference number of a document, becoming the file available numbering.
In the above-mentioned flow process of the present embodiment, system can be set up two in advance for recording the more catalogue of new data, by the more new data records of carrying in the update instruction received in one of them catalogue; Then, when the first trigger event occurs, carry out the catalogue switching, by the more new data records of carrying in the follow-up update instruction received in another catalogue, and will before record in the catalogue used each more new data with corresponding data file, merge in new data file; By in the catalogue of using before, record each more new data with after corresponding data file merges in new data file, the more new data before deleting in the catalogue of use.
Concrete, can adopt 0, the mode of 1 catalogue is stored new data more, set up respectively more 0 catalogue file of new data, 1 catalogue file, when the first trigger event occurs, carry out the catalogue switching, what suppose current use is 0 catalogue, when the first trigger event starts to carry out merging process, the more new data newly received will be stored in catalogue 1, more new data in catalogue 0 and corresponding data file are merged, and after merging process finishes, more new data in 0 catalogue is by deleted, then, in while, the first trigger event occurring next time, switching is got back to 0 catalogue and is carried out more the new data storage again, more new data in catalogue 1 and corresponding data file are merged, and after merging process finishes, delete the more new data in 1 catalogue, the rest may be inferred.
Preferably, the embodiment of the present invention also provide non-relational database data update method, can also comprise: when the second default trigger event occurs, whether the memory capacity sum that judges adjacent a plurality of data files surpasses default memory capacity threshold value, if do not surpass, described a plurality of data files are merged into to a data file.The second trigger event wherein can be to reach the preset data Piece file mergence cycle, can be also that respectively more new data is complete with corresponding data file merging, can also be to receive the data file merge command.The merging process of concrete data file can comprise the steps:
Steps A, sorted to the data file according to the order of the major key comprised in data file, using first data file in the data file after sequence as the benchmark file.
According to the order of the key stored in data file, can be sorted to the data file.For example, comprise key1, key2, key3 in data file 1, comprise key4, key5, key6 in data file 2, comprise key7, key8, key9 in data file 3, order that can the specified data file according to the order of key is data file 1, data file 2, data file 3.
Step B, whether the judgment standard file is last data file in the data file after sequence; If so, process ends; Otherwise, determine the storage space sum of the next data file of benchmark file and benchmark file, and perform step C.
Step C, judge whether described storage space sum surpasses default space threshold value; If so, using the next data file of described benchmark file as the benchmark file, and go to step B; Otherwise, the next data file of benchmark file and benchmark file is merged, using the data file after merging as the benchmark file, and go to step B.
For example, data file 1 is carried out to the data file merging process to data file n, it is 1M(million that the memory capacity threshold value is set).Using data file 1 as the benchmark file, whether the memory capacity sum of judgment standard file and data file 2 surpasses 1M, suppose not surpass 1M, data file 1 and data file 2 are merged into to data file 1 ', using data file 1 ' as the benchmark file, and whether the memory capacity sum that continues judgment standard file and data file 3 surpasses 1M, suppose to surpass 1M, using data file 3 as the benchmark file, whether the memory capacity sum of judgment standard file and data file 4 surpasses 1M, the rest may be inferred, until the benchmark file is while being last file in the data file queue, process ends.
The embodiment of the present invention also provides a kind of method of data query, and system corresponding each data file is in advance set up index file, records the scope of the major key that each SSTable in its corresponding data file stores in index file.Concrete, can record the beginning key in SSTable in index file, the number of key in SSTable, the skew in the data file of SSTable data under it.When database starts, system can be loaded into the content of each index file in internal memory in advance.
As shown in Figure 6, the flow process of this data enquire method can comprise the steps:
Step 601, when receiving query statement, system is determined the data file under the major key carried in described query statement.System can be according to the metadata recorded in meta data file, searches each more data file corresponding to key in new data, and concrete grammar is set forth in step 302, at this, is not repeated.
Step 602, the scope of the major key that each SSTable in this data file recorded in the system index file corresponding according to this data file stores, determine the SSTable under the major key carried in query statement.
When database starts, system can be loaded into the content of each index file in internal memory in advance.Then, system can, according to the scope of the major key that in the data file loaded in internal memory, each SSTable stores, be determined the SSTable that corresponding major key is affiliated.
Step 603, search the value that this major key is corresponding in the SSTable under this major key.
In the embodiment of the present invention, receive update instruction, and record the more new data carried in update instruction, more new data packets is drawn together major key and corresponding renewal content of operation, when the first default trigger event occurs, each that search record be the data file under the major key in new data more, according to the described renewal content of operation in new data more, each data file that more new data is corresponding with it is merged in new data file, and replace the data file before merging by described new data file, thereby, can improve the efficiency that non-relational database historical data is upgraded.
Embodiment bis-
As shown in Figure 7, the treatment scheme of non-relational database data update method in concrete application scenarios for the embodiment of the present invention provides, can comprise the steps:
Step 701, system is switched to more new data merging patterns, obtains the catalogue that current data is being used.The catalogue of supposing current use is 0 catalogue, and the follow-up more new data received again will be deposited in 1 catalogue.
Step 702, obtain key corresponding to all more new datas in this catalogue, and search according to metadata the data file that each key is corresponding.
Step 703, distribute the file available numbering, sets up new data file, and each data file that more new data is corresponding with it is merged in new data file.After merging end, can delete data file and corresponding index file thereof before merging, and be released to available by its reference number of a document.
Step 704, set up the index file of new data file, and by the content update of this index file in internal memory.The corresponding contents of index file in internal memory corresponding to data file before can merging with the content replacement of this index file.
Step 705, finish the more merging flow process of new data and historical data, and system is switched to normal mode.Under normal mode, system receives only more new data and stores in corresponding catalogue, and does not carry out the more merging of new data and historical data.
In the embodiment of the present invention, receive update instruction, and record the more new data carried in update instruction, more new data packets is drawn together major key and corresponding renewal content of operation, when the first default trigger event occurs, each that search record be the data file under the major key in new data more, according to the described renewal content of operation in new data more, each data file that more new data is corresponding with it is merged in new data file, and replace the data file before merging by described new data file, thereby, can improve the efficiency that non-relational database historical data is upgraded.
Embodiment tri-
Technical conceive based on identical, the embodiment of the present invention also provides a kind of non-relational database data updating device, as shown in Figure 8, comprising:
Logging modle 810, for receiving update instruction, and record the more new data carried in described update instruction, and described more new data packets is drawn together major key and corresponding renewal content of operation;
Search module 820, while occurring for the first trigger event when default, search each more data file under the major key in new data;
Update module 830, for according to the described renewal content of operation of new data more, merge to each data file that more new data is corresponding with it in new data file, and replace the front data file of merging by described new data file.
Preferably, also comprise the renewal data management module, for:
Set up in advance two for recording the catalogue of described more new data;
By the more new data records of carrying in the update instruction received in one of them catalogue;
When described the first trigger event occurs, carry out the catalogue switching, by the more new data records of carrying in the follow-up update instruction received in another catalogue, and will before record in the catalogue used each more new data with corresponding data file, merge in new data file;
By in the catalogue of using before, record each more new data with after corresponding data file merges in new data file, the more new data before deleting in the catalogue of use.
Preferably, also comprise the merging module, for:
When the second default trigger event occurs, judge whether the memory capacity sum of adjacent a plurality of data files surpasses default memory capacity threshold value, if do not surpass, described a plurality of data files are merged into to a data file.
Preferably, described merging module, specifically for:
Steps A, sorted to the data file according to the order of the major key comprised in data file, using first data file in the data file after sequence as the benchmark file;
Step B, whether the judgment standard file is last data file in the data file after sequence; If so, process ends; Otherwise, determine the storage space sum of the next data file of benchmark file and benchmark file, and perform step C;
Step C, judge whether described storage space sum surpasses default space threshold value; If so, using the next data file of described benchmark file as the benchmark file, and go to step B; Otherwise, the next data file of benchmark file and benchmark file is merged, using the data file after merging as the benchmark file, and go to step B.
Preferably, described the second default trigger event, be specially the preset data Piece file mergence cycle that reaches.
Preferably, also comprise:
Set up module, for corresponding each data file, set up index file, record the scope of the major key that each SSTable in its corresponding data file stores in index file;
Enquiry module, for when receiving query statement, determine the affiliated data file of major key of carrying in described query statement; The scope of the major key that each SSTable in this data file recorded in corresponding index file according to this data file stores, determine the SSTable under the major key carried in described query statement; Search the value that this major key is corresponding in SSTable under this major key.
Preferably, described the first default trigger event, be specially the default more new data merging cycle that reaches.
Preferably, also comprise the reference number of a document administration module, for:
For described new data file is distributed new reference number of a document;
The data file that deletion is replaced, and discharge the reference number of a document of this data file.
In the embodiment of the present invention, receive update instruction, and record the more new data carried in update instruction, more new data packets is drawn together major key and corresponding renewal content of operation, when the first default trigger event occurs, each that search record be the data file under the major key in new data more, according to the described renewal content of operation in new data more, each data file that more new data is corresponding with it is merged in new data file, and replace the data file before merging by described new data file, thereby, can improve the efficiency that non-relational database historical data is upgraded.
It will be appreciated by those skilled in the art that the module in the device in embodiment can be distributed in the device of embodiment according to the embodiment description, also can carry out respective change and be arranged in the one or more devices that are different from the present embodiment.The module of above-described embodiment can be merged into a module, also can further split into a plurality of submodules.
The invention described above embodiment sequence number, just to describing, does not represent the quality of embodiment.
Through the above description of the embodiments, those skilled in the art can be well understood to the mode that the present invention can add essential general hardware platform by software and realize, can certainly pass through hardware, but in a lot of situation, the former is better embodiment.Understanding based on such, the part that technical scheme of the present invention contributes to prior art in essence in other words can embody with the form of software product, this computer software product is stored in a storage medium, comprise that some instructions are with so that a station terminal equipment (can be mobile phone, personal computer, server, or the network equipment etc.) the described method of execution each embodiment of the present invention.
The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be looked protection scope of the present invention.