You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2014/08/21 16:16:07 UTC

svn commit: r1619402 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/update/HdfsTransactionLog.java core/src/java/org/apache/solr/update/HdfsUpdateLog.java

Author: markrmiller
Date: Thu Aug 21 14:16:07 2014
New Revision: 1619402

URL: http://svn.apache.org/r1619402
Log:
SOLR-6268: HdfsUpdateLog has a race condition that can expose a closed HDFS FileSystem instance and should close it's FileSystem instance if either inherited close method is called.

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsTransactionLog.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsUpdateLog.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1619402&r1=1619401&r2=1619402&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Aug 21 14:16:07 2014
@@ -299,6 +299,9 @@ Bug Fixes
   
 * SOLR-6393: TransactionLog replay performance on HDFS is very poor. (Mark Miller)  
 
+* SOLR-6268: HdfsUpdateLog has a race condition that can expose a closed HDFS FileSystem instance and should 
+  close it's FileSystem instance if either inherited close method is called. (Mark Miller)
+
 Optimizations
 ---------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsTransactionLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsTransactionLog.java?rev=1619402&r1=1619401&r2=1619402&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsTransactionLog.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsTransactionLog.java Thu Aug 21 14:16:07 2014
@@ -274,21 +274,12 @@ public class HdfsTransactionLog extends 
     try {
       synchronized (this) {
         fos.flushBuffer();
-        
-        // we must flush to hdfs
-        // TODO: we probably don't need to
-        // hsync below if we do this - I
-        // think they are equivalent.
-        tlogOutStream.hflush();
       }
 
       if (syncLevel == UpdateLog.SyncLevel.FSYNC) {
-        // Since fsync is outside of synchronized block, we can end up with a partial
-        // last record on power failure (which is OK, and does not represent an error...
-        // we just need to be aware of it when reading).
-        
-        //raf.getFD().sync();
         tlogOutStream.hsync();
+      } else {
+        tlogOutStream.hflush();
       }
 
     } catch (IOException e) {
@@ -304,18 +295,23 @@ public class HdfsTransactionLog extends 
       }
 
       synchronized (this) {
-        fos.flush();
-        tlogOutStream.hflush();
-        fos.close();
-
-        tlogOutStream.close();
+        fos.flushBuffer();
       }
+      
+      tlogOutStream.hflush();
+      tlogOutStream.close();
 
-      if (deleteOnClose) {
-        fs.delete(tlogFile, true);
-      }
     } catch (IOException e) {
+      log.error("Exception closing tlog.", e);
       throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+    } finally {
+      if (deleteOnClose) {
+        try {
+          fs.delete(tlogFile, true);
+        } catch (IOException e) {
+          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+        }
+      }
     }
   }
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsUpdateLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsUpdateLog.java?rev=1619402&r1=1619401&r2=1619402&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsUpdateLog.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/HdfsUpdateLog.java Thu Aug 21 14:16:07 2014
@@ -114,16 +114,18 @@ public class HdfsUpdateLog extends Updat
       }
     }
     
+    FileSystem oldFs = fs;
+    
     try {
-      if (fs != null) {
-        fs.close();
-      }
+      fs = FileSystem.newInstance(new Path(dataDir).toUri(), getConf());
     } catch (IOException e) {
       throw new SolrException(ErrorCode.SERVER_ERROR, e);
     }
     
     try {
-      fs = FileSystem.newInstance(new Path(dataDir).toUri(), getConf());
+      if (oldFs != null) {
+        oldFs.close();
+      }
     } catch (IOException e) {
       throw new SolrException(ErrorCode.SERVER_ERROR, e);
     }
@@ -278,8 +280,14 @@ public class HdfsUpdateLog extends Updat
   
   @Override
   public void close(boolean committed) {
-    synchronized (this) {
-      super.close(committed);
+    close(committed, false);
+  }
+  
+  @Override
+  public void close(boolean committed, boolean deleteOnClose) {
+    try {
+      super.close(committed, deleteOnClose);
+    } finally {
       IOUtils.closeQuietly(fs);
     }
   }