CN115269654A - Data cache supplementing method, device, equipment and medium - Google Patents

Data cache supplementing method, device, equipment and medium Download PDF

Info

Publication number
CN115269654A
CN115269654A CN202210910263.0A CN202210910263A CN115269654A CN 115269654 A CN115269654 A CN 115269654A CN 202210910263 A CN202210910263 A CN 202210910263A CN 115269654 A CN115269654 A CN 115269654A
Authority
CN
China
Prior art keywords
query
time period
cache data
cache
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210910263.0A
Other languages
Chinese (zh)
Inventor
吴溢豪
苏泽峰
苏贵生
李良伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianyi Cloud Technology Co Ltd
Original Assignee
Tianyi Cloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianyi Cloud Technology Co Ltd filed Critical Tianyi Cloud Technology Co Ltd
Priority to CN202210910263.0A priority Critical patent/CN115269654A/en
Publication of CN115269654A publication Critical patent/CN115269654A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • G06F16/24554Unary operations; Data partitioning operations

Abstract

The application provides a data cache supplementing method, a device, equipment and a medium, wherein the data cache supplementing method comprises the steps of analyzing a first query statement of a user to obtain a first index segment; judging whether cache data matched with the first query statement exists or not; if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not; if the cache data matched with the first index segment exists and the query time period of the cache data does not completely contain the query time period of the first query statement, acquiring the original data corresponding to the first query statement and supplementing the query time period of cache data missing in the cache data cluster. Because the query time period of cache data missing can be supplemented in the cache data cluster, a new query statement of a user is more prone to be matched with the cache data, the query pressure on the original data can be reduced, and the data query speed can be improved.

Description

Data cache supplementing method, device, equipment and medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a data cache replenishment method, apparatus, device, and medium.
Background
The Prometheus is widely applied to resource monitoring under the cloud native background, the monitoring data shows geometric growth speed, the response speed is very low when a user uses a query statement to query data often along with the increase of the monitoring data volume, the query data often times out, and the Prometheus service is down.
Prometheus provides a method for establishing a record rule, which can simplify complex query, but only provides a predefined rule at present, and query time is still long when data query is performed.
Disclosure of Invention
The embodiment of the application provides a data cache supplementing method, device, equipment and medium, which are used for improving the speed of data query in Prometous.
In a first aspect, an embodiment of the present application provides a data cache replenishment method, where the method includes:
analyzing a first query statement of a user to obtain a first index segment;
judging whether cache data matched with the first query statement exists or not based on cache data in the cache data cluster;
if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not;
if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment;
if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period of the cache data missing in the cache data cluster;
wherein the query time period of the cache data missing is a query time period in which the query time period of the first query statement is not within the query time period of the cache data.
Optionally, the analyzing the first query statement of the user to obtain the first index segment includes:
filtering indexes in the first query statement based on the first query statement of the user and existing recording rules in the cache data cluster to obtain a filtered first query statement;
and performing fragment extraction on the filtered first query statement based on a grammar rule to obtain a first index fragment.
Optionally, after determining whether there is cache data matching the first query statement based on the cache data in the cache data cluster, the method further includes:
if the cache data matched with the first query statement exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first query statement;
if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period of the cache data missing in the cache data cluster.
Optionally, after determining whether the query time period of the cached data completely includes the query time period of the first query statement, the method further includes:
if the query time period of the cache data completely contains the query time period of the first query statement, and the query time period of the cache data is equal to the query time period of the first query statement, obtaining cache interface data corresponding to the first query statement; or
If the query time period of the cache data completely comprises the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule, and acquiring the cache index segment recombined data.
Optionally, after determining whether there is cache data matching with the first indicator segment, the method further includes:
if the cache data matched with the first index segment does not exist, obtaining the original data corresponding to the first query statement, and supplementing the first index segment in the cache data cluster.
Optionally, after determining whether the query time period of the cache data completely contains the query time period of the first query statement, the method further includes:
if the query time period of the cache data completely comprises the query time period of the first query statement and the query time period of the cache data is equal to the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a calculation rule, and acquiring the cache index segment recombined data; or
If the query time period of the cache data completely contains the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule and a calculation rule, and acquiring the cache index segment recombined data.
In a second aspect, an embodiment of the present application further provides a data cache supplementing apparatus, including:
the analysis unit is used for analyzing a first query statement of a user to obtain a first index segment;
the judging unit is used for judging whether cache data matched with the first query statement exists or not based on the cache data in the cache data cluster; if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not; if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment;
the acquisition supplementing unit is used for acquiring original data corresponding to the first query statement and supplementing the query time period of the cache data missing in the cache data cluster if the query time period of the cache data does not completely contain the query time period of the first query statement; wherein the query time period of the cache data missing is a query time period in which the query time period of the first query statement is not within the query time period of the cache data.
Optionally, the parsing unit is specifically configured to:
filtering indexes in the first query statement based on the first query statement of the user and existing recording rules in the cache data cluster to obtain a filtered first query statement;
and extracting the fragments of the filtered first query statement based on a grammar rule to obtain a first index fragment.
Optionally, the determining unit is further configured to:
if the cache data matched with the first query statement exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first query statement; the acquisition replenishment unit is further configured to:
if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period of the cache data missing in the cache data cluster.
Optionally, the obtaining supplement unit is further configured to:
if the query time period of the cache data completely contains the query time period of the first query statement, and the query time period of the cache data is equal to the query time period of the first query statement, obtaining cache interface data corresponding to the first query statement; or
If the query time period of the cache data completely comprises the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule, and acquiring the cache index segment recombined data.
Optionally, the obtaining supplement unit is further configured to:
if the cache data matched with the first index segment does not exist, obtaining the original data corresponding to the first query statement, and supplementing the first index segment in the cache data cluster.
Optionally, the obtaining supplement unit is further configured to:
if the query time period of the cache data completely comprises the query time period of the first query statement and the query time period of the cache data is equal to the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a calculation rule, and acquiring the cache index segment recombined data; or
If the query time period of the cache data completely contains the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule and a calculation rule, and acquiring the cache index segment recombined data.
In a third aspect, the present application further provides an electronic device, including:
a memory for storing program instructions;
a processor for calling the program instructions stored in the memory and executing the steps comprised in the method of any one of the first aspect according to the obtained program instructions.
In a fourth aspect, the present application also provides a computer readable storage medium having stored thereon a computer program comprising program instructions which, when executed by a computer, cause the computer to perform the method of any one of the first aspects.
In a fifth aspect, the present application provides a computer program product comprising: computer program code which, when run on a computer, causes the computer to perform the method of any of the first aspects.
The embodiment of the application provides a data cache supplementing method, a device, equipment and a medium, wherein the data cache supplementing method comprises the steps of analyzing a first query statement of a user to obtain a first index segment; judging whether cache data matched with the first query statement exists or not based on the cache data in the cache data cluster; if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not; if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment; if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period with cache data missing in the cache data cluster. Because the query time period of cache data missing can be supplemented in the cache data cluster, a new query statement of a user is more prone to be matched with the cache data, the query pressure on the original data can be reduced, and the data query speed can be improved.
Drawings
In order to more clearly explain the technical solutions of the present application, the drawings required for the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic flow chart of a data cache replenishment method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a process for filtering an index according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of two types of cache data according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of reading time range selection according to an embodiment of the present invention;
fig. 5 is a schematic diagram illustrating the complete steps of a data cache replenishment method according to an embodiment of the present invention;
fig. 6 is a schematic diagram illustrating cache contents of a query statement according to an embodiment of the present invention;
fig. 7a is a schematic diagram of cached content of an indicator segment according to an embodiment of the present invention;
FIG. 7b is a diagram illustrating another example of the cached content of the indicator segment according to the embodiment of the present invention;
fig. 8 is a structural diagram of a Prometheus-based cache device according to an embodiment of the present disclosure;
fig. 9 is a structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions in the embodiments of the present application will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application. In the present application, the embodiments and features of the embodiments may be arbitrarily combined with each other without conflict. Also, while a logical order is shown in the flow diagrams, in some cases, the steps shown or described may be performed in an order different than here.
The terms "first" and "second" in the description and claims of the present application and the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the term "comprises" and any variations thereof, which are intended to cover non-exclusive protection. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus. The "plurality" in the present application may mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.
In the technical scheme, the data acquisition, transmission, use and the like all meet the requirements of relevant national laws and regulations.
Before describing a data cache supplementing method provided by the embodiment of the present application, for convenience of understanding, first, a technical background of the embodiment of the present application is described in detail below.
With the increase of the scale of the cloud computing cluster, the deployment of the K8S-based cloud native components is well developed, and Prometheus is widely applied to monitoring resources in the cloud native background. With the large deployment of containerization, the monitoring data shows a geometric growth speed, and the problems of preprocessing labels and data storage on the raw data pose great challenges to the promemeus tool. Monitoring the increase of data volume, the conditions that Query data is overtime, and a hydrometheus service is down due to slow Query frequently occur, and Query business needs to be optimized to enable the service to be more stable.
Among other things, prometheus' own logging rules allow us to pre-compute expressions that often need to be used or computed and save their results as a new set of data, querying pre-computed results is usually much faster than executing the original expressions each time it is needed, and is very effective for structured similar query statements. When a large number of similar, complex and structured queries are encountered, aggregation is performed from original data, which affects query efficiency, prometheus provides a method for establishing a record rule, which can simplify the complex query, but only provides a predefined rule at present, which is a fixed rule preset and is not flexible, and query efficiency of data is low.
In order to increase the speed of data query, an embodiment of the present invention provides a data cache replenishment method, as shown in fig. 1, where the method includes:
s101, analyzing a first query statement of a user to obtain a first index segment;
s102, judging whether cache data matched with the first query data exist or not based on the cache data in the cache data cluster;
s103, if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not;
s104, if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment;
s105, if the query time period of the cache data does not completely contain the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period with cache data missing in the cache data cluster; and the query time period of cache data missing is the query time period of the first query statement which is not in the query time period of the cache data.
The embodiment of the application provides a data cache supplementing method, which comprises the steps of analyzing a first query statement of a user to obtain a first index segment; judging whether cache data matched with the first query statement exists or not based on the cache data in the cache data cluster; if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not; if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment; if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period with cache data missing in the cache data cluster. Because the query time period of cache data missing can be supplemented in the cache data cluster, a new query statement of a user is more prone to be matched with the cache data, the query pressure on the original data can be reduced, and the data query speed can be improved.
The data cache supplementing method provided by the embodiment of the application can dynamically generate the record rule by identifying the index segment in the query statement of the user, thereby guiding the query process to hit the cache data, reducing the query pressure on the original data and improving the data query speed. The cache data hit means matching with the cache data, and specifically includes two situations, namely, matching of a first query statement of a user with the cache data and matching of a first index segment with the cache data, where matching of the first query statement with the cache data means that a second query statement identical to the first query statement exists in the cache data, and matching of the first index segment with the cache data means that a second index segment identical to the first index segment exists in the cache data. When the first index fragments are multiple, only the cache data has all the first index fragments to be matched, and if only parts of the index fragments exist, the first index fragments cannot be matched, namely the index fragments cannot be hit.
The system mainly comprises five modules, including a web service module, a cache hit judgment module, a PromQL time range judgment module, a cache Prometous module and a basic Prometous module, wherein the modules have the following functions:
the web service module: and receiving a PromQL statement query with a time range, namely a first query statement of a user, wherein the specific parameter format is similar to that of Prometheus external API/API/v1/query _ range.
A cache hit judgment module: and judging whether the first index segment obtained by analysis in the first query statement hits the cache or not, and replacing the first index segment into a cache index name.
And a PromQL time range judging module: and according to the specific time sequence attribute of the data, making related data processing logic including splicing, intercepting and the like.
Cache Prometheus module: corresponding to the name of the cache index in the cache database, providing statement query after the original PromQL statement is converted into the cache index.
Basic Prometheus module: a raw data query is provided.
For convenience of understanding, the present solution is described below with a simple mathematical expression, when a user uses Prometheus to perform data query by using a query statement, the Prometheus caches the corresponding query statement and indicator segment, for example, the following statements are included in a current cached data cluster: a + b 8: a 8; wherein a + b represents a query statement, a and b are respectively index segments, and 8.
When a user uses Prometheus again to perform data query, a first query statement used is a × b 7-9, where a × b and a + b are not the same and represent that the first query statement does not hit the cache data (the first query statement does not match the cache data), but both index segments a and b exist in the cache data, so that the first index segment hits the cache data, and then the query time period is compared, the query time period in the cache data is 8 00-12, and the query time period of the first query statement is 7-00, both belong to a partial overlapping relationship, that is, the query time period of the cache data does not completely include the query time period of the first query statement, then the original data corresponding to the first query statement is obtained at this time, and is queried and returned from the original data, and the time period of the cache data missing is 7:00-8, 00, then the content included in the cache data cluster may be expanded as follows: a + b 8: a 7.
In specific implementation, analyzing a first query statement of a user to obtain a first index segment includes: filtering indexes in the first query statement based on the first query statement of the user and existing recording rules in the cache data cluster to obtain a filtered first query statement; and performing fragment extraction on the filtered first query statement based on a grammar rule to obtain a first index fragment.
For example, the first query statement of the user is as follows:
Figure BDA0003773768390000101
in general, a single index exists in the PromQL statement, and a plurality of indexes appear in a complex query, for example, a metric1 and a metric2 exist in the above example, and operations such as + on (), group _ right () and the like are performed.
As shown in fig. 2, the corresponding index is filtered by using the original index name and the existing record rule in the cache, and then the relevant aggregation granularity and index name are extracted according to the grammar rule to form a PromQL grammar fragment. The grammar rules are mainly as follows:
agg_fun by(label)metric1{label="xxx"}[tm]
for the description of the syntax rule above to describe the index metric1, label filtering is first performed to obtain label = "xxx", then the granularity of t minutes of the data is extracted, the data is grouped according to label, and finally aggregation is performed using an agg _ fun function.
The relevant attributes of the query statement can thus be obtained, as shown in table 1:
TABLE 1
Index name metric1
Label (R) label="xxx"
Dimension of time [t]
Aggregation function agg_fun
Polymeric labels label
In the present application, the emphasis is on the metric1 and the time dimension t.
In conclusion, the PromQL is extracted according to a certain grammar rule to obtain a basic index segment. The data extraction result from table 1 is shown in table 2, and then the indicator segment is synchronized into the cache Prometheus in a recording rule manner, and the same indicator segment is obtained after the next query statement is analyzed, so that the hit cache data can be preliminarily determined.
TABLE 2
Figure BDA0003773768390000111
Figure BDA0003773768390000121
In a specific implementation, after judging whether there is cache data matching the first query statement based on the cache data in the cache data cluster, the method further includes:
if the cache data matched with the first query statement exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first query statement; "fully inclusive" means both "greater than" and "equal to," for example if the query time period for the cached data is 8:00-10, the query time period of the first query statement is 8:00-9, this is "greater than", if the query time period of the cached data is 8:00-10, the query time period of the first query statement is 8:00-10, this is "equal", and both cases are "fully inclusive".
If the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period with cache data missing in the cache data cluster.
For example, caching data includes: a + b 8; as another example, caching data includes: a + b 8.
In a specific implementation, after determining whether the query time period of the cache data completely includes the query time period of the first query statement, the method further includes:
if the query time period of the cache data completely contains the query time period of the first query statement, and the query time period of the cache data is equal to the query time period of the first query statement, obtaining cache interface data corresponding to the first query statement, which is equivalent to the fact that the first query statement completely hits the cache data, directly querying the cache interface data and returning the cache interface data; or
If the query time period of the cache data completely includes the query time period of the first query statement, and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule, and acquiring the cache index segment recombined data, where for example, the cache data includes: a + b 8.
In a specific implementation, after determining whether there is cache data matching the first indicator segment, the method further includes: if there is no cache data matching the first index segment, obtaining original data corresponding to the first query statement, and supplementing the first index segment in the cache data cluster, where this is equivalent to that both the index segment and the query statement fail to hit, for example, the cache data includes: a + b 8.
In a specific implementation, after determining whether the query time period of the cache data completely includes the query time period of the first query statement, the method further includes:
if the query time period of the cache data completely includes the query time period of the first query statement, and the query time period of the cache data is equal to the query time period of the first query statement, the cache data is converted into cache index segment restructuring data according to the calculation rule, and the cache index segment restructuring data is obtained, for example, the cache data includes: a + b 8:00-10 and b 8; or
If the query time period of the cache data completely includes the query time period of the first query statement, and the query time period of the cache data is greater than the query time period of the first query statement, the cache data is converted into cache index segment restructuring data according to the time rule and the calculation rule, and the cache index segment restructuring data is obtained, for example, the cache data includes: a + b 8:00-9 and b 8-00, when the first query statement misses the cache data, but the first index fragment hits the cache data, when a 8.
For the following detailed description, as shown in fig. 3, the data format in the cache data cluster is mainly in a key-value form, where the key is a query statement (second query statement) with a time range or an extracted indicator fragment (second indicator fragment), and for the case where the key is a query statement, the value content is data such as interface return; for extracting the indicator segment, value is the name of the indicator of the recording rule of the indicator segment in the cache Prometheus, that is, the recombination data of the cache indicator segment. The cache matching rule is a key and time range comparison, and the situation as shown in table 3 may occur:
TABLE 3
Figure BDA0003773768390000141
Case a: the key is a query statement, and the query time period of the cache data is greater than the query time period of the first query statement.
At the moment, the cache data are converted into cache index segment recombination data according to a time rule, and the cache index segment recombination data are obtained.
Case B: the key is an index segment, and the query time period of the cache data is greater than the query time period of the first query statement.
At the moment, the cache data are converted into cache index segment recombined data according to a time rule and a calculation rule, and the cache index segment recombined data are obtained.
Case C: the key is a query statement, and the query time period of the cache data is equal to the query time period of the first query statement.
And at the moment, directly acquiring the cache interface data corresponding to the first query statement.
Case D: the key is an index segment, and the query time period of the cache data is equal to the query time period of the first query statement.
At the moment, the cache data are converted into cache index segment recombination data according to a calculation rule, and the cache index segment recombination data are obtained.
Case E: the key is a query statement, and the query time period of the cache data does not completely contain the query time period of the first query statement.
At the moment, original data corresponding to the first query statement is obtained, and a query time period of cache data missing is supplemented in the cache data cluster;
as shown in fig. 4, for example, the buffer time range is [ 9-11 ] and the query time range is [ 8-00-12 ], then the data2 of [ 8.
Case F: the key is an index segment, and the query time period of the cache data does not completely contain the query time period of the first query statement.
At this time, the original data corresponding to the first query statement is obtained, and the query time period of cache data missing is supplemented in the cache data cluster.
If the cache data is not hit, that is, there is neither cache data matching the first query statement nor cache data matching the first index segment in the cache data cluster, the original data corresponding to the first query statement is obtained, and the first index segment is supplemented in the cache data cluster.
In specific implementation, for the above situations, it is necessary to guarantee the update of the cached data and the data operation in the cache promemeus. Updating aiming at cache data: because the records of the time range are added in the cache database, the use times of different time ranges can be used as the updating basis of the LRU algorithm. For cache Prometheus data operation: and (4) writing back data by using tools such as Promtool and the like, and establishing related recording rules.
The complete steps of a data cache replenishment method provided by the embodiment of the present application are shown in fig. 5.
S501, analyzing a first query statement of a user to obtain a first index segment;
s502, judging whether the first query statement is matched with the cache data; if yes, executing S508, if no, executing S503;
s503, judging whether the first index segment is matched with the cache data; if yes, executing S504, otherwise executing S507;
s504, judging whether the query time period of the cache data matched with the first index segment completely contains the query time period of the first query statement; if yes, executing S506, otherwise executing S505;
s505, acquiring original data corresponding to the first query statement, and supplementing a missing time period of cache data matched with the first index segment into a cache data cluster;
s506, if the query time period of the cache data is equal to the query time period of the first query statement, acquiring cache index segment recombined data converted according to a time rule; if the query time period of the cache data is longer than that of the first query statement, acquiring cache index segment recombined data converted according to the time rule and the calculation rule;
s507, acquiring original data, and supplementing a first index segment in the cache data cluster;
s508, judging whether the query time period of the cache data matched with the first query statement completely contains the query time period of the first query statement; if yes, executing S509, otherwise executing S510;
s509, if the query time period of the cache data is equal to the query time period of the first query statement, obtaining cache interface data corresponding to the first query statement; if the query time period of the cache data is longer than that of the first query statement, acquiring cache index segment recombined data converted according to a time rule;
and S510, acquiring original data, and supplementing the missing time period of the cache data matched with the first query statement into the cache data cluster.
In the application, the idea of dynamically recording rules and time range mapping data is provided to solve the problem of low speed when a large number of frequent similar query sentences are queried. The main implementation principle of the cache is that a recording rule is dynamically established in cache data according to the index segments by analyzing query statements, and the corresponding relation between the index segments and the cache recording rule is recorded in a cache database. When a new query request comes, whether the data is hit or not is judged firstly, if yes, the data is calculated and returned from the cache data, otherwise, the data is queried from the original data, the data which is not hit in the cache is synchronized, and the query speed is improved by increasing the cache in the middle.
In addition, by introducing the idea of dynamically establishing the recording rule, the method and the device can greatly improve the ability of Prometheus to provide query services to the outside under the condition of a large number of similar complex queries only by increasing part of storage space and calculation power, and ensure the stability of the components. An idea can be provided for similar time sequence database caching, except that a time dimension and index data are used as a cache index key, dimensions such as a label and an aggregation function are considered, and the cache key is reasonably customized according to different use scenes.
The process of the present application is described in detail below with specific examples:
for example, there are the following servers:
a certain trunk of a Prometheus server, PQ1 and PQ2 query servers, 8230;
caching a Prometheus server P1;
a Web application server W1;
cache hit algorithm server Cache1.
1. The web server W1 receives the external query statement parameters, and executes the grammar parser to obtain index fragment data.
For example, where the original query statement is:
round (sky by (lap 1, lap 2) (incrase (metric 1{ lap 1= "machine 1", lap 2= "address 1", lap 3= "online" } [1m ])) or vector (0) + on () group _ right () incrase (metric 2{ lap 1= "machine 2", lap 2= "address 2", lap 3= "ofline" } [1m ])), 1.0).
Two index fragments obtained by extraction are respectively:
fragment 1: incrase (metric 1{ label1= "machine 1", label2= "address 1", label3= "online" } [1m ];
fragment 2: incrase (metric 2{ label1= "machine 2", label2= "address 2", label3= "offline" } [1m ]).
Then the converted PromQL is:
round(sum by(lable1,label2)rule1 or vector(0)+on()group_right()rule2),1.0);
where rule1 represents segment 1 and rule2 represents segment 2.
2. The cache hit algorithm server reads cache data and judges whether the query hits the cache, wherein the content of the cache database at this time is as follows:
the cache contents of the query statement are shown in fig. 6, and the cache contents of the indicator segment are shown in fig. 7a and 7 b.
The process of processing when several queries are made is:
(1) Query time 2022.02.01 9:
round (Sum by (able 1, label 2) (incrase (metric 1{ label1= "machine 1", label2= "address 1", label3= "online" } [1m ]) or vector (0) + on () group _ right () incrase (metric 2{ label1= "machine 2", label2= "address 2", label3= "ofline" } [1m ])), 1.0)
Hit 2022.02.01.8 among them, 00-10, then corresponding to the query request here, the converted statement with record rule will be executed on the cache P1:
round(sum by(lable1,label2)rule1 or vector(0)+on()group_right()rule2),1.0)
at this time, the obtained data can be directly returned.
(2) Query time 2022.02.01 9, 00, query statement Q2:
round (sky by (lap 1, lap 2) (incrasse (metric 1{ lap 1= "machine 1", lap 2= "address 1", lap 3= "online" } [1m ])) or vector (0) + on () group _ right () incrasse (metric 3{ lap 1= "machine 1", lap 2= "address 1", lap 3= "ofline" } [1m ])), 1.0);
the resulting fragments were: incrase (metric 1{ label1= "machine 1", label2= "address 1", label3= "online" } [1m ])
incrase (metric 3{ label1= "machine 1", label2= "address 1", label3= "offline" } [1m ])
The index fragment meter 1 hits in the cache data, the meter 3 fails to hit, the query statement is queried from PQ1 and PQ2 and the result is returned, and then the data needs to be synchronized from the query servers PQ1 and PQ2 to the cache server P1. At this time, the index fragment cache of the metric3 and the cache data of the whole query statement Q2 are also added to the cache database.
(3) Query time 2022.02.01 8:
round (label 1, label 2) (incrasse (metric 1{ label1= "machine 1", label2= "address 1", label3= "online" } [1m ]) or vector (0) + on () group _ right () incrase (metric 2{ label1= "machine 2", label2= "address 2", label3= "ofloline" } [1m ])), 1.0)
And completely hitting 2022.02.01 to 20200-10, and acquiring interface data corresponding to the query statement in the cache database.
(4) Query time 2022.02.01 8:
round (label 1, label 2) (incrasse (metric 1{ label1= "machine 1", label2= "address 1", label3= "online" } [1m ]) or vector (0) + on () group _ right () incrase (metric 2{ label1= "machine 2", label2= "address 2", label3= "ofloline" } [1m ])), 1.0)
When the index fragments Metric1_1m _1649056699and Metric2_1m _1649056699are hit, the time range is 2022.02.01.
(5) Query time 2022.02.01:
round (sum by (label 1, label 2) (increate (metric 1{ label1= "machine 1", label2= "address 1", label3= "online" } [1m ]) or vector (0) + on () group _ right () increate (metric 2{ label1= "machine 2", label2= "address 2", label3= "offline" } [1m ])), 1.0)
If the query statement is hit, but the time range exceeds the cache range, the Q1 statement is queried from the original data PQ1, PQ2 and the like, and the data with the time range of 10. And newly adding the time range of the Q1 in the cache database, and synchronizing the time range data corresponding to the contained index fragment to the cache server P1.
Based on the same inventive concept, an embodiment of the present application further provides a Prometheus caching apparatus, please refer to fig. 8, the apparatus includes:
an analyzing unit 801, configured to analyze a first query statement of a user to obtain a first index segment;
a determining unit 802, configured to determine whether there is cache data matched with the first query statement based on cache data in the cache data cluster; if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not; if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment;
an obtaining and supplementing unit 803, configured to obtain, if the query time period of the cache data does not completely include the query time period of the first query statement, the original data corresponding to the first query statement, and supplement, in the cache data cluster, the query time period in which the cache data is missing; wherein the query time period of the cache data missing is a query time period in which the query time period of the first query statement is not within the query time period of the cache data.
Optionally, the parsing unit 801 is specifically configured to:
filtering indexes in the first query statement based on the first query statement of the user and existing recording rules in the cache data cluster to obtain a filtered first query statement;
and performing fragment extraction on the filtered first query statement based on a grammar rule to obtain a first index fragment.
Optionally, the determining unit 802 is further configured to:
if the cache data matched with the first query statement exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first query statement; the acquisition replenishment unit is further configured to:
if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period of the cache data missing in the cache data cluster.
Optionally, the obtaining and supplementing unit 803 is further configured to:
if the query time period of the cache data completely contains the query time period of the first query statement, and the query time period of the cache data is equal to the query time period of the first query statement, obtaining cache interface data corresponding to the first query statement; or
If the query time period of the cache data completely comprises the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule, and acquiring the cache index segment recombined data.
Optionally, the obtaining and supplementing unit 803 is further configured to:
if the cache data matched with the first index segment does not exist, obtaining original data corresponding to the first query statement, and supplementing the first index segment in the cache data cluster.
Optionally, the obtaining and supplementing unit 803 is further configured to:
if the query time period of the cache data completely comprises the query time period of the first query statement and the query time period of the cache data is equal to the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a calculation rule, and acquiring the cache index segment recombined data; or
If the query time period of the cache data completely contains the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule and a calculation rule, and acquiring the cache index segment recombined data.
Based on the same inventive concept, the embodiment of the present application provides an electronic device, which can implement the functions of the foregoing Prometheus data cache supplement method, please refer to fig. 9, and the device includes a processor 901 and a memory 902.
Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, and a computer program product includes: computer program code which, when run on a computer, causes the computer to perform any of the data cache replenishment methods as discussed above. Because the principle of solving the problem of the computer-readable storage medium is similar to the data cache supplementing method, the implementation of the computer-readable storage medium can refer to the implementation of the method, and repeated details are not repeated.
Based on the same inventive concept, the embodiment of the present application further provides a computer program product, where the computer program product includes: computer program code which, when run on a computer, causes the computer to perform any of the data cache replenishment methods as discussed above. Because the principle of solving the problems of the computer program product is similar to that of the data cache supplementing method, the implementation of the computer program product can refer to the implementation of the method, and repeated details are not repeated.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of user-operated steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for supplementing a data cache, comprising:
analyzing a first query statement of a user to obtain a first index segment;
judging whether cache data matched with the first query statement exists or not based on cache data in the cache data cluster;
if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not;
if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment;
if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period of the cache data missing in the cache data cluster;
and the query time period of the cache data missing is the query time period when the query time period of the first query statement is not in the query time period of the cache data.
2. The method of claim 1, wherein parsing the first query statement of the user to obtain a first index fragment comprises:
filtering indexes in the first query statement based on the first query statement of the user and existing recording rules in the cache data cluster to obtain a filtered first query statement;
and performing fragment extraction on the filtered first query statement based on a grammar rule to obtain a first index fragment.
3. The method of claim 1, wherein after determining whether there is cached data matching the first query statement based on cached data in the cached data cluster, further comprising:
if the cache data matched with the first query statement exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first query statement;
if the query time period of the cache data does not completely include the query time period of the first query statement, acquiring original data corresponding to the first query statement, and supplementing the query time period of the cache data missing in the cache data cluster.
4. The method of claim 3, wherein after determining whether the query time period of the cached data completely contains the query time period of the first query statement, further comprising:
if the query time period of the cache data completely contains the query time period of the first query statement, and the query time period of the cache data is equal to the query time period of the first query statement, obtaining cache interface data corresponding to the first query statement; or
If the query time period of the cache data completely contains the query time period of the first query statement, and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombination data according to a time rule, and acquiring the cache index segment recombination data.
5. The method of claim 1, wherein determining whether there is cached data matching the first metric segment further comprises:
if the cache data matched with the first index segment does not exist, obtaining the original data corresponding to the first query statement, and supplementing the first index segment in the cache data cluster.
6. The method of claim 1, wherein after determining whether the query time period of the cached data completely contains the query time period of the first query statement, the method further comprises:
if the query time period of the cache data completely contains the query time period of the first query statement and the query time period of the cache data is equal to the query time period of the first query statement, converting the cache data into cache index segment recombination data according to a calculation rule and acquiring the cache index segment recombination data; or
If the query time period of the cache data completely contains the query time period of the first query statement and the query time period of the cache data is greater than the query time period of the first query statement, converting the cache data into cache index segment recombined data according to a time rule and a calculation rule, and acquiring the cache index segment recombined data.
7. A data cache replenishment apparatus, comprising:
the analysis unit is used for analyzing a first query statement of a user to obtain a first index segment;
the judging unit is used for judging whether cache data matched with the first query statement exists or not based on the cache data in the cache data cluster; if the cache data matched with the first query statement does not exist, judging whether the cache data matched with the first index segment exists or not; if the cache data matched with the first index segment exists, judging whether the query time period of the cache data completely contains the query time period of the first query statement or not aiming at the cache data matched with the first index segment;
the acquisition supplementing unit is used for acquiring original data corresponding to the first query statement and supplementing the query time period of the cache data missing in the cache data cluster if the query time period of the cache data does not completely contain the query time period of the first query statement; wherein the query time period of the cache data missing is a query time period in which the query time period of the first query statement is not within the query time period of the cache data.
8. An electronic device, comprising:
a memory for storing program instructions;
a processor for calling program instructions stored in said memory and for executing the steps comprised in the method of any one of claims 1 to 6 in accordance with the obtained program instructions.
9. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program comprising program instructions that, when executed by a computer, cause the computer to perform the method according to any one of claims 1-6.
10. A computer program product, the computer program product comprising: computer program code which, when run on a computer, causes the computer to perform the method according to any of the preceding claims 1-6.
CN202210910263.0A 2022-07-29 2022-07-29 Data cache supplementing method, device, equipment and medium Pending CN115269654A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210910263.0A CN115269654A (en) 2022-07-29 2022-07-29 Data cache supplementing method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210910263.0A CN115269654A (en) 2022-07-29 2022-07-29 Data cache supplementing method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN115269654A true CN115269654A (en) 2022-11-01

Family

ID=83747194

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210910263.0A Pending CN115269654A (en) 2022-07-29 2022-07-29 Data cache supplementing method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN115269654A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117472293A (en) * 2023-12-27 2024-01-30 荣耀终端有限公司 Data storage method, electronic equipment and computer readable storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117472293A (en) * 2023-12-27 2024-01-30 荣耀终端有限公司 Data storage method, electronic equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
CN106897322B (en) A kind of access method and device of database and file system
US8825581B2 (en) Simplifying a graph of correlation rules while preserving semantic coverage
US10922133B2 (en) Method and apparatus for task scheduling
CN106293891B (en) Multidimensional investment index monitoring method
US10789232B2 (en) Method and system for generating a query plan for time series data
CN110134517A (en) A kind of parallel calculating method and device based on Formula Parsing
CN115269654A (en) Data cache supplementing method, device, equipment and medium
CN111666344A (en) Heterogeneous data synchronization method and device
CN114817651A (en) Data storage method, data query method, device and equipment
CN110633318A (en) Data extraction processing method, device, equipment and storage medium
CN113767403B (en) Automatic resolution of over-and under-designations in knowledge graphs
CN112883088B (en) Data processing method, device, equipment and storage medium
CN106557483A (en) A kind of data processing, data query method and apparatus
CN113010542A (en) Service data processing method and device, computer equipment and storage medium
CN117093619A (en) Rule engine processing method and device, electronic equipment and storage medium
CN110222046B (en) List data processing method, device, server and storage medium
US9576004B1 (en) Free space management in databases
CN111522918A (en) Data aggregation method and device, electronic equipment and computer readable storage medium
CN113792232B (en) Page feature calculation method, page feature calculation device, electronic equipment, page feature calculation medium and page feature calculation program product
CN114356712A (en) Data processing method, device, equipment, readable storage medium and program product
CN113326407A (en) Data processing method and device
CN113868138A (en) Method, system, equipment and storage medium for acquiring test data
CN113342647A (en) Test data generation method and device
CN112162951A (en) Information retrieval method, server and storage medium
CN109739883A (en) Promote the method, apparatus and electronic equipment of data query performance

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination