Skip to content

Commit ded9413

Browse files
authored
[TSDB] Improve downsampling performance by using tsid ordinals (#90088)
This PR modifies downsampling operation so that it uses global ordinal to track tsid changes PR depends on the work done in #90035 Relates to #74660
1 parent 5cc34b4 commit ded9413

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/downsample/RollupShardIndexer.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ public LeafBucketCollector getLeafCollector(final AggregationExecutionContext ag
254254
public void collect(int docId, long owningBucketOrd) throws IOException {
255255
final BytesRef tsid = aggCtx.getTsid();
256256
assert tsid != null : "Document without [" + TimeSeriesIdFieldMapper.NAME + "] field was found.";
257+
final int tsidOrd = aggCtx.getTsidOrd();
257258
final long timestamp = aggCtx.getTimestamp();
258259

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

304305
// Create new rollup bucket
305306
if (tsidChanged) {
306-
rollupBucketBuilder.resetTsid(tsid, lastHistoTimestamp);
307+
rollupBucketBuilder.resetTsid(tsid, tsidOrd, lastHistoTimestamp);
307308
} else {
308309
rollupBucketBuilder.resetTimestamp(lastHistoTimestamp);
309310
}
@@ -370,6 +371,7 @@ public ScoreMode scoreMode() {
370371

371372
private class RollupBucketBuilder {
372373
private BytesRef tsid;
374+
private int tsidOrd = -1;
373375
private long timestamp;
374376
private int docCount;
375377
private final Map<String, MetricFieldProducer> metricFieldProducers;
@@ -383,8 +385,9 @@ private class RollupBucketBuilder {
383385
/**
384386
* tsid changed, reset tsid and timestamp
385387
*/
386-
public RollupBucketBuilder resetTsid(BytesRef tsid, long timestamp) {
388+
public RollupBucketBuilder resetTsid(BytesRef tsid, int tsidOrd, long timestamp) {
387389
this.tsid = BytesRef.deepCopyOf(tsid);
390+
this.tsidOrd = tsidOrd;
388391
return resetTimestamp(timestamp);
389392
}
390393

@@ -493,6 +496,10 @@ public BytesRef tsid() {
493496
return tsid;
494497
}
495498

499+
public int tsidOrd() {
500+
return tsidOrd;
501+
}
502+
496503
public int docCount() {
497504
return docCount;
498505
}

x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ public void onFailure(Exception e) {
477477
assertBusy(() -> assertTrue("In progress rollup did not complete", rollupListener.success), 60, TimeUnit.SECONDS);
478478
}
479479

480-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/88800")
481480
public void testRollupDatastream() throws Exception {
482481
DownsampleConfig config = new DownsampleConfig(randomInterval());
483482
String dataStreamName = createDataStream();

0 commit comments

Comments
 (0)