mirror of https://github.com/apache/lucene.git
SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection
This commit is contained in:
parent
82a426c6e7
commit
b89015a2d4
|
@ -133,6 +133,8 @@ Other Changes
|
||||||
* SOLR-10397: Port 'autoAddReplicas' feature to the autoscaling framework and make it work with non-shared filesystems
|
* SOLR-10397: Port 'autoAddReplicas' feature to the autoscaling framework and make it work with non-shared filesystems
|
||||||
(Cao Manh Dat, shalin)
|
(Cao Manh Dat, shalin)
|
||||||
|
|
||||||
|
* SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection (noble)
|
||||||
|
|
||||||
================== 7.0.0 ==================
|
================== 7.0.0 ==================
|
||||||
|
|
||||||
Versions of Major Components
|
Versions of Major Components
|
||||||
|
|
|
@ -273,6 +273,11 @@ public class AutoScalingHandler extends RequestHandlerBase implements Permission
|
||||||
if (policies == null || !policies.containsKey(policyName)) {
|
if (policies == null || !policies.containsKey(policyName)) {
|
||||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No policy exists with name: " + policyName);
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No policy exists with name: " + policyName);
|
||||||
}
|
}
|
||||||
|
container.getZkController().getZkStateReader().getClusterState().forEachCollection(coll -> {
|
||||||
|
if (policyName.equals(coll.getPolicyName())) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
|
StrUtils.formatString("policy : {0} is being used by collection {1}", policyName, coll.getName()));
|
||||||
|
});
|
||||||
|
|
||||||
policies = new HashMap<>(policies);
|
policies = new HashMap<>(policies);
|
||||||
policies.remove(policyName);
|
policies.remove(policyName);
|
||||||
Policy p = currentConfig.getPolicy().withPolicies(policies);
|
Policy p = currentConfig.getPolicy().withPolicies(policies);
|
||||||
|
|
|
@ -737,6 +737,28 @@ public class AutoScalingHandlerTest extends SolrCloudTestCase {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteUsedPolicy() throws Exception {
|
||||||
|
CloudSolrClient solrClient = cluster.getSolrClient();
|
||||||
|
// add multiple policies
|
||||||
|
String setPolicyCommand = "{'set-policy': {" +
|
||||||
|
" 'nodelete':[" +
|
||||||
|
" {'nodeRole':'overseer', 'replica':0}]}}";
|
||||||
|
solrClient.request(createAutoScalingRequest(SolrRequest.METHOD.POST, setPolicyCommand));
|
||||||
|
CollectionAdminRequest.createCollection("COLL1", "conf", 1, 1)
|
||||||
|
.setPolicy("nodelete")
|
||||||
|
.process(cluster.getSolrClient());
|
||||||
|
String removePolicyCommand = "{remove-policy : nodelete}";
|
||||||
|
createAutoScalingRequest(SolrRequest.METHOD.POST, removePolicyCommand);
|
||||||
|
try {
|
||||||
|
solrClient.request(createAutoScalingRequest(SolrRequest.METHOD.POST, removePolicyCommand));
|
||||||
|
fail("should have failed");
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertTrue(e.getMessage().contains("is being used by collection"));
|
||||||
|
}
|
||||||
|
solrClient.request(CollectionAdminRequest.deleteCollection("COLL1"));
|
||||||
|
}
|
||||||
|
|
||||||
public static SolrRequest createAutoScalingRequest(SolrRequest.METHOD m, String message) {
|
public static SolrRequest createAutoScalingRequest(SolrRequest.METHOD m, String message) {
|
||||||
return createAutoScalingRequest(m, null, message);
|
return createAutoScalingRequest(m, null, message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue