forked from elastic/elasticsearch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make field data changes immediately taken into account and add the ab…
…ility to disallow field data loading. This commit changes field data configuration updates so that they are immediately taken into account for loading new segments. The way it works is that field data configuration is now cached separately from the field data cache, meaning that it is now possible to clear the field data configuration from IndexFieldDataService while the cache will stay around. On the next time that Elasticsearch will reload field data configuration, it will check if there is already a cache entry, and reuse it if it exists. To disable field data loading, all that is required is to change the field data format to "none" (supported by all field data types) using the update mapping API. Elasticsearch will then refuse to load field data on any new segment, but field data which has been loaded on the previous segments will remain available. So you need to clear the field data cache in order to reclaim memory (otherwise memory will be reclaimed slower, as segments get merged). Close elastic#4430 Close elastic#4431
- Loading branch information
Showing
8 changed files
with
332 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/org/elasticsearch/index/fielddata/plain/DisabledIndexFieldData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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 and will throw an {@link ElasticSearchIllegalStateException} if you try to load | ||
* {@link AtomicFieldData} instances. | ||
*/ | ||
public final class DisabledIndexFieldData 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 DisabledIndexFieldData(index, indexSettings, fieldNames, type, cache); | ||
} | ||
} | ||
|
||
public DisabledIndexFieldData(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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.