Data query method, device and equipment and computer readable storage medium
By distributing query requests between multiple cache nodes in the data storage center, the problem of inefficient data query is solved, and a more efficient and reliable data query process is achieved.
Patent Information
- Application Number
- CN202411400812.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-02-11
AI Technical Summary
In scenarios where the data volume is large and the query is frequent, directly visiting the data storage center for data query will lead to excessive load on the data storage center and reduce the efficiency of data query.
By receiving the query request from the terminal device, the target storage service is determined, and query instructions are sent to multiple cache nodes corresponding to the target storage service to obtain the query results of the target data item of the object to be queried.
The distributed cache nodes store data, which reduces the load pressure in the data center and improves the efficiency of data query. Different storage services are used to store data items of different data item types, which facilitates data management and rapid positioning, and improves the efficiency and reliability of data query.
Smart Images

Figure CN119415558A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data query method, device, equipment and computer-readable storage medium. Background Art
[0002] Data query refers to querying the data required by the user according to the user's instructions, such as querying the electricity consumption of an electric meter, querying the water consumption of a water meter, etc. Therefore, data query appears in daily life.
[0003] In the related art, when performing data query, the data to be queried is often obtained by directly accessing the data storage center. However, when this method is used in scenarios with large data volumes and frequent queries, it will cause the data storage center to be overloaded, reducing the efficiency of data query.
[0004] Therefore, how to improve the efficiency of data query is an urgent problem to be solved. Summary of the invention
[0005] To solve the above technical problems, embodiments of the present application provide a data query method, apparatus, device, and computer-readable storage medium.
[0006] Among them, the technical solution adopted in this application is:
[0007] A data query method, comprising:
[0008] Receiving a query request for a target data item of a query object sent by a terminal device;
[0009] Determine a target storage service for storing the target data item based on the query request; wherein different storage services are used to store data items of different data item types;
[0010] Sending query instructions for the target data items of the object to be queried to multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain query results for the target data items of the object to be queried based on the query instructions;
[0011] The query results sent by the multiple cache nodes are received, and the query results are sent to the terminal device.
[0012] A data query device, comprising:
[0013] A transceiver unit, configured to receive a query request for a target data item of a query object sent by a terminal device;
[0014] A determining unit, configured to determine a target storage service for storing the target data item based on the query request;
[0015] The transceiver unit is further used to send query instructions for the target data items of the object to be queried to the multiple cache nodes corresponding to the target storage service, so that the multiple cache nodes obtain query results for the target data items of the object to be queried based on the query instructions;
[0016] The transceiver unit is further configured to receive the query results sent by the multiple cache nodes, and send the query results to the terminal device.
[0017] In one embodiment of the present application, based on the aforementioned scheme, the determination unit is further used to determine the identification information of the object to be queried based on the identification information of the terminal device contained in the query request; the device also includes a processing unit for generating the query instruction based on the identification information of the object to be queried and the target data item; the transceiver unit is further used to send the query instruction to multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain the query results of the target data items of the object to be queried based on the query instruction.
[0018] In one embodiment of the present application, based on the aforementioned scheme, the process by which the multiple cache nodes obtain the query results of the target data item of the object to be queried based on the query instruction includes: if the first cache node does not obtain the query result, then read the data value corresponding to the target data item from the object to be queried, and use the data value as the query result; wherein, the first cache node is any one of the multiple cache nodes.
[0019] In one embodiment of the present application, based on the aforementioned scheme, the processing unit is also used to select the earliest received query result from the multiple query results as the target query result if there are multiple query results received for the target data item of the object to be queried; the transceiver unit is also used to send the target query result to the terminal device.
[0020] In one embodiment of the present application, based on the aforementioned scheme, before the query request for the target data item of the object to be queried is sent by the receiving terminal device, the transceiver unit is also used to receive a registration request sent by the cache node to be registered through the data channel to be registered; the registration request includes the identification information of the storage service corresponding to the cache node to be registered; the device also includes a storage unit, which is used to store the association relationship between the cache node to be registered, the storage service and the data channel to be registered in response to the registration request to complete the registration of the cache node to be registered; wherein different cache nodes are associated with different data channels; the query instructions for the target data items of the object to be queried are sent to multiple cache nodes corresponding to the target storage service respectively, including: sending query instructions for the target data items of the object to be queried to the multiple cache nodes through multiple data channels associated with the target storage service.
[0021] In one embodiment of the present application, based on the aforementioned scheme, the processing unit is further used to determine the data item type to which the target data item belongs; and select a storage service matching the data item type from multiple storage services as the target storage service.
[0022] In one embodiment of the present application, based on the aforementioned scheme, the processing unit is also used to extract the updated data value corresponding to the target data item and the version number corresponding to the updated data value from the data update request if a data update request for the target data item of the object to be queried is received from the second cache node; wherein the second cache node is any one of the multiple cache nodes; the transceiver unit is also used to send the updated data value and the version number to other cache nodes among the multiple cache nodes except the second cache node, so that each other cache node updates the target data item based on the updated data value and the version number.
[0023] A data query device includes a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the above data query method is implemented.
[0024] A computer-readable storage medium stores computer-readable instructions, which, when executed by a processor of a computer, enable the computer to execute the above data query method.
[0025] A computer program product includes computer-readable instructions, and when the computer-readable instructions are executed by a processor, the above data query method is implemented.
[0026] In the above technical solution:
[0027] After receiving a query request for the target data of the object to be queried sent by the terminal device, the target storage service for storing the target data item can be determined based on the query request. In this way, the query instruction for the target data item of the object to be queried can be sent to the multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes all query the query result of the target data item based on the query instruction. In this way, when the query result returned by the multiple cache nodes is received, the query result can be sent to the terminal device.
[0028] Through this method, firstly, data is stored through distributed cache nodes, which effectively reduces the load pressure of the data center and improves the data query efficiency.
[0029] Secondly, different storage services are used to store data items of different data item types, so that data can be differentiated according to the storage service, which is more convenient for data management. When performing data queries, the cache node storing the target data item can be located more quickly, thereby improving the efficiency of data queries.
[0030] Finally, each storage service corresponds to multiple cache nodes. When a cache node fails or the load is too high, other cache nodes can share the query task, ensuring the stability and response speed of the query and improving the reliability and efficiency of data query.
[0031] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0033] Figure 1 It is a schematic diagram of an implementation environment involved in this application;
[0034] Figure 2 is a flow chart of a data query method according to an exemplary embodiment;
[0035] Figure 3 is a flowchart of a data query method according to another exemplary embodiment
[0036] Figure 4 is a flow chart of a data query method according to another exemplary embodiment;
[0037] Figure 5 is a flow chart of a data query method according to another exemplary embodiment;
[0038] Figure 6 is a block diagram of a data query device according to an exemplary embodiment;
[0039] Figure 7 The diagram is a structural diagram of a computer system of a data query device according to an exemplary embodiment. DETAILED DESCRIPTION
[0040] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments that are the same as the present application. Instead, they are only examples of devices and methods that are the same as some aspects of the present application as detailed in the attached claims.
[0041] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0042] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, while some operations / steps can be integrated or partially integrated, so the actual execution order may change according to actual conditions.
[0043] It should be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.
[0044] It should be noted that in the specific implementation of the present application, when the user-related data is involved, when the embodiment of the present application is applied to a specific product or technology, the user's permission or consent is required, and the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions. At the same time, the formulas involved in the embodiments of the present application can be flexibly adjusted, such as increasing or decreasing the corresponding parameters.
[0045] See also Figure 1 , Figure 1 It is a schematic diagram of an implementation environment involved in this application.
[0046] Figure 1 The implementation environment shown is composed of a distributed cache system, which includes a terminal device 110, a central management node 120, a cache node 131, a cache node 132, a cache node 133, a cache node 134, an object to be queried 141, an object to be queried 142, an object to be queried 143 and an object to be queried 144.
[0047] Among them, the terminal device 110 can interact with the central management node 120, for example, it can send a query request for the target data item of the query object to the central management node 120. Accordingly, after receiving the query request, the central management node 120 will search for the corresponding query results from the multiple connected cache nodes according to the preset algorithms and strategies, and then feed them back to the terminal device 110.
[0048] The central management node 120 is a node that can manage multiple cache nodes and is responsible for detecting and managing the operating status of the entire distributed cache system. The central management node 120 can be a netty server. The number of the multiple cache nodes can be less than four or more than four. The embodiment of the present application takes one central management node managing four cache nodes as an example for explanation, which is not a limitation.
[0049] Each cache node can independently store and manage a portion of data, and these data can be data corresponding to the object to be queried. Depending on the storage service corresponding to each cache node, each cache node can store data items of different data item types. Among them, these data item types can be different depending on the object to be queried.
[0050] In the embodiment of the present application, the object to be queried may be a metering device, such as a water meter, an electric meter, a gas meter, etc. The number of objects to be queried may be more than four. Figure 1 Four objects to be queried are used as an example for explanation, which is not intended to be limiting.
[0051] For example, if the object to be queried is an electric meter, the data item types may be the electric power consumption of the electric meter, the balance of the electric meter, and the operating status of the electric meter (eg, sleep status, active status, etc.).
[0052] For another example, if the object to be queried is a water meter, the data item types may be the water consumption of the water meter, the remaining water volume of the water meter, and the operating status of the water meter (eg, normal status, abnormal status, etc.).
[0053] It should be noted that, in the embodiment of the present application, each data item type can be managed by a storage service. For example, if storage service 1 is a storage service for electricity consumption of an electric meter, then the cache node providing storage service 1 can be dedicated to storing data items of data item type of electricity consumption and their data values; if storage service 2 is a storage service for the balance of an electric meter, then the cache node providing storage service 2 can be dedicated to storing data items of data item type of balance and their data values.
[0054] exist Figure 1 In the example, assuming that cache node 131 and cache node 132 both provide storage service 1, then based on the above example, these two cache nodes will be responsible for storing the electricity consumption data items and their data values of the electricity meter, and both can store the electricity consumption data items and their data values corresponding to all the objects to be queried. Assuming that cache node 133 and cache node 134 both provide storage service 2, then based on the above example, which of these two cache nodes is responsible for storing the balance data items and their data values of the electricity meter, and both can store the balance data items and their data values corresponding to all the objects to be queried.
[0055] Optionally, when storing data items and data values corresponding to the data items, the cache node may adopt a key-value (KV) pair approach to improve query efficiency and rapid data location.
[0056] Optionally, the cache node may adopt an efficient data storage structure, such as a hash table or a binary tree, to improve data storage and retrieval efficiency.
[0057] Optionally, the cache node can automatically adjust the storage location and expiration time of the data item in the cache node according to the query frequency and importance of the data item. The expiration time represents the validity period of the data value corresponding to a data item, for example, it can be 24 hours, 48 hours, etc. If the expiration time is exceeded, the data value corresponding to the data item will become invalid.
[0058] Each object to be queried can count data items of multiple data item types and their data values. For example, if the object to be queried 141 is an electric meter, it will record the power consumption, balance, and operating status. Then, the object to be queried 141 can send the data value of power consumption to the cache node corresponding to the power consumption storage service (such as cache node 131 and cache node 132); the object to be queried 141 can send the data value of the balance to the cache node corresponding to the balance storage service (such as cache node 133 and cache node 134), and so on.
[0059] It should be noted that the terminal device in the embodiment of the present application may be a network access device. A network access device refers to a device that can communicate and exchange data with other devices or servers (such as a central management node) through a network (such as the Internet, a local area network, Wi-Fi, a mobile network, etc.), so that it can send, receive, and process network data packets and perform related network operations. In this application, a network access device may be a mobile phone, a desktop computer, a laptop computer, etc.
[0060] Optionally, the network access device can also be a mobile internet device (MID), a vehicle-mounted device, an aircraft, a wearable device (smart devices such as smart watches, smart bracelets, pedometers, etc.), a virtual reality device (such as a virtual reality (VR) device, an augmented reality (AR) device), etc.
[0061] Optionally, the central management node and the cache node in the embodiments of the present application can both be servers. The server can refer to an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.
[0062] See also Figure 2 , Figure 2 is a flow chart of a data query method according to an exemplary embodiment. The method can be applied to Figure 1 The implementation environment shown is specifically executed by the central management node 120. Of course, the method can also be applied to other implementation environments, and the execution subject of the method is not limited here.
[0063] The data query method will be described in detail below using the central management node 120 as an exemplary execution subject. Figure 2 As shown, in an exemplary embodiment, the method comprises at least the following steps:
[0064] S210: Receive a query request for a target data item of a query object sent by a terminal device.
[0065] The terminal device may be a user's device, and the user may operate on the terminal device to initiate a query request for a target data item of the object to be queried. The object to be queried may be a device that the user wants to query, such as an electric meter or water meter managed by the user. The embodiment of the present application is described by taking the electric meter as an example.
[0066] The user can use the terminal device to access the query platform provided by the central management node on a specific website. The query platform can indicate and display multiple data items on the terminal device, such as the power consumption, balance and operating status of the meter. The user can click on one or more of the multiple data items to determine the target data item.
[0067] It is understandable that the number of target data items may be one or more. The processing procedures of different target data items in this application are the same, and the processing procedure of one target data item is described here.
[0068] S220. Determine a target storage service for storing the target data item based on the query request; wherein different storage services are used to store data items of different data item types.
[0069] The target data item is managed by the target storage service. Therefore, the central management node can determine the target storage service that stores the target data item based on the target data item in the query request. For example, if the target data item is the electricity consumption of the meter, then the target storage service can be the electricity consumption storage service. If the target data item is the balance of the meter, then the target storage service can be the balance storage service. Therefore, different storage services are used to store data items of different data item types.
[0070] S230. Send query instructions for the target data items of the object to be queried to the multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain query results for the target data items of the object to be queried based on the query instructions.
[0071] In one embodiment of the present application, the central management node needs to first generate the query instruction based on the query request. Specifically, the central management node determines the identification information of the object to be queried based on the identification information of the terminal device contained in the query request. In other words, the user's terminal device has been bound to the device to be queried, and this binding relationship can also be stored in the central management node, so that the central management node knows which target data item of the object to be queried the terminal device needs to request to query. Then, the central management node will generate a query instruction based on the identification information of the object to be queried and the target data item, and send the query instruction to multiple cache nodes corresponding to the corresponding target storage services, so as to quickly respond to the query instruction and obtain the query result of the target data item of the object to be queried.
[0072] Each of the multiple cache nodes corresponding to the target storage service can query the target data item based on the query instruction. In this way, each cache node corresponding to the target storage service may obtain the query result of the target data item of the object to be queried, and the central management node will receive the query result of the target data item of the object to be queried sent by multiple cache nodes.
[0073] Optionally, it is assumed that the first cache node is any one of the multiple cache nodes. If the first cache node does not obtain the query result, the first cache node needs to read the data value corresponding to the target data item from the object to be queried, and use the data value as the query result of the target data item. In other words, the data value corresponding to the target data item may not exist in the first cache node, so it is necessary to read the data value corresponding to the target data item from the corresponding object to be queried, so that the query result of the target data item can be obtained.
[0074] The data value corresponding to the target data item may not exist in the first cache node, which may be due to the fact that the data value corresponding to the target data item sent by the object to be queried has not been received for a long time, resulting in the data value of the target data item being invalid. Alternatively, the target data item of the object to be queried is added to the first cache node for the first time, and the data value of the target data item has not been read for the first time.
[0075] S240: Receive query results sent by multiple cache nodes, and send the query results to the terminal device.
[0076] In one embodiment of the present application, some of the multiple cache nodes may be able to obtain query results, while some cache nodes may not be able to obtain query results due to network congestion or failure. Therefore, there may be more than two cache nodes that send query results to the central management node. In this case, that is, if there are multiple query results received for the target data item of the object to be queried, the central management node can select the earliest received query result from the multiple query results as the target query result. Then, the target query result can be sent to the terminal device, thereby completing the query of the target data item of the object to be queried.
[0077] Through this method, after receiving a query request for the target data of the object to be queried sent by the terminal device, the target storage service for storing the target data item can be determined based on the query request, so that the query instructions for the target data item of the object to be queried can be sent to the multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes all query the query results of the target data item based on the query instructions. In this way, when the query results returned by the multiple cache nodes are received, the query results can be sent to the terminal device.
[0078] Through this method, firstly, data is stored through distributed cache nodes, which effectively reduces the load pressure of the data center and improves the query efficiency.
[0079] Secondly, different storage services are used to store data items of different data item types, so that data can be differentiated according to the storage service, which is more convenient for data management. When performing data queries, the cache node storing the target data item can be located more quickly, thereby improving the efficiency of data queries.
[0080] Finally, each storage service corresponds to multiple cache nodes. When a cache node fails or the load is too high, other cache nodes can share the query task, ensuring the stability and response speed of the query and improving the reliability and efficiency of data query.
[0081] In one embodiment of the present application, another data query method is provided, which can be executed by a central management node. Figure 3 As shown, the data query method may include S310 to S320 and S210 to S240. That is, S310 to S320 are Figure 2 The steps required to be performed before S210 are shown.
[0082] S310 to S320 are described below:
[0083] S310: Receive a registration request sent by a cache node to be registered through a data channel to be registered; the registration request includes identification information of a storage service corresponding to the cache node to be registered.
[0084] The cache node to be registered refers to the cache node that has not been registered on the central management node. The cache node to be registered can be a cache node newly added by the technical staff of the central management node. It can be bound to a specific storage service so that it can store data items of the data item type associated with the storage service. In order to be managed by the central management node, the cache node to be registered needs to be registered on the central management node.
[0085] Specifically, the cache node to be registered will be bound to a data channel to be registered, and send the registration request to the central management node through the data channel to be registered. The registration request may be in the form of a registration frame.
[0086] S320. In response to the registration request, the association relationship between the cache node to be registered, the storage service and the data channel to be registered is stored to complete the registration of the cache node to be registered; wherein different cache nodes are associated with different data channels.
[0087] Then, after receiving the registration request, the central management node will parse the registration request, obtain the type of storage service provided by the cache node to be registered, and determine the data channel to be registered. In this way, the association between the cache node to be registered, the storage service and the data channel to be registered can be stored to complete the registration of the cache node to be registered.
[0088] Different cache nodes are associated with different data channels. That is, one data channel can be uniquely associated with one cache node, and the central management node can send data to the cache node through the data channel, and correspondingly, the cache node can also send data to the central management node through the data channel.
[0089] In one embodiment of the present application, since each cache node is already associated with a corresponding data channel, when the central management node sends query instructions for target data items of the query object to be queried to multiple cache nodes corresponding to the target storage service, it can use the data channel associated with each cache node to send the instructions.
[0090] Optionally, the central management node can also perform regular detection on each cache node to detect whether each cache node has any faults, such as blocking, disconnection, etc. If a faulty cache node is detected, a prompt message can be output to the technician so that the technician can perform operations such as repairing or deleting the cache node. When the cache node returns to normal, the central management node can automatically reintegrate it into the distributed cache system and perform data synchronization and recovery operations.
[0091] Through this method, the registration method of the cache node is simplified, so that the new cache node can quickly access the central management node. The cache node to be registered can immediately start storing related data items by establishing a connection with the central management node and sending a registration request, which reduces the maintenance cost and management complexity of the central management node.
[0092] Secondly, the central management node stores the relationship between cache nodes, storage services and data channels, making data transmission more efficient and reliable. Each cache node has a unique storage service and data channel. This one-to-one design ensures the smooth flow of data, avoids confusion caused by the increase in the number of nodes, and improves the efficiency of data query.
[0093] Finally, as data query needs grow, technicians can easily add new cache nodes to one or more storage services based on actual needs without affecting the operation of existing cache nodes, thereby improving the flexibility of data storage.
[0094] In one embodiment of the present application, another data query method is provided, which can be executed by a central management node. Figure 4 As shown, the data query method may include S410 to S420. That is, S410 to S420 are Figure 2 Steps that can be executed in addition to the steps that are executed.
[0095] S410 to S420 are described below:
[0096] S410. If a data update request for a target data item of a query object is received from a second cache node, an updated data value corresponding to the target data item and a version number corresponding to the updated data value are extracted from the data update request; wherein the second cache node is any one of the multiple cache nodes.
[0097] The central management node first receives a data update request for the target data item of the object to be queried from the second cache node. The content of this request includes the target data item, the updated data value corresponding to the target data item, and the version number corresponding to the updated data. Among them, the updated value represents the latest data value of the target data item, which comes from the object to be queried.
[0098] Optionally, the second cache node may periodically access the object to be queried to update the data value of the target data item to obtain the updated data value.
[0099] Optionally, the object to be queried may actively send the data value of the target data item to the second cache node, so that the second cache node may obtain the updated data value.
[0100] In the embodiment of the present application, when the data value of the target data item is updated, a version number corresponding to the updated data value can be generated, which represents the version of the corresponding data value of the target data item. The version number can be expressed as V1 (version 1), V2 (version 2), and version (3), etc.
[0101] When the second cache node obtains the updated data value, it can request to update the data value of the target data item of the object to be queried in the related node. At this time, the second cache node will send a data update request for the target data item of the object to be queried to the central management node. The related node refers to the node that provides the same storage service. For example, multiple cache nodes corresponding to the target storage service are all related nodes.
[0102] S420: Send the updated data value and version number to other cache nodes among the multiple cache nodes except the second cache node, so that each other cache node updates the target data item based on the updated data value and version number.
[0103] The central management node will broadcast the updated data value and the corresponding version number to all other cache nodes in the multiple cache nodes (i.e., all cache nodes in the multiple cache nodes except the second cache node). Each other cache node will compare the version number of the data value of the currently stored target data item with the version number of the updated data value. And based on the size, it will decide whether to update the data value of the target data item.
[0104] For example, if the version number corresponding to the updated data value sent by the second cache node is V3, and the version number of the data value of the target data item of a related node is V2, then the related node will update the data value of the target data item to make it the same as the updated data value.
[0105] For another example, if the version number of the data value of the target data item of a certain related node is V3, then the related node does not need to update the data value of the target data item.
[0106] Through this method, in the form of version numbers, multiple cache nodes can quickly keep the data values of target data items in the latest state, improving the data consistency of distributed cache nodes, thereby ensuring the accuracy of data queries.
[0107] In one embodiment of the present application, another data query method is provided, which can be executed by a cache node, a central management node and a terminal device. Figure 5 As shown, the data query method may include S501 to S508.
[0108] S501 to S508 are described below:
[0109] S501. Any cache node sends a registration request to the central management node.
[0110] Any cache node may read the configuration of the central management node, and send a registration request to the central management node through a bound channel, and the registration request may be a registration frame.
[0111] S502: The central management node responds to the registration request and registers any cache node.
[0112] The central management node will store the association between the storage services and channels corresponding to any cache node, thereby completing the registration of any cache node.
[0113] S503: The central management node receives a query request for a target data item of a query object sent by a terminal device.
[0114] S504: The central management node determines a target storage service for storing the target data item based on the query request.
[0115] S505: The central management node sends query instructions for target data items of the query object to multiple cache nodes corresponding to the target storage service respectively.
[0116] When the central management node sends a query instruction, it is sent through the channel corresponding to each cache node.
[0117] S506. The plurality of cache nodes obtain query results of the target data items of the object to be queried based on the query instruction.
[0118] S507. Multiple cache nodes send query results to the central management node.
[0119] If multiple query results for the target data item of the object to be queried are received, the earliest received query result is selected from the multiple query results as the target query result.
[0120] S508: The central management node sends the query result to the terminal device.
[0121] If the received query results for the target data item of the object to be queried are multiple, the central management node sends the target query results to the terminal device.
[0122] Optionally, the cache node may have a capacity utilization rate that is too high, and the central management node can detect it and issue an early warning to the technicians so that the technicians can expand the storage space of the cache node or delete some data.
[0123] The data query method of the present application is illustrated below with reference to two application scenarios.
[0124] In one embodiment of the present application, in a large Advanced Metering Infrastructure (AMI) hybrid energy storage system (HES), i.e., an AMI HES system, users may frequently read data such as the status of the meter through terminal devices. In order to improve the efficiency of data query, a distributed cache system is adopted. The system caches data in multiple local nodes, reduces the access pressure of the database, and speeds up the query. When a user queries the target data item of the meter (such as electricity consumption), the central management node will first obtain the query result of the target data item from the cache node. If the query result is not obtained in the cache node, the cache node will read the latest data value of the target data item from the meter and store it. In addition, the central management node will automatically adjust the cache strategy according to the access frequency of each data item of the meter, including the storage location and expiration time of the cached data, to improve the success rate of data query.
[0125] In one embodiment of the present application, in the prepaid system, the real-time and accuracy of the meter usage data are crucial. To this end, the use of a distributed cache system can significantly improve transaction processing efficiency and reduce network transmission load. Specifically, the central management node caches the transaction data of the meter (such as account balance, etc.) on multiple cache nodes, which can reduce dependence on remote databases and shorten data access time. Then, when the central management node receives a recharge request, it will first search for the account information and balance of the meter from multiple cache nodes. If it is not found in the cache, it is read from the meter and updated to the cache node.
[0126] In this way, first of all, by storing data through distributed cache nodes, the load pressure of the data center is effectively reduced and the query efficiency is improved.
[0127] Secondly, different storage services are used to store data items of different data item types, so that data can be differentiated according to the storage service, which is more convenient for data management. When performing data queries, the cache node storing the target data item can be located more quickly, thereby improving the efficiency of data queries.
[0128] Finally, each storage service corresponds to multiple cache nodes. When a cache node fails or the load is too high, other cache nodes can share the query task, ensuring the stability and response speed of the query and improving the reliability and efficiency of data query.
[0129] Figure 6 FIG. 1 is a block diagram of a data query device according to an embodiment of the present application. Figure 6 As shown, the data query device can be applied to a central management node, and the device includes:
[0130] A data query device, comprising:
[0131] The transceiver unit 610 is used to receive a query request for a target data item to be queried sent by a terminal device;
[0132] A determination unit 620, configured to determine a target storage service for storing the target data item based on the query request;
[0133] The transceiver unit 610 is further configured to send query instructions for the target data items of the query object to be queried to the multiple cache nodes corresponding to the target storage service, so that the multiple cache nodes obtain query results for the target data items of the query object based on the query instructions;
[0134] The transceiver unit 610 is further configured to receive query results sent by multiple cache nodes, and send the query results to the terminal device.
[0135] In one embodiment of the present application, based on the aforementioned scheme, the determination unit 620 is also used to determine the identification information of the object to be queried based on the identification information of the terminal device contained in the query request; the device also includes a processing unit 630, which is used to generate a query instruction based on the identification information of the object to be queried and the target data item; the transceiver unit 610 is also used to send query instructions to multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain the query results of the target data items of the object to be queried based on the query instructions.
[0136] In one embodiment of the present application, based on the aforementioned scheme, the process of multiple cache nodes obtaining query results of target data items of an object to be queried based on a query instruction includes: if the first cache node does not obtain the query result, then reading the data value corresponding to the target data item from the object to be queried, and using the data value as the query result; wherein the first cache node is any one of the multiple cache nodes.
[0137] In one embodiment of the present application, based on the aforementioned scheme, the processing unit 630 is also used to select the earliest received query result from the multiple query results as the target query result if there are multiple query results received for the target data item of the object to be queried; the transceiver unit 610 is also used to send the target query result to the terminal device.
[0138] In one embodiment of the present application, based on the aforementioned scheme, before receiving a query request for a target data item of an object to be queried sent by a terminal device, the transceiver unit 610 is also used to receive a registration request sent by the cache node to be registered through the data channel to be registered; the registration request includes identification information of the storage service corresponding to the cache node to be registered; the device also includes a storage unit 640, which is used to store the association relationship between the cache node to be registered, the storage service and the data channel to be registered in response to the registration request to complete the registration of the cache node to be registered; wherein different cache nodes are associated with different data channels; query instructions for the target data items of the object to be queried are sent to multiple cache nodes corresponding to the target storage service respectively, including: sending query instructions for the target data items of the object to be queried to multiple cache nodes through multiple data channels associated with the target storage service.
[0139] In one embodiment of the present application, based on the above-mentioned solution, the processing unit 630 is further used to determine the data item type to which the target data item belongs; and select a storage service matching the data item type from multiple storage services as the target storage service.
[0140] In one embodiment of the present application, based on the aforementioned scheme, the processing unit 630 is further used to extract the updated data value corresponding to the target data item and the version number corresponding to the updated data value from the data update request if a data update request for the target data item of the query object is received from the second cache node; wherein the second cache node is any one of the multiple cache nodes; the transceiver unit 610 is further used to send the updated data value and version number to other cache nodes among the multiple cache nodes except the second cache node, so that each other cache node updates the target data item based on the updated data value and version number.
[0141] It should be noted that the apparatus provided in the aforementioned embodiment and the method provided in the aforementioned embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment.
[0142] An embodiment of the present application also provides a data query device, including: one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the electronic device implements the above data query method.
[0143] Figure 7 It is a structural diagram of a computer system suitable for implementing a data query device of an embodiment of the present application.
[0144] It should be noted that Figure 7 The computer system 700 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0145] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 702 or the program loaded from the storage part 708 to the random access memory (RAM) 703, such as executing the method in the above embodiment. In the RAM 703, various programs and data required for system operation are also stored. The CPU 701, ROM 702 and RAM 703 are connected to each other through a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0146] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed so that a computer program read therefrom is installed into the storage section 708 as needed.
[0147] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 709, and / or installed from a removable medium 711. When the computer program is executed by a central processing unit (CPU) 701, various functions defined in the system of the present application are executed.
[0148] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. Computer-readable media may be, for example, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0149] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0150] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.
[0151] Another aspect of the present application also provides a computer readable medium having a computer program stored thereon, which implements the above data query method when the computer program is executed by a processor. The computer readable medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0152] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable medium. A processor of a computer device reads the computer instruction from the computer-readable medium, and the processor executes the computer instruction, so that the computer device executes the data query method provided in each of the above embodiments.
[0153] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A data query method, characterized in that: include: Receiving a query request for a target data item of a query object sent by a terminal device; Determine a target storage service for storing the target data item based on the query request; wherein different storage services are used to store data items of different data item types; Sending query instructions for the target data items of the object to be queried to multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain query results for the target data items of the object to be queried based on the query instructions; The query results sent by the multiple cache nodes are received, and the query results are sent to the terminal device.
2. The method according to claim 1, characterized in that The sending query instructions for the target data items of the to-be-queried object to the multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain query results for the target data items of the to-be-queried object based on the query instructions, includes: Determine the identification information of the object to be queried based on the identification information of the terminal device included in the query request; Based on the identification information of the object to be queried and the target data item, generating the query instruction; The query instructions are respectively sent to multiple cache nodes corresponding to the target storage service, so that the multiple cache nodes obtain query results of the target data items of the object to be queried based on the query instructions.
3. The method according to claim 2, characterized in that The process of the plurality of cache nodes acquiring the query result of the target data item of the object to be queried based on the query instruction includes: If the first cache node does not obtain the query result, the data value corresponding to the target data item is read from the object to be queried, and the data value is used as the query result; wherein the first cache node is any one of the multiple cache nodes.
4. The method according to claim 1, characterized in that: The receiving the query results sent by the multiple cache nodes, and sending the query results to the terminal device, includes: If there are multiple query results received for the target data item of the object to be queried, selecting the earliest received query result from the multiple query results as the target query result; Send the target query result to the terminal device.
5. The method according to claim 1, characterized in that Before receiving the query request for the target data item to be queried sent by the terminal device, the method further includes: Receiving a registration request sent by a cache node to be registered through a data channel to be registered; the registration request includes identification information of a storage service corresponding to the cache node to be registered; In response to the registration request, storing the association relationship between the cache node to be registered, the storage service and the data channel to be registered, so as to complete the registration of the cache node to be registered; wherein different cache nodes are associated with different data channels; The sending query instructions for the target data items of the to-be-queried object to the multiple cache nodes corresponding to the target storage service respectively includes: A query instruction for the target data item of the object to be queried is sent to the multiple cache nodes through multiple data channels associated with the target storage service.
6. The method according to claim 1, characterized in that The determining, based on the query request, a target storage service that matches the target data item includes: Determining the data item type to which the target data item belongs; A storage service matching the data item type is selected from a plurality of storage services as the target storage service.
7. The method according to claim 1, characterized in that The method further comprises: If a data update request for the target data item of the object to be queried is received from a second cache node, an updated data value corresponding to the target data item and a version number corresponding to the updated data value are extracted from the data update request; wherein the second cache node is any one of the multiple cache nodes; The updated data value and the version number are sent to other cache nodes among the multiple cache nodes except the second cache node, so that each other cache node updates the target data item based on the updated data value and the version number.
8. A data query device, characterized in that: include: A transceiver unit, configured to receive a query request for a target data item of a query object sent by a terminal device; A determining unit, configured to determine a target storage service for storing the target data item based on the query request; The transceiver unit is further used to send query instructions for the target data items of the object to be queried to the multiple cache nodes corresponding to the target storage service respectively, so that the multiple cache nodes obtain query results for the target data items of the object to be queried based on the query instructions; The transceiver unit is further configured to receive the query results sent by the multiple cache nodes, and send the query results to the terminal device.
9. A data query device, characterized in that: include: a memory storing computer-readable instructions; A processor reads the computer readable instructions stored in the memory to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 7.