Apache Solr open-source search software
SOLR-6111: The 'deleteshard' collection API should be able to delete a shard in 'construction' state
Shalin Shekhar Mangar7954c8584df8
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 54d9b2f2111..5ca800c3bce 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -134,6 +134,9 @@ Bug Fixes* SOLR-6101: Shard splitting doesn't work when legacyCloud=false is set incluster properties. (shalin)+* SOLR-6111: The 'deleteshard' collection API should be able to delete a shard+ in 'construction' state. (shalin)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.javaindex cad6952fc4a..1500f230923 100644--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java@@ -1686,10 +1686,11 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {}// For now, only allow for deletions of Inactive slices or custom hashes (range==null).// TODO: Add check for range gaps on Slice deletion- if (!(slice.getRange() == null || slice.getState().equals(Slice.INACTIVE) || slice.getState().equals(Slice.RECOVERY))) {+ if (!(slice.getRange() == null || slice.getState().equals(Slice.INACTIVE)+ || slice.getState().equals(Slice.RECOVERY) || slice.getState().equals(Slice.CONSTRUCTION))) {throw new SolrException(ErrorCode.BAD_REQUEST,"The slice: " + slice.getName() + " is currently "- + slice.getState() + ". Only INACTIVE (or custom-hashed) slices can be deleted.");+ + slice.getState() + ". Only non-active (or custom-hashed) slices can be deleted.");}ShardHandler shardHandler = shardHandlerFactory.getShardHandler();diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.javaindex 22bccfd1d22..460891291d9 100644--- a/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java@@ -28,7 +28,6 @@ import org.apache.solr.common.cloud.ZkNodeProps;import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.params.CollectionParams;import org.apache.solr.common.params.ModifiableSolrParams;-import org.apache.solr.handler.admin.CollectionsHandler;import org.apache.zookeeper.KeeperException;import org.junit.After;import org.junit.Before;@@ -91,7 +90,14 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {assertEquals("Shard1 is not active", Slice.ACTIVE, slice1.getState());assertEquals("Shard2 is not active", Slice.ACTIVE, slice2.getState());- setSliceAsInactive(SHARD1);+ try {+ deleteShard(SHARD1);+ fail("Deleting an active shard should not have succeeded");+ } catch (HttpSolrServer.RemoteSolrException e) {+ // expected+ }++ setSliceState(SHARD1, Slice.INACTIVE);clusterState = cloudClient.getZkStateReader().getClusterState();@@ -102,6 +108,10 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {deleteShard(SHARD1);confirmShardDeletion(SHARD1);++ setSliceState(SHARD2, Slice.CONSTRUCTION);+ deleteShard(SHARD2);+ confirmShardDeletion(SHARD2);}protected void confirmShardDeletion(String shard) throws SolrServerException, KeeperException,@@ -143,12 +153,12 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {baseServer.shutdown();}- protected void setSliceAsInactive(String slice) throws SolrServerException, IOException,+ protected void setSliceState(String slice, String state) throws SolrServerException, IOException,KeeperException, InterruptedException {DistributedQueue inQueue = Overseer.getInQueue(cloudClient.getZkStateReader().getZkClient());Map<String, Object> propMap = new HashMap<>();propMap.put(Overseer.QUEUE_OPERATION, "updateshardstate");- propMap.put(slice, Slice.INACTIVE);+ propMap.put(slice, state);propMap.put(ZkStateReader.COLLECTION_PROP, "collection1");ZkNodeProps m = new ZkNodeProps(propMap);ZkStateReader zkStateReader = cloudClient.getZkStateReader();@@ -159,7 +169,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {zkStateReader.updateClusterState(true);ClusterState clusterState = zkStateReader.getClusterState();String sliceState = clusterState.getSlice("collection1", slice).getState();- if (sliceState.equals(Slice.INACTIVE)) {+ if (sliceState.equals(state)) {transition = true;break;}@@ -167,7 +177,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {}if (!transition) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not set shard [" + slice + "] as INACTIVE");+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not set shard [" + slice + "] as " + state);}}