From aa5791a14f1abc23e003c0e199830b3bef8bdf64 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 29 Jun 2010 08:51:36 +0300 Subject: [PATCH] move block metadata checks to the transport level --- .../indices/alias/TransportIndicesAliasesAction.java | 9 +++++++++ .../indices/create/TransportCreateIndexAction.java | 6 ++++++ .../indices/delete/TransportDeleteIndexAction.java | 6 ++++++ .../indices/mapping/put/TransportPutMappingAction.java | 10 ++++++++++ .../master/TransportMasterNodeOperationAction.java | 7 +++++++ .../org/elasticsearch/cluster/block/ClusterBlocks.java | 6 +++--- .../cluster/metadata/MetaDataService.java | 8 -------- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java index 488f1bf285b..56f6a21120f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java @@ -23,6 +23,9 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockLevel; +import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.MetaDataService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -54,6 +57,12 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeOperationA return new IndicesAliasesResponse(); } + @Override protected void checkBlock(IndicesAliasesRequest request, ClusterState state) { + for (AliasAction aliasAction : request.aliasActions()) { + state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, aliasAction.index()); + } + } + @Override protected IndicesAliasesResponse masterOperation(IndicesAliasesRequest request) throws ElasticSearchException { MetaDataService.IndicesAliasesResult indicesAliasesResult = metaDataService.indicesAliases(request.aliasActions()); return new IndicesAliasesResponse(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java index be9e34a3484..2884a550e8e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java @@ -23,6 +23,8 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -56,6 +58,10 @@ public class TransportCreateIndexAction extends TransportMasterNodeOperationActi return new CreateIndexResponse(); } + @Override protected void checkBlock(CreateIndexRequest request, ClusterState state) { + state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, request.index()); + } + @Override protected CreateIndexResponse masterOperation(CreateIndexRequest request) throws ElasticSearchException { String cause = request.cause(); if (cause.length() == 0) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java index 78b3b318981..174ad24141c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java @@ -23,6 +23,8 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -56,6 +58,10 @@ public class TransportDeleteIndexAction extends TransportMasterNodeOperationActi return new DeleteIndexResponse(); } + @Override protected void checkBlock(DeleteIndexRequest request, ClusterState state) { + state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, request.index()); + } + @Override protected DeleteIndexResponse masterOperation(DeleteIndexRequest request) throws ElasticSearchException { MetaDataService.DeleteIndexResult deleteIndexResult = metaDataService.deleteIndex(request.index(), request.timeout()); return new DeleteIndexResponse(deleteIndexResult.acknowledged()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java index 6c9dda4139c..52e5f82da97 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -58,6 +59,15 @@ public class TransportPutMappingAction extends TransportMasterNodeOperationActio return new PutMappingResponse(); } + @Override protected void checkBlock(PutMappingRequest request, ClusterState state) { + // update to concrete indices + request.indices(state.metaData().concreteIndices(request.indices())); + + for (String index : request.indices()) { + state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, index); + } + } + @Override protected PutMappingResponse masterOperation(PutMappingRequest request) throws ElasticSearchException { ClusterState clusterState = clusterService.state(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java index afa59a5785b..760f7f14a82 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.BaseAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; @@ -60,12 +61,17 @@ public abstract class TransportMasterNodeOperationAction listener) { DiscoveryNodes nodes = clusterService.state().nodes(); if (nodes.localNodeMaster()) { threadPool.execute(new Runnable() { @Override public void run() { try { + checkBlock(request, clusterService.state()); Response response = masterOperation(request); listener.onResponse(response); } catch (Exception e) { @@ -101,6 +107,7 @@ public abstract class TransportMasterNodeOperationAction> indicesBuilder = ImmutableMap.builder(); for (Map.Entry> entry : levelHolders[level.id()].indices().entrySet()) { @@ -228,7 +228,7 @@ public class ClusterBlocks { } public static ClusterBlocks readClusterBlocks(StreamInput in) throws IOException { - ImmutableLevelHolder[] holders = new ImmutableLevelHolder[3]; + ImmutableLevelHolder[] holders = new ImmutableLevelHolder[ClusterBlockLevel.values().length]; for (ClusterBlockLevel level : ClusterBlockLevel.values()) { ImmutableSet global = readBlockSet(in); ImmutableMap.Builder> indicesBuilder = ImmutableMap.builder(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java index 89f71c04b07..c2b5185a9dc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java @@ -26,7 +26,6 @@ import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.action.index.NodeIndexCreatedAction; import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction; import org.elasticsearch.cluster.action.index.NodeMappingCreatedAction; -import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.strategy.ShardsRoutingStrategy; @@ -106,7 +105,6 @@ public class MetaDataService extends AbstractComponent { ClusterState clusterState = clusterService.state(); for (AliasAction aliasAction : aliasActions) { - clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, aliasAction.index()); if (!clusterState.metaData().hasIndex(aliasAction.index())) { throw new IndexMissingException(new Index(aliasAction.index())); } @@ -143,8 +141,6 @@ public class MetaDataService extends AbstractComponent { public synchronized CreateIndexResult createIndex(final String cause, final String index, final Settings indexSettings, Map mappings, TimeValue timeout) throws IndexAlreadyExistsException { ClusterState clusterState = clusterService.state(); - clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, index); - if (clusterState.routingTable().hasIndex(index)) { throw new IndexAlreadyExistsException(new Index(index)); } @@ -266,8 +262,6 @@ public class MetaDataService extends AbstractComponent { public synchronized DeleteIndexResult deleteIndex(final String index, TimeValue timeout) throws IndexMissingException { ClusterState clusterState = clusterService.state(); - clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, index); - RoutingTable routingTable = clusterState.routingTable(); if (!routingTable.hasIndex(index)) { throw new IndexMissingException(new Index(index)); @@ -349,8 +343,6 @@ public class MetaDataService extends AbstractComponent { throw new IndexMissingException(new Index("_all")); } for (String index : indices) { - clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, index); - IndexRoutingTable indexTable = clusterState.routingTable().indicesRouting().get(index); if (indexTable == null) { throw new IndexMissingException(new Index(index));