lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1584860 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/store/FSDirectory.java core/src/test/org/apache/lucene/store/TestDirectory.java
Date Fri, 04 Apr 2014 18:21:11 GMT
Author: rmuir
Date: Fri Apr  4 18:21:10 2014
New Revision: 1584860

URL: http://svn.apache.org/r1584860
Log:
LUCENE-5570: don't let fsync create new zero-byte files

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1584860&r1=1584859&r2=1584860&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Fri Apr  4 18:21:10 2014
@@ -243,6 +243,9 @@ Bug fixes
   directory outside of Lucene.  (Simon Willnauer, Shai Erera, Robert
   Muir, Mike McCandless)
 
+* LUCENE-5570: Don't let FSDirectory.sync() create new zero-byte files, instead throw
+  exception if a file is missing.  (Uwe Schindler, Mike McCandless, Robert Muir)
+
 Test Framework
 
 * LUCENE-5567: When a suite fails with zombie threads failure marker and count 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java?rev=1584860&r1=1584859&r2=1584860&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java Fri Apr
 4 18:21:10 2014
@@ -22,6 +22,8 @@ import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.file.StandardOpenOption;
 
 import java.util.Collection;
 import static java.util.Collections.synchronizedSet;
@@ -402,11 +404,11 @@ public abstract class FSDirectory extend
     IOException exc = null;
     while (!success && retryCount < 5) {
       retryCount++;
-      RandomAccessFile file = null;
+      FileChannel file = null;
       try {
         try {
-          file = new RandomAccessFile(fullFile, "rw");
-          file.getFD().sync();
+          file = FileChannel.open(fullFile.toPath(), StandardOpenOption.WRITE);
+          file.force(true); // TODO: we probably dont care about metadata, but this is what
we did before...
           success = true;
         } finally {
           if (file != null)

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java?rev=1584860&r1=1584859&r2=1584860&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java Fri Apr
 4 18:21:10 2014
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.file.NoSuchFileException;
 import java.util.Arrays;
+import java.util.Collections;
 
 import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
 import org.apache.lucene.util.LuceneTestCase;
@@ -287,5 +288,34 @@ public class TestDirectory extends Lucen
       TestUtil.rmDir(path);
     }
   }
+  
+  public void testFsyncDoesntCreateNewFiles() throws Exception {
+    File path = TestUtil.getTempDir("nocreate");
+    Directory fsdir = new SimpleFSDirectory(path);
+    
+    // write a file
+    IndexOutput out = fsdir.createOutput("afile", newIOContext(random()));
+    out.writeString("boo");
+    out.close();
+    
+    // delete it
+    assertTrue(new File(path, "afile").delete());
+    
+    // directory is empty
+    assertEquals(0, fsdir.listAll().length);
+    
+    // fsync it
+    try {
+      fsdir.sync(Collections.singleton("afile"));
+      fail("didn't get expected exception, instead fsync created new files: " + Arrays.asList(fsdir.listAll()));
+    } catch (FileNotFoundException | NoSuchFileException expected) {
+      // ok
+    }
+    
+    // directory is still empty
+    assertEquals(0, fsdir.listAll().length);
+    
+    fsdir.close();
+  }
 }
 



Mime
View raw message