[Yanel-dev] LuceneIndexerV2 : Suggestions for improvements

Balz Schreier balz.schreier at gmail.com
Wed Mar 23 10:59:53 CET 2011


Hi Michael,

I had to use the removeFromIndex(node) method from the LuceneIndexer class.
I also had a quick look at the LuceneIndexerV2.

Don't you think that the following is crucial to have it in place? :

1) When an IndexWriter gets created it must get closed under any
circumstances.
I would recommend to use the TCFTC pattern here (try catch finally try
catch):
try : create, do stuff, close
catch: throwable (not exception)
finally: try to close, catch throwable (do nothing in there),

e.g.:

*try* {
  create
  do stuff
*  close*

} *catch* (Throwable t) {
  logging

} *finally* {
  *try* {
*    close*

  } *catch* (Throwable t) {
  }
}


This way, you are absolutely sure that it gets closed whatever happens.
I found no try catch in updateDocument(). Maybe I'm wrong, I just quickly
had a look at it.

2)

If you have heavy traffic on your website, you want to avoid that your
instance of indexwriter can not be created (because another writer has
acquired the lock already).

Therefore I would introduce a central LOCK in the LuceneIndexer class:

*private static final String LOCK = "lock";*

Then I would update the code from 1) like this:

try {
*  synchronized (LOCK) {*
    create
    do stuff
    close
*  }*

} catch (Throwable t) {
  logging

} finally {
  try {
    close

  } catch (Throwable t) {
  }
}

What do you think?
This way, you are absolutely sure (as long as only one JVM is accessing the
index, so no Yanel cluster is running), that IndexWriter objects can be
created all the time, no exceptions!

You can also synchronize the whole method, but I think that it is much more
performant if you only synchronize the code sections where you really do
index modifications.

Cheers
Balz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wyona.org/pipermail/yanel-development/attachments/20110323/ed0e8e1f/attachment.html>


More information about the Yanel-development mailing list