You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2018/04/25 03:26:55 UTC
lucene-solr:branch_7x: SOLR-12261: Collection deletion's check for
alias membership should sync() aliases with ZK before throwing an error.
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 9201de762 -> 5a89f604c
SOLR-12261: Collection deletion's check for alias membership should
sync() aliases with ZK before throwing an error.
(cherry picked from commit 1370f6b)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/5a89f604
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/5a89f604
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/5a89f604
Branch: refs/heads/branch_7x
Commit: 5a89f604cdfc6fde68c8e6a5fdfb01f5ac3f732d
Parents: 9201de7
Author: David Smiley <ds...@apache.org>
Authored: Tue Apr 24 23:25:11 2018 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Tue Apr 24 23:26:49 2018 -0400
----------------------------------------------------------------------
solr/CHANGES.txt | 4 +++
.../api/collections/DeleteCollectionCmd.java | 30 ++++++++++++++------
2 files changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5a89f604/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b03e5c7..0aa8f4e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -167,6 +167,10 @@ Bug Fixes
* SOLR-11833: Allow searchRate trigger to delete replicas. Improve configurability of the trigger by specifying
upper / 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
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5a89f604/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
----------------------------------------------------------------------
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.java
index 1560363..c8143ba 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
@Override
public 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);
+ }
}