-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make field data changes immediately taken into account and add the ability to disallow field data loading. #4432
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
package org.elasticsearch.index.fielddata; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Maps; | ||
import org.apache.lucene.index.IndexReader; | ||
import org.elasticsearch.ElasticSearchIllegalArgumentException; | ||
import org.elasticsearch.common.collect.MapBuilder; | ||
|
@@ -36,12 +37,16 @@ | |
import org.elasticsearch.index.settings.IndexSettings; | ||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
/** | ||
*/ | ||
public class IndexFieldDataService extends AbstractIndexComponent { | ||
|
||
private static final String NONE_FORMAT = "none"; | ||
private static final String DOC_VALUES_FORMAT = "doc_values"; | ||
|
||
private final static ImmutableMap<String, IndexFieldData.Builder> buildersByType; | ||
private final static ImmutableMap<String, IndexFieldData.Builder> docValuesBuildersByType; | ||
private final static ImmutableMap<Tuple<String, String>, IndexFieldData.Builder> buildersByTypeAndFormat; | ||
|
@@ -71,28 +76,39 @@ public class IndexFieldDataService extends AbstractIndexComponent { | |
buildersByTypeAndFormat = MapBuilder.<Tuple<String, String>, IndexFieldData.Builder>newMapBuilder() | ||
.put(Tuple.tuple("string", "paged_bytes"), new PagedBytesIndexFieldData.Builder()) | ||
.put(Tuple.tuple("string", "fst"), new FSTBytesIndexFieldData.Builder()) | ||
.put(Tuple.tuple("string", "doc_values"), new DocValuesIndexFieldData.Builder()) | ||
.put(Tuple.tuple("string", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder()) | ||
.put(Tuple.tuple("string", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("string", "no"), new DocValuesIndexFieldData.Builder()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. an typo :) will fix |
||
.put(Tuple.tuple("float", "array"), new FloatArrayIndexFieldData.Builder()) | ||
.put(Tuple.tuple("float", "doc_values"), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.FLOAT)) | ||
.put(Tuple.tuple("float", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.FLOAT)) | ||
.put(Tuple.tuple("float", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("double", "array"), new DoubleArrayIndexFieldData.Builder()) | ||
.put(Tuple.tuple("double", "doc_values"), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.DOUBLE)) | ||
.put(Tuple.tuple("double", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.DOUBLE)) | ||
.put(Tuple.tuple("double", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("byte", "array"), new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.BYTE)) | ||
.put(Tuple.tuple("byte", "doc_values"), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.BYTE)) | ||
.put(Tuple.tuple("byte", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.BYTE)) | ||
.put(Tuple.tuple("byte", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("short", "array"), new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.SHORT)) | ||
.put(Tuple.tuple("short", "doc_values"), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.SHORT)) | ||
.put(Tuple.tuple("short", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.SHORT)) | ||
.put(Tuple.tuple("short", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("int", "array"), new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.INT)) | ||
.put(Tuple.tuple("int", "doc_values"), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.INT)) | ||
.put(Tuple.tuple("int", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.INT)) | ||
.put(Tuple.tuple("int", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("long", "array"), new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.LONG)) | ||
.put(Tuple.tuple("long", "doc_values"), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.LONG)) | ||
.put(Tuple.tuple("long", DOC_VALUES_FORMAT), new DocValuesIndexFieldData.Builder().numericType(IndexNumericFieldData.NumericType.LONG)) | ||
.put(Tuple.tuple("long", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.put(Tuple.tuple("geo_point", "array"), new GeoPointDoubleArrayIndexFieldData.Builder()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have a constant for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point |
||
.put(Tuple.tuple("geo_point", NONE_FORMAT), new NoneIndexFieldData.Builder()) | ||
.immutableMap(); | ||
} | ||
|
||
private final IndicesFieldDataCache indicesFieldDataCache; | ||
private final ConcurrentMap<String, IndexFieldData<?>> loadedFieldData = ConcurrentCollections.newConcurrentMap(); | ||
private final Map<String, IndexFieldDataCache> fieldDataCaches = Maps.newHashMap(); // no need for concurrency support, always used under lock | ||
|
||
IndexService indexService; | ||
|
||
// public for testing | ||
public IndexFieldDataService(Index index) { | ||
this(index, ImmutableSettings.Builder.EMPTY_SETTINGS, new IndicesFieldDataCache(ImmutableSettings.Builder.EMPTY_SETTINGS)); | ||
} | ||
|
@@ -114,6 +130,10 @@ public void clear() { | |
fieldData.clear(); | ||
} | ||
loadedFieldData.clear(); | ||
for (IndexFieldDataCache cache : fieldDataCaches.values()) { | ||
cache.clear(); | ||
} | ||
fieldDataCaches.clear(); | ||
} | ||
} | ||
|
||
|
@@ -123,12 +143,29 @@ public void clearField(String fieldName) { | |
if (fieldData != null) { | ||
fieldData.clear(); | ||
} | ||
IndexFieldDataCache cache = fieldDataCaches.remove(fieldName); | ||
if (cache != null) { | ||
cache.clear(); | ||
} | ||
} | ||
} | ||
|
||
public void clear(IndexReader reader) { | ||
for (IndexFieldData<?> indexFieldData : loadedFieldData.values()) { | ||
indexFieldData.clear(reader); | ||
synchronized (loadedFieldData) { | ||
for (IndexFieldData<?> indexFieldData : loadedFieldData.values()) { | ||
indexFieldData.clear(reader); | ||
} | ||
for (IndexFieldDataCache cache : fieldDataCaches.values()) { | ||
cache.clear(reader); | ||
} | ||
} | ||
} | ||
|
||
public void onMappingUpdate() { | ||
// synchronize to make sure to not miss field data instances that are being loaded | ||
synchronized (loadedFieldData) { | ||
// important: do not clear fieldDataCaches: the cache may be reused | ||
loadedFieldData.clear(); | ||
} | ||
} | ||
|
||
|
@@ -163,18 +200,21 @@ public <IFD extends IndexFieldData<?>> IFD getForField(FieldMapper<?> mapper) { | |
throw new ElasticSearchIllegalArgumentException("failed to find field data builder for field " + fieldNames.fullName() + ", and type " + type.getType()); | ||
} | ||
|
||
IndexFieldDataCache cache; | ||
// we default to node level cache, which in turn defaults to be unbounded | ||
// this means changing the node level settings is simple, just set the bounds there | ||
String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "node")); | ||
if ("resident".equals(cacheType)) { | ||
cache = new IndexFieldDataCache.Resident(indexService, fieldNames, type); | ||
} else if ("soft".equals(cacheType)) { | ||
cache = new IndexFieldDataCache.Soft(indexService, fieldNames, type); | ||
} else if ("node".equals(cacheType)) { | ||
cache = indicesFieldDataCache.buildIndexFieldDataCache(indexService, index, fieldNames, type); | ||
} else { | ||
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldNames.fullName() + "]"); | ||
IndexFieldDataCache cache = fieldDataCaches.get(fieldNames.indexName()); | ||
if (cache == null) { | ||
// we default to node level cache, which in turn defaults to be unbounded | ||
// this means changing the node level settings is simple, just set the bounds there | ||
String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "node")); | ||
if ("resident".equals(cacheType)) { | ||
cache = new IndexFieldDataCache.Resident(indexService, fieldNames, type); | ||
} else if ("soft".equals(cacheType)) { | ||
cache = new IndexFieldDataCache.Soft(indexService, fieldNames, type); | ||
} else if ("node".equals(cacheType)) { | ||
cache = indicesFieldDataCache.buildIndexFieldDataCache(indexService, index, fieldNames, type); | ||
} else { | ||
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldNames.fullName() + "]"); | ||
} | ||
fieldDataCaches.put(fieldNames.indexName(), cache); | ||
} | ||
|
||
fieldData = builder.build(index, indexSettings, fieldNames, type, cache); | ||
|
@@ -184,4 +224,5 @@ public <IFD extends IndexFieldData<?>> IFD getForField(FieldMapper<?> mapper) { | |
} | ||
return (IFD) fieldData; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. ElasticSearch licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.fielddata.plain; | ||
|
||
import org.apache.lucene.index.AtomicReaderContext; | ||
import org.elasticsearch.ElasticSearchIllegalStateException; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.fielddata.*; | ||
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode; | ||
import org.elasticsearch.index.mapper.FieldMapper; | ||
import org.elasticsearch.index.mapper.FieldMapper.Names; | ||
import org.elasticsearch.index.settings.IndexSettings; | ||
|
||
/** | ||
* A field data implementation that forbids loading. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe put a line here that it causes an exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed |
||
*/ | ||
public final class NoneIndexFieldData extends AbstractIndexFieldData<AtomicFieldData<?>> { | ||
|
||
public static class Builder implements IndexFieldData.Builder { | ||
@Override | ||
public IndexFieldData<AtomicFieldData<?>> build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) { | ||
return new NoneIndexFieldData(index, indexSettings, fieldNames, type, cache); | ||
} | ||
} | ||
|
||
public NoneIndexFieldData(Index index, Settings indexSettings, Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) { | ||
super(index, indexSettings, fieldNames, fieldDataType, cache); | ||
} | ||
|
||
@Override | ||
public boolean valuesOrdered() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public AtomicFieldData<?> loadDirect(AtomicReaderContext context) throws Exception { | ||
throw fail(); | ||
} | ||
|
||
@Override | ||
public IndexFieldData.XFieldComparatorSource comparatorSource(Object missingValue, SortMode sortMode) { | ||
throw fail(); | ||
} | ||
|
||
private ElasticSearchIllegalStateException fail() { | ||
return new ElasticSearchIllegalStateException("Field data loading is forbidden on " + getFieldNames().name()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since circuit breaker is going to happen, I think that this doc can be misleading, since the circuit breaker will kick in and not allow for the field to be loaded (and hopefully, in the future, blacklist a field using this feature, ha!, how things connect!). It is obviously still very much good to explicitly disable certain fields from loading to field data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a new commit to reword this part of the documentation. Does it look better?