Skip to content

Commit b24ad23

Browse files
committed
Reduce object generation per segment.
1 parent 73614f3 commit b24ad23

17 files changed

Lines changed: 190 additions & 1116 deletions

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public String name() {
4848
}
4949

5050
/**
51-
* Resets the producer to an empty value.
51+
* Resets the downsampler to an empty value.
5252
*/
5353
public abstract void reset();
5454

@@ -68,6 +68,12 @@ public T getLeaf(LeafReaderContext context) throws IOException {
6868

6969
public abstract void collect(T docValues, IntArrayList docIdBuffer) throws IOException;
7070

71+
/**
72+
* Utility class used for fetching field values by reading field data.
73+
* For fields whose type is multivalued the 'name' matches the parent field
74+
* name (normally used for indexing data), while the actual multiField
75+
* name is accessible by means of {@link MappedFieldType#name()}.
76+
*/
7177
abstract static class FieldValueFetcher<T> {
7278
protected final String name;
7379
protected final MappedFieldType fieldType;
@@ -127,10 +133,10 @@ private static AbstractFieldDownsampler<?> create(
127133
) {
128134
assert AggregateMetricDoubleFieldMapper.CONTENT_TYPE.equals(fieldType.typeName()) == false
129135
: "Aggregate metric double should be handled by a dedicated FieldValueFetcher";
130-
if (TDigestHistogramFieldProducer.TYPE.equals(fieldType.typeName())) {
136+
if (TDigestHistogramFieldDownsampler.TYPE.equals(fieldType.typeName())) {
131137
return TDigestHistogramFieldDownsampler.create(fieldName, fieldType, fieldData, samplingMethod);
132138
}
133-
if (ExponentialHistogramFieldProducer.TYPE.equals(fieldType.typeName())) {
139+
if (ExponentialHistogramFieldDownsampler.TYPE.equals(fieldType.typeName())) {
134140
return ExponentialHistogramFieldDownsampler.create(fieldName, fieldType, fieldData, samplingMethod);
135141
}
136142
if (fieldType.getMetricType() != null) {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
import java.util.Collection;
2323
import java.util.List;
2424

25-
import static org.elasticsearch.xpack.downsample.NumericMetricFieldProducer.MAX_NO_VALUE;
26-
import static org.elasticsearch.xpack.downsample.NumericMetricFieldProducer.MIN_NO_VALUE;
27-
2825
/**
29-
* A producer that can be used for downsampling aggregate metric double fields whether is a metric or a label. We need a separate producer
30-
* for each a sub-metric of an aggregate metric double, this means to downsample an aggregate metric double we will need 4.
26+
* A downsampler that can be used for downsampling aggregate metric double fields whether is a metric or a label. We need a separate
27+
* downsampler for each a sub-metric of an aggregate metric double, this means to downsample an aggregate metric double we will need 4.
3128
* This is mainly used when downsampling already downsampled indices.
3229
*/
3330
abstract sealed class AggregateMetricDoubleFieldDownsampler extends NumericMetricFieldDownsampler {
@@ -70,7 +67,6 @@ public void collect(SortedNumericDoubleValues docValues, IntArrayList docIdBuffe
7067
case min -> min = Math.min(value, min);
7168
case max -> max = Math.max(value, max);
7269
case sum -> sum.add(value);
73-
// This is the reason why we can't use GaugeMetricFieldProducer
7470
// For downsampled indices aggregate metric double's value count field needs to be summed.
7571
// (Note: not using CompensatedSum here should be ok given that value_count is mapped as long)
7672
case value_count -> count += Math.round(value);
@@ -162,7 +158,7 @@ public void write(XContentBuilder builder) throws IOException {
162158
}
163159

164160
/**
165-
* We use a specialised serializer because we are combining all the available submetric producers.
161+
* We use a specialised serializer because we are combining all the available submetric downsamplers.
166162
*/
167163
static class Serializer implements DownsampleFieldSerializer {
168164
private final Collection<AbstractFieldDownsampler<?>> downsamplers;
@@ -187,13 +183,13 @@ public void write(XContentBuilder builder) throws IOException {
187183

188184
builder.startObject(name);
189185
for (AbstractFieldDownsampler<?> fieldDownsampler : downsamplers) {
190-
assert name.equals(fieldDownsampler.name()) : "producer has a different name";
186+
assert name.equals(fieldDownsampler.name()) : "downsampler has a different name";
191187
if (fieldDownsampler.isEmpty()) {
192188
continue;
193189
}
194190
if (fieldDownsampler instanceof AggregateMetricDoubleFieldDownsampler == false) {
195191
throw new IllegalStateException(
196-
"Unexpected field producer class: " + fieldDownsampler.getClass().getSimpleName() + " for " + name + " field"
192+
"Unexpected field downsampler class: " + fieldDownsampler.getClass().getSimpleName() + " for " + name + " field"
197193
);
198194
}
199195
fieldDownsampler.write(builder);

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

Lines changed: 0 additions & 196 deletions
This file was deleted.

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

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)