jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Russell <pruss...@apache.org>
Subject Re: search index corruption?
Date Sun, 03 Oct 2004 09:11:56 GMT
On 3 Oct 2004, at 08:59, David Nuescheler wrote:
> is there a way to restart the index gracefully
> after abnormal termination, since something tells me that
> abnormal termination might happen quite frequently ;)

I'm not quite answering the question you're asking here, because I 
think it may be better to avoid the index being not being shutdown 
properly in the first place. I could well be teaching grandma to suck 
eggs here, so for apologies for that, but for the purposes of your 
test, you could substantially increase the chances of the of the 
shutdown method being executed by either putting the repository 
shutdown method call in a finally block:

         RepositoryFactory repof;
         try {
             repof = RepositoryFactory.create(args[0]);
             Repository repo=repof.getRepository("localfs");
             Session session=repo.login(new
             Node root=session.getRootNode();
             if (root.hasNode("perftest")) {
             Node testroot=root.addNode("perftest", "nt:unstructured");
             long start=System.currentTimeMillis();
             int i=0;
             while (i<10) {
             long done=System.currentTimeMillis();
         } catch (RepositoryException ex) {
         } finally {
             if ( repof != null ) { repof.shutdown(); }

... or rather less elegantly by adding a 'shutdown-hook' to the JVM 
using Runtime.addShutdownHook(Thread).

Using the 'finally' block would be the better way, and would ensure 
that the repository is properly shutdown regardless of what happens in 
the main loop of your test. Even an OutOfMemoryError would trigger the 
repository being shutdown -- that said, with an OOME, all bets are off 
when it comes to running any code at all ;) The only time this wouldn't 
shut the repository down properly is if the JVM itself crashed -- does 
happen, but not very often, I hope! Hopefully this will mean that the 
repository is not shutdown properly so rarely that you don't /need/ (at 
least in the short-term) to have an automatically recovering repository 

Hope that helps, and that I'm not wasting your time by telling you 
something you already knew!


Paul Russell
E-mail: prussell@apache.org
iChat/AIM: russelp@mac.com

View raw message