On 2/6/2013 8:05 PM, Alexandre Rafalovitch wrote:
Hello,
When I CTRL-C the example Solr, it prints a bunch of graceful shutdown
messages. I assume it shuts down safe and without corruption issues.
When I do that to Solrj (embedded, not remote), it just drops dead.
I found CoreContainer.shutdown(), which looks about right and does
terminate Solrj but it prints out a completely different set of messages.
Is CoreContainer.shutdown() the right method for Solrj (4.1)? Is there more
than just one call?
And what happens if you just Ctrl-C Solrj instance? Wiki says nothing about
shutdown, so I can imagine a lot of people probably think it is ok to just
kill it. Is there a danger of corruption?
I don't know the proper way to shut things down, but
CoreContainer.shutdown() is probably part of it. I can give you some
information about your Ctrl-C observations, though.
When you interrupt the example Solr, you're interrupting Jetty, not
Solr. Jetty is a battle-tested servlet container that implements a very
extensive shutdown hook. As a servlet in a servlet container, Solr very
likely interfaces into that shutdown hook.
When you interrupt SolrJ with EmbeddedSolrServer, that's an application
that you wrote. If you haven't implemented a shutdown hook, then the
application will simply die, and it's possible you could encounter data
loss. You'll have to implement a shutdown hook that closes everything
properly.
Some caveats I've learned about shutdown hooks: 1) Don't call
System.exit() from within your hook thread. This creates infinite
recursion. 2) If you can't be sure that all the threads in your app
have stopped by the time your hook thread ends, you'll have halt the JVM
to ensure that the program actually exits.
http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#halt%28int%29
Thanks,
Shawn