Mailing List Archive

IndexWriter.isLock()
Hi all
While I am using IndexWriter.isLock(), this method unlocks the index and
returns false.
Can anyone tell me why?
Re: IndexWriter.isLock() [ In reply to ]
Hmm, not good. Are you sure the index was previously locked?

Can you describe your environment? Which OS / Directory class are you using?

Maybe boil down to a small code fragment showing the issue?

Mike McCandless

http://blog.mikemccandless.com

On Sun, May 6, 2012 at 8:29 AM, S Eslamian <seslamian@gmail.com> wrote:
> Hi all
> While I am using IndexWriter.isLock(), this method unlocks the index and
> returns false.
> Can anyone tell me why?

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: IndexWriter.isLock() [ In reply to ]
Yes, I'm sure. I debug the code, and look at the files in the index folder,
it has a write.lock file before this line of code:
if (!(IndexWriter.isLock(NIOFSDirectory.open("fileAddr")))){
//do something
}

and after passing this line, index folder does not contain write.lock file
and code goes to the if loop while it shouldn't passes the if clause!

S Eslamian

On Sun, May 6, 2012 at 5:56 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> Hmm, not good. Are you sure the index was previously locked?
>
> Can you describe your environment? Which OS / Directory class are you
> using?
>
> Maybe boil down to a small code fragment showing the issue?
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> On Sun, May 6, 2012 at 8:29 AM, S Eslamian <seslamian@gmail.com> wrote:
> > Hi all
> > While I am using IndexWriter.isLock(), this method unlocks the index and
> > returns false.
> > Can anyone tell me why?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: IndexWriter.isLock() [ In reply to ]
My guess is you had a leftover lock file. With NativeFSLockFactory
(used by NIOFSDirectory), the presence of a lock file does not mean
the lock is held (unlike the older SimpleFSLockFactory).

The code that checks if the lock is held simply acquires and then
releases the lock. So if you had a leftover (but unlocked) lock file,
then the acquire succeeds, and on release the file is removed ...

If it's not a leftover lock file ... can you make a quick code
fragment showing the problem?

Mike McCandless

http://blog.mikemccandless.com

On Mon, May 7, 2012 at 12:27 AM, S Eslamian <seslamian@gmail.com> wrote:
> Yes, I'm sure. I debug the code, and look at the files in the index folder,
> it has a write.lock file before this line of code:
> if (!(IndexWriter.isLock(NIOFSDirectory.open("fileAddr")))){
>  //do something
> }
>
> and after passing this line, index folder does not contain write.lock file
> and code goes to the if loop while it shouldn't passes the if clause!
>
> S Eslamian
>
> On Sun, May 6, 2012 at 5:56 PM, Michael McCandless <
> lucene@mikemccandless.com> wrote:
>
>> Hmm, not good.  Are you sure the index was previously locked?
>>
>> Can you describe your environment?  Which OS / Directory class are you
>> using?
>>
>> Maybe boil down to a small code fragment showing the issue?
>>
>> Mike McCandless
>>
>> http://blog.mikemccandless.com
>>
>> On Sun, May 6, 2012 at 8:29 AM, S Eslamian <seslamian@gmail.com> wrote:
>> > Hi all
>> > While I am using IndexWriter.isLock(), this method unlocks the index and
>> > returns false.
>> > Can anyone tell me why?
>>
>> ---------------------------------------------------------------------
>> 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
Re: IndexWriter.isLock() [ In reply to ]
hmm... , What is a leftover lock file?

You know I debug my code, befor index folder has lock file, till line 7.
Then I close the program, like in a real run an interrupt has happened.
Next I debug the program again with that index folder which has the lock
file and it shouldn't passes the if clause. But it passes.

This is my sample code:

1.try{
2. if(!(IndexWriter.isLock(NIOFSDirectory.open("dstAddr")))){
3. IndexReader ir =
IndexReader.open(NIOFSDirectory.open("srcAddr"),true);
4. IndexWriterConfig iwc = new
IndexWriterConfig(Version.LUCENE_CURRENT, new SimpleAnalyzer());
5. IndexWriter iw = new
IndexWriter(NIOFSDirectory.open("dstAddr"),iwc);
6.
7. iw.addIndexes(ir);
8. iw.close();
9. }
10.} catch(CorruptIndexException e){
11. //TODO
12.} catch(LockObtainFailedException e){
13. //TODO
14.} catch(IOException e){
15. //TODO
16.}


On Mon, May 7, 2012 at 3:24 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> My guess is you had a leftover lock file. With NativeFSLockFactory
> (used by NIOFSDirectory), the presence of a lock file does not mean
> the lock is held (unlike the older SimpleFSLockFactory).
>
> The code that checks if the lock is held simply acquires and then
> releases the lock. So if you had a leftover (but unlocked) lock file,
> then the acquire succeeds, and on release the file is removed ...
>
> If it's not a leftover lock file ... can you make a quick code
> fragment showing the problem?
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> On Mon, May 7, 2012 at 12:27 AM, S Eslamian <seslamian@gmail.com> wrote:
> > Yes, I'm sure. I debug the code, and look at the files in the index
> folder,
> > it has a write.lock file before this line of code:
> > if (!(IndexWriter.isLock(NIOFSDirectory.open("fileAddr")))){
> > //do something
> > }
> >
> > and after passing this line, index folder does not contain write.lock
> file
> > and code goes to the if loop while it shouldn't passes the if clause!
> >
> > S Eslamian
> >
> > On Sun, May 6, 2012 at 5:56 PM, Michael McCandless <
> > lucene@mikemccandless.com> wrote:
> >
> >> Hmm, not good. Are you sure the index was previously locked?
> >>
> >> Can you describe your environment? Which OS / Directory class are you
> >> using?
> >>
> >> Maybe boil down to a small code fragment showing the issue?
> >>
> >> Mike McCandless
> >>
> >> http://blog.mikemccandless.com
> >>
> >> On Sun, May 6, 2012 at 8:29 AM, S Eslamian <seslamian@gmail.com> wrote:
> >> > Hi all
> >> > While I am using IndexWriter.isLock(), this method unlocks the index
> and
> >> > returns false.
> >> > Can anyone tell me why?
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>
Re: IndexWriter.isLock() [ In reply to ]
If I understand correctly, you're using the NativeFSLockFactory and that's
the expected behavior -- unlike SimpleFSLockFactory, if you terminate the
JVM and then restart the program, the lock is not held anymore -- that's
the advantage of using native-fs-lock because nobody really holds the lock
anymore (the previous JVM died !). SimpleFSLock gives you a headache in
that regard.

Can this explain what you observe?

Shai

On Mon, May 7, 2012 at 2:19 PM, S Eslamian <seslamian@gmail.com> wrote:

> hmm... , What is a leftover lock file?
>
> You know I debug my code, befor index folder has lock file, till line 7.
> Then I close the program, like in a real run an interrupt has happened.
> Next I debug the program again with that index folder which has the lock
> file and it shouldn't passes the if clause. But it passes.
>
> This is my sample code:
>
> 1.try{
> 2. if(!(IndexWriter.isLock(NIOFSDirectory.open("dstAddr")))){
> 3. IndexReader ir =
> IndexReader.open(NIOFSDirectory.open("srcAddr"),true);
> 4. IndexWriterConfig iwc = new
> IndexWriterConfig(Version.LUCENE_CURRENT, new SimpleAnalyzer());
> 5. IndexWriter iw = new
> IndexWriter(NIOFSDirectory.open("dstAddr"),iwc);
> 6.
> 7. iw.addIndexes(ir);
> 8. iw.close();
> 9. }
> 10.} catch(CorruptIndexException e){
> 11. //TODO
> 12.} catch(LockObtainFailedException e){
> 13. //TODO
> 14.} catch(IOException e){
> 15. //TODO
> 16.}
>
>
> On Mon, May 7, 2012 at 3:24 PM, Michael McCandless <
> lucene@mikemccandless.com> wrote:
>
> > My guess is you had a leftover lock file. With NativeFSLockFactory
> > (used by NIOFSDirectory), the presence of a lock file does not mean
> > the lock is held (unlike the older SimpleFSLockFactory).
> >
> > The code that checks if the lock is held simply acquires and then
> > releases the lock. So if you had a leftover (but unlocked) lock file,
> > then the acquire succeeds, and on release the file is removed ...
> >
> > If it's not a leftover lock file ... can you make a quick code
> > fragment showing the problem?
> >
> > Mike McCandless
> >
> > http://blog.mikemccandless.com
> >
> > On Mon, May 7, 2012 at 12:27 AM, S Eslamian <seslamian@gmail.com> wrote:
> > > Yes, I'm sure. I debug the code, and look at the files in the index
> > folder,
> > > it has a write.lock file before this line of code:
> > > if (!(IndexWriter.isLock(NIOFSDirectory.open("fileAddr")))){
> > > //do something
> > > }
> > >
> > > and after passing this line, index folder does not contain write.lock
> > file
> > > and code goes to the if loop while it shouldn't passes the if clause!
> > >
> > > S Eslamian
> > >
> > > On Sun, May 6, 2012 at 5:56 PM, Michael McCandless <
> > > lucene@mikemccandless.com> wrote:
> > >
> > >> Hmm, not good. Are you sure the index was previously locked?
> > >>
> > >> Can you describe your environment? Which OS / Directory class are you
> > >> using?
> > >>
> > >> Maybe boil down to a small code fragment showing the issue?
> > >>
> > >> Mike McCandless
> > >>
> > >> http://blog.mikemccandless.com
> > >>
> > >> On Sun, May 6, 2012 at 8:29 AM, S Eslamian <seslamian@gmail.com>
> wrote:
> > >> > Hi all
> > >> > While I am using IndexWriter.isLock(), this method unlocks the index
> > and
> > >> > returns false.
> > >> > Can anyone tell me why?
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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
> >
> >
>
Re: IndexWriter.isLock() [ In reply to ]
Thanks a lot. You mean this happens because of the NIOFSDirectory which I'm
using. Am I right?
But why the lock releases after calling isLock() method? I check the index
folder before this call and it has write.lock yet.


On Mon, May 7, 2012 at 3:58 PM, Shai Erera <serera@gmail.com> wrote:

> If I understand correctly, you're using the NativeFSLockFactory and that's
> the expected behavior -- unlike SimpleFSLockFactory, if you terminate the
> JVM and then restart the program, the lock is not held anymore -- that's
> the advantage of using native-fs-lock because nobody really holds the lock
> anymore (the previous JVM died !). SimpleFSLock gives you a headache in
> that regard.
>
> Can this explain what you observe?
>
> Shai
>
> On Mon, May 7, 2012 at 2:19 PM, S Eslamian <seslamian@gmail.com> wrote:
>
> > hmm... , What is a leftover lock file?
> >
> > You know I debug my code, befor index folder has lock file, till line 7.
> > Then I close the program, like in a real run an interrupt has happened.
> > Next I debug the program again with that index folder which has the lock
> > file and it shouldn't passes the if clause. But it passes.
> >
> > This is my sample code:
> >
> > 1.try{
> > 2. if(!(IndexWriter.isLock(NIOFSDirectory.open("dstAddr")))){
> > 3. IndexReader ir =
> > IndexReader.open(NIOFSDirectory.open("srcAddr"),true);
> > 4. IndexWriterConfig iwc = new
> > IndexWriterConfig(Version.LUCENE_CURRENT, new SimpleAnalyzer());
> > 5. IndexWriter iw = new
> > IndexWriter(NIOFSDirectory.open("dstAddr"),iwc);
> > 6.
> > 7. iw.addIndexes(ir);
> > 8. iw.close();
> > 9. }
> > 10.} catch(CorruptIndexException e){
> > 11. //TODO
> > 12.} catch(LockObtainFailedException e){
> > 13. //TODO
> > 14.} catch(IOException e){
> > 15. //TODO
> > 16.}
> >
> >
> > On Mon, May 7, 2012 at 3:24 PM, Michael McCandless <
> > lucene@mikemccandless.com> wrote:
> >
> > > My guess is you had a leftover lock file. With NativeFSLockFactory
> > > (used by NIOFSDirectory), the presence of a lock file does not mean
> > > the lock is held (unlike the older SimpleFSLockFactory).
> > >
> > > The code that checks if the lock is held simply acquires and then
> > > releases the lock. So if you had a leftover (but unlocked) lock file,
> > > then the acquire succeeds, and on release the file is removed ...
> > >
> > > If it's not a leftover lock file ... can you make a quick code
> > > fragment showing the problem?
> > >
> > > Mike McCandless
> > >
> > > http://blog.mikemccandless.com
> > >
> > > On Mon, May 7, 2012 at 12:27 AM, S Eslamian <seslamian@gmail.com>
> wrote:
> > > > Yes, I'm sure. I debug the code, and look at the files in the index
> > > folder,
> > > > it has a write.lock file before this line of code:
> > > > if (!(IndexWriter.isLock(NIOFSDirectory.open("fileAddr")))){
> > > > //do something
> > > > }
> > > >
> > > > and after passing this line, index folder does not contain write.lock
> > > file
> > > > and code goes to the if loop while it shouldn't passes the if clause!
> > > >
> > > > S Eslamian
> > > >
> > > > On Sun, May 6, 2012 at 5:56 PM, Michael McCandless <
> > > > lucene@mikemccandless.com> wrote:
> > > >
> > > >> Hmm, not good. Are you sure the index was previously locked?
> > > >>
> > > >> Can you describe your environment? Which OS / Directory class are
> you
> > > >> using?
> > > >>
> > > >> Maybe boil down to a small code fragment showing the issue?
> > > >>
> > > >> Mike McCandless
> > > >>
> > > >> http://blog.mikemccandless.com
> > > >>
> > > >> On Sun, May 6, 2012 at 8:29 AM, S Eslamian <seslamian@gmail.com>
> > wrote:
> > > >> > Hi all
> > > >> > While I am using IndexWriter.isLock(), this method unlocks the
> index
> > > and
> > > >> > returns false.
> > > >> > Can anyone tell me why?
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> 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
> > >
> > >
> >
>
Re: IndexWriter.isLock() [ In reply to ]
On Mon, May 7, 2012 at 7:19 AM, S Eslamian <seslamian@gmail.com> wrote:
> hmm... , What is a leftover lock file?
>
> You know I debug my code, befor index folder has lock file, till line 7.
> Then I close the program, like in a real run an interrupt has happened.

How do you close it? Just kill the process? That is what creates a
leftover lock file...

But with native locking, even though there is still a leftover lock
file in the filesystem, the lock is in fact released.

So then when you start up and run your test, IW.isLocked returns
false, and as a side effect removes the leftover lock file.

Mike McCandless

http://blog.mikemccandless.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: IndexWriter.isLock() [ In reply to ]
So if my program interrupts, the lock files in the indexes will be released
in the next run. hoom?

That's so good. Thank you Mr.McCandless for your help.

On Mon, May 7, 2012 at 5:04 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> On Mon, May 7, 2012 at 7:19 AM, S Eslamian <seslamian@gmail.com> wrote:
> > hmm... , What is a leftover lock file?
> >
> > You know I debug my code, befor index folder has lock file, till line 7.
> > Then I close the program, like in a real run an interrupt has happened.
>
> How do you close it? Just kill the process? That is what creates a
> leftover lock file...
>
> But with native locking, even though there is still a leftover lock
> file in the filesystem, the lock is in fact released.
>
> So then when you start up and run your test, IW.isLocked returns
> false, and as a side effect removes the leftover lock file.
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: IndexWriter.isLock() [ In reply to ]
On Tue, May 8, 2012 at 12:31 AM, S Eslamian <seslamian@gmail.com> wrote:

> So if my program interrupts, the lock files in the indexes will be released
> in the next run. hoom?

If you use NativeFSLockFactory (which is the default for
NIOFSDirectory) then, yes, the lock is always released by the OS when
the process exits.

> That's so good. Thank you Mr.McCandless for your help.

You're welcome!

Mike McCandless

http://blog.mikemccandless.com

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