From 38be478c46f7858314335fc854e722dd1005f8ab Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Mon, 2 Sep 2013 10:58:09 +0200 Subject: [PATCH] Fixed close index when the index is already closed Closes #3601 --- .../cluster/metadata/MetaDataIndexStateService.java | 12 ++++++------ .../indices/state/OpenCloseIndexTests.java | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java index 273b50a8ca1..ee433e388d6 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java @@ -96,14 +96,14 @@ public class MetaDataIndexStateService extends AbstractComponent { if (indexMetaData == null) { throw new IndexMissingException(new Index(index)); } - IndexRoutingTable indexRoutingTable = currentState.routingTable().index(index); - for (IndexShardRoutingTable shard : indexRoutingTable) { - if (!shard.primaryAllocatedPostApi()) { - throw new IndexPrimaryShardNotAllocatedException(new Index(index)); - } - } if (indexMetaData.state() != IndexMetaData.State.CLOSE) { + IndexRoutingTable indexRoutingTable = currentState.routingTable().index(index); + for (IndexShardRoutingTable shard : indexRoutingTable) { + if (!shard.primaryAllocatedPostApi()) { + throw new IndexPrimaryShardNotAllocatedException(new Index(index)); + } + } indicesToClose.add(index); } } diff --git a/src/test/java/org/elasticsearch/test/integration/indices/state/OpenCloseIndexTests.java b/src/test/java/org/elasticsearch/test/integration/indices/state/OpenCloseIndexTests.java index f5569aa7f7b..32ed4665629 100644 --- a/src/test/java/org/elasticsearch/test/integration/indices/state/OpenCloseIndexTests.java +++ b/src/test/java/org/elasticsearch/test/integration/indices/state/OpenCloseIndexTests.java @@ -227,9 +227,9 @@ public class OpenCloseIndexTests extends AbstractSharedClusterTest { assertIndexIsClosed("test1"); //no problem if we try to close an index that's already in close state - OpenIndexResponse openIndexResponse1 = client.admin().indices().prepareOpen("test1").execute().actionGet(); - assertThat(openIndexResponse1.isAcknowledged(), equalTo(true)); - assertIndexIsOpened("test1"); + closeIndexResponse = client.admin().indices().prepareClose("test1").execute().actionGet(); + assertThat(closeIndexResponse.isAcknowledged(), equalTo(true)); + assertIndexIsClosed("test1"); } @Test