Author: sannegrinovero
Date: 2010-03-28 10:39:15 -0400 (Sun, 28 Mar 2010)
New Revision: 19121
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Workspace.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
Log:
HSEARCH-474 Ensure IndexWriter is closed on errors in backend
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Workspace.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Workspace.java 2010-03-28
14:33:37 UTC (rev 19120)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Workspace.java 2010-03-28
14:39:15 UTC (rev 19121)
@@ -214,4 +214,26 @@
return entitiesInDirectory;
}
+ /**
+ * Forces release of Directory lock. Should be used only to cleanup as error recovery.
+ */
+ public synchronized void forceLockRelease() {
+ log.warn( "going to force release of the IndexWriter lock" );
+ try {
+ try {
+ if ( writer != null ) {
+ writer.close();
+ log.trace( "IndexWriter closed" );
+ }
+ }
+ finally {
+ writer = null; //make sure to send a faulty writer into garbage
+ IndexWriter.unlock( directoryProvider.getDirectory() );
+ }
+ }
+ catch (IOException ioe) {
+ throw new SearchException( "IOException while attempting to force release the
Directory Lock", ioe );
+ }
+ }
+
}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2010-03-28
14:33:37 UTC (rev 19120)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2010-03-28
14:39:15 UTC (rev 19121)
@@ -87,17 +87,28 @@
return;
}
log.debug( "Opening an IndexWriter for update" );
- IndexWriter indexWriter = workspace.getIndexWriter( batchmode );
try {
- for (LuceneWork lw : workOnWriter) {
- lw.getWorkDelegate( worker ).performWork( lw, indexWriter );
+ IndexWriter indexWriter = workspace.getIndexWriter( batchmode );
+ try {
+ for ( LuceneWork lw : workOnWriter ) {
+ lw.getWorkDelegate( worker ).performWork( lw, indexWriter );
+ }
+ workspace.commitIndexWriter();
+ performOptimizations();
}
- workspace.commitIndexWriter();
- performOptimizations();
+ finally {
+ if ( ! exclusiveIndexUsage ) workspace.closeIndexWriter();
+ }
}
- finally {
- if ( ! exclusiveIndexUsage )
+ catch (Throwable tw) {
+ //needs to be attempted even for out of memory errors, therefore we catch Throwable
+ log.error( "Unexpected error in Lucene Backend: ", tw );
+ try {
workspace.closeIndexWriter();
+ }
+ finally {
+ workspace.forceLockRelease();
+ }
}
}
Show replies by date