You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Chetan Mehrotra (JIRA)" <ji...@apache.org> on 2015/04/22 11:23:58 UTC

[jira] [Commented] (OAK-2797) Closeable aspect of Analyzer should be accounted for

    [ https://issues.apache.org/jira/browse/OAK-2797?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14506702#comment-14506702 ] 

Chetan Mehrotra commented on OAK-2797:
--------------------------------------

Looking at [Analyzer code|https://github.com/apache/lucene-solr/blob/lucene_solr_4_7_1/lucene/core/src/java/org/apache/lucene/analysis/Analyzer.java] it uses a {{CloseableThreadLocal}}

{code}
public abstract class Analyzer implements Closeable {

  private final ReuseStrategy reuseStrategy;

  // non final as it gets nulled if closed; pkg private for access by ReuseStrategy's final helper methods:
  CloseableThreadLocal<Object> storedValue = new CloseableThreadLocal<Object>();

 /** Frees persistent resources used by this Analyzer */
  @Override
  public void close() {
    if (storedValue != null) {
      storedValue.close();
      storedValue = null;
    }
  }
} 
{code}

And checking the docs for [CloseableThreadLocal|https://github.com/apache/lucene-solr/blob/lucene_solr_4_7_1/lucene/core/src/java/org/apache/lucene/util/CloseableThreadLocal.java] which states that it should not be closed *until all threads are done using the instance* it appears that we need to close the {{Analyzer}} only upon shutdown to free up resources. So possibly in {{LuceneIndexProviderService#deactivate}}

{code}
 *  We can not rely on {@link ThreadLocal#remove()} as it
 *  only removes the value for the caller thread, whereas
 *  {@link #close} takes care of all
 *  threads.  You should not call {@link #close} until all
 *  threads are done using the instance.
 *
 * @lucene.internal
 */

public class CloseableThreadLocal<T> implements Closeable {
{code}

> Closeable aspect of Analyzer should be accounted for
> ----------------------------------------------------
>
>                 Key: OAK-2797
>                 URL: https://issues.apache.org/jira/browse/OAK-2797
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: lucene
>            Reporter: Chetan Mehrotra
>             Fix For: 1.3.0
>
>
> Lucene {{Analyzer}} implements {{Closeable}} [1] interface and internally it has a ThreadLocal storage of some persistent resource
> So far in oak-lucene we do not take care of closing any analyzer. In fact we use a singleton Analyzer in all cases. Opening this bug to think about this aspect and see if our usage of Analyzer follows the best practices
> [1] http://lucene.apache.org/core/4_7_0/core/org/apache/lucene/analysis/Analyzer.html#close%28%29
> /cc [~teofili] [~alex.parvulescu]



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)