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 MC Moisei <mc...@comcast.net> on 2007/03/04 22:29:33 UTC

Clearing locks

Is there a easy way to clear locks ?

If I redeploy my war file and it happens that there is an indexing
happening the lock is not cleared. I know I can tell JVM to run the
finalizers before it exits but in this case the JVM is not exiting being
a hot deploy.

Any ideas ?
MC
 

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


Re: Clearing locks

Posted by Chris Hostetter <ho...@fucit.org>.
there are also the static IndexReder.isLocked(Directory) and
IndexReder.unlock(Directory) methods that encapsulate this logic for you
... they've been around since at least 1.4.3.


: Date: Sun, 4 Mar 2007 21:34:52 -0800
: From: Chris Lu <ch...@gmail.com>
: Reply-To: java-user@lucene.apache.org
: To: java-user@lucene.apache.org
: Subject: Re: Clearing locks
:
: They are not really unique. Here are my code to unlock the directory.
: Notice there are two locks.
:
:     public static void unlockDirectory(Directory dir) {
:         Lock dirLock = dir.makeLock(IndexWriter.WRITE_LOCK_NAME);
:         if (dirLock.isLocked()) {
:             logger.debug("unlocking " + dirLock);
:             dirLock.release();
:             logger.info("unlocked directory " + dir);
:         }
:         dirLock = dir.makeLock(IndexWriter.COMMIT_LOCK_NAME);
:         if (dirLock.isLocked()) {
:             logger.debug("unlocking " + dirLock);
:             dirLock.release();
:             logger.info("unlocked directory " + dir);
:         }
:     }
:
: --
: Chris Lu
: -------------------------
: Instant Full-Text Search On Any Database/Application
: site: http://www.dbsight.net
: demo: http://search.dbsight.com
:
: On 3/4/07, MC Moisei <mc...@comcast.net> wrote:
: > How do I clear the locks ? THey have unique names and the name changes
: > everytime...
: >
: > Chris Lu wrote:
: > > A safe way to do this is to clear the locks just before starting your
: > > war file.
: > >
: >
: >
: > ---------------------------------------------------------------------
: > 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
:



-Hoss


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


Re: Clearing locks

Posted by Michael McCandless <lu...@mikemccandless.com>.
"Chris Lu" <ch...@gmail.com> wrote:
> They are not really unique. Here are my code to unlock the directory.
> Notice there are two locks.
> 
>     public static void unlockDirectory(Directory dir) {
>         Lock dirLock = dir.makeLock(IndexWriter.WRITE_LOCK_NAME);
>         if (dirLock.isLocked()) {
>             logger.debug("unlocking " + dirLock);
>             dirLock.release();
>             logger.info("unlocked directory " + dir);
>         }
>         dirLock = dir.makeLock(IndexWriter.COMMIT_LOCK_NAME);
>         if (dirLock.isLocked()) {
>             logger.debug("unlocking " + dirLock);
>             dirLock.release();
>             logger.info("unlocked directory " + dir);
>         }
>     }

Note that as of 2.1, there is only the write.lock (no more commit
lock), and this means readers are read-only (they don't write to the
write lock).  And the write lock filename is stored in the index
directory and doesn't have the big prefix in front of it (by default).

Also as of 2.1, the locking implementation is decoupled from the
Directory implementation, so you can switch to example "in-process"
locking if you know all writers are in the same JVM, or, native file
locking (better than the default "simple" locks because lock files
will be release by the OS if the JVM crashes).  Look at the
*LockFactory javadocs for details.

Mike

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


Re: Clearing locks

Posted by Chris Lu <ch...@gmail.com>.
They are not really unique. Here are my code to unlock the directory.
Notice there are two locks.

    public static void unlockDirectory(Directory dir) {
        Lock dirLock = dir.makeLock(IndexWriter.WRITE_LOCK_NAME);
        if (dirLock.isLocked()) {
            logger.debug("unlocking " + dirLock);
            dirLock.release();
            logger.info("unlocked directory " + dir);
        }
        dirLock = dir.makeLock(IndexWriter.COMMIT_LOCK_NAME);
        if (dirLock.isLocked()) {
            logger.debug("unlocking " + dirLock);
            dirLock.release();
            logger.info("unlocked directory " + dir);
        }
    }

-- 
Chris Lu
-------------------------
Instant Full-Text Search On Any Database/Application
site: http://www.dbsight.net
demo: http://search.dbsight.com

On 3/4/07, MC Moisei <mc...@comcast.net> wrote:
> How do I clear the locks ? THey have unique names and the name changes
> everytime...
>
> Chris Lu wrote:
> > A safe way to do this is to clear the locks just before starting your
> > war file.
> >
>
>
> ---------------------------------------------------------------------
> 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: Clearing locks

Posted by MC Moisei <mc...@comcast.net>.
How do I clear the locks ? THey have unique names and the name changes
everytime...

Chris Lu wrote:
> A safe way to do this is to clear the locks just before starting your
> war file.
>


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


Re: Clearing locks

Posted by Chris Lu <ch...@gmail.com>.
A safe way to do this is to clear the locks just before starting your war file.

-- 
Chris Lu
-------------------------
Instant Full-Text Search On Any Database/Application
site: http://www.dbsight.net
demo: http://search.dbsight.com

On 3/4/07, MC Moisei <mc...@comcast.net> wrote:
> Is there a easy way to clear locks ?
>
> If I redeploy my war file and it happens that there is an indexing
> happening the lock is not cleared. I know I can tell JVM to run the
> finalizers before it exits but in this case the JVM is not exiting being
> a hot deploy.
>
> Any ideas ?
> MC
>
>
> ---------------------------------------------------------------------
> 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: Clearing locks

Posted by John Haxby <jc...@scalix.com>.
MC Moisei wrote:
> Is there a easy way to clear locks ?
>
> If I redeploy my war file and it happens that there is an indexing
> happening the lock is not cleared. I know I can tell JVM to run the
> finalizers before it exits but in this case the JVM is not exiting being
> a hot deploy.
>   
I'd do this by having a destroy() method in the servlet to explicitly 
shut down any operations.  Tomcat (or whatever the servlet is) will call 
destroy() for you when it shuts down the servlet.

jch

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


Re: Clearing locks

Posted by Daniel Noll <da...@nuix.com>.
MC Moisei wrote:
> Is there a easy way to clear locks ?
> 
> If I redeploy my war file and it happens that there is an indexing
> happening the lock is not cleared. I know I can tell JVM to run the
> finalizers before it exits but in this case the JVM is not exiting being
> a hot deploy.
> 
> Any ideas ?

Runtime.getRuntime().addShutdownHook(new Thread() { ... }) ?

That's supposed to be run at any time the JVM shuts down normally.  I 
doubt it runs in the event of a segfault or similar, but it might help.

Daniel

-- 
Daniel Noll

Nuix Pty Ltd
Suite 79, 89 Jones St, Ultimo NSW 2007, Australia    Ph: +61 2 9280 0699
Web: http://nuix.com/                               Fax: +61 2 9212 6902

This message is intended only for the named recipient. If you are not
the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
message or attachment is strictly prohibited.

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