Summary of the invention
The purpose of the application is to provide method, system, equipment and the computer-readable storage of a kind of block chain data storage
Medium, for promoting block chain global storage performance.
In order to solve the above technical problems, the application provides a kind of method of block chain data storage, this method comprises:
Receive data write request;
Call bottom LSM storage engines that the corresponding data to be written of the data write request are written in journal file,
And it will be in the data write-in memory database to be written;
If the value of the data to be written is greater than or equal to predetermined threshold, stored in file system described to be written
The keyword and value pointer of data;Wherein, described value pointer includes the location information and length letter of the value of the data to be written
Breath.
Optionally, further includes:
Receive data read request;
The keyword of data to be read is determined according to the data read request;
Call the bottom LSM storage engines in sequence successively in the memory database, volatile data base and described
The corresponding data item of the keyword is searched in file system;
When the data item is the value pointer of the data to be read, parsing described value pointer obtains the access of continuing
According to location information, and get the value of the data to be read according to the positional information.
Optionally, in the calling bottom LSM storage engines in sequence successively in the memory database, ephemeral data
After searching the corresponding data item of the keyword in library and the file system, further includes:
If not finding the corresponding data item of the keyword, miscue information is returned.
Optionally, it after keyword and value pointer that the data to be written are stored in the LSM storage engines, also wraps
It includes:
Obtain block chain state of a process information;
When the block chain state of a process is idle, the legacy data in the journal file is recycled.
Optionally, the method also includes:
If the value of the data to be written is less than the predetermined threshold, stored in the file system described to be written
Enter the keyword and value of data.
The application also provides a kind of system of block chain data storage, which includes:
First receiving module, for receiving data write request;
First calling module, for calling bottom LSM storage engines by the corresponding number to be written of the data write request
According in write-in journal file, and the data to be written are written in memory database;
Memory module, if the value for the data to be written is greater than or equal to predetermined threshold, in file system
Store the keyword and value pointer of the data to be written;Wherein, described value pointer includes the position of the value of the data to be written
Confidence breath and length information.
Optionally, further includes:
Second receiving module, for receiving data read requests;
Determining module, for determining the keyword of data to be read according to the data read request;
Second calling module, for call the bottom LSM storage engines in sequence successively the memory database,
The corresponding data item of the keyword is searched in volatile data base and the file system;
First obtains module, for when the data item is the value pointer of the data to be read, parsing described value to refer to
Needle obtains the location information of the data to be read, and gets the value of the data to be read according to the positional information.
Optionally, further includes:
Return module, for returning to miscue information when not finding the corresponding data item of the keyword.
The application also provides a kind of block chain data storage device, which includes:
Memory, for storing computer program;
Processor realizes the side that the block chain data as described in any of the above-described store when for executing the computer program
The step of method.
The application also provides a kind of computer readable storage medium, and calculating is stored on the computer readable storage medium
Machine program, the method that the block chain data as described in any of the above-described store is realized when the computer program is executed by processor
Step.
The method of block chain data storage provided herein, comprising: receive data write request;Bottom LSM is called to deposit
Storage engine writes data into the corresponding data write-in journal file to be written of request, and is written into data write-in internal storage data
In library;If the value of data to be written is greater than or equal to predetermined threshold, the key of data to be written is stored in file system
Word and value pointer;Wherein, value pointer includes the location information and length information of the value of data to be written.
Technical solution provided herein, by be written into data be written memory database after, if to be written
Enter the value of data not less than predetermined threshold, then stores the keyword and value pointer of data to be written, in file system to reduce
The size of SSTable file, and the use of block chain is supplied in the form of plug-in unit, greatly delay SSTable file excessive
The caused slow problem of read-write, extends the service life of single node memory block chain data, and have the overall performance of data
The promotion of highly significant.The application additionally provides the system of block chain data storage a kind of, equipment and computer-readable simultaneously
Storage medium has above-mentioned beneficial effect, and details are not described herein.
Specific embodiment
The core of the application is to provide method, system, equipment and the computer-readable storage of a kind of block chain data storage
Medium, for promoting block chain global storage performance.
To keep the purposes, technical schemes and advantages of the embodiment of the present application clearer, below in conjunction with the embodiment of the present application
In attached drawing, the technical scheme in the embodiment of the application is clearly and completely described, it is clear that described embodiment is
Some embodiments of the present application, instead of all the embodiments.Based on the embodiment in the application, those of ordinary skill in the art
Every other embodiment obtained without making creative work, shall fall in the protection scope of this application.
Referring to FIG. 1, Fig. 1 is a kind of flow chart of the method for block chain data storage provided by the embodiment of the present application.
It specifically comprises the following steps:
S101: data write request is received;
Block chain stores data by LSM Tree structure, and LSM Tree is a kind of data knot based on the hard disk
Structure can reduce hard disk tracking expense, and can provide the high speed to file in longer time compared with B+tree significantly
It is inserted into (deletion).However LSM-tree is in some cases, especially when inquiry needs quick response, performance is bad.Usually
LSM-tree is suitable for indexing the insertion application system more more frequent than retrieving.
When the size of data stored in memory database reaches preset predetermined threshold, LSM storage engines can execute secondary
Union operation (Minor Compaction) is wanted, by the data persistence in memory database into file system, please refers to figure
2, Fig. 2 execute the schematic diagram of secondary union operation for LSM storage engines, as shown in Fig. 2, secondary union operation be choose one or
The data stored in multiple small, adjacent dump SSTable files and 0 or multiple memory databases are merged into one bigger
SSTable file, Minor Compaction's the result is that less and bigger SSTable file;
When there are following three kinds of situations, secondary union operation operation can be triggered:
1) when 0 layer of number of files is more than the scheduled upper limit;
2) when the maximum capacity limitation that the file total size of a certain layer has been more than this layer;
3) when some file is invalid read number it is excessive;
Referring to FIG. 3, Fig. 3 is the schematic diagram that LSM storage engines execute main union operation, as shown in figure 3, main merge
Operating (Major Compaction) is by the SSTable file of multiple low-levels and the SSTable for being merged into a high-level
File, under normal circumstances, the main union operation time can be persistently long, and whole process can consume a large amount of system resources, to upper
Layer service has bigger influence, and after data volume increases, level level can increase therewith, and LSM is caused to read scale-up problem
It is more obvious, therefore this application provides a kind of methods of block chain data storage, for solving the above problems.
S102: calling bottom LSM storage engines to write data into the corresponding data write-in journal file to be written of request,
And it is written into data write-in memory database;
After receiving data write request, block chain LSM storage engines can be written into data first and be sequentially written in
In journal file, lost to avoid the memory database data under abnormal conditions, as data WAL (Write-Ahead
Logging, write-ahead log) success after, then be written into data write-in memory database in, so far write operation complete;
WAL is a kind of efficient log algorithm in database, under identical data volume, using the database of WAL log
For system when affairs are submitted, disk write operation only has traditional half of rewind journal or so, substantially increases data library disk
The efficiency of I/O operation, to improve the performance of database.
S103: if the value of data to be written is greater than or equal to predetermined threshold, number to be written is stored in file system
According to keyword and value pointer;
Optionally, if the value of data to be written is less than predetermined threshold, data to be written are stored in file system
Keyword and value;
When the value of data to be written is less than predetermined threshold, be directly written into data keyword and data to be written
It is worth (key-value) to be stored in file system directly in the form of SSTable file;
Value pointer (key-valuepointer) mentioned herein includes the location information and length of the value of data to be written
The purpose of information, the keyword and value pointer that store data to be written in file system here is, reduces SSTable file
Size, and then the slow problem of read-write caused by having delayed SSTable file excessive;
Optionally, which is specifically as follows the data of 12 byte-sizeds, and content is as follows:
4 byte Fid |
4 byte Value Length |
4 byte Offiset |
Wherein, which value journal file Fid is used to record the values of the data to be written in, and Value Length is
The length of the value of the data to be written, Offiset are position of the value of the data to be written in value journal file;
Optionally, stored in LSM storage engines data to be written keyword and value pointer after, can also be performed as
Lower step:
Obtain block chain state of a process information;
When block chain state of a process is idle, the legacy data in journal file is recycled;
Legacy data of the embodiment of the present application when block chain process is idle in recycling journal file, to ensure storage overhead not
Can infinitely it be amplified;
According to the above technical scheme it is found that the performance boost of the bigger this programme of the value of data to be written is just more obvious, and area
The value of the most of data to be written of block chain is relatively large;And from the point of view of surveying result according to pressure, under 20,000,000 contract reference datas,
The LSM storage engines reading performance of technical solution provided herein is 2.8 times of prior art performance, and SSTable file is big
Small to be reduced to original 8%, block chain pressure is surveyed under scene, and LSM Compaction time-consuming is reduced to original 30%.The program
It is greatly improved the overall performance of block chain bottom LSM storage engines.
Based on the above-mentioned technical proposal, the method for a kind of block chain data storage provided herein, by will be to be written
After entering data write-in memory database, judge whether the value of data to be written is less than predetermined threshold, if data to be written
Value is not less than predetermined threshold, then the keyword and value pointer of data to be written are stored in file system, to reduce SSTable text
The size of part, and the use of block chain is supplied in the form of plug-in unit, read-write caused by greatly having delayed SSTable file excessive
Slow problem, extends the service life of single node memory block chain data, and the overall performance of data is made to have highly significant
Promotion.
It on the basis of the above embodiments, can also include step as shown in Figure 4 when receiving data read command
Suddenly, it is illustrated below with reference to Fig. 4.
Referring to FIG. 4, Fig. 4 is the process of the method for the storage of another kind block chain data provided by the embodiment of the present application
Figure.
Itself specifically includes the following steps:
S401: data read request is received;
S402: the keyword of data to be read is determined according to data read request;
S403: call bottom LSM storage engines in sequence successively in memory database, volatile data base and file system
The corresponding data item of middle search key;
Optionally, in calling bottom LSM storage engines in sequence successively in memory database, volatile data base and file
In system after the corresponding data item of search key, further includes:
If not finding the corresponding data item of keyword, miscue information is returned.
S404: when data item is the value pointer of data to be read, analytic value pointer obtains the position letter of data to be read
It ceases, and gets the value of data to be read according to location information.
Optionally, when data item is the value of data to be read, then the value for directly returning to the data to be read can be completed
Data read operation.
Optionally, above-mentioned steps S403- step S404 is specifically as follows:
1) the corresponding data item of search key in memory database, is directly entered step 4 if searching;
2) the corresponding data item of search key in volatile data base, is directly entered step 4 if searching;
3) the corresponding data item of lookup keyword incremented by successively since 0 level of file system is straight if searching
It connects and enters step 4;
4) it after getting data item, is directly returned the result when the data item is the value of data to be written.If value be to
The value pointer that data are written, then parse the value pointer, and enter in specified value journal file and get data to be written
Value;
Preferably, it is obtained since the SSTable file of 0 level executes Minor Compaction, therefore the application is real
When can also by all SSTable files of 0 level carry out mmap operation be mapped into memory, with promoted 0 level reading performance.
Referring to FIG. 5, Fig. 5 is a kind of structure chart of the system of block chain data storage provided by the embodiment of the present application.
The system may include:
First receiving module 100, for receiving data write request;
First calling module 200, for calling bottom LSM storage engines to write data into the corresponding data to be written of request
It is written in journal file, and is written into data write-in memory database;
Memory module 300 is deposited in file system if the value for data to be written is greater than or equal to predetermined threshold
Store up the keyword and value pointer of data to be written;Wherein, value pointer includes the location information and length letter of the value of data to be written
Breath.
Referring to FIG. 6, Fig. 6 is the structure of the system of the storage of another kind block chain data provided by the embodiment of the present application
Figure.
The system can also include:
Second receiving module, for receiving data read requests;
Determining module, for determining the keyword of data to be read according to data read request;
Second calling module, for calling bottom LSM storage engines in sequence successively in memory database, ephemeral data
The corresponding data item of search key in library and file system;
First obtains module, for when data item is the value pointer of data to be read, analytic value pointer to obtain to be read
The location information of data, and get according to location information the value of data to be read.
The system can also include:
Return module, for returning to miscue information when not finding the corresponding data item of keyword.
The system can also include:
Second obtains module, for obtaining block chain state of a process information;
Recycling module, for recycling the legacy data in journal file when block chain state of a process is idle.
Each component part in system above can be applied in embodiment below:
First receiving module receives data write request;First calling module calls bottom LSM storage engines to write data
Enter to request in corresponding data write-in journal file to be written, and is written into data write-in memory database;If to be written
The value for entering data is greater than or equal to predetermined threshold, then memory module stores the keyword and value of data to be written in file system
Pointer;Second, which obtains module, obtains block chain state of a process information;When block chain state of a process is idle, recycling module
Recycle the legacy data in journal file.
Second receiving module receives data read request;Determining module determines data to be read according to data read request
Keyword;Second calling module calls bottom LSM storage engines in sequence successively in memory database, volatile data base and text
The corresponding data item of search key in part system;When not finding the corresponding data item of keyword, return module returns wrong
Accidentally prompt information.When data item is the value pointer of data to be read, the first acquisition module analytic value pointer obtains access of continuing
According to location information, and get according to location information the value of data to be read.
Referring to FIG. 7, Fig. 7 is a kind of structure chart of block chain data storage device provided by the embodiment of the present application.
The block chain data storage device 700 can generate bigger difference because configuration or performance are different, may include
One or more processors (central processing units, CPU) 722 are (for example, one or more are handled
Device) and memory 732, one or more storage application programs 742 or data 744 storage medium 730 (such as one or
More than one mass memory unit).Wherein, memory 732 and storage medium 730 can be of short duration storage or persistent storage.It deposits
Storage may include one or more modules (diagram does not mark) in the program of storage medium 730, and each module may include
To the series of instructions operation in device.Further, central processing unit 722 can be set to communicate with storage medium 730,
The series of instructions operation in storage medium 730 is executed on block chain data storage device 700.
Block chain data storage device 700 can also include one or more power supplys 727, one or more have
Line or radio network interface 750, one or more input/output interfaces 758, and/or, one or more operation systems
System 741, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM etc..
Step in the method for the storage of block chain data described in above-mentioned Fig. 1 to Fig. 4 is by block chain data storage device
It is realized based on the structure shown in Fig. 7.
It is apparent to those skilled in the art that for convenience and simplicity of description, the system of foregoing description,
The specific work process of device and module, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
In several embodiments provided herein, it should be understood that disclosed device, device and method, it can be with
It realizes by another way.For example, the apparatus embodiments described above are merely exemplary, for example, the division of module,
Only a kind of logical function partition, there may be another division manner in actual implementation, such as multiple module or components can be with
In conjunction with or be desirably integrated into another system, or some features can be ignored or not executed.Another point, it is shown or discussed
Mutual coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING of device or module or
Communication connection can be electrical property, mechanical or other forms.
Module may or may not be physically separated as illustrated by the separation member, show as module
Component may or may not be physical module, it can and it is in one place, or may be distributed over multiple networks
In module.Some or all of the modules therein can be selected to achieve the purpose of the solution of this embodiment according to the actual needs.
It, can also be in addition, can integrate in a processing module in each functional module in each embodiment of the application
It is that modules physically exist alone, can also be integrated in two or more modules in a module.Above-mentioned integrated mould
Block both can take the form of hardware realization, can also be realized in the form of software function module.
If integrated module is realized and when sold or used as an independent product in the form of software function module, can
To be stored in a computer readable storage medium.Based on this understanding, the technical solution of the application substantially or
Say that all or part of the part that contributes to existing technology or the technical solution can embody in the form of software products
Out, which is stored in a storage medium, including some instructions are used so that a computer equipment
The whole of (can be personal computer, funcall device or the network equipment etc.) execution each embodiment method of the application
Or part steps.And storage medium above-mentioned include: USB flash disk, mobile hard disk, read-only memory (Read-Only Memory,
ROM), random access memory (Random Access Memory, RAM), magnetic or disk etc. are various can store program
The medium of code.
It to a kind of method of block chain data storage provided herein, system, equipment and computer-readable deposits above
Storage media is described in detail.Specific examples are used herein to illustrate the principle and implementation manner of the present application,
The description of the example is only used to help understand the method for the present application and its core ideas.It should be pointed out that for this technology
For the those of ordinary skill in field, under the premise of not departing from the application principle, several improvement can also be carried out to the application
And modification, these improvement and modification are also fallen into the protection scope of the claim of this application.
It should also be noted that, in the present specification, relational terms such as first and second and the like be used merely to by
One entity or operation are distinguished with another entity or operation, without necessarily requiring or implying these entities or operation
Between there are any actual relationship or orders.Moreover, the terms "include", "comprise" or its any other variant meaning
Covering non-exclusive inclusion, so that the process, method, article or equipment for including a series of elements not only includes that
A little elements, but also including other elements that are not explicitly listed, or further include for this process, method, article or
The intrinsic element of equipment.In the absence of more restrictions, the element limited by sentence "including a ...", is not arranged
Except there is also other identical elements in the process, method, article or equipment for including element.