lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1715618 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/util/IOUtils.java lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
Date Sun, 22 Nov 2015 10:29:22 GMT
Author: uschindler
Date: Sun Nov 22 10:29:21 2015
New Revision: 1715618

URL: http://svn.apache.org/viewvc?rev=1715618&view=rev
Log:
Merged revision(s) 1715617 from lucene/dev/trunk:
LUCENE-6902: Don't retry to fsync files / directories; fail immediately

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1715618&r1=1715617&r2=1715618&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Sun Nov 22 10:29:21 2015
@@ -281,6 +281,9 @@ Other
 * LUCENE-6893: factor out CorePlusQueriesParser from CorePlusExtensionsParser
   (Christine Poerschke)
 
+* LUCENE-6902: Don't retry to fsync files / directories; fail
+  immediately. (Daniel Mitterdorfer, Uwe Schindler)
+
 Build
 
 * LUCENE-6732: Improve checker for invalid source patterns to also

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/IOUtils.java?rev=1715618&r1=1715617&r2=1715618&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
Sun Nov 22 10:29:21 2015
@@ -386,46 +386,22 @@ public final class IOUtils {
    *  because not all file systems and operating systems allow to fsync on a directory)
    */
   public static void fsync(Path fileToSync, boolean isDir) throws IOException {
-    IOException exc = null;
-    
     // If the file is a directory we have to open read-only, for regular files we must open
r/w for the fsync to have an effect.
     // See http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/
     try (final FileChannel file = FileChannel.open(fileToSync, isDir ? StandardOpenOption.READ
: StandardOpenOption.WRITE)) {
-      for (int retry = 0; retry < 5; retry++) {
-        try {
-          file.force(true);
-          return;
-        } catch (IOException ioe) {
-          if (exc == null) {
-            exc = ioe;
-          }
-          try {
-            // Pause 5 msec
-            Thread.sleep(5L);
-          } catch (InterruptedException ie) {
-            ThreadInterruptedException ex = new ThreadInterruptedException(ie);
-            ex.addSuppressed(exc);
-            throw ex;
-          }
-        }
-      }
+      file.force(true);
     } catch (IOException ioe) {
-      if (exc == null) {
-        exc = ioe;
+      if (isDir) {
+        // TODO: LUCENE-6169 - Fix this assert once Java 9 problems are solved!
+        assert (Constants.LINUX || Constants.MAC_OS_X) == false || Constants.JRE_IS_MINIMUM_JAVA9
:
+            "On Linux and MacOSX fsyncing a directory should not throw IOException, "+
+                "we just don't want to rely on that in production (undocumented). Got: "
+ ioe;
+        // Ignore exception if it is a directory
+        return;
       }
+      // Throw original exception
+      throw ioe;
     }
-    
-    if (isDir) {
-      // TODO: LUCENE-6169 - Fix this assert once Java 9 problems are solved!
-      assert (Constants.LINUX || Constants.MAC_OS_X) == false || Constants.JRE_IS_MINIMUM_JAVA9
:
-        "On Linux and MacOSX fsyncing a directory should not throw IOException, "+
-        "we just don't want to rely on that in production (undocumented). Got: " + exc;
-      // Ignore exception if it is a directory
-      return;
-    }
-    
-    // Throw original exception
-    throw exc;
   }
 
   /** If the dir is an {@link FSDirectory} or wraps one via possibly

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java?rev=1715618&r1=1715617&r2=1715618&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
Sun Nov 22 10:29:21 2015
@@ -466,4 +466,28 @@ public class TestIOUtils extends LuceneT
     assertFalse(IOUtils.spinsLinux(mockPath));
   }
   
+  public void testFsyncDirectory() throws Exception {
+    Path dir = createTempDir();
+    dir = FilterPath.unwrap(dir).toRealPath();
+
+    Path devdir = dir.resolve("dev");
+    Files.createDirectories(devdir);
+    IOUtils.fsync(devdir, true);
+    // no exception
+  }
+
+  public void testFsyncFile() throws Exception {
+    Path dir = createTempDir();
+    dir = FilterPath.unwrap(dir).toRealPath();
+
+    Path devdir = dir.resolve("dev");
+    Files.createDirectories(devdir);
+    Path somefile = devdir.resolve("somefile");
+    try (OutputStream o = Files.newOutputStream(somefile)) {
+      o.write("0\n".getBytes(StandardCharsets.US_ASCII));
+    }
+    IOUtils.fsync(somefile, false);
+    // no exception
+  }
+
 }



Mime
View raw message