A method and system for managing index partitions for time series data
Through the index partition management method for time series data, time series data is managed in partitions according to the time dimension and out-of-sequence data processing is optimized, which solves the problem of low efficiency of time series database index management in the existing technology and realizes efficient query analysis and index management. It is applicable Suitable for complex queries and time series data applications with large amounts of data.
Patent Information
- Application Number
- CN202111477748.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-06
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-12-06
AI Technical Summary
Existing time series databases have deficiencies in time series data index management and query analysis. In particular, they are inefficient when processing out-of-sequence data and cannot effectively support complex queries and large-volume time series data application scenarios.
Adopt an index partition management method for time series data, manage time series data by time dimension partition, and use the Time Detector component to determine the index partition to which the data belongs, use the IndexWriter object for index creation and query optimization, and retain the most recent writable and out-of-order cache index partitions To handle out-of-order data, regularly split and merge index data to improve query efficiency.
Significantly improves the efficiency of query analysis based on the time dimension, supports multiple index types and query types, is suitable for complex queries and large-volume time series data application scenarios, and maintains efficient index creation and query performance, especially in out-of-order data scenarios. outstanding.
Smart Images

Figure CN114428776B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of information technology, and in particular relates to an index partition management method and system for time series data. Background Art
[0002] With the development and popularization of the Internet, the amount of information on the network has exploded. Most data in practical applications have a common feature, which is time series, such as social media, smart home, surveillance cameras, Internet of Things and other data. Usually, the query of time series data is often limited to a certain time period, and the query and analysis of the full amount of time series data is not performed. At present, querying and analyzing various network data in the time dimension has become an important means to explore the potential value of cyberspace data.
[0003] Considering that the quality of time series data in real business scenarios is often uneven, data is often not indexed in chronological order. For example, hardware facility problems or network transmission problems in IoT applications can cause interruptions in the collection and transmission of time series data, resulting in varying degrees of disorder in the time series data. Disordered data not only affects the efficient management of time series data, but also has a great impact on the index management of time series data.
[0004] At present, time series database technology is widely used in time series data application scenarios, which can realize efficient organization and storage of time series data in the time dimension. However, the index function supported by time series database is limited, which leads to its limited query function and cannot effectively perform statistical analysis on time series data. Summary of the invention
[0005] In view of the shortcomings of existing time series data management technologies, the present invention proposes an index partition management method and system for time series data. The method manages the index of time series data in partitions in the time dimension, and optimizes the partition organization of the index for application scenarios with out-of-order data. When executing query analysis tasks within a specified time range, irrelevant index files can be quickly filtered out according to the time range, and query tasks can be completed by accessing only a small number of index disk files, thereby improving the efficiency of query analysis tasks based on the time dimension. At the same time, operations such as life cycle management such as migration and deletion of index data can be efficiently performed in units of time partitions.
[0006] The technical solution adopted by the present invention is as follows:
[0007] An index partition management method for time series data uses the following steps to create an index:
[0008] Encapsulate the necessary information for indexing each field in a time series data into a Document object;
[0009] According to the time value of the time series data, the index partition to which the index of the time series data belongs is determined based on the Time Detector component;
[0010] According to the start and end time of the index partition to which the time series data belongs, obtain the metadata information of the index partition and the IndexWriter object related to the index partition from the Time Partition Metadata component;
[0011] Use the IndexWriter object of the corresponding index partition to create an index for the data encapsulated in the Document object.
[0012] Optionally, the determining, based on the Time Detector component, to which index the time series data belongs, includes:
[0013] Two index partitions are reserved for writing index data, namely the most recently writable index partition and the out-of-order cache index partition, which are used to store the indexes of ordered data for most of the time and the indexes corresponding to some out-of-order data respectively;
[0014] The Time Detector component is used to determine whether the index of a time series data belongs to the most recent writable index partition or the out-of-order cache index partition. The Time Detector component maintains a most recent writable index partition based on the current time and the window size of the index partition. If the time value corresponding to a time series data belongs to the most recent writable index partition, the time series data is ordered; otherwise, the time series data is out-of-order, and its corresponding index is written to the out-of-order cache index partition.
[0015] Optionally, the most recently writable index partition is continuously updated in a rolling manner with the current time, and the index partitions whose time range is before the time range of the most recently writable index partition are read-only index partitions.
[0016] Optionally, the Time Partition Metadata component is responsible for maintaining metadata information of all index partitions; the metadata information of the index partitions is stored in a Map in memory, the key is composed of the start time and end time of the index partition, and the value includes the IndexWriter and IndexReader components of the index partition, the disk storage path of the index partition, and the amount of data indexed in the index partition; the Time Partition Metadata component is also responsible for the persistent storage of the index partition metadata information to avoid the loss of the index partition metadata information.
[0017] Optionally, the IndexWriter corresponding to the index time partition is used to perform an index creation operation on the data encapsulated in the Document object, including: first caching the index data in the memory, at which time the index data in the memory cannot be queried; then flushing the data in the memory to the disk to become an index file that can be queried.
[0018] Optionally, for the created index, use the following steps to query the index:
[0019] For index query tasks within a specified time range, first access the Time Partition Metadata component to filter out index partitions that intersect with the query time range;
[0020] For each index partition that intersects the query time range, a query object is constructed according to the query conditions, and then a thread is used to execute the index query subtask corresponding to the query object.
[0021] The subquery results of each index partition are first sorted locally by relevance, and then multiple subquery results are globally sorted and finally returned to the end user.
[0022] Optionally, the out-of-order index data of the out-of-order cache index partition is periodically split according to a time range, and the split index data is merged into a read-only index partition of a corresponding time range to prevent the out-of-order cache index partition from affecting query performance.
[0023] An index partition management system for time series data, comprising:
[0024] An index creation module, used to create an index according to the above method of the present invention;
[0025] The query index module is used to query the index according to the above method of the present invention.
[0026] The beneficial effects of the present invention are as follows:
[0027] 1. The index partition management method and system for time series data proposed in the present invention can be integrated with mainstream full-text indexing technologies such as Lucene to support multiple index types and query types.
[0028] 2. The index partition management method and system for time series data proposed in the present invention partitions the time series data index data in the time dimension. When executing the query analysis task within the specified time range, irrelevant index files can be quickly filtered out, greatly improving the query efficiency. At the same time, for historical data with poor timeliness, operations such as batch migration and deletion of index data and other life cycle management can be efficiently performed in units of index time partitions. It is suitable for time series data application scenarios with complex query types and large data volumes.
[0029] 3. The index partition management method and system for time series data proposed in the present invention optimizes the index partition management in processing disordered data indexes, and also maintains efficient index creation and index query performance in the application scenarios of disordered data. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a schematic diagram of the framework of the index partition management method proposed by the present invention.
[0031] Figure 2 It is a flow chart of creating an index in the index partition management method proposed by the present invention.
[0032] Figure 3 It is a query index flow chart of the index partition management method proposed by the present invention. DETAILED DESCRIPTION
[0033] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below through specific embodiments and drawings.
[0034] Figure 1 It is a framework diagram of the index partition management method proposed in the present invention. The index partition management method for time series data proposed in the present invention manages the index data by time partition, wherein each index partition is equivalent to a set of independent indexes, and each index partition has its own IndexWriter (index generator), IndexReader (index queryer) and other key functional components related to index creation, query, etc. The data in each index partition is ultimately stored in a separate folder. The metadata information of all index partitions, such as the start and end time of each index partition, the storage path of the index disk file in the index partition, etc., will be saved in the Time Partition Metadata component. Each time series data will have a time field value, and the Time Detector component will determine the index partition to which it belongs based on the time field value of the time series data, and then create an index under the index partition.
[0035] In addition, consider the application scenarios of out-of-order data. Each time index data is written to an index partition, it is first written to the memory, and then the index data in the memory is flushed to the disk. If the index data is managed by time partitions, creating indexes for out-of-order data will cause a large number of index time partitions to write index data at the same time, which will in turn cause a large number of index partitions to flush memory index data to disk and merge disk index files at the same time. As the number of index partitions increases, the efficiency of disk IO will become worse and worse, which will seriously affect the efficiency of index creation.
[0036] In order to alleviate the impact of disordered data on index creation and improve the efficiency of disk IO, the index partition management method proposed in the present invention uses a temporary index partition to temporarily store disordered index data, reducing the number of index partitions that need to access the disk when creating an index for disordered data. Since the time range of the index data contained in the temporary disordered index partition is uncertain, as the partition contains more and more index data, it will affect the query performance based on the time range to a certain extent. The index partition management method proposed in the present invention will regularly split the disordered index partition according to the time range, and merge the split index data back into the index partition of the corresponding time range. In this way, the impact of disordered data on index creation and query can be controlled.
[0037] According to the solution provided by the present invention, an index partition management method for time series data can be roughly divided into an index creation step and an index query step.
[0038] The process of creating an index is as follows Figure 2 As shown, it is divided into the following steps:
[0039] Step 1. For a time series data record containing multiple fields, you first need to determine the index type that needs to be created for each field, such as creating a full-text index for a text field, creating a numeric range index for a numeric field, and so on. Then encapsulate the index type of each field, the Boolean flag indicating whether the original value of the field needs to be additionally stored, the word segmenter required to create a full-text index, and other information into a Document object. If a field needs to store the original value of the field in addition to creating an index, the Boolean flag stored for the field is true. If a field needs to create a full-text index, the Document also includes a word segmenter for segmenting the field value.
[0040] Step 2: According to the time value of the time series data, the index partition to which the index of the time series data belongs is determined based on the Time Detector component.
[0041] Step 3. According to the start and end time of the index partition to which the time series data belongs, obtain the metadata information of the index partition and the IndexWriter object related to the index partition from the Time Partition Metadata component. If the index partition has not been created, create the index partition and save its metadata information in the Time Partition Metadata component.
[0042] Step 4. Use the IndexWriter object of the corresponding index partition to perform the actual index creation operation on the data encapsulated in the Document. The index data will first be cached in the memory, and the index data in the memory cannot be queried at this time. The data in the memory will then be flushed to the disk and become an index file that can be queried.
[0043] In step 2 above, considering the poor quality of time series data, it is necessary to create an index for some out-of-order data. In order to avoid writing index data to multiple index partitions at the same time in this scenario, which leads to the frequent refresh and merging of small disk index files for multiple index partitions, and to further improve the efficiency of each disk access, it is necessary to control the number of index partitions that can write index data at the same time. At the same time, considering the characteristics of time series data, most of the time series data currently written is still time-ordered, while out-of-order data accounts for only a relatively small part. When creating an index, only two index partitions that can write index data are retained, namely the most recently writable index partition and the out-of-order cache index partition, which are used to store the indexes of most time-ordered data and the indexes corresponding to some out-of-order data, respectively.
[0044] In step 2 above, whether the index of a time series data belongs to the most recent writable index partition or the random cache index partition, that is, whether a data is random or not, is determined by the Time Detector component. Time Detector will maintain a most recent writable index partition based on the current time and the window size of the index partition. If the time value corresponding to a time series data belongs to the most recent writable index partition, the time series data is ordered; otherwise, it is unordered, and its corresponding index should be written to the random cache index partition. For example, if the current time is May 17 and the index partition window size is 30 days, then the most recent writable index partition is from May 1 to May 30. If the time value of a time series data is between May 1 and May 30, its index will be written to the most recent writable index partition; otherwise, it will be written to the random cache index partition. The most recent writable index partition is continuously updated with the current system time. For example, if the current system time has reached May 31, then the time range of the new most recent writable time partition is from May 31 to June 29. The index partition with a time range between May 1 and May 30 becomes a read-only index partition (that is, except for the out-of-order cache index partition, which is used to write out-of-order data. For other index partitions, if the time range is before the time range of the most recently writable index partition, the index partition is a read-only index partition), and no index data will be written directly to the partition. When the most recently writable index partition rolls over to a read-only index partition, in order to improve the query performance of the read-only index partition, a merge operation will be performed on the underlying index files of the partition.
[0045] In step 3 above, the Time Partition Metadata component is responsible for maintaining the metadata information of all index partitions. The metadata information of index partitions is stored in a Map in memory. The key is composed of the start time and end time of the index partition, and the value includes the important index function components such as IndexWriter and IndexReader of the index partition, the disk storage path of the index partition, the amount of data indexed in the index partition, and other important information.
[0046] In step 3 above, in order to avoid the loss of index partition metadata information, the Time PartitionMetadata component is also responsible for persisting the index partition metadata information. When the index partition metadata information in memory is updated, the updated metadata information will be persisted to the disk file at the same time.
[0047] The process of querying the index is as follows Figure 3 As shown, it is divided into the following steps:
[0048] Step 1. For an index query task with a specified time range, first access the Time Partition Metadata component to filter out index partitions that intersect with the query time range.
[0049] Step 2. For each index partition that intersects with the query time range, build a Query object according to the query conditions, and then use a thread to execute the index query subtask corresponding to the Query object.
[0050] Step 3. Sort the subquery results of each index partition locally by relevance, then globally sort the multiple subquery results, and finally return them to the end user.
[0051] As mentioned above, in step 2, since the time range of the out-of-order index data contained in the out-of-order cache index partition is uncertain, this will cause the time range of the out-of-order cache index partition to be usually larger. Therefore, when executing a query within a specified time window range, the out-of-order cache index partition will usually intersect with the query time range. In order to prevent the out-of-order cache index partition from affecting query performance, it is necessary to control the number of indexes in the out-of-order cache index partition. To this end, the out-of-order index data of the out-of-order cache index partition will be periodically split according to the time range, and the split index data will be re-merged into the read-only index partition of the corresponding time range. In this way, the impact of introducing out-of-order cache index partitions on queries is alleviated.
[0052] In step 3 above, for each matching data in an index partition query sub-result, there is a score value for the relevance to the query condition. The matching data in each index partition sub-query result will first be sorted locally by relevance score, filtering out some irrelevant data. In order to make the most relevant data appear first in the final returned query result, it is also necessary to globally sort the query sub-results of all index partitions by relevance before returning them to the end user.
[0053] The key points of the present invention are:
[0054] 1. The index partition management method for time series data proposed in the present invention partitions the time series data index in the time dimension and optimizes the index partition management in terms of processing disordered data index. In the time series data scenario, it can provide efficient query analysis and index data management functions.
[0055] 2. The index partition management method for time series data proposed in the present invention mainly includes the following three functional components: The index time partition component is equivalent to a group of independent indexes, which is responsible for the persistent storage of index data. According to the characteristics of the index data in the index time partition, it can be specifically divided into the most recently writable index partition, the disordered cache index partition, and the read-only index partition. The Time Partition Metadata component is responsible for maintaining the metadata information of all index time partitions, and provides the access interface for querying indexes and creating indexes. The Time Detector component is responsible for determining the index time partition to which the time series data belongs based on the time field value of the time series data.
[0056] 3. The index partition management method for time series data proposed in the present invention mainly provides index creation and index query functions. When creating an index, first create a Document index object, then determine the index time partition to which the index data belongs based on the time value, then obtain the metadata information and IndexWriter object corresponding to the index partition, and finally perform the index creation operation through IndexWriter, and write the index to the corresponding index partition. When querying the index, first filter out the index partitions that have an intersection with the query time range, and then use a thread for each related index partition to execute the index query subtask of this partition, then locally sort and globally sort the subquery results of each index partition, and finally return the query results to the terminal user.
[0057] 4. The index partition management method for time series data proposed in the present invention introduces a special out-of-order cache index partition to temporarily save the index corresponding to the out-of-order data when creating the index. This can control the number of index partitions that can write index data at the same time, optimize disk efficiency, and improve index creation performance.
[0058] 5. The index partition management method for time series data proposed in the present invention will regularly split the out-of-order index data of the out-of-order cache index partition according to the time range, and merge the split index data into the read-only index partition of the corresponding time range, so as to alleviate the impact of introducing out-of-order cache index partitions on query performance.
[0059] In order to better express the index partition management method for time series data proposed in the present invention, the present invention is further explained below with reference to two functional processes of index creation and index query in combination with specific implementation examples.
[0060] Take Weibo data in social media data as an example. Since each Weibo data has its release time, it can be regarded as a kind of time series data. A Weibo data also contains other fields such as Weibo title, Weibo content, number of forwarded comments, etc. At the same time, assuming that the current system time is May 17, and the index time partition window size is 30 days, then the current latest writable partition time range is May 1 to May 30.
[0061] For the index creation process, we first create an index for a Weibo post published on May 16. In the first step, we create a full-text index for the Weibo title and Weibo content fields, and create a numerical range index for the Weibo forwarding comment count and publishing time fields, and build a Document object containing the index of each field. In the second step, we use the Time Detector component to determine whether the publishing time of this Weibo post belongs to the current most recent writable partition. In the third step, since the most recent writable partition is the first time to write index data, we need to initialize the disk storage location, IndexWriter, IndexReader and other key metadata information of the index partition. Then save it in the Time Partition Metadata component. In the fourth step, we use the IndexWriter object of the most recent writable partition to save the index data of this Weibo post. Then we create indexes for the three Weibo posts published on February 1, March 7, and April 16. The overall process is also divided into four steps. Because the Time Detector component determines that the release time of these three Weibo data does not belong to the current most recent writable partition, the indexes of these three Weibo data will be written into the random cache index partition. At this time, the time range of the random cache index partition is from February 1 to April 16.
[0062] For the index query process, let's take the query of microblog information containing "hybrid rice" from April 1 to the present as an example. The first step is to filter out index partitions that have an intersection with the query time range through the Time Partition Metadata component. At this time, only the most recently writable index partition and the random cache index partition meet the conditions. The second step is to build a Boolean query object based on the keyword query of the microblog content field and the range query of the microblog release time field. Each partition uses a thread to execute the index query subtask. The third step is to globally sort the subquery results of each index partition by relevance and then return them to the end user. Now split the random cache index partition by time range, and write the three microblog index data into three read-only index time partitions with a time range of February 1 to March 1, March 2 to March 31, and April 1 to April 30. At this time, execute the above query again. Only the most recently writable index partition and the read-only index partition with a time range of April 1 to April 30 meet the query time range. These two index partitions contain only two Weibo data indexes. Compared with the out-of-order cache index partition before it was split, the most recently writable index partition and the out-of-order cache index partition contain four Weibo data indexes, which reduces the amount of index data accessed when executing queries and improves query efficiency.
[0063] Based on the same inventive concept, another embodiment of the present invention provides an index partition management system for time series data, which includes:
[0064] An index creation module, used to create an index according to the index creation steps of the method of the present invention;
[0065] The query index module is used to query the index according to the query index step of the method of the present invention.
[0066] Based on the same inventive concept, another embodiment of the present invention provides an electronic device (computer, server, smart phone, etc.), which includes a memory and a processor, the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for executing each step in the method of the present invention.
[0067] Based on the same inventive concept, another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, disk, CD), which stores a computer program. When the computer program is executed by a computer, it implements the various steps of the method of the present invention.
[0068] The specific embodiments of the present invention disclosed above are intended to help understand the content of the present invention and implement it accordingly. It can be understood by those skilled in the art that various replacements, changes and modifications are possible without departing from the spirit and scope of the present invention. The present invention should not be limited to the contents disclosed in the embodiments of this specification, and the scope of protection of the present invention shall be subject to the scope defined in the claims.
Claims
1. A method for index partition management for time series data, characterized in that: Use the following steps to create an index: Encapsulate the necessary information for indexing each field in a time series data into a Document object; According to the time value of the time series data, the index partition to which the index of the time series data belongs is determined based on the Time Detector component; According to the start and end time of the index partition to which the time series data belongs, obtain the metadata information of the index partition and the IndexWriter object related to the index partition from the Time Partition Metadata component; Use the IndexWriter object of the corresponding index partition to create an index for the data encapsulated in the Document object; The determining, based on the Time Detector component, to which index the time series data belongs, includes: Two index partitions are reserved for writing index data, namely the most recently writable index partition and the out-of-order cache index partition, which are used to store the indexes of ordered data for most of the time and the indexes corresponding to some out-of-order data respectively; The Time Detector component is used to determine whether the index of a time series data belongs to the most recently writable index partition or the out-of-order cache index partition. The Time Detector component maintains a most recently writable index partition based on the current time and the window size of the index partition. If the time value corresponding to a time series data belongs to the most recently writable index partition, the time series data is ordered; otherwise, the time series data is out-of-order, and its corresponding index is written to the out-of-order cache index partition. The Time Partition Metadata component is responsible for maintaining the metadata information of all index partitions; the metadata information of the index partition is stored in a Map in the memory, the key is composed of the start time and end time of the index partition, and the value includes the IndexWriter and IndexReader components of the index partition, the disk storage path of the index partition, and the amount of data indexed in the index partition; the Time Partition Metadata component is also responsible for the persistent storage of the index partition metadata information to avoid the loss of the index partition metadata information.
2. The method according to claim 1, characterized in that: The most recently writable index partition is continuously updated with the current time, and the index partitions whose time ranges are before the time range of the most recently writable index partition are read-only index partitions.
3. The method according to claim 1, characterized in that The index creation operation for the data encapsulated in the Document object using the IndexWriter corresponding to the index time partition includes: first caching the index data in the memory, at which time the index data in the memory cannot be queried; then flushing the data in the memory to the disk to become an index file that can be queried.
4. The method according to any one of claims 1 to 3, characterized in that: For the created index, use the following steps to query the index: For index query tasks within a specified time range, first access the Time Partition Metadata component to filter out index partitions that intersect with the query time range; For each index partition that intersects the query time range, a query object is constructed according to the query conditions, and then a thread is used to execute the index query subtask corresponding to the query object. The subquery results of each index partition are first sorted locally by relevance, and then multiple subquery results are globally sorted and finally returned to the end user.
5. The method according to claim 4, characterized in that The out-of-order index data of the out-of-order cache index partition is periodically split according to the time range, and the split index data is merged into the read-only index partition of the corresponding time range to prevent the out-of-order cache index partition from affecting the query performance.
6. An index partition management system for time series data, characterized in that: include: An index creation module, used to create an index according to the method described in any one of claims 1 to 3; The query index module is used to query the index according to the query index step in the method according to claim 4 or 5.
7. An electronic device, characterized in that: The invention comprises a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program comprises instructions for executing the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Intelligent index establishing, inquiring and maintaining method supporting mass data classification and counting
CN105631003A
Real-time big-data oriented search engine implementing method
CN106294695A
