Change to LuceneIndexer so that it will attempt to close the searcher if it cannot replace the live index directory NIHVIVO-2065

This commit is contained in:
bdc34 2011-02-08 00:15:19 +00:00
parent aef7ef1a62
commit 54fa664a24
3 changed files with 34 additions and 29 deletions

View file

@ -36,7 +36,7 @@ public class LuceneIndexFactory {
return getLuceneIndexFactoryFromContext(context).innerGetIndexSearcher(context);
}
public static LuceneIndexFactory getLuceneIndexFactoryFromContext(ServletContext context){
protected static LuceneIndexFactory getLuceneIndexFactoryFromContext(ServletContext context){
Object obj = context.getAttribute(LUCENE_INDEX_FACTORY);
if( obj == null ){
log.error("cannot get LuceneIndexFactory from context. Search is not setup correctly");
@ -68,6 +68,20 @@ public class LuceneIndexFactory {
*/
public synchronized void forceNewIndexSearcher(){
log.debug("forcing the re-opening of the search index");
IndexSearcher oldSearcher = searcher;
searcher = null;
}
protected synchronized void forceClose(){
log.debug("forcing the closing of the search index");
try {
if( searcher != null )
searcher.close();
} catch (IOException e) {
log.error("could not close lucene searcher: " + e.getMessage());
}
searcher = null;
}

View file

@ -280,13 +280,25 @@ public class LuceneIndexer implements IndexerIface {
File offLineDir = new File(currentOffLineDir);
File liveDir = new File(liveIndexDir);
log.debug("deleting old live directory " + liveDir.getAbsolutePath());
boolean deleted = deleteDir(liveDir);
if (! deleted ){
log.error("failed to delete live index directory "
log.debug("failed to delete live index directory "
+ liveDir.getAbsolutePath());
log.debug("Attempting to close searcher and delete live directory");
this.luceneIndexFactory.forceClose();
boolean secondDeleted = deleteDir(liveDir);
if( ! secondDeleted ){
log.error("Search index is out of date and cannot be replaced " +
"because could not remove lucene index from directory"
+ liveDir.getAbsolutePath());
}
return;
}
log.debug("moving " + offLineDir.getAbsolutePath() + " to "
+ liveDir.getAbsolutePath());
boolean success = offLineDir.renameTo( liveDir );
if( ! success ){
log.error("could not move off line index at "
@ -295,7 +307,11 @@ public class LuceneIndexer implements IndexerIface {
return;
}
deleteDir(new File(currentOffLineDir));
File oldWorkignDir = new File(currentOffLineDir);
if( oldWorkignDir.exists() )
log.debug("old working directory should have been removed " +
"but still exits at " + oldWorkignDir.getAbsolutePath());
currentOffLineDir = null;
}