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 Gimantha Bandara <gi...@wso2.com> on 2015/05/21 15:11:54 UTC

Migrating from Lucene 4.10.3 to Lucene 5.10

Hi all,
I was going to through https://lucene.apache.org/core/5_1_0/MIGRATE.html
It is said that the Directory and LockFactory are now refactored.
We have implemented custom directory implementation with
SingleInstanceLockFactory. In Lucene 4.10.3 we have clearLock method. But I
dont find it in 5.1.0. How does Lucene 5.1.0 handle releasing the lock?

-- 
Gimantha Bandara
Software Engineer
WSO2. Inc : http://wso2.com
Mobile : +94714961919

Re: Migrating from Lucene 4.10.3 to Lucene 5.10

Posted by Gimantha Bandara <gi...@wso2.com>.
Hi Uwe,

Yes we have completely custom directory implementation, but anyway we have
not hardcoded the lock factory. But simply we are passing
SingleInstanceLockFactory with the constructor. I have implemented the
makeLock. I see some additional methods like renameFile..etc. I ll update
you once we implement all necessary methods. Thanks a lot for your
explanation!



On Thu, May 21, 2015 at 10:50 PM, Uwe Schindler <uw...@thetaphi.de> wrote:

> Hi,
>
> LockFactories are singletons in Lucene. Basically a directory does not
> even need a LockFactory, the LockFactories are just there to allow
> "configuring" it in FSDirectory subclasses. The abstract BaseDirectory
> class handles this for you, as it delegates all calls to the Directory to a
> given lock factory (this method is final). In your lock factory (ideally
> also a singleton) the method makeLock is where the lock instance should be
> created and returned based on the directory instance passed in. This lock
> instance is responsible to actually lock the directory and also to release
> the lock. There is no need to forcefully unlock, if you make sure that your
> code calls Lock#release() in a finally block.
>
> If you have a completely custom directory implementation with a
> hard-coded, non configureable locking mechanism, it makes no sense to
> extend BaseDirectory, just extend Directory and implement the abstract
> method makeLock(). This method is responsible for creating the lock
> instance that handles actual locking und unlocking. Alternatively you can
> just hardcode SingleInstanceLockFactory (like RAMDirectory does).
>
> clearLock is no longer existent, because it was never used in Lucene. It
> was there to forcefully remove a lock, which is a bad idea. The only
> available method is, as said before, Directory#makeLock that should return
> a Lock instance.
>
> Uwe
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: uwe@thetaphi.de
>
>
> > -----Original Message-----
> > From: Gimantha Bandara [mailto:gimantha@wso2.com]
> > Sent: Thursday, May 21, 2015 3:12 PM
> > To: java-user@lucene.apache.org
> > Subject: Migrating from Lucene 4.10.3 to Lucene 5.10
> >
> > Hi all,
> > I was going to through
> > https://lucene.apache.org/core/5_1_0/MIGRATE.html
> > It is said that the Directory and LockFactory are now refactored.
> > We have implemented custom directory implementation with
> > SingleInstanceLockFactory. In Lucene 4.10.3 we have clearLock method.
> But I
> > dont find it in 5.1.0. How does Lucene 5.1.0 handle releasing the lock?
> >
> > --
> > Gimantha Bandara
> > Software Engineer
> > WSO2. Inc : http://wso2.com
> > Mobile : +94714961919
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


-- 
Gimantha Bandara
Software Engineer
WSO2. Inc : http://wso2.com
Mobile : +94714961919

RE: Migrating from Lucene 4.10.3 to Lucene 5.10

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

LockFactories are singletons in Lucene. Basically a directory does not even need a LockFactory, the LockFactories are just there to allow "configuring" it in FSDirectory subclasses. The abstract BaseDirectory class handles this for you, as it delegates all calls to the Directory to a given lock factory (this method is final). In your lock factory (ideally also a singleton) the method makeLock is where the lock instance should be created and returned based on the directory instance passed in. This lock instance is responsible to actually lock the directory and also to release the lock. There is no need to forcefully unlock, if you make sure that your code calls Lock#release() in a finally block.

If you have a completely custom directory implementation with a hard-coded, non configureable locking mechanism, it makes no sense to extend BaseDirectory, just extend Directory and implement the abstract method makeLock(). This method is responsible for creating the lock instance that handles actual locking und unlocking. Alternatively you can just hardcode SingleInstanceLockFactory (like RAMDirectory does).

clearLock is no longer existent, because it was never used in Lucene. It was there to forcefully remove a lock, which is a bad idea. The only available method is, as said before, Directory#makeLock that should return a Lock instance. 

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Gimantha Bandara [mailto:gimantha@wso2.com]
> Sent: Thursday, May 21, 2015 3:12 PM
> To: java-user@lucene.apache.org
> Subject: Migrating from Lucene 4.10.3 to Lucene 5.10
> 
> Hi all,
> I was going to through
> https://lucene.apache.org/core/5_1_0/MIGRATE.html
> It is said that the Directory and LockFactory are now refactored.
> We have implemented custom directory implementation with
> SingleInstanceLockFactory. In Lucene 4.10.3 we have clearLock method. But I
> dont find it in 5.1.0. How does Lucene 5.1.0 handle releasing the lock?
> 
> --
> Gimantha Bandara
> Software Engineer
> WSO2. Inc : http://wso2.com
> Mobile : +94714961919


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