From 7c959e7ec3b46722a9eefbc4a50e86ba650ba508 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 31 Dec 2010 14:09:45 +0200 Subject: [PATCH] Master based operations (create index, delete index) to automatically retry on retryable cluster blocks (like recovery from gateway) --- .idea/dictionaries/kimchy.xml | 1 + .../alias/TransportIndicesAliasesAction.java | 9 ++- .../close/TransportCloseIndexAction.java | 5 +- .../create/TransportCreateIndexAction.java | 5 +- .../delete/TransportDeleteIndexAction.java | 5 +- .../delete/TransportDeleteMappingAction.java | 12 ++-- .../put/TransportPutMappingAction.java | 14 +++-- .../open/TransportOpenIndexAction.java | 5 +- .../TransportDeleteIndexTemplateAction.java | 5 +- .../put/TransportPutIndexTemplateAction.java | 5 +- .../TransportMasterNodeOperationAction.java | 60 +++++++++++++++---- .../cluster/block/ClusterBlock.java | 12 +++- .../cluster/block/ClusterBlockException.java | 9 +++ .../cluster/block/ClusterBlocks.java | 32 +++++++++- .../metadata/MetaDataStateIndexService.java | 2 +- .../elasticsearch/discovery/Discovery.java | 2 +- .../elasticsearch/gateway/GatewayService.java | 2 +- 17 files changed, 142 insertions(+), 43 deletions(-) diff --git a/.idea/dictionaries/kimchy.xml b/.idea/dictionaries/kimchy.xml index 5578def548f..7df68111cd3 100644 --- a/.idea/dictionaries/kimchy.xml +++ b/.idea/dictionaries/kimchy.xml @@ -120,6 +120,7 @@ reparse reparsed retrans + retryable retval routings rsts 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 2c8c693ee1d..a470321cc73 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 @@ -24,14 +24,17 @@ 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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService; +import org.elasticsearch.common.collect.Sets; 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.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; @@ -60,10 +63,12 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeOperationA return new IndicesAliasesResponse(); } - @Override protected void checkBlock(IndicesAliasesRequest request, ClusterState state) { + @Override protected ClusterBlockException checkBlock(IndicesAliasesRequest request, ClusterState state) { + Set indices = Sets.newHashSet(); for (AliasAction aliasAction : request.aliasActions()) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, aliasAction.index()); + indices.add(aliasAction.index()); } + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, indices.toArray(new String[indices.size()])); } @Override protected IndicesAliasesResponse masterOperation(IndicesAliasesRequest request, ClusterState state) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java index b6a54e55a46..afad884c8ac 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataStateIndexService; import org.elasticsearch.common.inject.Inject; @@ -61,8 +62,8 @@ public class TransportCloseIndexAction extends TransportMasterNodeOperationActio return new CloseIndexResponse(); } - @Override protected void checkBlock(CloseIndexRequest request, ClusterState state) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, request.index()); + @Override protected ClusterBlockException checkBlock(CloseIndexRequest request, ClusterState state) { + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, request.index()); } @Override protected CloseIndexResponse masterOperation(CloseIndexRequest request, ClusterState state) throws ElasticSearchException { 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 8f49f7fbf34..05590014048 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 @@ -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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService; import org.elasticsearch.common.inject.Inject; @@ -61,8 +62,8 @@ 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 ClusterBlockException checkBlock(CreateIndexRequest request, ClusterState state) { + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, request.index()); } @Override protected CreateIndexResponse masterOperation(CreateIndexRequest request, ClusterState state) throws ElasticSearchException { 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 cb1f0d18fbd..3701ded5dab 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 @@ -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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService; import org.elasticsearch.common.inject.Inject; @@ -61,8 +62,8 @@ 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 ClusterBlockException checkBlock(DeleteIndexRequest request, ClusterState state) { + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, request.index()); } @Override protected DeleteIndexResponse masterOperation(DeleteIndexRequest request, ClusterState state) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java index f75b2bc7da9..bf10aaeadb0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java @@ -30,6 +30,7 @@ import org.elasticsearch.action.support.master.TransportMasterNodeOperationActio import org.elasticsearch.client.Requests; 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.metadata.MetaDataMappingService; import org.elasticsearch.common.inject.Inject; @@ -78,13 +79,14 @@ public class TransportDeleteMappingAction extends TransportMasterNodeOperationAc return new DeleteMappingResponse(); } - @Override protected void checkBlock(DeleteMappingRequest request, ClusterState state) { + @Override protected void doExecute(DeleteMappingRequest request, ActionListener listener) { // update to concrete indices - request.indices(state.metaData().concreteIndices(request.indices())); + request.indices(clusterService.state().metaData().concreteIndices(request.indices())); + super.doExecute(request, listener); + } - for (String index : request.indices()) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, index); - } + @Override protected ClusterBlockException checkBlock(DeleteMappingRequest request, ClusterState state) { + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, request.indices()); } @Override protected DeleteMappingResponse masterOperation(final DeleteMappingRequest request, final ClusterState state) throws ElasticSearchException { 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 59ade1014bb..141e622058b 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 @@ -20,10 +20,12 @@ package org.elasticsearch.action.admin.indices.mapping.put; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.action.ActionListener; 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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataMappingService; import org.elasticsearch.common.inject.Inject; @@ -62,13 +64,13 @@ 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())); + @Override protected void doExecute(PutMappingRequest request, ActionListener listener) { + request.indices(clusterService.state().metaData().concreteIndices(request.indices())); + super.doExecute(request, listener); + } - for (String index : request.indices()) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, index); - } + @Override protected ClusterBlockException checkBlock(PutMappingRequest request, ClusterState state) { + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, request.indices()); } @Override protected PutMappingResponse masterOperation(PutMappingRequest request, ClusterState state) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java index 27feb45a2f0..caa6a2d0263 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataStateIndexService; import org.elasticsearch.common.inject.Inject; @@ -61,8 +62,8 @@ public class TransportOpenIndexAction extends TransportMasterNodeOperationAction return new OpenIndexResponse(); } - @Override protected void checkBlock(OpenIndexRequest request, ClusterState state) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, request.index()); + @Override protected ClusterBlockException checkBlock(OpenIndexRequest request, ClusterState state) { + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, request.index()); } @Override protected OpenIndexResponse masterOperation(OpenIndexRequest request, ClusterState state) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/delete/TransportDeleteIndexTemplateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/delete/TransportDeleteIndexTemplateAction.java index d2496160830..81b74069cda 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/delete/TransportDeleteIndexTemplateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/delete/TransportDeleteIndexTemplateAction.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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService; import org.elasticsearch.common.inject.Inject; @@ -61,8 +62,8 @@ public class TransportDeleteIndexTemplateAction extends TransportMasterNodeOpera return new DeleteIndexTemplateResponse(); } - @Override protected void checkBlock(DeleteIndexTemplateRequest request, ClusterState state) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, ""); + @Override protected ClusterBlockException checkBlock(DeleteIndexTemplateRequest request, ClusterState state) { + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, ""); } @Override protected DeleteIndexTemplateResponse masterOperation(DeleteIndexTemplateRequest request, ClusterState state) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java index b264416fad9..1730004d701 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.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.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService; import org.elasticsearch.common.inject.Inject; @@ -61,8 +62,8 @@ public class TransportPutIndexTemplateAction extends TransportMasterNodeOperatio return new PutIndexTemplateResponse(); } - @Override protected void checkBlock(PutIndexTemplateRequest request, ClusterState state) { - state.blocks().indexBlockedRaiseException(ClusterBlockLevel.METADATA, ""); + @Override protected ClusterBlockException checkBlock(PutIndexTemplateRequest request, ClusterState state) { + return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, ""); } @Override protected PutIndexTemplateResponse masterOperation(PutIndexTemplateRequest request, ClusterState state) throws ElasticSearchException { 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 7a84dafff96..359f73ec738 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 @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.TimeoutClusterStateListener; +import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -69,8 +70,8 @@ public abstract class TransportMasterNodeOperationAction blocks() { return blocks; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java index 473df72cf47..0eae69bd205 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java @@ -100,8 +100,15 @@ public class ClusterBlocks { } public void indexBlockedRaiseException(ClusterBlockLevel level, String index) throws ClusterBlockException { + ClusterBlockException blockException = indexBlockedException(level, index); + if (blockException != null) { + throw blockException; + } + } + + public ClusterBlockException indexBlockedException(ClusterBlockLevel level, String index) { if (!indexBlocked(level, index)) { - return; + return null; } ImmutableSet.Builder builder = ImmutableSet.builder(); builder.addAll(global(level)); @@ -109,7 +116,7 @@ public class ClusterBlocks { if (indexBlocks != null) { builder.addAll(indexBlocks); } - throw new ClusterBlockException(builder.build()); + return new ClusterBlockException(builder.build()); } public boolean indexBlocked(ClusterBlockLevel level, String index) { @@ -123,6 +130,27 @@ public class ClusterBlocks { return false; } + public ClusterBlockException indicesBlockedException(ClusterBlockLevel level, String[] indices) { + boolean indexIsBlocked = false; + for (String index : indices) { + if (indexBlocked(level, index)) { + indexIsBlocked = true; + } + } + if (!indexIsBlocked) { + return null; + } + ImmutableSet.Builder builder = ImmutableSet.builder(); + builder.addAll(global(level)); + for (String index : indices) { + ImmutableSet indexBlocks = indices(level).get(index); + if (indexBlocks != null) { + builder.addAll(indexBlocks); + } + } + return new ClusterBlockException(builder.build()); + } + static class ImmutableLevelHolder { static final ImmutableLevelHolder EMPTY = new ImmutableLevelHolder(ImmutableSet.of(), ImmutableMap.>of()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java index e3ba0a336e0..110028b6035 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java @@ -39,7 +39,7 @@ import org.elasticsearch.indices.IndexMissingException; */ public class MetaDataStateIndexService extends AbstractComponent { - public static final ClusterBlock INDEX_CLOSED_BLOCK = new ClusterBlock(4, "index closed", ClusterBlockLevel.READ_WRITE); + public static final ClusterBlock INDEX_CLOSED_BLOCK = new ClusterBlock(4, "index closed", false, ClusterBlockLevel.READ_WRITE); private final ClusterService clusterService; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java index d3e195ee285..b987fc02782 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java @@ -34,7 +34,7 @@ import org.elasticsearch.common.component.LifecycleComponent; */ public interface Discovery extends LifecycleComponent { - final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", ClusterBlockLevel.ALL); + final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", true, ClusterBlockLevel.ALL); DiscoveryNode localNode(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java index 88440ddc341..110fd212b3b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java @@ -47,7 +47,7 @@ import static org.elasticsearch.cluster.metadata.MetaData.*; */ public class GatewayService extends AbstractLifecycleComponent implements ClusterStateListener { - public static final ClusterBlock NOT_RECOVERED_FROM_GATEWAY_BLOCK = new ClusterBlock(1, "not recovered from gateway", ClusterBlockLevel.ALL); + public static final ClusterBlock NOT_RECOVERED_FROM_GATEWAY_BLOCK = new ClusterBlock(1, "not recovered from gateway", true, ClusterBlockLevel.ALL); private final Gateway gateway;