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

ASF subversion and git services commented on SOLR-12374:
--------------------------------------------------------

Commit d38f375fb971970f2b05829b82cef1f77372cf36 in lucene-solr's branch 
refs/heads/branch_7x from [~dsmiley]
[ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=d38f375 ]

SOLR-12374: Added SolrCore.withSearcher(lambda) convenience.
* and fixed SnapShooter.getIndexCommit bug forgetting to decref (rare?)

(cherry picked from commit e5f6adc)


> Add SolrCore.withSearcher(lambda accepting SolrIndexSearcher)
> -------------------------------------------------------------
>
>                 Key: SOLR-12374
>                 URL: https://issues.apache.org/jira/browse/SOLR-12374
>             Project: Solr
>          Issue Type: Improvement
>      Security Level: Public(Default Security Level. Issues are Public) 
>            Reporter: David Smiley
>            Assignee: David Smiley
>            Priority: Minor
>             Fix For: 7.4
>
>         Attachments: SOLR-12374.patch
>
>
> I propose adding the following to SolrCore:
> {code:java}
>   /**
>    * Executes the lambda with the {@link SolrIndexSearcher}.  This is more 
> convenience than using
>    * {@link #getSearcher()} since there is no ref-counting business to worry 
> about.
>    * Example:
>    * <pre class="prettyprint">
>    *   IndexReader reader = 
> h.getCore().withSearcher(SolrIndexSearcher::getIndexReader);
>    * </pre>
>    */
>   @SuppressWarnings("unchecked")
>   public <R> R withSearcher(Function<SolrIndexSearcher,R> lambda) {
>     final RefCounted<SolrIndexSearcher> refCounted = getSearcher();
>     try {
>       return lambda.apply(refCounted.get());
>     } finally {
>       refCounted.decref();
>     }
>   }
> {code}
> This is a nice tight convenience method, avoiding the clumsy RefCounted API 
> which is easy to accidentally incorrectly use – see 
> https://issues.apache.org/jira/browse/SOLR-11616?focusedCommentId=16477719&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16477719
> I guess my only (small) concern is if hypothetically you might make the 
> lambda short because it's easy to do that (see the one-liner example above) 
> but the object you return that you're interested in  (say IndexReader) could 
> potentially become invalid if the SolrIndexSearcher closes.  But I think/hope 
> that's impossible normally based on when this getSearcher() used?  I could at 
> least add a warning to the docs.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to