You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Dean Gurvitz <de...@gmail.com> on 2015/12/30 10:27:44 UTC

Proposed extension to SearchHandler / SearchComponent in Solr

Hello,

First of all I would like to say I'm new to this community so excuse me for
not filing a proper bug through Jira. I did try to follow the
"HowToContribute" guide as much as possible.

Recently I was writing a SearchComponent which works only in a distributed
context. In the prepare method it alters some static state, and then
reverts that modification during one of the calls to finishStage. However,
I realized that if an exception is thrown by another SearchComponent, the
change is never reverted and my state becomes "corrupted" and doesn't
reflect the reality.
To solve this, I thought about adding an "onException" method to the
SearchComponent class, and make appropriate modifications in SearchHandler
to support it. Such a change would allow SearchComponent to clean up after
themselves in a case of exceptions. What do you think?

Dean Gurvitz.

Re: Proposed extension to SearchHandler / SearchComponent in Solr

Posted by Chris Hostetter <ho...@fucit.org>.
: Recently I was writing a SearchComponent which works only in a distributed
: context. In the prepare method it alters some static state, and then
: reverts that modification during one of the calls to finishStage. However,
: I realized that if an exception is thrown by another SearchComponent, the
: change is never reverted and my state becomes "corrupted" and doesn't
: reflect the reality.
: To solve this, I thought about adding an "onException" method to the
: SearchComponent class, and make appropriate modifications in SearchHandler
: to support it. Such a change would allow SearchComponent to clean up after
: themselves in a case of exceptions. What do you think?

you really, REALLY, don't want to be modifying static state in a 
SearchCOmponent or RequestHandler -- not "java definition of static 
variable" or even "object instance variable state" on the 
components/handlers themselves.

SearchComponent and RequestHandler instances are re-used 
in parallel threads processing concurrent requests -- so any "state" you 
mutate on them will poluate the results of other requests happening at the 
same time.

If you have state you want to track between prepare/process/finishStage 
you should absolutely use the ResponseBuilder and/or 
SolrQueryRequest for this.

SolrQueryRequest.getContext() exists explicitly for third-party custom 
plugins to track state like you're describing.



-Hoss
http://www.lucidworks.com/

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