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:
parent
aef7ef1a62
commit
54fa664a24
3 changed files with 34 additions and 29 deletions
|
@ -36,7 +36,7 @@ public class LuceneIndexFactory {
|
||||||
return getLuceneIndexFactoryFromContext(context).innerGetIndexSearcher(context);
|
return getLuceneIndexFactoryFromContext(context).innerGetIndexSearcher(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LuceneIndexFactory getLuceneIndexFactoryFromContext(ServletContext context){
|
protected static LuceneIndexFactory getLuceneIndexFactoryFromContext(ServletContext context){
|
||||||
Object obj = context.getAttribute(LUCENE_INDEX_FACTORY);
|
Object obj = context.getAttribute(LUCENE_INDEX_FACTORY);
|
||||||
if( obj == null ){
|
if( obj == null ){
|
||||||
log.error("cannot get LuceneIndexFactory from context. Search is not setup correctly");
|
log.error("cannot get LuceneIndexFactory from context. Search is not setup correctly");
|
||||||
|
@ -68,6 +68,20 @@ public class LuceneIndexFactory {
|
||||||
*/
|
*/
|
||||||
public synchronized void forceNewIndexSearcher(){
|
public synchronized void forceNewIndexSearcher(){
|
||||||
log.debug("forcing the re-opening of the search index");
|
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;
|
searcher = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,13 +280,25 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
File offLineDir = new File(currentOffLineDir);
|
File offLineDir = new File(currentOffLineDir);
|
||||||
File liveDir = new File(liveIndexDir);
|
File liveDir = new File(liveIndexDir);
|
||||||
|
|
||||||
|
log.debug("deleting old live directory " + liveDir.getAbsolutePath());
|
||||||
boolean deleted = deleteDir(liveDir);
|
boolean deleted = deleteDir(liveDir);
|
||||||
if (! deleted ){
|
if (! deleted ){
|
||||||
log.error("failed to delete live index directory "
|
log.debug("failed to delete live index directory "
|
||||||
+ liveDir.getAbsolutePath());
|
+ 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("moving " + offLineDir.getAbsolutePath() + " to "
|
||||||
|
+ liveDir.getAbsolutePath());
|
||||||
|
|
||||||
boolean success = offLineDir.renameTo( liveDir );
|
boolean success = offLineDir.renameTo( liveDir );
|
||||||
if( ! success ){
|
if( ! success ){
|
||||||
log.error("could not move off line index at "
|
log.error("could not move off line index at "
|
||||||
|
@ -295,7 +307,11 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
return;
|
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;
|
currentOffLineDir = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,31 +105,6 @@ try {
|
||||||
out.write("<input type=submit value=\"Submit changes to logging levels\">");
|
out.write("<input type=submit value=\"Submit changes to logging levels\">");
|
||||||
out.write("</form>\n");
|
out.write("</form>\n");
|
||||||
|
|
||||||
|
|
||||||
/* write out form to do a test message */
|
|
||||||
out.write("<h2>Test the logging configuration by sending a test message</h2>\n");
|
|
||||||
out.write("<form name=\"TestForm\" ACTION=\""+request.getContextPath()+request.getServletPath()+"\" METHOD=\"PUT\">\n");
|
|
||||||
out.write("<input type=\"hidden\" name=\"doTestMsg\" value=\"true\">\n");
|
|
||||||
out.write("<table>\n\r");
|
|
||||||
out.write(" <tr><td>logger:</td>\n\r");
|
|
||||||
out.write(" <td><select name=\"logger\"/>\n\r");
|
|
||||||
for(String logName : logNames){
|
|
||||||
out.write(" <option>" + logName + "</option>\n\r");
|
|
||||||
}
|
|
||||||
out.write(" </select></td></tr>\n\r");
|
|
||||||
|
|
||||||
out.write(" <tr><td>level:</td>\n\r");
|
|
||||||
out.write(" <td><select name=\"level\">\n\r");
|
|
||||||
for (int i = 0; i < levels.length; i++) {
|
|
||||||
out.write(" <option>"+levels[i].toString() + "</option>\n\r");
|
|
||||||
}
|
|
||||||
out.write(" </select></td></tr>\n\r");
|
|
||||||
|
|
||||||
out.write(" <tr><td>message:</td> \n\r");
|
|
||||||
out.write(" <td><textarea name=\"msg\"></textarea></td></tr>\n\r");
|
|
||||||
out.write(" <tr><td><input type=\"submit\" value=\"submit test message\"/></td></tr>\n\r");
|
|
||||||
out.write("</table></form>\n");
|
|
||||||
|
|
||||||
out.write("</BODY></HTML>\r\n");
|
out.write("</BODY></HTML>\r\n");
|
||||||
out.flush();
|
out.flush();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue