[Yanel-dev] LuceneIndexerV2 : Suggestions for improvements

Balz Schreier balz.schreier at gmail.com
Wed Mar 23 11:42:42 CET 2011


Hi Michael,

another aspect I noticed are the public methods to create an IndexWriter.
Can you verify which parts in Yarep/Yanel really need that?
This is very dangerous because you have no control anymore by when the
writer gets closed. I would keep all modifying index logic inside the
Indexer class.

What do you think?

Cheers
Balz

On Wed, Mar 23, 2011 at 10:59 AM, Balz Schreier <balz.schreier at gmail.com>wrote:

> 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/c8966733/attachment.html>


More information about the Yanel-development mailing list