A kind of data of non relational database update method and device
Technical field
The present invention relates to networking technology area, particularly to a kind of data of non relational database update method and device.
Background technology
Table in relevant database all has fixing data structure, each tuple (each note in database table
Record) field groups Chengdu the same, even if not being that each tuple is required for all of field, but data base can be for the institute of each tuple
There are the corresponding data of field distribution.Such as, certain database table includes name, age, three, native place field, then in this table
Every record is required for including name, age, three, native place field, even if wherein the content of certain field of certain tuple is
Sky, system also to distribute a default value for it, such as 0.Such structure can so that the operation such as being attached between table and table,
But for another angle, it is also the key factor causing relevant database performance bottleneck so that relational data
Storehouse can not meet the demand to data base's height concurrent reading and writing, stores the high efficiency of mass data and the demand of access, to data
The enhanced scalability in storehouse and the demand of high availability.
In order to solve the problems referred to above, non-relational database (NoSQL) is arisen at the historic moment.The BigTable of Google with
The Dynamo of Amazon is very successful business NoSQL system.The NoSQL system that some are increased income, such as Membase,
MongoDB, Cassandra, BeansDB, Redis etc., have also been obtained extensively approval.
Non-relational database, it stores with key-value pair, and structure do not fixes, and each tuple can have different word
Section, each tuple can increase some oneself key-value pair as required, be not limited to the structure fixed, it is possible to reduce some time
Between and the expense in space.KV(Key-Value, key assignments) storage, it is a kind of mode of NoSQL storage, data are according to key-value pair
Form carries out organizing, index and storing.KV storage is especially suitable for being not related to the business datum of too much data relationship and business relations,
Can effectively reduce the number of times of read-write disk simultaneously, have more preferable readwrite performance than relational data library storage.
Key assignments memory mechanism uses the storage of key-value pair form, and value can be any random length data, uses major key can make letter
Single inquiry and complex query (such as list query, range query etc.), be periodically updated the merging of data and historical data simultaneously
Operations such as () this union operation can include adding, deletes, amendments is to process stale data.As it is shown in figure 1, more new data and going through
History data acquisition, with 0,1 directory management, arranges 0,1 two catalogues for more new data, and historical data is also provided with 0,1 two mesh
Record, it is assumed that current renewal data directory and historical data catalogue are all 0 catalogue, in the conjunction being updated data and historical data
And time, 0 catalogue of 0 catalogue of more new data and historical data is merged, and the data after merging are stored in the 1 of historical data
In catalogue, simultaneously in merging process, new more new data is written in 1 catalogue of more new data.Once it is updated upper
During the merging of data and historical data, 1 catalogue of more new data and 1 catalogue of historical data are merged into 0 mesh of historical data
In record, the rest may be inferred.
However, it is found by the inventors that, at least there are the following problems for prior art:
In existing data-updating method, the most more new data and the merging of historical data, will be by all of history number
Merging according to more new data, the historical data the most not changed also to merge and to move in another catalogue, effect
Rate is relatively low, considerably increases the expense of system.
Summary of the invention
It is an object of the invention to provide a kind of data of non relational database update method and device, to improve non-relation
The efficiency that type data historian data update, to this end, the embodiment of the present invention adopts the following technical scheme that
A kind of data of non relational database update method, including:
Receiving and update instruction, and record the described more new data updating and carrying in instruction, described more new data packets includes major key
With corresponding renewal operation content;
When the first default trigger event occurs, search the data file belonging to major key in each more new data;
According to the described renewal operation content in more new data, data file corresponding for each more new data is merged into
In new data file, and replace the data file before merging by described new data file.
A kind of data of non relational database updating device, including:
Logging modle, is used for receiving renewal instruction, and records the described more new data updating and carrying in instruction, described renewal
Data include major key and corresponding renewal operation content;
Search module, for when the first default trigger event occurs, searching belonging to the major key in each more new data
Data file;
More new module, for according to the described renewal operation content in more new data, by corresponding for each more new data
Data file is merged in new data file, and replaces the data file before merging by described new data file.
The above embodiment of the present invention, receives and updates instruction, and records the more new data carried in renewal instruction, updates number
According to including major key and corresponding renewal operation content, when the first default trigger event occurs, that searches record respectively updates number
The data file belonging to major key according to, according to the described renewal operation content in more new data, by right with it for the most more new data
The data file answered is merged in new data file, and replaces the data file before merging by described new data file, from
And, the efficiency that non-relational database historical data updates can be improved.
Accompanying drawing explanation
Fig. 1 is the storage mode schematic diagram of more new data and historical data in prior art;
The structural representation of SSTable in the data of non relational database update method that Fig. 2 provides for the embodiment of the present invention
Figure;
The schematic flow sheet of the data of non relational database update method that Fig. 3 provides for the embodiment of the present invention;
According to updating data search pair in the data of non relational database update method that Fig. 4 provides for the embodiment of the present invention
Answer the schematic diagram of data file;
Meta data file storage content in the data of non relational database update method that Fig. 5 provides for the embodiment of the present invention
Schematic diagram;
The flow process of data query method in the data of non relational database update method that Fig. 6 provides for the embodiment of the present invention
Schematic diagram;
The schematic flow sheet of the data of non relational database update method that Fig. 7 provides for the embodiment of the present invention;
The structural representation of the data of non relational database updating device that Fig. 8 provides for the embodiment of the present invention.
Detailed description of the invention
Below in conjunction with the accompanying drawing in the present invention, the technical scheme in the present invention is carried out clear, complete description, aobvious
So, described embodiment is a part of embodiment of the present invention rather than whole embodiments.Based on the enforcement in the present invention
Example, all other embodiments that those of ordinary skill in the art are obtained on the premise of not making creative work, all belong to
In the scope of protection of the invention.
Embodiment one
In the present embodiment, more new data with the storage organization of Memtable be stored in renewal file in, historical data with
The storage organization of SSTable is stored in one or more data file.SSTable structure is the storage of a kind of distributed key assignments
Structure, can comprise multiple SSTable in each data file, can store multiple value(master in each SSTable
The value that key is corresponding) and the interior index of block of correspondence, the structure of each SSTable can be as shown in Figure 2.Inquiring about when,
Can be first according to key(major key) inquire about its affiliated data file, the most further inquire about it belonging in this data file
SSTable, owing to the quantity of historical data is the hugest, use SSTable structure can promote search efficiency.Memtable
It is the storage organization of a kind of non-distributed, owing to the general quantity of more new data is fewer, so using Memtable structure permissible
Promote storage efficiency.
As it is shown on figure 3, the flow process of process of the data of non relational database update method provided for the embodiment of the present invention,
Specifically include following steps:
Step 301, system receives and updates instruction, and records the more new data carried in renewal instruction, and more new data packets includes
Major key and corresponding renewal operation content.
The attendant of data base can send renewal instruction by server or management terminal, and system receives renewal and refers to
After order, can first the more new data updated in instruction be stored in the middle of renewal file, specifically can deposit to use the form of list
Storage key and corresponding renewal operation content.More new data can include the key that its needs update, and include accordingly
The key-value operation (i.e. update operation content) to carrying out, this renewal operation content can be delete key-value to, add
Add key-value to or amendment value etc..
Step 302, when the first default trigger event occurs, the number belonging to major key in system searching the most more new data
According to file.
Concrete, this first trigger event preset can be to reach to preset more new data to merge cycle, i.e. system in advance
More new data is set and merges the cycle, be updated merging of data and historical data according to the cycle.It addition, the first triggering preset
Event can also is that receiving more new data merges instruction, i.e. can be sent the merging of more new data by database maintenance personnel and refer to
Order, to indicate system to be merged with historical data by more new data.
Concrete, as shown in Figure 4, system can search each more new data according to the metadata of record in meta data file
In data file corresponding for key.Metadata is a kind of data for describing data, the metadata of record in meta data file
Queue can be as it is shown in figure 5, the storage of the scope of key, file in the reference number of a document of each data file, file can be included
The information such as capacity.It addition, can be with the information of log file numbering in meta data file, as with reference number of a document, available literary composition
Part is numbered.
Step 303, system operates content according to the renewal in more new data, by data literary composition corresponding for each more new data
Part is merged in new data file, and replaces the data file before merging by new data file.
System, for every more new data, finds the data file of its correspondence according to the key in more new data, then will more
New data merges with corresponding data file.Concrete, the operation of merging is according in the renewal operation in more new data
Hold and carry out, can include deleting key-value to, add key-value to or amendment value etc..
When multiple more new data key correspond to same data file, these multiple more new datas are common and these data are civilian
Part is merged in new data file.Merging process can be according to each key and value in former data file, and more new data
In key and corresponding renewal operation content, according to the order of key, be again sequentially generated each in new data file
The memory capacity of SSTable, SSTable is the numerical value pre-set.
Preferably, system can be to merge the new data file obtained to distribute new reference number of a document (in file available volume
Choose in number).After merging terminates, system can delete the data file being replaced, and the file discharging this data file is compiled
Number, this document numbering is from becoming file available numbering with reference number of a document.
In the above-mentioned flow process of the present embodiment, system can pre-build two for the catalogue recording more new data, will connect
The more new data carried in instruction that updates received recorded in one of them catalogue;Then, occur whenever the first trigger event
Time, carry out catalogue switching, the subsequently received more new data carried in instruction that updates be recorded in another catalogue, and will
In the catalogue before used, each more new data of record is merged in new data file with corresponding data file;To make before
Catalogue in record each more new data be merged in new data file with corresponding data file after, make before deletion
Catalogue in more new data.
Concrete, in the way of using 0,1 catalogue, more new data can be stored, set up more new data respectively
0 catalogue file, 1 catalogue file, when the first trigger event occurs, carry out catalogue switching, it is assumed that currently used is 0 mesh
Record, when the first trigger event proceeds by merging process, the more new data being newly received will be stored in catalogue 1,
More new data in catalogue 0 is merged with corresponding data file, and the renewal after merging process terminates, in 0 catalogue
Data will be deleted, then, when there is the first trigger event next time, then switch back to 0 catalogue be updated data storage, will
More new data in catalogue 1 merges with corresponding data file, and after merging process terminates, and deletes in 1 catalogue more
New data, the rest may be inferred.
Preferably, the embodiment of the present invention additionally provide data of non relational database update method, it is also possible to including:
When the second default trigger event occurs, it is judged that whether the memory capacity sum of adjacent multiple data files exceedes is preset storage
Capacity threshold, without exceeding, then merges into a data file by the plurality of data file.Therein second triggers thing
Part can be to reach the preset data Piece file mergence cycle, it is also possible to is that each more new data merges complete with corresponding data file,
Can also is that receiving data file merges instruction.The merging process of concrete data file may include steps of:
Step A, is ranked up data file according to the order of the major key comprised in data file, by the data after sequence
First data file in file is as reference file.
According to the order of the key of storage in data file, data file can be ranked up.Such as, in data file 1
Comprise key1, key2, key3, data file 2 comprise key4, key5, key6, data file 3 comprises key7, key8,
According to the order of key, key9, then may determine that the order of data file is data file 1, data file 2, data file 3.
Step B, it is judged that whether reference file is last data file in the data file after sorting;If it is,
Then terminate flow process;Otherwise, it determines the memory space sum of the next data file of reference file and reference file, and perform step
Rapid C.
Step C, it is judged that whether described memory space sum exceedes default capacity-threshold;If it is, by described benchmark
The next data file of file is as reference file, and goes to step B;Otherwise, by next of reference file and reference file
Individual data Piece file mergence, the data file after merging is as reference file, and goes to step B.
Such as, data file 1 to data file n being carried out data file merging process, arranging memory capacity threshold value is 1M
(million).Using data file 1 as reference file, it is judged that the memory capacity sum of reference file and data file 2 whether more than 1M,
Assume to be not above 1M, then by 2-in-1 to data file 1 and data file and be data file 1 ', using data file 1 ' as benchmark
File, and whether continue the judgment standard file memory capacity sum with data file 3 more than 1M, it is assumed that more than 1M, then by number
According to file 3 as reference file, it is judged that whether the memory capacity sum of reference file and data file 4 is more than 1M, and the rest may be inferred,
During until reference file is last file in data file queue, terminate flow process.
The embodiment of the present invention additionally provides a kind of method of data query, and the most corresponding each data file of system sets up index
File, records the scope of the major key that each SSTable in the data file of its correspondence is stored in index file.Concrete, rope
Can record the beginning key in SSTable in quotation part, the number of key in SSTable, SSTable data are at its affiliated number
According to the skew in file.When data base starts, the content of each index file can be loaded in internal memory by system in advance.
As shown in Figure 6, the flow process of this data query method may include steps of:
Step 601, when receiving query statement, system determines the data belonging to the major key carried in described query statement
File.System can search the data literary composition corresponding for key in each more new data according to the metadata of record in meta data file
Part, concrete grammar illustrates the most, is not repeated at this.
Step 602, each according in this data file of record in index file corresponding to this data file of system
The scope of the major key that SSTable is stored, determines the SSTable belonging to the major key carried in query statement.
When data base starts, the content of each index file can be loaded in internal memory by system in advance.Then, system can
The scope of the major key to be stored according to each SSTable in the data file loaded in internal memory, determines belonging to corresponding major key
SSTable。
Step 603, searches the value that this major key is corresponding in the SSTable belonging to this major key.
In the embodiment of the present invention, receive and update instruction, and record the more new data carried in renewal instruction, more new data packets
Include major key and corresponding renewal operation content, when the first default trigger event occurs, search in each more new data of record
The data file belonging to major key, according to the described renewal operation content in more new data, by corresponding for each more new data
Data file is merged in new data file, and replaces the data file before merging by described new data file, thus, can
To improve the efficiency that non-relational database historical data updates.
Embodiment two
As it is shown in fig. 7, for the embodiment of the present invention provide data of non relational database update method in concrete applied field
Handling process in scape, may include steps of:
Step 701, system is switched to more new data merging patterns, obtains the catalogue that current data is currently in use.Assume to work as
The catalogue of front use is 0 catalogue, and the follow-up more new data received again is stored in 1 catalogue.
Step 702, obtains the key that in this catalogue, all more new datas are corresponding, and corresponding according to each key of metadata lookup
Data file.
Step 703, distribution file available numbering, set up new data file, and by number corresponding for each more new data
According in Piece file mergence to new data file.Merge after terminating, the index of the data file before merging and correspondence thereof can be deleted
File, and be released to can use by its reference number of a document.
Step 704, sets up the index file of new data file, and by the content update of this index file to internal memory.
Index file corresponding to the data file before merging corresponding contents in internal memory can be replaced by the content of this index file.
Step 705, terminates the flow process that merges of more new data and historical data, and system is switched to normal mode.At normal mode
Under formula, system only receives more new data and stores in corresponding catalogue, and is not updated merging of data and historical data.
In the embodiment of the present invention, receive and update instruction, and record the more new data carried in renewal instruction, more new data packets
Include major key and corresponding renewal operation content, when the first default trigger event occurs, search in each more new data of record
The data file belonging to major key, according to the described renewal operation content in more new data, by corresponding for each more new data
Data file is merged in new data file, and replaces the data file before merging by described new data file, thus, can
To improve the efficiency that non-relational database historical data updates.
Embodiment three
Based on identical technology design, the embodiment of the present invention additionally provides a kind of data of non relational database more new clothes
Put, as shown in Figure 8, including:
Logging modle 810, is used for receiving renewal instruction, and records the described more new data updating and carrying in instruction, described
More new data packets includes major key and corresponding renewal operation content;
Search module 820, for when the first default trigger event occurs, searching belonging to the major key in each more new data
Data file;
More new module 830, for according to the described renewal operation content in more new data, by corresponding for the most more new data
Data file be merged in new data file, and replace the data file before merging by described new data file.
Preferably, also include updating data management module, be used for:
Pre-build the catalogue of two more new datas described in record;
The more new data carried in instruction that updates received be recorded in one of them catalogue;
When described first trigger event occurs, carry out catalogue switching, will subsequently received renewal instruction be carried
More new data recorded in another catalogue, and in the catalogue that will use before record each more new data and corresponding data
Piece file mergence is in new data file;
In the catalogue that will use before, each more new data of record is merged into new data file with corresponding data file
More new data after in, in the catalogue used before deletion.
Preferably, also include merging module, be used for:
When the second default trigger event occurs, it is judged that whether the memory capacity sum of adjacent multiple data files exceedes
Preset memory capacity threshold value, without exceeding, then the plurality of data file is merged into a data file.
Preferably, described merging module, specifically for:
Step A, is ranked up data file according to the order of the major key comprised in data file, by the data after sequence
First data file in file is as reference file;
Step B, it is judged that whether reference file is last data file in the data file after sorting;If it is,
Then terminate flow process;Otherwise, it determines the memory space sum of the next data file of reference file and reference file, and perform step
Rapid C;
Step C, it is judged that whether described memory space sum exceedes default capacity-threshold;If it is, by described benchmark
The next data file of file is as reference file, and goes to step B;Otherwise, by next of reference file and reference file
Individual data Piece file mergence, the data file after merging is as reference file, and goes to step B.
Preferably, described the second default trigger event, specially reach the preset data Piece file mergence cycle.
Preferably, also include:
Set up module, set up index file for corresponding each data file, index file records the data literary composition of its correspondence
The scope of the major key that each SSTable in part is stored;
Enquiry module, for when receiving query statement, determines the number belonging to the major key carried in described query statement
According to file;The master stored according to each SSTable in this data file of record in the index file that this data file is corresponding
The scope of key, determines the SSTable belonging to the major key carried in described query statement;SSTable belonging to this major key looks into
Look for the value that this major key is corresponding.
Preferably, described the first default trigger event, specially reach to preset more new data and merge the cycle.
Preferably, also include that reference number of a document manages module, be used for:
For the reference number of a document that described new data file distribution is new;
Delete the data file being replaced, and discharge the reference number of a document of this data file.
In the embodiment of the present invention, receive and update instruction, and record the more new data carried in renewal instruction, more new data packets
Include major key and corresponding renewal operation content, when the first default trigger event occurs, search in each more new data of record
The data file belonging to major key, according to the described renewal operation content in more new data, by corresponding for each more new data
Data file is merged in new data file, and replaces the data file before merging by described new data file, thus, can
To improve the efficiency that non-relational database historical data updates.
It will be appreciated by those skilled in the art that the module in the device in embodiment can describe according to embodiment to carry out point
It is distributed in the device of embodiment, it is also possible to carry out respective change and be disposed other than in one or more devices of the present embodiment.On
The module stating embodiment can merge into a module, it is also possible to is further split into multiple submodule.
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 is it can be understood that can be by the present invention
Software adds the mode of required general hardware platform and realizes, naturally it is also possible to by hardware, but a lot of in the case of the former is more
Good embodiment.Based on such understanding, prior art is contributed by technical scheme the most in other words
Part can embody with the form of software product, and this computer software product is stored in a storage medium, if including
Dry instruction is with so that a station terminal equipment (can be mobile phone, personal computer, server, or the network equipment etc.) performs basis
Invent the method described in each embodiment.
The above is only the preferred embodiment of the present invention, it is noted that for the ordinary skill people of the art
For Yuan, under the premise without departing from the principles of the invention, it is also possible to make some improvements and modifications, these improvements and modifications also should
Depending on protection scope of the present invention.