Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lkts committed Apr 25, 2024
1 parent 313e479 commit 843d670
Show file tree
Hide file tree
Showing 30 changed files with 55 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.elasticsearch.index.mapper.ProvidedIdFieldMapper;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.script.ScriptContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptCompiler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/java/org/elasticsearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.FsDirectoryFactory;
import org.elasticsearch.indices.IndicesQueryCache;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.recovery.RecoveryState;
Expand Down Expand Up @@ -477,7 +477,7 @@ public IndexService newIndexService(
ValuesSourceRegistry valuesSourceRegistry,
IndexStorePlugin.IndexFoldersDeletionListener indexFoldersDeletionListener,
Map<String, IndexStorePlugin.SnapshotCommitSupplier> snapshotCommitSuppliers,
MapperMetrics metrics
MapperMetrics mapperMetrics
) throws IOException {
final IndexEventListener eventListener = freeze();
Function<IndexService, CheckedFunction<DirectoryReader, DirectoryReader, IOException>> readerWrapperFactory = indexReaderWrapper
Expand Down Expand Up @@ -539,7 +539,7 @@ public IndexService newIndexService(
indexFoldersDeletionListener,
snapshotCommitSupplier,
indexCommitListener.get(),
metrics
mapperMetrics
);
success = true;
return indexService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@
* Side Public License, v 1.
*/

package org.elasticsearch.indices;

import org.elasticsearch.index.mapper.SourceFieldMetrics;
package org.elasticsearch.index.mapper;

/**
* Groups together all metrics used in mappers.
* Main purpose of this class is to avoid verbosity of passing individual metric instances around.
*/
public class MapperMetrics {
public record MapperMetrics(SourceFieldMetrics sourceFieldMetrics) {
public static MapperMetrics NOOP = new MapperMetrics(SourceFieldMetrics.NOOP);

private final SourceFieldMetrics sourceFieldMetrics;

public MapperMetrics(SourceFieldMetrics sourceFieldMetrics) {
this.sourceFieldMetrics = sourceFieldMetrics;
}

public SourceFieldMetrics getSyntheticSourceMetrics() {
return sourceFieldMetrics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent;
Expand Down Expand Up @@ -790,9 +789,13 @@ public MapperRegistry getMapperRegistry() {

public SourceLoader getSourceLoader(MappingLookup mappingLookup, boolean forceSyntheticSource) {
if (forceSyntheticSource) {
return new SourceLoader.Synthetic(mappingLookup.getMapping(), mapperMetrics.getSyntheticSourceMetrics());
return getSyntheticSourceLoader(mappingLookup);
}

return mappingLookup.newSourceLoader();
}

public SourceLoader getSyntheticSourceLoader(MappingLookup mappingLookup) {
return new SourceLoader.Synthetic(mappingLookup.getMapping(), mapperMetrics.sourceFieldMetrics());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.similarity.SimilarityProvider;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;

import java.util.function.Function;
Expand Down Expand Up @@ -136,7 +135,7 @@ public ScriptCompiler scriptCompiler() {
return scriptCompiler;
}

public MapperMetrics getIndicesMetrics() {
public MapperMetrics getMapperMetrics() {
return mapperMetrics;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ public static class Builder extends MetadataFieldMapper.Builder {
);

private final IndexMode indexMode;
private final SourceFieldMetrics sourceFieldMetrics;

private final boolean supportsNonDefaultParameterValues;
private final SourceFieldMetrics sourceFieldMetrics;

public Builder(IndexMode indexMode, final Settings settings, SourceFieldMetrics sourceFieldMetrics) {
super(Defaults.NAME);
Expand Down Expand Up @@ -200,8 +199,8 @@ public SourceFieldMapper build() {
SourceFieldMapper sourceFieldMapper = new SourceFieldMapper(
mode.get(),
enabled.get(),
includes.getValue().toArray(String[]::new),
excludes.getValue().toArray(String[]::new),
includes.getValue().toArray(Strings.EMPTY_ARRAY),
excludes.getValue().toArray(Strings.EMPTY_ARRAY),
indexMode,
sourceFieldMetrics
);
Expand All @@ -213,14 +212,16 @@ public SourceFieldMapper build() {

}

public static final TypeParser PARSER = new ConfigurableTypeParser(
c -> c.getIndexSettings().getMode() == IndexMode.TIME_SERIES
? c.getIndexSettings().getIndexVersionCreated().onOrAfter(IndexVersions.V_8_7_0)
? tsdbDefault(c.getIndicesMetrics().getSyntheticSourceMetrics())
: tsdbLegacyDefault(c.getIndicesMetrics().getSyntheticSourceMetrics())
: defaultMapper(c.getIndicesMetrics().getSyntheticSourceMetrics()),
c -> new Builder(c.getIndexSettings().getMode(), c.getSettings(), c.getIndicesMetrics().getSyntheticSourceMetrics())
);
public static final TypeParser PARSER = new ConfigurableTypeParser(c -> {
var metrics = c.getMapperMetrics().sourceFieldMetrics();

if (c.getIndexSettings().getMode() == IndexMode.TIME_SERIES) {
return c.getIndexSettings().getIndexVersionCreated().onOrAfter(IndexVersions.V_8_7_0)
? tsdbDefault(metrics)
: tsdbLegacyDefault(metrics);
}
return defaultMapper(metrics);
}, c -> new Builder(c.getIndexSettings().getMode(), c.getSettings(), c.getMapperMetrics().sourceFieldMetrics()));

static final class SourceFieldType extends MappedFieldType {
private final boolean enabled;
Expand Down Expand Up @@ -269,7 +270,6 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) {
private final String[] includes;
private final String[] excludes;
private final SourceFilter sourceFilter;

private final IndexMode indexMode;
private final SourceFieldMetrics sourceFieldMetrics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
* Contains metrics for operations involving source field.
*/
public class SourceFieldMetrics {
public static SourceFieldMetrics NOOP = new SourceFieldMetrics(MeterRegistry.NOOP, () -> 0);
public static final SourceFieldMetrics NOOP = new SourceFieldMetrics(MeterRegistry.NOOP, () -> 0);

public static final String SYNTHETIC_SOURCE_LOAD_LATENCY = "es.mapper.synthetic_source.load.latency.histogram";

private final LongSupplier relativeTimeSupplier;

private final LongHistogram synthethicSourceLoadLatency;
private final LongHistogram syntheticSourceLoadLatency;

public SourceFieldMetrics(MeterRegistry meterRegistry, LongSupplier relativeTimeSupplier) {
this.synthethicSourceLoadLatency = meterRegistry.registerLongHistogram(
this.syntheticSourceLoadLatency = meterRegistry.registerLongHistogram(
SYNTHETIC_SOURCE_LOAD_LATENCY,
"Time it takes to load fields and construct synthetic source",
"ms"
Expand All @@ -40,6 +40,6 @@ public LongSupplier getRelativeTimeSupplier() {
}

public void recordSyntheticSourceLoadLatency(TimeValue value) {
this.synthethicSourceLoadLatency.record(value.millis());
this.syntheticSourceLoadLatency.record(value.millis());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public boolean containsBrokenAnalysis(String field) {
public SearchLookup lookup() {
if (this.lookup == null) {
SourceProvider sourceProvider = isSourceSynthetic()
? SourceProvider.fromSyntheticSource(mapperService.getSourceLoader(mappingLookup, true))
? SourceProvider.fromSyntheticSource(mapperService.getSyntheticSourceLoader(mappingLookup))
: SourceProvider.fromStoredFields();
setLookupProviders(sourceProvider, LeafFieldLookupProvider.fromStoredFields());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.elasticsearch.index.get.GetStats;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MappingLookup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AnalysisRegistry;
import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.plugins.EnginePlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.IndicesServiceBuilder;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.ShardLimitValidator;
import org.elasticsearch.indices.SystemIndexMappingUpdateService;
import org.elasticsearch.indices.SystemIndices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.index.IndexVersionUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.elasticsearch.cluster.version.CompatibilityVersionsUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.plugins.ClusterCoordinationPlugin;
import org.elasticsearch.plugins.MetadataUpgrader;
import org.elasticsearch.test.ESTestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import org.elasticsearch.index.store.Store;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.IndicesQueryCache;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.test.ESTestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.test.TransportVersionUtils;
import org.elasticsearch.test.index.IndexVersionUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.mapper.FieldMapper.Parameter;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptCompiler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.TransportVersionUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import org.elasticsearch.index.mapper.TestRuntimeField;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.script.field.DelegateDocValuesField;
import org.elasticsearch.script.field.DocValuesScriptFieldFactory;
Expand Down Expand Up @@ -559,10 +559,13 @@ private static MapperService createMapperService(IndexSettings indexSettings, Ma
when(mapperService.isMultiField(anyString())).then(
(Answer<Boolean>) invocation -> mappingLookup.isMultiField(invocation.getArgument(0))
);
when(mapperService.getSourceLoader(any(), eq(true))).thenReturn(
when(mapperService.getSyntheticSourceLoader(any())).thenReturn(
new SourceLoader.Synthetic(mappingLookup.getMapping(), SourceFieldMetrics.NOOP)
);
when(mapperService.getSourceLoader(any(), eq(false))).thenReturn(mappingLookup.newSourceLoader());
when(mapperService.getSourceLoader(any(), eq(true))).thenReturn(
new SourceLoader.Synthetic(mappingLookup.getMapping(), SourceFieldMetrics.NOOP)
);
return mapperService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import org.elasticsearch.index.shard.ShardLongFieldRange;
import org.elasticsearch.indices.EmptySystemIndices;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.ShardLimitValidator;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.snapshots.EmptySnapshotsInfoService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.IndicesServiceBuilder;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.indices.ShardLimitValidator;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.indices.analysis.AnalysisModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.index.mapper.MapperMetrics;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParserConfiguration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.xcontent.XContentParser;

/**
Expand Down
Loading

0 comments on commit 843d670

Please sign in to comment.