Data storage method, data query method and related devices
By using the message queue peak shaving and the associated storage method of the distributed file system in the energy storage device data storage, the real-time and performance problems of the energy storage device data storage and query are solved, and efficient data processing and query are achieved.
Patent Information
- Application Number
- CN202310266911.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-19
- Publication Date
- 2024-09-20
AI Technical Summary
The existing technology has the problem of high storage and maintenance costs in energy storage equipment data storage and query, and it is difficult to meet the needs of real-time data storage and query. Especially in scenarios where equipment reports frequently and the data volume is large and updated frequently, the performance is low.
By obtaining the operating data and attribute parameters of the target device, use the message queue to perform data peak shaving, and write the data into the pre-categorization directory of the distributed file system, establish an associated storage of data and metadata, and use streaming processing tools and caching Space-optimized query performance.
It effectively solves the problem of frequent data reporting affecting writing performance, improves writing performance, ensures real-time efficiency of data storage and query, reduces dependence on hive, and is suitable for real-time data scenarios.
Smart Images

Figure CN118672992A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent data processing, and in particular to a data storage method, a data query method and related devices. Background Art
[0002] With the development of the energy storage industry, the application scenarios of household energy storage equipment are becoming more and more extensive. The data of the equipment is usually sent to the cloud server through communication equipment, and the cloud server finally stores a large amount of data. At present, for the above scenarios, the industry's solution is to consider storing the reported data directly in MySQL, or storing it in a distributed file system through hive. The problem with the former approach is that when devices report frequently, it will pose a great threat to the write performance of the MySQL cluster. The write pressure is dispersed by expanding the cluster, but if the MySQL cluster is too large, it will cause poor maintainability, and the server cost and cluster maintenance cost will also increase accordingly; the problem with the latter approach is that although the use of a distributed file system can achieve smooth expansion of storage nodes, for scenarios with large data volumes and frequent updates, the performance of writing to HDFS through Hive is extremely low. The reason is that Hive needs to maintain metadata related to HDFS storage and Hive table structure; for the latter approach, instead of storing through Hive, directly storing the Hfds file system, the update performance at this time can reach a very high level, but this scenario is only suitable for offline data. The scenario of offline data has the characteristics of high latency and is not applicable to scenarios where real-time display of statistical data reported by energy storage devices is required. Summary of the invention
[0003] In view of the above problems existing in the prior art, the present invention proposes a data storage method, a data query method and related devices, which mainly solve the problems that the existing methods have high storage and maintenance costs and are difficult to meet real-time data storage and query needs.
[0004] In order to achieve the above purpose and other purposes, the technical solution adopted by the present invention is as follows.
[0005] The present application provides a data storage method, comprising:
[0006] Acquire operation data of different target devices and attribute parameters corresponding to the operation data;
[0007] Performing data peak shaving on the operation data through a message queue to obtain data to be stored;
[0008] The data to be stored is written into a corresponding target directory of a distributed file system according to the attribute parameters, and the attribute parameters are used as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset partitioning strategy.
[0009] In an embodiment of the present application, obtaining operation data of different target devices includes:
[0010] Establishing a long connection with the target device to read the operation data of the target device into a cache in the form of a byte stream, wherein each of the byte streams contains a plurality of operation data;
[0011] Compare the byte length of the byte stream in the cache with a preset total length threshold to obtain a comparison result;
[0012] A complete byte stream is extracted from the cache according to the comparison result, so as to determine the operation data of the target device based on the complete byte stream.
[0013] In an embodiment of the present application, before comparing the byte length of the byte stream in the cache with a preset total length threshold, the method further includes:
[0014] Reading a byte start marker for storing a byte length in the byte stream;
[0015] Determine a target field for storing the byte length according to the byte start identifier and a preset byte offset;
[0016] The preset total length threshold is determined according to the target field.
[0017] In an embodiment of the present application, extracting a complete byte stream from the cache according to the comparison result includes:
[0018] If the length of the current byte stream in the cache is less than the preset total length threshold, wait for the next byte stream to enter the cache, and add bytes of the corresponding length in the next byte stream to the current byte stream to obtain a byte stream with a byte length equal to the preset total length threshold as a complete byte stream;
[0019] If the length of the current byte stream in the cache is greater than the preset total length threshold, a byte stream equal to the preset total length threshold is intercepted from the current byte stream according to the byte start identifier as a complete byte stream.
[0020] In an embodiment of the present application, writing the data to be stored into a corresponding target directory of the distributed file system according to the attribute parameters includes:
[0021] Compare the attribute parameters with the preset description fields of each target directory for similarity to obtain a matching target directory;
[0022] The target file path of the matched target directory is obtained, and the corresponding operation data is written into the target file path through a preset streaming processing tool.
[0023] In an embodiment of the present application, the attribute parameters are used as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, including:
[0024] Starting a scheduled task to add the attribute parameters to a preset metadata partition table;
[0025] The data to be stored in the target directory is associated with corresponding attribute parameters in the metadata partition table to perform a running data query based on the metadata partition table.
[0026] The present application also provides a data query method, including:
[0027] Obtaining a query statement, and comparing the query statement with attribute parameters corresponding to operation data of different target devices to obtain matching attribute parameters;
[0028] The corresponding operation data stored in the corresponding target directory is called according to the matched attribute parameters to obtain the first query data, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy, the corresponding operation data stored in the target directory is obtained by writing the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and the data to be stored is obtained by performing data peak shaving on the operation data through a message queue.
[0029] In an embodiment of the present application, after calling the corresponding operation data stored in the preset target directory according to the matched attribute parameters, the method further includes:
[0030] Calling cache data in a preset cache space according to the matched attribute parameters to obtain second query data, wherein the cache data includes the latest multiple pieces of data to be stored written into the distributed file system;
[0031] The first query data and the second query data are combined and output as a query result.
[0032] In an embodiment of the present application, before calling the cache data in the preset cache space according to the matched attribute parameters, the method further includes:
[0033] Sorting the cache data in the preset cache space according to the acquisition time of the corresponding running data of different target devices to obtain a sorted set;
[0034] The sorted set is updated according to the time attribute of the sorted set, so that the latest fixed number of cache data is retained in the sorted set.
[0035] The present application also provides a data storage device, comprising:
[0036] A data acquisition module, used to acquire the operating data of different target devices and the attribute parameters corresponding to the operating data;
[0037] A peak shaving module, used for performing data peak shaving on the operation data through a message queue to obtain data to be stored;
[0038] A storage module is used to write the data to be stored into a corresponding target directory of a distributed file system according to the attribute parameters, and use the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy.
[0039] The present application also provides a data query device, comprising:
[0040] A query module, used to obtain a query statement, compare the query statement with the attribute parameters corresponding to the operation data of different target devices, and obtain matching attribute parameters;
[0041] An output module is used to call the corresponding operation data stored in the corresponding target directory according to the matched attribute parameters to obtain the first query data, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy, and the corresponding operation data stored in the target directory is obtained by writing the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and the data to be stored is obtained by performing data peak shaving on the operation data through a message queue.
[0042] The present application also provides a computer device, the device comprising a processor and a memory;
[0043] The memory is used to store computer programs;
[0044] The processor is used to execute the energy storage device scheduling method or the model management method according to the computer program.
[0045] The present application also provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used for the energy storage device scheduling method or the model management method.
[0046] As described above, a data storage method, a data query method and related devices provided by the present application have the following beneficial effects.
[0047] This application can effectively solve the problem of frequent data reporting affecting write performance by shaving data peaks. At the same time, after writing the data into the distributed file system, the association between the target data and the metadata is established, and writing is no longer dependent on hive, which can greatly improve the write performance and ensure real-time and efficient data storage and query. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 Schematic diagram of a data storage method in one embodiment of the present application.
[0049] Figure 2 Schematic diagram of a data query method in one embodiment of the present application.
[0050] Figure 3 Schematic diagram of the structure of a data storage device in one embodiment of the present application.
[0051] Figure 4 Schematic diagram of the structure of a data query device in one embodiment of the present application.
[0052] Figure 5 A schematic diagram of the structure of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0054] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0055] See also Figure 1 , Figure 1 The following is a flow chart of a data storage method in an embodiment of the present application. The data storage method of the present application is described in detail in conjunction with a specific embodiment. The data storage method includes the following steps:
[0056] Step S100, obtaining operation data of different target devices and attribute parameters corresponding to the operation data.
[0057] In one embodiment, the target device includes but is not limited to photovoltaic energy storage devices at the user end, and photovoltaic energy storage devices are taken as an example here. Photovoltaic energy storage devices distributed in different regions are connected to the cloud server, and the operating data of the photovoltaic energy storage devices is reported to the cloud server. The cloud server collects the reported operating data and stores the data for query and call according to different needs. It should be noted that the operating data may include: power generation, storage capacity, power consumption, light duration, etc. This application does not impose any restrictions on the operating data. The attribute data corresponding to the operating data include cloud data collection time, operating environment parameters, environmental humidity, light intensity, longitude and latitude of the target device and other parameters. Each time the target device reports operating data, the cloud can synchronously collect the attribute parameters of the corresponding target data.
[0058] In one embodiment, obtaining operation data of different target devices includes the following steps:
[0059] Step S101, establishing a long connection with the target device to read the operating data of the target device into a cache in the form of a byte stream, wherein each of the byte streams contains a plurality of operating data.
[0060] In actual applications, when the target device reports operating data to the cloud, it needs to initiate a connection to the cloud first. The cloud can establish a connection with the target device by calling the access service of the corresponding target device. The access services of different types of target devices may be different. The type or identification of the target device can be obtained through the request initiated by the target device. Then, based on the type or identification information, the preset access service of the cloud is called to establish a connection between the cloud and the target device. After the connection is established, the current operating data is reported to the cloud. After that, the connection between the cloud and the target device will be maintained for a period of time. During the holding time, the target device can perform data reporting operations again based on the connection without re-establishing the connection. The above is the overall process of long connection data transmission. Among them, the holding time can be set according to the actual application requirements and is not limited here. After the cloud receives the operating data reported by the target device, it reads the byte stream corresponding to the operating data. A byte stream may include multiple operating data. It should be noted that before establishing a long connection between the target device and the cloud by calling the access service, the data parsing protocol between the target device and the cloud can be specified in the access service so that the reported data can be uniformly parsed based on the data parsing protocol.
[0061] Step S102: compare the byte length of the byte stream in the cache with a preset total length threshold to obtain a comparison result.
[0062] In one embodiment, since there are usually problems of half packets or sticky packets during the data reading process, it is necessary to process the byte stream in the cache to ensure the integrity of the byte stream.
[0063] In one embodiment, before comparing the byte length of the byte stream in the cache with a preset total length threshold, the following steps are also included:
[0064] Step S1021, read the byte start mark for saving the byte length in the byte stream. The starting subscript and offset of the byte can be saved in the byte stream by specifying the byte, and the offset can be set according to actual application requirements and saved in the specified byte.
[0065] Step S1022, determine the target field for storing the byte length according to the byte start identifier and the preset byte offset. The cloud can calculate the overall length of a byte stream by reading the specified byte. For example, the two bytes with a subscript of 4 and a length of 2 in the cache are used as bytes for storing byte stream information. The cloud can calculate the total length of a byte stream by reading the two bytes with a subscript of 4 and a length of 2 in the cache.
[0066] Step S1023, determining the preset total length threshold according to the target field. Specifically, the calculated total length can be directly used as the preset total length threshold. The preset total length threshold of different target devices can be set to be different, which can be adjusted according to actual application requirements and is not limited here.
[0067] Furthermore, the byte stream can be read from the cache to determine whether the length of the read byte stream is consistent with the preset total length threshold. If it is less than the preset total length threshold, there is a half-packet problem; if it is greater than the preset total length threshold, there is a sticky packet problem.
[0068] Step S103: extracting a complete byte stream from the cache according to the comparison result, so as to determine the operation data of the target device based on the complete byte stream.
[0069] In one embodiment, extracting the complete byte stream from the cache according to the comparison result comprises the following steps:
[0070] Step S1031, if the length of the current byte stream in the cache is less than the preset total length threshold, wait for the next byte stream to enter the cache, and add the bytes of the corresponding length in the next byte stream to the current byte stream to obtain a byte stream with a byte length equal to the preset total length threshold as a complete byte stream.
[0071] Specifically, when it is determined based on the preset total length threshold that the read byte stream has a half-packet problem, the difference between the length of the current byte stream and the preset total length threshold is calculated. The subsequent byte stream can be waited for to be read into the cache, and based on the calculated difference, bytes of the length corresponding to the difference are intercepted from the byte stream read in later and added to the current byte stream to obtain a complete byte stream. Exemplarily, the first byte identifier of the next byte stream to be read can be read, the calculated difference is used as the offset, and the first byte identifier is used as the starting point, and bytes of the length corresponding to the offset are intercepted as the added bytes.
[0072] Step S1032: If the length of the current byte stream in the cache is greater than the preset total length threshold, a byte stream equal to the preset total length threshold is intercepted from the current byte stream according to the byte start identifier as a complete byte stream.
[0073] Specifically, when it is determined based on the preset total length threshold that the read byte stream has a sticky packet problem, the difference between the length of the current byte stream and the preset total length threshold is calculated. Based on the calculated difference, bytes of the length corresponding to the difference are intercepted from the current byte stream and added to the next byte stream read in, so as to obtain a complete byte stream. Exemplarily, the first byte in the current byte stream can be used as the calculation starting point, the last byte identifier corresponding to the preset total length threshold is calculated, the calculated difference is used as the offset, the last byte identifier is used as the starting point, bytes of the length corresponding to the offset are intercepted as the added bytes, and added to the next byte stream read in, so as to obtain a complete byte stream.
[0074] Step S110, performing data peak shaving on the operation data through a message queue to obtain data to be stored.
[0075] In one embodiment, since the cloud is synchronously connected to a large number of target devices, there may be a large amount of operation data uploaded or attribute parameters corresponding to a large amount of operation data collected synchronously at the same time node, which will greatly affect the data reading and writing performance. Therefore, after the data is parsed to obtain a complete byte stream, the byte stream can be sent to the kafka data platform, and the byte stream can be peak-cut based on the message queue. Only a preset upper limit of byte streams is allowed to be written to the message queue each time to achieve the purpose of peak-cutting and reduce the pressure on subsequent processes to store data. The data written to the message queue is used as the data to be stored. The data to be stored is subsequently written directly to the distributed file system through a streaming processing tool. It should be noted that streaming processing tools include but are not limited to flink.
[0076] Step S120, writing the data to be stored into a corresponding target directory of the distributed file system according to the attribute parameters, and using the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset partitioning strategy.
[0077] In one embodiment, the distributed file system can divide directories according to attribute parameters to obtain target directories corresponding to different attribute parameters. After the data to be stored is written into the distributed file system, it will be stored according to the following dimensions: data type, time, and region. Exemplarily, data of different data types are stored separately according to the content reported by different target devices and the different reporting cycles; based on the collection time, the operating data of each target device in different time periods are stored in different target directories, and based on the region, the operating data of target devices in the same region are stored in the same target directory. Based on the above storage rules, data of different data types, times, and regions are stored in different target directories.
[0078] In one embodiment, writing the data to be stored into a corresponding target directory of a distributed file system according to the attribute parameters comprises the following steps:
[0079] Step S121 : performing a similarity comparison between the attribute parameters and the preset description fields of each target directory to obtain a matching target directory.
[0080] In one embodiment, since the target directory is pre-partitioned based on attribute parameters, the leading attribute parameters used to pre-partition the target directory can be used as the description field of the corresponding target directory; the attribute parameters corresponding to the running data in the current byte stream can be matched with the description field corresponding to the target directory for similarity, and the target directory whose similarity reaches a set threshold can be used as the matching target directory.
[0081] Step S122, obtaining the target file path of the matched target directory, and writing the corresponding operation data into the target file path through a preset streaming processing tool.
[0082] In one embodiment, after obtaining a matching target directory, the target file path where the system stores the target directory data can be called, and the running data in the byte stream is written into the corresponding target file path through a streaming processing tool such as flink.
[0083] In one embodiment, using the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage includes the following steps:
[0084] Step S123, starting a scheduled task to add the attribute parameters to a preset metadata partition table;
[0085] In one embodiment, after the operation data is written into the corresponding target directory, the attribute parameters can be added to a preset metadata partition table by calling a scheduled task, and the attribute parameters of each operation data can be stored through the metadata partition table.
[0086] Step S124: Associating the data to be stored in the target directory with corresponding attribute parameters in the metadata partition table, so as to perform a data query based on the metadata partition table.
[0087] In one embodiment, the attribute parameters in the metadata partition table can be associated with the data to be stored in the target directory by means of data indexes. For example, a mapping relationship between the attribute parameters and the corresponding data in the target directory can be established, and the storage data corresponding to the mapping relationship can be directly called by subsequently searching for new attribute parameters.
[0088] Based on the data storage method of the embodiment of the present application, a long connection is established through the cloud connection service and the data reported by the target device is parsed, providing an effective solution to the half-packet and sticky packet problems, ensuring the integrity of the data received by the cloud and the reliability of subsequent storage and query; traffic peak shaving is performed based on the message queue, which can effectively ensure the stable operation of the system when processing a large amount of data; distributed storage is performed based on attribute parameters, which is conducive to the rapid response of subsequent data queries; data writing is performed based on byte streams, and there is no need to rely on hive in advance for metadata maintenance and management, thereby ensuring data storage performance; after data storage is completed, the metadata partition table is associated to facilitate subsequent data queries.
[0089] See also Figure 2 , Figure 2 The present invention also provides a data query method, which includes the following steps:
[0090] Step S200: obtaining a query statement, comparing the query statement with the attribute parameters corresponding to the operation data of different target devices, and obtaining matching attribute parameters.
[0091] In one embodiment, after associating the attribute parameters as metadata with the data stored in the target directory based on the steps of the aforementioned data storage method, in response to a query statement input by the user, the query statement can be compared with the attribute parameters in the metadata partition table, the similarity between the two can be calculated, and the attribute parameters whose similarity reaches a set threshold can be used as the attribute parameters that match the query statement.
[0092] Step S210, calling the corresponding operating data stored in the corresponding target directory according to the matched attribute parameters to obtain the first query data, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy, and the corresponding operating data stored in the target directory is obtained by writing the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and the data to be stored is obtained by performing data peak shaving on the operating data through a message queue.
[0093] In one embodiment, after obtaining the matching attribute parameters, the associated stored data is called based on the attribute parameters as the first query data.
[0094] In one embodiment, after calling the corresponding operation data stored in the preset target directory according to the matched attribute parameters, the following steps are also included:
[0095] Step S211, calling cache data in a preset cache space according to the matched attribute parameters to obtain second query data, wherein the cache data includes the latest multiple pieces of the to-be-stored data written into the distributed file system.
[0096] In one embodiment, in order to solve the problem of query data delay, after the running data is stored in the corresponding target directory of the distributed file system, the newly written running data can be saved in the preset cache space to obtain cache data. When the user performs a query, the cache data in the preset cache space is synchronously called according to the matching attribute parameters obtained from the query statement to obtain the second query data.
[0097] Step S212: combine the first query data and the second query data and output them as a query result.
[0098] In one embodiment, the first query data and the second query data are combined and output as the query result. The latest data in the preset cache space is combined into the result of the distributed file query, thereby ensuring the real-time performance of the data query.
[0099] In one embodiment, before calling the cache data in the preset cache space according to the matched attribute parameters, the following steps are also included:
[0100] Step S213 , sorting the cache data in the preset cache space according to the acquisition time of the corresponding running data of different target devices to obtain a sorted set.
[0101] In one embodiment, the cache data stored in the preset cache space may be sorted based on the time sequence to obtain a sorted set, and the time may be determined based on attribute parameters of different running data.
[0102] Step S214: updating the sorted set according to the time attribute of the sorted set so that the latest fixed number of cache data is retained in the sorted set.
[0103] In one embodiment, in actual application, the sorting combination can be updated based on the time attribute of the sorting set. Only multiple data closest to the current time node are retained in the sorting set. The specific number of retained data can be set according to actual application requirements and is not limited here.
[0104] Based on the data query method of the embodiment of the present application, the real-time nature of the data query results can be effectively guaranteed by performing a comprehensive query on the data in the preset cache space and the data in the distributed file system.
[0105] The entire process of data storage and query of the present application is described in detail below in conjunction with specific embodiments.
[0106] In one embodiment, target devices distributed in different regions can establish a long connection with the cloud. The target device initiates a connection request to the cloud, calls the corresponding connection service of the cloud based on the type or identification of the target device, and establishes a long connection for data transmission. After receiving the operation data reported by the target device, the cloud can synchronously collect the time information of the reported operation data, the geographical location of the target device, the current time and environmental conditions and other attribute parameters. The reported operation data is resolved according to the same resolution protocol pre-agreed with the target device, and the resolved data is written into the cache in the form of a byte stream, and the byte stream is judged to be complete based on the data in the cache.
[0107] In one embodiment, the length of a byte stream corresponding to the corresponding target device can be saved based on a specific field in the cache. The cloud obtains the total length information of a byte stream by reading the specific field, and determines whether there is a half-packet or sticky packet problem in each byte stream read based on the total length information. For the half-packet problem, after the subsequent byte stream is read in, the byte data of the corresponding length is intercepted from the subsequent byte stream and added to the current byte stream to ensure that the length of the current byte stream meets the length information saved in the specific field, thereby obtaining a complete byte stream. For the sticky packet problem, it can be determined which part of the bytes does not belong to the current byte stream based on the total length information saved in the specific field, and the data that does not belong to the current byte stream will flow into the next byte stream read in.
[0108] In one embodiment, after the complete byte stream is obtained through the above steps, the byte stream can be directly written into the corresponding target directory of the distributed file system through a streaming processing tool. It should be noted that the target directory is pre-partitioned based on the attribute parameters that need to be collected. Before writing to the target directory, the target directory that matches the corresponding operating data can be determined based on the attribute parameters corresponding to the operating data. After the operating data is written to the target directory, the latest operating data can also be stored in the preset cache space. In addition, the attribute parameters corresponding to the operating data written to the distributed file system are written into the metadata partition table through a scheduled task, and the attribute parameters are used as metadata of the corresponding operating data to establish a binding relationship between the operating data in the target directory and the corresponding attribute parameters in the metadata partition table.
[0109] In one embodiment, when performing data query, the input query statement can be matched with the attribute parameters in the metadata partition table to obtain the matched attribute parameters, and the running data bound to the attribute parameters in the distributed file system can be called based on the matched attribute parameters. At the same time, the latest running data in the preset cache space is obtained based on the matched attribute parameters, and the running data obtained from the distributed file system is merged with the running data obtained from the preset cache space as the query result output. It should be noted that the data stored in the preset cache space can be sorted based on the chronological order of data collection time, and querying based on the sorted data can improve the query response speed. At the same time, the data query is performed by combining the preset cache space and the distributed file system to ensure the real-time nature of the query data and effectively solve the problem of data lag.
[0110] With respect to the data storage method and data query method described above, the present application also provides corresponding data storage devices and data query devices, so that the above data storage method and data query method can be applied and implemented in practice.
[0111] See also Figure 3 , Figure 3 It is the same as the above Figure 1 The structural diagram of a data storage device 300 corresponding to the data storage method shown in FIG. Figure 3 As shown, the data storage device 300 includes:
[0112] A data acquisition module 310 is used to acquire operating data of different target devices and attribute parameters corresponding to the operating data;
[0113] The peak shaving module 311 is used to perform data peak shaving on the operation data through a message queue to obtain data to be stored;
[0114] The storage module 312 is used to write the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and use the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, and the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy.
[0115] In one embodiment, Figure 3 Based on the data storage device shown, the data acquisition module 310 is specifically used to: establish a long connection with the target device to read the operating data of the target device into a cache in the form of a byte stream, wherein each of the byte streams contains multiple operating data; compare the byte length of the byte stream in the cache with a preset total length threshold to obtain a comparison result; extract a complete byte stream from the cache according to the comparison result to determine the operating data of the target device based on the complete byte stream.
[0116] In one embodiment, Figure 3 Based on the data storage device shown, the data acquisition module 310 is specifically used to read the byte start identifier in the byte stream for storing the byte length; determine the target field for storing the byte length based on the byte start identifier and the preset byte offset; and determine the preset total length threshold based on the target field.
[0117] In one embodiment, Figure 3 On the basis of the data storage device shown, the data acquisition module 310 is specifically used to wait for the next byte stream to flow into the cache if the length of the current byte stream in the cache is less than the preset total length threshold, and add bytes of corresponding length in the next byte stream to the current byte stream to obtain a byte stream with a byte length equal to the preset total length threshold as a complete byte stream; if the length of the current byte stream in the cache is greater than the preset total length threshold, then according to the byte start identifier, a byte stream equal to the preset total length threshold is intercepted from the current byte stream as a complete byte stream.
[0118] In one embodiment, Figure 3 Based on the data storage device shown, the storage module 312 is specifically used to write the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, including: performing a similarity comparison between the attribute parameters and the preset description fields of each target directory to obtain a matching target directory; obtaining the target file path of the matching target directory, and writing the corresponding running data into the target file path through a preset streaming processing tool.
[0119] In one embodiment, Figure 3Based on the data storage device shown, the storage module 312 is specifically used to use the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, including: starting a scheduled task to add the attribute parameters to a preset metadata partition table; associating the data to be stored in the target directory with the corresponding attribute parameters in the metadata partition table to run data queries based on the metadata partition table.
[0120] See also Figure 4 , Figure 4 It is the same as the above Figure 3 The data query method shown in FIG. 4 is a structural diagram of a data query device 400 corresponding to the data query method shown in FIG. Figure 4 As shown, the data reading device 400 includes: a query module 410, used to obtain a query statement, compare the query statement with the attribute parameters corresponding to the operation data of different target devices, and obtain matching attribute parameters; an output module 411, used to call the corresponding operation data stored in the corresponding target directory according to the matching attribute parameters to obtain first query data, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy, the corresponding operation data stored in the target directory is obtained by writing the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and the data to be stored is obtained by performing data peak shaving on the operation data through a message queue.
[0121] In one embodiment, Figure 4 Based on the data query device shown, the output module 411 is specifically used to call the corresponding running data stored in the preset target directory according to the matched attribute parameters, and further includes: calling the cache data in the preset cache space according to the matched attribute parameters to obtain the second query data, the cache data including the latest multiple data to be stored written in the distributed file system; merging the first query data and the second query data as the query result output. In one embodiment, Figure 4 On the basis of the data query device shown, the output module 411 is specifically used for: before calling the cache data in the preset cache space according to the matching attribute parameters, it also includes: sorting the cache data in the preset cache space according to the acquisition time of the corresponding running data of different target devices to obtain a sorted set; updating the sorted set according to the time attribute of the sorted set so that the latest fixed number of cache data is retained in the sorted set.
[0122] The embodiment of the present application also provides a computer device for storing or reading data, which may specifically be a server. The server provided by the embodiment of the present application will be introduced below from the perspective of hardware entity.
[0123] See also Figure 5 , Figure 5 A schematic diagram of the structure of a server 1200 provided for an embodiment of the present application. The server 1200 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1222 (for example, one or more processors) and memory 1232, and one or more storage media 1230 (for example, one or more mass storage devices) storing application programs 1242 or data 1244. Among them, the memory 1232 and the storage medium 1230 may be short-term storage or permanent storage. The program stored in the storage medium 1230 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1222 may be configured to communicate with the storage medium 1230 to execute a series of instruction operations in the storage medium 1230 on the server.
[0124] The server 1200 may also include one or more power supplies 1226, one or more wired or wireless network interfaces 1250, one or more input and output interfaces 1258, and / or one or more operating systems, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0125] The steps performed by the server in the above embodiment can be based on the Figure 5 The server structure shown in FIG. 1 is a CPU 1222 configured to execute the steps of any implementation of the data storage method or data query method provided in the embodiments of the present application.
[0126] An embodiment of the present application also provides a computer-readable storage medium for storing a computer program, wherein the computer program is used to execute any implementation of a data storage method or a data query method described in the aforementioned embodiments.
[0127] The present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes any one of the data storage methods or data query methods described in the above embodiments.
[0128] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0129] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0130] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0131] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0132] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (full name in English: Read-Only Memory, English abbreviation: ROM), random access memory (full name in English: Random Access Memory, English abbreviation: RAM), disk or optical disk and other media that can store computer programs.
[0133] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A data storage method, characterized in that: include: Acquire operation data of different target devices and attribute parameters corresponding to the operation data; Performing data peak shaving on the operation data through a message queue to obtain data to be stored; The data to be stored is written into a corresponding target directory of a distributed file system according to the attribute parameters, and the attribute parameters are used as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset partitioning strategy.
2. The data storage method according to claim 1, characterized in that: Obtain operation data of different target devices, including: Establishing a long connection with the target device to read the operation data of the target device into a cache in the form of a byte stream, wherein each of the byte streams contains a plurality of operation data; Compare the byte length of the byte stream in the cache with a preset total length threshold to obtain a comparison result; A complete byte stream is extracted from the cache according to the comparison result, so as to determine the operation data of the target device based on the complete byte stream.
3. The data storage method according to claim 2, characterized in that: Before comparing the byte length of the byte stream in the cache with the preset total length threshold, the method further includes: Reading a byte start marker for storing a byte length in the byte stream; Determine a target field for storing the byte length according to the byte start identifier and a preset byte offset; The preset total length threshold is determined according to the target field.
4. The data storage method according to claim 3, characterized in that: Extracting a complete byte stream from the cache according to the comparison result includes: If the length of the current byte stream in the cache is less than the preset total length threshold, wait for the next byte stream to enter the cache, and add bytes of the corresponding length in the next byte stream to the current byte stream to obtain a byte stream with a byte length equal to the preset total length threshold as a complete byte stream; If the length of the current byte stream in the cache is greater than the preset total length threshold, a byte stream equal to the preset total length threshold is intercepted from the current byte stream according to the byte start identifier as a complete byte stream.
5. The data storage method according to claim 1, characterized in that: Writing the data to be stored into a corresponding target directory of the distributed file system according to the attribute parameters includes: Compare the attribute parameters with the preset description fields of each target directory for similarity to obtain a matching target directory; The target file path of the matched target directory is obtained, and the corresponding operation data is written into the target file path through a preset streaming processing tool.
6. The data storage method according to claim 1, characterized in that: Using the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, includes: Starting a scheduled task to add the attribute parameters to a preset metadata partition table; The data to be stored in the target directory is associated with corresponding attribute parameters in the metadata partition table to perform a running data query based on the metadata partition table.
7. A data query method, characterized in that: include: Obtaining a query statement, and comparing the query statement with attribute parameters corresponding to operation data of different target devices to obtain matching attribute parameters; The corresponding operation data stored in the corresponding target directory is called according to the matched attribute parameters to obtain the first query data, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy, the corresponding operation data stored in the target directory is obtained by writing the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and the data to be stored is obtained by performing data peak shaving on the operation data through a message queue.
8. The data query method according to claim 7, characterized in that: After calling the corresponding operation data stored in the preset target directory according to the matched attribute parameters, the method further includes: Calling cache data in a preset cache space according to the matched attribute parameters to obtain second query data, wherein the cache data includes the latest multiple pieces of data to be stored written into the distributed file system; The first query data and the second query data are combined and output as a query result.
9. The data query method according to claim 8, characterized in that: Before calling the cache data in the preset cache space according to the matched attribute parameters, the method further includes: Sorting the cache data in the preset cache space according to the acquisition time of the corresponding running data of different target devices to obtain a sorted set; The sorted set is updated according to the time attribute of the sorted set, so that the latest fixed number of cache data is retained in the sorted set.
10. A data storage device, characterized in that: include: A data acquisition module, used to acquire the operating data of different target devices and the attribute parameters corresponding to the operating data; A peak shaving module, used for performing data peak shaving on the operation data through a message queue to obtain data to be stored; A storage module is used to write the data to be stored into a corresponding target directory of a distributed file system according to the attribute parameters, and use the attribute parameters as metadata of the data to be stored in the corresponding target directory to associate the data to be stored with the corresponding metadata for storage, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy.
11. A data query device, characterized in that: include: A query module, used to obtain a query statement, compare the query statement with the attribute parameters corresponding to the operation data of different target devices, and obtain matching attribute parameters; An output module is used to call the corresponding operation data stored in the corresponding target directory according to the matched attribute parameters to obtain the first query data, wherein the target directory is obtained by pre-classifying the attribute parameters based on a preset division strategy, and the corresponding operation data stored in the target directory is obtained by writing the data to be stored into the corresponding target directory of the distributed file system according to the attribute parameters, and the data to be stored is obtained by performing data peak shaving on the operation data through a message queue.
12. A computer device, characterized in that: The device includes a processor and a memory; The memory is used to store computer programs; The processor is used to execute the energy storage device scheduling method described in any one of claims 1 to 6, or the model management method described in any one of claims 7 to 9 according to the computer program.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used for the energy storage device scheduling method described in any one of claims 1-6, or the model management method described in any one of claims 7-9.
Citation Information
Patent Citations
Passenger travel data ad-hoc query system and method
CN105550351A
An offline real-time data processing method and system based on a big data framework
CN108984610A
Distributed message processing method and system
CN114138520A
Data transmission method and streaming data transmission system
CN115473858A
