You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by MakMak <po...@gmail.com> on 2009/03/06 20:26:18 UTC

Deadlock in using FSDirectory

Hi,

 I have the following :

Thread1  ----

1. Acquires a lock on FSDirectory.getDirectory (not right, not needed, but
should not be harmful anyway)
2. Issues an IndexReader.reopen() to open the reader and search. This call
waits on acquiring a MultiSegmentReader lock.

Thread2  -----

1. Issues prevIndexReader.close() which locks a MultiSegmentReader and then
goes ahead and waits on a lock for FSDirectory



Actual code:
Thread 1->
        at
org.apache.lucene.index.DirectoryIndexReader.reopen(DirectoryIndexReader.java:85)
        - waiting to lock <0xfffffffecaba1638> (a
org.apache.lucene.index.MultiSegmentReader)
        at
com.sample.search.LuceneEngine.getIndexReader(LuceneEngine.java:505)
        at
com.sample.search.LuceneEngine.doContractSearch(LuceneEngine.java:480)
        at com.sample.search.LuceneEngine.doSearch(LuceneEngine.java:458)
        - locked <0xfffffffe43ad06e0> (a
org.apache.lucene.store.FSDirectory)
        at
com.sample.search.FileSearchManager.doSearch(AttachmentSearchManager.java:117)
        at
com.sample.search.FileSearchFilter.<init>(AttachmentSearchFilter.java:70)


Thread2->
        at org.apache.lucene.store.FSDirectory.close(FSDirectory.java:480)
        - waiting to lock <0xfffffffe43ad06e0> (a
org.apache.lucene.store.FSDirectory)
        at
org.apache.lucene.index.DirectoryIndexReader.doClose(DirectoryIndexReader.java:164)
        at
org.apache.lucene.index.MultiSegmentReader.doClose(MultiSegmentReader.java:411)
        - locked <0xfffffffecaba1638> (a
org.apache.lucene.index.MultiSegmentReader)
        at org.apache.lucene.index.IndexReader.decRef(IndexReader.java:124)
        - locked <0xfffffffecaba1638> (a
org.apache.lucene.index.MultiSegmentReader)
        at org.apache.lucene.index.IndexReader.close(IndexReader.java:832)
        - locked <0xfffffffecaba1638> (a
org.apache.lucene.index.MultiSegmentReader)
        at com.sample.search.Engine.getIndexReader(LuceneEngine.java:508)
        at
com.sample.search.Engine.findMatchingFragments(LuceneEngine.java:521)


-- 
View this message in context: http://www.nabble.com/Deadlock-in-using-FSDirectory-tp22378951p22378951.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


Re: Deadlock in using FSDirectory

Posted by Michael McCandless <lu...@mikemccandless.com>.
MakMak wrote:

> Hey Mike, thanks for the quick response, I tried passing Directory to
> IndexReader.open() and there were no deadlocks!! I will get rid of
> synchronizing on FSDirectory too.

Great!

> However do you think it will be better to modify the docs for  
> FSDirectory
> and remove the sync part of "Directories are cached, so that, for a  
> given
> canonical path, the same FSDirectory instance will always be  
> returned by
> getDirectory. This permits synchronization on directories." Sounds
> misleading.

Hmm -- good point.  I'll remove that last sentence.

> Lastly, can you please very briefly explain why passing a Directory  
> worked?

The deadlock happens when the reader tries to close the directory,  
which it only does if it had opened it when passed a File or String.   
If you pass Directory in, then the reader does not close it.

Mike

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


Re: Deadlock in using FSDirectory

Posted by MakMak <po...@gmail.com>.
Hey Mike, thanks for the quick response, I tried passing Directory to
IndexReader.open() and there were no deadlocks!! I will get rid of
synchronizing on FSDirectory too. 

However do you think it will be better to modify the docs for FSDirectory
and remove the sync part of "Directories are cached, so that, for a given
canonical path, the same FSDirectory instance will always be returned by
getDirectory. This permits synchronization on directories." Sounds
misleading.

Lastly, can you please very briefly explain why passing a Directory worked?

-thanks
-- 
View this message in context: http://www.nabble.com/Deadlock-in-using-FSDirectory-tp22378951p22380572.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


Re: Deadlock in using FSDirectory

Posted by Michael McCandless <lu...@mikemccandless.com>.
It's not safe for you to synchronize externally on the Directory
instance returned from FSDirectory.getDirectory -- that's leading
to the deadlock here right?

It looks like you passed in a File or String to IndexReader.open?  One
workaround (I think -- not tested) might be to pass Directory
instead.

Mike

MakMak wrote:

>
> Hi,
>
> I have the following :
>
> Thread1  ----
>
> 1. Acquires a lock on FSDirectory.getDirectory (not right, not  
> needed, but
> should not be harmful anyway)
> 2. Issues an IndexReader.reopen() to open the reader and search.  
> This call
> waits on acquiring a MultiSegmentReader lock.
>
> Thread2  -----
>
> 1. Issues prevIndexReader.close() which locks a MultiSegmentReader  
> and then
> goes ahead and waits on a lock for FSDirectory
>
>
>
> Actual code:
> Thread 1->
>        at
> org 
> .apache 
> .lucene.index.DirectoryIndexReader.reopen(DirectoryIndexReader.java: 
> 85)
>        - waiting to lock <0xfffffffecaba1638> (a
> org.apache.lucene.index.MultiSegmentReader)
>        at
> com.sample.search.LuceneEngine.getIndexReader(LuceneEngine.java:505)
>        at
> com.sample.search.LuceneEngine.doContractSearch(LuceneEngine.java:480)
>        at com.sample.search.LuceneEngine.doSearch(LuceneEngine.java: 
> 458)
>        - locked <0xfffffffe43ad06e0> (a
> org.apache.lucene.store.FSDirectory)
>        at
> com 
> .sample 
> .search.FileSearchManager.doSearch(AttachmentSearchManager.java:117)
>        at
> com 
> .sample.search.FileSearchFilter.<init>(AttachmentSearchFilter.java:70)
>
>
> Thread2->
>        at org.apache.lucene.store.FSDirectory.close(FSDirectory.java: 
> 480)
>        - waiting to lock <0xfffffffe43ad06e0> (a
> org.apache.lucene.store.FSDirectory)
>        at
> org 
> .apache 
> .lucene.index.DirectoryIndexReader.doClose(DirectoryIndexReader.java: 
> 164)
>        at
> org 
> .apache 
> .lucene.index.MultiSegmentReader.doClose(MultiSegmentReader.java:411)
>        - locked <0xfffffffecaba1638> (a
> org.apache.lucene.index.MultiSegmentReader)
>        at  
> org.apache.lucene.index.IndexReader.decRef(IndexReader.java:124)
>        - locked <0xfffffffecaba1638> (a
> org.apache.lucene.index.MultiSegmentReader)
>        at org.apache.lucene.index.IndexReader.close(IndexReader.java: 
> 832)
>        - locked <0xfffffffecaba1638> (a
> org.apache.lucene.index.MultiSegmentReader)
>        at com.sample.search.Engine.getIndexReader(LuceneEngine.java: 
> 508)
>        at
> com.sample.search.Engine.findMatchingFragments(LuceneEngine.java:521)
>
>
> -- 
> View this message in context: http://www.nabble.com/Deadlock-in-using-FSDirectory-tp22378951p22378951.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


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