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 Jørgen Trosby <jo...@zedge.net> on 2010/10/11 18:11:07 UTC

SolrEventListeners are instantiated twice

I have a problem registering a custom-written firstSearcher
SolrEventListener. Even though I only register the listener in the query
section of solrconfig.xml, listening to the firstSearcher event, the
listener is also attached to the UpdateHandler and thus the init-method runs
twice because there is two instances of the class. To eliminate any other
configuration issues with our solr set-up, I used the example in the solr
distribution, with a simple logging implementation of SolrEventListener
which dumps a stack trace during the execution of the init method to
reproduce the error. The test class was compiled and put into a jar-file
which was then put in the example/solr/lib folder (had to be created). Then
I added <listener event="firstSearcher"
class="net.zedge.search.TestSolrEventListener"/> in the <query>-section of
solrconfig.xml and started the server. The log output from the server gave
the following two stack traces:

First time the class is instantiated:

11-Oct-2010 17:51:08 org.apache.solr.core.SolrCore initListeners
INFO: [] Added SolrEventListener:
org.apache.solr.core.QuerySenderListener{queries=[]}
11-Oct-2010 17:51:08 org.apache.solr.core.SolrCore initListeners
INFO: [] Added SolrEventListener:
org.apache.solr.core.QuerySenderListener{queries=[{q=solr
rocks,start=0,rows=10}, {q=static firstSearcher warming query from
solrconfig.xml}]}
11-Oct-2010 17:51:08 net.zedge.search.TestSolrEventListener init
WARNING: Event listener init
java.lang.Exception: foo
at
net.zedge.search.TestSolrEventListener.init(TestSolrEventListener.java:12)
at org.apache.solr.core.SolrCore.createInitInstance(SolrCore.java:446)
at org.apache.solr.core.SolrCore.initListeners(SolrCore.java:279)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:545)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:455)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:310)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:200)
at
org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:125)
at
org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:86)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:662)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at
org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at
org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at
org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)
11-Oct-2010 17:51:08 org.apache.solr.core.SolrCore initListeners
INFO: [] Added SolrEventListener:
net.zedge.search.TestSolrEventListener@5f90a0d6


Second time:

11-Oct-2010 17:51:08 org.apache.solr.search.SolrIndexSearcher <init>
INFO: Opening Searcher@79b66b06 main
11-Oct-2010 17:51:08 net.zedge.search.TestSolrEventListener init
WARNING: Event listener init
java.lang.Exception: foo
at
net.zedge.search.TestSolrEventListener.init(TestSolrEventListener.java:12)
at org.apache.solr.core.SolrCore.createInitInstance(SolrCore.java:446)
at
org.apache.solr.update.UpdateHandler.parseEventListeners(UpdateHandler.java:66)
at org.apache.solr.update.UpdateHandler.<init>(UpdateHandler.java:95)
at
org.apache.solr.update.DirectUpdateHandler2.<init>(DirectUpdateHandler2.java:154)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.solr.core.SolrCore.createInstance(SolrCore.java:429)
at org.apache.solr.core.SolrCore.createUpdateHandler(SolrCore.java:460)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:586)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:455)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:310)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:200)
at
org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:125)
at
org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:86)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:662)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at
org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at
org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at
org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)
11-Oct-2010 17:51:08
org.apache.solr.update.DirectUpdateHandler2$CommitTracker <init>
INFO: AutoCommit: disabled
11-Oct-2010 17:51:08 org.apache.solr.handler.component.SpellCheckComponent
inform

It seems the UpdateHandler creates an instance even though no <listener>-tag
exists in the <updateHandler>-section of solrconfig.xml. I tried to work
around the problem by adding a postCommit-listener with a
listenerType-argument set to another value than the firstSearcher-listener
to be able to tell the difference, but then the class was instantiated five
times instead of two (three of them through the UpdateHandler).

Is this behaviour caused by a bug in solr, or is there a problem with my
listener-configuration in solrconfig.xml? I have attached the
solrconfig.xml, java source and log output I used in the test. The included
config and log output are from a subversion-build of solr, but the code has
also been tested in the newest stable build.

-- 
Jørgen Trosby
Free your phone
http://www.zedge.net

Re: SolrEventListeners are instantiated twice

Posted by Chris Hostetter <ho...@fucit.org>.
: SolrEventListener. Even though I only register the listener in the query
: section of solrconfig.xml, listening to the firstSearcher event, the
: listener is also attached to the UpdateHandler and thus the init-method runs
: twice because there is two instances of the class. To eliminate any other

Jørgen: thank you for reporting this.

It is definitely a bug, and i have opened a jira trakcing issue with an 
attached test demonstrating your problem and a proposed fix that i am 
currently testing...

https://issues.apache.org/jira/browse/SOLR-2285


-Hoss