Peter wrote:
> In step 3. -- since there is only one reference to the
> searhcer -- the real searcher is closed:
> <original-code>
> else // last reference to searcher
> {
> info.searcher.close();
> }
> </original-code>
> The info isn't deleted.
>
> In step 4. in method getSearcher the info is found and the
> closed Searcher object is returned.
Yes, thanks for the bug report! I had already fixed that bug in my code,
but I figured it was just an example anyway, so I didn't mention it. :) On
the other hand, the way it was intended to work is (I think) slightly
different than what you did. In step 3, the searcher should *not* be closed
on release unless it is an old, no longer in use one. Here is the diff of
the fix:
--- IndexAccessControl.java 2002/02/11 20:28:39 1.2
+++ IndexAccessControl.java 2002/04/02 22:40:55 1.3
@@ -137,10 +137,12 @@
String sync = path.getAbsolutePath().intern();
synchronized (sync) // sync on specific index
{
+ boolean old = false;
CheckoutInfo info = (CheckoutInfo)SEARCHER_PATHS.get(path);
if (info == null || searcher != info.searcher) // this isn't
the info we're looking for
{
info = (CheckoutInfo)OLD_SEARCHERS.get(searcher);
+ old = true;
}
if (info != null) // found a searcher
{
@@ -148,7 +150,7 @@
{
info.checkoutCount--;
}
- else // last reference to searcher
+ else if (old)// last reference to old searcher
{
info.searcher.close();
}
> Other:
> a. I changed the IndexAccessControl it's not static any more.
> You can make a new instance for every index.
> b. I created a ManagedSearcher class that is returned by
> getSearcher. If you call close method of this class it
> notifies the IndexAccessControl to release the searcher.
> So the usage:
> IndexAccessControl iac =
> IndexAccessControl.getInstance("/pathToIndex");
> Searcher searcher = iac.getSearcher();
> // use the searcher
> searcher.close();
Yes, that is good.
> If you like this architecture we could improve the code:
> 1. decoupling factory method and access control logic
> 2. decoupling searcher managment and reader/writer managment
Yes, there is still a lot of room for improvement on this. :)
> 3. solve the problem of last used searcher: if the last used
> searcher is released the searcher is closed. Getting searcher
> again takes a lot of time. We should have a pool of searcher
> where the size of pool is 1.
This should not be problem with the corrected releaseSearcher() code above.
> Unfortunatla to use compile and use ManagedSearcher class you
> have to modify lucene source: the Searcher has not public
> abstract methods --> you can't maka subclass of Searcher in
> other package that org.apache.lucene.search.
You're right, Lucene was designed with performance, not extensibility as a
primary goal. So... some modifications to the core will no doubt need to be
made...
Scott