Cut the following classes over to ImmutableOpenMap:

* MetaData
* IndexMetaData
* ClusterState
* IndexTemplateMetaData
This commit is contained in:
Martijn van Groningen 2013-11-07 11:58:52 -05:00
parent 46ab6a1533
commit 036febe110
47 changed files with 616 additions and 456 deletions

View File

@ -32,7 +32,7 @@ import org.apache.lucene.util.fst.*;
import org.apache.lucene.util.fst.FST.BytesReader;
import org.apache.lucene.util.fst.PairOutputs.Pair;
import org.apache.lucene.util.fst.Util.MinResult;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.collect.HppcMaps;
import java.io.File;
import java.io.IOException;

View File

@ -19,24 +19,25 @@
package org.elasticsearch.action.admin.indices.alias.get;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*/
public class GetAliasesResponse extends ActionResponse {
private Map<String, List<AliasMetaData>> aliases = new HashMap<String, List<AliasMetaData>>();
private ImmutableOpenMap<String, List<AliasMetaData>> aliases = ImmutableOpenMap.of();
public GetAliasesResponse(Map<String, List<AliasMetaData>> aliases) {
public GetAliasesResponse(ImmutableOpenMap<String, List<AliasMetaData>> aliases) {
this.aliases = aliases;
}
@ -44,7 +45,7 @@ public class GetAliasesResponse extends ActionResponse {
}
public Map<String, List<AliasMetaData>> getAliases() {
public ImmutableOpenMap<String, List<AliasMetaData>> getAliases() {
return aliases;
}
@ -52,6 +53,7 @@ public class GetAliasesResponse extends ActionResponse {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliasesBuilder = ImmutableOpenMap.builder();
for (int i = 0; i < size; i++) {
String key = in.readString();
int valueSize = in.readVInt();
@ -59,18 +61,19 @@ public class GetAliasesResponse extends ActionResponse {
for (int j = 0; j < valueSize; j++) {
value.add(AliasMetaData.Builder.readFrom(in));
}
aliases.put(key, value);
aliasesBuilder.put(key, ImmutableList.copyOf(value));
}
aliases = aliasesBuilder.build();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(aliases.size());
for (Map.Entry<String, List<AliasMetaData>> entry : aliases.entrySet()) {
out.writeString(entry.getKey());
out.writeVInt(entry.getValue().size());
for (AliasMetaData aliasMetaData : entry.getValue()) {
for (ObjectObjectCursor<String, List<AliasMetaData>> entry : aliases) {
out.writeString(entry.key);
out.writeVInt(entry.value.size());
for (AliasMetaData aliasMetaData : entry.value) {
AliasMetaData.Builder.writeTo(aliasMetaData, out);
}
}

View File

@ -24,13 +24,13 @@ import org.elasticsearch.action.support.master.TransportMasterNodeOperationActio
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
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.List;
import java.util.Map;
/**
*/
@ -68,7 +68,7 @@ public class TransportGetAliasesAction extends TransportMasterNodeOperationActio
request.indices(concreteIndices);
@SuppressWarnings("unchecked") // ImmutableList to List results incompatible type
Map<String, List<AliasMetaData>> result = (Map) state.metaData().findAliases(request.aliases(), request.indices());
ImmutableOpenMap<String, List<AliasMetaData>> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), request.indices());
listener.onResponse(new GetAliasesResponse(result));
}

View File

@ -27,13 +27,12 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
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.Map;
/**
* Types exists transport action.
*/
@ -85,7 +84,7 @@ public class TransportTypesExistsAction extends TransportMasterNodeOperationActi
return;
}
Map<String, MappingMetaData> mappings = state.metaData().getIndices().get(concreteIndex).mappings();
ImmutableOpenMap<String, MappingMetaData> mappings = state.metaData().getIndices().get(concreteIndex).mappings();
if (mappings.isEmpty()) {
listener.onResponse(new TypesExistsResponse(false));
return;

View File

@ -19,33 +19,33 @@
package org.elasticsearch.action.admin.indices.mapping.get;
import com.google.common.collect.ImmutableMap;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import java.util.Map;
/**
*/
public class GetMappingsResponse extends ActionResponse {
private ImmutableMap<String, ImmutableMap<String, MappingMetaData>> mappings = ImmutableMap.of();
private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.of();
GetMappingsResponse(ImmutableMap<String, ImmutableMap<String, MappingMetaData>> mappings) {
GetMappingsResponse(ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {
this.mappings = mappings;
}
GetMappingsResponse() {
}
public ImmutableMap<String, ImmutableMap<String, MappingMetaData>> mappings() {
public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings() {
return mappings;
}
public ImmutableMap<String, ImmutableMap<String, MappingMetaData>> getMappings() {
public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> getMappings() {
return mappings();
}
@ -53,11 +53,11 @@ public class GetMappingsResponse extends ActionResponse {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
ImmutableMap.Builder<String, ImmutableMap<String, MappingMetaData>> indexMapBuilder = ImmutableMap.builder();
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
for (int i = 0; i < size; i++) {
String key = in.readString();
int valueSize = in.readVInt();
ImmutableMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableMap.builder();
ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
for (int j = 0; j < valueSize; j++) {
typeMapBuilder.put(in.readString(), MappingMetaData.readFrom(in));
}
@ -70,12 +70,12 @@ public class GetMappingsResponse extends ActionResponse {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(mappings.size());
for (Map.Entry<String, ImmutableMap<String, MappingMetaData>> indexEntry : mappings.entrySet()) {
out.writeString(indexEntry.getKey());
out.writeVInt(indexEntry.getValue().size());
for (Map.Entry<String, MappingMetaData> typeEntry : indexEntry.getValue().entrySet()) {
out.writeString(typeEntry.getKey());
MappingMetaData.writeTo(typeEntry.getValue(), out);
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappings) {
out.writeString(indexEntry.key);
out.writeVInt(indexEntry.value.size());
for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
out.writeString(typeEntry.key);
MappingMetaData.writeTo(typeEntry.value, out);
}
}
}

View File

@ -19,13 +19,13 @@
package org.elasticsearch.action.admin.indices.mapping.get;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.info.TransportClusterInfoAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
@ -58,7 +58,7 @@ public class TransportGetMappingsAction extends TransportClusterInfoAction<GetMa
@Override
protected void doMasterOperation(final GetMappingsRequest request, final ClusterState state, final ActionListener<GetMappingsResponse> listener) throws ElasticSearchException {
logger.trace("serving getMapping request based on version {}", state.version());
ImmutableMap<String, ImmutableMap<String, MappingMetaData>> result = state.metaData().findMappings(
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> result = state.metaData().findMappings(
request.indices(), request.types()
);
listener.onResponse(new GetMappingsResponse(result));

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.action.admin.indices.template.get;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.Lists;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
@ -32,7 +33,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.List;
import java.util.Map;
/**
*
@ -66,18 +66,20 @@ public class TransportGetIndexTemplatesAction extends TransportMasterNodeOperati
@Override
protected void masterOperation(GetIndexTemplatesRequest request, ClusterState state, ActionListener<GetIndexTemplatesResponse> listener) throws ElasticSearchException {
List<IndexTemplateMetaData> results = Lists.newArrayList();
List<IndexTemplateMetaData> results;
// If we did not ask for a specific name, then we return all templates
if (request.names().length == 0) {
results.addAll(state.metaData().templates().values());
results = Lists.newArrayList(state.metaData().templates().values().toArray(IndexTemplateMetaData.class));
} else {
results = Lists.newArrayList();
}
for (String name : request.names()) {
if (Regex.isSimpleMatchPattern(name)) {
for (Map.Entry<String, IndexTemplateMetaData> entry : state.metaData().templates().entrySet()) {
if (Regex.simpleMatch(name, entry.getKey())) {
results.add(entry.getValue());
for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : state.metaData().templates()) {
if (Regex.simpleMatch(name, entry.key)) {
results.add(entry.value);
}
}
} else if (state.metaData().templates().containsKey(name)) {

View File

@ -19,34 +19,34 @@
package org.elasticsearch.action.admin.indices.warmer.get;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import java.io.IOException;
import java.util.Map;
/**
*/
public class GetWarmersResponse extends ActionResponse {
private ImmutableMap<String, ImmutableList<IndexWarmersMetaData.Entry>> warmers = ImmutableMap.of();
private ImmutableOpenMap<String, ImmutableList<IndexWarmersMetaData.Entry>> warmers = ImmutableOpenMap.of();
GetWarmersResponse(ImmutableMap<String, ImmutableList<IndexWarmersMetaData.Entry>> warmers) {
GetWarmersResponse(ImmutableOpenMap<String, ImmutableList<IndexWarmersMetaData.Entry>> warmers) {
this.warmers = warmers;
}
GetWarmersResponse() {
}
public ImmutableMap<String, ImmutableList<IndexWarmersMetaData.Entry>> warmers() {
public ImmutableOpenMap<String, ImmutableList<IndexWarmersMetaData.Entry>> warmers() {
return warmers;
}
public ImmutableMap<String, ImmutableList<IndexWarmersMetaData.Entry>> getWarmers() {
public ImmutableOpenMap<String, ImmutableList<IndexWarmersMetaData.Entry>> getWarmers() {
return warmers();
}
@ -54,7 +54,7 @@ public class GetWarmersResponse extends ActionResponse {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
ImmutableMap.Builder<String, ImmutableList<IndexWarmersMetaData.Entry>> indexMapBuilder = ImmutableMap.builder();
ImmutableOpenMap.Builder<String, ImmutableList<IndexWarmersMetaData.Entry>> indexMapBuilder = ImmutableOpenMap.builder();
for (int i = 0; i < size; i++) {
String key = in.readString();
int valueSize = in.readVInt();
@ -75,10 +75,10 @@ public class GetWarmersResponse extends ActionResponse {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(warmers.size());
for (Map.Entry<String, ImmutableList<IndexWarmersMetaData.Entry>> indexEntry : warmers.entrySet()) {
out.writeString(indexEntry.getKey());
out.writeVInt(indexEntry.getValue().size());
for (IndexWarmersMetaData.Entry warmerEntry : indexEntry.getValue()) {
for (ObjectObjectCursor<String, ImmutableList<IndexWarmersMetaData.Entry>> indexEntry : warmers) {
out.writeString(indexEntry.key);
out.writeVInt(indexEntry.value.size());
for (IndexWarmersMetaData.Entry warmerEntry : indexEntry.value) {
out.writeString(warmerEntry.name());
out.writeStringArray(warmerEntry.types());
out.writeBytesReference(warmerEntry.source());

View File

@ -26,6 +26,7 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.info.TransportClusterInfoAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
@ -58,7 +59,7 @@ public class TransportGetWarmersAction extends TransportClusterInfoAction<GetWar
@Override
protected void doMasterOperation(final GetWarmersRequest request, final ClusterState state, final ActionListener<GetWarmersResponse> listener) throws ElasticSearchException {
ImmutableMap<String, ImmutableList<IndexWarmersMetaData.Entry>> result = state.metaData().findWarmers(
ImmutableOpenMap<String, ImmutableList<IndexWarmersMetaData.Entry>> result = state.metaData().findWarmers(
request.indices(), request.types(), request.warmers()
);
listener.onResponse(new GetWarmersResponse(result));

View File

@ -19,12 +19,14 @@
package org.elasticsearch.cluster;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import java.util.Arrays;
import java.util.List;
/**
@ -81,13 +83,14 @@ public class ClusterChangedEvent {
*/
public List<String> indicesCreated() {
if (previousState == null) {
return Lists.newArrayList(state.metaData().indices().keySet());
return Arrays.asList(state.metaData().indices().keys().toArray(String.class));
}
if (!metaDataChanged()) {
return ImmutableList.of();
}
List<String> created = null;
for (String index : state.metaData().indices().keySet()) {
for (ObjectCursor<String> cursor : state.metaData().indices().keys()) {
String index = cursor.value;
if (!previousState.metaData().hasIndex(index)) {
if (created == null) {
created = Lists.newArrayList();
@ -109,7 +112,8 @@ public class ClusterChangedEvent {
return ImmutableList.of();
}
List<String> deleted = null;
for (String index : previousState.metaData().indices().keySet()) {
for (ObjectCursor<String> cursor : previousState.metaData().indices().keys()) {
String index = cursor.value;
if (!state.metaData().hasIndex(index)) {
if (deleted == null) {
deleted = Lists.newArrayList();

View File

@ -19,7 +19,8 @@
package org.elasticsearch.cluster;
import com.google.common.collect.ImmutableMap;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.cluster.block.ClusterBlock;
@ -34,7 +35,7 @@ import org.elasticsearch.cluster.routing.*;
import org.elasticsearch.cluster.routing.allocation.AllocationExplanation;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.io.stream.BytesStreamInput;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
@ -54,8 +55,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
/**
*
*/
@ -110,7 +109,7 @@ public class ClusterState implements ToXContent {
private final AllocationExplanation allocationExplanation;
private final ImmutableMap<String, Custom> customs;
private final ImmutableOpenMap<String, Custom> customs;
// built on demand
private volatile RoutingNodes routingNodes;
@ -121,7 +120,7 @@ public class ClusterState implements ToXContent {
this(version, state.metaData(), state.routingTable(), state.nodes(), state.blocks(), state.allocationExplanation(), state.customs());
}
public ClusterState(long version, MetaData metaData, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, AllocationExplanation allocationExplanation, ImmutableMap<String, Custom> customs) {
public ClusterState(long version, MetaData metaData, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, AllocationExplanation allocationExplanation, ImmutableOpenMap<String, Custom> customs) {
this.version = version;
this.metaData = metaData;
this.routingTable = routingTable;
@ -187,11 +186,11 @@ public class ClusterState implements ToXContent {
return allocationExplanation();
}
public ImmutableMap<String, Custom> customs() {
public ImmutableOpenMap<String, Custom> customs() {
return this.customs;
}
public ImmutableMap<String, Custom> getCustoms() {
public ImmutableOpenMap<String, Custom> getCustoms() {
return this.customs;
}
@ -290,7 +289,8 @@ public class ClusterState implements ToXContent {
builder.startObject("metadata");
builder.startObject("templates");
for (IndexTemplateMetaData templateMetaData : metaData().templates().values()) {
for (ObjectCursor<IndexTemplateMetaData> cursor : metaData().templates().values()) {
IndexTemplateMetaData templateMetaData = cursor.value;
builder.startObject(templateMetaData.name(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("template", templateMetaData.template());
@ -308,15 +308,15 @@ public class ClusterState implements ToXContent {
builder.endObject();
builder.startObject("mappings");
for (Map.Entry<String, CompressedString> entry : templateMetaData.mappings().entrySet()) {
byte[] mappingSource = entry.getValue().uncompressed();
for (ObjectObjectCursor<String, CompressedString> cursor1 : templateMetaData.mappings()) {
byte[] mappingSource = cursor1.value.uncompressed();
XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
Map<String, Object> mapping = parser.map();
if (mapping.size() == 1 && mapping.containsKey(entry.getKey())) {
if (mapping.size() == 1 && mapping.containsKey(cursor1.key)) {
// the type name is the root value, reduce it
mapping = (Map<String, Object>) mapping.get(entry.getKey());
mapping = (Map<String, Object>) mapping.get(cursor1.key);
}
builder.field(entry.getKey());
builder.field(cursor1.key);
builder.map(mapping);
}
builder.endObject();
@ -343,22 +343,22 @@ public class ClusterState implements ToXContent {
builder.endObject();
builder.startObject("mappings");
for (Map.Entry<String, MappingMetaData> entry : indexMetaData.mappings().entrySet()) {
byte[] mappingSource = entry.getValue().source().uncompressed();
for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.mappings()) {
byte[] mappingSource = cursor.value.source().uncompressed();
XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
Map<String, Object> mapping = parser.map();
if (mapping.size() == 1 && mapping.containsKey(entry.getKey())) {
if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
// the type name is the root value, reduce it
mapping = (Map<String, Object>) mapping.get(entry.getKey());
mapping = (Map<String, Object>) mapping.get(cursor.key);
}
builder.field(entry.getKey());
builder.field(cursor.key);
builder.map(mapping);
}
builder.endObject();
builder.startArray("aliases");
for (String alias : indexMetaData.aliases().keySet()) {
builder.value(alias);
for (ObjectCursor<String> cursor : indexMetaData.aliases().keys()) {
builder.value(cursor.value);
}
builder.endArray();
@ -366,9 +366,9 @@ public class ClusterState implements ToXContent {
}
builder.endObject();
for (Map.Entry<String, MetaData.Custom> entry : metaData.customs().entrySet()) {
builder.startObject(entry.getKey());
MetaData.lookupFactorySafe(entry.getKey()).toXContent(entry.getValue(), builder, params);
for (ObjectObjectCursor<String, MetaData.Custom> cursor : metaData.customs()) {
builder.startObject(cursor.key);
MetaData.lookupFactorySafe(cursor.key).toXContent(cursor.value, builder, params);
builder.endObject();
}
@ -441,9 +441,9 @@ public class ClusterState implements ToXContent {
}
if (!params.paramAsBoolean("filter_customs", false)) {
for (Map.Entry<String, Custom> entry : customs().entrySet()) {
builder.startObject(entry.getKey());
lookupFactorySafe(entry.getKey()).toXContent(entry.getValue(), builder, params);
for (ObjectObjectCursor<String, Custom> cursor : customs) {
builder.startObject(cursor.key);
lookupFactorySafe(cursor.key).toXContent(cursor.value, builder, params);
builder.endObject();
}
}
@ -467,10 +467,10 @@ public class ClusterState implements ToXContent {
private DiscoveryNodes nodes = DiscoveryNodes.EMPTY_NODES;
private ClusterBlocks blocks = ClusterBlocks.EMPTY_CLUSTER_BLOCK;
private AllocationExplanation allocationExplanation = AllocationExplanation.EMPTY;
private MapBuilder<String, Custom> customs = newMapBuilder();
private final ImmutableOpenMap.Builder<String, Custom> customs;
public Builder() {
customs = ImmutableOpenMap.builder();
}
public Builder(ClusterState state) {
@ -480,7 +480,7 @@ public class ClusterState implements ToXContent {
this.metaData = state.metaData();
this.blocks = state.blocks();
this.allocationExplanation = state.allocationExplanation();
this.customs.putAll(state.customs());
this.customs = ImmutableOpenMap.builder(state.customs());
}
public Builder nodes(DiscoveryNodes.Builder nodesBuilder) {
@ -550,7 +550,7 @@ public class ClusterState implements ToXContent {
}
public ClusterState build() {
return new ClusterState(version, metaData, routingTable, nodes, blocks, allocationExplanation, customs.immutableMap());
return new ClusterState(version, metaData, routingTable, nodes, blocks, allocationExplanation, customs.build());
}
public static byte[] toBytes(ClusterState state) throws IOException {
@ -571,9 +571,9 @@ public class ClusterState implements ToXContent {
ClusterBlocks.Builder.writeClusterBlocks(state.blocks(), out);
state.allocationExplanation().writeTo(out);
out.writeVInt(state.customs().size());
for (Map.Entry<String, Custom> entry : state.customs().entrySet()) {
out.writeString(entry.getKey());
lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out);
for (ObjectObjectCursor<String, Custom> cursor : state.customs()) {
out.writeString(cursor.key);
lookupFactorySafe(cursor.key).writeTo(cursor.value, out);
}
}

View File

@ -19,6 +19,8 @@
package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.ElasticSearchIllegalStateException;
@ -27,6 +29,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.node.DiscoveryNodeFilters;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Preconditions;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.io.stream.StreamInput;
@ -164,13 +167,13 @@ public class IndexMetaData {
private final State state;
private final Map<String, AliasMetaData> aliases;
private final ImmutableOpenMap<String, AliasMetaData> aliases;
private final Settings settings;
private final Map<String, MappingMetaData> mappings;
private final ImmutableOpenMap<String, MappingMetaData> mappings;
private final Map<String, Custom> customs;
private final ImmutableOpenMap<String, Custom> customs;
private transient final int totalNumberOfShards;
@ -178,7 +181,7 @@ public class IndexMetaData {
private final DiscoveryNodeFilters includeFilters;
private final DiscoveryNodeFilters excludeFilters;
private IndexMetaData(String index, long version, State state, Settings settings, Map<String, MappingMetaData> mappings, Map<String, AliasMetaData> aliases, Map<String, Custom> customs) {
private IndexMetaData(String index, long version, State state, Settings settings, ImmutableOpenMap<String, MappingMetaData> mappings, ImmutableOpenMap<String, AliasMetaData> aliases, ImmutableOpenMap<String, Custom> customs) {
Preconditions.checkArgument(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, -1) != -1, "must specify numberOfShards for index [" + index + "]");
Preconditions.checkArgument(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, -1) != -1, "must specify numberOfReplicas for index [" + index + "]");
this.index = index;
@ -287,19 +290,19 @@ public class IndexMetaData {
return settings();
}
public Map<String, AliasMetaData> aliases() {
public ImmutableOpenMap<String, AliasMetaData> aliases() {
return this.aliases;
}
public Map<String, AliasMetaData> getAliases() {
public ImmutableOpenMap<String, AliasMetaData> getAliases() {
return aliases();
}
public Map<String, MappingMetaData> mappings() {
public ImmutableOpenMap<String, MappingMetaData> mappings() {
return mappings;
}
public Map<String, MappingMetaData> getMappings() {
public ImmutableOpenMap<String, MappingMetaData> getMappings() {
return mappings();
}
@ -324,11 +327,11 @@ public class IndexMetaData {
return mappings.get(MapperService.DEFAULT_MAPPING);
}
public Map<String, Custom> customs() {
public ImmutableOpenMap<String, Custom> customs() {
return this.customs;
}
public Map<String, Custom> getCustoms() {
public ImmutableOpenMap<String, Custom> getCustoms() {
return this.customs;
}
@ -405,22 +408,25 @@ public class IndexMetaData {
private State state = State.OPEN;
private long version = 1;
private Settings settings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private MapBuilder<String, MappingMetaData> mappings = MapBuilder.newMapBuilder();
private MapBuilder<String, AliasMetaData> aliases = MapBuilder.newMapBuilder();
private MapBuilder<String, Custom> customs = MapBuilder.newMapBuilder();
private final ImmutableOpenMap.Builder<String, MappingMetaData> mappings;
private final ImmutableOpenMap.Builder<String, AliasMetaData> aliases;
private final ImmutableOpenMap.Builder<String, Custom> customs;
public Builder(String index) {
this.index = index;
this.mappings = ImmutableOpenMap.builder();
this.aliases = ImmutableOpenMap.builder();
this.customs = ImmutableOpenMap.builder();
}
public Builder(IndexMetaData indexMetaData) {
this(indexMetaData.index());
settings(indexMetaData.settings());
mappings.putAll(indexMetaData.mappings);
aliases.putAll(indexMetaData.aliases);
customs.putAll(indexMetaData.customs);
this.index = indexMetaData.index();
this.state = indexMetaData.state;
this.version = indexMetaData.version;
this.settings = indexMetaData.settings();
this.mappings = ImmutableOpenMap.builder(indexMetaData.mappings);
this.aliases = ImmutableOpenMap.builder(indexMetaData.aliases);
this.customs = ImmutableOpenMap.builder(indexMetaData.customs);
}
public String index() {
@ -524,18 +530,18 @@ public class IndexMetaData {
}
public IndexMetaData build() {
MapBuilder<String, AliasMetaData> tmpAliases = aliases;
ImmutableOpenMap.Builder<String, AliasMetaData> tmpAliases = aliases;
Settings tmpSettings = settings;
// For backward compatibility
String[] legacyAliases = settings.getAsArray("index.aliases");
if (legacyAliases.length > 0) {
tmpAliases = MapBuilder.newMapBuilder();
tmpAliases = ImmutableOpenMap.builder();
for (String alias : legacyAliases) {
AliasMetaData aliasMd = AliasMetaData.newAliasMetaDataBuilder(alias).build();
tmpAliases.put(alias, aliasMd);
}
tmpAliases.putAll(aliases.map());
tmpAliases.putAll(aliases);
// Remove index.aliases from settings once they are migrated to the new data structure
tmpSettings = ImmutableSettings.settingsBuilder().put(settings).putArray("index.aliases").build();
}
@ -543,12 +549,12 @@ public class IndexMetaData {
// update default mapping on the MappingMetaData
if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING);
for (MappingMetaData mappingMetaData : mappings.map().values()) {
mappingMetaData.updateDefaultMapping(defaultMapping);
for (ObjectCursor<MappingMetaData> cursor : mappings.values()) {
cursor.value.updateDefaultMapping(defaultMapping);
}
}
return new IndexMetaData(index, version, state, tmpSettings, mappings.readOnlyMap(), tmpAliases.readOnlyMap(), customs.readOnlyMap());
return new IndexMetaData(index, version, state, tmpSettings, mappings.build(), tmpAliases.build(), customs.build());
}
public static void toXContent(IndexMetaData indexMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
@ -566,11 +572,11 @@ public class IndexMetaData {
builder.endObject();
builder.startArray("mappings");
for (Map.Entry<String, MappingMetaData> entry : indexMetaData.mappings().entrySet()) {
for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.mappings()) {
if (binary) {
builder.value(entry.getValue().source().compressed());
builder.value(cursor.value.source().compressed());
} else {
byte[] data = entry.getValue().source().uncompressed();
byte[] data = cursor.value.source().uncompressed();
XContentParser parser = XContentFactory.xContent(data).createParser(data);
Map<String, Object> mapping = parser.mapOrdered();
parser.close();
@ -579,15 +585,15 @@ public class IndexMetaData {
}
builder.endArray();
for (Map.Entry<String, Custom> entry : indexMetaData.customs().entrySet()) {
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
lookupFactorySafe(entry.getKey()).toXContent(entry.getValue(), builder, params);
for (ObjectObjectCursor<String, Custom> cursor : indexMetaData.customs()) {
builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE);
lookupFactorySafe(cursor.key).toXContent(cursor.value, builder, params);
builder.endObject();
}
builder.startObject("aliases");
for (AliasMetaData alias : indexMetaData.aliases().values()) {
AliasMetaData.Builder.toXContent(alias, builder, params);
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.aliases().values()) {
AliasMetaData.Builder.toXContent(cursor.value, builder, params);
}
builder.endObject();
@ -688,17 +694,17 @@ public class IndexMetaData {
out.writeByte(indexMetaData.state().id());
writeSettingsToStream(indexMetaData.settings(), out);
out.writeVInt(indexMetaData.mappings().size());
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
MappingMetaData.writeTo(mappingMd, out);
for (ObjectCursor<MappingMetaData> cursor : indexMetaData.mappings().values()) {
MappingMetaData.writeTo(cursor.value, out);
}
out.writeVInt(indexMetaData.aliases().size());
for (AliasMetaData aliasMd : indexMetaData.aliases().values()) {
AliasMetaData.Builder.writeTo(aliasMd, out);
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.aliases().values()) {
AliasMetaData.Builder.writeTo(cursor.value, out);
}
out.writeVInt(indexMetaData.customs().size());
for (Map.Entry<String, Custom> entry : indexMetaData.customs().entrySet()) {
out.writeString(entry.getKey());
lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out);
for (ObjectObjectCursor<String, Custom> cursor : indexMetaData.customs()) {
out.writeString(cursor.key);
lookupFactorySafe(cursor.key).writeTo(cursor.value, out);
}
}
}

View File

@ -19,7 +19,8 @@
package org.elasticsearch.cluster.metadata;
import com.google.common.collect.ImmutableMap;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.io.stream.StreamInput;
@ -49,11 +50,11 @@ public class IndexTemplateMetaData {
private final Settings settings;
// the mapping source should always include the type as top level
private final ImmutableMap<String, CompressedString> mappings;
private final ImmutableOpenMap<String, CompressedString> mappings;
private final ImmutableMap<String, IndexMetaData.Custom> customs;
private final ImmutableOpenMap<String, IndexMetaData.Custom> customs;
public IndexTemplateMetaData(String name, int order, String template, Settings settings, ImmutableMap<String, CompressedString> mappings, ImmutableMap<String, IndexMetaData.Custom> customs) {
public IndexTemplateMetaData(String name, int order, String template, Settings settings, ImmutableOpenMap<String, CompressedString> mappings, ImmutableOpenMap<String, IndexMetaData.Custom> customs) {
this.name = name;
this.order = order;
this.template = template;
@ -94,19 +95,19 @@ public class IndexTemplateMetaData {
return settings();
}
public ImmutableMap<String, CompressedString> mappings() {
public ImmutableOpenMap<String, CompressedString> mappings() {
return this.mappings;
}
public ImmutableMap<String, CompressedString> getMappings() {
public ImmutableOpenMap<String, CompressedString> getMappings() {
return this.mappings;
}
public ImmutableMap<String, IndexMetaData.Custom> customs() {
public ImmutableOpenMap<String, IndexMetaData.Custom> customs() {
return this.customs;
}
public ImmutableMap<String, IndexMetaData.Custom> getCustoms() {
public ImmutableOpenMap<String, IndexMetaData.Custom> getCustoms() {
return this.customs;
}
@ -154,12 +155,14 @@ public class IndexTemplateMetaData {
private Settings settings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private MapBuilder<String, CompressedString> mappings = MapBuilder.newMapBuilder();
private ImmutableOpenMap.Builder<String, CompressedString> mappings;
private MapBuilder<String, IndexMetaData.Custom> customs = MapBuilder.newMapBuilder();
private ImmutableOpenMap.Builder<String, IndexMetaData.Custom> customs;
public Builder(String name) {
this.name = name;
mappings = ImmutableOpenMap.builder();
customs = ImmutableOpenMap.builder();
}
public Builder(IndexTemplateMetaData indexTemplateMetaData) {
@ -167,8 +170,9 @@ public class IndexTemplateMetaData {
order(indexTemplateMetaData.order());
template(indexTemplateMetaData.template());
settings(indexTemplateMetaData.settings());
mappings.putAll(indexTemplateMetaData.mappings());
customs.putAll(indexTemplateMetaData.customs());
mappings = ImmutableOpenMap.builder(indexTemplateMetaData.mappings());
customs = ImmutableOpenMap.builder(indexTemplateMetaData.customs());
}
public Builder order(int order) {
@ -225,7 +229,7 @@ public class IndexTemplateMetaData {
}
public IndexTemplateMetaData build() {
return new IndexTemplateMetaData(name, order, template, settings, mappings.immutableMap(), customs.immutableMap());
return new IndexTemplateMetaData(name, order, template, settings, mappings.build(), customs.build());
}
public static void toXContent(IndexTemplateMetaData indexTemplateMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
@ -242,22 +246,22 @@ public class IndexTemplateMetaData {
if (params.paramAsBoolean("reduce_mappings", false)) {
builder.startObject("mappings");
for (Map.Entry<String, CompressedString> entry : indexTemplateMetaData.mappings().entrySet()) {
byte[] mappingSource = entry.getValue().uncompressed();
for (ObjectObjectCursor<String, CompressedString> cursor : indexTemplateMetaData.mappings()) {
byte[] mappingSource = cursor.value.uncompressed();
XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
Map<String, Object> mapping = parser.map();
if (mapping.size() == 1 && mapping.containsKey(entry.getKey())) {
if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
// the type name is the root value, reduce it
mapping = (Map<String, Object>) mapping.get(entry.getKey());
mapping = (Map<String, Object>) mapping.get(cursor.key);
}
builder.field(entry.getKey());
builder.field(cursor.key);
builder.map(mapping);
}
builder.endObject();
} else {
builder.startArray("mappings");
for (Map.Entry<String, CompressedString> entry : indexTemplateMetaData.mappings().entrySet()) {
byte[] data = entry.getValue().uncompressed();
for (ObjectObjectCursor<String, CompressedString> cursor : indexTemplateMetaData.mappings()) {
byte[] data = cursor.value.uncompressed();
XContentParser parser = XContentFactory.xContent(data).createParser(data);
Map<String, Object> mapping = parser.mapOrderedAndClose();
builder.map(mapping);
@ -265,9 +269,9 @@ public class IndexTemplateMetaData {
builder.endArray();
}
for (Map.Entry<String, IndexMetaData.Custom> entry : indexTemplateMetaData.customs().entrySet()) {
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
IndexMetaData.lookupFactorySafe(entry.getKey()).toXContent(entry.getValue(), builder, params);
for (ObjectObjectCursor<String, IndexMetaData.Custom> cursor : indexTemplateMetaData.customs()) {
builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE);
IndexMetaData.lookupFactorySafe(cursor.key).toXContent(cursor.value, builder, params);
builder.endObject();
}
@ -371,14 +375,14 @@ public class IndexTemplateMetaData {
out.writeString(indexTemplateMetaData.template());
ImmutableSettings.writeSettingsToStream(indexTemplateMetaData.settings(), out);
out.writeVInt(indexTemplateMetaData.mappings().size());
for (Map.Entry<String, CompressedString> entry : indexTemplateMetaData.mappings().entrySet()) {
out.writeString(entry.getKey());
entry.getValue().writeTo(out);
for (ObjectObjectCursor<String, CompressedString> cursor : indexTemplateMetaData.mappings()) {
out.writeString(cursor.key);
cursor.value.writeTo(out);
}
out.writeVInt(indexTemplateMetaData.customs().size());
for (Map.Entry<String, IndexMetaData.Custom> entry : indexTemplateMetaData.customs().entrySet()) {
out.writeString(entry.getKey());
IndexMetaData.lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out);
for (ObjectObjectCursor<String, IndexMetaData.Custom> cursor : indexTemplateMetaData.customs()) {
out.writeString(cursor.key);
IndexMetaData.lookupFactorySafe(cursor.key).writeTo(cursor.value, out);
}
}
}

View File

@ -19,18 +19,23 @@
package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.ObjectArrayList;
import com.carrotsearch.hppc.ObjectOpenHashSet;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.base.Predicate;
import com.google.common.collect.*;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.RamUsageEstimator;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.collect.XMaps;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.regex.Regex;
@ -48,7 +53,6 @@ import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.*;
/**
@ -120,22 +124,22 @@ public class MetaData implements Iterable<IndexMetaData> {
private final Settings transientSettings;
private final Settings persistentSettings;
private final Settings settings;
private final Map<String, IndexMetaData> indices;
private final Map<String, IndexTemplateMetaData> templates;
private final Map<String, Custom> customs;
private final ImmutableOpenMap<String, IndexMetaData> indices;
private final ImmutableOpenMap<String, IndexTemplateMetaData> templates;
private final ImmutableOpenMap<String, Custom> customs;
private final transient int totalNumberOfShards; // Transient ? not serializable anyway?
private final int numberOfShards;
private final String[] allIndices;
private final ImmutableSet<String> allIndicesSet;
private final String[] allOpenIndices;
private final Map<String, Map<String, AliasMetaData>> aliases;
private final Map<String, StringArray> aliasAndIndexToIndexMap;
private final ImmutableOpenMap<String, ImmutableOpenMap<String, AliasMetaData>> aliases;
private final ImmutableOpenMap<String, String[]> aliasAndIndexToIndexMap;
MetaData(long version, Settings transientSettings, Settings persistentSettings, Map<String, IndexMetaData> indices, Map<String, IndexTemplateMetaData> templates, Map<String, Custom> customs) {
@SuppressWarnings("unchecked")
MetaData(long version, Settings transientSettings, Settings persistentSettings, ImmutableOpenMap<String, IndexMetaData> indices, ImmutableOpenMap<String, IndexTemplateMetaData> templates, ImmutableOpenMap<String, Custom> customs) {
this.version = version;
this.transientSettings = transientSettings;
this.persistentSettings = persistentSettings;
@ -146,25 +150,25 @@ public class MetaData implements Iterable<IndexMetaData> {
int totalNumberOfShards = 0;
int numberOfShards = 0;
int numAliases = 0;
for (IndexMetaData indexMetaData : indices.values()) {
totalNumberOfShards += indexMetaData.totalNumberOfShards();
numberOfShards += indexMetaData.numberOfShards();
numAliases += indexMetaData.aliases().size();
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
totalNumberOfShards += cursor.value.totalNumberOfShards();
numberOfShards += cursor.value.numberOfShards();
numAliases += cursor.value.aliases().size();
}
this.totalNumberOfShards = totalNumberOfShards;
this.numberOfShards = numberOfShards;
// build all indices map
List<String> allIndicesLst = Lists.newArrayList();
for (IndexMetaData indexMetaData : indices.values()) {
allIndicesLst.add(indexMetaData.index());
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
allIndicesLst.add(cursor.value.index());
}
allIndices = allIndicesLst.toArray(new String[allIndicesLst.size()]);
allIndicesSet = ImmutableSet.copyOf(allIndices);
int numIndices = allIndicesSet.size();
int numIndices = allIndicesLst.size();
List<String> allOpenIndices = Lists.newArrayList();
for (IndexMetaData indexMetaData : indices.values()) {
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
IndexMetaData indexMetaData = cursor.value;
if (indexMetaData.state() == IndexMetaData.State.OPEN) {
allOpenIndices.add(indexMetaData.index());
}
@ -172,47 +176,56 @@ public class MetaData implements Iterable<IndexMetaData> {
this.allOpenIndices = allOpenIndices.toArray(new String[allOpenIndices.size()]);
// build aliases map
Map<String, Map<String, AliasMetaData>> tmpAliases = new HashMap<String, Map<String, AliasMetaData>>(numAliases);
for (IndexMetaData indexMetaData : indices.values()) {
ImmutableOpenMap.Builder<String, Object> tmpAliases = ImmutableOpenMap.builder(numAliases);
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
IndexMetaData indexMetaData = cursor.value;
String index = indexMetaData.index();
for (AliasMetaData aliasMd : indexMetaData.aliases().values()) {
Map<String, AliasMetaData> indexAliasMap = tmpAliases.get(aliasMd.alias());
for (ObjectCursor<AliasMetaData> aliasCursor : indexMetaData.aliases().values()) {
AliasMetaData aliasMd = aliasCursor.value;
ImmutableOpenMap.Builder<String, AliasMetaData> indexAliasMap = (ImmutableOpenMap.Builder<String, AliasMetaData>) tmpAliases.get(aliasMd.alias());
if (indexAliasMap == null) {
indexAliasMap = new HashMap<String, AliasMetaData>(indices.size());
indexAliasMap = ImmutableOpenMap.builder(indices.size());
tmpAliases.put(aliasMd.alias(), indexAliasMap);
}
indexAliasMap.put(index, aliasMd);
}
}
for (String alias : tmpAliases.keySet()) {
tmpAliases.put(alias, XMaps.makeReadOnly(tmpAliases.get(alias)));
}
this.aliases = XMaps.makeReadOnly(tmpAliases);
Map<String, StringArray> aliasAndIndexToIndexMap = new HashMap<String, StringArray>(numAliases + numIndices);
for (IndexMetaData indexMetaData : indices.values()) {
StringArray indicesLst = aliasAndIndexToIndexMap.get(indexMetaData.index());
for (ObjectCursor<String> cursor : tmpAliases.keys()) {
String alias = cursor.value;
// if there is access to the raw values buffer of the map that the immutable maps wraps, then we don't need to use put, and just set array slots
ImmutableOpenMap<String, AliasMetaData> map = ((ImmutableOpenMap.Builder) tmpAliases.get(alias)).cast().build();
tmpAliases.put(alias, map);
}
this.aliases = tmpAliases.<String, ImmutableOpenMap<String, AliasMetaData>>cast().build();
ImmutableOpenMap.Builder<String, Object> aliasAndIndexToIndexMap = ImmutableOpenMap.builder(numAliases + numIndices);
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
IndexMetaData indexMetaData = cursor.value;
ObjectArrayList<String> indicesLst = (ObjectArrayList<String>) aliasAndIndexToIndexMap.get(indexMetaData.index());
if (indicesLst == null) {
indicesLst = new StringArray();
indicesLst = new ObjectArrayList<String>();
aliasAndIndexToIndexMap.put(indexMetaData.index(), indicesLst);
}
indicesLst.add(indexMetaData.index());
for (String alias : indexMetaData.aliases().keySet()) {
indicesLst = aliasAndIndexToIndexMap.get(alias);
for (ObjectCursor<String> cursor1 : indexMetaData.aliases().keys()) {
String alias = cursor1.value;
indicesLst = (ObjectArrayList<String>) aliasAndIndexToIndexMap.get(alias);
if (indicesLst == null) {
indicesLst = new StringArray();
indicesLst = new ObjectArrayList<String>();
aliasAndIndexToIndexMap.put(alias, indicesLst);
}
indicesLst.add(indexMetaData.index());
}
}
for (StringArray value : aliasAndIndexToIndexMap.values()) {
value.trim();
for (ObjectObjectCursor<String, Object> cursor : aliasAndIndexToIndexMap) {
String[] indicesLst = ((ObjectArrayList<String>) cursor.value).toArray(String.class);
aliasAndIndexToIndexMap.put(cursor.key, indicesLst);
}
this.aliasAndIndexToIndexMap = XMaps.makeReadOnly(aliasAndIndexToIndexMap);
this.aliasAndIndexToIndexMap = aliasAndIndexToIndexMap.<String, String[]>cast().build();
}
public long version() {
@ -234,11 +247,11 @@ public class MetaData implements Iterable<IndexMetaData> {
return this.persistentSettings;
}
public Map<String, Map<String, AliasMetaData>> aliases() {
public ImmutableOpenMap<String, ImmutableOpenMap<String, AliasMetaData>> aliases() {
return this.aliases;
}
public Map<String, Map<String, AliasMetaData>> getAliases() {
public ImmutableOpenMap<String, ImmutableOpenMap<String, AliasMetaData>> getAliases() {
return aliases();
}
@ -250,25 +263,25 @@ public class MetaData implements Iterable<IndexMetaData> {
* @param concreteIndices The concrete indexes the index aliases must point to order to be returned.
* @return the found index aliases grouped by index
*/
public ImmutableMap<String, ImmutableList<AliasMetaData>> findAliases(final String[] aliases, String[] concreteIndices) {
public ImmutableOpenMap<String, ImmutableList<AliasMetaData>> findAliases(final String[] aliases, String[] concreteIndices) {
assert aliases != null;
assert concreteIndices != null;
if (concreteIndices.length == 0) {
return ImmutableMap.of();
return ImmutableOpenMap.of();
}
ImmutableMap.Builder<String, ImmutableList<AliasMetaData>> mapBuilder = ImmutableMap.builder();
Sets.SetView<String> intersection = Sets.intersection(Sets.newHashSet(concreteIndices), indices.keySet());
ImmutableOpenMap.Builder<String, ImmutableList<AliasMetaData>> mapBuilder = ImmutableOpenMap.builder();
Iterable<String> intersection = HppcMaps.intersection(ObjectOpenHashSet.from(concreteIndices), indices.keys());
for (String index : intersection) {
IndexMetaData indexMetaData = indices.get(index);
Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() {
public boolean apply(String alias) {
// Simon says: we could build and FST out of the alias key and then run a regexp query against it ;)
return Regex.simpleMatch(aliases, alias);
List<AliasMetaData> filteredValues = Lists.newArrayList();
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) {
AliasMetaData value = cursor.value;
if (Regex.simpleMatch(aliases, value.alias())) {
filteredValues.add(value);
}
}
}).values();
if (!filteredValues.isEmpty()) {
mapBuilder.put(index, ImmutableList.copyOf(filteredValues));
}
@ -291,16 +304,16 @@ public class MetaData implements Iterable<IndexMetaData> {
return false;
}
Sets.SetView<String> intersection = Sets.intersection(Sets.newHashSet(concreteIndices), indices.keySet());
Iterable<String> intersection = HppcMaps.intersection(ObjectOpenHashSet.from(concreteIndices), indices.keys());
for (String index : intersection) {
IndexMetaData indexMetaData = indices.get(index);
Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() {
public boolean apply(String alias) {
return Regex.simpleMatch(aliases, alias);
List<AliasMetaData> filteredValues = Lists.newArrayList();
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) {
AliasMetaData value = cursor.value;
if (Regex.simpleMatch(aliases, value.alias())) {
filteredValues.add(value);
}
}).values();
}
if (!filteredValues.isEmpty()) {
return true;
}
@ -308,47 +321,45 @@ public class MetaData implements Iterable<IndexMetaData> {
return false;
}
public ImmutableMap<String, ImmutableMap<String, MappingMetaData>> findMappings(String[] concreteIndices, final String[] types) {
public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> findMappings(String[] concreteIndices, final String[] types) {
assert types != null;
assert concreteIndices != null;
if (concreteIndices.length == 0) {
return ImmutableMap.of();
return ImmutableOpenMap.of();
}
ImmutableMap.Builder<String, ImmutableMap<String, MappingMetaData>> indexMapBuilder = ImmutableMap.builder();
Sets.SetView<String> intersection = Sets.intersection(Sets.newHashSet(concreteIndices), indices.keySet());
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
Iterable<String> intersection = HppcMaps.intersection(ObjectOpenHashSet.from(concreteIndices), indices.keys());
for (String index : intersection) {
IndexMetaData indexMetaData = indices.get(index);
Map<String, MappingMetaData> filteredMappings;
ImmutableOpenMap.Builder<String, MappingMetaData> filteredMappings;
if (types.length == 0) {
indexMapBuilder.put(index, ImmutableMap.copyOf(indexMetaData.getMappings())); // No types specified means get it all
indexMapBuilder.put(index, indexMetaData.getMappings()); // No types specified means get it all
} else {
filteredMappings = Maps.filterKeys(indexMetaData.getMappings(), new Predicate<String>() {
@Override
public boolean apply(String type) {
return Regex.simpleMatch(types, type);
filteredMappings = ImmutableOpenMap.builder();
for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.mappings()) {
if (Regex.simpleMatch(types, cursor.key)) {
filteredMappings.put(cursor.key, cursor.value);
}
});
}
if (!filteredMappings.isEmpty()) {
indexMapBuilder.put(index, ImmutableMap.copyOf(filteredMappings));
indexMapBuilder.put(index, filteredMappings.build());
}
}
}
return indexMapBuilder.build();
}
public ImmutableMap<String, ImmutableList<IndexWarmersMetaData.Entry>> findWarmers(String[] concreteIndices, final String[] types, final String[] warmers) {
public ImmutableOpenMap<String, ImmutableList<IndexWarmersMetaData.Entry>> findWarmers(String[] concreteIndices, final String[] types, final String[] warmers) {
assert warmers != null;
assert concreteIndices != null;
if (concreteIndices.length == 0) {
return ImmutableMap.of();
return ImmutableOpenMap.of();
}
ImmutableMap.Builder<String, ImmutableList<IndexWarmersMetaData.Entry>> mapBuilder = ImmutableMap.builder();
Sets.SetView<String> intersection = Sets.intersection(Sets.newHashSet(concreteIndices), indices.keySet());
ImmutableOpenMap.Builder<String, ImmutableList<IndexWarmersMetaData.Entry>> mapBuilder = ImmutableOpenMap.builder();
Iterable<String> intersection = HppcMaps.intersection(ObjectOpenHashSet.from(concreteIndices), indices.keys());
for (String index : intersection) {
IndexMetaData indexMetaData = indices.get(index);
IndexWarmersMetaData indexWarmersMetaData = indexMetaData.custom(IndexWarmersMetaData.TYPE);
@ -386,10 +397,6 @@ public class MetaData implements Iterable<IndexMetaData> {
return allIndices;
}
public ImmutableSet<String> concreteAllIndicesAsSet() {
return allIndicesSet;
}
public String[] getConcreteAllIndices() {
return concreteAllIndices();
}
@ -407,14 +414,14 @@ public class MetaData implements Iterable<IndexMetaData> {
*/
public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex) {
// Check if index is specified by an alias
Map<String, AliasMetaData> indexAliases = aliases.get(aliasOrIndex);
ImmutableOpenMap<String, AliasMetaData> indexAliases = aliases.get(aliasOrIndex);
if (indexAliases == null || indexAliases.isEmpty()) {
return routing;
}
if (indexAliases.size() > 1) {
throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has more than one index associated with it [" + indexAliases.keySet() + "], can't execute a single index op");
throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has more than one index associated with it [" + Arrays.toString(indexAliases.keys().toArray(String.class)) + "], can't execute a single index op");
}
AliasMetaData aliasMd = indexAliases.values().iterator().next();
AliasMetaData aliasMd = indexAliases.values().iterator().next().value;
if (aliasMd.indexRouting() != null) {
if (routing != null) {
if (!routing.equals(aliasMd.indexRouting())) {
@ -455,40 +462,40 @@ public class MetaData implements Iterable<IndexMetaData> {
}
for (String aliasOrIndex : aliasesOrIndices) {
Map<String, AliasMetaData> indexToRoutingMap = aliases.get(aliasOrIndex);
ImmutableOpenMap<String, AliasMetaData> indexToRoutingMap = aliases.get(aliasOrIndex);
if (indexToRoutingMap != null && !indexToRoutingMap.isEmpty()) {
for (Map.Entry<String, AliasMetaData> indexRouting : indexToRoutingMap.entrySet()) {
if (!norouting.contains(indexRouting.getKey())) {
if (!indexRouting.getValue().searchRoutingValues().isEmpty()) {
for (ObjectObjectCursor<String, AliasMetaData> indexRouting : indexToRoutingMap) {
if (!norouting.contains(indexRouting.key)) {
if (!indexRouting.value.searchRoutingValues().isEmpty()) {
// Routing alias
if (routings == null) {
routings = newHashMap();
}
Set<String> r = routings.get(indexRouting.getKey());
Set<String> r = routings.get(indexRouting.key);
if (r == null) {
r = new HashSet<String>();
routings.put(indexRouting.getKey(), r);
routings.put(indexRouting.key, r);
}
r.addAll(indexRouting.getValue().searchRoutingValues());
r.addAll(indexRouting.value.searchRoutingValues());
if (paramRouting != null) {
r.retainAll(paramRouting);
}
if (r.isEmpty()) {
routings.remove(indexRouting.getKey());
routings.remove(indexRouting.key);
}
} else {
// Non-routing alias
if (!norouting.contains(indexRouting.getKey())) {
norouting.add(indexRouting.getKey());
if (!norouting.contains(indexRouting.key)) {
norouting.add(indexRouting.key);
if (paramRouting != null) {
Set<String> r = new HashSet<String>(paramRouting);
if (routings == null) {
routings = newHashMap();
}
routings.put(indexRouting.getKey(), r);
routings.put(indexRouting.key, r);
} else {
if (routings != null) {
routings.remove(indexRouting.getKey());
routings.remove(indexRouting.key);
}
}
}
@ -527,13 +534,13 @@ public class MetaData implements Iterable<IndexMetaData> {
paramRouting = Strings.splitStringByCommaToSet(routing);
}
Map<String, AliasMetaData> indexToRoutingMap = aliases.get(aliasOrIndex);
ImmutableOpenMap<String, AliasMetaData> indexToRoutingMap = aliases.get(aliasOrIndex);
if (indexToRoutingMap != null && !indexToRoutingMap.isEmpty()) {
// It's an alias
for (Map.Entry<String, AliasMetaData> indexRouting : indexToRoutingMap.entrySet()) {
if (!indexRouting.getValue().searchRoutingValues().isEmpty()) {
for (ObjectObjectCursor<String, AliasMetaData> indexRouting : indexToRoutingMap) {
if (!indexRouting.value.searchRoutingValues().isEmpty()) {
// Routing alias
Set<String> r = new HashSet<String>(indexRouting.getValue().searchRoutingValues());
Set<String> r = new HashSet<String>(indexRouting.value.searchRoutingValues());
if (paramRouting != null) {
r.retainAll(paramRouting);
}
@ -541,7 +548,7 @@ public class MetaData implements Iterable<IndexMetaData> {
if (routings == null) {
routings = newHashMap();
}
routings.put(indexRouting.getKey(), r);
routings.put(indexRouting.key, r);
}
} else {
// Non-routing alias
@ -550,7 +557,7 @@ public class MetaData implements Iterable<IndexMetaData> {
if (routings == null) {
routings = newHashMap();
}
routings.put(indexRouting.getKey(), r);
routings.put(indexRouting.key, r);
}
}
}
@ -608,11 +615,11 @@ public class MetaData implements Iterable<IndexMetaData> {
if (this.indices.containsKey(aliasOrIndex)) {
return aliasesOrIndices;
}
StringArray actualLst = aliasAndIndexToIndexMap.get(aliasOrIndex);
String[] actualLst = aliasAndIndexToIndexMap.get(aliasOrIndex);
if (actualLst == null) {
throw new IndexMissingException(new Index(aliasOrIndex));
} else {
return actualLst.values;
return actualLst;
}
}
@ -631,13 +638,13 @@ public class MetaData implements Iterable<IndexMetaData> {
Set<String> actualIndices = new HashSet<String>();
for (String index : aliasesOrIndices) {
StringArray actualLst = aliasAndIndexToIndexMap.get(index);
String[] actualLst = aliasAndIndexToIndexMap.get(index);
if (actualLst == null) {
if (ignoreIndices != IgnoreIndices.MISSING) {
throw new IndexMissingException(new Index(index));
}
} else {
for (String x : actualLst.values) {
for (String x : actualLst) {
actualIndices.add(x);
}
}
@ -655,14 +662,14 @@ public class MetaData implements Iterable<IndexMetaData> {
return index;
}
// not an actual index, fetch from an alias
StringArray lst = aliasAndIndexToIndexMap.get(index);
String[] lst = aliasAndIndexToIndexMap.get(index);
if (lst == null) {
throw new IndexMissingException(new Index(index));
}
if (lst.values.length > 1) {
throw new ElasticSearchIllegalArgumentException("Alias [" + index + "] has more than one indices associated with it [" + Arrays.toString(lst.values) + "], can't execute a single index op");
if (lst.length > 1) {
throw new ElasticSearchIllegalArgumentException("Alias [" + index + "] has more than one indices associated with it [" + Arrays.toString(lst) + "], can't execute a single index op");
}
return lst.values[0];
return lst[0];
}
/**
@ -729,7 +736,8 @@ public class MetaData implements Iterable<IndexMetaData> {
}
}
}
for (String alias : aliases.keySet()) {
for (ObjectCursor<String> cursor : aliases.keys()) {
String alias = cursor.value;
if (Regex.simpleMatch(aliasOrIndex, alias)) {
found = true;
if (add) {
@ -761,27 +769,27 @@ public class MetaData implements Iterable<IndexMetaData> {
return indices.get(index);
}
public Map<String, IndexMetaData> indices() {
public ImmutableOpenMap<String, IndexMetaData> indices() {
return this.indices;
}
public Map<String, IndexMetaData> getIndices() {
public ImmutableOpenMap<String, IndexMetaData> getIndices() {
return indices();
}
public Map<String, IndexTemplateMetaData> templates() {
public ImmutableOpenMap<String, IndexTemplateMetaData> templates() {
return this.templates;
}
public Map<String, IndexTemplateMetaData> getTemplates() {
public ImmutableOpenMap<String, IndexTemplateMetaData> getTemplates() {
return this.templates;
}
public Map<String, Custom> customs() {
public ImmutableOpenMap<String, Custom> customs() {
return this.customs;
}
public Map<String, Custom> getCustoms() {
public ImmutableOpenMap<String, Custom> getCustoms() {
return this.customs;
}
@ -921,7 +929,23 @@ public class MetaData implements Iterable<IndexMetaData> {
@Override
public Iterator<IndexMetaData> iterator() {
return indices.values().iterator();
final Iterator<ObjectCursor<IndexMetaData>> cursor = indices.values().iterator();
return new Iterator<IndexMetaData>() {
@Override
public boolean hasNext() {
return cursor.hasNext();
}
@Override
public IndexMetaData next() {
return cursor.next().value;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported");
}
};
}
public static boolean isGlobalStateEquals(MetaData metaData1, MetaData metaData2) {
@ -933,15 +957,15 @@ public class MetaData implements Iterable<IndexMetaData> {
}
// Check if any persistent metadata needs to be saved
int customCount1 = 0;
for (Map.Entry<String, Custom> entry : metaData1.customs.entrySet()) {
if (customFactories.get(entry.getKey()).isPersistent()) {
if (!entry.equals(metaData2.custom(entry.getKey()))) return false;
for (ObjectObjectCursor<String, Custom> cursor : metaData1.customs) {
if (customFactories.get(cursor.key).isPersistent()) {
if (!cursor.equals(metaData2.custom(cursor.key))) return false;
customCount1++;
}
}
int customCount2 = 0;
for (Map.Entry<String, Custom> entry : metaData2.customs.entrySet()) {
if (customFactories.get(entry.getKey()).isPersistent()) {
for (ObjectObjectCursor<String, Custom> cursor : metaData2.customs) {
if (customFactories.get(cursor.key).isPersistent()) {
customCount2++;
}
}
@ -964,21 +988,23 @@ public class MetaData implements Iterable<IndexMetaData> {
private Settings transientSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private Settings persistentSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private MapBuilder<String, IndexMetaData> indices = newMapBuilder();
private MapBuilder<String, IndexTemplateMetaData> templates = newMapBuilder();
private MapBuilder<String, Custom> customs = newMapBuilder();
private final ImmutableOpenMap.Builder<String, IndexMetaData> indices;
private final ImmutableOpenMap.Builder<String, IndexTemplateMetaData> templates;
private final ImmutableOpenMap.Builder<String, Custom> customs;
public Builder() {
indices = ImmutableOpenMap.builder();
templates = ImmutableOpenMap.builder();
customs = ImmutableOpenMap.builder();
}
public Builder(MetaData metaData) {
this.transientSettings = metaData.transientSettings;
this.persistentSettings = metaData.persistentSettings;
this.version = metaData.version;
this.indices.putAll(metaData.indices);
this.templates.putAll(metaData.templates);
this.customs.putAll(metaData.customs);
this.indices = ImmutableOpenMap.builder(metaData.indices);
this.templates = ImmutableOpenMap.builder(metaData.templates);
this.customs = ImmutableOpenMap.builder(metaData.customs);
}
public Builder put(IndexMetaData.Builder indexMetaDataBuilder) {
@ -1045,7 +1071,7 @@ public class MetaData implements Iterable<IndexMetaData> {
public Builder updateSettings(Settings settings, String... indices) {
if (indices == null || indices.length == 0) {
indices = this.indices.map().keySet().toArray(new String[this.indices.map().keySet().size()]);
indices = this.indices.keys().toArray(String.class);
}
for (String index : indices) {
IndexMetaData indexMetaData = this.indices.get(index);
@ -1060,7 +1086,7 @@ public class MetaData implements Iterable<IndexMetaData> {
public Builder updateNumberOfReplicas(int numberOfReplicas, String... indices) {
if (indices == null || indices.length == 0) {
indices = this.indices.map().keySet().toArray(new String[this.indices.map().keySet().size()]);
indices = this.indices.keys().toArray(String.class);
}
for (String index : indices) {
IndexMetaData indexMetaData = this.indices.get(index);
@ -1096,7 +1122,7 @@ public class MetaData implements Iterable<IndexMetaData> {
}
public MetaData build() {
return new MetaData(version, transientSettings, persistentSettings, indices.readOnlyMap(), templates.readOnlyMap(), customs.readOnlyMap());
return new MetaData(version, transientSettings, persistentSettings, indices.build(), templates.build(), customs.build());
}
public static String toXContent(MetaData metaData) throws IOException {
@ -1130,8 +1156,8 @@ public class MetaData implements Iterable<IndexMetaData> {
}
builder.startObject("templates");
for (IndexTemplateMetaData template : metaData.templates().values()) {
IndexTemplateMetaData.Builder.toXContent(template, builder, params);
for (ObjectCursor<IndexTemplateMetaData> cursor : metaData.templates().values()) {
IndexTemplateMetaData.Builder.toXContent(cursor.value, builder, params);
}
builder.endObject();
@ -1143,11 +1169,11 @@ public class MetaData implements Iterable<IndexMetaData> {
builder.endObject();
}
for (Map.Entry<String, Custom> entry : metaData.customs().entrySet()) {
Custom.Factory factory = lookupFactorySafe(entry.getKey());
for (ObjectObjectCursor<String, Custom> cursor : metaData.customs()) {
Custom.Factory factory = lookupFactorySafe(cursor.key);
if (!globalPersistentOnly || factory.isPersistent()) {
builder.startObject(entry.getKey());
factory.toXContent(entry.getValue(), builder, params);
builder.startObject(cursor.key);
factory.toXContent(cursor.value, builder, params);
builder.endObject();
}
}
@ -1240,45 +1266,14 @@ public class MetaData implements Iterable<IndexMetaData> {
IndexMetaData.Builder.writeTo(indexMetaData, out);
}
out.writeVInt(metaData.templates.size());
for (IndexTemplateMetaData template : metaData.templates.values()) {
IndexTemplateMetaData.Builder.writeTo(template, out);
for (ObjectCursor<IndexTemplateMetaData> cursor : metaData.templates.values()) {
IndexTemplateMetaData.Builder.writeTo(cursor.value, out);
}
out.writeVInt(metaData.customs().size());
for (Map.Entry<String, Custom> entry : metaData.customs().entrySet()) {
out.writeString(entry.getKey());
lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out);
for (ObjectObjectCursor<String, Custom> cursor : metaData.customs()) {
out.writeString(cursor.key);
lookupFactorySafe(cursor.key).writeTo(cursor.value, out);
}
}
}
static class StringArray {
String[] values = new String[1];
int head = 0;
void add(String value) {
if (head == values.length) {
grow();
}
values[head++] = value;
}
void grow() {
int newSize = values.length + 1;
String[] newValues = new String[ArrayUtil.oversize(newSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(values, 0, newValues, 0, values.length);
values = newValues;
}
void trim() {
if (values.length == head) {
return;
}
String[] newValues = new String[head];
System.arraycopy(values, 0, newValues, 0, head);
values = newValues;
}
}
}

View File

@ -19,6 +19,8 @@
package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@ -210,17 +212,17 @@ public class MetaDataCreateIndexService extends AbstractComponent {
// apply templates, merging the mappings into the request mapping if exists
for (IndexTemplateMetaData template : templates) {
for (Map.Entry<String, CompressedString> entry : template.mappings().entrySet()) {
if (mappings.containsKey(entry.getKey())) {
XContentHelper.mergeDefaults(mappings.get(entry.getKey()), parseMapping(entry.getValue().string()));
for (ObjectObjectCursor<String, CompressedString> cursor : template.mappings()) {
if (mappings.containsKey(cursor.key)) {
XContentHelper.mergeDefaults(mappings.get(cursor.key), parseMapping(cursor.value.string()));
} else {
mappings.put(entry.getKey(), parseMapping(entry.getValue().string()));
mappings.put(cursor.key, parseMapping(cursor.value.string()));
}
}
// handle custom
for (Map.Entry<String, Custom> customEntry : template.customs().entrySet()) {
String type = customEntry.getKey();
IndexMetaData.Custom custom = customEntry.getValue();
for (ObjectObjectCursor<String, Custom> cursor : template.customs()) {
String type = cursor.key;
IndexMetaData.Custom custom = cursor.value;
IndexMetaData.Custom existing = customs.get(type);
if (existing == null) {
customs.put(type, custom);
@ -463,7 +465,8 @@ public class MetaDataCreateIndexService extends AbstractComponent {
private List<IndexTemplateMetaData> findTemplates(Request request, ClusterState state) {
List<IndexTemplateMetaData> templates = Lists.newArrayList();
for (IndexTemplateMetaData template : state.metaData().templates().values()) {
for (ObjectCursor<IndexTemplateMetaData> cursor : state.metaData().templates().values()) {
IndexTemplateMetaData template = cursor.value;
if (Regex.simpleMatch(template.template(), request.index)) {
templates.add(template);
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
@ -141,7 +142,8 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
if (indexMetaData.mappings().containsKey(MapperService.DEFAULT_MAPPING)) {
indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, indexMetaData.mappings().get(MapperService.DEFAULT_MAPPING).source().string(), false);
}
for (MappingMetaData mappingMetaData : indexMetaData.mappings().values()) {
for (ObjectCursor<MappingMetaData> cursor : indexMetaData.mappings().values()) {
MappingMetaData mappingMetaData = cursor.value;
indexService.mapperService().merge(mappingMetaData.type(), mappingMetaData.source().string(), false);
}
} catch (Exception e) {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.elasticsearch.ElasticSearchException;
@ -72,7 +73,8 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
@Override
public ClusterState execute(ClusterState currentState) {
Set<String> templateNames = Sets.newHashSet();
for (String templateName : currentState.metaData().templates().keySet()) {
for (ObjectCursor<String> cursor : currentState.metaData().templates().keys()) {
String templateName = cursor.value;
if (Regex.simpleMatch(request.name, templateName)) {
templateNames.add(templateName);
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.cluster.routing;
import com.carrotsearch.hppc.ObjectIntOpenHashMap;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@ -133,7 +134,8 @@ public class RoutingNodes implements Iterable<RoutingNode> {
public int requiredAverageNumberOfShardsPerNode() {
int totalNumberOfShards = 0;
// we need to recompute to take closed shards into account
for (IndexMetaData indexMetaData : metaData.indices().values()) {
for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
IndexMetaData indexMetaData = cursor.value;
if (indexMetaData.state() == IndexMetaData.State.OPEN) {
totalNumberOfShards += indexMetaData.totalNumberOfShards();
}

View File

@ -1,9 +1,13 @@
package org.elasticsearch.common.hppc;
package org.elasticsearch.common.collect;
import com.carrotsearch.hppc.ObjectIntOpenHashMap;
import com.carrotsearch.hppc.ObjectLookupContainer;
import com.carrotsearch.hppc.ObjectObjectOpenHashMap;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import java.util.Iterator;
/**
*/
public final class HppcMaps {
@ -57,6 +61,50 @@ public final class HppcMaps {
};
}
/**
* @return an intersection view over the two specified containers (which can be KeyContainer or ObjectOpenHashSet).
*/
// Hppc has forEach, but this means we need to build an intermediate set, with this method we just iterate
// over each unique value without creating a third set.
public static <T> Iterable<T> intersection(ObjectLookupContainer<T> container1, final ObjectLookupContainer<T> container2) {
assert container1 != null && container2 != null;
final Iterator<ObjectCursor<T>> iterator = container1.iterator();
final Iterator<T> intersection = new Iterator<T>() {
T current;
@Override
public boolean hasNext() {
if (iterator.hasNext()) {
do {
T next = iterator.next().value;
if (container2.contains(next)) {
current = next;
return true;
}
} while (iterator.hasNext());
}
return false;
}
@Override
public T next() {
return current;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return intersection;
}
};
}
public final static class Object {
public final static class Integer {

View File

@ -146,6 +146,10 @@ public final class ImmutableOpenMap<KType, VType> implements Iterable<ObjectObje
return new Builder<KType, VType>();
}
public static <KType, VType> Builder<KType, VType> builder(int size) {
return new Builder<KType, VType>(size);
}
public static <KType, VType> Builder<KType, VType> builder(ImmutableOpenMap<KType, VType> map) {
return new Builder<KType, VType>(map);
}
@ -159,6 +163,10 @@ public final class ImmutableOpenMap<KType, VType> implements Iterable<ObjectObje
this(EMPTY);
}
public Builder(int size) {
this.map = new ObjectObjectOpenHashMap<KType, VType>(size);
}
public Builder(ImmutableOpenMap<KType, VType> map) {
this.map = map.map.clone();
}
@ -267,5 +275,11 @@ public final class ImmutableOpenMap<KType, VType> implements Iterable<ObjectObje
public ObjectContainer<VType> values() {
return map.values();
}
@SuppressWarnings("unchecked")
public <K, V> Builder<K, V> cast() {
return (Builder) this;
}
}
}

View File

@ -84,10 +84,6 @@ public class MapBuilder<K, V> {
return this.map;
}
public Map<K, V> readOnlyMap() {
return XMaps.makeReadOnly(map);
}
public ImmutableMap<K, V> immutableMap() {
return ImmutableMap.copyOf(map);
}

View File

@ -1,41 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.collect;
import java.util.Collections;
import java.util.Map;
/**
* This class provides factory methods for Maps. The returned {@link Map}
* instances are general purpose maps and non of the method guarantees a
* concrete implementation unless the return type is a concrete type. The
* implementations used might change over time, if you rely on a specific
* Implementation you should use a concrete constructor.
*/
public final class XMaps {
/**
* Wraps the given map into a read only implementation.
*/
public static <K, V> Map<K, V> makeReadOnly(Map<K, V> map) {
return Collections.unmodifiableMap(map);
}
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.gateway;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.cluster.*;
import org.elasticsearch.cluster.block.ClusterBlock;
@ -264,8 +265,8 @@ public class GatewayService extends AbstractLifecycleComponent<GatewayService> i
// initialize all index routing tables as empty
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable());
for (IndexMetaData indexMetaData : updatedState.metaData().indices().values()) {
routingTableBuilder.addAsRecovery(indexMetaData);
for (ObjectCursor<IndexMetaData> cursor : updatedState.metaData().indices().values()) {
routingTableBuilder.addAsRecovery(cursor.value);
}
// start with 0 based versions for routing table
routingTableBuilder.version(0);

View File

@ -20,6 +20,7 @@
package org.elasticsearch.gateway.local;
import com.carrotsearch.hppc.ObjectFloatOpenHashMap;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.Sets;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.FailedNodeException;
@ -148,8 +149,8 @@ public class LocalGateway extends AbstractLifecycleComponent<Gateway> implements
} else if (nodeState.metaData().version() > electedGlobalState.version()) {
electedGlobalState = nodeState.metaData();
}
for (IndexMetaData indexMetaData : nodeState.metaData().indices().values()) {
indices.addTo(indexMetaData.index(), 1);
for (ObjectCursor<IndexMetaData> cursor : nodeState.metaData().indices().values()) {
indices.addTo(cursor.value.index(), 1);
}
}
if (found < requiredAllocation) {

View File

@ -230,7 +230,8 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
continue;
}
if (!newMetaData.hasIndex(current.index())) {
logger.debug("[{}] deleting index that is no longer part of the metadata (indices: [{}])", current.index(), newMetaData.indices().keySet());
// TODO: Create util for toString()
logger.debug("[{}] deleting index that is no longer part of the metadata (indices: [{}])", current.index(), newMetaData.indices().keys());
if (nodeEnv.hasNodeFile()) {
FileSystemUtils.deleteRecursively(nodeEnv.indexLocations(new Index(current.index())));
}

View File

@ -116,7 +116,8 @@ public class NoneGateway extends AbstractLifecycleComponent<Gateway> implements
// only delete indices when we already received a state (currentMetaData != null)
for (IndexMetaData current : currentMetaData) {
if (!newMetaData.hasIndex(current.index())) {
logger.debug("[{}] deleting index that is no longer part of the metadata (indices: [{}])", current.index(), newMetaData.indices().keySet());
// TODO: have util for toString()
logger.debug("[{}] deleting index that is no longer part of the metadata (indices: [{}])", current.index(), newMetaData.indices().keys());
if (nodeEnv.hasNodeFile()) {
FileSystemUtils.deleteRecursively(nodeEnv.indexLocations(new Index(current.index())));
}

View File

@ -30,7 +30,7 @@ import org.apache.lucene.search.Filter;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;

View File

@ -20,6 +20,8 @@
package org.elasticsearch.indices.cluster;
import com.carrotsearch.hppc.IntOpenHashSet;
import com.carrotsearch.hppc.ObjectContainer;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.Lists;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ExceptionsHelper;
@ -353,7 +355,8 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
}
// go over and add the relevant mappings (or update them)
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
for (ObjectCursor<MappingMetaData> cursor : indexMetaData.mappings().values()) {
MappingMetaData mappingMd = cursor.value;
String mappingType = mappingMd.type();
CompressedString mappingSource = mappingMd.source();
if (mappingType.equals(MapperService.DEFAULT_MAPPING)) { // we processed _default_ first
@ -456,9 +459,10 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
}
}
private void processAliases(String index, Collection<AliasMetaData> aliases, IndexAliasesService indexAliasesService) {
private void processAliases(String index, ObjectContainer<AliasMetaData> aliases, IndexAliasesService indexAliasesService) {
HashMap<String, IndexAlias> newAliases = newHashMap();
for (AliasMetaData aliasMd : aliases) {
for (ObjectCursor<AliasMetaData> cursor : aliases) {
AliasMetaData aliasMd = cursor.value;
String alias = aliasMd.alias();
CompressedString filter = aliasMd.filter();
try {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.alias;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
@ -75,8 +76,8 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler {
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("aliases");
for (AliasMetaData alias : indexMetaData.aliases().values()) {
AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS);
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.aliases().values()) {
AliasMetaData.Builder.toXContent(cursor.value, builder, ToXContent.EMPTY_PARAMS);
}
builder.endObject();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.alias.get;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
@ -37,7 +38,6 @@ import org.elasticsearch.rest.action.support.RestXContentBuilder;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
@ -81,10 +81,10 @@ public class RestGetAliasesAction extends BaseRestHandler {
}
builder.startObject();
for (Map.Entry<String, List<AliasMetaData>> entry : response.getAliases().entrySet()) {
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
for (ObjectObjectCursor<String, List<AliasMetaData>> entry : response.getAliases()) {
builder.startObject(entry.key, XContentBuilder.FieldCaseConversion.NONE);
builder.startObject(Fields.ALIASES);
for (AliasMetaData alias : entry.getValue()) {
for (AliasMetaData alias : entry.value) {
AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS);
}
builder.endObject();

View File

@ -19,13 +19,14 @@
package org.elasticsearch.rest.action.admin.indices.mapping.get;
import com.google.common.collect.ImmutableMap;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -36,7 +37,6 @@ import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
@ -69,7 +69,7 @@ public class RestGetMappingAction extends BaseRestHandler {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject();
ImmutableMap<String, ImmutableMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
if (mappingsByIndex.isEmpty()) {
if (indices.length != 0 && types.length != 0) {
channel.sendResponse(new XContentThrowableRestResponse(request, new TypeMissingException(new Index(indices[0]), types[0])));
@ -84,11 +84,11 @@ public class RestGetMappingAction extends BaseRestHandler {
return;
}
for (Map.Entry<String, ImmutableMap<String, MappingMetaData>> indexEntry : mappingsByIndex.entrySet()) {
builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
for (Map.Entry<String, MappingMetaData> typeEntry : indexEntry.getValue().entrySet()) {
builder.field(typeEntry.getKey());
builder.map(typeEntry.getValue().sourceAsMap());
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappingsByIndex) {
builder.startObject(indexEntry.key, XContentBuilder.FieldCaseConversion.NONE);
for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
builder.field(typeEntry.key);
builder.map(typeEntry.value.sourceAsMap());
}
builder.endObject();
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.warmer.get;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequest;
@ -35,7 +36,6 @@ import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
@ -75,10 +75,10 @@ public class RestGetWarmerAction extends BaseRestHandler {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject();
for (Map.Entry<String, ImmutableList<IndexWarmersMetaData.Entry>> entry : response.warmers().entrySet()) {
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
for (ObjectObjectCursor<String, ImmutableList<IndexWarmersMetaData.Entry>> entry : response.warmers()) {
builder.startObject(entry.key, XContentBuilder.FieldCaseConversion.NONE);
builder.startObject(IndexWarmersMetaData.TYPE, XContentBuilder.FieldCaseConversion.NONE);
for (IndexWarmersMetaData.Entry warmerEntry : entry.getValue()) {
for (IndexWarmersMetaData.Entry warmerEntry : entry.value) {
IndexWarmersMetaData.FACTORY.toXContent(warmerEntry, builder, request);
}
builder.endObject();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.river.routing;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.elasticsearch.ElasticSearchException;
@ -123,8 +124,8 @@ public class RiversRouter extends AbstractLifecycleComponent<RiversRouter> imple
IndexMetaData indexMetaData = newClusterState.metaData().index(riverIndexName);
// go over and create new river routing (with no node) for new types (rivers names)
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
String mappingType = mappingMd.type(); // mapping type is the name of the river
for (ObjectCursor<MappingMetaData> cursor : indexMetaData.mappings().values()) {
String mappingType = cursor.value.type(); // mapping type is the name of the river
if (!currentState.routing().hasRiverByName(mappingType)) {
// no river, we need to add it to the routing with no node allocation
try {

View File

@ -27,7 +27,7 @@ import org.apache.lucene.search.*;
import org.apache.lucene.util.PriorityQueue;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;

View File

@ -24,7 +24,7 @@ import com.carrotsearch.hppc.ObjectObjectOpenHashMap;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.CollectionStatistics;
import org.apache.lucene.search.TermStatistics;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;

View File

@ -28,7 +28,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.search.CollectionStatistics;
import org.apache.lucene.search.TermStatistics;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.SearchPhase;
import org.elasticsearch.search.internal.SearchContext;

View File

@ -24,7 +24,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.CollectionStatistics;
import org.apache.lucene.search.TermStatistics;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.SearchPhaseResult;

View File

@ -18,6 +18,8 @@
*/
package org.elasticsearch.snapshots;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version;
@ -207,16 +209,16 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
}
if (metaData.templates() != null) {
// TODO: Should all existing templates be deleted first?
for (IndexTemplateMetaData template : metaData.templates().values()) {
mdBuilder.put(template);
for (ObjectCursor<IndexTemplateMetaData> cursor : metaData.templates().values()) {
mdBuilder.put(cursor.value);
}
}
if (metaData.customs() != null) {
for (ImmutableMap.Entry<String, MetaData.Custom> custom : metaData.customs().entrySet()) {
if (!RepositoriesMetaData.TYPE.equals(custom.getKey())) {
for (ObjectObjectCursor<String, MetaData.Custom> cursor : metaData.customs()) {
if (!RepositoriesMetaData.TYPE.equals(cursor.key)) {
// Don't restore repositories while we are working with them
// TODO: Should we restore them at the end?
mdBuilder.putCustom(custom.getKey(), custom.getValue());
mdBuilder.putCustom(cursor.key, cursor.value);
}
}
}

View File

@ -22,6 +22,8 @@ package org.elasticsearch.benchmark.aliases;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.IndexAlreadyExistsException;
@ -29,6 +31,7 @@ import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import java.io.IOException;
import java.util.List;
/**
*/
@ -66,7 +69,7 @@ public class AliasesBenchmark {
System.out.println("Adding " + diff + " more aliases to get to the start amount of " + BASE_ALIAS_COUNT + " aliases");
IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases();
for (int i = 1; i <= diff; i++) {
builder.addAlias(INDEX_NAME, "alias" + numberOfAliases + i);
builder.addAlias(INDEX_NAME, Strings.randomBase64UUID());
if (i % 1000 == 0) {
builder.execute().actionGet();
builder = client.admin().indices().prepareAliases();
@ -78,9 +81,12 @@ public class AliasesBenchmark {
} else if (numberOfAliases > BASE_ALIAS_COUNT) {
IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases();
int diff = numberOfAliases - BASE_ALIAS_COUNT;
System.out.println("Removing " + diff + " aliases to get to the start amount of " + BASE_ALIAS_COUNT + "aliases");
System.out.println("Removing " + diff + " aliases to get to the start amount of " + BASE_ALIAS_COUNT + " aliases");
List<AliasMetaData> aliases= client.admin().indices().prepareGetAliases("*")
.addIndices(INDEX_NAME)
.execute().actionGet().getAliases().get(INDEX_NAME);
for (int i = 0; i <= diff; i++) {
builder.removeAlias(INDEX_NAME, "alias" + (BASE_ALIAS_COUNT + i));
builder.removeAlias(INDEX_NAME, aliases.get(i).alias());
if (i % 1000 == 0) {
builder.execute().actionGet();
builder = client.admin().indices().prepareAliases();
@ -105,7 +111,7 @@ public class AliasesBenchmark {
long time = System.currentTimeMillis();
// String filter = termFilter("field" + i, "value" + i).toXContent(XContentFactory.jsonBuilder(), null).string();
client.admin().indices().prepareAliases().addAlias(INDEX_NAME, "alias" + i/*, filter*/)
client.admin().indices().prepareAliases().addAlias(INDEX_NAME, Strings.randomBase64UUID()/*, filter*/)
.execute().actionGet();
totalTime += System.currentTimeMillis() - time;
}
@ -119,7 +125,7 @@ public class AliasesBenchmark {
}
private static int countAliases(Client client) {
GetAliasesResponse response = client.admin().indices().prepareGetAliases("a*")
GetAliasesResponse response = client.admin().indices().prepareGetAliases("*")
.addIndices(INDEX_NAME)
.execute().actionGet();
if (response.getAliases().isEmpty()) {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.cluster.ack;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
@ -46,8 +47,6 @@ import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import java.util.Map;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.SUITE;
@ -97,10 +96,10 @@ public class AckTests extends ElasticsearchIntegrationTest {
for (Client client : clients()) {
GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get();
assertThat(getWarmersResponse.warmers().size(), equalTo(1));
Map.Entry<String,ImmutableList<IndexWarmersMetaData.Entry>> entry = getWarmersResponse.warmers().entrySet().iterator().next();
assertThat(entry.getKey(), equalTo("test"));
assertThat(entry.getValue().size(), equalTo(1));
assertThat(entry.getValue().get(0).name(), equalTo("custom_warmer"));
ObjectObjectCursor<String,ImmutableList<IndexWarmersMetaData.Entry>> entry = getWarmersResponse.warmers().iterator().next();
assertThat(entry.key, equalTo("test"));
assertThat(entry.value.size(), equalTo(1));
assertThat(entry.value.get(0).name(), equalTo("custom_warmer"));
}
}

View File

@ -1,5 +1,6 @@
package org.elasticsearch.cluster.routing.allocation;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@ -276,8 +277,8 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
MetaData metaData = metaDataBuilder.build();
for (IndexMetaData index : metaData.indices().values()) {
routingTableBuilder.addAsNew(index);
for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
routingTableBuilder.addAsNew(cursor.value);
}
RoutingTable routingTable = routingTableBuilder.build();
@ -325,8 +326,9 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
IndexMetaData.Builder index = IndexMetaData.builder("test" + indexOrdinal).numberOfShards(numberOfShards).numberOfReplicas(
numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
routingTableBuilder.addAsNew(index.build());
IndexMetaData imd = index.build();
metaDataBuilder = metaDataBuilder.put(imd, true);
routingTableBuilder.addAsNew(imd);
MetaData metaData = metaDataBuilder.build();
RoutingTable routingTable = routingTableBuilder.build();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.cluster.routing.allocation;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.cluster.ClusterInfoService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -150,8 +151,8 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
MetaData metaData = metaDataBuilder.build();
for (IndexMetaData index : metaData.indices().values()) {
routingTableBuilder.addAsNew(index);
for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
routingTableBuilder.addAsNew(cursor.value);
}
RoutingTable routingTable = routingTableBuilder.build();
@ -453,8 +454,8 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
IndexMetaData.Builder indexMeta = IndexMetaData.builder("test").numberOfShards(5).numberOfReplicas(1);
metaDataBuilder = metaDataBuilder.put(indexMeta);
MetaData metaData = metaDataBuilder.build();
for (IndexMetaData index : metaData.indices().values()) {
routingTableBuilder.addAsNew(index);
for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
routingTableBuilder.addAsNew(cursor.value);
}
RoutingTable routingTable = routingTableBuilder.build();
DiscoveryNodes.Builder nodes = DiscoveryNodes.builder();

View File

@ -0,0 +1,100 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.elasticsearch.common.hppc;
import com.carrotsearch.hppc.ObjectOpenHashSet;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
public class HppcMapsTests extends ElasticsearchTestCase {
@Test
public void testIntersection() throws Exception {
ObjectOpenHashSet<String> set1 = ObjectOpenHashSet.from("1", "2", "3");
ObjectOpenHashSet<String> set2 = ObjectOpenHashSet.from("1", "2", "3");
List<String> values = toList(HppcMaps.intersection(set1, set2));
assertThat(values.size(), equalTo(3));
assertThat(values.contains("1"), equalTo(true));
assertThat(values.contains("2"), equalTo(true));
assertThat(values.contains("3"), equalTo(true));
set1 = ObjectOpenHashSet.from("1", "2", "3");
set2 = ObjectOpenHashSet.from("3", "4", "5");
values = toList(HppcMaps.intersection(set1, set2));
assertThat(values.size(), equalTo(1));
assertThat(values.get(0), equalTo("3"));
set1 = ObjectOpenHashSet.from("1", "2", "3");
set2 = ObjectOpenHashSet.from("4", "5", "6");
values = toList(HppcMaps.intersection(set1, set2));
assertThat(values.size(), equalTo(0));
set1 = ObjectOpenHashSet.from();
set2 = ObjectOpenHashSet.from("3", "4", "5");
values = toList(HppcMaps.intersection(set1, set2));
assertThat(values.size(), equalTo(0));
set1 = ObjectOpenHashSet.from("1", "2", "3");
set2 = ObjectOpenHashSet.from();
values = toList(HppcMaps.intersection(set1, set2));
assertThat(values.size(), equalTo(0));
set1 = ObjectOpenHashSet.from();
set2 = ObjectOpenHashSet.from();
values = toList(HppcMaps.intersection(set1, set2));
assertThat(values.size(), equalTo(0));
set1 = null;
set2 = ObjectOpenHashSet.from();
try {
toList(HppcMaps.intersection(set1, set2));
fail();
} catch (AssertionError e) {}
set1 = ObjectOpenHashSet.from();
set2 = null;
try {
toList(HppcMaps.intersection(set1, set2));
fail();
} catch (AssertionError e) {}
set1 = null;
set2 = null;
try {
toList(HppcMaps.intersection(set1, set2));
fail();
} catch (AssertionError e) {}
}
private List<String> toList(Iterable<String> iterable) {
List<String> list = new ArrayList<String>();
for (String s : iterable) {
list.add(s);
}
return list;
}
}

View File

@ -53,7 +53,7 @@ public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest {
ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
for (int i = 0; i < 10 && !clusterState.metaData().index("test").mappings().containsKey("type1"); i++, Thread.sleep(100)) ;
assertThat(clusterState.metaData().index("test").mappings(), hasKey("type1"));
assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(true));
GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings("test").setTypes("type1").execute().actionGet();
assertThat(mappingsResponse.getMappings().get("test").get("type1"), notNullValue());

View File

@ -40,7 +40,7 @@ public class SimpleGetMappingsTests extends ElasticsearchIntegrationTest {
public void getMappingsWhereThereAreNone() {
createIndex("index");
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
assertThat(response.mappings(), hasKey("index"));
assertThat(response.mappings().containsKey("index"), equalTo(true));
assertThat(response.mappings().get("index").size(), equalTo(0));
}

View File

@ -8,6 +8,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.MapperParsingException;
@ -330,8 +331,8 @@ public class UpdateMappingTests extends ElasticsearchIntegrationTest {
assertThat(response.isAcknowledged(), equalTo(true));
GetMappingsResponse getMappingResponse = client2.admin().indices().prepareGetMappings(indexName).get();
Map<String, MappingMetaData> mappings = getMappingResponse.getMappings().get(indexName);
assertThat(mappings.keySet(), Matchers.hasItem(typeName));
ImmutableOpenMap<String, MappingMetaData> mappings = getMappingResponse.getMappings().get(indexName);
assertThat(mappings.containsKey(typeName), equalTo(true));
assertThat(((Map<String, Object>) mappings.get(typeName).getSourceAsMap().get("properties")).keySet(), Matchers.hasItem(fieldName));
}
} catch (Throwable t) {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.indices.warmer;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse;
@ -33,8 +34,6 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.hamcrest.Matchers;
import org.junit.Test;
import java.util.Map;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@ -184,10 +183,10 @@ public class SimpleIndicesWarmerTests extends ElasticsearchIntegrationTest {
GetWarmersResponse getWarmersResponse = client().admin().indices().prepareGetWarmers("test").get();
assertThat(getWarmersResponse.warmers().size(), equalTo(1));
Map.Entry<String, ImmutableList<IndexWarmersMetaData.Entry>> entry = getWarmersResponse.warmers().entrySet().iterator().next();
assertThat(entry.getKey(), equalTo("test"));
assertThat(entry.getValue().size(), equalTo(1));
assertThat(entry.getValue().iterator().next().name(), equalTo("custom_warmer"));
ObjectObjectCursor<String, ImmutableList<IndexWarmersMetaData.Entry>> entry = getWarmersResponse.warmers().iterator().next();
assertThat(entry.key, equalTo("test"));
assertThat(entry.value.size(), equalTo(1));
assertThat(entry.value.iterator().next().name(), equalTo("custom_warmer"));
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer").get();
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));