diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index 908a25a9abe..857f457ecae 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.cluster.node.info; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.Build; import org.elasticsearch.Version; import org.elasticsearch.action.support.nodes.BaseNodeResponse; @@ -75,7 +76,7 @@ public class NodeInfo extends BaseNodeResponse { NodeInfo() { } - public NodeInfo(Version version, Build build, DiscoveryNode node, @Nullable ImmutableMap serviceAttributes, @Nullable Settings settings, + public NodeInfo(Version version, Build build, DiscoveryNode node, @Nullable Map serviceAttributes, @Nullable Settings settings, @Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable ThreadPoolInfo threadPool, @Nullable TransportInfo transport, @Nullable HttpInfo http, @Nullable PluginsInfo plugins) { super(node); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index e740a4fc67c..6512ee5cef7 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -19,7 +19,6 @@ package org.elasticsearch.cluster.routing; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.collect.MapBuilder; @@ -39,6 +38,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; +import static java.util.Collections.emptyMap; + /** * {@link IndexShardRoutingTable} encapsulates all instances of a single shard. * Each Elasticsearch index consists of multiple shards, each shard encapsulates @@ -60,6 +61,10 @@ public class IndexShardRoutingTable implements Iterable { final static List NO_SHARDS = Collections.emptyList(); final boolean allShardsStarted; + private volatile Map activeShardsByAttributes = emptyMap(); + private volatile Map initializingShardsByAttributes = emptyMap(); + private final Object shardsByAttributeMutex = new Object(); + /** * The initializing list, including ones that are initializing on a target node because of relocation. * If we can come up with a better variable name, it would be nice... @@ -476,10 +481,6 @@ public class IndexShardRoutingTable implements Iterable { } } - private volatile Map activeShardsByAttributes = ImmutableMap.of(); - private volatile Map initializingShardsByAttributes = ImmutableMap.of(); - private final Object shardsByAttributeMutex = new Object(); - private AttributesRoutings getActiveAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = activeShardsByAttributes.get(key); if (shardRoutings == null) { diff --git a/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java b/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java index ea5a664ceb1..3837de81b60 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java +++ b/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java @@ -16,8 +16,6 @@ package org.elasticsearch.common.inject.assistedinject; -import com.google.common.collect.ImmutableMap; - import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Injector; @@ -42,6 +40,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static java.util.Collections.emptyMap; import static java.util.Collections.singleton; import static java.util.Collections.unmodifiableSet; @@ -223,7 +222,7 @@ public class FactoryProvider implements Provider, HasDependencies { } if (constructors.isEmpty()) { - return ImmutableMap.of(); + return emptyMap(); } Method[] factoryMethods = factoryType.getRawType().getMethods(); diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index e36843038da..663abd746f0 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -19,8 +19,6 @@ package org.elasticsearch.common.settings; -import java.nio.charset.StandardCharsets; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.Version; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Strings; @@ -30,20 +28,40 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.property.PropertyPlaceholder; import org.elasticsearch.common.settings.loader.SettingsLoader; import org.elasticsearch.common.settings.loader.SettingsLoaderFactory; -import org.elasticsearch.common.unit.*; +import org.elasticsearch.common.unit.ByteSizeUnit; +import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.unit.MemorySizeValue; +import org.elasticsearch.common.unit.RatioValue; +import org.elasticsearch.common.unit.SizeValue; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static java.util.Collections.emptyMap; +import static java.util.Collections.unmodifiableMap; import static org.elasticsearch.common.Strings.toCamelCase; import static org.elasticsearch.common.unit.ByteSizeValue.parseBytesSizeValue; import static org.elasticsearch.common.unit.SizeValue.parseSizeValue; @@ -70,8 +88,8 @@ public final class Settings implements ToXContent { return settingsRequireUnits; } + private final Map forcedUnderscoreSettings; private SortedMap settings; - private final ImmutableMap forcedUnderscoreSettings; Settings(Map settings) { // we use a sorted map for consistent serialization when using getAsMap() @@ -86,7 +104,7 @@ public final class Settings implements ToXContent { forcedUnderscoreSettings.put(toUnderscoreCase, entry.getValue()); } } - this.forcedUnderscoreSettings = forcedUnderscoreSettings == null ? ImmutableMap.of() : ImmutableMap.copyOf(forcedUnderscoreSettings); + this.forcedUnderscoreSettings = forcedUnderscoreSettings == null ? emptyMap() : unmodifiableMap(forcedUnderscoreSettings); } /** 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 54b2c98b71d..0314f8f6aae 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper; -import com.google.common.collect.ImmutableMap; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; @@ -70,6 +69,8 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.locks.ReentrantReadWriteLock; +import static java.util.Collections.emptyMap; + /** * */ @@ -85,7 +86,7 @@ public class DocumentMapper implements ToXContent { private final RootObjectMapper rootObjectMapper; - private ImmutableMap meta = ImmutableMap.of(); + private Map meta = emptyMap(); private final Mapper.BuilderContext builderContext; @@ -115,7 +116,7 @@ public class DocumentMapper implements ToXContent { this.rootMappers.put(FieldNamesFieldMapper.class, new FieldNamesFieldMapper(indexSettings, mapperService.fullName(FieldNamesFieldMapper.NAME))); } - public Builder meta(ImmutableMap meta) { + public Builder meta(Map meta) { this.meta = meta; return this; } @@ -169,7 +170,7 @@ public class DocumentMapper implements ToXContent { public DocumentMapper(MapperService mapperService, @Nullable Settings indexSettings, DocumentMapperParser docMapperParser, RootObjectMapper rootObjectMapper, - ImmutableMap meta, + Map meta, Map, MetadataFieldMapper> rootMappers, List sourceTransforms, ReentrantReadWriteLock mappingLock) { @@ -234,7 +235,7 @@ public class DocumentMapper implements ToXContent { return this.typeText; } - public ImmutableMap meta() { + public Map meta() { return mapping.meta; } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java index bb991ef2603..ed5c3b3de8f 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.mapper; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; @@ -35,10 +36,33 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.mapper.core.*; +import org.elasticsearch.index.mapper.core.BinaryFieldMapper; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper; +import org.elasticsearch.index.mapper.core.ByteFieldMapper; +import org.elasticsearch.index.mapper.core.CompletionFieldMapper; +import org.elasticsearch.index.mapper.core.DateFieldMapper; +import org.elasticsearch.index.mapper.core.DoubleFieldMapper; +import org.elasticsearch.index.mapper.core.FloatFieldMapper; +import org.elasticsearch.index.mapper.core.IntegerFieldMapper; +import org.elasticsearch.index.mapper.core.LongFieldMapper; +import org.elasticsearch.index.mapper.core.ShortFieldMapper; +import org.elasticsearch.index.mapper.core.StringFieldMapper; +import org.elasticsearch.index.mapper.core.TokenCountFieldMapper; +import org.elasticsearch.index.mapper.core.TypeParsers; import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper; import org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper; -import org.elasticsearch.index.mapper.internal.*; +import org.elasticsearch.index.mapper.internal.AllFieldMapper; +import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper; +import org.elasticsearch.index.mapper.internal.IdFieldMapper; +import org.elasticsearch.index.mapper.internal.IndexFieldMapper; +import org.elasticsearch.index.mapper.internal.ParentFieldMapper; +import org.elasticsearch.index.mapper.internal.RoutingFieldMapper; +import org.elasticsearch.index.mapper.internal.SourceFieldMapper; +import org.elasticsearch.index.mapper.internal.TTLFieldMapper; +import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; +import org.elasticsearch.index.mapper.internal.TypeFieldMapper; +import org.elasticsearch.index.mapper.internal.UidFieldMapper; +import org.elasticsearch.index.mapper.internal.VersionFieldMapper; import org.elasticsearch.index.mapper.ip.IpFieldMapper; import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.index.mapper.object.RootObjectMapper; @@ -47,8 +71,15 @@ import org.elasticsearch.index.similarity.SimilarityLookupService; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import static java.util.Collections.unmodifiableMap; import static org.elasticsearch.index.mapper.MapperBuilders.doc; public class DocumentMapperParser { @@ -240,11 +271,12 @@ public class DocumentMapperParser { } } - ImmutableMap attributes = ImmutableMap.of(); - if (mapping.containsKey("_meta")) { - attributes = ImmutableMap.copyOf((Map) mapping.remove("_meta")); + Map meta = (Map) mapping.remove("_meta"); + if (meta != null) { + // It may not be required to copy meta here to maintain immutability + // but the cost is pretty low here. + docBuilder.meta(unmodifiableMap(new HashMap<>(meta))); } - docBuilder.meta(attributes); checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: "); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/Mapping.java b/core/src/main/java/org/elasticsearch/index/mapper/Mapping.java index c3b22c6f512..412bb56a785 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/Mapping.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/Mapping.java @@ -59,9 +59,9 @@ public final class Mapping implements ToXContent { final MetadataFieldMapper[] metadataMappers; final ImmutableMap, MetadataFieldMapper> rootMappersMap; final SourceTransform[] sourceTransforms; - volatile ImmutableMap meta; + volatile Map meta; - public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, MetadataFieldMapper[] metadataMappers, SourceTransform[] sourceTransforms, ImmutableMap meta) { + public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, MetadataFieldMapper[] metadataMappers, SourceTransform[] sourceTransforms, Map meta) { this.indexCreated = indexCreated; this.root = rootObjectMapper; this.metadataMappers = metadataMappers; @@ -119,7 +119,7 @@ public final class Mapping implements ToXContent { meta = mergeWith.meta; } } - + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { root.toXContent(builder, params, new ToXContent() { diff --git a/core/src/main/java/org/elasticsearch/index/query/ParsedQuery.java b/core/src/main/java/org/elasticsearch/index/query/ParsedQuery.java index d1a4ca5ab1c..1c219268a93 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ParsedQuery.java +++ b/core/src/main/java/org/elasticsearch/index/query/ParsedQuery.java @@ -19,22 +19,31 @@ package org.elasticsearch.index.query; -import com.google.common.collect.ImmutableMap; - import org.apache.lucene.search.Query; import org.elasticsearch.common.lucene.search.Queries; +import java.util.Map; + +import static java.util.Collections.emptyMap; + /** * The result of parsing a query. - * - * */ public class ParsedQuery { - private final Query query; - private final ImmutableMap namedFilters; + private final Map namedFilters; - public ParsedQuery(Query query, ImmutableMap namedFilters) { + /** + * Store the query and filters. + * + * @param query + * the query + * @param namedFilters + * an immutable Map containing the named filters. Good callers + * use emptyMap or unmodifiableMap and copy the source to make + * sure this is immutable. + */ + public ParsedQuery(Query query, Map namedFilters) { this.query = query; this.namedFilters = namedFilters; } @@ -46,7 +55,7 @@ public class ParsedQuery { public ParsedQuery(Query query) { this.query = query; - this.namedFilters = ImmutableMap.of(); + this.namedFilters = emptyMap(); } /** @@ -56,11 +65,11 @@ public class ParsedQuery { return this.query; } - public ImmutableMap namedFilters() { - return this.namedFilters; + public Map namedFilters() { + return namedFilters; } public static ParsedQuery parsedMatchAllQuery() { - return new ParsedQuery(Queries.newMatchAllQuery(), ImmutableMap.of()); + return new ParsedQuery(Queries.newMatchAllQuery(), emptyMap()); } } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 3b24544267d..37941530dd0 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -98,6 +98,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; +import static java.util.Collections.emptyMap; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder; @@ -121,8 +122,8 @@ public class IndicesService extends AbstractLifecycleComponent i private final NodeEnvironment nodeEnv; private final TimeValue shardsClosedTimeout; - private volatile Map indices = ImmutableMap.of(); - + private volatile Map indices = emptyMap(); + static class IndexServiceInjectorPair { private final IndexService indexService; private final Injector injector; @@ -140,7 +141,7 @@ public class IndicesService extends AbstractLifecycleComponent i return injector; } } - + private final Map> pendingDeletes = new HashMap<>(); private final OldShardsStats oldShardsStats = new OldShardsStats(); @@ -347,7 +348,7 @@ public class IndicesService extends AbstractLifecycleComponent i modules.add(new MapperServiceModule()); modules.add(new IndexAliasesServiceModule()); modules.add(new IndexModule(indexSettings)); - + pluginsService.processModules(modules); Injector indexInjector; diff --git a/core/src/main/java/org/elasticsearch/node/service/NodeService.java b/core/src/main/java/org/elasticsearch/node/service/NodeService.java index 369f7e084bf..d394765bcfc 100644 --- a/core/src/main/java/org/elasticsearch/node/service/NodeService.java +++ b/core/src/main/java/org/elasticsearch/node/service/NodeService.java @@ -19,8 +19,6 @@ package org.elasticsearch.node.service; -import com.google.common.collect.ImmutableMap; - import org.elasticsearch.Build; import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; @@ -44,6 +42,8 @@ import org.elasticsearch.transport.TransportService; import java.io.IOException; import java.util.Map; +import static java.util.Collections.emptyMap; + /** */ public class NodeService extends AbstractComponent { @@ -59,7 +59,7 @@ public class NodeService extends AbstractComponent { @Nullable private HttpServer httpServer; - private volatile ImmutableMap serviceAttributes = ImmutableMap.of(); + private volatile Map serviceAttributes = emptyMap(); private final Version version; diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java index b421e4ac7a6..c1194f1f401 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java @@ -19,8 +19,6 @@ package org.elasticsearch.search.internal; -import com.google.common.collect.ImmutableMap; - import org.apache.lucene.search.Explanation; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchParseException; @@ -54,6 +52,8 @@ import java.util.List; import java.util.Map; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; +import static java.util.Collections.unmodifiableMap; import static org.elasticsearch.common.lucene.Lucene.readExplanation; import static org.elasticsearch.common.lucene.Lucene.writeExplanation; import static org.elasticsearch.search.SearchShardTarget.readSearchShardTarget; @@ -317,10 +317,7 @@ public class InternalSearchHit implements SearchHit { @Override public Map highlightFields() { - if (highlightFields == null) { - return ImmutableMap.of(); - } - return this.highlightFields; + return highlightFields == null ? emptyMap() : highlightFields; } @Override @@ -573,69 +570,32 @@ public class InternalSearchHit implements SearchHit { } int size = in.readVInt(); if (size == 0) { - fields = ImmutableMap.of(); + fields = emptyMap(); } else if (size == 1) { SearchHitField hitField = readSearchHitField(in); - fields = ImmutableMap.of(hitField.name(), hitField); - } else if (size == 2) { - SearchHitField hitField1 = readSearchHitField(in); - SearchHitField hitField2 = readSearchHitField(in); - fields = ImmutableMap.of(hitField1.name(), hitField1, hitField2.name(), hitField2); - } else if (size == 3) { - SearchHitField hitField1 = readSearchHitField(in); - SearchHitField hitField2 = readSearchHitField(in); - SearchHitField hitField3 = readSearchHitField(in); - fields = ImmutableMap.of(hitField1.name(), hitField1, hitField2.name(), hitField2, hitField3.name(), hitField3); - } else if (size == 4) { - SearchHitField hitField1 = readSearchHitField(in); - SearchHitField hitField2 = readSearchHitField(in); - SearchHitField hitField3 = readSearchHitField(in); - SearchHitField hitField4 = readSearchHitField(in); - fields = ImmutableMap.of(hitField1.name(), hitField1, hitField2.name(), hitField2, hitField3.name(), hitField3, hitField4.name(), hitField4); - } else if (size == 5) { - SearchHitField hitField1 = readSearchHitField(in); - SearchHitField hitField2 = readSearchHitField(in); - SearchHitField hitField3 = readSearchHitField(in); - SearchHitField hitField4 = readSearchHitField(in); - SearchHitField hitField5 = readSearchHitField(in); - fields = ImmutableMap.of(hitField1.name(), hitField1, hitField2.name(), hitField2, hitField3.name(), hitField3, hitField4.name(), hitField4, hitField5.name(), hitField5); + fields = singletonMap(hitField.name(), hitField); } else { - ImmutableMap.Builder builder = ImmutableMap.builder(); + Map fields = new HashMap<>(); for (int i = 0; i < size; i++) { SearchHitField hitField = readSearchHitField(in); - builder.put(hitField.name(), hitField); + fields.put(hitField.name(), hitField); } - fields = builder.build(); + this.fields = unmodifiableMap(fields); } size = in.readVInt(); if (size == 0) { - highlightFields = ImmutableMap.of(); + highlightFields = emptyMap(); } else if (size == 1) { HighlightField field = readHighlightField(in); - highlightFields = ImmutableMap.of(field.name(), field); - } else if (size == 2) { - HighlightField field1 = readHighlightField(in); - HighlightField field2 = readHighlightField(in); - highlightFields = ImmutableMap.of(field1.name(), field1, field2.name(), field2); - } else if (size == 3) { - HighlightField field1 = readHighlightField(in); - HighlightField field2 = readHighlightField(in); - HighlightField field3 = readHighlightField(in); - highlightFields = ImmutableMap.of(field1.name(), field1, field2.name(), field2, field3.name(), field3); - } else if (size == 4) { - HighlightField field1 = readHighlightField(in); - HighlightField field2 = readHighlightField(in); - HighlightField field3 = readHighlightField(in); - HighlightField field4 = readHighlightField(in); - highlightFields = ImmutableMap.of(field1.name(), field1, field2.name(), field2, field3.name(), field3, field4.name(), field4); + highlightFields = singletonMap(field.name(), field); } else { - ImmutableMap.Builder builder = ImmutableMap.builder(); + Map highlightFields = new HashMap<>(); for (int i = 0; i < size; i++) { HighlightField field = readHighlightField(in); - builder.put(field.name(), field); + highlightFields.put(field.name(), field); } - highlightFields = builder.build(); + this.highlightFields = unmodifiableMap(highlightFields); } size = in.readVInt(); diff --git a/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java index 3b8b2e1b1fa..1c7773e34b8 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -90,6 +90,7 @@ import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CopyOnWriteArrayList; +import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableSet; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_CREATION_DATE; @@ -232,7 +233,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); RoutingTable.Builder rtBuilder = RoutingTable.builder(currentState.routingTable()); - final ImmutableMap shards; + Map shards; Set aliases = new HashSet<>(); if (!renamedIndices.isEmpty()) { // We have some indices to restore @@ -311,7 +312,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis RestoreInProgress.Entry restoreEntry = new RestoreInProgress.Entry(snapshotId, RestoreInProgress.State.INIT, Collections.unmodifiableList(new ArrayList<>(renamedIndices.keySet())), shards); builder.putCustom(RestoreInProgress.TYPE, new RestoreInProgress(restoreEntry)); } else { - shards = ImmutableMap.of(); + shards = emptyMap(); } checkAliasNameConflicts(renamedIndices, aliases);