Skip to content

Commit c20ffe2

Browse files
committed
Remove MapperService argument from IndexFieldData.Builder#build (elastic#63197)
MapperService carries a lot of weight and is only used to determine if loading of field data for the id field is enabled, which can be done in a different way. There was another usage that recently went away with the removal of `TypeFieldMapper`.
1 parent 7405af8 commit c20ffe2

File tree

45 files changed

+164
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+164
-108
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
211211
@Override
212212
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
213213
failIfNoDocValues();
214-
return (cache, breakerService, mapperService) -> {
214+
return (cache, breakerService) -> {
215215
final IndexNumericFieldData scaledValues = new SortedNumericIndexFieldData.Builder(
216216
name(),
217217
IndexNumericFieldData.NumericType.LONG
218-
).build(cache, breakerService, mapperService);
218+
).build(cache, breakerService);
219219
return new ScaledFloatIndexFieldData(scaledValues, scalingFactor);
220220
};
221221
}

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void testFieldData() throws IOException {
155155
= new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float1", scalingFactor);
156156
IndexNumericFieldData fielddata = (IndexNumericFieldData) f1.fielddataBuilder("index", () -> {
157157
throw new UnsupportedOperationException();
158-
}).build(null, null, null);
158+
}).build(null, null);
159159
assertEquals(fielddata.getNumericType(), IndexNumericFieldData.NumericType.DOUBLE);
160160
LeafNumericFieldData leafFieldData = fielddata.load(reader.leaves().get(0));
161161
SortedNumericDoubleValues values = leafFieldData.getDoubleValues();
@@ -168,7 +168,7 @@ public void testFieldData() throws IOException {
168168
= new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float2", scalingFactor);
169169
fielddata = (IndexNumericFieldData) f2.fielddataBuilder("index", () -> {
170170
throw new UnsupportedOperationException();
171-
}).build(null, null, null);
171+
}).build(null, null);
172172
leafFieldData = fielddata.load(reader.leaves().get(0));
173173
values = leafFieldData.getDoubleValues();
174174
assertTrue(values.advanceExact(0));

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
729729
shardContext::lookup);
730730
IndexFieldDataCache cache = new IndexFieldDataCache.None();
731731
CircuitBreakerService circuitBreaker = new NoneCircuitBreakerService();
732-
return (IFD) builder.build(cache, circuitBreaker, shardContext.getMapperService());
732+
return (IFD) builder.build(cache, circuitBreaker);
733733
}
734734
};
735735
}

server/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.elasticsearch.common.Nullable;
3838
import org.elasticsearch.common.util.BigArrays;
3939
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
40-
import org.elasticsearch.index.mapper.MapperService;
4140
import org.elasticsearch.indices.breaker.CircuitBreakerService;
4241
import org.elasticsearch.search.DocValueFormat;
4342
import org.elasticsearch.search.MultiValueMode;
@@ -246,7 +245,7 @@ public abstract BucketedSort newBucketedSort(BigArrays bigArrays, SortOrder sort
246245

247246
interface Builder {
248247

249-
IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService);
248+
IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService);
250249
}
251250

252251
interface Global<FD extends LeafFieldData> extends IndexFieldData<FD> {

server/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
135135
}
136136
}
137137

138-
return (IFD) builder.build(cache, circuitBreakerService, mapperService);
138+
return (IFD) builder.build(cache, circuitBreakerService);
139139
}
140140

141141
/**

server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointIndexFieldData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
3232
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
3333
import org.elasticsearch.index.fielddata.LeafGeoPointFieldData;
34-
import org.elasticsearch.index.mapper.MapperService;
3534
import org.elasticsearch.indices.breaker.CircuitBreakerService;
3635
import org.elasticsearch.search.DocValueFormat;
3736
import org.elasticsearch.search.MultiValueMode;
@@ -113,7 +112,7 @@ public Builder(String name, ValuesSourceType valuesSourceType) {
113112
}
114113

115114
@Override
116-
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
115+
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
117116
// ignore breaker
118117
return new LatLonPointIndexFieldData(name, valuesSourceType);
119118
}

server/src/main/java/org/elasticsearch/index/fielddata/plain/BinaryIndexFieldData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
2828
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
2929
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
30-
import org.elasticsearch.index.mapper.MapperService;
3130
import org.elasticsearch.indices.breaker.CircuitBreakerService;
3231
import org.elasticsearch.search.DocValueFormat;
3332
import org.elasticsearch.search.MultiValueMode;
@@ -47,7 +46,7 @@ public Builder(String name, ValuesSourceType valuesSourceType) {
4746
}
4847

4948
@Override
50-
public BinaryIndexFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
49+
public BinaryIndexFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
5150
return new BinaryIndexFieldData(name, valuesSourceType);
5251
}
5352
}

server/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryIndexFieldData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.index.fielddata.IndexFieldData;
2828
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
2929
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
30-
import org.elasticsearch.index.mapper.MapperService;
3130
import org.elasticsearch.indices.breaker.CircuitBreakerService;
3231
import org.elasticsearch.search.DocValueFormat;
3332
import org.elasticsearch.search.MultiValueMode;
@@ -92,7 +91,7 @@ public Builder(String name, ValuesSourceType valuesSourceType) {
9291
}
9392

9493
@Override
95-
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
94+
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
9695
// Ignore breaker
9796
return new BytesBinaryIndexFieldData(name, valuesSourceType);
9897
}

server/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,34 @@
3636
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
3737
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
3838
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
39-
import org.elasticsearch.index.mapper.MapperService;
4039
import org.elasticsearch.indices.breaker.CircuitBreakerService;
4140
import org.elasticsearch.search.DocValueFormat;
4241
import org.elasticsearch.search.MultiValueMode;
4342
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
4443
import org.elasticsearch.search.sort.BucketedSort;
4544
import org.elasticsearch.search.sort.SortOrder;
4645

47-
import java.io.IOException;
4846
import java.util.Collection;
4947
import java.util.Collections;
50-
import java.util.function.Function;
5148

5249
public class ConstantIndexFieldData extends AbstractIndexOrdinalsFieldData {
5350

5451
public static class Builder implements IndexFieldData.Builder {
5552

56-
private final Function<MapperService, String> valueFunction;
53+
private final String constantValue;
5754
private final String name;
5855
private final ValuesSourceType valuesSourceType;
5956

60-
public Builder(Function<MapperService, String> valueFunction, String name, ValuesSourceType valuesSourceType) {
61-
this.valueFunction = valueFunction;
57+
public Builder(String constantValue, String name, ValuesSourceType valuesSourceType) {
58+
this.constantValue = constantValue;
6259
this.name = name;
6360
this.valuesSourceType = valuesSourceType;
6461
}
6562

6663
@Override
67-
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
68-
return new ConstantIndexFieldData(name, valueFunction.apply(mapperService), valuesSourceType);
64+
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
65+
return new ConstantIndexFieldData(name, constantValue, valuesSourceType);
6966
}
70-
7167
}
7268

7369
private static class ConstantLeafFieldData extends AbstractLeafOrdinalsFieldData {
@@ -116,7 +112,7 @@ public int ordValue() {
116112
}
117113

118114
@Override
119-
public boolean advanceExact(int target) throws IOException {
115+
public boolean advanceExact(int target) {
120116
docID = target;
121117
return true;
122118
}
@@ -126,7 +122,7 @@ public int docID() {
126122
return docID;
127123
}
128124
};
129-
return (SortedSetDocValues) DocValues.singleton(sortedValues);
125+
return DocValues.singleton(sortedValues);
130126
}
131127

132128
@Override
@@ -148,8 +144,7 @@ public final LeafOrdinalsFieldData load(LeafReaderContext context) {
148144
}
149145

150146
@Override
151-
public LeafOrdinalsFieldData loadDirect(LeafReaderContext context)
152-
throws Exception {
147+
public LeafOrdinalsFieldData loadDirect(LeafReaderContext context) {
153148
return atomicFieldData;
154149
}
155150

@@ -172,7 +167,7 @@ public IndexOrdinalsFieldData loadGlobal(DirectoryReader indexReader) {
172167
}
173168

174169
@Override
175-
public IndexOrdinalsFieldData loadGlobalDirect(DirectoryReader indexReader) throws Exception {
170+
public IndexOrdinalsFieldData loadGlobalDirect(DirectoryReader indexReader) {
176171
return loadGlobal(indexReader);
177172
}
178173

server/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
4747
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
4848
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
49-
import org.elasticsearch.index.mapper.MapperService;
5049
import org.elasticsearch.indices.breaker.CircuitBreakerService;
5150
import org.elasticsearch.search.DocValueFormat;
5251
import org.elasticsearch.search.MultiValueMode;
@@ -77,7 +76,7 @@ public Builder(String name, double minFrequency, double maxFrequency, int minSeg
7776
}
7877

7978
@Override
80-
public IndexOrdinalsFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
79+
public IndexOrdinalsFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
8180
return new PagedBytesIndexFieldData(name, valuesSourceType, cache, breakerService,
8281
minFrequency, maxFrequency, minSegmentSize);
8382
}

0 commit comments

Comments
 (0)