Remove ImmutableMap#copyOf from core/src/main
Mostly favoring unmodifiableMap and making sure to only wrap maps that aren't otherwise returned and so cannot be copied. MapMaker#immutableMap has to go next.
This commit is contained in:
parent
ab7fa7fe9e
commit
a378cc6866
|
@ -25,16 +25,18 @@ import org.elasticsearch.action.support.HandledTransportAction;
|
|||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TransportGetFieldMappingsAction extends HandledTransportAction<GetFieldMappingsRequest, GetFieldMappingsResponse> {
|
||||
|
@ -88,7 +90,7 @@ public class TransportGetFieldMappingsAction extends HandledTransportAction<GetF
|
|||
}
|
||||
|
||||
private GetFieldMappingsResponse merge(AtomicReferenceArray<Object> indexResponses) {
|
||||
MapBuilder<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mergedResponses = MapBuilder.newMapBuilder();
|
||||
Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mergedResponses = new HashMap<>();
|
||||
for (int i = 0; i < indexResponses.length(); i++) {
|
||||
Object element = indexResponses.get(i);
|
||||
if (element instanceof GetFieldMappingsResponse) {
|
||||
|
@ -96,6 +98,6 @@ public class TransportGetFieldMappingsAction extends HandledTransportAction<GetF
|
|||
mergedResponses.putAll(response.mappings());
|
||||
}
|
||||
}
|
||||
return new GetFieldMappingsResponse(mergedResponses.immutableMap());
|
||||
return new GetFieldMappingsResponse(unmodifiableMap(mergedResponses));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,17 +30,19 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NodeClient extends AbstractClient {
|
||||
|
||||
private final ImmutableMap<GenericAction, TransportAction> actions;
|
||||
private final Map<GenericAction, TransportAction> actions;
|
||||
|
||||
@Inject
|
||||
public NodeClient(Settings settings, ThreadPool threadPool, Headers headers, Map<GenericAction, TransportAction> actions) {
|
||||
super(settings, threadPool, headers);
|
||||
this.actions = ImmutableMap.copyOf(actions);
|
||||
this.actions = unmodifiableMap(actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.cluster;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterState.Custom;
|
||||
import org.elasticsearch.cluster.metadata.SnapshotId;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -33,10 +31,12 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* Meta data about restore processes that are currently executing
|
||||
|
@ -419,14 +419,14 @@ public class RestoreInProgress extends AbstractDiffable<Custom> implements Custo
|
|||
for (int j = 0; j < indices; j++) {
|
||||
indexBuilder.add(in.readString());
|
||||
}
|
||||
ImmutableMap.Builder<ShardId, ShardRestoreStatus> builder = ImmutableMap.<ShardId, ShardRestoreStatus>builder();
|
||||
Map<ShardId, ShardRestoreStatus> builder = new HashMap<>();
|
||||
int shards = in.readVInt();
|
||||
for (int j = 0; j < shards; j++) {
|
||||
ShardId shardId = ShardId.readShardId(in);
|
||||
ShardRestoreStatus shardState = ShardRestoreStatus.readShardRestoreStatus(in);
|
||||
builder.put(shardId, shardState);
|
||||
}
|
||||
entries[i] = new Entry(snapshotId, state, Collections.unmodifiableList(indexBuilder), builder.build());
|
||||
entries[i] = new Entry(snapshotId, state, Collections.unmodifiableList(indexBuilder), unmodifiableMap(builder));
|
||||
}
|
||||
return new RestoreInProgress(entries);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
package org.elasticsearch.common.collect;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -83,7 +83,7 @@ public class MapBuilder<K, V> {
|
|||
return this.map;
|
||||
}
|
||||
|
||||
public ImmutableMap<K, V> immutableMap() {
|
||||
return ImmutableMap.copyOf(map);
|
||||
public Map<K, V> immutableMap() {
|
||||
return unmodifiableMap(new HashMap<>(map));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.elasticsearch.common.inject.internal;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.inject.Key;
|
||||
|
@ -25,7 +24,15 @@ import org.elasticsearch.common.inject.spi.Element;
|
|||
import org.elasticsearch.common.inject.spi.ElementVisitor;
|
||||
import org.elasticsearch.common.inject.spi.PrivateElements;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* @author jessewilson@google.com (Jesse Wilson)
|
||||
|
@ -92,7 +99,7 @@ public final class PrivateElementsImpl implements PrivateElements {
|
|||
for (ExposureBuilder<?> exposureBuilder : exposureBuilders) {
|
||||
exposedKeysToSourcesMutable.put(exposureBuilder.getKey(), exposureBuilder.getSource());
|
||||
}
|
||||
exposedKeysToSources = ImmutableMap.copyOf(exposedKeysToSourcesMutable);
|
||||
exposedKeysToSources = unmodifiableMap(exposedKeysToSourcesMutable);
|
||||
exposureBuilders = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.gateway;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -36,6 +34,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* The dangling indices state is responsible for finding new dangling indices (indices that have
|
||||
|
@ -76,7 +75,8 @@ public class DanglingIndicesState extends AbstractComponent {
|
|||
* The current set of dangling indices.
|
||||
*/
|
||||
Map<String, IndexMetaData> getDanglingIndices() {
|
||||
return ImmutableMap.copyOf(danglingIndices);
|
||||
// This might be a good use case for CopyOnWriteHashMap
|
||||
return unmodifiableMap(new HashMap<>(danglingIndices));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.http;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
|
@ -28,18 +26,29 @@ import org.elasticsearch.common.io.Streams;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestFilter;
|
||||
import org.elasticsearch.rest.RestFilterChain;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.rest.RestStatus.*;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.elasticsearch.rest.RestStatus.FORBIDDEN;
|
||||
import static org.elasticsearch.rest.RestStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -204,7 +213,7 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
|
|||
final String separator = siteFile.getFileSystem().getSeparator();
|
||||
// Convert file separators.
|
||||
sitePath = sitePath.replace("/", separator);
|
||||
|
||||
|
||||
Path file = siteFile.resolve(sitePath);
|
||||
|
||||
// return not found instead of forbidden to prevent malicious requests to find out if files exist or dont exist
|
||||
|
@ -275,7 +284,7 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
|
|||
mimeTypes.put("svg", "image/svg+xml");
|
||||
mimeTypes.put("ico", "image/vnd.microsoft.icon");
|
||||
mimeTypes.put("mp3", "audio/mpeg");
|
||||
DEFAULT_MIME_TYPES = ImmutableMap.copyOf(mimeTypes);
|
||||
DEFAULT_MIME_TYPES = unmodifiableMap(mimeTypes);
|
||||
}
|
||||
|
||||
public static final Map<String, String> DEFAULT_MIME_TYPES;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.analysis;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -37,15 +36,17 @@ import java.io.Closeable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AnalysisService extends AbstractIndexComponent implements Closeable {
|
||||
|
||||
private final ImmutableMap<String, NamedAnalyzer> analyzers;
|
||||
private final ImmutableMap<String, TokenizerFactory> tokenizers;
|
||||
private final ImmutableMap<String, CharFilterFactory> charFilters;
|
||||
private final ImmutableMap<String, TokenFilterFactory> tokenFilters;
|
||||
private final Map<String, NamedAnalyzer> analyzers;
|
||||
private final Map<String, TokenizerFactory> tokenizers;
|
||||
private final Map<String, CharFilterFactory> charFilters;
|
||||
private final Map<String, TokenFilterFactory> tokenFilters;
|
||||
|
||||
private final NamedAnalyzer defaultAnalyzer;
|
||||
private final NamedAnalyzer defaultIndexAnalyzer;
|
||||
|
@ -98,7 +99,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
|
|||
}
|
||||
}
|
||||
|
||||
this.tokenizers = ImmutableMap.copyOf(tokenizers);
|
||||
this.tokenizers = unmodifiableMap(tokenizers);
|
||||
|
||||
Map<String, CharFilterFactory> charFilters = new HashMap<>();
|
||||
if (charFilterFactoryFactories != null) {
|
||||
|
@ -133,7 +134,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
|
|||
}
|
||||
}
|
||||
|
||||
this.charFilters = ImmutableMap.copyOf(charFilters);
|
||||
this.charFilters = unmodifiableMap(charFilters);
|
||||
|
||||
Map<String, TokenFilterFactory> tokenFilters = new HashMap<>();
|
||||
if (tokenFilterFactoryFactories != null) {
|
||||
|
@ -168,7 +169,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
|
|||
}
|
||||
}
|
||||
}
|
||||
this.tokenFilters = ImmutableMap.copyOf(tokenFilters);
|
||||
this.tokenFilters = unmodifiableMap(tokenFilters);
|
||||
|
||||
Map<String, AnalyzerProvider> analyzerProviders = new HashMap<>();
|
||||
if (analyzerFactoryFactories != null) {
|
||||
|
@ -275,7 +276,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
|
|||
throw new IllegalArgumentException("analyzer name must not start with '_'. got \"" + analyzer.getKey() + "\"");
|
||||
}
|
||||
}
|
||||
this.analyzers = ImmutableMap.copyOf(analyzers);
|
||||
this.analyzers = unmodifiableMap(analyzers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,10 +19,8 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.util.Accountable;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -41,6 +39,7 @@ import org.elasticsearch.index.fielddata.plain.PackedArrayIndexFieldData;
|
|||
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
|
||||
import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType.Names;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.core.BooleanFieldMapper;
|
||||
import org.elasticsearch.index.mapper.internal.IndexFieldMapper;
|
||||
|
@ -56,7 +55,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.mapper.MappedFieldType.Names;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -70,26 +69,28 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||
private static final String ARRAY_FORMAT = "array";
|
||||
private static final String PAGED_BYTES_FORMAT = "paged_bytes";
|
||||
|
||||
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;
|
||||
private final static Map<String, IndexFieldData.Builder> buildersByType;
|
||||
private final static Map<String, IndexFieldData.Builder> docValuesBuildersByType;
|
||||
private final static Map<Tuple<String, String>, IndexFieldData.Builder> buildersByTypeAndFormat;
|
||||
private final CircuitBreakerService circuitBreakerService;
|
||||
|
||||
static {
|
||||
buildersByType = MapBuilder.<String, IndexFieldData.Builder>newMapBuilder()
|
||||
.put("string", new PagedBytesIndexFieldData.Builder())
|
||||
.put("float", new FloatArrayIndexFieldData.Builder())
|
||||
.put("double", new DoubleArrayIndexFieldData.Builder())
|
||||
.put("byte", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.BYTE))
|
||||
.put("short", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.SHORT))
|
||||
.put("int", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.INT))
|
||||
.put("long", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.LONG))
|
||||
.put("geo_point", new GeoPointDoubleArrayIndexFieldData.Builder())
|
||||
.put(ParentFieldMapper.NAME, new ParentChildIndexFieldData.Builder())
|
||||
.put(IndexFieldMapper.NAME, new IndexIndexFieldData.Builder())
|
||||
.put("binary", new DisabledIndexFieldData.Builder())
|
||||
.put(BooleanFieldMapper.CONTENT_TYPE, new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.BOOLEAN))
|
||||
.immutableMap();
|
||||
Map<String, IndexFieldData.Builder> buildersByTypeBuilder = new HashMap<>();
|
||||
buildersByTypeBuilder.put("string", new PagedBytesIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put("float", new FloatArrayIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put("double", new DoubleArrayIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put("byte", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.BYTE));
|
||||
buildersByTypeBuilder.put("short", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.SHORT));
|
||||
buildersByTypeBuilder.put("int", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.INT));
|
||||
buildersByTypeBuilder.put("long", new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.LONG));
|
||||
buildersByTypeBuilder.put("geo_point", new GeoPointDoubleArrayIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put(ParentFieldMapper.NAME, new ParentChildIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put(IndexFieldMapper.NAME, new IndexIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put("binary", new DisabledIndexFieldData.Builder());
|
||||
buildersByTypeBuilder.put(BooleanFieldMapper.CONTENT_TYPE,
|
||||
new PackedArrayIndexFieldData.Builder().setNumericType(IndexNumericFieldData.NumericType.BOOLEAN));
|
||||
buildersByType = unmodifiableMap(buildersByTypeBuilder);
|
||||
|
||||
|
||||
docValuesBuildersByType = MapBuilder.<String, IndexFieldData.Builder>newMapBuilder()
|
||||
.put("string", new DocValuesIndexFieldData.Builder())
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.queryparser.classic.MapperQueryParser;
|
||||
import org.apache.lucene.queryparser.classic.QueryParserSettings;
|
||||
|
@ -37,7 +36,11 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.analysis.AnalysisService;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.mapper.ContentPath;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.Mapper;
|
||||
import org.elasticsearch.index.mapper.MapperBuilders;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||
import org.elasticsearch.index.mapper.object.ObjectMapper;
|
||||
import org.elasticsearch.index.query.support.NestedScope;
|
||||
|
@ -54,6 +57,8 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* Context object used to create lucene queries on the shard level.
|
||||
*/
|
||||
|
@ -186,8 +191,9 @@ public class QueryShardContext {
|
|||
}
|
||||
}
|
||||
|
||||
public ImmutableMap<String, Query> copyNamedQueries() {
|
||||
return ImmutableMap.copyOf(namedQueries);
|
||||
public Map<String, Query> copyNamedQueries() {
|
||||
// This might be a good use case for CopyOnWriteHashMap
|
||||
return unmodifiableMap(new HashMap<>(namedQueries));
|
||||
}
|
||||
|
||||
public void combineNamedQueries(QueryShardContext context) {
|
||||
|
|
|
@ -19,13 +19,29 @@
|
|||
|
||||
package org.elasticsearch.index.similarity;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.search.similarities.*;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.apache.lucene.search.similarities.AfterEffect;
|
||||
import org.apache.lucene.search.similarities.AfterEffectB;
|
||||
import org.apache.lucene.search.similarities.AfterEffectL;
|
||||
import org.apache.lucene.search.similarities.BasicModel;
|
||||
import org.apache.lucene.search.similarities.BasicModelBE;
|
||||
import org.apache.lucene.search.similarities.BasicModelD;
|
||||
import org.apache.lucene.search.similarities.BasicModelG;
|
||||
import org.apache.lucene.search.similarities.BasicModelIF;
|
||||
import org.apache.lucene.search.similarities.BasicModelIn;
|
||||
import org.apache.lucene.search.similarities.BasicModelIne;
|
||||
import org.apache.lucene.search.similarities.BasicModelP;
|
||||
import org.apache.lucene.search.similarities.DFRSimilarity;
|
||||
import org.apache.lucene.search.similarities.Normalization;
|
||||
import org.apache.lucene.search.similarities.Similarity;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.assistedinject.Assisted;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* {@link SimilarityProvider} for {@link DFRSimilarity}.
|
||||
* <p>
|
||||
|
@ -38,12 +54,11 @@ import org.elasticsearch.common.settings.Settings;
|
|||
* @see DFRSimilarity For more information about configuration
|
||||
*/
|
||||
public class DFRSimilarityProvider extends AbstractSimilarityProvider {
|
||||
|
||||
private static final ImmutableMap<String, BasicModel> MODEL_CACHE;
|
||||
private static final ImmutableMap<String, AfterEffect> EFFECT_CACHE;
|
||||
private static final Map<String, BasicModel> MODEL_CACHE;
|
||||
private static final Map<String, AfterEffect> EFFECT_CACHE;
|
||||
|
||||
static {
|
||||
MapBuilder<String, BasicModel> models = MapBuilder.newMapBuilder();
|
||||
Map<String, BasicModel> models = new HashMap<>();
|
||||
models.put("be", new BasicModelBE());
|
||||
models.put("d", new BasicModelD());
|
||||
models.put("g", new BasicModelG());
|
||||
|
@ -51,13 +66,13 @@ public class DFRSimilarityProvider extends AbstractSimilarityProvider {
|
|||
models.put("in", new BasicModelIn());
|
||||
models.put("ine", new BasicModelIne());
|
||||
models.put("p", new BasicModelP());
|
||||
MODEL_CACHE = models.immutableMap();
|
||||
MODEL_CACHE = unmodifiableMap(models);
|
||||
|
||||
MapBuilder<String, AfterEffect> effects = MapBuilder.newMapBuilder();
|
||||
Map<String, AfterEffect> effects = new HashMap<>();
|
||||
effects.put("no", new AfterEffect.NoAfterEffect());
|
||||
effects.put("b", new AfterEffectB());
|
||||
effects.put("l", new AfterEffectL());
|
||||
EFFECT_CACHE = effects.immutableMap();
|
||||
EFFECT_CACHE = unmodifiableMap(effects);
|
||||
}
|
||||
|
||||
private final DFRSimilarity similarity;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.snapshots.blobstore;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
|
@ -38,6 +37,8 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* Contains information about all snapshot for the given shard in repository
|
||||
* <p>
|
||||
|
@ -77,15 +78,15 @@ public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, To
|
|||
physicalFileList.add(newFiles.get(fileInfo.name()));
|
||||
}
|
||||
}
|
||||
ImmutableMap.Builder<String, List<FileInfo>> mapBuilder = ImmutableMap.builder();
|
||||
Map<String, List<FileInfo>> mapBuilder = new HashMap<>();
|
||||
for (Map.Entry<String, List<FileInfo>> entry : physicalFiles.entrySet()) {
|
||||
mapBuilder.put(entry.getKey(), Collections.unmodifiableList(new ArrayList<>(entry.getValue())));
|
||||
}
|
||||
this.physicalFiles = mapBuilder.build();
|
||||
this.files = ImmutableMap.copyOf(newFiles);
|
||||
this.physicalFiles = unmodifiableMap(mapBuilder);
|
||||
this.files = unmodifiableMap(newFiles);
|
||||
}
|
||||
|
||||
private BlobStoreIndexShardSnapshots(ImmutableMap<String, FileInfo> files, List<SnapshotFiles> shardSnapshots) {
|
||||
private BlobStoreIndexShardSnapshots(Map<String, FileInfo> files, List<SnapshotFiles> shardSnapshots) {
|
||||
this.shardSnapshots = shardSnapshots;
|
||||
this.files = files;
|
||||
Map<String, List<FileInfo>> physicalFiles = new HashMap<>();
|
||||
|
@ -99,11 +100,11 @@ public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, To
|
|||
physicalFileList.add(files.get(fileInfo.name()));
|
||||
}
|
||||
}
|
||||
ImmutableMap.Builder<String, List<FileInfo>> mapBuilder = ImmutableMap.builder();
|
||||
Map<String, List<FileInfo>> mapBuilder = new HashMap<>();
|
||||
for (Map.Entry<String, List<FileInfo>> entry : physicalFiles.entrySet()) {
|
||||
mapBuilder.put(entry.getKey(), Collections.unmodifiableList(new ArrayList<>(entry.getValue())));
|
||||
}
|
||||
this.physicalFiles = mapBuilder.build();
|
||||
this.physicalFiles = unmodifiableMap(mapBuilder);
|
||||
}
|
||||
|
||||
private BlobStoreIndexShardSnapshots() {
|
||||
|
@ -232,13 +233,14 @@ public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, To
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlobStoreIndexShardSnapshots fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException {
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == null) { // New parser
|
||||
token = parser.nextToken();
|
||||
}
|
||||
Map<String, List<String>> snapshotsMap = new HashMap<>();
|
||||
ImmutableMap.Builder<String, FileInfo> filesBuilder = ImmutableMap.builder();
|
||||
Map<String, FileInfo> files = new HashMap<>();
|
||||
if (token == XContentParser.Token.START_OBJECT) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token != XContentParser.Token.FIELD_NAME) {
|
||||
|
@ -252,7 +254,7 @@ public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, To
|
|||
}
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
FileInfo fileInfo = FileInfo.fromXContent(parser);
|
||||
filesBuilder.put(fileInfo.name(), fileInfo);
|
||||
files.put(fileInfo.name(), fileInfo);
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseFieldMatcher.match(currentFieldName, ParseFields.SNAPSHOTS) == false) {
|
||||
|
@ -288,7 +290,6 @@ public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, To
|
|||
}
|
||||
}
|
||||
|
||||
ImmutableMap<String, FileInfo> files = filesBuilder.build();
|
||||
List<SnapshotFiles> snapshots = new ArrayList<>();
|
||||
for (Map.Entry<String, List<String>> entry : snapshotsMap.entrySet()) {
|
||||
List<FileInfo> fileInfosBuilder = new ArrayList<>();
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.lucene.store.LockObtainFailedException;
|
||||
import org.apache.lucene.util.CollectionUtil;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
@ -99,6 +97,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
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;
|
||||
|
@ -389,11 +388,11 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
|
|||
}
|
||||
|
||||
logger.debug("[{}] closing ... (reason [{}])", index, reason);
|
||||
Map<String, IndexServiceInjectorPair> tmpMap = new HashMap<>(indices);
|
||||
IndexServiceInjectorPair remove = tmpMap.remove(index);
|
||||
Map<String, IndexServiceInjectorPair> newIndices = new HashMap<>(indices);
|
||||
IndexServiceInjectorPair remove = newIndices.remove(index);
|
||||
indexService = remove.getIndexService();
|
||||
indexInjector = remove.getInjector();
|
||||
indices = ImmutableMap.copyOf(tmpMap);
|
||||
indices = unmodifiableMap(newIndices);
|
||||
}
|
||||
|
||||
indicesLifecycle.beforeIndexClosed(indexService);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.indices.query;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
|
@ -32,12 +31,13 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class IndicesQueriesRegistry extends AbstractComponent {
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
private ImmutableMap<String, QueryParser<?>> queryParsers;
|
||||
public class IndicesQueriesRegistry extends AbstractComponent {
|
||||
private Map<String, QueryParser<?>> queryParsers;
|
||||
|
||||
@Inject
|
||||
public IndicesQueriesRegistry(Settings settings, Set<QueryParser> injectedQueryParsers, NamedWriteableRegistry namedWriteableRegistry) {
|
||||
public IndicesQueriesRegistry(Settings settings, Set<QueryParser<?>> injectedQueryParsers, NamedWriteableRegistry namedWriteableRegistry) {
|
||||
super(settings);
|
||||
Map<String, QueryParser<?>> queryParsers = new HashMap<>();
|
||||
for (QueryParser<?> queryParser : injectedQueryParsers) {
|
||||
|
@ -49,13 +49,13 @@ public class IndicesQueriesRegistry extends AbstractComponent {
|
|||
// EmptyQueryBuilder is not registered as query parser but used internally.
|
||||
// We need to register it with the NamedWriteableRegistry in order to serialize it
|
||||
namedWriteableRegistry.registerPrototype(QueryBuilder.class, EmptyQueryBuilder.PROTOTYPE);
|
||||
this.queryParsers = ImmutableMap.copyOf(queryParsers);
|
||||
this.queryParsers = unmodifiableMap(queryParsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the registered query parsers
|
||||
*/
|
||||
public ImmutableMap<String, QueryParser<?>> queryParsers() {
|
||||
public Map<String, QueryParser<?>> queryParsers() {
|
||||
return queryParsers;
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
|
|||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -40,9 +39,11 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -93,11 +94,15 @@ public class NodeService extends AbstractComponent {
|
|||
}
|
||||
|
||||
public synchronized void putAttribute(String key, String value) {
|
||||
serviceAttributes = new MapBuilder<>(serviceAttributes).put(key, value).immutableMap();
|
||||
Map<String, String> newServiceAttributes = new HashMap<>(serviceAttributes);
|
||||
newServiceAttributes.put(key, value);
|
||||
serviceAttributes = unmodifiableMap(newServiceAttributes);
|
||||
}
|
||||
|
||||
public synchronized void removeAttribute(String key) {
|
||||
serviceAttributes = new MapBuilder<>(serviceAttributes).remove(key).immutableMap();
|
||||
Map<String, String> newServiceAttributes = new HashMap<>(serviceAttributes);
|
||||
newServiceAttributes.remove(key);
|
||||
serviceAttributes = unmodifiableMap(newServiceAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -31,6 +29,8 @@ import org.elasticsearch.search.lookup.SearchLookup;
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* A native script engine service.
|
||||
*/
|
||||
|
@ -38,12 +38,12 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri
|
|||
|
||||
public static final String NAME = "native";
|
||||
|
||||
private final ImmutableMap<String, NativeScriptFactory> scripts;
|
||||
private final Map<String, NativeScriptFactory> scripts;
|
||||
|
||||
@Inject
|
||||
public NativeScriptEngineService(Settings settings, Map<String, NativeScriptFactory> scripts) {
|
||||
super(settings);
|
||||
this.scripts = ImmutableMap.copyOf(scripts);
|
||||
this.scripts = unmodifiableMap(scripts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,15 +19,13 @@
|
|||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +36,7 @@ import static java.util.Collections.unmodifiableSet;
|
|||
public final class ScriptContextRegistry {
|
||||
static final Set<String> RESERVED_SCRIPT_CONTEXTS = reservedScriptContexts();
|
||||
|
||||
private final ImmutableMap<String, ScriptContext> scriptContexts;
|
||||
private final Map<String, ScriptContext> scriptContexts;
|
||||
|
||||
public ScriptContextRegistry(Collection<ScriptContext.Plugin> customScriptContexts) {
|
||||
Map<String, ScriptContext> scriptContexts = new HashMap<>();
|
||||
|
@ -52,13 +50,13 @@ public final class ScriptContextRegistry {
|
|||
throw new IllegalArgumentException("script context [" + customScriptContext.getKey() + "] cannot be registered twice");
|
||||
}
|
||||
}
|
||||
this.scriptContexts = ImmutableMap.copyOf(scriptContexts);
|
||||
this.scriptContexts = unmodifiableMap(scriptContexts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list that contains all the supported {@link ScriptContext}s, both standard ones and registered via plugins
|
||||
*/
|
||||
ImmutableCollection<ScriptContext> scriptContexts() {
|
||||
Collection<ScriptContext> scriptContexts() {
|
||||
return scriptContexts.values();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
|
@ -29,6 +28,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* Holds the {@link org.elasticsearch.script.ScriptMode}s for each of the different scripting languages available,
|
||||
* each script source and each scripted operation.
|
||||
|
@ -38,7 +39,7 @@ public class ScriptModes {
|
|||
static final String SCRIPT_SETTINGS_PREFIX = "script.";
|
||||
static final String ENGINE_SETTINGS_PREFIX = "script.engine";
|
||||
|
||||
final ImmutableMap<String, ScriptMode> scriptModes;
|
||||
final Map<String, ScriptMode> scriptModes;
|
||||
|
||||
ScriptModes(Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Settings settings) {
|
||||
//filter out the native engine as we don't want to apply fine grained settings to it.
|
||||
|
@ -48,7 +49,7 @@ public class ScriptModes {
|
|||
this.scriptModes = buildScriptModeSettingsMap(settings, filteredEngines, scriptContextRegistry);
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, ScriptMode> buildScriptModeSettingsMap(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry) {
|
||||
private static Map<String, ScriptMode> buildScriptModeSettingsMap(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry) {
|
||||
HashMap<String, ScriptMode> scriptModesMap = new HashMap<>();
|
||||
|
||||
//file scripts are enabled by default, for any language
|
||||
|
@ -61,7 +62,7 @@ public class ScriptModes {
|
|||
processSourceBasedGlobalSettings(settings, scriptEngines, scriptContextRegistry, scriptModesMap);
|
||||
processOperationBasedGlobalSettings(settings, scriptEngines, scriptContextRegistry, scriptModesMap);
|
||||
processEngineSpecificSettings(settings, scriptEngines, scriptContextRegistry, scriptModesMap);
|
||||
return ImmutableMap.copyOf(scriptModesMap);
|
||||
return unmodifiableMap(scriptModesMap);
|
||||
}
|
||||
|
||||
private static void processSourceBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Map<String, ScriptMode> scriptModes) {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.search;
|
|||
import com.carrotsearch.hppc.ObjectHashSet;
|
||||
import com.carrotsearch.hppc.ObjectSet;
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
|
@ -112,6 +111,7 @@ import java.util.concurrent.Executor;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.elasticsearch.common.Strings.hasLength;
|
||||
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
|
||||
import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes;
|
||||
|
@ -160,7 +160,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
|||
|
||||
private final ConcurrentMapLong<SearchContext> activeContexts = ConcurrentCollections.newConcurrentMapLongWithAggressiveConcurrency();
|
||||
|
||||
private final ImmutableMap<String, SearchParseElement> elementParsers;
|
||||
private final Map<String, SearchParseElement> elementParsers;
|
||||
|
||||
private final ParseFieldMatcher parseFieldMatcher;
|
||||
|
||||
|
@ -212,7 +212,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
|||
elementParsers.putAll(queryPhase.parseElements());
|
||||
elementParsers.putAll(fetchPhase.parseElements());
|
||||
elementParsers.put("stats", new StatsGroupsParseElement());
|
||||
this.elementParsers = ImmutableMap.copyOf(elementParsers);
|
||||
this.elementParsers = unmodifiableMap(elementParsers);
|
||||
|
||||
this.keepAliveReaper = threadPool.scheduleWithFixedDelay(new Reaper(), keepAliveInterval);
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.carrotsearch.hppc.IntHashSet;
|
|||
import com.carrotsearch.hppc.IntSet;
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -91,6 +90,7 @@ import java.util.concurrent.BlockingQueue;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
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;
|
||||
|
@ -237,7 +237,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
Set<String> aliases = new HashSet<>();
|
||||
if (!renamedIndices.isEmpty()) {
|
||||
// We have some indices to restore
|
||||
ImmutableMap.Builder<ShardId, RestoreInProgress.ShardRestoreStatus> shardsBuilder = ImmutableMap.builder();
|
||||
Map<ShardId, RestoreInProgress.ShardRestoreStatus> shardsBuilder = new HashMap<>();
|
||||
for (Map.Entry<String, String> indexEntry : renamedIndices.entrySet()) {
|
||||
String index = indexEntry.getValue();
|
||||
boolean partial = checkPartial(index);
|
||||
|
@ -308,7 +308,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
}
|
||||
}
|
||||
|
||||
shards = shardsBuilder.build();
|
||||
shards = unmodifiableMap(shardsBuilder);
|
||||
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 {
|
||||
|
@ -574,7 +574,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
|
||||
if (shards != null) {
|
||||
if (!completed(shards)) {
|
||||
entries.add(new RestoreInProgress.Entry(entry.snapshotId(), RestoreInProgress.State.STARTED, entry.indices(), ImmutableMap.copyOf(shards)));
|
||||
entries.add(new RestoreInProgress.Entry(entry.snapshotId(), RestoreInProgress.State.STARTED, entry.indices(), unmodifiableMap(shards)));
|
||||
} else {
|
||||
logger.info("restore [{}] is done", entry.snapshotId());
|
||||
if (batchedRestoreInfo == null) {
|
||||
|
@ -746,7 +746,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
// Some indices were deleted, let's make sure all indices that we are restoring still exist
|
||||
for (RestoreInProgress.Entry entry : restore.entries()) {
|
||||
List<ShardId> shardsToFail = null;
|
||||
for (ImmutableMap.Entry<ShardId, ShardRestoreStatus> shard : entry.shards().entrySet()) {
|
||||
for (Map.Entry<ShardId, ShardRestoreStatus> shard : entry.shards().entrySet()) {
|
||||
if (!shard.getValue().state().completed()) {
|
||||
if (!event.state().metaData().hasIndex(shard.getKey().getIndex())) {
|
||||
if (shardsToFail == null) {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.snapshots;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.lucene.index.IndexCommit;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
|
@ -71,6 +70,7 @@ import java.util.concurrent.locks.Lock;
|
|||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.elasticsearch.cluster.SnapshotsInProgress.completed;
|
||||
|
||||
/**
|
||||
|
@ -227,15 +227,15 @@ public class SnapshotShardsService extends AbstractLifecycleComponent<SnapshotSh
|
|||
newSnapshots.put(entry.snapshotId(), startedShards);
|
||||
if (snapshotShards != null) {
|
||||
// We already saw this snapshot but we need to add more started shards
|
||||
ImmutableMap.Builder<ShardId, IndexShardSnapshotStatus> shards = ImmutableMap.builder();
|
||||
Map<ShardId, IndexShardSnapshotStatus> shards = new HashMap<>();
|
||||
// Put all shards that were already running on this node
|
||||
shards.putAll(snapshotShards.shards);
|
||||
// Put all newly started shards
|
||||
shards.putAll(startedShards);
|
||||
survivors.put(entry.snapshotId(), new SnapshotShards(shards.build()));
|
||||
survivors.put(entry.snapshotId(), new SnapshotShards(unmodifiableMap(shards)));
|
||||
} else {
|
||||
// Brand new snapshot that we haven't seen before
|
||||
survivors.put(entry.snapshotId(), new SnapshotShards(ImmutableMap.copyOf(startedShards)));
|
||||
survivors.put(entry.snapshotId(), new SnapshotShards(unmodifiableMap(startedShards)));
|
||||
}
|
||||
}
|
||||
} else if (entry.state() == SnapshotsInProgress.State.ABORTED) {
|
||||
|
@ -277,7 +277,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent<SnapshotSh
|
|||
// If startup of these shards fails later, we don't want to try starting these shards again
|
||||
shutdownLock.lock();
|
||||
try {
|
||||
shardSnapshots = ImmutableMap.copyOf(survivors);
|
||||
shardSnapshots = unmodifiableMap(survivors);
|
||||
if (shardSnapshots.isEmpty()) {
|
||||
// Notify all waiting threads that no more snapshots
|
||||
shutdownCondition.signalAll();
|
||||
|
@ -404,7 +404,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent<SnapshotSh
|
|||
private static class SnapshotShards {
|
||||
private final Map<ShardId, IndexShardSnapshotStatus> shards;
|
||||
|
||||
private SnapshotShards(ImmutableMap<ShardId, IndexShardSnapshotStatus> shards) {
|
||||
private SnapshotShards(Map<ShardId, IndexShardSnapshotStatus> shards) {
|
||||
this.shards = shards;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.threadpool;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.util.Counter;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -57,7 +56,7 @@ import java.util.concurrent.ThreadFactory;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.common.unit.SizeValue.parseSizeValue;
|
||||
import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes;
|
||||
|
@ -89,7 +88,7 @@ public class ThreadPool extends AbstractComponent {
|
|||
|
||||
public static final String THREADPOOL_GROUP = "threadpool.";
|
||||
|
||||
private volatile ImmutableMap<String, ExecutorHolder> executors;
|
||||
private volatile Map<String, ExecutorHolder> executors;
|
||||
|
||||
private final Map<String, Settings> defaultExecutorTypeSettings;
|
||||
|
||||
|
@ -118,26 +117,38 @@ public class ThreadPool extends AbstractComponent {
|
|||
int availableProcessors = EsExecutors.boundedNumberOfProcessors(settings);
|
||||
int halfProcMaxAt5 = Math.min(((availableProcessors + 1) / 2), 5);
|
||||
int halfProcMaxAt10 = Math.min(((availableProcessors + 1) / 2), 10);
|
||||
defaultExecutorTypeSettings = ImmutableMap.<String, Settings>builder()
|
||||
.put(Names.GENERIC, settingsBuilder().put("type", "cached").put("keep_alive", "30s").build())
|
||||
.put(Names.INDEX, settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 200).build())
|
||||
.put(Names.BULK, settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 50).build())
|
||||
.put(Names.GET, settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 1000).build())
|
||||
.put(Names.SEARCH, settingsBuilder().put("type", "fixed").put("size", ((availableProcessors * 3) / 2) + 1).put("queue_size", 1000).build())
|
||||
.put(Names.SUGGEST, settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 1000).build())
|
||||
.put(Names.PERCOLATE, settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 1000).build())
|
||||
.put(Names.MANAGEMENT, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", 5).build())
|
||||
// no queue as this means clients will need to handle rejections on listener queue even if the operation succeeded
|
||||
// the assumption here is that the listeners should be very lightweight on the listeners side
|
||||
.put(Names.LISTENER, settingsBuilder().put("type", "fixed").put("size", halfProcMaxAt10).build())
|
||||
.put(Names.FLUSH, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt5).build())
|
||||
.put(Names.REFRESH, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt10).build())
|
||||
.put(Names.WARMER, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt5).build())
|
||||
.put(Names.SNAPSHOT, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt5).build())
|
||||
.put(Names.OPTIMIZE, settingsBuilder().put("type", "fixed").put("size", 1).build())
|
||||
.put(Names.FETCH_SHARD_STARTED, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", availableProcessors * 2).build())
|
||||
.put(Names.FETCH_SHARD_STORE, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", availableProcessors * 2).build())
|
||||
.build();
|
||||
Map<String, Settings> defaultExecutorTypeSettings = new HashMap<>();
|
||||
defaultExecutorTypeSettings.put(Names.GENERIC, settingsBuilder().put("type", "cached").put("keep_alive", "30s").build());
|
||||
defaultExecutorTypeSettings.put(Names.INDEX,
|
||||
settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 200).build());
|
||||
defaultExecutorTypeSettings.put(Names.BULK,
|
||||
settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 50).build());
|
||||
defaultExecutorTypeSettings.put(Names.GET,
|
||||
settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 1000).build());
|
||||
defaultExecutorTypeSettings.put(Names.SEARCH,
|
||||
settingsBuilder().put("type", "fixed").put("size", ((availableProcessors * 3) / 2) + 1).put("queue_size", 1000).build());
|
||||
defaultExecutorTypeSettings.put(Names.SUGGEST,
|
||||
settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 1000).build());
|
||||
defaultExecutorTypeSettings.put(Names.PERCOLATE,
|
||||
settingsBuilder().put("type", "fixed").put("size", availableProcessors).put("queue_size", 1000).build());
|
||||
defaultExecutorTypeSettings .put(Names.MANAGEMENT, settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", 5).build());
|
||||
// no queue as this means clients will need to handle rejections on listener queue even if the operation succeeded
|
||||
// the assumption here is that the listeners should be very lightweight on the listeners side
|
||||
defaultExecutorTypeSettings.put(Names.LISTENER, settingsBuilder().put("type", "fixed").put("size", halfProcMaxAt10).build());
|
||||
defaultExecutorTypeSettings.put(Names.FLUSH,
|
||||
settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt5).build());
|
||||
defaultExecutorTypeSettings.put(Names.REFRESH,
|
||||
settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt10).build());
|
||||
defaultExecutorTypeSettings.put(Names.WARMER,
|
||||
settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt5).build());
|
||||
defaultExecutorTypeSettings.put(Names.SNAPSHOT,
|
||||
settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", halfProcMaxAt5).build());
|
||||
defaultExecutorTypeSettings.put(Names.OPTIMIZE, settingsBuilder().put("type", "fixed").put("size", 1).build());
|
||||
defaultExecutorTypeSettings.put(Names.FETCH_SHARD_STARTED,
|
||||
settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", availableProcessors * 2).build());
|
||||
defaultExecutorTypeSettings.put(Names.FETCH_SHARD_STORE,
|
||||
settingsBuilder().put("type", "scaling").put("keep_alive", "5m").put("size", availableProcessors * 2).build());
|
||||
this.defaultExecutorTypeSettings = unmodifiableMap(defaultExecutorTypeSettings);
|
||||
|
||||
Map<String, ExecutorHolder> executors = new HashMap<>();
|
||||
for (Map.Entry<String, Settings> executor : defaultExecutorTypeSettings.entrySet()) {
|
||||
|
@ -156,7 +167,7 @@ public class ThreadPool extends AbstractComponent {
|
|||
if (!executors.get(Names.GENERIC).info.getType().equals("cached")) {
|
||||
throw new IllegalArgumentException("generic thread pool must be of type cached");
|
||||
}
|
||||
this.executors = ImmutableMap.copyOf(executors);
|
||||
this.executors = unmodifiableMap(executors);
|
||||
this.scheduler = new ScheduledThreadPoolExecutor(1, EsExecutors.daemonThreadFactory(settings, "scheduler"), new EsAbortPolicy());
|
||||
this.scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
this.scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
|
||||
|
@ -446,7 +457,9 @@ public class ThreadPool extends AbstractComponent {
|
|||
ExecutorHolder oldExecutorHolder = executors.get(executor.getKey());
|
||||
ExecutorHolder newExecutorHolder = rebuild(executor.getKey(), oldExecutorHolder, updatedSettings, executor.getValue());
|
||||
if (!oldExecutorHolder.equals(newExecutorHolder)) {
|
||||
executors = newMapBuilder(executors).put(executor.getKey(), newExecutorHolder).immutableMap();
|
||||
Map<String, ExecutorHolder> newExecutors = new HashMap<>(executors);
|
||||
newExecutors.put(executor.getKey(), newExecutorHolder);
|
||||
executors = unmodifiableMap(newExecutors);
|
||||
if (!oldExecutorHolder.executor().equals(newExecutorHolder.executor()) && oldExecutorHolder.executor() instanceof EsThreadPoolExecutor) {
|
||||
retiredExecutors.add(oldExecutorHolder);
|
||||
((EsThreadPoolExecutor) oldExecutorHolder.executor()).shutdown(new ExecutorShutdownListener(oldExecutorHolder));
|
||||
|
@ -466,7 +479,9 @@ public class ThreadPool extends AbstractComponent {
|
|||
// case the settings contains a thread pool not defined in the initial settings in the constructor. The if
|
||||
// statement will then fail and so this prevents the addition of new thread groups at runtime, which is desired.
|
||||
if (!newExecutorHolder.equals(oldExecutorHolder)) {
|
||||
executors = newMapBuilder(executors).put(entry.getKey(), newExecutorHolder).immutableMap();
|
||||
Map<String, ExecutorHolder> newExecutors = new HashMap<>(executors);
|
||||
newExecutors.put(entry.getKey(), newExecutorHolder);
|
||||
executors = unmodifiableMap(newExecutors);
|
||||
if (!oldExecutorHolder.executor().equals(newExecutorHolder.executor()) && oldExecutorHolder.executor() instanceof EsThreadPoolExecutor) {
|
||||
retiredExecutors.add(oldExecutorHolder);
|
||||
((EsThreadPoolExecutor) oldExecutorHolder.executor()).shutdown(new ExecutorShutdownListener(oldExecutorHolder));
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.transport.netty;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -93,6 +91,7 @@ import java.net.InetSocketAddress;
|
|||
import java.net.SocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.channels.CancelledKeyException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -115,6 +114,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.elasticsearch.common.network.NetworkService.TcpSettings.TCP_BLOCKING;
|
||||
import static org.elasticsearch.common.network.NetworkService.TcpSettings.TCP_BLOCKING_CLIENT;
|
||||
import static org.elasticsearch.common.network.NetworkService.TcpSettings.TCP_BLOCKING_SERVER;
|
||||
|
@ -340,7 +340,7 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
|||
|
||||
@Override
|
||||
public Map<String, BoundTransportAddress> profileBoundAddresses() {
|
||||
return ImmutableMap.copyOf(profileBoundAddresses);
|
||||
return unmodifiableMap(new HashMap<>(profileBoundAddresses));
|
||||
}
|
||||
|
||||
private InetSocketAddress createPublishAddress(String publishHost, int publishPort) {
|
||||
|
@ -453,7 +453,7 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
|||
bindServerBootstrap(name, hostAddress, settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void bindServerBootstrap(final String name, final InetAddress hostAddress, Settings profileSettings) {
|
||||
|
||||
String port = profileSettings.get("port");
|
||||
|
@ -657,15 +657,15 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
|||
|
||||
@Override
|
||||
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws Exception {
|
||||
return parse(address, settings.get("transport.profiles.default.port",
|
||||
settings.get("transport.netty.port",
|
||||
settings.get("transport.tcp.port",
|
||||
return parse(address, settings.get("transport.profiles.default.port",
|
||||
settings.get("transport.netty.port",
|
||||
settings.get("transport.tcp.port",
|
||||
DEFAULT_PORT_RANGE))), perAddressLimit);
|
||||
}
|
||||
|
||||
|
||||
// this code is a take on guava's HostAndPort, like a HostAndPortRange
|
||||
|
||||
// pattern for validating ipv6 bracked addresses.
|
||||
|
||||
// pattern for validating ipv6 bracked addresses.
|
||||
// not perfect, but PortsRange should take care of any port range validation, not a regex
|
||||
private static final Pattern BRACKET_PATTERN = Pattern.compile("^\\[(.*:.*)\\](?::([\\d\\-]*))?$");
|
||||
|
||||
|
@ -698,12 +698,12 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if port isn't specified, fill with the default
|
||||
if (portString == null || portString.isEmpty()) {
|
||||
portString = defaultPortRange;
|
||||
}
|
||||
|
||||
|
||||
// generate address for each port in the range
|
||||
Set<InetAddress> addresses = new HashSet<>(Arrays.asList(InetAddress.getAllByName(host)));
|
||||
List<TransportAddress> transportAddresses = new ArrayList<>();
|
||||
|
|
|
@ -135,6 +135,7 @@ com.google.common.collect.ImmutableMap#of(java.lang.Object, java.lang.Object, ja
|
|||
com.google.common.collect.ImmutableMap#of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)
|
||||
com.google.common.collect.ImmutableMap#of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)
|
||||
com.google.common.collect.ImmutableMap#of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)
|
||||
com.google.common.collect.ImmutableMap#copyOf(java.util.Map)
|
||||
|
||||
@defaultMessage Do not violate java's access system
|
||||
java.lang.reflect.AccessibleObject#setAccessible(boolean)
|
||||
|
|
Loading…
Reference in New Issue