CN110532228B - Method, system and equipment for reading block chain data and readable storage medium - Google Patents
Method, system and equipment for reading block chain data and readable storage medium Download PDFInfo
- Publication number
- CN110532228B CN110532228B CN201910824394.5A CN201910824394A CN110532228B CN 110532228 B CN110532228 B CN 110532228B CN 201910824394 A CN201910824394 A CN 201910824394A CN 110532228 B CN110532228 B CN 110532228B
- Authority
- CN
- China
- Prior art keywords
- data
- keyword
- data item
- item corresponding
- blockchain
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/13—File access structures, e.g. distributed indices
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/14—Details of searching files based on file metadata
- G06F16/148—File search processing
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/1727—Details of free space management performed by the file system
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/18—File system types
- G06F16/1805—Append-only file systems, e.g. using logs or journals to store data
- G06F16/1815—Journaling file systems
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Library & Information Science (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请公开了一种区块链数据读取的方法,包括:接收数据读取请求;根据数据读取请求确定待读取数据的关键字;调用底层LSM存储引擎依次在内存数据库及临时数据库中查找关键字对应的数据项;若未查找到关键字对应的数据项,则在文件系统的各个层级中并行查找关键字对应的数据项。本申请通过在内存数据库及临时数据库中未查找到关键字对应的数据项时,在文件系统的各个层级中并行查找关键字对应的数据项,以缩减区块链读操作的时间开销,极大的降低了由于LSM层级过多而导致的读写缓慢问题,使LSM读性能有了非常显著的提升。本申请同时还提供了一种区块链数据读取的系统、设备及计算机可读存储介质,具有上述有益效果。
The present application discloses a method for reading blockchain data, including: receiving a data reading request; determining a keyword of the data to be read according to the data reading request; calling the underlying LSM storage engine to sequentially store data in an in-memory database and a temporary database The data item corresponding to the keyword is searched; if the data item corresponding to the keyword is not found, the data item corresponding to the keyword is searched in parallel in each level of the file system. In the present application, when the data item corresponding to the keyword is not found in the in-memory database and the temporary database, the data item corresponding to the keyword is searched in parallel in each level of the file system, so as to reduce the time overhead of the blockchain read operation, greatly reducing the time overhead of the blockchain read operation. It reduces the problem of slow reading and writing caused by too many LSM layers, so that the LSM read performance has been significantly improved. The present application also provides a system, device and computer-readable storage medium for reading blockchain data, which have the above beneficial effects.
Description
技术领域technical field
本申请涉及区块链领域,特别涉及一种区块链数据读取的方法、系统、设备及计算机可读存储介质。The present application relates to the field of blockchain, and in particular, to a method, system, device and computer-readable storage medium for reading blockchain data.
背景技术Background technique
区块链通过LSM Tree(Log Structure Merge Tree,日志结构合并树)结构对数据进行存储,传统的LSM Tree可以通过level db(google实现的非常高效的kv数据库)、rocksdb(嵌入式Key-value存储系统)等实现对数据的存储,其优点是通过将磁盘的随机写转化成顺序写,以达到最优的写性能,从而快速地建立索引。The blockchain stores data through the LSM Tree (Log Structure Merge Tree) structure. The traditional LSM Tree can be stored through level db (a very efficient kv database implemented by google) and rocksdb (embedded Key-value storage). System) to realize the storage of data, the advantage of which is to achieve the optimal write performance by converting the random write of the disk into a sequential write, so as to quickly build an index.
然而,随着数据量不断的增大,level层级的增多,LSM读放大问题更加明显,而且LSM Compaction开销激增,压力环境下尤其明显,影响区块链进程整体性能。However, as the amount of data increases and the level increases, the problem of LSM read amplification becomes more obvious, and the overhead of LSM compaction surges, especially in a stressful environment, which affects the overall performance of the blockchain process.
因此,如何提升区块链整体读取性能是本领域技术人员目前需要解决的技术问题。Therefore, how to improve the overall read performance of the blockchain is a technical problem that needs to be solved by those skilled in the art.
发明内容SUMMARY OF THE INVENTION
本申请的目的是提供一种区块链数据读取的方法、系统、设备及计算机可读存储介质,用于提升区块链整体读取性能。The purpose of this application is to provide a method, system, device and computer-readable storage medium for reading blockchain data, which are used to improve the overall reading performance of the blockchain.
为解决上述技术问题,本申请提供一种区块链数据读取的方法,该方法包括:In order to solve the above technical problems, the present application provides a method for reading blockchain data, the method comprising:
接收数据读取请求;Receive data read requests;
根据所述数据读取请求确定待读取数据的关键字;Determine the keyword of the data to be read according to the data read request;
调用底层LSM存储引擎依次在内存数据库及临时数据库中查找所述关键字对应的数据项;Invoke the underlying LSM storage engine to find the data item corresponding to the keyword in the memory database and the temporary database in turn;
若未查找到所述关键字对应的数据项,则在文件系统的各个层级中并行查找所述关键字对应的数据项。If the data item corresponding to the keyword is not found, the data item corresponding to the keyword is searched in parallel in each level of the file system.
可选的,在所述在文件系统的各个层级中并行查找所述关键字对应的数据项之后,还包括:Optionally, after the parallel search for the data item corresponding to the keyword in each level of the file system, the method further includes:
判断是否查找到所述关键字对应的数据项;Determine whether the data item corresponding to the keyword is found;
若否,则返回错误提示信息;If not, return an error message;
若是,则判断查找到的所述数据项是否唯一;If yes, then judge whether the found data item is unique;
当所述数据项不唯一时,返回所述层级最低的数据项。When the data item is not unique, the data item with the lowest level is returned.
可选的,还包括:Optionally, also include:
接收数据写入请求;Receive data write request;
调用所述底层LSM存储引擎将所述数据写入请求对应的待写入数据写入日志文件中,并将所述待写入数据写入所述内存数据库中;Invoke the underlying LSM storage engine to write the data to be written corresponding to the data write request into the log file, and write the data to be written into the in-memory database;
当所述内存数据库中存储的数据达到预定阈值时,执行次要合并操作,以将所述内存数据库中存储的数据持久化到所述文件系统中。When the data stored in the in-memory database reaches a predetermined threshold, a secondary merge operation is performed to persist the data stored in the in-memory database to the file system.
可选的,在所述执行次要合并操作之后,还包括:Optionally, after the performing the secondary merge operation, the method further includes:
获取区块链进程的状态信息;Get the status information of the blockchain process;
当所述区块链进程的状态为闲置时,回收所述日志文件中的旧数据。When the state of the blockchain process is idle, the old data in the log file is recovered.
可选的,所述文件系统的存储介质为固态硬盘;Optionally, the storage medium of the file system is a solid-state hard disk;
所述文件系统中SSTable文件的大小为1mb、2mb、4mb中的至少一项。The size of the SSTable file in the file system is at least one of 1mb, 2mb, and 4mb.
可选的,所述在文件系统的各个层级中并行查找所述关键字对应的数据项,包括:Optionally, the parallel search for the data item corresponding to the keyword in each level of the file system includes:
通过内存映射文件方式将所述文件系统的零层级中的数据项映射至所述内存数据库中;mapping data items in the zero-level of the file system to the in-memory database by means of a memory-mapped file;
在所述内存数据库中查找所述关键字对应的数据项。Search the data item corresponding to the keyword in the memory database.
本申请还提供一种区块链数据读取的系统,该系统包括:The application also provides a system for reading blockchain data, the system comprising:
第一接收模块,用于接收数据读取请求;a first receiving module, configured to receive a data read request;
确定模块,用于根据所述数据读取请求确定待读取数据的关键字;a determining module, configured to determine the keyword of the data to be read according to the data read request;
第一调用模块,用于调用底层LSM存储引擎依次在内存数据库及临时数据库中查找所述关键字对应的数据项;The first calling module is used to call the underlying LSM storage engine to search the data item corresponding to the keyword in the memory database and the temporary database in turn;
并行查找模块,用于当未查找到所述关键字对应的数据项时,在文件系统的各个层级中并行查找所述关键字对应的数据项。The parallel search module is configured to search for the data item corresponding to the keyword in parallel in each level of the file system when the data item corresponding to the keyword is not found.
可选的,还包括:Optionally, also include:
第一判断模块,用于判断是否查找到所述关键字对应的数据项;a first judgment module, used for judging whether the data item corresponding to the keyword is found;
第一返回模块,用于当未查找到所述关键字对应的数据项时,返回错误提示信息;The first return module is used to return error prompt information when the data item corresponding to the keyword is not found;
第二判断模块,用于当查找到所述关键字对应的数据项时,判断查找到的所述数据项是否唯一;a second judgment module, configured to judge whether the found data item is unique when the data item corresponding to the keyword is found;
第二返回模块,用于当所述数据项不唯一时,返回所述层级最低的数据项。The second returning module is configured to return the data item with the lowest level when the data item is not unique.
本申请还提供一种区块链数据读取设备,该区块链数据读取设备包括:The application also provides a blockchain data reading device, the blockchain data reading device includes:
存储器,用于存储计算机程序;memory for storing computer programs;
处理器,用于执行所述计算机程序时实现如上述任一项所述区块链数据读取的方法的步骤。The processor is configured to implement the steps of the method for reading blockchain data according to any one of the above when executing the computer program.
本申请还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如上述任一项所述区块链数据读取的方法的步骤。The present application also provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the method for reading blockchain data according to any one of the above A step of.
本申请所提供区块链数据读取的方法,包括:接收数据读取请求;根据数据读取请求确定待读取数据的关键字;调用底层LSM存储引擎依次在内存数据库及临时数据库中查找关键字对应的数据项;若未查找到所述关键字对应的数据项,则在文件系统的各个层级中并行查找关键字对应的数据项。The method for reading blockchain data provided by this application includes: receiving a data reading request; determining the keyword of the data to be read according to the data reading request; calling the underlying LSM storage engine to sequentially search for the key in the memory database and the temporary database If the data item corresponding to the keyword is not found, the data item corresponding to the keyword is searched in parallel in each level of the file system.
本申请所提供的技术方案,通过在内存数据库及临时数据库中未查找到关键字对应的数据项时,在文件系统的各个层级中并行查找关键字对应的数据项,以缩减区块链读操作的时间开销,并以插件的形式提供给区块链使用,极大的降低了由于LSM层级过多而导致的读写缓慢问题,使LSM读性能有了非常显著的提升。本申请同时还提供了一种区块链数据读取的系统、设备及计算机可读存储介质,具有上述有益效果,在此不再赘述。The technical solution provided by the present application, when the data item corresponding to the keyword is not found in the memory database and the temporary database, the data item corresponding to the keyword is searched in parallel in each level of the file system, so as to reduce the block chain read operation The time overhead of LSM is provided to the blockchain in the form of a plug-in, which greatly reduces the slow reading and writing problem caused by too many LSM layers, and greatly improves the LSM read performance. The present application also provides a system, device and computer-readable storage medium for reading blockchain data, which have the above beneficial effects, and will not be repeated here.
附图说明Description of drawings
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only It is an embodiment of the present application. For those of ordinary skill in the art, other drawings can also be obtained according to the provided drawings without any creative effort.
图1为本申请实施例所提供的一种区块链数据读取的方法的流程图;1 is a flowchart of a method for reading blockchain data provided by an embodiment of the present application;
图2为LSM存储引擎执行次要合并操作的示意图;Figure 2 is a schematic diagram of the LSM storage engine performing a secondary merge operation;
图3为LSM存储引擎执行主要合并操作的示意图;Fig. 3 is the schematic diagram that LSM storage engine performs main merge operation;
图4为本申请实施例所提供的另一种区块链数据读取的方法的流程图;4 is a flowchart of another method for reading blockchain data provided by an embodiment of the present application;
图5为本申请实施例所提供的一种区块链数据读取的系统的结构图;5 is a structural diagram of a system for reading blockchain data provided by an embodiment of the present application;
图6为本申请实施例所提供的另一种区块链数据读取的系统的结构图;FIG. 6 is a structural diagram of another blockchain data reading system provided by an embodiment of the present application;
图7为本申请实施例所提供的一种区块链数据读取设备的结构图。FIG. 7 is a structural diagram of a block chain data reading device provided by an embodiment of the present application.
具体实施方式Detailed ways
本申请的核心是提供一种区块链数据读取的方法、系统、设备及计算机可读存储介质,用于提升区块链整体读取性能。The core of this application is to provide a method, system, device and computer-readable storage medium for reading blockchain data, which are used to improve the overall reading performance of the blockchain.
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments It is a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
请参考图1,图1为本申请实施例所提供的一种区块链数据读取的方法的流程图。Please refer to FIG. 1 , which is a flowchart of a method for reading blockchain data provided by an embodiment of the present application.
其具体包括如下步骤:It specifically includes the following steps:
S101:接收数据读取请求;S101: Receive a data read request;
区块链通过LSM Tree结构对数据进行存储,LSM Tree是一种基于硬盘的数据结构,与B+tree相比,能显著地减少硬盘磁盘寻道开销,并能在较长的时间提供对文件的高速插入(删除)。然而LSM-tree在某些情况下,特别是在查询需要快速响应时性能不佳。通常LSM-tree适用于索引插入比检索更频繁的应用系统。The blockchain stores data through the LSM Tree structure. LSM Tree is a hard disk-based data structure. Compared with B+tree, it can significantly reduce the overhead of hard disk and disk seek, and can provide files for a long time. high-speed insertion (deletion). However, LSM-tree performs poorly in some cases, especially when queries require fast responses. Usually LSM-tree is suitable for applications where index insertion is more frequent than retrieval.
当内存数据库中存储的数据大小达到预设的预定阈值时,LSM存储引擎会执行次要合并操作(Minor Compaction),将内存数据库中的数据持久化到文件系统中,请参考图2,图2为LSM存储引擎执行次要合并操作的示意图,如图2所示,次要合并操作是选取一个或多个小的、相邻的转储SSTable文件与0个或多个内存数据库中存储的数据合并成一个更大的SSTable文件,一次Minor Compaction的结果是更少并且更大的SSTable文件;When the size of the data stored in the in-memory database reaches a preset predetermined threshold, the LSM storage engine will perform a minor consolidation operation (Minor Compaction) to persist the data in the in-memory database to the file system, please refer to Figure 2, Figure 2 A schematic diagram of performing a secondary merge operation for the LSM storage engine, as shown in Figure 2, the secondary merge operation is to select one or more small, adjacent dump SSTable files and zero or more data stored in in-memory databases Merged into a larger SSTable file, the result of a Minor Compaction is fewer and larger SSTable files;
当存在如下三种情况时,会触发次要合并操作操作:The secondary merge operation is triggered when there are three conditions as follows:
1)当0层文件数超过预定的上限;1) When the number of files at level 0 exceeds the predetermined upper limit;
2)当某一层的文件总大小超过了该层的最大容量限制;2) When the total file size of a layer exceeds the maximum capacity limit of the layer;
3)当某个文件无效读取的次数过多;3) When a certain file is read invalidly too many times;
请参考图3,图3为LSM存储引擎执行主要合并操作的示意图,如图3所示,主要合并操作(Major Compaction)是将多个低层级的SSTable文件和合并成一个高层级的SSTable文件,一般情况下,主要合并操作时间会持续比较长,整个过程会消耗大量系统资源,对上层业务有比较大的影响,而当数据量增大之后,level层级会随之增多,导致LSM读放大问题更加明显,故本申请提供了一种区块链数据读取的方法,用于解决上述问题。Please refer to FIG. 3. FIG. 3 is a schematic diagram of the LSM storage engine performing the main merge operation. As shown in FIG. 3, the major merge operation (Major Compaction) is to merge multiple low-level SSTable files into a high-level SSTable file. Under normal circumstances, the main merge operation time will last for a long time, and the whole process will consume a lot of system resources, which will have a relatively large impact on the upper-layer business. When the amount of data increases, the level level will increase accordingly, resulting in LSM read amplification problem It is more obvious, so the present application provides a method for reading blockchain data, which is used to solve the above problems.
S102:根据数据读取请求确定待读取数据的关键字;S102: Determine the keyword of the data to be read according to the data read request;
S103:调用底层LSM存储引擎依次在内存数据库及临时数据库中查找关键字对应的数据项;S103: Invoke the underlying LSM storage engine to sequentially search the in-memory database and the temporary database for the data item corresponding to the keyword;
基于该待读取数据的值可能存在于内存数据库、临时数据库或文件系统中,因此本申请实施例在根据数据读取请求确定待读取数据的关键字之后,调用底层LSM存储引擎依次在内存数据库及临时数据库中查找关键字对应的数据项,若查找到了,则直接返回该数据项即可完成数据的读操作。The value based on the data to be read may exist in an in-memory database, a temporary database, or a file system. Therefore, in this embodiment of the present application, after the keyword of the data to be read is determined according to the data read request, the underlying LSM storage engine is called to store the data in the memory in turn. The data item corresponding to the keyword is searched in the database and the temporary database. If the data item is found, the data item can be directly returned to complete the data read operation.
S104:若未查找到关键字对应的数据项,则在文件系统的各个层级中并行查找关键字对应的数据项。S104: If the data item corresponding to the keyword is not found, search for the data item corresponding to the keyword in each hierarchy of the file system in parallel.
可选的,这里提到的在文件系统的各个层级中并行查找关键字对应的数据项,其具体可以为:Optionally, the parallel search for data items corresponding to keywords in each level of the file system mentioned here may specifically be:
通过内存映射文件方式将文件系统的零层级中的数据项映射至内存数据库中;Map the data items in the zero-level file system to the in-memory database by means of memory-mapped files;
在内存数据库中查找关键字对应的数据项;Find the data item corresponding to the keyword in the memory database;
由于level 0层是特殊的一层,其SSTable文件由memtable执行Minor Compaction操作直接得到,因此在level 0层中的key是无序的,一次LSM读操作在level 0中可能会读取多个文件,极端场景下我们会串行的读取level 0层中的所有SSTable文件,level 0中的读操作也可以执行并发读操作。但是level 0中的SSTable文件存储空间较小,因此本申请实施例采取level 0层中的文件通过mmap方式映射至内存的方式提升读性能;Since the level 0 layer is a special layer, its SSTable file is directly obtained by the Minor Compaction operation performed by memtable, so the keys in the level 0 layer are out of order, and an LSM read operation may read multiple files in level 0. , in extreme scenarios, we will serially read all SSTable files in the level 0 layer, and the read operations in level 0 can also perform concurrent read operations. However, the storage space of the SSTable file in level 0 is small, so in the embodiment of the present application, the file in the level 0 layer is mapped to the memory by mmap to improve the read performance;
可选的,在在文件系统的各个层级中并行查找关键字对应的数据项之后,还可以执行如下步骤:Optionally, after the data items corresponding to the keywords are searched in parallel in each level of the file system, the following steps may also be performed:
判断是否查找到关键字对应的数据项;Determine whether the data item corresponding to the keyword is found;
若否,则返回错误提示信息;If not, return an error message;
若是,则判断查找到的数据项是否唯一;If yes, then judge whether the found data item is unique;
当数据项不唯一时,返回层级最低的数据项。When the data item is not unique, the data item with the lowest level is returned.
可选的,当数据项唯一时,直接返回该数据项即可;Optionally, when the data item is unique, just return the data item directly;
这里提到的当数据项不唯一时返回层级最低的数据项的目的在于,文件系统中层级越低的数据越新,因此返回层级最低的数据项;The purpose of returning the data item with the lowest level when the data item is not unique mentioned here is that the data with the lower level in the file system is newer, so the data item with the lowest level is returned;
优选的,由于当某个文件无效读次数过多时会触发LSM的Major Compaction操作,而并发读特性无疑会放大文件无效读带来的影响,因此本申请实施例还可以在并发读方案中将文件无效读触发LSM的Major Compaction的条件去除,以避免文件无效读次数过多导致的Major Compaction操作造成的性能损耗问题;Preferably, because the Major Compaction operation of LSM will be triggered when a certain file has too many invalid reads, and the concurrent read feature will undoubtedly magnify the impact of invalid file reads, the embodiment of the present application may also include files in the concurrent read scheme. Remove the condition that invalid read triggers Major Compaction of LSM to avoid performance loss caused by Major Compaction operation caused by excessive number of invalid file reads;
优选的,由于固态硬盘具有随机读性能优势,因此使用固态硬盘的区块链节点利用本方案更能增加LSM的读性能;在此基础上,还可以将区块链LSM存储的SSTable文件大小由64kb调整至1mb、2mb或4mb,以使SSTable文件更适用于固态硬盘存储介质;Preferably, since solid-state drives have the advantage of random read performance, blockchain nodes using solid-state drives can use this solution to increase the read performance of LSM; on this basis, the size of the SSTable file stored in the blockchain LSM can be changed from 64kb adjusted to 1mb, 2mb or 4mb to make SSTable files more suitable for SSD storage media;
由于当前市面上常见的固态硬盘存储介质可支持10万iops的读写能力,完全可以满足基于level层级的并发读特性,因此本申请所提供的技术方案能够使得固态硬盘的随机读性能得以发挥,将原本需要读N层的时间,统一优化为读1层的时间,由于固态硬盘拥有较高的iops能力,而且由于区块链每秒读db数据量较小的缘故,使得LSM并发读方案在区块链项目中能够得到很好的施展;Since the common solid-state hard disk storage media currently on the market can support a read and write capability of 100,000 iops, which can fully meet the level-based concurrent read characteristics, the technical solution provided in this application can make the random read performance of the solid-state hard disk be utilized. The time that originally needed to read N layers is uniformly optimized to the time to read 1 layer. Because solid-state drives have high iops capability, and because the blockchain reads a small amount of db data per second, the LSM concurrent read solution is It can be well displayed in the blockchain project;
基于上述技术方案,本申请所提供的一种区块链数据读取的方法,通过在内存数据库及临时数据库中未查找到关键字对应的数据项时,在文件系统的各个层级中并行查找关键字对应的数据项,以缩减区块链读操作的时间开销,并以插件的形式提供给区块链使用,极大的降低了由于LSM层级过多而导致的读写缓慢问题,使LSM读性能有了非常显著的提升。Based on the above technical solutions, a method for reading blockchain data provided by the present application, by searching for the key in each level of the file system in parallel when the data item corresponding to the keyword is not found in the memory database and the temporary database The data item corresponding to the word can reduce the time overhead of the blockchain read operation, and provide it to the blockchain in the form of a plug-in. Performance has been significantly improved.
在上述实施例的基础上,当接收到数据写入命令时,还可以包括如图4所示的步骤,下面结合图4进行说明。On the basis of the above embodiment, when a data write command is received, the steps shown in FIG. 4 may also be included, which will be described below with reference to FIG. 4 .
请参考图4,图4为本申请实施例所提供的另一种区块链数据存储的方法的流程图。Please refer to FIG. 4 , which is a flowchart of another method for storing blockchain data provided by an embodiment of the present application.
其具体包括以下步骤:It specifically includes the following steps:
S401:接收数据写入请求;S401: Receive a data write request;
S402:调用底层LSM存储引擎将数据写入请求对应的待写入数据写入日志文件中,并将待写入数据写入内存数据库中;S402: Invoke the underlying LSM storage engine to write the data to be written corresponding to the data write request into the log file, and write the data to be written into the in-memory database;
S403:当内存数据库中存储的数据达到预定阈值时,执行次要合并操作,以将内存数据库中存储的数据持久化到文件系统中。S403: When the data stored in the in-memory database reaches a predetermined threshold, perform a secondary merge operation to persist the data stored in the in-memory database to the file system.
这里提到的次要合并操作即为上文中提到的Minor Compaction;The minor merge operation mentioned here is the Minor Compaction mentioned above;
可选的,在执行次要合并操作之后,还可以执行如下步骤:Optionally, after the secondary merge operation is performed, the following steps may also be performed:
获取区块链进程的状态信息;Get the status information of the blockchain process;
当区块链进程的状态为闲置时,回收日志文件中的旧数据。When the state of the blockchain process is idle, the old data in the log file is recycled.
本申请实施例在区块链进程闲置时回收日志文件中的旧数据,以确保存储开销不会被无限放大。In the embodiment of the present application, old data in the log file is recovered when the blockchain process is idle, so as to ensure that the storage overhead is not infinitely amplified.
请参考图5,图5为本申请实施例所提供的一种区块链数据读取的系统的结构图。Please refer to FIG. 5 , which is a structural diagram of a system for reading blockchain data provided by an embodiment of the present application.
该系统可以包括:The system can include:
第一接收模块100,用于接收数据读取请求;a
确定模块200,用于根据数据读取请求确定待读取数据的关键字;A
第一调用模块300,用于调用底层LSM存储引擎依次在内存数据库及临时数据库中查找关键字对应的数据项;The
并行查找模块400,用于当未查找到关键字对应的数据项时,在文件系统的各个层级中并行查找关键字对应的数据项。The
请参考图6,图6为本申请实施例所提供的另一种区块链数据读取的系统的结构图。Please refer to FIG. 6 , which is a structural diagram of another system for reading blockchain data provided by an embodiment of the present application.
该系统还可以包括:The system may also include:
第一判断模块,用于判断是否查找到关键字对应的数据项;The first judgment module is used for judging whether the data item corresponding to the keyword is found;
第一返回模块,用于当未查找到关键字对应的数据项时,返回错误提示信息;The first return module is used to return an error message when the data item corresponding to the keyword is not found;
第二判断模块,用于当查找到关键字对应的数据项时,判断查找到的数据项是否唯一;The second judgment module is used for judging whether the found data item is unique when the data item corresponding to the keyword is found;
第二返回模块,用于当数据项不唯一时,返回层级最低的数据项。The second return module is used to return the data item with the lowest level when the data item is not unique.
该系统还可以包括:The system may also include:
第二接收模块,用于接收数据写入请求;a second receiving module, configured to receive a data write request;
第二调用模块,用于调用底层LSM存储引擎将数据写入请求对应的待写入数据写入日志文件中,并将待写入数据写入内存数据库中;The second calling module is used to call the underlying LSM storage engine to write the data to be written corresponding to the data write request into the log file, and to write the data to be written into the in-memory database;
执行模块,用于当内存数据库中存储的数据达到预定阈值时,执行次要合并操作,以将内存数据库中存储的数据持久化到文件系统中。The execution module is configured to perform a secondary merge operation when the data stored in the in-memory database reaches a predetermined threshold, so as to persist the data stored in the in-memory database to the file system.
该系统还可以包括:The system may also include:
获取模块,用于获取区块链进程的状态信息;The acquisition module is used to acquire the status information of the blockchain process;
回收模块,用于当区块链进程的状态为闲置时,回收日志文件中的旧数据。The recycling module is used to recycle the old data in the log file when the state of the blockchain process is idle.
可选的,该文件系统的存储介质可以为固态硬盘;Optionally, the storage medium of the file system may be a solid-state hard disk;
该文件系统中SSTable文件的大小可以为1mb、2mb、4mb中的至少一项。The size of the SSTable file in the file system may be at least one of 1mb, 2mb, and 4mb.
该并行查找模块400可以包括:The
映射子模块,用于通过内存映射文件方式将文件系统的零层级中的数据项映射至内存数据库中;The mapping submodule is used to map the data items in the zero-level file system to the in-memory database by means of memory-mapped files;
查找子模块,用于在内存数据库中查找关键字对应的数据项。The lookup submodule is used to look up the data item corresponding to the keyword in the memory database.
以上系统中的各个组成部分可实际应用于以下的实施例中:Each component in the above system can be practically applied in the following embodiments:
第一接收模块接收数据读取请求;确定模块根据数据读取请求确定待读取数据的关键字;第一调用模块调用底层LSM存储引擎依次在内存数据库及临时数据库中查找关键字对应的数据项;当未查找到关键字对应的数据项时,并行查找模块在文件系统的各个层级中并行查找关键字对应的数据项。The first receiving module receives the data reading request; the determining module determines the keyword of the data to be read according to the data reading request; the first calling module invokes the underlying LSM storage engine to sequentially search the in-memory database and the temporary database for the data item corresponding to the keyword ; When the data item corresponding to the keyword is not found, the parallel search module searches for the data item corresponding to the keyword in parallel in each level of the file system.
第一判断模块判断是否查找到关键字对应的数据项;当未查找到关键字对应的数据项时,第一返回模块返回错误提示信息;当查找到关键字对应的数据项时,第二判断模块判断查找到的数据项是否唯一;当数据项不唯一时,第二返回模块返回层级最低的数据项。The first judgment module judges whether the data item corresponding to the keyword is found; when the data item corresponding to the keyword is not found, the first return module returns an error message; when the data item corresponding to the keyword is found, the second judgment The module judges whether the found data item is unique; when the data item is not unique, the second return module returns the data item with the lowest level.
第二接收模块接收数据写入请求;第二调用模块调用底层LSM存储引擎将数据写入请求对应的待写入数据写入日志文件中,并将待写入数据写入内存数据库中;当内存数据库中存储的数据达到预定阈值时,执行模块执行次要合并操作,以将内存数据库中存储的数据持久化到文件系统中;获取模块获取区块链进程的状态信息;当区块链进程的状态为闲置时,回收模块回收日志文件中的旧数据。The second receiving module receives the data write request; the second calling module calls the underlying LSM storage engine to write the data to be written corresponding to the data write request into the log file, and writes the data to be written into the memory database; when the memory When the data stored in the database reaches a predetermined threshold, the execution module performs a secondary merge operation to persist the data stored in the in-memory database to the file system; the acquisition module obtains the status information of the blockchain process; When the status is idle, the recycling module recycles the old data in the log file.
请参考图7,图7为本申请实施例所提供的一种区块链数据读取设备的结构图。Please refer to FIG. 7 , which is a structural diagram of a blockchain data reading device provided by an embodiment of the present application.
该区块链数据读取设备700可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上处理器(central processing units,CPU)722(例如,一个或一个以上处理器)和存储器732,一个或一个以上存储应用程序742或数据744的存储介质730(例如一个或一个以上海量存储设备)。其中,存储器732和存储介质730可以是短暂存储或持久存储。存储在存储介质730的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对装置中的一系列指令操作。更进一步地,中央处理器722可以设置为与存储介质730通信,在区块链数据读取设备700上执行存储介质730中的一系列指令操作。The blockchain
区块链数据读取设备700还可以包括一个或一个以上电源727,一个或一个以上有线或无线网络接口750,一个或一个以上输入输出接口758,和/或,一个或一个以上操作系统741,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。The blockchain
上述图1至图4所描述的区块链数据读取的方法中的步骤由区块链数据读取设备基于该图7所示的结构实现。The steps in the method for reading blockchain data described above in FIGS. 1 to 4 are implemented by the blockchain data reading device based on the structure shown in FIG. 7 .
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and module described above can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置、设备和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个模块或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或模块的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed apparatuses, devices and methods may be implemented in other manners. For example, the device embodiments described above are only illustrative. For example, the division of modules is only a logical function division. In actual implementation, there may be other division methods, for example, multiple modules or components may be combined or integrated. to another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or modules, and may be in electrical, mechanical or other forms.
作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到多个网络模块上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。Modules described as separate components may or may not be physically separated, and components shown as modules may or may not be physical modules, that is, may be located in one place, or may be distributed to multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist physically alone, or two or more modules may be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware, and can also be implemented in the form of software function modules.
集成的模块如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,功能调用装置,或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The integrated modules, if implemented in the form of software functional modules and sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the present application can be embodied in the form of software products in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, and the computer software products are stored in a storage medium , which includes several instructions to cause a computer device (which may be a personal computer, a function invocation device, or a network device, etc.) to execute all or part of the steps of the methods in the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes .
以上对本申请所提供的一种区块链数据读取的方法、系统、设备及计算机可读存储介质进行了详细介绍。本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想。应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以对本申请进行若干改进和修饰,这些改进和修饰也落入本申请权利要求的保护范围内。The method, system, device, and computer-readable storage medium for reading blockchain data provided by the present application have been described in detail above. Specific examples are used herein to illustrate the principles and implementations of the present application, and the descriptions of the above embodiments are only used to help understand the methods and core ideas of the present application. It should be pointed out that for those of ordinary skill in the art, without departing from the principles of the present application, several improvements and modifications can also be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.
还需要说明的是,在本说明书中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括要素的过程、方法、物品或者设备中还存在另外的相同要素。It should also be noted that, in this specification, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these entities or operations. There is no such actual relationship or sequence between operations. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion such that a process, method, article or device comprising a list of elements includes not only those elements, but also includes not explicitly listed or other elements inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, article, or device that includes the element.
Claims (7)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910824394.5A CN110532228B (en) | 2019-09-02 | 2019-09-02 | Method, system and equipment for reading block chain data and readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910824394.5A CN110532228B (en) | 2019-09-02 | 2019-09-02 | Method, system and equipment for reading block chain data and readable storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN110532228A CN110532228A (en) | 2019-12-03 |
| CN110532228B true CN110532228B (en) | 2022-09-02 |
Family
ID=68666370
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910824394.5A Active CN110532228B (en) | 2019-09-02 | 2019-09-02 | Method, system and equipment for reading block chain data and readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN110532228B (en) |
Families Citing this family (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111782707B (en) * | 2020-06-19 | 2024-04-16 | 京东科技信息技术有限公司 | A data query method and system |
| CN113535714B (en) * | 2021-06-18 | 2025-12-09 | 深圳市汉云科技有限公司 | Data storage method, data reading method and computer equipment |
| CN114020657B (en) * | 2021-11-03 | 2023-03-17 | 无锡沐创集成电路设计有限公司 | Message searching method, system, storage medium and electronic equipment |
| CN116737687A (en) * | 2022-03-02 | 2023-09-12 | 腾讯科技(深圳)有限公司 | Data processing methods, devices, computer equipment and computer-readable storage media |
Family Cites Families (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN106844650A (en) * | 2017-01-20 | 2017-06-13 | 中国科学院计算技术研究所 | A kind of daily record merges the merging method and system of tree |
| CN107402824B (en) * | 2017-05-31 | 2020-06-02 | 创新先进技术有限公司 | Data processing method and device |
-
2019
- 2019-09-02 CN CN201910824394.5A patent/CN110532228B/en active Active
Also Published As
| Publication number | Publication date |
|---|---|
| CN110532228A (en) | 2019-12-03 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110532228B (en) | Method, system and equipment for reading block chain data and readable storage medium | |
| CN110515957A (en) | Method, system, device and readable storage medium for blockchain data storage | |
| CN102609360B (en) | Data processing method, data processing device and data processing system | |
| CN112632069B (en) | Hash table data storage management method, device, medium and electronic equipment | |
| CN109977111A (en) | Using the data management system based on hash and the key-value data structure based on tree | |
| WO2021073635A1 (en) | Data storage method and device | |
| KR20140042522A (en) | Apparatus and method for directory entry look up, and recording medium recording the directory entry look up program thereof | |
| CN112015716A (en) | Database data migration method, device, medium and electronic device | |
| WO2018205151A1 (en) | Data updating method and storage device | |
| CN110287152A (en) | A data management method and related device | |
| KR20230026946A (en) | Key value storage device with hashing | |
| WO2022121274A1 (en) | Metadata management method and apparatus in storage system, and storage system | |
| WO2021184996A1 (en) | Data storage method and apparatus for database | |
| CN116303267A (en) | Data access method, device, equipment and storage medium | |
| CN115080605A (en) | Data processing method, device, equipment and storage medium | |
| WO2025162051A1 (en) | Data processing | |
| CN113297432B (en) | Methods, processor-readable media and systems for partition splitting and merging | |
| US12026371B2 (en) | Method, system, and device for writing compressed data to disk, and readable storage medium | |
| US10558636B2 (en) | Index page with latch-free access | |
| KR101806394B1 (en) | A data processing method having a structure of the cache index specified to the transaction in a mobile environment dbms | |
| WO2024055571A1 (en) | Namespace setting method and apparatus, and readable storage medium | |
| CN114356241B (en) | Storage methods, devices, electronic equipment and readable media for small object data | |
| Sarwat et al. | FAST: a generic framework for flash-aware spatial trees | |
| CN112000289B (en) | All-flash storage server system data management method and related components | |
| CN120596435A (en) | Metadata writing and reading method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| TA01 | Transfer of patent application right |
Effective date of registration: 20210913 Address after: 518000 21 / f-23 / F, block B, building 12, Shenzhen Bay science and technology ecological park, No. 18, South Keji Road, high tech community, Yuehai street, Nanshan District, Shenzhen City, Guangdong Province Applicant after: Xunlei Networking Technologies, Ltd. Applicant after: SHENZHEN ONETHING TECHNOLOGIES Co.,Ltd. Address before: 518052 Room 201, building A, No. 1, Qian Wan Road, Qianhai Shenzhen Hong Kong cooperation zone, Shenzhen, Guangdong (Shenzhen Qianhai business secretary Co., Ltd.) Applicant before: SHENZHEN ONETHING TECHNOLOGIES Co.,Ltd. |
|
| TA01 | Transfer of patent application right | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| TR01 | Transfer of patent right |
Effective date of registration: 20240618 Address after: 518000, 2101 to 2107, Xunlei Building, No. 3709 Baishi Road, Gaoxin District, Yuehai Street, Nanshan District, Shenzhen, Guangdong Province Patentee after: Xunlei Networking Technologies, Ltd. Country or region after: China Address before: 518000 21 / f-23 / F, block B, building 12, Shenzhen Bay science and technology ecological park, No. 18, South Keji Road, high tech community, Yuehai street, Nanshan District, Shenzhen City, Guangdong Province Patentee before: Xunlei Networking Technologies, Ltd. Country or region before: China Patentee before: SHENZHEN ONETHING TECHNOLOGIES Co.,Ltd. |
|
| TR01 | Transfer of patent right |
