You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Li Li <fa...@gmail.com> on 2011/09/06 04:43:25 UTC

What will happen when one thread is closing a searcher while another is searching?

hi all,
     I am using spellcheck in solr 1.4. I found that spell check is not
implemented as SolrCore. in SolrCore, it uses reference count to track
current searcher. oldSearcher and newSearcher will both exist if oldSearcher
is servicing some query. But in FileBasedSpellChecker

  public void build(SolrCore core, SolrIndexSearcher searcher) {
    try {
      loadExternalFileDictionary(core.getSchema(),
core.getResourceLoader());
      spellChecker.clearIndex();
      spellChecker.indexDictionary(dictionary);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  public void clearIndex() throws IOException {
    IndexWriter writer = new IndexWriter(spellIndex, null, true);
    writer.close();

    //close the old searcher
    searcher.close();
    searcher = new IndexSearcher(this.spellIndex);
  }

  it clear old Index and close current searcher. When other thread is doing
search and searcher.close() is called, will it cause problem? Or
searcher.close() has finished and new IndexSearch has not yet constructed.
When other thread try to do search, will it also be problematic?

Re: What will happen when one thread is closing a searcher while another is searching?

Posted by Michael McCandless <lu...@mikemccandless.com>.
Closing a searcher while thread(s) is/are still using it is definitely
bad, so, this code looks spooky...

But: it possible something higher up (in Solr) is ensuring this code
runs exclusively?  I don't know enough about this part of Solr...

Mike McCandless

http://blog.mikemccandless.com

On Mon, Sep 5, 2011 at 10:43 PM, Li Li <fa...@gmail.com> wrote:
> hi all,
>     I am using spellcheck in solr 1.4. I found that spell check is not
> implemented as SolrCore. in SolrCore, it uses reference count to track
> current searcher. oldSearcher and newSearcher will both exist if oldSearcher
> is servicing some query. But in FileBasedSpellChecker
>
>  public void build(SolrCore core, SolrIndexSearcher searcher) {
>    try {
>      loadExternalFileDictionary(core.getSchema(),
> core.getResourceLoader());
>      spellChecker.clearIndex();
>      spellChecker.indexDictionary(dictionary);
>    } catch (IOException e) {
>      throw new RuntimeException(e);
>    }
>  }
>  public void clearIndex() throws IOException {
>    IndexWriter writer = new IndexWriter(spellIndex, null, true);
>    writer.close();
>
>    //close the old searcher
>    searcher.close();
>    searcher = new IndexSearcher(this.spellIndex);
>  }
>
>  it clear old Index and close current searcher. When other thread is doing
> search and searcher.close() is called, will it cause problem? Or
> searcher.close() has finished and new IndexSearch has not yet constructed.
> When other thread try to do search, will it also be problematic?
>

Re: What will happen when one thread is closing a searcher while another is searching?

Posted by Michael McCandless <lu...@mikemccandless.com>.
Closing a searcher while thread(s) is/are still using it is definitely
bad, so, this code looks spooky...

But: it possible something higher up (in Solr) is ensuring this code
runs exclusively?  I don't know enough about this part of Solr...

Mike McCandless

http://blog.mikemccandless.com

On Mon, Sep 5, 2011 at 10:43 PM, Li Li <fa...@gmail.com> wrote:
> hi all,
>     I am using spellcheck in solr 1.4. I found that spell check is not
> implemented as SolrCore. in SolrCore, it uses reference count to track
> current searcher. oldSearcher and newSearcher will both exist if oldSearcher
> is servicing some query. But in FileBasedSpellChecker
>
>  public void build(SolrCore core, SolrIndexSearcher searcher) {
>    try {
>      loadExternalFileDictionary(core.getSchema(),
> core.getResourceLoader());
>      spellChecker.clearIndex();
>      spellChecker.indexDictionary(dictionary);
>    } catch (IOException e) {
>      throw new RuntimeException(e);
>    }
>  }
>  public void clearIndex() throws IOException {
>    IndexWriter writer = new IndexWriter(spellIndex, null, true);
>    writer.close();
>
>    //close the old searcher
>    searcher.close();
>    searcher = new IndexSearcher(this.spellIndex);
>  }
>
>  it clear old Index and close current searcher. When other thread is doing
> search and searcher.close() is called, will it cause problem? Or
> searcher.close() has finished and new IndexSearch has not yet constructed.
> When other thread try to do search, will it also be problematic?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org