Apache Lucene open-source search software
SOLR-12261: Collection deletion's check for alias membership should sync() aliases with ZK before throwing an error.
David Smiley1370f6b52078
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex fb49903d3f2..d01b1035fc0 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -187,6 +187,10 @@ Bug Fixes* SOLR-11833: Allow searchRate trigger to delete replicas. Improve configurability of the trigger by specifyingupper / lower thresholds and respective actions (ab)+* SOLR-12261: If you attempt to delete a collection immediately after deleting an alias it used to be a part of, you may+ get an error that's it's a member of that alias. This check now ensures the alias state is sync()'ed with ZK first.+ (David Smiley)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.javaindex 15603633569..c8143ba35cb 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java@@ -62,15 +62,10 @@ public class DeleteCollectionCmd implements OverseerCollectionMessageHandler.Cmd@Overridepublic void call(ClusterState state, ZkNodeProps message, NamedList results) throws Exception {- ZkStateReader zkStateReader = ocmh.zkStateReader;- Aliases aliases = zkStateReader.getAliases();final String collection = message.getStr(NAME);- for (Map.Entry<String, List<String>> ent : aliases.getCollectionAliasListMap().entrySet()) {- if (ent.getValue().contains(collection)) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,- "Collection : " + collection + " is part of alias " + ent.getKey() + " remove or modify the alias before removing this collection.");- }- }+ ZkStateReader zkStateReader = ocmh.zkStateReader;++ checkNotReferencedByAlias(zkStateReader, collection);boolean removeCounterNode = true;try {@@ -154,4 +149,23 @@ public class DeleteCollectionCmd implements OverseerCollectionMessageHandler.Cmd}}}++ private void checkNotReferencedByAlias(ZkStateReader zkStateReader, String collection) throws Exception {+ String alias = referencedByAlias(collection, zkStateReader.getAliases());+ if (alias != null) {+ zkStateReader.aliasesManager.update(); // aliases may have been stale; get latest from ZK+ alias = referencedByAlias(collection, zkStateReader.getAliases());+ if (alias != null) {+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "Collection : " + collection + " is part of alias " + alias + " remove or modify the alias before removing this collection.");+ }+ }+ }++ private String referencedByAlias(String collection, Aliases aliases) {+ return aliases.getCollectionAliasListMap().entrySet().stream()+ .filter(e -> e.getValue().contains(collection))+ .map(Map.Entry::getKey) // alias name+ .findFirst().orElse(null);+ }}