Skip to content

Commit

Permalink
Internal: Add METADATA_READ and METADATA_WRITE blocks
Browse files Browse the repository at this point in the history
This commit splits the current ClusterBlockLevel.METADATA into two disctins ClusterBlockLevel.METADATA_READ and ClusterBlockLevel.METADATA_WRITE blocks. It allows to make a distinction between
an operation that modifies the index or cluster metadata and an operation that does not change any metadata.

Before this commit, many operations where blocked when the cluster was read-only: Cluster Stats, Get Mappings, Get Snapshot, Get Index Settings, etc. Now those operations are allowed even when
the cluster or the index is read-only.

Related to #8102, #2833

Closes #3703
Closes #5855
Closes #10521
Closes #10522
  • Loading branch information
tlrx committed Apr 23, 2015
1 parent 2e2e345 commit adc0807
Show file tree
Hide file tree
Showing 81 changed files with 1,912 additions and 252 deletions.
30 changes: 30 additions & 0 deletions rest-api-spec/test/indices.exists/20_read_only_index.yaml
@@ -0,0 +1,30 @@
---
"Test indices.exists on a read only index":

- do:
indices.create:
index: test_index_ro

- do:
indices.put_settings:
index: test_index_ro
body:
index.blocks.read_only: true

- do:
indices.exists:
index: test_index_ro

- is_true: ''

- do:
indices.put_settings:
index: test_index_ro
body:
index.blocks.read_only: false

- do:
indices.exists:
index: test_index_ro

- is_true: ''
Expand Up @@ -75,7 +75,8 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(NodesShutdownRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
// Stopping a node impacts the cluster state, so we check for the METADATA_WRITE block here
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected DeleteRepositoryResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(DeleteRepositoryRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, "");
}

@Override
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected GetRepositoriesResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(GetRepositoriesRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_READ, "");
}

@Override
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected PutRepositoryResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(PutRepositoryRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, "");
}

@Override
Expand Down
Expand Up @@ -69,7 +69,7 @@ protected VerifyRepositoryResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(VerifyRepositoryRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_READ, "");
}

@Override
Expand Down
Expand Up @@ -58,7 +58,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(ClusterRerouteRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}

@Override
Expand Down
Expand Up @@ -76,7 +76,7 @@ protected ClusterBlockException checkBlock(ClusterUpdateSettingsRequest request,
request.persistentSettings().getAsMap().isEmpty() && request.transientSettings().getAsMap().size() == 1 && request.transientSettings().get(MetaData.SETTING_READ_ONLY) != null) {
return null;
}
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}


Expand Down
Expand Up @@ -58,7 +58,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(ClusterSearchShardsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected CreateSnapshotResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(CreateSnapshotRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, "");
}

@Override
Expand Down
Expand Up @@ -64,7 +64,7 @@ protected DeleteSnapshotResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(DeleteSnapshotRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, "");
}

@Override
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected GetSnapshotsResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(GetSnapshotsRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_READ, "");
}

@Override
Expand Down
Expand Up @@ -65,7 +65,13 @@ protected RestoreSnapshotResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(RestoreSnapshotRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
// Restoring a snapshot might change the global state and create/change an index,
// so we need to check for METADATA_WRITE and WRITE blocks
ClusterBlockException blockException = state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, "");
if (blockException != null) {
return blockException;
}
return state.blocks().indexBlockedException(ClusterBlockLevel.WRITE, "");
}

@Override
Expand Down
Expand Up @@ -70,7 +70,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(SnapshotsStatusRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}

@Override
Expand Down
Expand Up @@ -53,7 +53,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(PendingClusterTasksRequest request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}

@Override
Expand Down
Expand Up @@ -78,7 +78,7 @@ protected ClusterBlockException checkBlock(IndicesAliasesRequest request, Cluste
indices.add(index);
}
}
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, indices.toArray(new String[indices.size()]));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indices.toArray(new String[indices.size()]));
}

@Override
Expand Down
Expand Up @@ -49,7 +49,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -52,7 +52,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -175,12 +175,12 @@ protected GroupShardsIterator shards(ClusterState clusterState, ClearIndicesCach

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, ClearIndicesCacheRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, ClearIndicesCacheRequest request, String[] concreteIndices) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, concreteIndices);
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices);
}

}
Expand Up @@ -76,7 +76,7 @@ protected void doExecute(CloseIndexRequest request, ActionListener<CloseIndexRes

@Override
protected ClusterBlockException checkBlock(CloseIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected CreateIndexResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(CreateIndexRequest request, ClusterState state) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, request.index());
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.index());
}

@Override
Expand Down
Expand Up @@ -76,7 +76,7 @@ protected void doExecute(DeleteIndexRequest request, ActionListener<DeleteIndexR

@Override
protected ClusterBlockException checkBlock(DeleteIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected IndicesExistsResponse newResponse() {
protected ClusterBlockException checkBlock(IndicesExistsRequest request, ClusterState state) {
//make sure through indices options that the concrete indices call never throws IndexMissingException
IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed());
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, clusterService.state().metaData().concreteIndices(indicesOptions, request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, clusterService.state().metaData().concreteIndices(indicesOptions, request.indices()));
}

@Override
Expand Down
Expand Up @@ -62,7 +62,7 @@ protected TypesExistsResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(TypesExistsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -120,11 +120,11 @@ protected GroupShardsIterator shards(ClusterState clusterState, FlushRequest req

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, FlushRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, FlushRequest countRequest, String[] concreteIndices) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, concreteIndices);
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices);
}
}
Expand Up @@ -60,7 +60,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(GetIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -29,6 +29,8 @@
import org.elasticsearch.action.support.single.custom.TransportSingleCustomOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject;
Expand All @@ -38,10 +40,10 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.DocumentFieldMappers;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.TypeMissingException;
Expand Down Expand Up @@ -134,6 +136,11 @@ protected GetFieldMappingsResponse newResponse() {
return new GetFieldMappingsResponse();
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, InternalRequest request) {
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_READ, request.concreteIndex());
}

private static final ToXContent.Params includeDefaultsParams = new ToXContent.Params() {

final static String INCLUDE_DEFAULTS = "include_defaults";
Expand Down
Expand Up @@ -51,7 +51,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(GetMappingsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -66,7 +66,7 @@ protected PutMappingResponse newResponse() {

@Override
protected ClusterBlockException checkBlock(PutMappingRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, clusterService.state().metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, clusterService.state().metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -76,7 +76,7 @@ protected void doExecute(OpenIndexRequest request, ActionListener<OpenIndexRespo

@Override
protected ClusterBlockException checkBlock(OpenIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}

@Override
Expand Down
Expand Up @@ -121,11 +121,11 @@ protected GroupShardsIterator shards(ClusterState clusterState, OptimizeRequest

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, OptimizeRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, OptimizeRequest request, String[] concreteIndices) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, concreteIndices);
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices);
}
}
Expand Up @@ -122,11 +122,11 @@ protected GroupShardsIterator shards(ClusterState clusterState, RefreshRequest r

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, RefreshRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, RefreshRequest countRequest, String[] concreteIndices) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, concreteIndices);
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices);
}
}
Expand Up @@ -83,12 +83,12 @@ protected GroupShardsIterator shards(ClusterState clusterState, IndicesSegmentsR

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, IndicesSegmentsRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, IndicesSegmentsRequest countRequest, String[] concreteIndices) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, concreteIndices);
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, concreteIndices);
}

@Override
Expand Down
Expand Up @@ -62,7 +62,7 @@ protected String executor() {

@Override
protected ClusterBlockException checkBlock(GetSettingsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, state.metaData().concreteIndices(request.indicesOptions(), request.indices()));
}


Expand Down

0 comments on commit adc0807

Please sign in to comment.