Skip to content

Commit

Permalink
Closed indices should not cause block failures on some APIs what exec…
Browse files Browse the repository at this point in the history
…uting against _all indices, closes #1010.
  • Loading branch information
kimchy committed Jul 10, 2011
1 parent 1acca20 commit b275e6f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
Expand Up @@ -91,7 +91,7 @@ public class TransportSearchAction extends BaseAction<SearchRequest, SearchRespo
if (optimizeSingleShard && searchRequest.searchType() != SCAN && searchRequest.searchType() != COUNT) {
try {
ClusterState clusterState = clusterService.state();
String[] concreteIndices = clusterState.metaData().concreteIndices(searchRequest.indices());
String[] concreteIndices = clusterState.metaData().concreteIndices(searchRequest.indices(), false, true);
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(searchRequest.routing(), searchRequest.indices());
int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, searchRequest.indices(), concreteIndices, searchRequest.queryHint(), routingMap, searchRequest.preference());
if (shardCount == 1) {
Expand Down
Expand Up @@ -20,7 +20,12 @@
package org.elasticsearch.action.search.type;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.*;
import org.elasticsearch.action.search.ReduceSearchPhaseException;
import org.elasticsearch.action.search.SearchOperationThreading;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -105,7 +110,7 @@ protected BaseAsyncAction(SearchRequest request, ActionListener<SearchResponse>

nodes = clusterState.nodes();

String[] concreteIndices = clusterState.metaData().concreteIndices(request.indices());
String[] concreteIndices = clusterState.metaData().concreteIndices(request.indices(), false, true);

for (String index : concreteIndices) {
clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.READ, index);
Expand Down
Expand Up @@ -32,7 +32,11 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.*;
import org.elasticsearch.transport.BaseTransportRequestHandler;
import org.elasticsearch.transport.BaseTransportResponseHandler;
import org.elasticsearch.transport.TransportChannel;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportService;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;
Expand Down Expand Up @@ -152,7 +156,7 @@ class AsyncBroadcastAction {
clusterState = clusterService.state();

// update to concrete indices
concreteIndices = clusterState.metaData().concreteIndices(request.indices());
concreteIndices = clusterState.metaData().concreteIndices(request.indices(), false, true);
checkBlock(request, concreteIndices, clusterState);

nodes = clusterState.nodes();
Expand Down
Expand Up @@ -72,6 +72,7 @@ public class MetaData implements Iterable<IndexMetaData> {
private final transient int totalNumberOfShards;

private final String[] allIndices;
private final String[] allOpenIndices;

private final ImmutableMap<String, ImmutableMap<String, AliasMetaData>> aliases;

Expand Down Expand Up @@ -99,6 +100,14 @@ private MetaData(long version, ImmutableMap<String, IndexMetaData> indices, Immu
}
allIndices = allIndicesLst.toArray(new String[allIndicesLst.size()]);

List<String> allOpenIndices = Lists.newArrayList();
for (IndexMetaData indexMetaData : indices.values()) {
if (indexMetaData.state() == IndexMetaData.State.OPEN) {
allOpenIndices.add(indexMetaData.index());
}
}
this.allOpenIndices = allOpenIndices.toArray(new String[allOpenIndices.size()]);

// build aliases map
MapBuilder<String, MapBuilder<String, AliasMetaData>> tmpAliasesMap = newMapBuilder();
for (IndexMetaData indexMetaData : indices.values()) {
Expand Down Expand Up @@ -207,18 +216,26 @@ public String[] getConcreteAllIndices() {
return concreteAllIndices();
}

public String[] concreteAllOpenIndices() {
return allOpenIndices;
}

public String[] getConcreteAllOpenIndices() {
return allOpenIndices;
}

/**
* Translates the provided indices (possibly aliased) into actual indices.
*/
public String[] concreteIndices(String[] indices) throws IndexMissingException {
return concreteIndices(indices, false);
return concreteIndices(indices, false, false);
}

/**
* Translates the provided indices (possibly aliased) into actual indices.
*/
public String[] concreteIndicesIgnoreMissing(String[] indices) {
return concreteIndices(indices, true);
return concreteIndices(indices, true, false);
}

/**
Expand Down Expand Up @@ -404,18 +421,18 @@ public Map<String, Set<String>> resolveSearchRouting(@Nullable String routing, S
/**
* Translates the provided indices (possibly aliased) into actual indices.
*/
public String[] concreteIndices(String[] indices, boolean ignoreMissing) throws IndexMissingException {
public String[] concreteIndices(String[] indices, boolean ignoreMissing, boolean allOnlyOpen) throws IndexMissingException {
if (indices == null || indices.length == 0) {
return concreteAllIndices();
return allOnlyOpen ? concreteAllOpenIndices() : concreteAllIndices();
}
// optimize for single element index (common case)
if (indices.length == 1) {
String index = indices[0];
if (index.length() == 0) {
return concreteAllIndices();
return allOnlyOpen ? concreteAllOpenIndices() : concreteAllIndices();
}
if (index.equals("_all")) {
return concreteAllIndices();
return allOnlyOpen ? concreteAllOpenIndices() : concreteAllIndices();
}
// if a direct index name, just return the array provided
if (this.indices.containsKey(index)) {
Expand Down
Expand Up @@ -102,7 +102,7 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio

@Override public int searchShardsCount(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable String queryHint, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
if (concreteIndices == null || concreteIndices.length == 0) {
concreteIndices = clusterState.metaData().concreteAllIndices();
concreteIndices = clusterState.metaData().concreteAllOpenIndices();
}
if (routing != null) {
HashSet<ShardId> set = new HashSet<ShardId>();
Expand Down Expand Up @@ -135,7 +135,7 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio

@Override public GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable String queryHint, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
if (concreteIndices == null || concreteIndices.length == 0) {
concreteIndices = clusterState.metaData().concreteAllIndices();
concreteIndices = clusterState.metaData().concreteAllOpenIndices();
}

if (routing != null) {
Expand Down

0 comments on commit b275e6f

Please sign in to comment.