mirror of https://github.com/apache/lucene.git
LUCENE-5570: don't let fsync create new zero-byte files
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1584860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a858257fc6
commit
f8c30e27ae
|
@ -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
|
||||
|
|
|
@ -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 extends BaseDirectory {
|
|||
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)
|
||||
|
|
|
@ -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 LuceneTestCase {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue