From 9d422c1c34e8712a595a173196ed11a8456d7fdf Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Wed, 4 Jan 2017 13:16:49 -0600 Subject: [PATCH] IndicesService handles all exceptions during index deletion (#22433) Previously, we could run into a situation where attempting to delete an index due to a cluster state update would cause an unhandled exception to bubble up to the ClusterService and cause the cluster state applier to fail. The result of this situation is that the cluster state never gets updated on the ClusterService because the exception happens before all cluster state appliers have completed and the ClusterService only updates the cluster state once all cluster state appliers have successfully completed. All other methods on IndicesService properly handle all exceptions and not just IOExceptions, but there were two instances with respect to index deletion where only IOExceptions where handled by the IndicesService. If any other exception occurred during these delete operations, the exception would be bubbled up to the ClusterService, causing the aforementioned issues. This commit ensures all methods in IndicesService properly capture all types of Exceptions, so that the ClusterService manages to update the cluster state, even in the presence of shard creation/deletion failures. Note that the lack of updating the cluster state in the presence of such exceptions can have many unintended consequences, one of them being the tripping of the assertion in IndicesClusterStateService#removeUnallocatedIndices where the assumption is that if there is an IndexService to remove with an unassigned shard, then the index must exist in the cluster state, but if the cluster state was never updated due to the aforementioned exceptions, then the cluster state will not have the index in question. --- .../main/java/org/elasticsearch/indices/IndicesService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 8f5d01d7683..0ab2f3ca281 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -602,7 +602,7 @@ public class IndicesService extends AbstractLifecycleComponent "the cluster state [" + index.getIndexUUID() + "] [" + metaData.getIndexUUID() + "]"); } deleteIndexStore(reason, metaData, clusterState); - } catch (IOException e) { + } catch (Exception e) { logger.warn((Supplier) () -> new ParameterizedMessage("[{}] failed to delete unassigned index (reason [{}])", metaData.getIndex(), reason), e); } } @@ -764,14 +764,14 @@ public class IndicesService extends AbstractLifecycleComponent final IndexMetaData metaData; try { metaData = metaStateService.loadIndexState(index); - } catch (IOException e) { + } catch (Exception e) { logger.warn((Supplier) () -> new ParameterizedMessage("[{}] failed to load state file from a stale deleted index, folders will be left on disk", index), e); return null; } final IndexSettings indexSettings = buildIndexSettings(metaData); try { deleteIndexStoreIfDeletionAllowed("stale deleted index", index, indexSettings, ALWAYS_TRUE); - } catch (IOException e) { + } catch (Exception e) { // we just warn about the exception here because if deleteIndexStoreIfDeletionAllowed // throws an exception, it gets added to the list of pending deletes to be tried again logger.warn((Supplier) () -> new ParameterizedMessage("[{}] failed to delete index on disk", metaData.getIndex()), e);