mirror of https://github.com/apache/lucene.git
SOLR-12261: Collection deletion's check for alias membership should
sync() aliases with ZK before throwing an error.
This commit is contained in:
parent
c5a1738151
commit
1370f6b520
|
@ -187,6 +187,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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue