You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Maxim Khesin <ma...@fluidobjects.com> on 2004/03/08 20:14:41 UTC

IndexWriter q

Hi all,
I have seen the following usage in IndexWriter:

synchronized (directory) {              // in- & inter-process sync
     new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), 
COMMIT_LOCK_TIMEOUT) {
         public Object doBody() throws IOException {
           segmentInfos.write(directory);      // commit before deleting
           deleteSegments(segmentsToDelete);      // delete now-unused 
segments
           return null;
         }
       }.run();
   }

my question is:
It seems that the synchronized (directory) code is redundant, since 
there is already a file-based lock there. Is there a special case that 
synchronized(directory) handles?

thanks,
max.



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Re: IndexWriter q

Posted by Doug Cutting <cu...@apache.org>.
It's partly historical, partly useful and partly an optimization. 
Before lock files were added to Lucene, synchronization was done within 
the JVM, based on the directory.  This still works, even with Directory 
implementations that do not provide file-based locking, which may be 
useful.  Finally, it avoids checking lock files if another thread in the 
same JVM is already updating the index, which is more efficient.

Doug

Maxim Khesin wrote:
> Hi all,
> I have seen the following usage in IndexWriter:
> 
> synchronized (directory) {              // in- & inter-process sync
>     new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), 
> COMMIT_LOCK_TIMEOUT) {
>         public Object doBody() throws IOException {
>           segmentInfos.write(directory);      // commit before deleting
>           deleteSegments(segmentsToDelete);      // delete now-unused 
> segments
>           return null;
>         }
>       }.run();
>   }
> 
> my question is:
> It seems that the synchronized (directory) code is redundant, since 
> there is already a file-based lock there. Is there a special case that 
> synchronized(directory) handles?
> 
> thanks,
> max.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org