opening an IndexWriter for an exisiting index causing lock exception

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

opening an IndexWriter for an exisiting index causing lock exception

S Edirisinghe
Hello,

I'm having a write lock problem when I try to open an existing index.
When I try to open the index with the recreate set to false, I get this
exception

java.io.IOException: Lock obtain timed out: Lock@/tmp/lucene-
e683c0b3e52b8094bba62b22617efd41-write.lock
    at org.apache.lucene.store.Lock.obtain(Lock.java:58)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:255)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:205)
    at im.service.search.impl.InfomunityLuceneIndexManager.openIndex(
InfomunityLuceneIndexManager.java:108)
    at im.service.search.impl.InfomunityLuceneIndexManager.<init>(
InfomunityLuceneIndexManager.java:71)
    at im.service.search.impl.test.InfomunityLuceneIndexManagerTest.<init>(
InfomunityLuceneIndexManagerTest.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(
NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at org.junit.internal.runners.TestClassMethodsRunner.createTest(
TestClassMethodsRunner.java:60)

when I try to open it. If I open it with recreate set to false, it opens
fine, but obviously it destroys the exisiting files. This error happens at
the start of the application. the first thing it starts to do is
...
            try{
                openIndex(false);
            } catch (IOException fe){//if there is no index or it is
incomplete we will have to rebuild it
                log.info("rebuilding index: " + infomunity.getName() + "
id=" + infomunity.getId());

                String msg = "could not open index for " +
infomunity.getName() +
                "\n\t" + fe.getMessage();
                StringWriter sw = new StringWriter() ;
                PrintWriter stackWriter = new PrintWriter( sw );
                fe.printStackTrace(stackWriter);

                log.error(msg + "\n\n" + sw.toString());
            }
...
    private synchronized IndexWriter openIndex(boolean recreate) throws
IOException{
        return (indexWriter = new IndexWriter(path,new
KeywordAnalyzer(),recreate));
    }

All I'm doing is calling open. There is no documents being added. Is there
something I'm missing? At the time I start the application there are no lock
files in the tmp directory.

thanks
Reply | Threaded
Open this post in threaded view
|

Re: opening an IndexWriter for an exisiting index causing lock exception

Michael McCandless-2
S Edirisinghe wrote:

> I'm having a write lock problem when I try to open an existing index.
> When I try to open the index with the recreate set to false, I get this
> exception
>
> java.io.IOException: Lock obtain timed out: Lock@/tmp/lucene-
> e683c0b3e52b8094bba62b22617efd41-write.lock
>    at org.apache.lucene.store.Lock.obtain(Lock.java:58)
>    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:255)
>    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:205)
>    at im.service.search.impl.InfomunityLuceneIndexManager.openIndex(
> InfomunityLuceneIndexManager.java:108)
>    at im.service.search.impl.InfomunityLuceneIndexManager.<init>(
> InfomunityLuceneIndexManager.java:71)
>    at im.service.search.impl.test.InfomunityLuceneIndexManagerTest.<init>(
> InfomunityLuceneIndexManagerTest.java:31)
>    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>    at sun.reflect.NativeConstructorAccessorImpl.newInstance(
> NativeConstructorAccessorImpl.java:39)
>    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
> DelegatingConstructorAccessorImpl.java:27)
>    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
>    at org.junit.internal.runners.TestClassMethodsRunner.createTest(
> TestClassMethodsRunner.java:60)

Which version of Lucene are you using?

By far the most common cause of this is a leftover lock file from a
previous un-graceful exit.

But it sounds like you've checked that already.

So if you're certain that this lock file name is not in fact present
when you start your application, maybe double check that no other code
is creating an IndexWriter (or that your openIndex is not being called
more than once)?  Or you're not running two threads through this code?

Actually, since you're running under Junit, are you sure there wasn't
another test case that had failed to close its writer against this
index?

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: opening an IndexWriter for an exisiting index causing lock exception

S Edirisinghe
Thanks Mike, you are right. There was a really bad test method that didn't
clean up after itself. Thanks for the heads up. This was not a Lucene
problem, it was just me not going through all of the unit test methods.

On 1/8/07, Michael McCandless <[hidden email]> wrote:

>
> S Edirisinghe wrote:
>
> > I'm having a write lock problem when I try to open an existing index.
> > When I try to open the index with the recreate set to false, I get this
> > exception
> >
> > java.io.IOException: Lock obtain timed out: Lock@/tmp/lucene-
> > e683c0b3e52b8094bba62b22617efd41-write.lock
> >    at org.apache.lucene.store.Lock.obtain(Lock.java:58)
> >    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:255)
> >    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:205)
> >    at im.service.search.impl.InfomunityLuceneIndexManager.openIndex(
> > InfomunityLuceneIndexManager.java:108)
> >    at im.service.search.impl.InfomunityLuceneIndexManager.<init>(
> > InfomunityLuceneIndexManager.java:71)
> >    at im.service.search.impl.test.InfomunityLuceneIndexManagerTest
> .<init>(
> > InfomunityLuceneIndexManagerTest.java:31)
> >    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> >    at sun.reflect.NativeConstructorAccessorImpl.newInstance(
> > NativeConstructorAccessorImpl.java:39)
> >    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
> > DelegatingConstructorAccessorImpl.java:27)
> >    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
> >    at org.junit.internal.runners.TestClassMethodsRunner.createTest(
> > TestClassMethodsRunner.java:60)
>
> Which version of Lucene are you using?
>
> By far the most common cause of this is a leftover lock file from a
> previous un-graceful exit.
>
> But it sounds like you've checked that already.
>
> So if you're certain that this lock file name is not in fact present
> when you start your application, maybe double check that no other code
> is creating an IndexWriter (or that your openIndex is not being called
> more than once)?  Or you're not running two threads through this code?
>
> Actually, since you're running under Junit, are you sure there wasn't
> another test case that had failed to close its writer against this
> index?
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>