Block data range query method, device and system and computer equipment
By deploying master and slave servers in blockchain nodes and combining them with data iterators, cross-server block data range queries are enabled, solving the problem of low query efficiency caused by large amounts of blockchain data, improving query efficiency and enhancing system scalability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-27
- Publication Date
- 2026-04-07
AI Technical Summary
The increase in blockchain data volume leads to increased storage pressure on individual nodes. When querying multiple nodes in a cluster, network latency and bandwidth are limited, making it impossible to perform range queries efficiently and affecting query efficiency.
In a blockchain node, master servers and slave servers are deployed. Each slave server manages a data iterator. Through the three-level linkage of master server, slave server, and data iterator, cross-server block data range queries are achieved, optimizing the processing of data query requests and prefetch instructions.
It improves the efficiency of querying blockchain data, enhances the scalability of the system, and supports data migration, expansion, and archiving functions.
Smart Images

Figure CN121807935A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular to a method, apparatus, system and computer device for querying block data ranges. Background Technology
[0002] Due to its decentralized and verifiable nature, blockchain requires each node to store all transaction and state data from the genesis block onwards. As applications evolve, storage engines that only support point queries cannot meet complex retrieval needs, making range queries crucial.
[0003] However, with the increasing volume of blockchain data, individual nodes struggle to store it. When querying multi-node clusters, results need to be retrieved and merged across all nodes, a centralized merging process that many distributed solutions do not support. Furthermore, network latency and bandwidth limitations during data transmission make performance and memory bottlenecks when coordinating nodes to process large amounts of data, impacting query efficiency and requiring urgent solutions. Summary of the Invention
[0004] Therefore, it is necessary to provide a method, apparatus, system, and computer equipment for querying block data ranges to address the aforementioned technical problems and improve the efficiency of blockchain data range queries.
[0005] Firstly, this application provides a method for querying block data ranges, including:
[0006] Receive a data query request; the data query request includes a first relative query range of the target data to be queried;
[0007] Send the data query request to at least one slave server;
[0008] Receive target candidate data fed back from each slave server; wherein, the target candidate data is the data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the first relative query range;
[0009] Select target data that meets the first relative query range from the target candidate data.
[0010] In one embodiment, sending a data query request to at least one slave server includes:
[0011] Based on the first relative query range and the previous initial candidate data queried by each data iterator managed by each slave server corresponding to the master server, the data query request is sent to at least one slave server that meets the preset requirements.
[0012] In one embodiment, the method further includes:
[0013] Based on the first relative query range corresponding to the data query request, predict the second relative query range corresponding to the next data query request;
[0014] Based on the second relative query range, a data prefetch instruction is generated and sent to at least one slave server;
[0015] Receive candidate prefetch data from each slave server; wherein, the candidate prefetch data is the data that the corresponding slave server selects from the initial prefetch data and satisfies the second relative query range; the initial prefetch data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the second relative query range;
[0016] Select target prefetch data that meets the second relative query range from the candidate prefetch data and store the target prefetch data.
[0017] In one embodiment, sending a data query request to at least one slave server includes:
[0018] Based on the first relative query range corresponding to the data query request, query the target data from the stored target prefetch data;
[0019] If the target data is not found, the data query request will be sent to at least one slave server.
[0020] Secondly, this application provides a method for querying block data ranges, including:
[0021] In response to a data query request sent from the master server corresponding to the slave server, a data query request is sent to at least one data iterator under management; the data query request includes a first relative query range of the target data to be queried;
[0022] Receive initial candidate data that satisfy the first relative query range from each data iterator's query of its corresponding block, and select target candidate data that satisfy the first relative query range from the initial candidate data;
[0023] The target candidate data is sent to the main server so that the main server can select the target data that meets the first relative query range from the target candidate data.
[0024] In one embodiment, sending a data query request to at least one managed data iterator includes:
[0025] Based on the first relative query range and the previous initial candidate data queried from each data iterator managed by the server, a data query request is sent to at least one data iterator that meets the preset requirements.
[0026] Thirdly, this application also provides a block data range query system, which includes:
[0027] One main server;
[0028] The master server corresponds to at least two slave servers; each slave server manages at least one data iterator.
[0029] The master server is used to send the received data query request to at least one slave server, and after receiving the target candidate data fed back by each slave server in response to the data query request, select the target data that meets the first relative query range from the target candidate data; the data query request includes the first relative query range of the target data to be queried;
[0030] For any slave server, the slave server is used to send the received data query request to at least one managed data iterator, and after receiving the initial candidate data fed back by each data iterator in response to the data query request, select the target candidate data that satisfies the first relative query range from the initial candidate data, and send the target candidate data to the master server.
[0031] Fourthly, this application also provides a block data range query device, comprising:
[0032] The request receiving module is used to receive data query requests; the data query request includes a first relative query range of the target data to be queried;
[0033] The first request sending module is used to send data query requests to at least one slave server;
[0034] The first data receiving module is used to receive target candidate data fed back by each slave server; wherein, the target candidate data is the data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the first relative query range;
[0035] The data selection module is used to select target data that meets the first relative query range from the target candidate data.
[0036] Fifthly, this application also provides a block data range query device, comprising:
[0037] The second request sending module is used to send a data query request to at least one managed data iterator in response to a data query request sent by the master server corresponding to the slave server; the data query request includes a first relative query range of the target data to be queried;
[0038] The second data receiving module is used to receive the initial candidate data that each data iterator queries from its corresponding block and satisfies the first relative query range, and select the target candidate data that satisfies the first relative query range from the initial candidate data.
[0039] The data sending module is used to send target candidate data to the main server, so that the main server can select target data that meets the first relative query range from the target candidate data.
[0040] Sixthly, this application also provides a computer device, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to perform the following steps:
[0041] Receive a data query request; the data query request includes a first relative query range of the target data to be queried;
[0042] Send the data query request to at least one slave server;
[0043] Receive target candidate data fed back from each slave server; wherein, the target candidate data is the data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the first relative query range;
[0044] Select target data that meets the first relative query range from the target candidate data.
[0045] In a seventh aspect, this application also provides a computer device, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to perform the following steps:
[0046] In response to a data query request sent from the master server corresponding to the slave server, a data query request is sent to at least one data iterator under management; the data query request includes a first relative query range of the target data to be queried;
[0047] Receive initial candidate data that satisfy the first relative query range from each data iterator's query of its corresponding block, and select target candidate data that satisfy the first relative query range from the initial candidate data;
[0048] The target candidate data is sent to the main server so that the main server can select the target data that meets the first relative query range from the target candidate data.
[0049] Eighthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0050] Receive a data query request; the data query request includes a first relative query range of the target data to be queried;
[0051] Send the data query request to at least one slave server;
[0052] Receive target candidate data fed back from each slave server; wherein, the target candidate data is the data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the first relative query range;
[0053] Select target data that meets the first relative query range from the target candidate data.
[0054] Ninthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0055] In response to a data query request sent from the master server corresponding to the slave server, a data query request is sent to at least one data iterator under management; the data query request includes a first relative query range of the target data to be queried;
[0056] Receive initial candidate data that satisfy the first relative query range from each data iterator's query of its corresponding block, and select target candidate data that satisfy the first relative query range from the initial candidate data;
[0057] The target candidate data is sent to the main server so that the main server can select the target data that meets the first relative query range from the target candidate data.
[0058] In a tenth aspect, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0059] Receive a data query request; the data query request includes a first relative query range of the target data to be queried;
[0060] Send the data query request to at least one slave server;
[0061] Receive target candidate data fed back from each slave server; wherein, the target candidate data is the data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the first relative query range;
[0062] Select target data that meets the first relative query range from the target candidate data.
[0063] In an eleventh aspect, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0064] In response to a data query request sent from the master server corresponding to the slave server, a data query request is sent to at least one data iterator under management; the data query request includes a first relative query range of the target data to be queried;
[0065] Receive initial candidate data that satisfy the first relative query range from each data iterator's query of its corresponding block, and select target candidate data that satisfy the first relative query range from the initial candidate data;
[0066] The target candidate data is sent to the main server so that the main server can select the target data that meets the first relative query range from the target candidate data.
[0067] The aforementioned method, apparatus, system, and computer equipment for querying block data ranges utilize a master server deployed within a blockchain node. This master server has at least two slave servers, each managing at least one data iterator. Upon receiving a data query request, the master server sends it to its corresponding slave servers, which in turn send it to their managed data iterators. For the initial candidate data retrieved by the data iterators, the slave servers select and merge them to obtain target candidate data, which is then sent to the master server. Similarly, the master server selects and merges the target candidate data received from the slave servers to obtain the target data within the first relative query range that satisfies the data query request across the entire blockchain node. This three-tiered linkage of the master server, slave servers, and data iterators enables cross-server block data range queries, improving both the efficiency of data range queries and the scalability of the entire system. It also provides technical support for the data migration, expansion, and archiving functions of the blockchain storage engine. Attached Figure Description
[0068] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0069] Figure 1A This is an application environment diagram of a block data range query method in one embodiment;
[0070] Figure 1BThis is a system architecture diagram of a block data range query system in one embodiment;
[0071] Figure 2 This is a flowchart illustrating a block data range query method in one embodiment;
[0072] Figure 3 This is a flowchart illustrating the block data prefetching step in one embodiment;
[0073] Figure 4 This is a flowchart illustrating the block data range query method in another embodiment;
[0074] Figure 5 This is a timing diagram of a block data range query method in one embodiment;
[0075] Figure 6 This is a structural block diagram of a block data range query device in one embodiment;
[0076] Figure 7 This is a structural block diagram of a block data range query device in another embodiment;
[0077] Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0078] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0079] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0080] The block data range query method provided in this application embodiment can be applied to, for example, Figure 1AIn the application environment shown, the master server 102 communicates with the slave servers 104 via a network. Specifically, the master server 102 receives a data query request; the data query request includes a first relative query range of the target data to be queried; the master server 102 sends the data query request to at least one slave server 104; the master server 102 receives target candidate data fed back by each slave server 104; wherein, the target candidate data is the data that the corresponding slave server 104 selects from the initial candidate data that satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server 104 queries from its corresponding block that satisfies the first relative query range; the master server 102 selects the target data that satisfies the first relative query range from the target candidate data.
[0081] In one embodiment, the block data range query system provided in this application has the following system architecture: Figure 1B As shown. This includes one master server (Global Iterator Manager); at least two slave servers (Iterator Managers) corresponding to the master server, each slave server managing at least one data iterator. The master server is used to send received data query requests to at least one slave server, and after receiving target candidate data from each slave server in response to the data query request, select target data that satisfies a first relative query range from the target candidate data; the data query request includes a first relative query range of the target data to be queried; for any slave server, the slave server is used to send received data query requests to at least one managed data iterator, and after receiving initial candidate data from its corresponding data block in response to the data query request that satisfies the first relative query range, select target candidate data that satisfies the first relative query range from the initial candidate data, and send the target candidate data to the master server.
[0082] It is worth noting that the master server can be the server with the best performance of the Central Processing Unit (CPU) among all the servers deployed by the blockchain node, that is, the server with the best computing power.
[0083] In one exemplary embodiment, such as Figure 2 As shown, a method for querying block data ranges is provided, which can be applied to... Figure 1A Taking the main server 102 as an example, the following steps are included:
[0084] S210 receives data query requests.
[0085] The data query request includes a first relative query range of the target data to be queried. This first relative query range characterizes the relative range of the target data within the block. For example, a data query request could be used to request the latest data, the earliest data, the data preceding the latest data, or the data following the earliest data, etc.
[0086] For example, in this embodiment, the user can input a data query request, in which case the main server receives the data query request sent by the user.
[0087] S220, send the data query request to at least one slave server.
[0088] In one alternative implementation, the master server can generate a data query task based on a data query request and send the data query task to all connected slave servers.
[0089] To avoid consuming the computing power of slave servers, the data query task can be sent to these slave servers before the data query task is issued, by selecting slave servers that may store the target data from all connected slave servers.
[0090] In one optional implementation, a data query request can be sent to at least one slave server that meets preset requirements, based on a first relative query range and the previous initial candidate data queried by each data iterator managed by each slave server corresponding to the master server. The previous initial candidate data is the data selected by the corresponding iterator in response to the previous data query request.
[0091] Optionally, a preset requirement is used to ensure that the key value of the previous initial candidate data queried from each data iterator managed by the server satisfies a first relative query range. For example, if the first relative query range corresponding to a data query request represents querying the previous data, then the preset requirement is used to ensure that the key value of the previous initial candidate data queried from each data iterator managed by the server is not less than the key value of the previous target data. As another example, if the first relative query range corresponding to a data query request represents querying the next data, then the preset requirement is used to ensure that the key value of the previous initial candidate data queried from each data iterator managed by the server is not greater than the key value of the previous target data.
[0092] In another alternative implementation, the data query request can be sent to at least one slave server that meets the preset requirements based on the first relative query range and the key value of the previous target candidate data selected by each slave server corresponding to the master server, that is, the key value currently pointed to.
[0093] For example, data query requests can include multiple types, with different types of requests corresponding to different first relative query ranges. The first relative query range can include retrieving the maximum key-value data, retrieving the minimum key-value data, retrieving the previous key-value data, retrieving the next key-value data, and retrieving a specified key-value data. Accordingly, based on a preset selection strategy, slave servers that meet preset requirements are selected from among the slave servers. The preset selection strategy is as follows:
[0094]
[0095] S230 receives target candidate data fed back from each slave server.
[0096] The target candidate data is the data that the corresponding slave server selects from the initial candidate data and that satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and that satisfies the first relative query range.
[0097] It can be understood that for any data iterator, the initial candidate data it selects is the data in its corresponding block that satisfies the first relative query range; for the slave server, after receiving each initial candidate data, it selects the data that satisfies the first relative query range from the initial candidate data as the target candidate data and sends it to the master server.
[0098] In some embodiments, if the first relative query range corresponding to the data query request indicates querying the latest data, it can be understood as querying the data with the largest key value among all data. Accordingly, each data iterator selects the data with the largest key value from its corresponding block as the initial candidate data and sends it to the corresponding slave server; each slave server selects the initial candidate data with the largest key value from the received initial candidate data as the target candidate data and sends it to the master server.
[0099] To facilitate understanding, this process is illustrated with an example: The master server corresponds to slave server 1 and slave server 2; slave server 1 manages data iterator 1 and data iterator 2; slave server 2 manages data iterator 3 and data iterator 4; the key values of the data stored in data iterator 1 are 3 and 4 respectively; the key values of the data stored in data iterator 2 are 5 and 6 respectively; the key values of the data stored in data iterator 3 are 3 and 5 respectively; the key values of the data stored in data iterator 4 are 5 and 7 respectively; the first relative query range represents the query for the latest data, so data iterator 1 selects the data with key value 4 as the initial candidate data; data iterator 2 selects the data with key value 6 as the initial candidate data; data iterator 3 selects the data with key value 5 as the initial candidate data; data iterator 4 selects the data with key value 7 as the initial candidate data. After receiving each initial candidate data, slave server 1 selects the initial candidate data with key value 6 as the target candidate data; after receiving each initial candidate data, slave server 2 selects the initial candidate data with key value 7 as the target candidate data.
[0100] S240, Select target data that meets the first relative query range from the target candidate data.
[0101] Understandably, for the main server, the data that satisfies the first relative query range is selected from the initial candidate data as the target data.
[0102] In some embodiments, if the first relative query range corresponding to the data query request indicates querying the latest data, it can be understood as querying the data with the largest key value among all data. Accordingly, after receiving each target candidate data, the main server selects the target candidate data with the largest key value as the target data.
[0103] Continuing with the example above, after receiving each target candidate data, the main server selects the target candidate data with a key value of 7 as the target data.
[0104] In the aforementioned block data range query method, a master server is deployed in the blockchain node, with at least two slave servers corresponding to the master server. Each slave server manages at least one data iterator. After receiving a data query request, the master server sends the data query request to its corresponding slave servers, which then send the data query request to their managed data iterators. For the initial candidate data obtained by the data iterators, the slave servers select and merge them to obtain target candidate data, which is then sent to the master server. For the target candidate data received by the master server from the slave servers, the master server selects and merges them to obtain the target data within the first relative query range corresponding to the data query request in the entire blockchain node. Throughout this process, through the three-level linkage of the master server, slave servers, and data iterators, cross-server block data range queries are achieved. This improves the efficiency of data range queries and enhances the scalability of the entire system, providing technical support for the data migration, expansion, and archiving functions of the blockchain storage engine.
[0105] Based on the technical solutions of the above embodiments, this application also provides an optional embodiment. In this optional embodiment, the block data range query method provided by this application is further described.
[0106] See Figure 3 The block data prefetching steps shown include:
[0107] S310, based on the first relative query range corresponding to the data query request, predict the second relative query range corresponding to the next data query request.
[0108] In one optional implementation, the correspondence between the first relative query range and the reference relative query range can be determined, and the reference relative query range corresponding to the first relative query range of the data query request can be used as the second relative query range of the next data query request.
[0109] In another alternative implementation, all types of query ranges can be used as the second relative query range.
[0110] It's important to note that because the keys in range queries exhibit a certain regularity, the First and Last operations only return the keys corresponding to begin and end, while Next and Prev return the keys preceding and following the currently pointed-to key, respectively. Since seek operations are few in number and highly uncertain, they are not considered for caching. Therefore, the core idea is that when a range query returns a result, it simultaneously caches the data needed for the next possible executions of Next, Prev, First, and Last on the main server.
[0111] S320, based on the second relative query range, generate a data prefetch instruction and send the data prefetch instruction to at least one slave server.
[0112] Among them, the data prefetch instruction is used to retrieve data that may be queried next.
[0113] In some embodiments, all slave servers are also deployed with a cache, which stores candidate prefetch data. This caches the previous and next keys of the currently pointed-to key, the largest and smallest keys of the node, and the values corresponding to these keys. The purpose is to accelerate the range query process and move the high-latency index traversal and disk read processes to the background.
[0114] S330 receives candidate prefetch data from each slave server.
[0115] Among them, the candidate prefetch data is the data that the corresponding slave server selects from the initial prefetch data and that meets the second relative query range; the initial prefetch data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and that meets the second relative query range.
[0116] It is understandable that the way the data iterator managed by the server queries the initial prefetch data from its corresponding block is the same as the way it queries the initial candidate data; the way the server selects candidate prefetch data is the same as the way it selects target candidate data; these will not be elaborated here.
[0117] S340: Select target prefetch data that meets the second relative query range from the candidate prefetch data, and store the target prefetch data.
[0118] It is understandable that the main server selects target prefetch data in the same way as it selects target data, so it will not be elaborated here.
[0119] For example, after the master server selects the target prefetch data, it can store the target prefetch data in a new data block for easy retrieval later.
[0120] It is understandable that if prefetched data exists in the master server, the target data can be queried from the stored target prefetched data according to the first relative query range corresponding to the data query request; if the target data is not found, the data query request is sent to at least one slave server.
[0121] In the above embodiments, based on the pattern of range queries, the data that the next data query request may query is pre-acquired and stored on the main server, which can further improve the data query efficiency.
[0122] In one exemplary embodiment, such as Figure 4 As shown, a method for querying block data ranges is provided, which can be applied to... Figure 1A Taking server 104 as an example, the following steps are included:
[0123] S410, in response to a data query request sent by the master server corresponding to the slave server, sends a data query request to at least one managed data iterator.
[0124] The data query request includes the first relative query range of the target data to be queried.
[0125] In one alternative implementation, data query requests can be sent to all managed data iterators.
[0126] In one alternative implementation, a data query request can be sent to at least one data iterator that meets preset requirements, based on a first relative query range and the previous initial candidate data queried from each data iterator managed by the server.
[0127] For example, data query requests can include multiple types, with different types of requests corresponding to different first relative query ranges. The first relative query range can include retrieving the maximum key-value data, retrieving the minimum key-value data, retrieving the previous key-value data, retrieving the next key-value data, and retrieving a specified key-value data. Accordingly, based on a preset selection strategy, a data iterator that meets preset requirements is selected from each data iterator. The preset selection strategy is as follows:
[0128]
[0129] S420, receive the initial candidate data that satisfies the first relative query range from the corresponding block queried by each data iterator, and select the target candidate data that satisfies the first relative query range from the initial candidate data.
[0130] It should be noted that the process of selecting initial candidate data and selecting target candidate data from the server by the data iterator has been described in the above embodiments and will not be repeated here.
[0131] S430, the target candidate data is sent to the master server so that the master server can select target data that meets the first relative query range from the target candidate data.
[0132] In the aforementioned block data range query method, a master server is deployed in the blockchain node, with at least two slave servers corresponding to the master server. Each slave server manages at least one data iterator. After receiving a data query request, the master server sends the data query request to its corresponding slave servers, which then send the data query request to their managed data iterators. For the initial candidate data obtained by the data iterators, the slave servers select and merge them to obtain target candidate data, which is then sent to the master server. For the target candidate data received by the master server from the slave servers, the master server selects and merges them to obtain the target data within the first relative query range corresponding to the data query request in the entire blockchain node. Throughout this process, through the three-level linkage of the master server, slave servers, and data iterators, cross-server block data range queries are achieved. This improves the efficiency of data range queries and enhances the scalability of the entire system, providing technical support for the data migration, expansion, and archiving functions of the blockchain storage engine.
[0133] Because range queries depend on the state of the current data iterator, the data iterator itself needs to save its state to prepare for the next request. Based on this, the method by which the slave server responds to data prefetching instructions is described: to obtain the initial prefetched data, the state of the data iterator itself must change. Therefore, the slave server can create an additional shadow iterator to execute the data prefetching instructions, while the data iterator retains its original state.
[0134] For example, after obtaining the initial candidate data for each data iterator, the slave server issues a task to create a shadow iterator. The state of the shadow iterator is consistent with the state of the current iterator. After the shadow iterator is created, the slave server issues a prefetch retrieval task to the shadow iterator to obtain the initial prefetch data. For example, if the data corresponding to First and Last does not exist in the node's cache, the slave server issues a prefetch task for First and Last data. Additionally, if the slave server also deploys a cache, it can check whether the data corresponding to the two keys before and after the target candidate data is in the local cache. If the former key is not in the cache, a Prev task is issued; if the latter key is not in the cache, a Next task is issued.
[0135] After each slave server completes the data prefetching task sent to the shadow iterator it manages, it merges the initial prefetched data, selects candidate prefetched data that meets the second relative query range, and submits them to the master server. The master server merges the candidate prefetched data and stores the target prefetched data in the corresponding block.
[0136] It should be noted that, based on the above architecture, when new data is written, the data update will only exist in the latest block of the master server, while there will be no new data written in other blocks of the slave server and the master server.
[0137] The data iterator state of the latest block on the master server can be updated based on the type of the previous data query request (i.e., the relative query range) and the key value of the target data submitted by the user last time, i.e., last_key. In this way, in response to the next data query request, the newly written data can be queried. For example, the update strategy can be as follows:
[0138]
[0139] Based on the technical solutions of the above embodiments, this application also provides an optional embodiment. In this optional embodiment, the block data range query method provided by this application is described in detail.
[0140] See Figure 5 The sequence diagram shown for the block data range query method includes:
[0141] S501, the master server receives data query requests;
[0142] The data query request includes the first relative query range of the target data to be queried;
[0143] S502, the master server queries the target data from the stored target prefetch data according to the first relative query range corresponding to the data query request;
[0144] S503, if the target data is not found, the master server sends the data query request to at least one slave server that meets the preset requirements based on the first relative query range and the previous initial candidate data queried by each data iterator managed by each slave server corresponding to the master server.
[0145] S504, the server sends a data query request to at least one data iterator that meets preset requirements, based on the first relative query range and the previous initial candidate data queried from each data iterator managed by the server.
[0146] The data query request includes the first relative query range of the target data to be queried;
[0147] S505, receive from the server the initial candidate data that each data iterator queries from its corresponding block and satisfies the first relative query range, and select the target candidate data that satisfies the first relative query range from the initial candidate data;
[0148] S506, the server sends the target candidate data to the master server;
[0149] S507, The master server selects target data that meets the first relative query range from the target candidate data;
[0150] S508, the master server outputs the target data;
[0151] S509, the master server predicts the second relative query range corresponding to the next data query request based on the first relative query range corresponding to the data query request;
[0152] S510, the master server generates a data prefetch instruction based on the second relative query range and sends the data prefetch instruction to at least one slave server;
[0153] S511, the master server receives candidate prefetch data from each slave server;
[0154] Among them, the candidate prefetch data is the data that the corresponding slave server selects from the initial prefetch data and that meets the second relative query range; the initial prefetch data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and that meets the second relative query range;
[0155] S512, the master server selects the target prefetch data that meets the second relative query range from the candidate prefetch data and stores the target prefetch data.
[0156] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0157] Based on the same inventive concept, this application also provides a block data range query device for implementing the block data range query method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more block data range query device embodiments provided below can be found in the limitations of the block data range query method described above, and will not be repeated here.
[0158] In one exemplary embodiment, such as Figure 6 As shown, a block data range query device is provided, comprising: a request receiving module 610, a first request sending module 620, a first data receiving module 630, and a data selection module 640, wherein:
[0159] The request receiving module 610 is used to receive a data query request; the data query request includes a first relative query range of the target data to be queried.
[0160] The first request sending module 620 is used to send a data query request to at least one slave server;
[0161] The first data receiving module 630 is used to receive target candidate data fed back by each slave server; wherein, the target candidate data is the data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is the data that the data iterator managed by the corresponding slave server queries from its own corresponding block and satisfies the first relative query range;
[0162] The data selection module 640 is used to select target data that meets the first relative query range from the target candidate data.
[0163] In one embodiment, the first request sending module 620 is specifically used to send a data query request to at least one slave server that meets preset requirements, based on the first relative query range and the previous initial candidate data queried by each data iterator managed by each slave server corresponding to the master server.
[0164] In one embodiment, the block data range query device includes a data prefetching module, comprising a range prediction unit for predicting a second relative query range corresponding to the next data query request based on a first relative query range corresponding to the data query request; an instruction generation unit for generating a data prefetching instruction based on the second relative query range and sending the data prefetching instruction to at least one slave server; a data receiving unit for receiving candidate prefetched data fed back by each slave server; wherein the candidate prefetched data is data that satisfies the second relative query range selected by the corresponding slave server from the initial prefetched data; the initial prefetched data is data that satisfies the second relative query range queried by the data iterator managed by the corresponding slave server from its corresponding block; and a data storage unit for selecting target prefetched data that satisfies the second relative query range from the candidate prefetched data and storing the target prefetched data.
[0165] In one embodiment, the first request sending module 620 includes a data query unit, configured to query target data from the stored target prefetched data according to the first relative query range corresponding to the data query request; and a request sending unit, configured to send the data query request to at least one slave server if the target data is not found.
[0166] In one exemplary embodiment, such as Figure 7 As shown, a block data range query device is provided, comprising: a second request sending module 710, a second data receiving module 720, and a data sending module 730, wherein:
[0167] The second request sending module 710 is used to send a data query request to at least one managed data iterator in response to a data query request sent by the master server corresponding to the slave server; the data query request includes a first relative query range of the target data to be queried;
[0168] The second data receiving module 720 is used to receive the initial candidate data that satisfies the first relative query range queried by each data iterator from its corresponding block, and select the target candidate data that satisfies the first relative query range from the initial candidate data.
[0169] The data sending module 730 is used to send target candidate data to the main server so that the main server can select target data that meets the first relative query range from the target candidate data.
[0170] In one embodiment, the second request sending module 710 is specifically configured to send a data query request to at least one data iterator that meets preset requirements, based on the first relative query range and the previous initial candidate data queried from each data iterator managed by the server.
[0171] Each module in the aforementioned block data range query device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0172] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When executed by the processor, the computer program implements a block data range query method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0173] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0174] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0175] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0176] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0177] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0178] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0179] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0180] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for querying a range of block data, characterized in that, A master server deployed in a blockchain node, wherein the master server has at least two slave servers; Each of the aforementioned slave servers manages at least one data iterator; the method includes: Receive a data query request; the data query request includes a first relative query range of the target data to be queried; Send the data query request to at least one slave server; Receive target candidate data fed back by each of the slave servers; wherein, the target candidate data is data selected by the corresponding slave server from the initial candidate data that satisfies the first relative query range; the initial candidate data is data queried by the data iterator managed by the corresponding slave server from its corresponding block that satisfies the first relative query range; Select target data that satisfies the first relative query range from the target candidate data.
2. The method according to claim 1, characterized in that, Sending the data query request to at least one slave server includes: Based on the first relative query range and the previous initial candidate data queried by each data iterator managed by each slave server corresponding to the master server, the data query request is sent to at least one slave server that meets the preset requirements.
3. The method according to claim 1, characterized in that, The method further includes: Based on the first relative query range corresponding to the data query request, predict the second relative query range corresponding to the next data query request; Based on the second relative query range, a data prefetch instruction is generated and sent to at least one slave server; Receive candidate prefetch data fed back by each of the slave servers; wherein, the candidate prefetch data is data that the corresponding slave server selects from the initial prefetch data that satisfies the second relative query range; the initial prefetch data is data that the data iterator managed by the corresponding slave server queries from its corresponding block that satisfies the second relative query range; Select target prefetch data that satisfies the second relative query range from the candidate prefetch data, and store the target prefetch data.
4. The method according to claim 3, characterized in that, Sending the data query request to at least one slave server includes: Based on the first relative query range corresponding to the data query request, query the target data from the stored target prefetch data; If the target data is not found, the data query request is sent to at least one slave server.
5. A method for querying a range of block data, characterized in that, The method, applied to a slave server deployed in a blockchain node, includes: In response to a data query request sent by the master server corresponding to the slave server, the data query request is sent to at least one managed data iterator; the data query request includes a first relative query range of the target data to be queried; Receive initial candidate data that satisfies the first relative query range from the corresponding block queried by each of the data iterators, and select target candidate data that satisfies the first relative query range from the initial candidate data; The target candidate data is sent to the main server so that the main server can select target data that meets the first relative query range from the target candidate data.
6. The method according to claim 5, characterized in that, Sending the data query request to at least one managed data iterator includes: Based on the first relative query range and the previous initial candidate data queried from each data iterator managed by the server, the data query request is sent to at least one data iterator that meets the preset requirements.
7. A block data range query system, characterized in that, The system includes: One main server; The master server corresponds to at least two slave servers; each slave server manages at least one data iterator. The master server is used to send the received data query request to at least one slave server, and after receiving the target candidate data fed back by each slave server in response to the data query request, select target data that meets the first relative query range from the target candidate data; the data query request includes the first relative query range of the target data to be queried. For any slave server, the slave server is used to send the received data query request to at least one managed data iterator, and after receiving the initial candidate data fed back by each of the data iterators in response to the data query request, select target candidate data that satisfies the first relative query range from the initial candidate data, and send the target candidate data to the master server.
8. A block data range query device, characterized in that, A master server deployed in a blockchain node, wherein the master server has at least two slave servers; Each of the aforementioned slave servers manages at least one data iterator; the apparatus includes: A request receiving module is used to receive data query requests; the data query request includes a first relative query range of the target data to be queried. The first request sending module is used to send the data query request to at least one slave server; The first data receiving module is used to receive target candidate data fed back by each of the slave servers; wherein, the target candidate data is data that the corresponding slave server selects from the initial candidate data and satisfies the first relative query range; the initial candidate data is data that the data iterator managed by the corresponding slave server queries from its corresponding block and satisfies the first relative query range; The data selection module is used to select target data that meets the first relative query range from the target candidate data.
9. A block data range query device, characterized in that, A slave server deployed in a blockchain node, the device comprising: The second request sending module is used to send the data query request to at least one managed data iterator in response to the data query request sent by the master server corresponding to the slave server; the data query request includes a first relative query range of the target data to be queried; The second data receiving module is used to receive initial candidate data that satisfies the first relative query range from the corresponding block queried by each of the data iterators, and to select target candidate data that satisfies the first relative query range from the initial candidate data; The data sending module is used to send the target candidate data to the main server, so that the main server can select target data that meets the first relative query range from the target candidate data.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1-6.