[
https://issues.apache.org/jira/browse/SOLR-6246?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15232476#comment-15232476
]
Gérald Quaire commented on SOLR-6246:
-------------------------------------
Hello,
I met this issue in my project. I need to reload the Solr Core after modifying
the configuration of the suggester via Solrj. In my suggester, I 'm using an
AnalyzingInfixSuggester as lookup algorithm. At each reload command, the
"LockObtainFailedException" exception rises.
To avoid this problem, I have overloaded the SuggestComponent and the
SolrSuggester classes in order to introduce a static map that stores the
suggesters already created for the current core and the current composant. My
SolrSuggester is now implemented the Closeable interface to call the close
method of the lookup object.
So when the core is reloading, the SuggestComponent first gets the suggesters
created previously by this core and closes all suggesters. And then, it can
create the new Suggester instances. Here is an excerpt of the code in the
SuggestComponent:
protected static Map<String, Map<String, SolrSuggester>> CoreSuggesters =
new ConcurrentHashMap<>();
...
@Override
public void inform(SolrCore core) {
if (initParams != null) {
LOG.info("Initializing SuggestComponent");
CoreSuggesters.computeIfPresent(core.getName() + this.getName(), (K,
map) -> {
if (map != null) {
for (SolrSuggester suggest : map.values()) {
try {
suggest.close();
} catch (IOException e) {
LOG.warn("Could not close the suggester.", e);
}
}
map.clear();
}
return null;
});
// Initialize the new suggesters here
...
CoreSuggesters.putIfAbsent(core.getName() + this.getName(),
suggesters);
core.addCloseHook(new CloseHook() {
@Override
public void preClose(SolrCore core) {
CoreSuggesters.computeIfPresent(core.getName() +
internalName, (K, map) -> {
if (map != null) {
for (SolrSuggester suggest : map.values()) {
try {
suggest.close();
} catch (IOException e) {
LOG.warn("Could not close the suggester.",
e);
}
}
map.clear();
}
return null;
});
} // end of the inform method
It was painful to make the overloadingbecause the classes SuggestComponent and
SolrSuggester are not written to be extended.
This code has fixed my issue for now. I don't know if it is a clean solution (I
don't think so), but it seems working. I hope this trick will be helpful.
> Core fails to reload when AnalyzingInfixSuggester is used as a Suggester
> ------------------------------------------------------------------------
>
> Key: SOLR-6246
> URL: https://issues.apache.org/jira/browse/SOLR-6246
> Project: Solr
> Issue Type: Sub-task
> Components: SearchComponents - other
> Affects Versions: 4.8, 4.8.1, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4
> Reporter: Varun Thacker
> Attachments: SOLR-6246-test.patch, SOLR-6246-test.patch,
> SOLR-6246.patch
>
>
> LUCENE-5477 - added near-real-time suggest building to
> AnalyzingInfixSuggester. One of the changes that went in was a writer is
> persisted now to support real time updates via the add() and update() methods.
> When we call Solr's reload command, a new instance of AnalyzingInfixSuggester
> is created. When trying to create a new writer on the same Directory a lock
> cannot be obtained and Solr fails to reload the core.
> Also when AnalyzingInfixLookupFactory throws a RuntimeException we should
> pass along the original message.
> I am not sure what should be the approach to fix it. Should we have a
> reloadHook where we close the writer?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]