-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Write prefix partition for tsid in tsdb codec #144617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+721
−65
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
64e4dc2
Write prefix partition for tsid
dnhatn e5be91a
fix tests
dnhatn 85a68a6
Merge remote-tracking branch 'elastic/main' into codec-write-tsid-pre…
dnhatn cb79d7f
fix tests
dnhatn 25d4fa5
Merge remote-tracking branch 'elastic/main' into codec-write-tsid-pre…
dnhatn a6e5772
1024 partitions
dnhatn 599dbdf
Merge remote-tracking branch 'elastic/main' into codec-write-tsid-pre…
dnhatn 6bbf4a8
version 4
dnhatn 1b762aa
Merge remote-tracking branch 'elastic/main' into codec-write-tsid-pre…
dnhatn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
server/src/main/java/org/elasticsearch/index/codec/tsdb/PartitionedDocValues.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.codec.tsdb; | ||
|
|
||
| import org.apache.lucene.index.LeafReaderContext; | ||
| import org.apache.lucene.search.IndexSearcher; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * An extension for doc-values which is the primary sort key, and values are grouped by some prefix bytes. One example is `_tsid` in | ||
| * time-series, where time-series can be grouped by the first few bytes, and the query engine can process a slice of time-series | ||
| * containing all "continuous" time-series sharing the same prefix. This is necessary instead of querying a slice of docs because some | ||
| * aggregations such as rate require all data points from a single time-series to be processed by the same operator. | ||
| */ | ||
| public interface PartitionedDocValues { | ||
| /** | ||
| * @param prefixes the prefix keys | ||
| * @param startDocs the startDocs of corresponding prefix keys | ||
| * @param numPartitions the actual number of prefixes available in the partition | ||
| */ | ||
| record PrefixPartitions(int[] prefixes, int[] startDocs, int numPartitions) { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the prefixed partition from the doc-values of this field if exists. | ||
| * @param reused an existing prefix partitions can be reused to avoid allocating memory | ||
| */ | ||
| @Nullable | ||
| PrefixPartitions prefixPartitions(PrefixPartitions reused) throws IOException; | ||
|
|
||
| /** | ||
| * The number of bits used in prefix partitions | ||
| */ | ||
| int prefixPartitionBits(); | ||
|
|
||
| /** | ||
| * Check if the given index searcher can be partitioned by tsid prefix. | ||
| * @param searcher the index searcher to check | ||
| * @return true if all non-empty segments support tsid prefix partitioning | ||
| */ | ||
| static boolean canPartitionByTsidPrefix(IndexSearcher searcher) throws IOException { | ||
| for (LeafReaderContext leafContext : searcher.getLeafContexts()) { | ||
| var sortedDV = leafContext.reader().getSortedDocValues(TimeSeriesIdFieldMapper.NAME); | ||
| // empty segment | ||
| if (sortedDV == null) { | ||
| continue; | ||
| } | ||
| if (sortedDV instanceof PartitionedDocValues partition && partition.prefixPartitionBits() > 0) { | ||
| continue; | ||
| } | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version 3 is kind of in
ES819Version3TSDBDocValuesFormat, maybe use value 4 for the prefix partitioning? And maybe add that version 3 is part of that new format.In hindsight
ES819Version3TSDBDocValuesFormatwasn't needed (incorrect serverless upgrading made me think we had to introduce this), but it also doesn't have its own codec versioning scheme. This isn't idea, but hopefully we can start with new versioning scheme whenES94TSDBDocValuesFormatis introduced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I pushed 6bbf4a8