From e8e74ae569c929a228a5cd2bc546f5351166464b Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 24 Jun 2015 14:31:07 -0700 Subject: [PATCH] Mappings: Remove close() from Mapper There was only a single actual "use" of close, for a threadlocal in VersionFieldMapper. However, that threadlocal is completely unnecessary, so this change removes the threadlocal and close() altogether. --- .../index/mapper/DocumentMapper.java | 4 ---- .../org/elasticsearch/index/mapper/Mapper.java | 2 -- .../index/mapper/core/AbstractFieldMapper.java | 11 ----------- .../index/mapper/core/NumberFieldMapper.java | 4 ---- .../index/mapper/geo/GeoPointFieldMapper.java | 14 -------------- .../mapper/internal/VersionFieldMapper.java | 16 ++-------------- .../index/mapper/object/ObjectMapper.java | 7 ------- .../mapper/externalvalues/ExternalMapper.java | 9 --------- .../externalvalues/ExternalRootMapper.java | 4 ---- 9 files changed, 2 insertions(+), 69 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index 773ff9b1099..0357f8299b9 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -442,10 +442,6 @@ public class DocumentMapper implements ToXContent { public void close() { documentParser.close(); - mapping.root.close(); - for (RootMapper rootMapper : mapping.rootMappers) { - rootMapper.close(); - } } @Override diff --git a/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java b/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java index 55253783909..9155fd8683c 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java @@ -129,6 +129,4 @@ public interface Mapper extends ToXContent, Iterable { String name(); void merge(Mapper mergeWith, MergeResult mergeResult) throws MergeMappingException; - - void close(); } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java index 2c6a865ccd9..21429053c0f 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -564,11 +564,6 @@ public abstract class AbstractFieldMapper implements FieldMapper { protected abstract String contentType(); - @Override - public void close() { - multiFields.close(); - } - public static class MultiFields { public static MultiFields empty() { @@ -702,12 +697,6 @@ public abstract class AbstractFieldMapper implements FieldMapper { }); } - public void close() { - for (ObjectCursor cursor : mappers.values()) { - cursor.value.close(); - } - } - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (pathType != Defaults.PATH_TYPE) { builder.field("path", pathType.name().toLowerCase(Locale.ROOT)); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java index e9d9896a101..5b086ba65d4 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java @@ -335,10 +335,6 @@ public abstract class NumberFieldMapper extends AbstractFieldMapper implements A } } - @Override - public void close() { - } - protected NumericTokenStream popCachedStream() { if (fieldType().numericPrecisionStep() == 4) { return tokenStream4.get(); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java index 6ca88d63d41..d856face38c 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -739,20 +739,6 @@ public class GeoPointFieldMapper extends AbstractFieldMapper implements ArrayVal multiFields.parse(this, context); } - @Override - public void close() { - super.close(); - if (latMapper != null) { - latMapper.close(); - } - if (lonMapper != null) { - lonMapper.close(); - } - if (geohashMapper != null) { - geohashMapper.close(); - } - } - @Override public Iterator iterator() { List extras = new ArrayList<>(); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/internal/VersionFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/internal/VersionFieldMapper.java index 327ef7aebcd..0de26037cd5 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/internal/VersionFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/internal/VersionFieldMapper.java @@ -116,13 +116,6 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe } } - private final ThreadLocal fieldCache = new ThreadLocal() { - @Override - protected Field initialValue() { - return new NumericDocValuesField(NAME, -1L); - } - }; - public VersionFieldMapper(Settings indexSettings) { super(Defaults.FIELD_TYPE, true, null, indexSettings); } @@ -134,8 +127,8 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe @Override protected void parseCreateField(ParseContext context, List fields) throws IOException { - // see UidFieldMapper.parseCreateField - final Field version = fieldCache.get(); + // see InternalEngine.updateVersion to see where the real version value is set + final Field version = new NumericDocValuesField(NAME, -1L); context.version(version); fields.add(version); } @@ -180,9 +173,4 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe public void merge(Mapper mergeWith, MergeResult mergeResult) throws MergeMappingException { // nothing to do } - - @Override - public void close() { - fieldCache.remove(); - } } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index ac887d7d11b..c762e0ab751 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -544,13 +544,6 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea } - @Override - public void close() { - for (Mapper mapper : mappers.values()) { - mapper.close(); - } - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { toXContent(builder, params, null); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java index 9de34988360..a49e8a0a566 100755 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java @@ -236,15 +236,6 @@ public class ExternalMapper extends AbstractFieldMapper { return Iterators.concat(super.iterator(), Lists.newArrayList(binMapper, boolMapper, pointMapper, shapeMapper, stringMapper).iterator()); } - @Override - public void close() { - binMapper.close(); - boolMapper.close(); - pointMapper.close(); - shapeMapper.close(); - stringMapper.close(); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(fieldType().names().shortName()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalRootMapper.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalRootMapper.java index 9e4d43f5189..0395dd22936 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalRootMapper.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalRootMapper.java @@ -52,10 +52,6 @@ public class ExternalRootMapper implements RootMapper { return Collections.emptyIterator(); } - @Override - public void close() { - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return builder.startObject(CONTENT_TYPE).endObject();