move block metadata checks to the transport level

This commit is contained in:
kimchy 2010-06-29 08:51:36 +03:00
parent a82bf74c1c
commit aa5791a14f
7 changed files with 41 additions and 11 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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());

View File

@ -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();

View File

@ -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<Request extends MasterN
protected abstract Response masterOperation(Request request) throws ElasticSearchException;
protected void checkBlock(Request request, ClusterState state) {
}
@Override protected void doExecute(final Request request, final ActionListener<Response> 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<Request extends MasterN
@Override public void messageReceived(final Request request, final TransportChannel channel) throws Exception {
if (clusterService.state().nodes().localNodeMaster()) {
checkBlock(request, clusterService.state());
Response response = masterOperation(request);
channel.sendResponse(response);
} else {

View File

@ -155,7 +155,7 @@ public class ClusterBlocks {
private LevelHolder[] levelHolders;
public Builder() {
levelHolders = new LevelHolder[3];
levelHolders = new LevelHolder[ClusterBlockLevel.values().length];
for (int i = 0; i < levelHolders.length; i++) {
levelHolders[i] = new LevelHolder();
}
@ -216,7 +216,7 @@ public class ClusterBlocks {
}
public ClusterBlocks build() {
ImmutableLevelHolder[] holders = new ImmutableLevelHolder[3];
ImmutableLevelHolder[] holders = new ImmutableLevelHolder[ClusterBlockLevel.values().length];
for (ClusterBlockLevel level : ClusterBlockLevel.values()) {
ImmutableMap.Builder<String, ImmutableSet<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
for (Map.Entry<String, Set<ClusterBlock>> 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<ClusterBlock> global = readBlockSet(in);
ImmutableMap.Builder<String, ImmutableSet<ClusterBlock>> indicesBuilder = ImmutableMap.builder();

View File

@ -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<String, String> 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));