Skip to content
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

[TSDB] Improve downsampling performance by using tsid ordinals #90088

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ public LeafBucketCollector getLeafCollector(final AggregationExecutionContext ag
public void collect(int docId, long owningBucketOrd) throws IOException {
final BytesRef tsid = aggCtx.getTsid();
assert tsid != null : "Document without [" + TimeSeriesIdFieldMapper.NAME + "] field was found.";
final int tsidOrd = aggCtx.getTsidOrd();
final long timestamp = aggCtx.getTimestamp();

boolean tsidChanged = tsid.equals(rollupBucketBuilder.tsid()) == false;
boolean tsidChanged = tsidOrd != rollupBucketBuilder.tsidOrd();
if (tsidChanged || timestamp < lastHistoTimestamp) {
lastHistoTimestamp = Math.max(
rounding.round(timestamp),
Expand Down Expand Up @@ -303,7 +304,7 @@ public void collect(int docId, long owningBucketOrd) throws IOException {

// Create new rollup bucket
if (tsidChanged) {
rollupBucketBuilder.resetTsid(tsid, lastHistoTimestamp);
rollupBucketBuilder.resetTsid(tsid, tsidOrd, lastHistoTimestamp);
} else {
rollupBucketBuilder.resetTimestamp(lastHistoTimestamp);
}
Expand Down Expand Up @@ -370,6 +371,7 @@ public ScoreMode scoreMode() {

private class RollupBucketBuilder {
private BytesRef tsid;
private int tsidOrd = -1;
private long timestamp;
private int docCount;
private final Map<String, MetricFieldProducer> metricFieldProducers;
Expand All @@ -383,8 +385,9 @@ private class RollupBucketBuilder {
/**
* tsid changed, reset tsid and timestamp
*/
public RollupBucketBuilder resetTsid(BytesRef tsid, long timestamp) {
public RollupBucketBuilder resetTsid(BytesRef tsid, int tsidOrd, long timestamp) {
this.tsid = BytesRef.deepCopyOf(tsid);
this.tsidOrd = tsidOrd;
return resetTimestamp(timestamp);
}

Expand Down Expand Up @@ -493,6 +496,10 @@ public BytesRef tsid() {
return tsid;
}

public int tsidOrd() {
return tsidOrd;
}

public int docCount() {
return docCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ public void onFailure(Exception e) {
assertBusy(() -> assertTrue("In progress rollup did not complete", rollupListener.success), 60, TimeUnit.SECONDS);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/88800")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an unrelated unmuting? Looking at the source issue it seems to have already been fixed elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have fixed this issue some time ago. I don't know why this was not muted.
I unmuted it in this PR rather than submitting a separate one for this.

public void testRollupDatastream() throws Exception {
DownsampleConfig config = new DownsampleConfig(randomInterval());
String dataStreamName = createDataStream();
Expand Down