Summary of the invention
Technical matters to be solved by this invention is: for prior art Problems existing, a kind of memory database querying method based on key-value pair and device are provided, the present invention is separated by data separating, operation, the mode of key assignments inquiry, and in conjunction with the advantage of different pieces of information structure, organising data.Particular by all non-query manipulation of this memory database of interface line thread management; The data encasement block of data query is outputted to, by the Data Update of data manipulation buffer zone to real time data by the sequence of Data Update thread real time data; Then management data query block, data encasement block, and after data ready, realize switching between the two.Query interface only visit data query block data are set simultaneously, reach object of the present invention.
The technical solution used in the present invention is as follows:
A kind of memory database querying method based on key-value pair comprises:
Step 1: with random value by after Hash algorithm for encryption, query key will be formed, and query key and described character string structure are formed a key-value pair;
Step 2: memory database maintenance module arranges the data manipulation buffer zone that memory database maintenance module application memory size can be arranged; Construct a RB_Tree as real time data district; Apply for that one piece of shared drive is as data query district, and data query district head, data query block pointer, data encasement block pointer, data query block, data encasement block are set for data query district;
Step 3: memory database maintenance module opens the Data Update thread for the interface thread and data real-time update carrying out command operating; Described unlatching thread receives data operation commands and data by Socket, and by data manipulation instruction and data write data manipulation buffer zone;
Step 4: client call query interface, query interface, according to the pointed of data query district head, carries out dichotomy inquiry according to key-value pair, and returns Query Result by query interface in data query district.
Further, in described step 3, the Data Update thread specific works process of data real-time update is:
Step 31: memory database maintenance module turn-on data more new thread, described Data Update thread, by the data of data manipulation buffer zone, adds real time data district to by data manipulation instruction;
Step 32: after having added data, Data Update thread is by real time data district data sorting and output to data encasement block;
Step 33: after data output to data encasement block completely, Data Update thread exchanges and points to the pointer of data query block and the pointer of data encasement block; The described pointer of sensing data query block and the pointer of data encasement block are arranged in data query build portion (reaching the object exchanging data query block and data encasement block), perform step 31.
A kind of memory database inquiry unit based on key-value pair comprises:
Key-value pair forms module, for random value by after Hash algorithm for encryption, forming query key, and query key and described character string structure are formed a key-value pair;
Memory database maintenance module, for arranging the data manipulation buffer zone that memory database maintenance module application memory size can be arranged; Construct a RB_Tree as real time data district; Apply for that one piece of shared drive is as data query district, and data query district head, data query block pointer, data encasement block pointer, data query block, data encasement block are set for data query district; Then memory database maintenance module opens the Data Update thread for the interface thread and data real-time update carrying out command operating; Described unlatching thread receives data operation commands and data by Socket, and by data manipulation instruction and data write data manipulation buffer zone;
Client, for calling query interface, query interface, according to the pointed of data query district head, carries out dichotomy inquiry according to key-value pair, and returns Query Result by query interface in data query district.
Further, the Data Update thread specific works process of described data real-time update is:
Step 31: memory database maintenance module turn-on data more new thread, described Data Update thread, by the data of data manipulation buffer zone, adds real time data district to by data manipulation instruction;
Step 32: after having added data, Data Update thread is by real time data district data sorting and output to data encasement block;
Step 33: after data output to data encasement block completely, Data Update thread exchanges and points to the pointer of data query block and the pointer of data encasement block; The described pointer of sensing data query block and the pointer of data encasement block are arranged in data query build portion (reaching the object exchanging data query block and data encasement block), perform step 31.
In sum, owing to have employed technique scheme, the invention has the beneficial effects as follows:
1, be separated by data separating, operation, the mode of key assignments inquiry, and in conjunction with the advantage of different pieces of information structure, organising data.
2, query manipulation is separated with non-query manipulation, and the non-query manipulation of database is by interface line thread management, and query manipulation can carry out at any time, and without any need for mutual exclusion action.
3, real time data is separated with data query.Data query block, data encasement block are separated, and by interface line thread management, external inquiry is without any perception.
The advantage of the present invention compared with existing database, data query structure is that can bear high frequency inquires about, and can return Query Result at a high speed, can support ten million order of magnitude, can not affect the ability of the memory database of normal queries operation when data manipulation;
Through actual measurement, when 2,000 ten thousand character string, 1,000 ten thousand concurrent inquiries, average lookup time only needs 7us, the poorest about 10us, optimum approximately 3us.
Embodiment
All features disclosed in this instructions, or the step in disclosed all methods or process, except mutually exclusive feature and/or step, all can combine by any way.
Arbitrary feature disclosed in this instructions (comprising any accessory claim, summary and accompanying drawing), unless specifically stated otherwise, all can be replaced by other equivalences or the alternative features with similar object.That is, unless specifically stated otherwise, each feature is an example in a series of equivalence or similar characteristics.
1, random value refers to arbitrary string, numeral;
2, data manipulation instruction refers to the instructions such as interpolation, deletion or amendment;
3, memory database maintenance module can be realized by a process;
4, data separating, operation separation, key assignments inquiry.Utilize the advantage of different pieces of information structure, organising data.By allowing certain data syn-chronization time delay, the entirety realizing memory database is efficient.
5, DATA POPULATION is divided into 3 parts: data manipulation buffer zone, real time data 1 district, data query district.Data query is divided into again: data query block, data encasement block.
The course of work of the present invention:
One, interface thread is used to manage all non-query manipulation of this memory database.
1 by the Data Update of data manipulation buffer zone to real time data.
Real time data sequence is outputted to the data encasement block of data query by 2.
3 management data query blocks, data encasement block.Switching is between the two realized after data ready.
Two, query interface only visit data query block.
Query manipulation can carry out at any time, and without any need for mutual exclusion action.
Specific embodiment: a kind of memory database querying method based on key-value pair comprises:
Step 1: with random value by after Hash algorithm for encryption, query key will be formed, and query key and described character string structure are formed a key-value pair;
Step 2: memory database maintenance module arranges the data manipulation buffer zone that memory database maintenance module application memory size can be arranged; Construct a RB_Tree as real time data district; Apply for that one piece of shared drive is as data query district, and data query district head, data query block pointer, data encasement block pointer, data query block, data encasement block are set for data query district;
Step 3: memory database maintenance module opens the Data Update thread for the interface thread and data real-time update carrying out command operating; Described unlatching thread receives data operation commands and data by Socket, and by data manipulation instruction and data write data manipulation buffer zone;
Step 4: client call query interface, query interface, according to the pointed of data query district head, carries out dichotomy inquiry according to key-value pair, and returns Query Result by query interface in data query district.
Wherein, in described step 3, the Data Update thread specific works process of data real-time update is:
Step 31: memory database maintenance module turn-on data more new thread, described Data Update thread, by the data of data manipulation buffer zone, adds real time data district to by data manipulation instruction;
Step 32: after having added data, Data Update thread is by real time data district data sorting and output to data encasement block;
Step 33: after data output to data encasement block completely, Data Update thread exchanges and points to the pointer of data query block and the pointer of data encasement block; The described pointer of sensing data query block and the pointer of data encasement block are arranged in data query build portion (reaching the object exchanging data query block and data encasement block), perform step 31.
The present invention is not limited to aforesaid embodiment.The present invention expands to any new feature of disclosing in this manual or any combination newly, and the step of the arbitrary new method disclosed or process or any combination newly.