mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-24 15:17:30 -04:00
Avoid reading unnecessary dimension values when downsampling (#124451)
Read dimension values once per tsid/bucket docid range instead of for each document being processed. The dimension value within a bucket-interval docid range is always to same and this avoids unnecessary reads. Latency of downsampling the tsdb track index into a 1 hour interval downsample index drop by ~16% (running on my local machine).
This commit is contained in:
parent
a5f186bb5d
commit
6afd3ecc58
2 changed files with 32 additions and 9 deletions
|
@ -44,16 +44,29 @@ public class DimensionFieldProducer extends AbstractDownsampleFieldProducer {
|
|||
isEmpty = true;
|
||||
}
|
||||
|
||||
void collect(final Object value) {
|
||||
void collectOnce(final Object value) {
|
||||
assert isEmpty;
|
||||
Objects.requireNonNull(value);
|
||||
if (isEmpty) {
|
||||
this.value = value;
|
||||
this.isEmpty = false;
|
||||
return;
|
||||
}
|
||||
if (value.equals(this.value) == false) {
|
||||
throw new IllegalArgumentException("Dimension value changed without tsid change [" + value + "] != [" + this.value + "]");
|
||||
this.value = value;
|
||||
this.isEmpty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an expensive check, that slows down downsampling significantly.
|
||||
* Given that index is sorted by tsid as primary key, this shouldn't really happen.
|
||||
*/
|
||||
boolean validate(FormattedDocValues docValues, int docId) throws IOException {
|
||||
if (docValues.advanceExact(docId)) {
|
||||
int docValueCount = docValues.docValueCount();
|
||||
for (int i = 0; i < docValueCount; i++) {
|
||||
var value = docValues.nextValue();
|
||||
if (value.equals(this.value) == false) {
|
||||
assert false : "Dimension value changed without tsid change [" + value + "] != [" + this.value + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,12 +82,17 @@ public class DimensionFieldProducer extends AbstractDownsampleFieldProducer {
|
|||
|
||||
@Override
|
||||
public void collect(FormattedDocValues docValues, int docId) throws IOException {
|
||||
if (dimension.isEmpty == false) {
|
||||
assert dimension.validate(docValues, docId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (docValues.advanceExact(docId) == false) {
|
||||
return;
|
||||
}
|
||||
int docValueCount = docValues.docValueCount();
|
||||
for (int i = 0; i < docValueCount; i++) {
|
||||
this.dimension.collect(docValues.nextValue());
|
||||
this.dimension.collectOnce(docValues.nextValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue