Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D566210E38 for ; Fri, 4 Apr 2014 18:21:36 +0000 (UTC) Received: (qmail 96009 invoked by uid 500); 4 Apr 2014 18:21:35 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 95999 invoked by uid 99); 4 Apr 2014 18:21:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2014 18:21:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2014 18:21:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 89E602388A33; Fri, 4 Apr 2014 18:21:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@lucene.apache.org From: rmuir@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140404182111.89E602388A33@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(); + } }